Merge branch 'master' of github.com:strapi/strapi into wysiwyg

This commit is contained in:
cyril lopez 2018-03-19 12:53:15 +01:00
commit 17aa4049d1
11 changed files with 89 additions and 91 deletions

View File

@ -656,7 +656,6 @@ module.exports = {
// Set the password. // Set the password.
model.set('password', passwordHashed); model.set('password', passwordHashed);
});
} }
} }
``` ```

View File

@ -5,7 +5,7 @@ const _ = require('lodash');
shell.echo(''); shell.echo('');
shell.echo('🕓 The setup process can take few minutes.'); shell.echo('🕓 The setup process can take few minutes.');
shell.echo(''); shell.echo('');
shell.echo(`🔸 Administration Panel`); shell.echo('🔸 Administration Panel');
shell.echo('📦 Installing packages...'); shell.echo('📦 Installing packages...');
const pwd = shell.pwd(); const pwd = shell.pwd();
@ -19,28 +19,28 @@ shell.rm('-rf', path.resolve(appPath, 'package-lock.json'));
shell.rm('-rf', path.resolve(appPath, 'admin', 'package-lock.json')); shell.rm('-rf', path.resolve(appPath, 'admin', 'package-lock.json'));
// Install the project dependencies. // Install the project dependencies.
shell.exec(`cd ${appPath} && npm install --ignore-scripts`, { shell.exec(`cd "${appPath}" && npm install --ignore-scripts`, {
silent silent
}); });
// Install the administration dependencies. // Install the administration dependencies.
shell.exec(`cd ${path.resolve(appPath, 'admin')} && npm install`, { shell.exec(`cd "${path.resolve(appPath, 'admin')}" && npm install`, {
silent silent
}); });
if (isDevelopmentMode) { if (isDevelopmentMode) {
shell.exec(`cd ${path.resolve(appPath, 'admin')} && npm link strapi-helper-plugin && npm link strapi-utils`, { shell.exec(`cd "${path.resolve(appPath, 'admin')}" && npm link strapi-helper-plugin && npm link strapi-utils`, {
silent silent
}); });
} else { } else {
shell.exec(`cd ${path.resolve(appPath, 'admin', 'node_modules', 'strapi-helper-plugin')} && npm install`, { shell.exec(`cd "${path.resolve(appPath, 'admin', 'node_modules', 'strapi-helper-plugin')}" && npm install`, {
silent silent
}); });
} }
shell.echo('🏗 Building...'); shell.echo('🏗 Building...');
const build = shell.exec(`cd ${path.resolve(appPath, 'admin')} && APP_PATH=${appPath} npm run build`, { const build = shell.exec(`cd "${path.resolve(appPath, 'admin')}" && APP_PATH="${appPath}" npm run build`, {
silent silent
}); });
@ -58,23 +58,23 @@ if (process.env.npm_config_plugins === 'true') {
shell.ls('* -d', plugins).forEach(function (plugin) { shell.ls('* -d', plugins).forEach(function (plugin) {
shell.echo(`🔸 Plugin - ${_.upperFirst(plugin)}`); shell.echo(`🔸 Plugin - ${_.upperFirst(plugin)}`);
shell.echo('📦 Installing packages...'); shell.echo('📦 Installing packages...');
shell.exec(`cd ${path.resolve(plugins, plugin)} && npm install`, { shell.exec(`cd "${path.resolve(plugins, plugin)}" && npm install`, {
silent silent
}); });
if (isDevelopmentMode) { if (isDevelopmentMode) {
shell.exec(`cd ${path.resolve(plugins, plugin)} && npm link strapi-helper-plugin`, { shell.exec(`cd "${path.resolve(plugins, plugin)}" && npm link strapi-helper-plugin`, {
silent silent
}); });
} else { } else {
shell.exec(`cd ${path.resolve(plugins, plugin, 'node_modules', 'strapi-helper-plugin')} && npm install`, { shell.exec(`cd "${path.resolve(plugins, plugin, 'node_modules', 'strapi-helper-plugin')}" && npm install`, {
silent silent
}); });
} }
shell.echo('🏗 Building...'); shell.echo('🏗 Building...');
const build = shell.exec(`cd ${path.resolve(plugins, plugin)} && APP_PATH=${appPath} npm run build`, { const build = shell.exec(`cd "${path.resolve(plugins, plugin)}" && APP_PATH="${appPath}" npm run build`, {
silent silent
}); });

View File

@ -18,7 +18,7 @@ module.exports = (scope, success, error) => {
knex.raw('select 1+1 as result').then(() => { knex.raw('select 1+1 as result').then(() => {
logger.info('The app has been connected to the database successfully'); logger.info('The app has been connected to the database successfully');
knex.destroy(); knex.destroy();
execSync(`rm -r ${scope.tmpPath}`); execSync(`rm -r "${scope.tmpPath}"`);
logger.info('Copying the dashboard...'); logger.info('Copying the dashboard...');

View File

@ -5,64 +5,43 @@
*/ */
module.exports = { module.exports = {
// Before saving a value. // Before saving a value.
// Fired before an `insert` or `update` query. // Fired before an `insert` or `update` query.
// beforeSave: function (model, attrs, options) { // beforeSave: async (model, attrs, options) => {},
// return new Promise();
// },
// After saving a value. // After saving a value.
// Fired after an `insert` or `update` query. // Fired after an `insert` or `update` query.
// afterSave: function (model, response, options) { // afterSave: async (model, response, options) => {},
// return new Promise();
// },
// Before fetching a value. // Before fetching a value.
// Fired before a `fetch` operation. // Fired before a `fetch` operation.
// beforeFetch: function (model, columns, options) { // beforeFetch: async (model, columns, options) => {},
// return new Promise();
// },
// After fetching a value. // After fetching a value.
// Fired after a `fetch` operation. // Fired after a `fetch` operation.
// afterFetch: function (model, response, options) { // afterFetch: async (model, response, options) => {},
// return new Promise();
// },
// Before creating a value. // Before creating a value.
// Fired before `insert` query. // Fired before an `insert` query.
// beforeCreate: function (model, attrs, options) { // beforeCreate: async (model, attrs, options) => {},
// return new Promise();
// },
// After creating a value. // After creating a value.
// Fired after `insert` query. // Fired after an `insert` query.
// afterCreate: function (model, attrs, options) { // afterCreate: async (model, attrs, options) => {},
// return new Promise();
// },
// Before updating a value. // Before updating a value.
// Fired before an `update` query. // Fired before an `update` query.
// beforeUpdate: function (model, attrs, options) { // beforeUpdate: async (model, attrs, options) => {},
// return new Promise();
// },
// After updating a value. // After updating a value.
// Fired after an `update` query. // Fired after an `update` query.
// afterUpdate: function (model, attrs, options) { // afterUpdate: async (model, attrs, options) => {},
// return new Promise();
// },
// Before destroying a value. // Before destroying a value.
// Fired before a `delete` query. // Fired before a `delete` query.
// beforeDestroy: function (model, attrs, options) { // beforeDestroy: async (model, attrs, options) => {},
// return new Promise();
// },
// After destroying a value. // After destroying a value.
// Fired after a `delete` query. // Fired after a `delete` query.
// afterDestroy: function (model, attrs, options) { // afterDestroy: async (model, attrs, options) => {}
// return new Promise();
// }
}; };

View File

@ -29,11 +29,11 @@ module.exports = {
// afterFetch: async (model, result) => {}, // afterFetch: async (model, result) => {},
// Before creating a value. // Before creating a value.
// Fired before `insert` query. // Fired before an `insert` query.
// beforeCreate: async (model) => {}, // beforeCreate: async (model) => {},
// After creating a value. // After creating a value.
// Fired after `insert` query. // Fired after an `insert` query.
// afterCreate: async (model, result) => {}, // afterCreate: async (model, result) => {},
// Before updating a value. // Before updating a value.

View File

@ -32,7 +32,7 @@ module.exports = (scope, success, error) => {
Mongoose.connection.close(); Mongoose.connection.close();
execSync(`rm -r ${scope.tmpPath}`); execSync(`rm -r "${scope.tmpPath}"`);
logger.info('Copying the dashboard...'); logger.info('Copying the dashboard...');

View File

@ -19,32 +19,33 @@ module.exports = mongoose => {
return { return {
convertType: mongooseType => { convertType: mongooseType => {
switch (mongooseType.toLowerCase()) { switch (mongooseType.toLowerCase()) {
case 'string': case 'array':
case 'password': return 'Array';
case 'text':
case 'email':
return 'String';
case 'integer':
case 'biginteger':
return 'Number';
case 'float':
case 'decimal':
return 'Float';
case 'date':
case 'time':
case 'datetime':
case 'timestamp':
return Date;
case 'boolean': case 'boolean':
return 'Boolean'; return 'Boolean';
case 'binary': case 'binary':
return 'Buffer'; return 'Buffer';
case 'uuid': case 'date':
return 'ObjectId'; case 'datetime':
case 'enumeration': case 'time':
return 'String'; case 'timestamp':
return Date;
case 'decimal':
case 'float':
return 'Float';
case 'json': case 'json':
return 'Mixed'; return 'Mixed';
case 'biginteger':
case 'integer':
return 'Number';
case 'uuid':
return 'ObjectId';
case 'email':
case 'enumeration':
case 'password':
case 'string':
case 'text':
return 'String';
default: default:
} }

View File

@ -26,7 +26,7 @@ module.exports = (scope, success, error) => {
logger.info('The app has been connected to the database successfully!'); logger.info('The app has been connected to the database successfully!');
execSync(`rm -r ${scope.tmpPath}`); execSync(`rm -r "${scope.tmpPath}"`);
logger.info('Copying the dashboard...'); logger.info('Copying the dashboard...');

View File

@ -87,6 +87,9 @@ class Strapi extends EventEmitter {
try { try {
this.config = assign(this.config, config) this.config = assign(this.config, config)
// Emit starting event.
this.emit('server:starting');
// Enhance app. // Enhance app.
await this.enhancer(); await this.enhancer();
// Load the app. // Load the app.
@ -100,7 +103,9 @@ class Strapi extends EventEmitter {
// Launch server. // Launch server.
this.server.listen(this.config.port, err => { this.server.listen(this.config.port, err => {
if (err) { if (err) {
console.log(err); this.log.debug(`Server wasn't able to start properly.`);
console.error(err);
return this.stop();
} }
this.log.info('Server started in ' + this.config.appPath); this.log.info('Server started in ' + this.config.appPath);
@ -112,14 +117,16 @@ class Strapi extends EventEmitter {
this.log.debug(`Version: ${this.config.info.strapi} (node v${this.config.info.node})`); this.log.debug(`Version: ${this.config.info.strapi} (node v${this.config.info.node})`);
this.log.info('To shut down your server, press <CTRL> + C at any time'); this.log.info('To shut down your server, press <CTRL> + C at any time');
// Emit started event.
this.emit('server:started');
if (cb && typeof cb === 'function') { if (cb && typeof cb === 'function') {
cb(); cb();
} }
}); });
} catch (e) { } catch (err) {
this.log.debug(`Server wasn't able to start properly.`); this.log.debug(`Server wasn't able to start properly.`);
this.log.error(e); console.error(err);
console.error(e);
this.stop(); this.stop();
} }
} }
@ -136,6 +143,17 @@ class Strapi extends EventEmitter {
}); });
}); });
this.server.on('error', err => {
if (err.code === 'EADDRINUSE') {
this.log.debug(`Server wasn't able to start properly.`);
this.log.error(`The port ${err.port} is already used by another application.`);
this.stop();
return;
}
console.error(err);
});
this.server.destroy = cb => { this.server.destroy = cb => {
this.server.close(cb); this.server.close(cb);

View File

@ -91,6 +91,12 @@ const mountHooks = function (files, cwd) {
}); });
}), }),
resolve (err, results) => {
if (err) {
return reject(err);
}
resolve();
}
); );
}; };

View File

@ -14,16 +14,10 @@ const exposer = require('./exposer');
module.exports = { module.exports = {
loadFile: function(url) { loadFile: function(url) {
try {
// Clear cache. // Clear cache.
delete require.cache[require.resolve(path.resolve(this.config.appPath, url))]; delete require.cache[require.resolve(path.resolve(this.config.appPath, url))];
// Require without cache. // Require without cache.
return require(path.resolve(this.config.appPath, url)); return require(path.resolve(this.config.appPath, url));
} catch (e) {
this.log.error(e);
return {};
}
}, },
setConfig: function(ctx, path, type, loader) { setConfig: function(ctx, path, type, loader) {
@ -123,11 +117,12 @@ module.exports = {
try { try {
if (this.config.uuid) { if (this.config.uuid) {
const publicKey = fs.readFileSync(path.resolve(__dirname, 'resources', 'key.pub')); const publicKey = fs.readFileSync(path.resolve(__dirname, 'resources', 'key.pub'));
const options = { timeout: 1000 };
const [usage, signedHash, required] = await Promise.all([ const [usage, signedHash, required] = await Promise.all([
fetch('https://strapi.io/assets/images/usage.gif'), fetch('https://strapi.io/assets/images/usage.gif', options),
fetch('https://strapi.io/hash.txt'), fetch('https://strapi.io/hash.txt', options),
fetch('https://strapi.io/required.txt') fetch('https://strapi.io/required.txt', options)
]); ]);
if (usage.status === 200 && signedHash.status === 200) { if (usage.status === 200 && signedHash.status === 200) {