diff --git a/README.md b/README.md index b5234118f7..ae38024059 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,22 @@ You now are able to use the Strapi CLI. Simply create your first application and $ strapi new ``` +Note that you can generate a dry application using the `dry` option: + +```bash +$ strapi new --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 diff --git a/bin/strapi-new.js b/bin/strapi-new.js index dbb7f1fc7c..71d86a997d 100755 --- a/bin/strapi-new.js +++ b/bin/strapi-new.js @@ -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(); diff --git a/bin/strapi.js b/bin/strapi.js index 030af9ffbc..e07bddfdf1 100755 --- a/bin/strapi.js +++ b/bin/strapi.js @@ -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'); diff --git a/lib/Strapi.js b/lib/Strapi.js index ffef8233d9..339f5a63d8 100755 --- a/lib/Strapi.js +++ b/lib/Strapi.js @@ -36,6 +36,17 @@ function Strapi() { // Mixin support for `Strapi.prototype.after()`. mixinAfter(this); + // Bind `this` context for all `Strapi.prototype.*` methods. + this.load = this.load.bind(this); + this.start = this.start.bind(this); + this.stop = this.stop.bind(this); + this.restart = this.restart.bind(this); + this.initialize = this.initialize.bind(this); + this.exposeGlobals = this.exposeGlobals.bind(this); + this.runBootstrap = this.runBootstrap.bind(this); + this.isLocalStrapiValid = this.isLocalStrapiValid.bind(this); + this.isStrapiAppSync = this.isStrapiAppSync.bind(this); + // Expose `koa`. this.server = require('koa'); this.app = require('koa')(); diff --git a/lib/configuration/hooks/_config/index.js b/lib/configuration/hooks/_config/index.js index 1e77f79b6a..49306cfc61 100644 --- a/lib/configuration/hooks/_config/index.js +++ b/lib/configuration/hooks/_config/index.js @@ -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')); diff --git a/lib/configuration/index.js b/lib/configuration/index.js index e2fac457ef..a47534e0c6 100755 --- a/lib/configuration/index.js +++ b/lib/configuration/index.js @@ -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', diff --git a/lib/private/loadHooks.js b/lib/private/loadHooks.js index 4aded3db6e..5e81c2a97e 100755 --- a/lib/private/loadHooks.js +++ b/lib/private/loadHooks.js @@ -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; diff --git a/lib/server.js b/lib/server.js index 258136d2be..fe3c7dc8bb 100755 --- a/lib/server.js +++ b/lib/server.js @@ -12,6 +12,13 @@ const Strapi = require('./Strapi'); * (maintains backwards compatibility with constructor usage). */ -module.exports = function () { +module.exports = strapiFactory; + +function strapiFactory() { return new Strapi(); -}; +} + +// Backwards compatibility for Strapi singleton usage. +const singleton = strapiFactory(); +strapiFactory.isLocalStrapiValid = singleton.isLocalStrapiValid.bind(singleton); +strapiFactory.isStrapiAppSync = singleton.isStrapiAppSync.bind(singleton);