Merge branch 'master' of github.com:wistityhq/strapi into feature/admin

This commit is contained in:
Pierre BURGY 2015-12-02 16:57:19 +01:00
commit fbc398e780
12 changed files with 84 additions and 65 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

@ -10,7 +10,6 @@ const events = require('events');
const util = require('util');
// Public node modules.
const _ = require('lodash');
const winston = require('winston');
// Local dependencies.
@ -38,15 +37,15 @@ function Strapi() {
mixinAfter(this);
// Bind `this` context for all `Strapi.prototype.*` methods.
this.load = _.bind(this.load, this);
this.start = _.bind(this.start, this);
this.stop = _.bind(this.stop, this);
this.restart = _.bind(this.restart, this);
this.initialize = _.bind(this.initialize, this);
this.exposeGlobals = _.bind(this.exposeGlobals, this);
this.runBootstrap = _.bind(this.runBootstrap, this);
this.isLocalStrapiValid = _.bind(this.isLocalStrapiValid, this);
this.isStrapiAppSync = _.bind(this.isStrapiAppSync, this);
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');

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

@ -17,7 +17,7 @@ const __initializeHooks = require('./private/loadHooks');
* Load the Strapi instance
*/
module.exports = function (strapi) {
module.exports = strapi => {
const Configuration = __Configuration(strapi);
const initializeHooks = __initializeHooks(strapi);
@ -80,13 +80,9 @@ module.exports = function (strapi) {
}
async.series([
function (cb) {
loadHookDefinitions(strapi.hooks, cb);
},
function (cb) {
initializeHooks(strapi.hooks, cb);
}
], function (err) {
cb => loadHookDefinitions(strapi.hooks, cb),
cb => initializeHooks(strapi.hooks, cb)
], err => {
if (err) {
return cb(err);
}

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;

View File

@ -16,81 +16,73 @@ const async = require('async');
* (useful for the Studio)
*/
module.exports = function (cb) {
const self = this;
module.exports = cb => {
console.log();
// Update the Strapi status (might be used
// by the core or some hooks).
self.reloading = true;
this.reloading = true;
// Async module loader to rebuild a
// dictionary of the application.
async.auto({
// Rebuild the dictionaries.
dictionaries: function (cb) {
self.on('hook:_config:reloaded', function () {
self.on('hook:_api:reloaded', function () {
cb();
});
self.hooks._api.reload();
dictionaries: cb => {
this.on('hook:_config:reloaded', () => {
this.on('hook:_api:reloaded', () => cb());
this.hooks._api.reload();
});
self.hooks._config.reload();
this.hooks._config.reload();
}
},
// Callback.
function (err) {
err => {
// Just in case there is an error.
if (err) {
self.log.error('Impossible to reload the server');
self.log.error('Please restart the server manually');
self.stop();
this.log.error('Impossible to reload the server');
this.log.error('Please restart the server manually');
this.stop();
}
// Tell the application the framework is reloading
// (might be used by some hooks).
self.reloading = true;
this.reloading = true;
// Teardown Waterline adapters and
// reload the Waterline ORM.
self.after('hook:waterline:reloaded', function () {
self.after('hook:router:reloaded', function () {
process.nextTick(function () {
cb();
});
this.after('hook:waterline:reloaded', () => {
this.after('hook:router:reloaded', () => {
process.nextTick(() => cb());
// Update `strapi` status.
self.reloaded = true;
self.reloading = false;
this.reloaded = true;
this.reloading = false;
// Finally inform the developer everything seems ok.
if (cluster.isMaster && _.isPlainObject(strapi.config.reload) && !_.isEmpty(strapi.config.reload) && strapi.config.reload.workers < 1) {
self.log.info('Application\'s dictionnary updated');
self.log.warn('You still need to restart your server to fully enjoy changes...');
this.log.info('Application\'s dictionnary updated');
this.log.warn('You still need to restart your server to fully enjoy changes...');
}
// Kill every worker processes.
_.forEach(cluster.workers, function () {
process.kill(process.pid, 'SIGHUP');
});
_.forEach(cluster.workers, () => process.kill(process.pid, 'SIGHUP'));
if (cluster.isMaster && _.isPlainObject(strapi.config.reload) && !_.isEmpty(strapi.config.reload) && strapi.config.reload.workers > 0) {
self.log.info('Application restarted');
this.log.info('Application restarted');
console.log();
}
});
// Reloading the router.
self.hooks.router.reload();
this.hooks.router.reload();
});
// Reloading the ORM.
self.hooks.waterline.reload();
this.hooks.waterline.reload();
});
};

View File

@ -4,9 +4,6 @@
* Module dependencies
*/
// Public node modules.
const _ = require('lodash');
// Local dependencies.
const Strapi = require('./Strapi');
@ -23,5 +20,5 @@ function strapiFactory() {
// Backwards compatibility for Strapi singleton usage.
const singleton = strapiFactory();
strapiFactory.isLocalStrapiValid = _.bind(singleton.isLocalStrapiValid, singleton);
strapiFactory.isStrapiAppSync = _.bind(singleton.isStrapiAppSync, singleton);
strapiFactory.isLocalStrapiValid = singleton.isLocalStrapiValid.bind(singleton);
strapiFactory.isStrapiAppSync = singleton.isStrapiAppSync.bind(singleton);

View File

@ -29,10 +29,8 @@ module.exports = function start(configOverride, cb) {
};
async.series([
function (cb) {
self.load(configOverride, cb);
},
self.initialize
cb => self.load(configOverride, cb),
this.initialize
],
function strapiReady(err) {

View File

@ -12,15 +12,14 @@
*/
module.exports = function stop() {
const self = this;
// Flag `self._exiting` as soon as the application has begun to shutdown.
// Flag `this._exiting` as soon as the application has begun to shutdown.
// This may be used by hooks and other parts of core.
self._exiting = true;
this._exiting = true;
// Exit the REPL.
process.exit(0);
// Emit a `stop` event.
self.emit('stop');
this.emit('stop');
};