Merge pull request #18436 from strapi/chore/pack-up-strapi-core

This commit is contained in:
Ben Irvin 2023-10-17 14:08:41 +02:00 committed by GitHub
commit a824b06b11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
87 changed files with 291 additions and 294 deletions

View File

@ -34,7 +34,7 @@ describe('Role CRUD End to End', () => {
sortedData.conditions = sortedData.conditions.sort();
// eslint-disable-next-line node/no-extraneous-require
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const hasSSO = features.isEnabled('sso');
if (hasSSO) {

View File

@ -54,7 +54,7 @@ describeOnCondition(edition === 'EE')('Provider Login', () => {
strapi = await createStrapiInstance();
utils = createUtils(strapi);
// eslint-disable-next-line node/no-extraneous-require
hasSSO = require('@strapi/strapi/dist/utils/ee').default.features.isEnabled('sso');
hasSSO = require('@strapi/strapi/dist/utils/ee').features.isEnabled('sso');
await createFixtures();

View File

@ -54,7 +54,7 @@ describeOnCondition(edition === 'EE')('SSO Provider Options', () => {
strapi = await createStrapiInstance();
utils = createUtils(strapi);
// eslint-disable-next-line node/no-extraneous-require
hasSSO = require('@strapi/strapi/dist/utils/ee').default.features.isEnabled('sso');
hasSSO = require('@strapi/strapi/dist/utils/ee').features.isEnabled('sso');
await createFixtures();

View File

@ -95,7 +95,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
beforeAll(async () => {
await builder.addContentTypes([model]).build();
// eslint-disable-next-line node/no-extraneous-require
hasRW = require('@strapi/strapi/dist/utils/ee').default.features.isEnabled('review-workflows');
hasRW = require('@strapi/strapi/dist/utils/ee').features.isEnabled('review-workflows');
strapi = await createStrapiInstance({ bypassAuth: false });
requests.admin = await createAuthRequest({ strapi });

View File

@ -29,14 +29,14 @@ const CheckboxDataCell = ({ rowId, index }) => {
);
return (
<BaseCheckbox
aria-label={ariaLabel}
checked={isChecked}
onClick={stopPropagation}
onChange={() => {
onSelectRow({ name: rowId, value: !isChecked });
}}
/>
<BaseCheckbox
aria-label={ariaLabel}
checked={isChecked}
onClick={stopPropagation}
onChange={() => {
onSelectRow({ name: rowId, value: !isChecked });
}}
/>
);
};
@ -74,59 +74,59 @@ const EntityActionsDataCell = ({
);
return (
<Flex gap={1} justifyContent="end" onClick={stopPropagation}>
<Flex gap={1} justifyContent="end" onClick={stopPropagation}>
<IconButton
forwardedAs={Link}
onClick={() => {
trackUsage('willEditEntryFromButton');
}}
to={{
pathname: `${pathname}/${rowId}`,
state: { from: pathname },
search: pluginsQueryParams,
}}
label={formatMessage(
{ id: 'app.component.table.edit', defaultMessage: 'Edit {target}' },
{ target: itemLineText }
)}
noBorder
>
<Pencil />
</IconButton>
{canCreate && (
<IconButton
forwardedAs={Link}
onClick={() => {
trackUsage('willEditEntryFromButton');
}}
to={{
pathname: `${pathname}/${rowId}`,
state: { from: pathname },
search: pluginsQueryParams,
}}
onClick={handleCloneClick(rowId)}
label={formatMessage(
{ id: 'app.component.table.edit', defaultMessage: 'Edit {target}' },
{
id: 'app.component.table.duplicate',
defaultMessage: 'Duplicate {target}',
},
{ target: itemLineText }
)}
noBorder
>
<Pencil />
<Duplicate />
</IconButton>
)}
{canCreate && (
<IconButton
onClick={handleCloneClick(rowId)}
label={formatMessage(
{
id: 'app.component.table.duplicate',
defaultMessage: 'Duplicate {target}',
},
{ target: itemLineText }
)}
noBorder
>
<Duplicate />
</IconButton>
)}
{canDelete && (
<IconButton
onClick={() => {
trackUsage('willDeleteEntryFromList');
setSelectedEntries([rowId]);
setIsConfirmDeleteRowOpen(true);
}}
label={formatMessage(
{ id: 'global.delete-target', defaultMessage: 'Delete {target}' },
{ target: itemLineText }
)}
noBorder
>
<Trash />
</IconButton>
)}
</Flex>
{canDelete && (
<IconButton
onClick={() => {
trackUsage('willDeleteEntryFromList');
setSelectedEntries([rowId]);
setIsConfirmDeleteRowOpen(true);
}}
label={formatMessage(
{ id: 'global.delete-target', defaultMessage: 'Delete {target}' },
{ target: itemLineText }
)}
noBorder
>
<Trash />
</IconButton>
)}
</Flex>
);
};

View File

@ -1,7 +1,7 @@
'use strict';
// eslint-disable-next-line node/no-extraneous-require
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const executeCEBootstrap = require('../../server/bootstrap');
const { getService } = require('../../server/utils');
const actions = require('./config/admin-actions');

View File

@ -2,7 +2,7 @@
const { isNil } = require('lodash/fp');
// eslint-disable-next-line node/no-extraneous-require
const ee = require('@strapi/strapi/dist/utils/ee').default;
const ee = require('@strapi/strapi/dist/utils/ee');
const { env } = require('@strapi/utils');
const { getService } = require('../../../server/utils');

View File

@ -1,7 +1,7 @@
'use strict';
// eslint-disable-next-line node/no-extraneous-require
const ee = require('@strapi/strapi/dist/utils/ee').default;
const ee = require('@strapi/strapi/dist/utils/ee');
const _ = require('lodash');
const { pick, isNil } = require('lodash/fp');
const { ApplicationError, ForbiddenError } = require('@strapi/utils').errors;

View File

@ -1,6 +1,6 @@
'use strict';
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const executeCEDestroy = require('../../server/destroy');
module.exports = async ({ strapi }) => {

View File

@ -1,6 +1,6 @@
'use strict';
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const executeCERegister = require('../../server/register');
const migrateAuditLogsTable = require('./migrations/audit-logs-table');
const migrateReviewWorkflowStagesColor = require('./migrations/review-workflows-stages-color');

View File

@ -1,6 +1,6 @@
'use strict';
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const enableFeatureMiddleware = (featureName) => (ctx, next) => {
if (features.isEnabled(featureName)) {

View File

@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => true;
Object.assign(eeModule, {
default: {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
},
});

View File

@ -1,10 +1,10 @@
'use strict';
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const { register } = require('@strapi/provider-audit-logs-local');
const { scheduleJob } = require('node-schedule');
const createAuditLogsService = require('../audit-logs');
const createEventHub = require('../../../../../strapi/dist/services/event-hub').default;
const createEventHub = require('../../../../../strapi/dist/services/event-hub');
jest.mock('../../../../server/register');
@ -13,11 +13,9 @@ jest.mock('../../utils', () => ({
}));
jest.mock('@strapi/strapi/dist/utils/ee', () => ({
default: {
features: {
isEnabled: jest.fn(),
get: jest.fn(),
},
features: {
isEnabled: jest.fn(),
get: jest.fn(),
},
}));

View File

@ -20,11 +20,9 @@ describe('Passport', () => {
describe('Init (SSO disabled)', () => {
beforeAll(() => {
jest.mock('@strapi/strapi/dist/utils/ee', () => ({
default: {
features: {
// Disable the SSO feature
isEnabled: (feature) => feature !== 'sso',
},
features: {
// Disable the SSO feature
isEnabled: (feature) => feature !== 'sso',
},
}));
});
@ -60,11 +58,9 @@ describe('Passport', () => {
describe('Init (SSO enabled)', () => {
beforeAll(() => {
jest.mock('@strapi/strapi/dist/utils/ee', () => ({
default: {
features: {
// Enable all the features (including SSO)
isEnabled: () => true,
},
features: {
// Enable all the features (including SSO)
isEnabled: () => true,
},
}));
});

View File

@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => true;
Object.assign(eeModule, {
default: {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
},
});

View File

@ -1,14 +1,12 @@
'use strict';
jest.mock('@strapi/strapi/dist/utils/ee', () => ({
default: {
features: {
isEnabled() {
return true;
},
list() {
return [{ name: 'sso' }];
},
features: {
isEnabled() {
return true;
},
list() {
return [{ name: 'sso' }];
},
},
}));

View File

@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => true;
Object.assign(eeModule, {
default: {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
},
});

View File

@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => true;
Object.assign(eeModule, {
default: {
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
features: {
isEnabled() {
return true;
},
getEnabled() {
return ['review-workflows'];
},
},
});

View File

@ -2,7 +2,7 @@
const localProvider = require('@strapi/provider-audit-logs-local');
const { scheduleJob } = require('node-schedule');
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const DEFAULT_RETENTION_DAYS = 90;

View File

@ -1,7 +1,7 @@
'use strict';
// eslint-disable-next-line node/no-extraneous-require
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const { UnauthorizedError } = require('@strapi/utils').errors;
const createLocalStrategy = require('../../../server/services/passport/local-strategy');

View File

@ -1,6 +1,6 @@
'use strict';
const ee = require('@strapi/strapi/dist/utils/ee').default;
const ee = require('@strapi/strapi/dist/utils/ee');
const { authEventsMapper } = require('../../../../server/services/passport');
const createProviderRegistry = require('./provider-registry');

View File

@ -1,7 +1,7 @@
'use strict';
// eslint-disable-next-line node/no-extraneous-require
const ee = require('@strapi/strapi/dist/utils/ee').default;
const ee = require('@strapi/strapi/dist/utils/ee');
const { take, drop, map, prop, pick, reverse, isNil } = require('lodash/fp');
const { getService } = require('../../../server/utils');
const { SUPER_ADMIN_CODE } = require('../../../server/services/constants');

View File

@ -7,11 +7,9 @@ let ssoEnabled = true;
jest.mock('@strapi/strapi/dist/utils/ee', () => {
return {
default: {
features: {
isEnabled() {
return ssoEnabled;
},
features: {
isEnabled() {
return ssoEnabled;
},
},
};

View File

@ -1,6 +1,6 @@
'use strict';
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const { isEmpty } = require('lodash/fp');
const isSsoLocked = async (user) => {

View File

@ -2,7 +2,7 @@
const { yup, validateYupSchema } = require('@strapi/utils');
// eslint-disable-next-line node/no-extraneous-require
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const roleCreateSchema = yup
.object()

View File

@ -2,7 +2,7 @@
const { yup, validateYupSchema } = require('@strapi/utils');
// eslint-disable-next-line node/no-extraneous-require
const { features } = require('@strapi/strapi/dist/utils/ee').default;
const { features } = require('@strapi/strapi/dist/utils/ee');
const { schemas } = require('../../../server/validation/user');
const ssoUserCreationInputExtension = yup

View File

@ -4,14 +4,12 @@ jest.mock('@strapi/strapi/dist/utils/ee', () => {
const eeModule = () => false;
Object.assign(eeModule, {
default: {
features: {
isEnabled() {
return false;
},
list() {
return [];
},
features: {
isEnabled() {
return false;
},
list() {
return [];
},
},
});

View File

@ -8,7 +8,7 @@ const { exists } = require('fs-extra');
const { env } = require('@strapi/utils');
const { isUsingTypeScript } = require('@strapi/typescript-utils');
// eslint-disable-next-line node/no-extraneous-require
const ee = require('@strapi/strapi/dist/utils/ee').default;
const ee = require('@strapi/strapi/dist/utils/ee');
const {
validateUpdateProjectSettings,

View File

@ -4,7 +4,7 @@ const _ = require('lodash');
const { merge } = require('lodash/fp');
const permissionService = require('../permission');
const { toPermission } = require('../../domain/permission');
const createEventHub = require('../../../../strapi/dist/services/event-hub').default;
const createEventHub = require('../../../../strapi/dist/services/event-hub');
describe('Permission Service', () => {
beforeEach(() => {

View File

@ -4,7 +4,7 @@ const _ = require('lodash');
const roleService = require('../role');
const { SUPER_ADMIN_CODE } = require('../constants');
const { create: createPermission, toPermission } = require('../../domain/permission');
const createEventHub = require('../../../../strapi/dist/services/event-hub').default;
const createEventHub = require('../../../../strapi/dist/services/event-hub');
describe('Role', () => {
describe('create', () => {

View File

@ -1,52 +1,52 @@
type Condition = {
id: string;
displayName: string;
category: string;
}
id: string;
displayName: string;
category: string;
};
type Permission = {
action: string;
displayName: string;
plugin: string;
subCategory: string;
}
action: string;
displayName: string;
plugin: string;
subCategory: string;
};
type ContentTypePermission = {
actionId: string;
applyToProperties: string[];
label: string;
subjects: string[];
}
actionId: string;
applyToProperties: string[];
label: string;
subjects: string[];
};
type ContentTypeSubject = {
uid: string;
label: string;
properties: ContentTypeSubjectProperties[];
uid: string;
label: string;
properties: ContentTypeSubjectProperties[];
};
type ContentTypeSubjectPropertyChild = {
label: string;
value: string;
required?: boolean;
}
label: string;
value: string;
required?: boolean;
};
type ContentTypeSubjectProperties = {
label: string;
value: string;
children: ContentTypeSubjectPropertyChild[];
}
label: string;
value: string;
children: ContentTypeSubjectPropertyChild[];
};
type ContentTypePermissions = {
actions: ContentTypePermission[];
subjects: ContentTypeSubject[];
}
actions: ContentTypePermission[];
subjects: ContentTypeSubject[];
};
export interface RolePermissions {
conditions: Condition[];
sections: {
plugins: Permission[];
settings: Permission[];
singleTypes: ContentTypePermissions;
collectionTypes: ContentTypePermissions;
}
conditions: Condition[];
sections: {
plugins: Permission[];
settings: Permission[];
singleTypes: ContentTypePermissions;
collectionTypes: ContentTypePermissions;
};
}

View File

@ -1,7 +1,2 @@
#!/usr/bin/env node
'use strict';
const { runStrapiCommand } = require('../dist/commands');
runStrapiCommand(process.argv);
require('../dist/cli');

View File

@ -1,5 +0,0 @@
const strapi = require('./dist');
module.exports = strapi.default;
module.exports.factories = strapi.factories;
module.exports.compile = strapi.compile;

View File

@ -64,7 +64,9 @@
"url": "https://strapi.io"
}
],
"main": "./index.js",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"source": "./src/index.ts",
"types": "./dist/index.d.ts",
"bin": "./bin/strapi.js",
"files": [
@ -75,16 +77,14 @@
"index.js"
],
"scripts": {
"build": "run -T tsc -p tsconfig.build.json && run copy-files",
"build:ts": "run build",
"clean": "run -T rimraf ./dist",
"build": "run pack-up build && run copy-files",
"copy-files": "copyfiles -u 1 -a 'src/**/*.html' 'src/**/*.png' dist",
"postinstall": "node ./scripts/postinstall.js",
"lint": "run -T eslint .",
"prepublishOnly": "yarn clean && yarn build",
"test:unit": "run -T jest",
"test:unit:watch": "run -T jest --watch",
"watch": "run -T tsc -p tsconfig.build.json -w --preserveWatchOutput"
"watch": "pack-up watch"
},
"dependencies": {
"@koa/cors": "3.4.3",
@ -144,7 +144,6 @@
"package-json": "7.0.0",
"pkg-up": "3.1.0",
"qs": "6.11.1",
"resolve-cwd": "3.0.0",
"semver": "7.5.4",
"statuses": "2.0.1",
"typescript": "5.2.2",
@ -152,6 +151,7 @@
"yup": "0.32.9"
},
"devDependencies": {
"@strapi/pack-up": "workspace:*",
"@strapi/ts-zen": "^0.2.0",
"@types/bcryptjs": "2.4.3",
"@types/configstore": "5.0.1",

View File

@ -0,0 +1,16 @@
// eslint-disable-next-line import/no-extraneous-dependencies
import { defineConfig } from '@strapi/pack-up';
import { builtinModules } from 'node:module';
export default defineConfig({
bundles: [
{
source: './src/cli.ts',
require: './dist/cli.js',
runtime: 'node',
},
],
externals: [...builtinModules],
preserveModules: true,
runtime: 'node',
});

View File

@ -0,0 +1,3 @@
import { runStrapiCommand } from './commands';
runStrapiCommand(process.argv);

View File

@ -25,7 +25,7 @@ const mock = {
admin,
};
jest.mock('../../../../../index', () => {
jest.mock('../../../../../Strapi', () => {
const impl: any = jest.fn(() => mock);
impl.compile = jest.fn();

View File

@ -1,7 +1,7 @@
import { yup } from '@strapi/utils';
import _ from 'lodash';
import inquirer from 'inquirer';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
interface CmdOptions {
email?: string;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import { runAction } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import action from './action';
/**
* `$ strapi admin:create-user`
@ -13,7 +14,7 @@ const command: StrapiCommand = ({ command }) => {
.option('-p, --password <password>', 'Password of the new admin')
.option('-f, --firstname <first name>', 'First name of the new admin')
.option('-l, --lastname <last name>', 'Last name of the new admin')
.action(getLocalScript('admin/create-user'));
.action(runAction('admin:create-user', action));
};
export default command;

View File

@ -16,7 +16,7 @@ const mock = {
admin,
};
jest.mock('../../../../../index', () => {
jest.mock('../../../../../Strapi', () => {
const impl = jest.fn(() => mock);
Object.assign(impl, {

View File

@ -1,6 +1,6 @@
import _ from 'lodash';
import inquirer from 'inquirer';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
interface CmdOptions {
email?: string;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi admin:reset-user-password`
@ -11,7 +12,7 @@ const command: StrapiCommand = ({ command }) => {
.description("Reset an admin user's password")
.option('-e, --email <email>', 'The user email')
.option('-p, --password <password>', 'New password for the user')
.action(getLocalScript('admin/reset-user-password'));
.action(runAction('admin:reset-user-password', action));
};
export default command;

View File

@ -1,4 +1,4 @@
import strapi from '../../..';
import strapi from '../../../Strapi';
import { buildAdmin } from '../../builders';
interface CmdOptions {

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../utils/helpers';
import type { StrapiCommand } from '../../types';
import { runAction } from '../../utils/helpers';
import action from './action';
/**
* `$ strapi build`
@ -9,7 +10,7 @@ const command: StrapiCommand = ({ command }) => {
.command('build')
.option('--no-optimization', 'Build the admin app without optimizing assets')
.description('Build the strapi admin app')
.action(getLocalScript('build-command')); // build-command dir to avoid problems with 'build' being commonly ignored
.action(runAction('build', action)); // build-command dir to avoid problems with 'build' being commonly ignored
};
export default command;

View File

@ -1,7 +1,7 @@
import CLITable from 'cli-table3';
import chalk from 'chalk';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
export default async () => {
const appContext = await strapi.compile();

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi components:list`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('components:list')
.description('List all the application components')
.action(getLocalScript('components/list'));
.action(runAction('components:list', action));
};
export default command;

View File

@ -1,5 +1,5 @@
import fs from 'fs';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
interface CmdOptions {
file?: string;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi configuration:dump`
@ -11,7 +12,7 @@ const command: StrapiCommand = ({ command }) => {
.description('Dump configurations of your application')
.option('-f, --file <file>', 'Output file, default output is stdout')
.option('-p, --pretty', 'Format the output JSON with indentation and line breaks', false)
.action(getLocalScript('configuration/dump'));
.action(runAction('configuration:dump', action));
};
export default command;

View File

@ -2,7 +2,7 @@ import fs from 'fs';
import _ from 'lodash';
import type { Database } from '@strapi/database';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
type Strategy = 'replace' | 'merge' | 'keep';

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi configuration:restore`
@ -11,7 +12,7 @@ const command: StrapiCommand = ({ command }) => {
.description('Restore configurations of your application')
.option('-f, --file <file>', 'Input file, default input is stdin')
.option('-s, --strategy <strategy>', 'Strategy name, one of: "replace", "merge", "keep"')
.action(getLocalScript('configuration/restore'));
.action(runAction('configuration:restore', action));
};
export default command;

View File

@ -1,5 +1,5 @@
import REPL from 'repl';
import strapi from '../../../index';
import strapi from '../../../Strapi';
/**
* `$ strapi console`

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../utils/helpers';
import type { StrapiCommand } from '../../types';
import { runAction } from '../../utils/helpers';
import action from './action';
/**
* `$ strapi console`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('console')
.description('Open the Strapi framework console')
.action(getLocalScript('console'));
.action(runAction('console', action));
};
export default command;

View File

@ -1,7 +1,7 @@
import CLITable from 'cli-table3';
import chalk from 'chalk';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
export default async () => {
const appContext = await strapi.compile();

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi content-types:list`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('content-types:list')
.description('List all the application content-types')
.action(getLocalScript('content-types/list'));
.action(runAction('content-types:list', action));
};
export default command;

View File

@ -1,7 +1,7 @@
import CLITable from 'cli-table3';
import chalk from 'chalk';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
export default async () => {
const appContext = await strapi.compile();

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi controllers:list`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('controllers:list')
.description('List all the application controllers')
.action(getLocalScript('controllers/list'));
.action(runAction('controllers:list', action));
};
export default command;

View File

@ -9,7 +9,7 @@ import tsUtils from '@strapi/typescript-utils';
import type { Strapi } from '@strapi/types';
import loadConfiguration from '../../../core/app-configuration';
import strapi from '../../../index';
import strapi from '../../../Strapi';
import { buildTypeScript, buildAdmin } from '../../builders';
interface CmdOptions {
@ -23,7 +23,7 @@ interface CmdOptions {
* `$ strapi develop`
*
*/
export default async ({ build, watchAdmin, polling, browser }: CmdOptions) => {
export default async ({ build, watchAdmin, polling, browser }: CmdOptions): Promise<void> => {
const appDir = process.cwd();
const isTSProject = await tsUtils.isUsingTypeScript(appDir);
@ -183,7 +183,7 @@ const workerProcess = async ({
}
});
return strapiInstance.start();
strapiInstance.start();
};
/**

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../utils/helpers';
import type { StrapiCommand } from '../../types';
import { runAction } from '../../utils/helpers';
import action from './action';
/**
* `$ strapi develop`
@ -13,7 +14,7 @@ const command: StrapiCommand = ({ command }) => {
.option('--polling', 'Watch for file changes in network directories', false)
.option('--browser <name>', 'Open the browser', true)
.description('Start your Strapi application in development mode')
.action(getLocalScript('develop'));
.action(runAction('develop', action));
};
export default command;

View File

@ -1,7 +1,7 @@
import CLITable from 'cli-table3';
import chalk from 'chalk';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
export default async () => {
const appContext = await strapi.compile();

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi hooks:list`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('hooks:list')
.description('List all the application hooks')
.action(getLocalScript('hooks/list'));
.action(runAction('hooks:list', action));
};
export default command;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../utils/helpers';
import type { StrapiCommand } from '../../types';
import { runAction } from '../../utils/helpers';
import action from './action';
/**
* `$ strapi install`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('install [plugins...]')
.description('Install a Strapi plugin')
.action(getLocalScript('install'));
.action(runAction('install', action));
};
export default command;

View File

@ -1,7 +1,7 @@
import CLITable from 'cli-table3';
import chalk from 'chalk';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
export default async () => {
const appContext = await strapi.compile();

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi middlewares:list`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('middlewares:list')
.description('List all the application middlewares')
.action(getLocalScript('middlewares/list'));
.action(runAction('middlewares:list', action));
};
export default command;

View File

@ -1,6 +1,7 @@
import { forceOption } from '../../../utils/commander';
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi plugin:build`
@ -14,7 +15,7 @@ const command: StrapiCommand = ({ command }) => {
.option('--silent', "Don't log anything", false)
.option('--sourcemap', 'produce sourcemaps', false)
.option('--minify', 'minify the output', false)
.action(getLocalScript('plugin/build-command'));
.action(runAction('plugin:build', action));
};
export default command;

View File

@ -1,7 +1,7 @@
import CLITable from 'cli-table3';
import chalk from 'chalk';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
export default async () => {
const appContext = await strapi.compile();

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi policies:list`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('policies:list')
.description('List all the application policies')
.action(getLocalScript('policies/list'));
.action(runAction('policies:list', action));
};
export default command;

View File

@ -1,5 +1,5 @@
import { EOL } from 'os';
import strapi from '../../../index';
import strapi from '../../../Strapi';
interface CmdOptions {
uuid: boolean;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../utils/helpers';
import type { StrapiCommand } from '../../types';
import { runAction } from '../../utils/helpers';
import action from './action';
/**
* `$ strapi report`
@ -11,7 +12,7 @@ const command: StrapiCommand = ({ command }) => {
.option('-u, --uuid', 'Include Project UUID')
.option('-d, --dependencies', 'Include Project Dependencies')
.option('--all', 'Include All Information')
.action(getLocalScript('report'));
.action(runAction('report', action));
};
export default command;

View File

@ -2,7 +2,7 @@ import CLITable from 'cli-table3';
import chalk from 'chalk';
import { toUpper } from 'lodash/fp';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
export default async () => {
const appContext = await strapi.compile();

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi routes:list``
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('routes:list')
.description('List all the application routes')
.action(getLocalScript('routes/list'));
.action(runAction('routes:list', action));
};
export default command;

View File

@ -1,7 +1,7 @@
import CLITable from 'cli-table3';
import chalk from 'chalk';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
export default async () => {
const appContext = await strapi.compile();

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi services:list`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('services:list')
.description('List all the application services')
.action(getLocalScript('services/list'));
.action(runAction('services:list', action));
};
export default command;

View File

@ -1,6 +1,6 @@
import fs from 'fs';
import tsUtils from '@strapi/typescript-utils';
import strapi from '../../../index';
import strapi from '../../../Strapi';
/**
* `$ strapi start`
@ -19,5 +19,5 @@ export default async () => {
`${outDir} directory not found. Please run the build command before starting your application`
);
return strapi({ appDir, distDir }).start();
strapi({ appDir, distDir }).start();
};

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../utils/helpers';
import type { StrapiCommand } from '../../types';
import { runAction } from '../../utils/helpers';
import action from './action';
/**
* `$ strapi start`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('start')
.description('Start your Strapi application')
.action(getLocalScript('start'));
.action(runAction('start', action));
};
export default command;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi telemetry:disable`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('telemetry:disable')
.description('Disable anonymous telemetry and metadata sending to Strapi analytics')
.action(getLocalScript('telemetry/disable'));
.action(runAction('telemetry:disable', action));
};
export default command;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi telemetry:enable`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('telemetry:enable')
.description('Enable anonymous telemetry and metadata sending to Strapi analytics')
.action(getLocalScript('telemetry/enable'));
.action(runAction('telemetry:enable', action));
};
export default command;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
*`$ strapi templates:generate <directory>`
@ -8,7 +9,7 @@ const command: StrapiCommand = ({ command }) => {
command
.command('templates:generate <directory>')
.description('Generate template from Strapi project')
.action(getLocalScript('templates/generate'));
.action(runAction('templates:generate', action));
};
export default command;

View File

@ -1,5 +1,5 @@
import tsUtils from '@strapi/typescript-utils';
import strapi from '../../../../index';
import strapi from '../../../../Strapi';
interface CmdOptions {
debug?: boolean;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../../utils/helpers';
import type { StrapiCommand } from '../../../types';
import { runAction } from '../../../utils/helpers';
import action from './action';
/**
* `$ strapi ts:generate-types`
@ -15,7 +16,7 @@ const command: StrapiCommand = ({ command }) => {
'-o, --out-dir <outDir>',
'Specify a relative root directory in which the definitions will be generated. Changing this value might break types exposed by Strapi that relies on generated types.'
)
.action(getLocalScript('ts/generate-types'));
.action(runAction('ts:generate-types', action));
};
export default command;

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../utils/helpers';
import type { StrapiCommand } from '../../types';
import { runAction } from '../../utils/helpers';
import action from './action';
/**
* `$ strapi uninstall`
@ -9,7 +10,7 @@ const command: StrapiCommand = ({ command }) => {
.command('uninstall [plugins...]')
.description('Uninstall a Strapi plugin')
.option('-d, --delete-files', 'Delete files', false)
.action(getLocalScript('uninstall'));
.action(runAction('uninstall', action));
};
export default command;

View File

@ -3,7 +3,7 @@ import { getConfigUrls, getAbsoluteServerUrl } from '@strapi/utils';
import { getEnabledPlugins } from '../../../core/loaders/plugins/get-enabled-plugins';
import addSlash from '../../../utils/addSlash';
import strapi from '../../../index';
import strapi from '../../../Strapi';
export default async ({ browser }: { browser: boolean }) => {
const appContext = await strapi.compile();

View File

@ -1,5 +1,6 @@
import { getLocalScript } from '../../utils/helpers';
import type { StrapiCommand } from '../../types';
import { runAction } from '../../utils/helpers';
import action from './action';
/**
* `$ strapi watch-admin`
@ -9,7 +10,7 @@ const command: StrapiCommand = ({ command }) => {
.command('watch-admin')
.option('--browser <name>', 'Open the browser', true)
.description('Start the admin development server')
.action(getLocalScript('watch-admin'));
.action(runAction('watch-admin', action));
};
export default command;

View File

@ -5,7 +5,7 @@ import { getConfigUrls } from '@strapi/utils';
import ee from '../../utils/ee';
import addSlash from '../../utils/addSlash';
import strapi from '../../index';
import strapi from '../../Strapi';
import { getEnabledPlugins } from '../../core/loaders/plugins/get-enabled-plugins';
export interface Options {

View File

@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-var-requires */
import chalk from 'chalk';
import { has, isString, isArray } from 'lodash/fp';
import resolveCwd from 'resolve-cwd';
import { prompt } from 'inquirer';
import boxen from 'boxen';
import type { Command } from 'commander';
@ -133,26 +132,14 @@ const assertCwdContainsStrapiProject = (name: string) => {
}
};
const getLocalScript =
(name: string) =>
const runAction =
(name: string, action: (...args: any[]) => Promise<void>) =>
(...args: unknown[]) => {
assertCwdContainsStrapiProject(name);
const cmdPath = resolveCwd.silent(`@strapi/strapi/dist/commands/actions/${name}/action`);
if (!cmdPath) {
console.log(
`Error loading the local ${chalk.yellow(
name
)} command. Strapi might not be installed in your "node_modules". You may need to run "yarn install".`
);
process.exit(1);
}
const script = require(cmdPath).default;
Promise.resolve()
.then(() => {
return script(...args);
return action(...args);
})
.catch((error) => {
console.error(error);
@ -210,7 +197,7 @@ export {
assertUrlHasProtocol,
ifOptions,
readableBytes,
getLocalScript,
runAction,
assertCwdContainsStrapiProject,
notifyExperimentalCommand,
};

View File

@ -2,7 +2,4 @@ import strapiFactory from './Strapi';
export type * from '@strapi/types';
export * as factories from './factories';
export { default as compile } from './compile';
export default strapiFactory;

View File

@ -3,6 +3,6 @@
"compilerOptions": {
"noEmit": true
},
"include": ["src"],
"include": ["src", "packup.config.ts"],
"exclude": ["node_modules"]
}

View File

@ -7781,7 +7781,7 @@ __metadata:
languageName: unknown
linkType: soft
"@strapi/pack-up@4.14.4, @strapi/pack-up@workspace:*, @strapi/pack-up@workspace:packages/utils/pack-up":
"@strapi/pack-up@workspace:*, @strapi/pack-up@workspace:packages/utils/pack-up":
version: 0.0.0-use.local
resolution: "@strapi/pack-up@workspace:packages/utils/pack-up"
dependencies:
@ -8281,7 +8281,7 @@ __metadata:
"@strapi/generate-new": 4.14.4
"@strapi/generators": 4.14.4
"@strapi/logger": 4.14.4
"@strapi/pack-up": 4.14.4
"@strapi/pack-up": "workspace:*"
"@strapi/permissions": 4.14.4
"@strapi/plugin-content-manager": 4.14.4
"@strapi/plugin-content-type-builder": 4.14.4
@ -8346,7 +8346,6 @@ __metadata:
package-json: 7.0.0
pkg-up: 3.1.0
qs: 6.11.1
resolve-cwd: 3.0.0
semver: 7.5.4
statuses: 2.0.1
supertest: 6.3.3