Add --dry option

This commit is contained in:
loicsaintroch 2015-12-02 14:57:00 +01:00
parent 4c5d7377cd
commit 71cc569e78
6 changed files with 41 additions and 3 deletions

View File

@ -44,6 +44,22 @@ You now are able to use the Strapi CLI. Simply create your first application and
$ strapi new <appName>
```
Note that you can generate a dry application using the `dry` option:
```bash
$ strapi new <appName> --dry
```
This will generate a Strapi application without:
- the built-in `user`, `email` and `upload` APIs,
- the `grant` hook,
- the open-source admin panel,
- the Waterline ORM (`waterline` and `blueprints` hooks disabled),
- the Strapi Studio connection (`studio` hook disabled).
This feature allows you to only use Strapi for your HTTP server structure if you want to.
### Start your application
```bash

View File

@ -52,6 +52,13 @@ module.exports = function () {
strapiPackageJSON: packageJSON
};
// Save the `dry` option inside the scope.
if (scope.args[1] && scope.args[1].dry) {
scope.dry = true;
} else {
scope.dry = false;
}
// Pass the original CLI arguments down to the generator
// (but first, remove commander's extra argument)
cliArguments.pop();

View File

@ -44,6 +44,7 @@ cmd = program.command('new');
cmd.unknownOption = NOOP;
cmd.description('create a new application ');
cmd.action(require('./strapi-new'));
cmd.option('-d, --dry', 'naked Strapi application');
// `$ strapi start`
cmd = program.command('start');

View File

@ -116,8 +116,10 @@ module.exports = function (strapi) {
// (aiming to not have issue with adapters when rebuilding the dictionary).
// It's kind of messy, for now, but it works fine. If someone has a better
// solution we'd be glad to accept a Pull Request.
const ormConfig = JSON.parse(fs.readFileSync(path.resolve(strapi.config.appPath, strapi.config.paths.config, 'environments', strapi.config.environment, 'databases.json')));
strapi.config.orm = ormConfig.orm;
if (!strapi.config.dry) {
const ormConfig = JSON.parse(fs.readFileSync(path.resolve(strapi.config.appPath, strapi.config.paths.config, 'environments', strapi.config.environment, 'databases.json')));
strapi.config.orm = ormConfig.orm;
}
// Save different environments inside an array because we need it in the Strapi Studio.
strapi.config.environments = fs.readdirSync(path.resolve(strapi.config.appPath, strapi.config.paths.config, 'environments'));

View File

@ -64,6 +64,9 @@ module.exports = function (strapi) {
workers: os.cpus().length
},
// Application is not `dry` by default.
dry: false,
// Default paths.
paths: {
tmp: '.tmp',

View File

@ -37,7 +37,16 @@ module.exports = function (strapi) {
delete hooks.studio;
}
// Handle folder-defined modules (default to `lib/index.js`)
// Remove undesired hooks when this is a `dry` application.
if (strapi.config.dry) {
delete hooks.blueprints;
delete hooks.dashboard;
delete hooks.grant;
delete hooks.studio;
delete hooks.waterline;
}
// Handle folder-defined modules (default to `./lib/index.js`)
// Since a hook definition must be a function.
if (_.isObject(hookPrototype) && !_.isArray(hookPrototype) && !_.isFunction(hookPrototype)) {
hookPrototype = hookPrototype.index;