mirror of
https://github.com/strapi/strapi.git
synced 2025-09-27 09:25:46 +00:00
188 lines
5.0 KiB
JavaScript
Executable File
188 lines
5.0 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
|
|
'use strict';
|
|
|
|
/**
|
|
* Module dependencies
|
|
*/
|
|
|
|
// Public node modules.
|
|
const _ = require('lodash');
|
|
|
|
// Strapi utilities.
|
|
const program = require('strapi-utils').commander;
|
|
|
|
// Local Strapi dependencies.
|
|
const packageJSON = require('../package.json');
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
const getScript = name => (...args) =>
|
|
require(`../lib/commands/${name}`)(...args);
|
|
|
|
/**
|
|
* Normalize version argument
|
|
*
|
|
* `$ strapi -v`
|
|
* `$ strapi -V`
|
|
* `$ strapi --version`
|
|
* `$ strapi version`
|
|
*/
|
|
|
|
program.allowUnknownOption(true);
|
|
|
|
// Expose version.
|
|
program.version(packageJSON.version, '-v, --version');
|
|
|
|
// Make `-v` option case-insensitive.
|
|
process.argv = _.map(process.argv, arg => {
|
|
return arg === '-V' ? '-v' : arg;
|
|
});
|
|
|
|
// `$ strapi version` (--version synonym)
|
|
program
|
|
.command('version')
|
|
.description('output your version of Strapi')
|
|
.action(() => {
|
|
console.log(packageJSON.version);
|
|
});
|
|
|
|
// `$ strapi console`
|
|
program
|
|
.command('console')
|
|
.description('open the Strapi framework console')
|
|
.action(getScript('console'));
|
|
|
|
// `$ strapi new`
|
|
program
|
|
.command('new')
|
|
.option('--debug', 'Display database connection error')
|
|
.option('--quickstart', 'Quickstart app creation')
|
|
.option('--dbclient <dbclient>', 'Database client')
|
|
.option('--dbhost <dbhost>', 'Database host')
|
|
.option('--dbsrv <dbsrv>', 'Database srv')
|
|
.option('--dbport <dbport>', 'Database port')
|
|
.option('--dbname <dbname>', 'Database name')
|
|
.option('--dbusername <dbusername>', 'Database username')
|
|
.option('--dbpassword <dbpassword>', 'Database password')
|
|
.option('--dbssl <dbssl>', 'Database SSL')
|
|
.option('--dbauth <dbauth>', 'Authentication Database')
|
|
.option('--dbfile <dbfile>', 'Database file path for sqlite')
|
|
.option('--dbforce', 'Overwrite database content if any')
|
|
.description('create a new application')
|
|
.action(getScript('new'));
|
|
|
|
// `$ strapi start`
|
|
program
|
|
.command('start')
|
|
.description('Start your Strapi application')
|
|
.action(getScript('start'));
|
|
|
|
// `$ strapi dev`
|
|
program
|
|
.command('dev')
|
|
.option('--no-build', 'Disable build', false)
|
|
.description('Start your Strapi application in dev mode')
|
|
.action(getScript('dev'));
|
|
|
|
// `$ strapi generate:api`
|
|
program
|
|
.command('generate:api <id> [attributes...]')
|
|
.option('-t, --tpl <template>', 'template name')
|
|
.option('-a, --api <api>', 'API name to generate a sub API')
|
|
.option('-p, --plugin <plugin>', 'plugin name to generate a sub API')
|
|
.description('generate a basic API')
|
|
.action((id, attributes, cliArguments) => {
|
|
cliArguments.attributes = attributes;
|
|
getScript('generate')(id, cliArguments);
|
|
});
|
|
|
|
// `$ strapi generate:controller`
|
|
program
|
|
.command('generate:controller <id>')
|
|
.option('-a, --api <api>', 'API name to generate a sub API')
|
|
.option('-p, --plugin <api>', 'plugin name')
|
|
.option('-t, --tpl <template>', 'template name')
|
|
.description('generate a controller for an API')
|
|
.action(getScript('generate'));
|
|
|
|
// `$ strapi generate:model`
|
|
program
|
|
.command('generate:model <id> [attributes...]')
|
|
.option('-a, --api <api>', 'API name to generate a sub API')
|
|
.option('-p, --plugin <api>', 'plugin name')
|
|
.option('-t, --tpl <template>', 'template name')
|
|
.description('generate a model for an API')
|
|
.action((id, attributes, cliArguments) => {
|
|
cliArguments.attributes = attributes;
|
|
getScript('generate')(id, cliArguments);
|
|
});
|
|
|
|
// `$ strapi generate:policy`
|
|
program
|
|
.command('generate:policy <id>')
|
|
.option('-a, --api <api>', 'API name')
|
|
.option('-p, --plugin <api>', 'plugin name')
|
|
.description('generate a policy for an API')
|
|
.action(getScript('generate'));
|
|
|
|
// `$ strapi generate:service`
|
|
program
|
|
.command('generate:service <id>')
|
|
.option('-a, --api <api>', 'API name')
|
|
.option('-p, --plugin <api>', 'plugin name')
|
|
.option('-t, --tpl <template>', 'template name')
|
|
.description('generate a service for an API')
|
|
.action(getScript('generate'));
|
|
|
|
// `$ strapi generate:plugin`
|
|
program
|
|
.command('generate:plugin <id>')
|
|
.option('-n, --name <name>', 'Plugin name')
|
|
.description('generate a basic plugin')
|
|
.action(getScript('generate'));
|
|
|
|
program
|
|
.command('build')
|
|
.description('Builds the strapi admin app')
|
|
.action(getScript('build'));
|
|
|
|
// `$ strapi install`
|
|
program
|
|
.command('install [plugins...]')
|
|
.option('-d, --dev', 'Development mode')
|
|
.description('install a Strapi plugin')
|
|
.action(getScript('install'));
|
|
|
|
// `$ strapi uninstall`
|
|
program
|
|
.command('uninstall [plugins...]')
|
|
.description('uninstall a Strapi plugin')
|
|
.action(getScript('uninstall'));
|
|
|
|
/**
|
|
* Normalize help argument
|
|
*/
|
|
|
|
// `$ strapi help` (--help synonym)
|
|
program
|
|
.command('help')
|
|
.description('output the help')
|
|
.action(program.usageMinusWildcard);
|
|
|
|
// `$ strapi <unrecognized_cmd>`
|
|
// Mask the '*' in `help`.
|
|
program.command('*').action(program.usageMinusWildcard);
|
|
|
|
// Don't balk at unknown options.
|
|
|
|
/**
|
|
* `$ strapi`
|
|
*/
|
|
|
|
program.parse(process.argv);
|
|
const NO_COMMAND_SPECIFIED = program.args.length === 0;
|
|
if (NO_COMMAND_SPECIFIED) {
|
|
program.usageMinusWildcard();
|
|
}
|