diff --git a/packages/core/strapi/lib/commands/__tests__/admin-create.test.js b/packages/core/strapi/lib/commands/__tests__/admin-create.test.js index 17687429a1..7e77945733 100644 --- a/packages/core/strapi/lib/commands/__tests__/admin-create.test.js +++ b/packages/core/strapi/lib/commands/__tests__/admin-create.test.js @@ -33,7 +33,7 @@ jest.mock('../../index', () => { }); const inquirer = require('inquirer'); -const createAdminCommand = require('../scripts/admin-create'); +const createAdminCommand = require('../actions/admin/create-user/action'); describe('admin:create command', () => { beforeEach(() => { diff --git a/packages/core/strapi/lib/commands/__tests__/admin-reset.test.js b/packages/core/strapi/lib/commands/__tests__/admin-reset.test.js index 537b2aba1a..0ce97e3516 100644 --- a/packages/core/strapi/lib/commands/__tests__/admin-reset.test.js +++ b/packages/core/strapi/lib/commands/__tests__/admin-reset.test.js @@ -24,7 +24,7 @@ jest.mock('../../index', () => { }); const inquirer = require('inquirer'); -const resetAdminPasswordCommand = require('../scripts/admin-reset'); +const resetAdminPasswordCommand = require('../actions/admin/reset-user-password/action'); describe('admin:reset-password command', () => { beforeEach(() => { diff --git a/packages/core/strapi/lib/commands/scripts/admin-create.js b/packages/core/strapi/lib/commands/actions/admin/create-user/action.js similarity index 98% rename from packages/core/strapi/lib/commands/scripts/admin-create.js rename to packages/core/strapi/lib/commands/actions/admin/create-user/action.js index b06e07250a..a080281b48 100644 --- a/packages/core/strapi/lib/commands/scripts/admin-create.js +++ b/packages/core/strapi/lib/commands/actions/admin/create-user/action.js @@ -3,7 +3,7 @@ const { yup } = require('@strapi/utils'); const _ = require('lodash'); const inquirer = require('inquirer'); -const strapi = require('../../index'); +const strapi = require('../../../../index'); const emailValidator = yup.string().email('Invalid email address').lowercase(); diff --git a/packages/core/strapi/lib/commands/actions/admin/create-user/command.js b/packages/core/strapi/lib/commands/actions/admin/create-user/command.js new file mode 100644 index 0000000000..f1b961d657 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/admin/create-user/command.js @@ -0,0 +1,15 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('admin:create-user') + .alias('admin:create') + .description('Create a new admin') + .option('-e, --email ', 'Email of the new admin') + .option('-p, --password ', 'Password of the new admin') + .option('-f, --firstname ', 'First name of the new admin') + .option('-l, --lastname ', 'Last name of the new admin') + .action(getLocalScript('admin/create-user')); +}; diff --git a/packages/core/strapi/lib/commands/scripts/admin-reset.js b/packages/core/strapi/lib/commands/actions/admin/reset-user-password/action.js similarity index 96% rename from packages/core/strapi/lib/commands/scripts/admin-reset.js rename to packages/core/strapi/lib/commands/actions/admin/reset-user-password/action.js index 47f03941d4..b7f5473880 100644 --- a/packages/core/strapi/lib/commands/scripts/admin-reset.js +++ b/packages/core/strapi/lib/commands/actions/admin/reset-user-password/action.js @@ -2,7 +2,7 @@ const _ = require('lodash'); const inquirer = require('inquirer'); -const strapi = require('../../index'); +const strapi = require('../../../../index'); const promptQuestions = [ { type: 'input', name: 'email', message: 'User email?' }, diff --git a/packages/core/strapi/lib/commands/actions/admin/reset-user-password/command.js b/packages/core/strapi/lib/commands/actions/admin/reset-user-password/command.js new file mode 100644 index 0000000000..0996531d7a --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/admin/reset-user-password/command.js @@ -0,0 +1,13 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('admin:reset-user-password') + .alias('admin:reset-password') + .description("Reset an admin user's password") + .option('-e, --email ', 'The user email') + .option('-p, --password ', 'New password for the user') + .action(getLocalScript('admin/reset-user-password')); +}; diff --git a/packages/core/strapi/lib/commands/scripts/build.js b/packages/core/strapi/lib/commands/actions/build-action/action.js similarity index 76% rename from packages/core/strapi/lib/commands/scripts/build.js rename to packages/core/strapi/lib/commands/actions/build-action/action.js index 8706463919..15f9de8367 100644 --- a/packages/core/strapi/lib/commands/scripts/build.js +++ b/packages/core/strapi/lib/commands/actions/build-action/action.js @@ -1,7 +1,7 @@ 'use strict'; -const strapi = require('../..'); -const { buildAdmin } = require('../builders'); +const strapi = require('../../..'); +const { buildAdmin } = require('../../builders'); /** * `$ strapi build` diff --git a/packages/core/strapi/lib/commands/actions/build-action/command.js b/packages/core/strapi/lib/commands/actions/build-action/command.js index a397e25992..8deda3808e 100644 --- a/packages/core/strapi/lib/commands/actions/build-action/command.js +++ b/packages/core/strapi/lib/commands/actions/build-action/command.js @@ -1,13 +1,12 @@ 'use strict'; -const { loadProjectScript } = require('../../scripts/utils/helpers'); +const { getLocalScript } = require('../../utils/helpers'); -// TODO: fix gitignore so that this folder can be called build module.exports = ({ command /* , argv */ }) => { // `$ strapi build` command .command('build') .option('--no-optimization', 'Build the admin app without optimizing assets') .description('Build the strapi admin app') - .action(loadProjectScript('build')); + .action(getLocalScript('build-action')); // TODO: fix gitignore so that this folder can be called build }; diff --git a/packages/core/strapi/lib/commands/scripts/configurationDump.js b/packages/core/strapi/lib/commands/actions/configuration/dump/action.js similarity index 96% rename from packages/core/strapi/lib/commands/scripts/configurationDump.js rename to packages/core/strapi/lib/commands/actions/configuration/dump/action.js index 4a752916b9..7c6527e91b 100644 --- a/packages/core/strapi/lib/commands/scripts/configurationDump.js +++ b/packages/core/strapi/lib/commands/actions/configuration/dump/action.js @@ -1,7 +1,7 @@ 'use strict'; const fs = require('fs'); -const strapi = require('../../index'); +const strapi = require('../../../../index'); const CHUNK_SIZE = 100; diff --git a/packages/core/strapi/lib/commands/actions/configuration/dump/command.js b/packages/core/strapi/lib/commands/actions/configuration/dump/command.js new file mode 100644 index 0000000000..f42007ea51 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/configuration/dump/command.js @@ -0,0 +1,13 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('configuration:dump') + .alias('config:dump') + .description('Dump configurations of your application') + .option('-f, --file ', 'Output file, default output is stdout') + .option('-p, --pretty', 'Format the output JSON with indentation and line breaks', false) + .action(getLocalScript('configuration/dump')); +}; diff --git a/packages/core/strapi/lib/commands/scripts/configurationRestore.js b/packages/core/strapi/lib/commands/actions/configuration/restore/action.js similarity index 98% rename from packages/core/strapi/lib/commands/scripts/configurationRestore.js rename to packages/core/strapi/lib/commands/actions/configuration/restore/action.js index 595ab731c2..fc416df741 100644 --- a/packages/core/strapi/lib/commands/scripts/configurationRestore.js +++ b/packages/core/strapi/lib/commands/actions/configuration/restore/action.js @@ -3,7 +3,7 @@ const fs = require('fs'); const _ = require('lodash'); -const strapi = require('../../index'); +const strapi = require('../../../../index'); /** * Will restore configurations. It reads from a file or stdin diff --git a/packages/core/strapi/lib/commands/actions/configuration/restore/command.js b/packages/core/strapi/lib/commands/actions/configuration/restore/command.js new file mode 100644 index 0000000000..e82783a707 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/configuration/restore/command.js @@ -0,0 +1,13 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('configuration:restore') + .alias('config:restore') + .description('Restore configurations of your application') + .option('-f, --file ', 'Input file, default input is stdin') + .option('-s, --strategy ', 'Strategy name, one of: "replace", "merge", "keep"') + .action(getLocalScript('configuration/restore')); +}; diff --git a/packages/core/strapi/lib/commands/actions/console copy/command.js b/packages/core/strapi/lib/commands/actions/console copy/command.js new file mode 100644 index 0000000000..ef77b27612 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/console copy/command.js @@ -0,0 +1,11 @@ +'use strict'; + +const { loadProjectScript } = require('../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + // `$ strapi console` + command + .command('console') + .description('Open the Strapi framework console') + .action(loadProjectScript('console')); +}; diff --git a/packages/core/strapi/lib/commands/actions/console/command.js b/packages/core/strapi/lib/commands/actions/console/command.js index 1b0b041f51..ce3b4629bd 100644 --- a/packages/core/strapi/lib/commands/actions/console/command.js +++ b/packages/core/strapi/lib/commands/actions/console/command.js @@ -1,6 +1,6 @@ 'use strict'; -const { getLocalScript } = require('../../scripts/utils/helpers'); +const { getLocalScript } = require('../../utils/helpers'); module.exports = ({ command /* , argv */ }) => { // `$ strapi console` diff --git a/packages/core/strapi/lib/commands/actions/content-types/list/command.js b/packages/core/strapi/lib/commands/actions/content-types/list/command.js new file mode 100644 index 0000000000..50ed7dec1b --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/content-types/list/command.js @@ -0,0 +1,10 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('content-types:list') + .description('List all the application content-types') + .action(getLocalScript('content-types/list')); +}; diff --git a/packages/core/strapi/lib/commands/actions/controllers/list/command.js b/packages/core/strapi/lib/commands/actions/controllers/list/command.js new file mode 100644 index 0000000000..8906e4768d --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/controllers/list/command.js @@ -0,0 +1,10 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('controllers:list') + .description('List all the application controllers') + .action(getLocalScript('controllers/list')); +}; diff --git a/packages/core/strapi/lib/commands/actions/develop copy/command.js b/packages/core/strapi/lib/commands/actions/develop copy/command.js new file mode 100644 index 0000000000..f43e077101 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/develop copy/command.js @@ -0,0 +1,16 @@ +'use strict'; + +const { loadProjectScript } = require('../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + // `$ strapi develop` + command + .command('develop') + .alias('dev') + .option('--no-build', 'Disable build') + .option('--watch-admin', 'Enable watch', false) + .option('--polling', 'Watch for file changes in network directories', false) + .option('--browser ', 'Open the browser', true) + .description('Start your Strapi application in development mode') + .action(loadProjectScript('develop')); +}; diff --git a/packages/core/strapi/lib/commands/scripts/develop.js b/packages/core/strapi/lib/commands/actions/develop/action.js similarity index 96% rename from packages/core/strapi/lib/commands/scripts/develop.js rename to packages/core/strapi/lib/commands/actions/develop/action.js index 8f83cec6f9..f49e321c45 100644 --- a/packages/core/strapi/lib/commands/scripts/develop.js +++ b/packages/core/strapi/lib/commands/actions/develop/action.js @@ -9,9 +9,9 @@ const { getOr } = require('lodash/fp'); const { joinBy } = require('@strapi/utils'); const tsUtils = require('@strapi/typescript-utils'); -const loadConfiguration = require('../../core/app-configuration'); -const strapi = require('../../index'); -const { buildTypeScript, buildAdmin } = require('../builders'); +const loadConfiguration = require('../../../core/app-configuration'); +const strapi = require('../../../index'); +const { buildTypeScript, buildAdmin } = require('../../builders'); /** * `$ strapi develop` diff --git a/packages/core/strapi/lib/commands/actions/develop/command.js b/packages/core/strapi/lib/commands/actions/develop/command.js index 28225f68fe..2658672381 100644 --- a/packages/core/strapi/lib/commands/actions/develop/command.js +++ b/packages/core/strapi/lib/commands/actions/develop/command.js @@ -1,6 +1,6 @@ 'use strict'; -const { getLocalScript } = require('../../scripts/utils/helpers'); +const { getLocalScript } = require('../../utils/helpers'); module.exports = ({ command /* , argv */ }) => { // `$ strapi develop` diff --git a/packages/core/strapi/lib/commands/actions/export/action.js b/packages/core/strapi/lib/commands/actions/export/action.js index 5f7761ac0f..015337d27c 100644 --- a/packages/core/strapi/lib/commands/actions/export/action.js +++ b/packages/core/strapi/lib/commands/actions/export/action.js @@ -24,8 +24,8 @@ const { loadersFactory, exitMessageText, abortTransfer, -} = require('../../scripts/transfer/utils'); -const { exitWith } = require('../../scripts/utils/helpers'); +} = require('../../utils/data-transfer'); +const { exitWith } = require('../../utils/helpers'); /** * @typedef ExportCommandOptions Options given to the CLI import command * diff --git a/packages/core/strapi/lib/commands/actions/export/command.js b/packages/core/strapi/lib/commands/actions/export/command.js index 045cd0ef06..09238f4618 100644 --- a/packages/core/strapi/lib/commands/actions/export/command.js +++ b/packages/core/strapi/lib/commands/actions/export/command.js @@ -6,9 +6,9 @@ const { onlyOption, throttleOption, validateExcludeOnly, -} = require('../../scripts/transfer/utils'); -const { promptEncryptionKey } = require('../../scripts/utils/commander'); -const { getLocalScript } = require('../../scripts/utils/helpers'); +} = require('../../utils/data-transfer'); +const { promptEncryptionKey } = require('../../utils/commander'); +const { getLocalScript } = require('../../utils/helpers'); module.exports = (commandContext) => { const { command } = commandContext; diff --git a/packages/core/strapi/lib/commands/actions/generate/command.js b/packages/core/strapi/lib/commands/actions/generate/command.js index a628e875b0..c926c55d28 100644 --- a/packages/core/strapi/lib/commands/actions/generate/command.js +++ b/packages/core/strapi/lib/commands/actions/generate/command.js @@ -1,6 +1,6 @@ 'use strict'; -const { assertCwdContainsStrapiProject } = require('../../scripts/utils/helpers'); +const { assertCwdContainsStrapiProject } = require('../../utils/helpers'); module.exports = ({ command, argv }) => { // $ strapi generate diff --git a/packages/core/strapi/lib/commands/actions/generate/template/command.js b/packages/core/strapi/lib/commands/actions/generate/template/command.js new file mode 100644 index 0000000000..5cf64ddc85 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/generate/template/command.js @@ -0,0 +1,11 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command }) => { + // `$ strapi generate:template ` + command + .command('templates:generate ') + .description('Generate template from Strapi project') + .action(getLocalScript('template/generate')); +}; diff --git a/packages/core/strapi/lib/commands/actions/hooks/list/command.js b/packages/core/strapi/lib/commands/actions/hooks/list/command.js new file mode 100644 index 0000000000..8be46fc8d5 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/hooks/list/command.js @@ -0,0 +1,10 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('hooks:list') + .description('List all the application hooks') + .action(getLocalScript('hooks/list')); +}; diff --git a/packages/core/strapi/lib/commands/actions/import/action.js b/packages/core/strapi/lib/commands/actions/import/action.js index 5668bf7a77..5a04fcdbcb 100644 --- a/packages/core/strapi/lib/commands/actions/import/action.js +++ b/packages/core/strapi/lib/commands/actions/import/action.js @@ -20,8 +20,8 @@ const { loadersFactory, exitMessageText, abortTransfer, -} = require('../../scripts/transfer/utils'); -const { exitWith } = require('../../scripts/utils/helpers'); +} = require('../../utils/data-transfer'); +const { exitWith } = require('../../utils/helpers'); /** * @typedef {import('@strapi/data-transfer/src/file/providers').ILocalFileSourceProviderOptions} ILocalFileSourceProviderOptions diff --git a/packages/core/strapi/lib/commands/actions/import/command.js b/packages/core/strapi/lib/commands/actions/import/command.js index 89b4badb8e..400bb95663 100644 --- a/packages/core/strapi/lib/commands/actions/import/command.js +++ b/packages/core/strapi/lib/commands/actions/import/command.js @@ -8,9 +8,9 @@ const { onlyOption, throttleOption, validateExcludeOnly, -} = require('../../scripts/transfer/utils'); -const { confirmMessage, forceOption } = require('../../scripts/utils/commander'); -const { getLocalScript, exitWith } = require('../../scripts/utils/helpers'); +} = require('../../utils/data-transfer'); +const { confirmMessage, forceOption } = require('../../utils/commander'); +const { getLocalScript, exitWith } = require('../../utils/helpers'); module.exports = (commandContext) => { const { command } = commandContext; diff --git a/packages/core/strapi/lib/commands/actions/install copy/command.js b/packages/core/strapi/lib/commands/actions/install copy/command.js new file mode 100644 index 0000000000..31bfc1eef3 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/install copy/command.js @@ -0,0 +1,11 @@ +'use strict'; + +const { getLocalScript } = require('../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + // `$ strapi install` + command + .command('install [plugins...]') + .description('Install a Strapi plugin') + .action(getLocalScript('install')); +}; diff --git a/packages/core/strapi/lib/commands/scripts/install.js b/packages/core/strapi/lib/commands/actions/install/action.js similarity index 95% rename from packages/core/strapi/lib/commands/scripts/install.js rename to packages/core/strapi/lib/commands/actions/install/action.js index b6088765a0..3a2c9444d9 100644 --- a/packages/core/strapi/lib/commands/scripts/install.js +++ b/packages/core/strapi/lib/commands/actions/install/action.js @@ -4,7 +4,7 @@ const { join } = require('path'); const { existsSync } = require('fs-extra'); const ora = require('ora'); const execa = require('execa'); -const findPackagePath = require('../../load/package-path'); +const findPackagePath = require('../../../load/package-path'); module.exports = async (plugins) => { const loader = ora(); diff --git a/packages/core/strapi/lib/commands/actions/install/command.js b/packages/core/strapi/lib/commands/actions/install/command.js index 0227fc0d76..31bfc1eef3 100644 --- a/packages/core/strapi/lib/commands/actions/install/command.js +++ b/packages/core/strapi/lib/commands/actions/install/command.js @@ -1,6 +1,6 @@ 'use strict'; -const { getLocalScript } = require('../../scripts/utils/helpers'); +const { getLocalScript } = require('../../utils/helpers'); module.exports = ({ command /* , argv */ }) => { // `$ strapi install` diff --git a/packages/core/strapi/lib/commands/actions/middlewares/list/command.js b/packages/core/strapi/lib/commands/actions/middlewares/list/command.js new file mode 100644 index 0000000000..cdf07fb153 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/middlewares/list/command.js @@ -0,0 +1,10 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('middlewares:list') + .description('List all the application middlewares') + .action(getLocalScript('middlewares/list')); +}; diff --git a/packages/core/strapi/lib/commands/actions/policies/list/command.js b/packages/core/strapi/lib/commands/actions/policies/list/command.js new file mode 100644 index 0000000000..6f8b880681 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/policies/list/command.js @@ -0,0 +1,10 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('policies:list') + .description('List all the application policies') + .action(getLocalScript('policies/list')); +}; diff --git a/packages/core/strapi/lib/commands/actions/routes/list/command.js b/packages/core/strapi/lib/commands/actions/routes/list/command.js new file mode 100644 index 0000000000..c450541286 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/routes/list/command.js @@ -0,0 +1,10 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('routes:list') + .description('List all the application routes') + .action(getLocalScript('routes/list')); +}; diff --git a/packages/core/strapi/lib/commands/actions/services/list/command.js b/packages/core/strapi/lib/commands/actions/services/list/command.js new file mode 100644 index 0000000000..41a90604a1 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/services/list/command.js @@ -0,0 +1,10 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + command + .command('services:list') + .description('List all the application services') + .action(getLocalScript('services/list')); +}; diff --git a/packages/core/strapi/lib/commands/scripts/services/list.js b/packages/core/strapi/lib/commands/actions/services/list/list.js similarity index 91% rename from packages/core/strapi/lib/commands/scripts/services/list.js rename to packages/core/strapi/lib/commands/actions/services/list/list.js index b6bfa828e6..8bb2905bbf 100644 --- a/packages/core/strapi/lib/commands/scripts/services/list.js +++ b/packages/core/strapi/lib/commands/actions/services/list/list.js @@ -3,7 +3,7 @@ const CLITable = require('cli-table3'); const chalk = require('chalk'); -const strapi = require('../../../index'); +const strapi = require('../../../../index'); module.exports = async function () { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/lib/commands/actions/start/command.js b/packages/core/strapi/lib/commands/actions/start/command.js index 5698d6af1d..4fccc3ddc3 100644 --- a/packages/core/strapi/lib/commands/actions/start/command.js +++ b/packages/core/strapi/lib/commands/actions/start/command.js @@ -1,11 +1,11 @@ 'use strict'; -const { loadProjectScript } = require('../../scripts/utils/helpers'); +const { getLocalScript } = require('../../utils/helpers'); module.exports = ({ command /* , argv */ }) => { // `$ strapi start` command .command('start') .description('Start your Strapi application') - .action(loadProjectScript('start')); + .action(getLocalScript('start')); }; diff --git a/packages/core/strapi/lib/commands/scripts/opt-out-telemetry.js b/packages/core/strapi/lib/commands/actions/telemetry/disable/action.js similarity index 97% rename from packages/core/strapi/lib/commands/scripts/opt-out-telemetry.js rename to packages/core/strapi/lib/commands/actions/telemetry/disable/action.js index a03c5a878d..26c3130834 100644 --- a/packages/core/strapi/lib/commands/scripts/opt-out-telemetry.js +++ b/packages/core/strapi/lib/commands/actions/telemetry/disable/action.js @@ -4,7 +4,7 @@ const { resolve } = require('path'); const fse = require('fs-extra'); const chalk = require('chalk'); const fetch = require('node-fetch'); -const machineID = require('../../utils/machine-id'); +const machineID = require('../../../../utils/machine-id'); const readPackageJSON = async (path) => { try { diff --git a/packages/core/strapi/lib/commands/actions/telemetry/disable/command.js b/packages/core/strapi/lib/commands/actions/telemetry/disable/command.js new file mode 100644 index 0000000000..0906dae756 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/telemetry/disable/command.js @@ -0,0 +1,11 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + // `$ strapi opt-out-telemetry` + command + .command('telemetry:disable') + .description('Disable anonymous telemetry and metadata sending to Strapi analytics') + .action(getLocalScript('telemetry/disable')); +}; diff --git a/packages/core/strapi/lib/commands/scripts/opt-in-telemetry.js b/packages/core/strapi/lib/commands/actions/telemetry/enable/action.js similarity index 97% rename from packages/core/strapi/lib/commands/scripts/opt-in-telemetry.js rename to packages/core/strapi/lib/commands/actions/telemetry/enable/action.js index 9d53479dad..685587f446 100644 --- a/packages/core/strapi/lib/commands/scripts/opt-in-telemetry.js +++ b/packages/core/strapi/lib/commands/actions/telemetry/enable/action.js @@ -5,7 +5,7 @@ const fse = require('fs-extra'); const chalk = require('chalk'); const fetch = require('node-fetch'); const { v4: uuidv4 } = require('uuid'); -const machineID = require('../../utils/machine-id'); +const machineID = require('../../../../utils/machine-id'); const readPackageJSON = async (path) => { try { diff --git a/packages/core/strapi/lib/commands/actions/telemetry/enable/command.js b/packages/core/strapi/lib/commands/actions/telemetry/enable/command.js new file mode 100644 index 0000000000..5183c3fb26 --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/telemetry/enable/command.js @@ -0,0 +1,11 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + // `$ strapi opt-in-telemetry` + command + .command('telemetry:enable') + .description('Enable anonymous telemetry and metadata sending to Strapi analytics') + .action(getLocalScript('telemetry/enable')); +}; diff --git a/packages/core/strapi/lib/commands/actions/templates/generate/command.js b/packages/core/strapi/lib/commands/actions/templates/generate/command.js index e69de29bb2..2c720de64a 100644 --- a/packages/core/strapi/lib/commands/actions/templates/generate/command.js +++ b/packages/core/strapi/lib/commands/actions/templates/generate/command.js @@ -0,0 +1,11 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + // `$ strapi generate:template ` + command + .command('templates:generate ') + .description('Generate template from Strapi project') + .action(getLocalScript('templates/generate')); +}; diff --git a/packages/core/strapi/lib/commands/actions/transfer/action.js b/packages/core/strapi/lib/commands/actions/transfer/action.js index a3e0e48e55..235c2a589b 100644 --- a/packages/core/strapi/lib/commands/actions/transfer/action.js +++ b/packages/core/strapi/lib/commands/actions/transfer/action.js @@ -21,8 +21,8 @@ const { loadersFactory, exitMessageText, abortTransfer, -} = require('../../scripts/transfer/utils'); -const { exitWith } = require('../../scripts/utils/helpers'); +} = require('../../utils/data-transfer'); +const { exitWith } = require('../../utils/helpers'); /** * @typedef TransferCommandOptions Options given to the CLI transfer command diff --git a/packages/core/strapi/lib/commands/actions/transfer/command.js b/packages/core/strapi/lib/commands/actions/transfer/command.js index 1b673fcd2a..59afc7f4c3 100644 --- a/packages/core/strapi/lib/commands/actions/transfer/command.js +++ b/packages/core/strapi/lib/commands/actions/transfer/command.js @@ -2,19 +2,19 @@ const inquirer = require('inquirer'); const { Option } = require('commander'); -const { confirmMessage, forceOption, parseURL } = require('../../scripts/utils/commander'); +const { confirmMessage, forceOption, parseURL } = require('../../utils/commander'); const { getLocalScript, exitWith, assertUrlHasProtocol, ifOptions, -} = require('../../scripts/utils/helpers'); +} = require('../../utils/helpers'); const { excludeOption, onlyOption, throttleOption, validateExcludeOnly, -} = require('../../scripts/transfer/utils'); +} = require('../../utils/data-transfer'); module.exports = ({ command /* , argv */ }) => { // `$ strapi transfer` diff --git a/packages/core/strapi/lib/commands/scripts/ts/generate-types.js b/packages/core/strapi/lib/commands/actions/ts/generate-types/action.js similarity index 92% rename from packages/core/strapi/lib/commands/scripts/ts/generate-types.js rename to packages/core/strapi/lib/commands/actions/ts/generate-types/action.js index 09c678e2e1..49839c0230 100644 --- a/packages/core/strapi/lib/commands/scripts/ts/generate-types.js +++ b/packages/core/strapi/lib/commands/actions/ts/generate-types/action.js @@ -2,7 +2,7 @@ const tsUtils = require('@strapi/typescript-utils'); -const strapi = require('../../index'); +const strapi = require('../../../../index'); module.exports = async function ({ outDir, file, verbose, silent }) { if (verbose && silent) { diff --git a/packages/core/strapi/lib/commands/actions/ts/generate-types/command.js b/packages/core/strapi/lib/commands/actions/ts/generate-types/command.js new file mode 100644 index 0000000000..9b558e96ab --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/ts/generate-types/command.js @@ -0,0 +1,18 @@ +'use strict'; + +const { getLocalScript } = require('../../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + // `$ strapi ts:generate-types` + command + .command('ts:generate-types') + .description(`Generate TypeScript typings for your schemas`) + .option( + '-o, --out-dir ', + 'Specify a relative directory in which the schemas definitions will be generated' + ) + .option('-f, --file ', 'Specify a filename to store the schemas definitions') + .option('--verbose', `Display more information about the types generation`, false) + .option('-s, --silent', `Run the generation silently, without any output`, false) + .action(getLocalScript('ts/generate-types')); +}; diff --git a/packages/core/strapi/lib/commands/actions/uninstall copy/command.js b/packages/core/strapi/lib/commands/actions/uninstall copy/command.js new file mode 100644 index 0000000000..7c0df35adb --- /dev/null +++ b/packages/core/strapi/lib/commands/actions/uninstall copy/command.js @@ -0,0 +1,12 @@ +'use strict'; + +const { getLocalScript } = require('../../utils/helpers'); + +module.exports = ({ command /* , argv */ }) => { + // `$ strapi uninstall` + command + .command('uninstall [plugins...]') + .description('Uninstall a Strapi plugin') + .option('-d, --delete-files', 'Delete files', false) + .action(getLocalScript('uninstall')); +}; diff --git a/packages/core/strapi/lib/commands/scripts/uninstall.js b/packages/core/strapi/lib/commands/actions/uninstall/action.js similarity index 96% rename from packages/core/strapi/lib/commands/scripts/uninstall.js rename to packages/core/strapi/lib/commands/actions/uninstall/action.js index 0acb1735f4..d8a395bb6a 100644 --- a/packages/core/strapi/lib/commands/scripts/uninstall.js +++ b/packages/core/strapi/lib/commands/actions/uninstall/action.js @@ -5,7 +5,7 @@ const { existsSync, removeSync } = require('fs-extra'); const ora = require('ora'); const execa = require('execa'); const inquirer = require('inquirer'); -const findPackagePath = require('../../load/package-path'); +const findPackagePath = require('../../../load/package-path'); module.exports = async (plugins, { deleteFiles }) => { const answers = await inquirer.prompt([ diff --git a/packages/core/strapi/lib/commands/actions/uninstall/command.js b/packages/core/strapi/lib/commands/actions/uninstall/command.js index a8360e3170..7c0df35adb 100644 --- a/packages/core/strapi/lib/commands/actions/uninstall/command.js +++ b/packages/core/strapi/lib/commands/actions/uninstall/command.js @@ -1,6 +1,6 @@ 'use strict'; -const { getLocalScript } = require('../../scripts/utils/helpers'); +const { getLocalScript } = require('../../utils/helpers'); module.exports = ({ command /* , argv */ }) => { // `$ strapi uninstall` diff --git a/packages/core/strapi/lib/commands/scripts/watchAdmin.js b/packages/core/strapi/lib/commands/actions/watch-admin/action.js similarity index 83% rename from packages/core/strapi/lib/commands/scripts/watchAdmin.js rename to packages/core/strapi/lib/commands/actions/watch-admin/action.js index 5b881e55f3..35f9f14f6b 100644 --- a/packages/core/strapi/lib/commands/scripts/watchAdmin.js +++ b/packages/core/strapi/lib/commands/actions/watch-admin/action.js @@ -3,9 +3,9 @@ const strapiAdmin = require('@strapi/admin'); const { getConfigUrls, getAbsoluteServerUrl } = require('@strapi/utils'); -const getEnabledPlugins = require('../../core/loaders/plugins/get-enabled-plugins'); -const addSlash = require('../../utils/addSlash'); -const strapi = require('../../index'); +const getEnabledPlugins = require('../../../core/loaders/plugins/get-enabled-plugins'); +const addSlash = require('../../../utils/addSlash'); +const strapi = require('../../../index'); module.exports = async function ({ browser }) { const appContext = await strapi.compile(); diff --git a/packages/core/strapi/lib/commands/actions/watch-admin/command.js b/packages/core/strapi/lib/commands/actions/watch-admin/command.js index 273bcba317..896f95f69c 100644 --- a/packages/core/strapi/lib/commands/actions/watch-admin/command.js +++ b/packages/core/strapi/lib/commands/actions/watch-admin/command.js @@ -1,6 +1,6 @@ 'use strict'; -const { getLocalScript } = require('../../scripts/utils/helpers'); +const { getLocalScript } = require('../../utils/helpers'); module.exports = ({ command /* , argv */ }) => { // `$ strapi watch-admin` @@ -8,5 +8,5 @@ module.exports = ({ command /* , argv */ }) => { .command('watch-admin') .option('--browser ', 'Open the browser', true) .description('Start the admin development server') - .action(getLocalScript('watchAdmin')); + .action(getLocalScript('watch-admin')); }; diff --git a/packages/core/strapi/lib/commands/index.js b/packages/core/strapi/lib/commands/index.js index 2c87e1a257..1454c82005 100644 --- a/packages/core/strapi/lib/commands/index.js +++ b/packages/core/strapi/lib/commands/index.js @@ -2,7 +2,37 @@ const { Command } = require('commander'); -const availableCommands = ['version', 'console', 'new', 'export', 'import']; +const availableCommands = [ + 'admin/create-user', + 'admin/reset-user-password', + 'build-action', // TODO: this should be 'build' but that is ignored + 'configuration/dump', + 'configuration/restore', + 'console', + 'content-types/list', + 'controllers/list', + 'develop', + 'export', + 'generate', + 'generate/template', + 'hooks/list', + 'import', + 'install', + 'middlewares/list', + 'new', + 'policies/list', + 'routes/list', + 'services/list', + 'start', + 'telemetry/disable', + 'telemetry/enable', + 'templates/generate', + 'transfer', + 'ts/generate-types', + 'uninstall', + 'version', + 'watch-admin', +]; const buildStrapiCommand = (argv, command = new Command()) => { // Initial program setup @@ -20,112 +50,6 @@ const buildStrapiCommand = (argv, command = new Command()) => { } }); - /* - - - // `$ strapi generate:template ` - command - .command('templates:generate ') - .description('Generate template from Strapi project') - .action(getLocalScript('generate-template')); - - - command - .command('configuration:dump') - .alias('config:dump') - .description('Dump configurations of your application') - .option('-f, --file ', 'Output file, default output is stdout') - .option('-p, --pretty', 'Format the output JSON with indentation and line breaks', false) - .action(getLocalScript('configurationDump')); - - command - .command('configuration:restore') - .alias('config:restore') - .description('Restore configurations of your application') - .option('-f, --file ', 'Input file, default input is stdin') - .option('-s, --strategy ', 'Strategy name, one of: "replace", "merge", "keep"') - .action(getLocalScript('configurationRestore')); - - // Admin - command - .command('admin:create-user') - .alias('admin:create') - .description('Create a new admin') - .option('-e, --email ', 'Email of the new admin') - .option('-p, --password ', 'Password of the new admin') - .option('-f, --firstname ', 'First name of the new admin') - .option('-l, --lastname ', 'Last name of the new admin') - .action(getLocalScript('admin-create')); - - command - .command('admin:reset-user-password') - .alias('admin:reset-password') - .description("Reset an admin user's password") - .option('-e, --email ', 'The user email') - .option('-p, --password ', 'New password for the user') - .action(getLocalScript('admin-reset')); - - command - .command('routes:list') - .description('List all the application routes') - .action(getLocalScript('routes/list')); - - command - .command('middlewares:list') - .description('List all the application middlewares') - .action(getLocalScript('middlewares/list')); - - command - .command('policies:list') - .description('List all the application policies') - .action(getLocalScript('policies/list')); - - command - .command('content-types:list') - .description('List all the application content-types') - .action(getLocalScript('content-types/list')); - - command - .command('hooks:list') - .description('List all the application hooks') - .action(getLocalScript('hooks/list')); - - command - .command('services:list') - .description('List all the application services') - .action(getLocalScript('services/list')); - - command - .command('controllers:list') - .description('List all the application controllers') - .action(getLocalScript('controllers/list')); - - // `$ strapi opt-out-telemetry` - command - .command('telemetry:disable') - .description('Disable anonymous telemetry and metadata sending to Strapi analytics') - .action(getLocalScript('opt-out-telemetry')); - - // `$ strapi opt-in-telemetry` - command - .command('telemetry:enable') - .description('Enable anonymous telemetry and metadata sending to Strapi analytics') - .action(getLocalScript('opt-in-telemetry')); - - command - .command('ts:generate-types') - .description(`Generate TypeScript typings for your schemas`) - .option( - '-o, --out-dir ', - 'Specify a relative directory in which the schemas definitions will be generated' - ) - .option('-f, --file ', 'Specify a filename to store the schemas definitions') - .option('--verbose', `Display more information about the types generation`, false) - .option('-s, --silent', `Run the generation silently, without any output`, false) - .action(getLocalScript('ts/generate-types')); - -*/ - return command; }; diff --git a/packages/core/strapi/lib/commands/scripts/utils/commander.js b/packages/core/strapi/lib/commands/utils/commander.js similarity index 100% rename from packages/core/strapi/lib/commands/scripts/utils/commander.js rename to packages/core/strapi/lib/commands/utils/commander.js diff --git a/packages/core/strapi/lib/commands/scripts/transfer/utils.js b/packages/core/strapi/lib/commands/utils/data-transfer.js similarity index 97% rename from packages/core/strapi/lib/commands/scripts/transfer/utils.js rename to packages/core/strapi/lib/commands/utils/data-transfer.js index d47b71ad28..8a44c31d9f 100644 --- a/packages/core/strapi/lib/commands/scripts/transfer/utils.js +++ b/packages/core/strapi/lib/commands/utils/data-transfer.js @@ -12,9 +12,9 @@ const { createLogger, } = require('@strapi/logger'); const ora = require('ora'); -const { readableBytes, exitWith } = require('../utils/helpers'); -const strapi = require('../../../index'); -const { getParseListWithChoices, parseInteger } = require('../utils/commander'); +const { readableBytes, exitWith } = require('./helpers'); +const strapi = require('../../index'); +const { getParseListWithChoices, parseInteger } = require('./commander'); const exitMessageText = (process, error = false) => { const processCapitalized = process[0].toUpperCase() + process.slice(1); diff --git a/packages/core/strapi/lib/commands/scripts/utils/helpers.js b/packages/core/strapi/lib/commands/utils/helpers.js similarity index 99% rename from packages/core/strapi/lib/commands/scripts/utils/helpers.js rename to packages/core/strapi/lib/commands/utils/helpers.js index 7bdfbc0a85..c106fccf7b 100644 --- a/packages/core/strapi/lib/commands/scripts/utils/helpers.js +++ b/packages/core/strapi/lib/commands/utils/helpers.js @@ -133,7 +133,7 @@ const getLocalScript = (name) => (...args) => { assertCwdContainsStrapiProject(name); - console.log('getLocalScript', name); + const cmdPath = resolveCwd.silent(`@strapi/strapi/lib/commands/actions/${name}/action`); if (!cmdPath) { console.log(