mirror of
https://github.com/strapi/strapi.git
synced 2025-09-03 05:39:36 +00:00
Auto install engine/adapter during restart
This commit is contained in:
parent
c4132d382a
commit
57b64f34fd
@ -24,7 +24,7 @@ $ npm install strapi -g
|
||||
### Link to the Strapi Studio
|
||||
|
||||
> We advise you to use our Studio to build APIs. To do so, you need to create a Strapi account.
|
||||
[Go to the Strapi Studio to signup](http://studio.strapi.io).
|
||||
[Go to the Strapi Studio to signup](http://localhost:1338).
|
||||
Studio is dedicated to developers to build applications without writing
|
||||
any single line of code thanks to its powerful set of tools.
|
||||
|
||||
@ -91,7 +91,7 @@ $ strapi generate api car name:string year:integer license:string
|
||||
The Strapi Studio allows you to easily build and manage your application environment
|
||||
thanks to a powerful User Interface.
|
||||
|
||||
Log into the Strapi Studio with your user account ([http://studio.strapi.io](http://studio.strapi.io))
|
||||
Log into the Strapi Studio with your user account ([http://localhost:1338](http://localhost:1338))
|
||||
and follow the instructions to start the experience.
|
||||
|
||||

|
||||
|
@ -64,7 +64,7 @@ module.exports = function () {
|
||||
fs.readFile(path.resolve(HOME, '.strapirc'), 'utf8', function (noRcFile, config) {
|
||||
if (noRcFile) {
|
||||
logger.warn('You do not have a `.strapirc` file at `' + HOME + '`.');
|
||||
logger.warn('First, you need to create an account on http://studio.strapi.io/');
|
||||
logger.warn('First, you need to create an account on http://localhost:1338/');
|
||||
logger.warn('Then, execute `$ strapi login` to start the experience.');
|
||||
process.exit(1);
|
||||
}
|
||||
@ -85,7 +85,7 @@ module.exports = function () {
|
||||
preambleCRLF: true,
|
||||
postambleCRLF: true,
|
||||
json: true,
|
||||
uri: 'http://studio.strapi.io/app',
|
||||
uri: 'http://localhost:1338/app',
|
||||
body: {
|
||||
name: appPkg.name,
|
||||
token: config.token,
|
||||
|
@ -81,7 +81,7 @@ module.exports = function () {
|
||||
preambleCRLF: true,
|
||||
postambleCRLF: true,
|
||||
json: true,
|
||||
uri: 'http://studio.strapi.io/auth/local',
|
||||
uri: 'http://localhost:1338/auth/local',
|
||||
body: {
|
||||
identifier: result.email,
|
||||
password: result.password
|
||||
|
@ -92,7 +92,7 @@ module.exports = function () {
|
||||
fs.readFile(path.resolve(HOME, '.strapirc'), 'utf8', function (noRcFile, config) {
|
||||
if (noRcFile) {
|
||||
logger.warn('You do not have a `.strapirc` file at `' + HOME + '`.');
|
||||
logger.warn('First, you need to create an account on http://studio.strapi.io/');
|
||||
logger.warn('First, you need to create an account on http://localhost:1338/');
|
||||
logger.warn('Then, execute `$ strapi login` to start the experience.');
|
||||
process.exit(1);
|
||||
}
|
||||
@ -106,7 +106,7 @@ module.exports = function () {
|
||||
preambleCRLF: true,
|
||||
postambleCRLF: true,
|
||||
json: true,
|
||||
uri: 'http://studio.strapi.io/app',
|
||||
uri: 'http://localhost:1338/app',
|
||||
body: {
|
||||
name: cliArguments[0],
|
||||
token: config.token
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
// Node.js core.
|
||||
const path = require('path');
|
||||
const spawn = require('child_process').spawn;
|
||||
|
||||
// Public node modules.
|
||||
const _ = require('lodash');
|
||||
@ -53,10 +54,55 @@ module.exports = function (strapi) {
|
||||
|
||||
// Finally, use the middleware.
|
||||
strapi.app.use(strapi.middlewares.views(path.resolve(strapi.config.appPath, strapi.config.paths.views), strapi.config.views));
|
||||
}
|
||||
|
||||
cb();
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Installation template engines
|
||||
*/
|
||||
|
||||
installation: function () {
|
||||
const done = _.after(_.size(strapi.config.views.map), function () {
|
||||
strapi.emit('hook:views:installed');
|
||||
});
|
||||
|
||||
_.forEach(strapi.config.views.map, function (engine) {
|
||||
try {
|
||||
require(path.resolve(strapi.config.appPath, 'node_modules', engine));
|
||||
|
||||
done();
|
||||
} catch (err) {
|
||||
if (strapi.config.environment === 'development') {
|
||||
strapi.log.warn('Installing the `' + engine + '` template engine, please wait...');
|
||||
console.log();
|
||||
|
||||
const process = spawn('npm', ['install', engine, '--save']);
|
||||
|
||||
process.on('error', function (error) {
|
||||
strapi.log.error('The template engine `' + engine + '` has not been installed.');
|
||||
strapi.log.error(error);
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on('close', function (code) {
|
||||
if (code !== 0) {
|
||||
strapi.log.error('The template engine `' + engine + '` has not been installed.');
|
||||
strapi.log.error('Code: ' + code);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
done();
|
||||
});
|
||||
} else {
|
||||
strapi.log.error('The template engine `' + engine + '` is not installed.');
|
||||
strapi.log.error('Execute `$ npm install ' + engine + ' --save` to install it.');
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return hook;
|
||||
|
@ -83,7 +83,7 @@ module.exports = function (strapi) {
|
||||
|
||||
// Add the Studio URL.
|
||||
studio: {
|
||||
url: 'http://studio.strapi.io'
|
||||
url: 'http://localhost:1338'
|
||||
},
|
||||
|
||||
// Start off needed empty objects and strings.
|
||||
|
@ -141,7 +141,7 @@ module.exports = function (strapi) {
|
||||
|
||||
// Prepare all other hooks.
|
||||
prepare: function prepareHooks(cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio', 'router'), function (id, cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio', 'router', 'waterline'), function (id, cb) {
|
||||
prepareHook(id);
|
||||
process.nextTick(cb);
|
||||
}, cb);
|
||||
@ -149,7 +149,7 @@ module.exports = function (strapi) {
|
||||
|
||||
// Apply the default config for all other hooks.
|
||||
defaults: function defaultConfigHooks(cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio', 'router'), function (id, cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio', 'router', 'waterline'), function (id, cb) {
|
||||
const hook = hooks[id];
|
||||
applyDefaults(hook);
|
||||
process.nextTick(cb);
|
||||
@ -158,7 +158,7 @@ module.exports = function (strapi) {
|
||||
|
||||
// Load all other hooks.
|
||||
load: function loadOtherHooks(cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio', 'router'), function (id, cb) {
|
||||
async.each(_.without(_.keys(hooks), '_config', '_api', 'studio', 'router', 'waterline'), function (id, cb) {
|
||||
loadHook(id, cb);
|
||||
}, cb);
|
||||
},
|
||||
@ -171,6 +171,16 @@ module.exports = function (strapi) {
|
||||
prepareHook('router');
|
||||
applyDefaults(hooks.router);
|
||||
loadHook('router', cb);
|
||||
},
|
||||
|
||||
// Load the waterline hook.
|
||||
waterline: function loadWaterlineHook(cb) {
|
||||
if (!hooks.waterline) {
|
||||
return cb();
|
||||
}
|
||||
prepareHook('waterline');
|
||||
applyDefaults(hooks.waterline);
|
||||
loadHook('waterline', cb);
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -18,6 +18,7 @@ const async = require('async');
|
||||
|
||||
module.exports = cb => {
|
||||
const self = this;
|
||||
let runDone = null;
|
||||
|
||||
console.log();
|
||||
|
||||
@ -57,10 +58,17 @@ module.exports = cb => {
|
||||
// Run adapters installation
|
||||
if (cluster.isMaster) {
|
||||
self.hooks.waterline.installation();
|
||||
|
||||
++runDone;
|
||||
|
||||
if (_.isPlainObject(self.config.view)) {
|
||||
self.hooks.views.installation();
|
||||
|
||||
++runDone;
|
||||
}
|
||||
}
|
||||
|
||||
// Install new adapters
|
||||
strapi.after('hook:waterline:installed', () => {
|
||||
const installed = _.after(runDone, () => {
|
||||
self.log.warn('Application is restarting...');
|
||||
console.log();
|
||||
|
||||
@ -99,5 +107,13 @@ module.exports = cb => {
|
||||
// Reloading the ORM.
|
||||
self.hooks.waterline.reload();
|
||||
});
|
||||
|
||||
strapi.after('hook:waterline:installed', () => {
|
||||
installed();
|
||||
});
|
||||
|
||||
strapi.after('hook:views:installed', () => {
|
||||
installed();
|
||||
});
|
||||
});
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user