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
|
### 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.
|
> 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
|
Studio is dedicated to developers to build applications without writing
|
||||||
any single line of code thanks to its powerful set of tools.
|
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
|
The Strapi Studio allows you to easily build and manage your application environment
|
||||||
thanks to a powerful User Interface.
|
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.
|
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) {
|
fs.readFile(path.resolve(HOME, '.strapirc'), 'utf8', function (noRcFile, config) {
|
||||||
if (noRcFile) {
|
if (noRcFile) {
|
||||||
logger.warn('You do not have a `.strapirc` file at `' + HOME + '`.');
|
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.');
|
logger.warn('Then, execute `$ strapi login` to start the experience.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@ -85,7 +85,7 @@ module.exports = function () {
|
|||||||
preambleCRLF: true,
|
preambleCRLF: true,
|
||||||
postambleCRLF: true,
|
postambleCRLF: true,
|
||||||
json: true,
|
json: true,
|
||||||
uri: 'http://studio.strapi.io/app',
|
uri: 'http://localhost:1338/app',
|
||||||
body: {
|
body: {
|
||||||
name: appPkg.name,
|
name: appPkg.name,
|
||||||
token: config.token,
|
token: config.token,
|
||||||
|
@ -81,7 +81,7 @@ module.exports = function () {
|
|||||||
preambleCRLF: true,
|
preambleCRLF: true,
|
||||||
postambleCRLF: true,
|
postambleCRLF: true,
|
||||||
json: true,
|
json: true,
|
||||||
uri: 'http://studio.strapi.io/auth/local',
|
uri: 'http://localhost:1338/auth/local',
|
||||||
body: {
|
body: {
|
||||||
identifier: result.email,
|
identifier: result.email,
|
||||||
password: result.password
|
password: result.password
|
||||||
|
@ -92,7 +92,7 @@ module.exports = function () {
|
|||||||
fs.readFile(path.resolve(HOME, '.strapirc'), 'utf8', function (noRcFile, config) {
|
fs.readFile(path.resolve(HOME, '.strapirc'), 'utf8', function (noRcFile, config) {
|
||||||
if (noRcFile) {
|
if (noRcFile) {
|
||||||
logger.warn('You do not have a `.strapirc` file at `' + HOME + '`.');
|
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.');
|
logger.warn('Then, execute `$ strapi login` to start the experience.');
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
@ -106,7 +106,7 @@ module.exports = function () {
|
|||||||
preambleCRLF: true,
|
preambleCRLF: true,
|
||||||
postambleCRLF: true,
|
postambleCRLF: true,
|
||||||
json: true,
|
json: true,
|
||||||
uri: 'http://studio.strapi.io/app',
|
uri: 'http://localhost:1338/app',
|
||||||
body: {
|
body: {
|
||||||
name: cliArguments[0],
|
name: cliArguments[0],
|
||||||
token: config.token
|
token: config.token
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
// Node.js core.
|
// Node.js core.
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
|
const spawn = require('child_process').spawn;
|
||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
@ -53,9 +54,54 @@ module.exports = function (strapi) {
|
|||||||
|
|
||||||
// Finally, use the middleware.
|
// Finally, use the middleware.
|
||||||
strapi.app.use(strapi.middlewares.views(path.resolve(strapi.config.appPath, strapi.config.paths.views), strapi.config.views));
|
strapi.app.use(strapi.middlewares.views(path.resolve(strapi.config.appPath, strapi.config.paths.views), strapi.config.views));
|
||||||
}
|
|
||||||
|
|
||||||
cb();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ module.exports = function (strapi) {
|
|||||||
|
|
||||||
// Add the Studio URL.
|
// Add the Studio URL.
|
||||||
studio: {
|
studio: {
|
||||||
url: 'http://studio.strapi.io'
|
url: 'http://localhost:1338'
|
||||||
},
|
},
|
||||||
|
|
||||||
// Start off needed empty objects and strings.
|
// Start off needed empty objects and strings.
|
||||||
|
@ -141,7 +141,7 @@ module.exports = function (strapi) {
|
|||||||
|
|
||||||
// Prepare all other hooks.
|
// Prepare all other hooks.
|
||||||
prepare: function prepareHooks(cb) {
|
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);
|
prepareHook(id);
|
||||||
process.nextTick(cb);
|
process.nextTick(cb);
|
||||||
}, cb);
|
}, cb);
|
||||||
@ -149,7 +149,7 @@ module.exports = function (strapi) {
|
|||||||
|
|
||||||
// Apply the default config for all other hooks.
|
// Apply the default config for all other hooks.
|
||||||
defaults: function defaultConfigHooks(cb) {
|
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];
|
const hook = hooks[id];
|
||||||
applyDefaults(hook);
|
applyDefaults(hook);
|
||||||
process.nextTick(cb);
|
process.nextTick(cb);
|
||||||
@ -158,7 +158,7 @@ module.exports = function (strapi) {
|
|||||||
|
|
||||||
// Load all other hooks.
|
// Load all other hooks.
|
||||||
load: function loadOtherHooks(cb) {
|
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);
|
loadHook(id, cb);
|
||||||
}, cb);
|
}, cb);
|
||||||
},
|
},
|
||||||
@ -171,6 +171,16 @@ module.exports = function (strapi) {
|
|||||||
prepareHook('router');
|
prepareHook('router');
|
||||||
applyDefaults(hooks.router);
|
applyDefaults(hooks.router);
|
||||||
loadHook('router', cb);
|
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 => {
|
module.exports = cb => {
|
||||||
const self = this;
|
const self = this;
|
||||||
|
let runDone = null;
|
||||||
|
|
||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
@ -57,10 +58,17 @@ module.exports = cb => {
|
|||||||
// Run adapters installation
|
// Run adapters installation
|
||||||
if (cluster.isMaster) {
|
if (cluster.isMaster) {
|
||||||
self.hooks.waterline.installation();
|
self.hooks.waterline.installation();
|
||||||
|
|
||||||
|
++runDone;
|
||||||
|
|
||||||
|
if (_.isPlainObject(self.config.view)) {
|
||||||
|
self.hooks.views.installation();
|
||||||
|
|
||||||
|
++runDone;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Install new adapters
|
const installed = _.after(runDone, () => {
|
||||||
strapi.after('hook:waterline:installed', () => {
|
|
||||||
self.log.warn('Application is restarting...');
|
self.log.warn('Application is restarting...');
|
||||||
console.log();
|
console.log();
|
||||||
|
|
||||||
@ -99,5 +107,13 @@ module.exports = cb => {
|
|||||||
// Reloading the ORM.
|
// Reloading the ORM.
|
||||||
self.hooks.waterline.reload();
|
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