mirror of
https://github.com/strapi/strapi.git
synced 2025-12-27 23:24:03 +00:00
Load local commands when necessary with strapi cli
This commit is contained in:
parent
8ea78aadcd
commit
de253163f5
@ -351,6 +351,8 @@ type UsersPermissionsRole {
|
||||
|
||||
type UsersPermissionsUser {
|
||||
id: ID!
|
||||
created_at: DateTime!
|
||||
updated_at: DateTime!
|
||||
username: String!
|
||||
email: String!
|
||||
provider: String
|
||||
|
||||
@ -11,14 +11,23 @@ const _ = require('lodash');
|
||||
|
||||
// Strapi utilities.
|
||||
const program = require('strapi-utils').commander;
|
||||
const resolveCwd = require('resolve-cwd');
|
||||
|
||||
// Local Strapi dependencies.
|
||||
const packageJSON = require('../package.json');
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
const getScript = name => (...args) =>
|
||||
require(`../lib/commands/${name}`)(...args);
|
||||
const getLocalScript = name => (...args) => {
|
||||
const cmdPath = resolveCwd.silent(`strapi/lib/commands/${name}`);
|
||||
if (!cmdPath) {
|
||||
console.log(
|
||||
`> Error loading the local ${name} command. Strapi might not be installed in your "node_modules". You may need to run "npm install"`
|
||||
);
|
||||
}
|
||||
|
||||
return require(cmdPath)(...args);
|
||||
};
|
||||
|
||||
/**
|
||||
* Normalize version argument
|
||||
@ -51,7 +60,7 @@ program
|
||||
program
|
||||
.command('console')
|
||||
.description('open the Strapi framework console')
|
||||
.action(getScript('console'));
|
||||
.action(getLocalScript('console'));
|
||||
|
||||
// `$ strapi new`
|
||||
program
|
||||
@ -70,20 +79,20 @@ program
|
||||
.option('--dbfile <dbfile>', 'Database file path for sqlite')
|
||||
.option('--dbforce', 'Overwrite database content if any')
|
||||
.description('create a new application')
|
||||
.action(getScript('new'));
|
||||
.action(require('../lib/commands/new'));
|
||||
|
||||
// `$ strapi start`
|
||||
program
|
||||
.command('start')
|
||||
.description('Start your Strapi application')
|
||||
.action(getScript('start'));
|
||||
.action(getLocalScript('start'));
|
||||
|
||||
// `$ strapi dev`
|
||||
program
|
||||
.command('dev')
|
||||
.option('--no-build', 'Disable build', false)
|
||||
.description('Start your Strapi application in dev mode')
|
||||
.action(getScript('dev'));
|
||||
.action(getLocalScript('dev'));
|
||||
|
||||
// `$ strapi generate:api`
|
||||
program
|
||||
@ -94,7 +103,7 @@ program
|
||||
.description('generate a basic API')
|
||||
.action((id, attributes, cliArguments) => {
|
||||
cliArguments.attributes = attributes;
|
||||
getScript('generate')(id, cliArguments);
|
||||
getLocalScript('generate')(id, cliArguments);
|
||||
});
|
||||
|
||||
// `$ strapi generate:controller`
|
||||
@ -104,7 +113,7 @@ program
|
||||
.option('-p, --plugin <api>', 'plugin name')
|
||||
.option('-t, --tpl <template>', 'template name')
|
||||
.description('generate a controller for an API')
|
||||
.action(getScript('generate'));
|
||||
.action(getLocalScript('generate'));
|
||||
|
||||
// `$ strapi generate:model`
|
||||
program
|
||||
@ -115,7 +124,7 @@ program
|
||||
.description('generate a model for an API')
|
||||
.action((id, attributes, cliArguments) => {
|
||||
cliArguments.attributes = attributes;
|
||||
getScript('generate')(id, cliArguments);
|
||||
getLocalScript('generate')(id, cliArguments);
|
||||
});
|
||||
|
||||
// `$ strapi generate:policy`
|
||||
@ -124,7 +133,7 @@ program
|
||||
.option('-a, --api <api>', 'API name')
|
||||
.option('-p, --plugin <api>', 'plugin name')
|
||||
.description('generate a policy for an API')
|
||||
.action(getScript('generate'));
|
||||
.action(getLocalScript('generate'));
|
||||
|
||||
// `$ strapi generate:service`
|
||||
program
|
||||
@ -133,32 +142,32 @@ program
|
||||
.option('-p, --plugin <api>', 'plugin name')
|
||||
.option('-t, --tpl <template>', 'template name')
|
||||
.description('generate a service for an API')
|
||||
.action(getScript('generate'));
|
||||
.action(getLocalScript('generate'));
|
||||
|
||||
// `$ strapi generate:plugin`
|
||||
program
|
||||
.command('generate:plugin <id>')
|
||||
.option('-n, --name <name>', 'Plugin name')
|
||||
.description('generate a basic plugin')
|
||||
.action(getScript('generate'));
|
||||
.action(getLocalScript('generate'));
|
||||
|
||||
program
|
||||
.command('build')
|
||||
.description('Builds the strapi admin app')
|
||||
.action(getScript('build'));
|
||||
.action(getLocalScript('build'));
|
||||
|
||||
// `$ strapi install`
|
||||
program
|
||||
.command('install [plugins...]')
|
||||
.option('-d, --dev', 'Development mode')
|
||||
.description('install a Strapi plugin')
|
||||
.action(getScript('install'));
|
||||
.action(getLocalScript('install'));
|
||||
|
||||
// `$ strapi uninstall`
|
||||
program
|
||||
.command('uninstall [plugins...]')
|
||||
.description('uninstall a Strapi plugin')
|
||||
.action(getScript('uninstall'));
|
||||
.action(getLocalScript('uninstall'));
|
||||
|
||||
/**
|
||||
* Normalize help argument
|
||||
|
||||
@ -60,6 +60,7 @@
|
||||
"node-schedule": "^1.2.0",
|
||||
"opn": "^5.3.0",
|
||||
"ora": "^3.0.0",
|
||||
"resolve-cwd": "^3.0.0",
|
||||
"rimraf": "^2.6.2",
|
||||
"shelljs": "^0.8.3",
|
||||
"strapi-generate": "3.0.0-alpha.26.2",
|
||||
|
||||
12
yarn.lock
12
yarn.lock
@ -14891,6 +14891,13 @@ resolve-cwd@^2.0.0:
|
||||
dependencies:
|
||||
resolve-from "^3.0.0"
|
||||
|
||||
resolve-cwd@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve-cwd/-/resolve-cwd-3.0.0.tgz#0f0075f1bb2544766cf73ba6a6e2adfebcb13f2d"
|
||||
integrity sha512-OrZaX2Mb+rJCpH/6CpSqt9xFVpN++x01XnN2ie9g6P5/3xelLAkXWVADpdz1IHD/KFfEXyE6V0U01OQ3UO2rEg==
|
||||
dependencies:
|
||||
resolve-from "^5.0.0"
|
||||
|
||||
resolve-dir@^1.0.0, resolve-dir@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/resolve-dir/-/resolve-dir-1.0.1.tgz#79a40644c362be82f26effe739c9bb5382046f43"
|
||||
@ -14919,6 +14926,11 @@ resolve-from@^4.0.0:
|
||||
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
|
||||
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
|
||||
|
||||
resolve-from@^5.0.0:
|
||||
version "5.0.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-5.0.0.tgz#c35225843df8f776df21c57557bc087e9dfdfc69"
|
||||
integrity sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==
|
||||
|
||||
resolve-path@^1.4.0:
|
||||
version "1.4.0"
|
||||
resolved "https://registry.yarnpkg.com/resolve-path/-/resolve-path-1.4.0.tgz#c4bda9f5efb2fce65247873ab36bb4d834fe16f7"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user