diff --git a/README.md b/README.md index ae38024059..99d5dc3357 100644 --- a/README.md +++ b/README.md @@ -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. ![Strapi Studio](http://strapi.io/assets/screenshots/studio.png "Strapi Studio") diff --git a/bin/strapi-link.js b/bin/strapi-link.js index 8e469dffb8..bd1111a967 100644 --- a/bin/strapi-link.js +++ b/bin/strapi-link.js @@ -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, diff --git a/bin/strapi-login.js b/bin/strapi-login.js index 1ca220548e..c8feff835a 100644 --- a/bin/strapi-login.js +++ b/bin/strapi-login.js @@ -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 diff --git a/bin/strapi-new.js b/bin/strapi-new.js index 71d86a997d..589fcf5c61 100755 --- a/bin/strapi-new.js +++ b/bin/strapi-new.js @@ -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 diff --git a/lib/configuration/hooks/views/index.js b/lib/configuration/hooks/views/index.js index efc476a9a2..5afa3e85e9 100644 --- a/lib/configuration/hooks/views/index.js +++ b/lib/configuration/hooks/views/index.js @@ -6,6 +6,7 @@ // Node.js core. const path = require('path'); +const spawn = require('child_process').spawn; // Public node modules. const _ = require('lodash'); @@ -53,9 +54,54 @@ 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(); + 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); + } + } + }); } }; diff --git a/lib/configuration/index.js b/lib/configuration/index.js index a47534e0c6..75df3ba910 100755 --- a/lib/configuration/index.js +++ b/lib/configuration/index.js @@ -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. diff --git a/lib/private/loadHooks.js b/lib/private/loadHooks.js index e317fced64..aa0e80cd78 100755 --- a/lib/private/loadHooks.js +++ b/lib/private/loadHooks.js @@ -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); } }, diff --git a/lib/restart.js b/lib/restart.js index d72b6b7a92..69ea0779c7 100644 --- a/lib/restart.js +++ b/lib/restart.js @@ -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(); + }); }); };