mirror of
https://github.com/strapi/strapi.git
synced 2025-12-24 21:54:24 +00:00
Move entire repository to ES6 & fix tests
This commit is contained in:
parent
6e65f9d693
commit
c6d2be25b5
@ -12,6 +12,7 @@
|
||||
},
|
||||
"xo": {
|
||||
"space": true,
|
||||
"esnext": true,
|
||||
"envs": [
|
||||
"mocha",
|
||||
"node"
|
||||
@ -68,7 +69,7 @@
|
||||
"url": "https://github.com/strapi/strapi/issues"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4.0.0",
|
||||
"node": ">= 7.0.0",
|
||||
"npm": ">= 3.0.0"
|
||||
},
|
||||
"license": "MIT"
|
||||
|
||||
@ -34,7 +34,7 @@ module.exports = function (strapi) {
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
initialize: function (cb) {
|
||||
initialize: cb => {
|
||||
let globalName;
|
||||
|
||||
// Make sure the Knex hook is present since Knex needs it.
|
||||
@ -45,7 +45,7 @@ module.exports = function (strapi) {
|
||||
}
|
||||
|
||||
// Only run this logic after the Knex has finished to load.
|
||||
strapi.after('hook:knex:loaded', function () {
|
||||
strapi.after('hook:knex:loaded', () => {
|
||||
|
||||
// Initialize collections
|
||||
_.set(strapi, 'bookshelf.collections', {});
|
||||
@ -55,12 +55,12 @@ module.exports = function (strapi) {
|
||||
return cb();
|
||||
}
|
||||
|
||||
const loadedHook = _.after(_.size(strapi.models), function () {
|
||||
const loadedHook = _.after(_.size(strapi.models), () => {
|
||||
cb();
|
||||
});
|
||||
|
||||
// Parse every registered model.
|
||||
_.forEach(strapi.models, function (definition, model) {
|
||||
_.forEach(strapi.models, (definition, model) => {
|
||||
globalName = _.upperFirst(_.camelCase(definition.globalId));
|
||||
|
||||
// Make sure the model has a table name.
|
||||
@ -97,10 +97,10 @@ module.exports = function (strapi) {
|
||||
|
||||
// Call this callback function after we are done parsing
|
||||
// all attributes for relationships-- see below.
|
||||
const done = _.after(_.size(definition.attributes), function () {
|
||||
const done = _.after(_.size(definition.attributes), () => {
|
||||
try {
|
||||
// Initialize lifecycle callbacks.
|
||||
loadedModel.initialize = function () {
|
||||
loadedModel.initialize = () => {
|
||||
const self = this;
|
||||
const lifecycle = {
|
||||
creating: 'beforeCreate',
|
||||
@ -115,7 +115,7 @@ module.exports = function (strapi) {
|
||||
saved: 'afterSave'
|
||||
};
|
||||
|
||||
_.forEach(lifecycle, function (fn, key) {
|
||||
_.forEach(lifecycle, (fn, key) => {
|
||||
if (_.isFunction(strapi.models[model.toLowerCase()][fn])) {
|
||||
self.on(key, strapi.models[model.toLowerCase()][fn]);
|
||||
}
|
||||
@ -149,7 +149,7 @@ module.exports = function (strapi) {
|
||||
|
||||
// Add every relationships to the loaded model for Bookshelf.
|
||||
// Basic attributes don't need this-- only relations.
|
||||
_.forEach(definition.attributes, function (details, name) {
|
||||
_.forEach(definition.attributes, (details, name) => {
|
||||
const verbose = _.get(utilsModels.getNature(details, name), 'verbose') || '';
|
||||
|
||||
// Build associations key
|
||||
@ -159,31 +159,31 @@ module.exports = function (strapi) {
|
||||
|
||||
switch (verbose) {
|
||||
case 'hasOne':
|
||||
const FK = _.findKey(strapi.models[details.model].attributes, function (details) {
|
||||
const FK = _.findKey(strapi.models[details.model].attributes, details => {
|
||||
if (details.hasOwnProperty('model') && details.model === model && details.hasOwnProperty('via') && details.via === name) {
|
||||
return details;
|
||||
}
|
||||
});
|
||||
|
||||
loadedModel[name] = function () {
|
||||
loadedModel[name] = () => {
|
||||
return this.hasOne(global[_.capitalize(details.model)], FK);
|
||||
};
|
||||
break;
|
||||
|
||||
case 'hasMany':
|
||||
loadedModel[name] = function () {
|
||||
loadedModel[name] = () => {
|
||||
return this.hasMany(global[_.capitalize(details.collection)], details.via);
|
||||
};
|
||||
break;
|
||||
|
||||
case 'belongsTo':
|
||||
loadedModel[name] = function () {
|
||||
loadedModel[name] = () => {
|
||||
return this.belongsTo(global[_.capitalize(details.model)], name);
|
||||
};
|
||||
break;
|
||||
|
||||
case 'belongsToMany':
|
||||
const tableName = _.map(_.sortBy([strapi.models[details.collection].attributes[details.via], details], 'collection'), function (table) {
|
||||
const tableName = _.map(_.sortBy([strapi.models[details.collection].attributes[details.via], details], 'collection'), table => {
|
||||
return _.snakeCase(pluralize.plural(table.collection) + ' ' + pluralize.plural(table.via));
|
||||
}).join('__');
|
||||
|
||||
@ -203,7 +203,7 @@ module.exports = function (strapi) {
|
||||
relationship.attribute = pluralize.singular(details.via);
|
||||
}
|
||||
|
||||
loadedModel[name] = function () {
|
||||
loadedModel[name] = () => {
|
||||
return this.belongsToMany(global[_.capitalize(details.collection)], tableName, relationship.attribute + '_' + relationship.column, details.attribute + '_' + details.column);
|
||||
};
|
||||
break;
|
||||
|
||||
@ -23,7 +23,7 @@ module.exports = {
|
||||
* @return {String}
|
||||
*/
|
||||
|
||||
getCollectionIdentity: function (collection) {
|
||||
getCollectionIdentity: collection => {
|
||||
return _.capitalize(collection.forge().tableName);
|
||||
},
|
||||
|
||||
@ -33,12 +33,10 @@ module.exports = {
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
fetch: function (collectionIdentity, collection, criteria) {
|
||||
fetch: (collectionIdentity, collection, criteria) => {
|
||||
return collection.forge(criteria)
|
||||
.fetch({withRelated: helpers.getAssociationsByIdentity(collectionIdentity)})
|
||||
.then(function (data) {
|
||||
return _.isEmpty(data) ? data : data.toJSON();
|
||||
});
|
||||
.then(data => _.isEmpty(data) ? data : data.toJSON());
|
||||
},
|
||||
|
||||
/**
|
||||
@ -47,17 +45,15 @@ module.exports = {
|
||||
* @return {Array}
|
||||
*/
|
||||
|
||||
fetchAll: function (collectionIdentity, collection, criteria) {
|
||||
const filters = _.omit(helpers.handleFilters(criteria), function (value) {
|
||||
fetchAll: (collectionIdentity, collection, criteria) => {
|
||||
const filters = _.omit(helpers.handleFilters(criteria), value => {
|
||||
return _.isUndefined(value) || _.isNumber(value) ? _.isNull(value) : _.isEmpty(value);
|
||||
});
|
||||
|
||||
return collection.forge()
|
||||
.query(filters)
|
||||
.fetchAll({withRelated: helpers.getAssociationsByIdentity(collectionIdentity)})
|
||||
.then(function (data) {
|
||||
return data.toJSON() || data;
|
||||
});
|
||||
.then(data => data.toJSON() || data);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -66,8 +62,8 @@ module.exports = {
|
||||
* @return {Array}
|
||||
*/
|
||||
|
||||
fetchLatest: function (collectionIdentity, collection, criteria) {
|
||||
const filters = _.omit(helpers.handleFilters(criteria), function (value) {
|
||||
fetchLatest: (collectionIdentity, collection, criteria) => {
|
||||
const filters = _.omit(helpers.handleFilters(criteria), value => {
|
||||
return _.isUndefined(value) || _.isNumber(value) ? _.isNull(value) : _.isEmpty(value);
|
||||
});
|
||||
|
||||
@ -80,9 +76,7 @@ module.exports = {
|
||||
return collection.forge(criteria)
|
||||
.query(filters)
|
||||
.fetchAll({withRelated: helpers.getAssociationsByIdentity(collectionIdentity)})
|
||||
.then(function (data) {
|
||||
return data.toJSON() || data;
|
||||
});
|
||||
.then(data => data.toJSON() || data);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -91,8 +85,8 @@ module.exports = {
|
||||
* @return {Array}
|
||||
*/
|
||||
|
||||
fetchFirst: function (collectionIdentity, collection, criteria) {
|
||||
const filters = _.omit(helpers.handleFilters(criteria), function (value) {
|
||||
fetchFirst: (collectionIdentity, collection, criteria) => {
|
||||
const filters = _.omit(helpers.handleFilters(criteria), value => {
|
||||
return _.isUndefined(value) || _.isNumber(value) ? _.isNull(value) : _.isEmpty(value);
|
||||
});
|
||||
|
||||
@ -105,9 +99,7 @@ module.exports = {
|
||||
return collection.forge(criteria)
|
||||
.query(filters)
|
||||
.fetchAll({withRelated: helpers.getAssociationsByIdentity(collectionIdentity)})
|
||||
.then(function (data) {
|
||||
return data.toJSON() || data;
|
||||
});
|
||||
.then(data => data.toJSON() || data);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -116,12 +108,10 @@ module.exports = {
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
create: function (collectionIdentity, rootValue, args) {
|
||||
create: (collectionIdentity, rootValue, args) => {
|
||||
return strapi.services[collectionIdentity.toLowerCase()]
|
||||
.add(rootValue.context.request.body)
|
||||
.then(function (data) {
|
||||
return _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data;
|
||||
});
|
||||
.then(data => _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -130,16 +120,14 @@ module.exports = {
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
update: function (collectionIdentity, rootValue, args) {
|
||||
update: (collectionIdentity, rootValue, args) => {
|
||||
_.merge(args, rootValue.context.request.body);
|
||||
|
||||
const PK = utils.getPK(collectionIdentity.toLowerCase(), null, strapi.models);
|
||||
|
||||
return strapi.services[collectionIdentity.toLowerCase()]
|
||||
.edit(_.set({}, PK, args[PK]), _.omit(args, PK))
|
||||
.then(function (data) {
|
||||
return _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data;
|
||||
});
|
||||
.then(data => _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -148,14 +136,12 @@ module.exports = {
|
||||
* @return {Object}
|
||||
*/
|
||||
|
||||
delete: function (collectionIdentity, rootValue, args) {
|
||||
delete: (collectionIdentity, rootValue, args) => {
|
||||
_.merge(args, rootValue.context.request.body);
|
||||
|
||||
return strapi.services[collectionIdentity.toLowerCase()]
|
||||
.remove(args)
|
||||
.then(function (data) {
|
||||
return _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data;
|
||||
});
|
||||
.then(data => _.isFunction(_.get(data, 'toJSON')) ? data.toJSON() : data);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -164,7 +150,5 @@ module.exports = {
|
||||
* @return {Array}
|
||||
*/
|
||||
|
||||
count: function (collectionIdentity, collection) {
|
||||
return collection.forge().count();
|
||||
}
|
||||
count: (collectionIdentity, collection) => collection.forge().count()
|
||||
};
|
||||
|
||||
@ -17,10 +17,10 @@ module.exports = {
|
||||
* Find primary key
|
||||
*/
|
||||
|
||||
getPK: function (collectionIdentity, collection, models) {
|
||||
getPK: (collectionIdentity, collection, models) => {
|
||||
// This is not a Bookshelf collection, only the name.
|
||||
if (_.isString(collectionIdentity) && !_.isUndefined(models)) {
|
||||
const PK = _.findKey(_.get(models, collectionIdentity + '.attributes'), function (o) {
|
||||
const PK = _.findKey(_.get(models, collectionIdentity + '.attributes'), o => {
|
||||
return o.hasOwnProperty('primary');
|
||||
});
|
||||
|
||||
@ -52,9 +52,7 @@ module.exports = {
|
||||
* Find primary key
|
||||
*/
|
||||
|
||||
getCount: function (type) {
|
||||
return strapi.bookshelf.collections[type].forge().count().then(function (count) {
|
||||
return count;
|
||||
});
|
||||
getCount: type => {
|
||||
return strapi.bookshelf.collections[type].forge().count().then(count => count);
|
||||
}
|
||||
};
|
||||
|
||||
@ -40,7 +40,7 @@ module.exports = (scope, cb) => {
|
||||
keep_function_indentation: true,
|
||||
space_before_conditional: true,
|
||||
end_with_newline: true
|
||||
}), 'utf8', function (err) {
|
||||
}), 'utf8', err => {
|
||||
if (err) {
|
||||
return cb(err, null);
|
||||
} else {
|
||||
|
||||
@ -68,7 +68,7 @@ module.exports = (scope, cb) => {
|
||||
}
|
||||
|
||||
// Make sure the needed client is installed.
|
||||
_.forEach(scope.connections, function (config) {
|
||||
_.forEach(scope.connections, config => {
|
||||
try {
|
||||
scope.db = require(path.resolve(scope.rootPath, 'node_modules', 'knex'))(scope.dbConfig);
|
||||
} catch (err) {
|
||||
|
||||
@ -25,14 +25,14 @@ module.exports = (models, modelName) => {
|
||||
const tplTableCreate = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'tables', 'createTableIfNotExists.template'), 'utf8');
|
||||
if (_.isEmpty(_.get(models[modelName], 'up.others'))) {
|
||||
_.set(models[modelName], 'up.others', _.unescape(_.template(tplTableCreate)({
|
||||
models: models,
|
||||
models,
|
||||
tableName: modelName,
|
||||
attributes: models[modelName].attributes,
|
||||
options: models[modelName].options
|
||||
})));
|
||||
} else {
|
||||
models[modelName].up.others += _.unescape(_.template(tplTableCreate)({
|
||||
models: models,
|
||||
models,
|
||||
tableName: modelName,
|
||||
attributes: models[modelName].attributes,
|
||||
options: models[modelName].options
|
||||
|
||||
@ -24,7 +24,7 @@ module.exports = (models, modelName, value, option) => {
|
||||
const tplOption = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'tables', 'options', option + '.template'), 'utf8');
|
||||
models[modelName][option] = _.unescape(_.template(tplOption)({
|
||||
tableName: modelName,
|
||||
option: option,
|
||||
value: value
|
||||
option,
|
||||
value
|
||||
}));
|
||||
};
|
||||
|
||||
@ -78,29 +78,29 @@ module.exports = (rootModels, modelName, details, attribute, toDrop, onlyDrop, h
|
||||
tplRelationUp = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'relations', 'hasOne.template'), 'utf8');
|
||||
models[modelName].attributes[attribute].create.others += _.unescape(_.template(tplRelationUp)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
|
||||
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropColumn-unique.template'), 'utf8');
|
||||
models[modelName].attributes[attribute].delete.others += _.unescape(_.template(tplRelationDown)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
} else {
|
||||
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropColumn-unique.template'), 'utf8');
|
||||
models[modelName].attributes[attribute].create.drop += _.unescape(_.template(tplRelationDown)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
|
||||
tplRelationUp = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'relations', 'hasOne.template'), 'utf8');
|
||||
models[modelName].attributes[attribute].delete.drop += _.unescape(_.template(tplRelationUp)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
}
|
||||
} else if (infos.verbose === 'belongsTo') {
|
||||
@ -115,30 +115,30 @@ module.exports = (rootModels, modelName, details, attribute, toDrop, onlyDrop, h
|
||||
tplRelationUp = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'relations', 'belongsTo.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].create.others += _.unescape(_.template(tplRelationUp)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details,
|
||||
attribute,
|
||||
details,
|
||||
nature: infos.nature
|
||||
}));
|
||||
|
||||
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropColumn.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].delete.drop += _.unescape(_.template(tplRelationDown)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
} else {
|
||||
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropForeign.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].create.drop += _.unescape(_.template(tplRelationDown)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
|
||||
tplRelationUp = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'relations', 'belongsTo.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].delete.others += _.unescape(_.template(tplRelationUp)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details,
|
||||
attribute,
|
||||
details,
|
||||
nature: infos.nature
|
||||
}));
|
||||
}
|
||||
@ -147,29 +147,29 @@ module.exports = (rootModels, modelName, details, attribute, toDrop, onlyDrop, h
|
||||
tplRelationUp = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'relations', 'belongsTo-unique.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].create.others += _.unescape(_.template(tplRelationUp)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
|
||||
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropColumn-unique.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].delete.drop += _.unescape(_.template(tplRelationDown)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
} else {
|
||||
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropColumn.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].create.drop += _.unescape(_.template(tplRelationDown)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
|
||||
tplRelationUp = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'relations', 'belongsTo.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].delete.others += _.unescape(_.template(tplRelationUp)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details,
|
||||
attribute,
|
||||
details,
|
||||
nature: infos.nature
|
||||
}));
|
||||
}
|
||||
@ -179,15 +179,15 @@ module.exports = (rootModels, modelName, details, attribute, toDrop, onlyDrop, h
|
||||
tplRelationDown = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'dropForeign.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].create.drop += _.unescape(_.template(tplRelationDown)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
|
||||
tplRelationUp = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'relations', 'belongsTo.template'), 'utf8');
|
||||
rootModels[modelName].attributes[attribute].delete.others += _.unescape(_.template(tplRelationUp)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details,
|
||||
attribute,
|
||||
details,
|
||||
nature: infos.nature
|
||||
}));
|
||||
}
|
||||
@ -240,10 +240,10 @@ module.exports = (rootModels, modelName, details, attribute, toDrop, onlyDrop, h
|
||||
|
||||
// Create relationships table for many-to-many.
|
||||
rootModels[relationTable].up.others += _.unescape(_.template(tplTableUp)({
|
||||
models: models,
|
||||
models,
|
||||
tableName: relationTable,
|
||||
details: details,
|
||||
relationship: relationship
|
||||
details,
|
||||
relationship
|
||||
}));
|
||||
|
||||
if (_.isUndefined(_.get(rootModels, relationTable + '.attributes.fk'))) {
|
||||
@ -268,7 +268,7 @@ module.exports = (rootModels, modelName, details, attribute, toDrop, onlyDrop, h
|
||||
};
|
||||
|
||||
rootModels[relationTable].down.drop += _.unescape(_.template(tplSelectTableDown)({
|
||||
models: models,
|
||||
models,
|
||||
tableName: relationTable,
|
||||
attributes: models[relationTable].attributes,
|
||||
toDrop: true
|
||||
@ -382,10 +382,10 @@ module.exports = (rootModels, modelName, details, attribute, toDrop, onlyDrop, h
|
||||
if (rootModels[relationTable].down.others.indexOf('createTableIfNotExists(\'' + relationTable + '\'') === -1) {
|
||||
// Create previous relationships table on migration rollback.
|
||||
rootModels[relationTable].down.others += _.unescape(_.template(tplTableUp)({
|
||||
models: models,
|
||||
models,
|
||||
tableName: relationTable || relationTable,
|
||||
details: details,
|
||||
relationship: relationship
|
||||
details,
|
||||
relationship
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ module.exports = (models, modelName) => {
|
||||
|
||||
if (!_.isEmpty(emptyArrayForDrop)) {
|
||||
models[modelName].up.drop += _.unescape(_.template(tplSelectTableUp)({
|
||||
models: models,
|
||||
models,
|
||||
tableName: modelName,
|
||||
attributes: models[modelName].newAttributes,
|
||||
toDrop: true
|
||||
@ -53,7 +53,7 @@ module.exports = (models, modelName) => {
|
||||
|
||||
if (!_.isEmpty(emptyArrayForOthers)) {
|
||||
models[modelName].up.others += _.unescape(_.template(tplSelectTableUp)({
|
||||
models: models,
|
||||
models,
|
||||
tableName: modelName,
|
||||
attributes: models[modelName].newAttributes,
|
||||
toDrop: false
|
||||
@ -87,7 +87,7 @@ module.exports = (models, modelName) => {
|
||||
|
||||
if (!_.isEmpty(emptyArrayForDrop)) {
|
||||
models[modelName].down.drop += _.unescape(_.template(tplSelectTableDown)({
|
||||
models: models,
|
||||
models,
|
||||
tableName: modelName,
|
||||
attributes: models[modelName].newAttributes,
|
||||
toDrop: true
|
||||
@ -96,7 +96,7 @@ module.exports = (models, modelName) => {
|
||||
|
||||
if (!_.isEmpty(emptyArrayForOthers)) {
|
||||
models[modelName].down.others += _.unescape(_.template(tplSelectTableDown)({
|
||||
models: models,
|
||||
models,
|
||||
tableName: modelName,
|
||||
attributes: models[modelName].newAttributes,
|
||||
toDrop: false
|
||||
|
||||
@ -36,7 +36,7 @@ module.exports = (models, modelName, details, attribute, toDrop, onlyDrop) => {
|
||||
// Template: delete a specific column.
|
||||
models[modelName].attributes[attribute].create.drop = _.unescape(_.template(tplTypeDelete)({
|
||||
tableName: modelName,
|
||||
attribute: attribute
|
||||
attribute
|
||||
}));
|
||||
}
|
||||
|
||||
@ -44,8 +44,8 @@ module.exports = (models, modelName, details, attribute, toDrop, onlyDrop) => {
|
||||
if (_.isUndefined(onlyDrop)) {
|
||||
models[modelName].attributes[attribute].create.others = _.unescape(_.template(tplTypeCreate)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
details: details
|
||||
attribute,
|
||||
details
|
||||
}));
|
||||
}
|
||||
|
||||
@ -54,7 +54,7 @@ module.exports = (models, modelName, details, attribute, toDrop, onlyDrop) => {
|
||||
if (!_.isUndefined(details.defaultTo)) {
|
||||
const tplDefaultTo = fs.readFileSync(path.resolve(__dirname, '..', '..', 'templates', 'builder', 'columns', 'chainables', 'defaultTo.template'), 'utf8');
|
||||
models[modelName].attributes[attribute].create.others += _.unescape(_.template(tplDefaultTo)({
|
||||
details: details
|
||||
details
|
||||
}));
|
||||
}
|
||||
|
||||
@ -88,20 +88,20 @@ module.exports = (models, modelName, details, attribute, toDrop, onlyDrop) => {
|
||||
// Template: delete a specific column.
|
||||
models[modelName].attributes[attribute].delete.drop = _.unescape(_.template(tplTypeDelete)({
|
||||
tableName: modelName,
|
||||
attribute: attribute
|
||||
attribute
|
||||
}));
|
||||
}
|
||||
|
||||
models[modelName].attributes[attribute].delete.others = _.unescape(_.template(tplTypeDeleteCreate)({
|
||||
tableName: modelName,
|
||||
attribute: attribute,
|
||||
attribute,
|
||||
details: models[modelName].oldAttributes[attribute]
|
||||
}));
|
||||
} else {
|
||||
// Template: delete a specific column.
|
||||
models[modelName].attributes[attribute].delete.others = _.unescape(_.template(tplTypeDelete)({
|
||||
tableName: modelName,
|
||||
attribute: attribute
|
||||
attribute
|
||||
}));
|
||||
}
|
||||
};
|
||||
|
||||
@ -45,7 +45,7 @@ function generate(generator, scope, cb) {
|
||||
generator.before(scope, reportback.extend({
|
||||
error: sb.error,
|
||||
invalid: sb.invalid,
|
||||
success: function () {
|
||||
success: () => {
|
||||
|
||||
// Emit output.
|
||||
sb.log.verbose('Generating ' + util.inspect(generator) + ' at `' + scope.rootPath + '`...');
|
||||
@ -110,7 +110,7 @@ function generate(generator, scope, cb) {
|
||||
rootPath: path.resolve(scope.rootPath, parsedKeyPath),
|
||||
|
||||
// Include reference to original keypath for error reporting.
|
||||
keyPath: keyPath
|
||||
keyPath
|
||||
});
|
||||
|
||||
// If `target` is an array, run each item.
|
||||
@ -128,14 +128,14 @@ function generate(generator, scope, cb) {
|
||||
|
||||
// Otherwise, just run the single target generator/helper.
|
||||
generateTarget({
|
||||
target: target,
|
||||
target,
|
||||
parent: generator,
|
||||
scope: targetScope,
|
||||
recursiveGenerate: generate
|
||||
}, asyncEachSb);
|
||||
},
|
||||
|
||||
function done(err) {
|
||||
err => {
|
||||
|
||||
// Expose a `error` handler in generators.
|
||||
if (err) {
|
||||
|
||||
@ -30,13 +30,13 @@ module.exports = function (options, cb) {
|
||||
// `templates` directory.
|
||||
const absSrcPath = path.resolve(options.templatesDirectory, options.templatePath);
|
||||
|
||||
fs.readFile(absSrcPath, 'utf8', function (err, contents) {
|
||||
fs.readFile(absSrcPath, 'utf8', (err, contents) => {
|
||||
if (err) {
|
||||
return cb.error(err);
|
||||
}
|
||||
|
||||
return fileHelper(_.merge(options, {
|
||||
contents: contents
|
||||
contents
|
||||
}), cb);
|
||||
});
|
||||
};
|
||||
|
||||
@ -43,7 +43,7 @@ module.exports = function (options, cb) {
|
||||
const rootPath = path.resolve(process.cwd(), options.rootPath);
|
||||
|
||||
// Only override an existing file if `options.force` is true.
|
||||
fs.exists(rootPath, function (exists) {
|
||||
fs.exists(rootPath, exists => {
|
||||
if (exists && !options.force) {
|
||||
return cb.alreadyExists('Something else already exists at `' + rootPath + '`.');
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ module.exports = function (options, cb) {
|
||||
const rootPath = path.resolve(process.cwd(), options.rootPath);
|
||||
|
||||
// Only override an existing folder if `options.force` is true.
|
||||
fs.lstat(rootPath, function (err) {
|
||||
fs.lstat(rootPath, err => {
|
||||
const exists = !(err && err.code === 'ENOENT');
|
||||
if (exists && err) {
|
||||
return cb.error(err);
|
||||
@ -51,7 +51,7 @@ module.exports = function (options, cb) {
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
fs.remove(rootPath, function deletedOldINode(err) {
|
||||
fs.remove(rootPath, err => {
|
||||
if (err) {
|
||||
return cb.error(err);
|
||||
}
|
||||
@ -69,7 +69,7 @@ module.exports = function (options, cb) {
|
||||
}
|
||||
|
||||
// Create the directory.
|
||||
fs.mkdirs(rootPath, function directoryWasWritten(err) {
|
||||
fs.mkdirs(rootPath, err => {
|
||||
if (err) {
|
||||
return cb.error(err);
|
||||
}
|
||||
|
||||
@ -40,13 +40,13 @@ module.exports = function (options, handlers) {
|
||||
const rootPath = path.resolve(process.cwd(), options.rootPath);
|
||||
|
||||
// Only override an existing file if `options.force` is true.
|
||||
fs.exists(rootPath, function (exists) {
|
||||
fs.exists(rootPath, exists => {
|
||||
if (exists && !options.force) {
|
||||
return handlers.alreadyExists('Something else already exists at `' + rootPath + '`.');
|
||||
}
|
||||
|
||||
if (exists) {
|
||||
fs.remove(rootPath, function deletedOldINode(err) {
|
||||
fs.remove(rootPath, err => {
|
||||
if (err) {
|
||||
return handlers.error(err);
|
||||
}
|
||||
@ -57,7 +57,7 @@ module.exports = function (options, handlers) {
|
||||
}
|
||||
|
||||
function _afterwards_() {
|
||||
fs.outputJSON(rootPath, options.data, {spaces: 2}, function (err) {
|
||||
fs.outputJSON(rootPath, options.data, {spaces: 2}, err => {
|
||||
if (err) {
|
||||
return handlers.error(err);
|
||||
} else {
|
||||
|
||||
@ -35,7 +35,7 @@ module.exports = function (options, cb) {
|
||||
|
||||
const absTemplatePath = path.resolve(options.templatesDirectory, options.templatePath);
|
||||
|
||||
fs.readFile(absTemplatePath, 'utf8', function (err, contents) {
|
||||
fs.readFile(absTemplatePath, 'utf8', (err, contents) => {
|
||||
if (err) {
|
||||
err = err instanceof Error ? err : new Error(err);
|
||||
err.message = 'Template error: ' + err.message;
|
||||
@ -61,7 +61,7 @@ module.exports = function (options, cb) {
|
||||
}
|
||||
|
||||
return fileHelper(_.merge(options, {
|
||||
contents: contents
|
||||
contents
|
||||
}), cb);
|
||||
});
|
||||
};
|
||||
|
||||
@ -38,11 +38,11 @@ function generateTarget(options, cb) {
|
||||
let _resolves = 0;
|
||||
|
||||
async.until(
|
||||
function checkIfTargetIsValidYet() {
|
||||
() => {
|
||||
return isValidTarget(target) || ++_resolves > maxResolves;
|
||||
},
|
||||
function tryToParseTarget(asyncCb) {
|
||||
parseTarget(target, scope, function (err, resolvedTarget) {
|
||||
asyncCb => {
|
||||
parseTarget(target, scope, (err, resolvedTarget) => {
|
||||
if (err) {
|
||||
return asyncCb(err);
|
||||
}
|
||||
@ -50,7 +50,7 @@ function generateTarget(options, cb) {
|
||||
return asyncCb();
|
||||
});
|
||||
},
|
||||
function afterwards(err) {
|
||||
err => {
|
||||
if (err) {
|
||||
return sb(err);
|
||||
}
|
||||
@ -125,7 +125,7 @@ function mergeSubtargetScope(scope, subtarget) {
|
||||
const knownHelpers = ['folder', 'template', 'jsonfile', 'file', 'copy'];
|
||||
|
||||
function targetIsHelper(target) {
|
||||
return _.some(target, function (subTarget, key) {
|
||||
return _.some(target, (subTarget, key) => {
|
||||
return _.includes(knownHelpers, key);
|
||||
});
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ exports.pathRegexp = (path, keys, sensitive, strict) => {
|
||||
path = path
|
||||
.concat(strict ? '' : '/?')
|
||||
.replace(/\/\(/g, '(?:/')
|
||||
.replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?(\*)?/g, function (_, slash, format, key, capture, optional, star) {
|
||||
.replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?(\*)?/g, (_, slash, format, key, capture, optional, star) => {
|
||||
keys.push({
|
||||
name: key,
|
||||
optional: !!optional
|
||||
|
||||
@ -35,7 +35,7 @@ module.exports = function (strapi) {
|
||||
* Initialize the hook
|
||||
*/
|
||||
|
||||
initialize: function (cb) {
|
||||
initialize: cb => {
|
||||
let globalName;
|
||||
|
||||
// Return callback if there is no model
|
||||
@ -58,8 +58,8 @@ module.exports = function (strapi) {
|
||||
// Initialize collections
|
||||
_.set(strapi, 'mongoose.collections', {});
|
||||
|
||||
const loadedAttributes = _.after(_.size(strapi.models), function () {
|
||||
_.forEach(strapi.models, function (definition, model) {
|
||||
const loadedAttributes = _.after(_.size(strapi.models), () => {
|
||||
_.forEach(strapi.models, (definition, model) => {
|
||||
try {
|
||||
let collection = strapi.mongoose.collections[mongooseUtils.toCollectionName(definition.globalName)];
|
||||
|
||||
@ -72,7 +72,7 @@ module.exports = function (strapi) {
|
||||
save: 'beforeSave'
|
||||
};
|
||||
|
||||
_.forEach(preLifecycle, function (fn, key) {
|
||||
_.forEach(preLifecycle, (fn, key) => {
|
||||
if (_.isFunction(strapi.models[model.toLowerCase()][fn])) {
|
||||
collection.schema.pre(key, strapi.models[model.toLowerCase()][fn]);
|
||||
}
|
||||
@ -86,7 +86,7 @@ module.exports = function (strapi) {
|
||||
save: 'afterSave'
|
||||
};
|
||||
|
||||
_.forEach(postLifecycle, function (fn, key) {
|
||||
_.forEach(postLifecycle, (fn, key) => {
|
||||
if (_.isFunction(strapi.models[model.toLowerCase()][fn])) {
|
||||
collection.schema.post(key, strapi.models[model.toLowerCase()][fn]);
|
||||
}
|
||||
@ -130,7 +130,7 @@ module.exports = function (strapi) {
|
||||
});
|
||||
|
||||
// Parse every registered model.
|
||||
_.forEach(strapi.models, function (definition, model) {
|
||||
_.forEach(strapi.models, (definition, model) => {
|
||||
definition.globalName = _.upperFirst(_.camelCase(definition.globalId));
|
||||
|
||||
// Make sure the model has a connection.
|
||||
@ -165,7 +165,7 @@ module.exports = function (strapi) {
|
||||
|
||||
// Call this callback function after we are done parsing
|
||||
// all attributes for relationships-- see below.
|
||||
const done = _.after(_.size(definition.attributes), function () {
|
||||
const done = _.after(_.size(definition.attributes), () => {
|
||||
// Generate schema without virtual populate
|
||||
_.set(strapi.mongoose.collections, mongooseUtils.toCollectionName(definition.globalName) + '.schema', new mongoose.Schema(_.omitBy(definition.loadedModel, model => {
|
||||
return model.type === 'virtual';
|
||||
@ -176,7 +176,7 @@ module.exports = function (strapi) {
|
||||
|
||||
// Add every relationships to the loaded model for Bookshelf.
|
||||
// Basic attributes don't need this-- only relations.
|
||||
_.forEach(definition.attributes, function (details, name) {
|
||||
_.forEach(definition.attributes, (details, name) => {
|
||||
const verbose = _.get(utilsModels.getNature(details, name), 'verbose') || '';
|
||||
|
||||
// Build associations key
|
||||
|
||||
@ -28,7 +28,7 @@ module.exports = {
|
||||
* Find primary key per ORM
|
||||
*/
|
||||
|
||||
getPK: function (collectionIdentity, collection, models) {
|
||||
getPK: (collectionIdentity, collection, models) => {
|
||||
if (_.isString(collectionIdentity)) {
|
||||
const ORM = this.getORM(collectionIdentity);
|
||||
|
||||
@ -50,7 +50,7 @@ module.exports = {
|
||||
* Find primary key per ORM
|
||||
*/
|
||||
|
||||
getCount: function (collectionIdentity) {
|
||||
getCount: collectionIdentity => {
|
||||
if (_.isString(collectionIdentity)) {
|
||||
const ORM = this.getORM(collectionIdentity);
|
||||
|
||||
@ -73,7 +73,7 @@ module.exports = {
|
||||
* Find relation nature with verbose
|
||||
*/
|
||||
|
||||
getNature: function (association, key, models) {
|
||||
getNature: (association, key, models) => {
|
||||
const strapi = _.isUndefined(global['strapi']) && !_.isUndefined(models) ? _.set({}, 'models', models) : global['strapi'];
|
||||
const types = {
|
||||
current: '',
|
||||
@ -208,7 +208,7 @@ module.exports = {
|
||||
* Return ORM used for this collection.
|
||||
*/
|
||||
|
||||
getORM: function (collectionIdentity) {
|
||||
getORM: collectionIdentity => {
|
||||
return _.get(strapi.models, collectionIdentity.toLowerCase() + '.orm');
|
||||
},
|
||||
|
||||
@ -216,7 +216,7 @@ module.exports = {
|
||||
* Define associations key to models
|
||||
*/
|
||||
|
||||
defineAssociations: function (model, definition, association, key) {
|
||||
defineAssociations: (model, definition, association, key) => {
|
||||
// Initialize associations object
|
||||
if (definition.associations === undefined) {
|
||||
definition.associations = [];
|
||||
@ -252,7 +252,7 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
|
||||
getVia: function (attribute, association) {
|
||||
getVia: (attribute, association) => {
|
||||
return _.findKey(strapi.models[association.model || association.collection].attributes, {via: attribute});
|
||||
}
|
||||
};
|
||||
|
||||
@ -25,7 +25,7 @@ exports.detectRoute = endpoint => {
|
||||
|
||||
// Return the verb and the endpoint.
|
||||
return {
|
||||
verb: verb,
|
||||
endpoint: endpoint
|
||||
verb,
|
||||
endpoint
|
||||
};
|
||||
};
|
||||
|
||||
@ -42,7 +42,7 @@ module.exports = function () {
|
||||
|
||||
// Run the rollback.
|
||||
scope.db.migrate.rollback()
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
logger.info('Rollback successfully made for the `' + scope.connection + '` connection!');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
@ -41,10 +41,10 @@ module.exports = function () {
|
||||
|
||||
// Run the migration.
|
||||
scope.db.migrate.latest()
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
return scope.db.seed.run();
|
||||
})
|
||||
.then(function () {
|
||||
.then(() => {
|
||||
logger.info('Migration successfully made for the `' + scope.connection + '` connection!');
|
||||
process.exit(0);
|
||||
});
|
||||
|
||||
@ -44,7 +44,7 @@ module.exports = function () {
|
||||
watchDirectory: process.cwd(),
|
||||
killTree: true, // Kills the entire child process tree on `exit`,
|
||||
spinSleepTime: 0,
|
||||
command: 'node --harmony'
|
||||
command: 'node --harmony-async-await'
|
||||
});
|
||||
|
||||
const child = new (forever.Monitor)('server.js', options);
|
||||
@ -61,7 +61,7 @@ module.exports = function () {
|
||||
|
||||
// Run app as a child_process
|
||||
// when harmony flag is not detected.
|
||||
if (!~process.execArgv.indexOf('--harmony-async-await')) {
|
||||
if (!~process.execArgv.indexOf('--harmony')) {
|
||||
const opts = Object.create(process.env);
|
||||
opts.execArgv = ['--harmony-async-await'];
|
||||
|
||||
|
||||
@ -43,7 +43,7 @@ module.exports = function () {
|
||||
try {
|
||||
process.chdir(path.resolve(__dirname, '..', 'node_modules', 'strapi-generate-' + name));
|
||||
logger.debug('Pulling the latest updates of `strapi-generate-' + name + '`.');
|
||||
exec('git pull ' + info.remote + ' ' + info.branch, function (err) {
|
||||
exec('git pull ' + info.remote + ' ' + info.branch, err => {
|
||||
if (err) {
|
||||
logger.error('Impossible to update `strapi-generate-' + name + '`.');
|
||||
} else {
|
||||
@ -53,7 +53,7 @@ module.exports = function () {
|
||||
} catch (err) {
|
||||
process.chdir(path.resolve(__dirname, '..', 'node_modules'));
|
||||
logger.debug('Cloning the `strapi-generate-' + name + '` repository for the first time...');
|
||||
exec('git clone ' + info.repository + ' strapi-generate-' + name, function (err) {
|
||||
exec('git clone ' + info.repository + ' strapi-generate-' + name, err => {
|
||||
if (err) {
|
||||
logger.error('Impossible to clone the `strapi-generate-' + name + '` repository.');
|
||||
console.log(err);
|
||||
@ -61,7 +61,7 @@ module.exports = function () {
|
||||
logger.info('Successfully cloned the `strapi-generate-' + name + '` repository.');
|
||||
process.chdir(path.resolve(__dirname, '..', 'node_modules', 'strapi-generate-' + name));
|
||||
logger.debug('Installing dependencies for `strapi-generate-' + name + '`...');
|
||||
exec('npm install', function (err) {
|
||||
exec('npm install', err => {
|
||||
if (err) {
|
||||
logger.error('Impossible to install dependencies for `strapi-generate-' + name + '`.');
|
||||
console.log(err);
|
||||
|
||||
@ -40,7 +40,7 @@ program.allowUnknownOption(true);
|
||||
program.version(packageJSON.version, '-v, --version');
|
||||
|
||||
// Make `-v` option case-insensitive.
|
||||
process.argv = _.map(process.argv, function (arg) {
|
||||
process.argv = _.map(process.argv, arg => {
|
||||
return (arg === '-V') ? '-v' : arg;
|
||||
});
|
||||
|
||||
@ -116,7 +116,7 @@ cmd.action(require('./strapi-generate'));
|
||||
// Custom generators from `.strapirc`.
|
||||
try {
|
||||
const config = JSON.parse(fs.readFileSync(path.resolve(HOME, '.strapirc')));
|
||||
_.forEach(config.generators, function (info, name) {
|
||||
_.forEach(config.generators, (info, name) => {
|
||||
cmd = program.command('generate:' + name);
|
||||
cmd.unknownOption = NOOP;
|
||||
cmd.description(info.description);
|
||||
|
||||
@ -49,11 +49,11 @@ class Strapi extends EventEmitter {
|
||||
// Expose every middleware inside `strapi.middlewares`.
|
||||
this.middlewares = require('koa-load-middlewares')({
|
||||
config: path.resolve(__dirname, '..', 'package.json'),
|
||||
pattern: ['koa-*', 'koa.*'],
|
||||
pattern: ['koa-*', 'koa.*', 'k*'],
|
||||
scope: ['dependencies', 'devDependencies'],
|
||||
replaceString: /^koa(-|\.)/,
|
||||
camelize: true,
|
||||
lazy: true
|
||||
lazy: false
|
||||
});
|
||||
|
||||
// New Winston logger.
|
||||
|
||||
@ -39,7 +39,8 @@ module.exports = strapi => {
|
||||
headers: [
|
||||
'Content-Type',
|
||||
'Authorization'
|
||||
]
|
||||
],
|
||||
keepHeadersOnError: false
|
||||
}
|
||||
},
|
||||
|
||||
@ -49,14 +50,15 @@ module.exports = strapi => {
|
||||
|
||||
initialize: cb => {
|
||||
if (_.isPlainObject(strapi.config.cors) && !_.isEmpty(strapi.config.cors)) {
|
||||
strapi.app.use(strapi.middlewares.convert(strapi.middlewares.cors({
|
||||
strapi.app.use(strapi.middlewares.kcors({
|
||||
origin: strapi.config.cors.origin,
|
||||
expose: strapi.config.cors.expose,
|
||||
exposeHeaders: strapi.config.cors.expose,
|
||||
maxAge: strapi.config.cors.maxAge,
|
||||
credentials: strapi.config.cors.credentials,
|
||||
methods: strapi.config.cors.methods,
|
||||
headers: strapi.config.cors.headers
|
||||
})));
|
||||
allowMethods: strapi.config.cors.methods,
|
||||
allowHeaders: strapi.config.cors.headers,
|
||||
keepHeadersOnError: strapi.config.cors.keepHeadersOnError
|
||||
}));
|
||||
}
|
||||
|
||||
cb();
|
||||
|
||||
@ -72,7 +72,7 @@ module.exports = strapi => {
|
||||
method: value.method,
|
||||
path: value.path,
|
||||
handler: _.union(policies, [action]),
|
||||
validate: validate
|
||||
validate
|
||||
}, _.isEmpty));
|
||||
} catch (err) {
|
||||
cb(err);
|
||||
@ -107,7 +107,7 @@ module.exports = strapi => {
|
||||
method: value.method,
|
||||
path: value.path,
|
||||
handler: _.remove([strapi.middlewares.compose(policies), action], o => _.isFunction(o)),
|
||||
validate: validate
|
||||
validate
|
||||
}, _.isEmpty));
|
||||
} catch (err) {
|
||||
cb(err);
|
||||
@ -136,7 +136,7 @@ module.exports = strapi => {
|
||||
method: value.method,
|
||||
path: value.path,
|
||||
handler: _.remove([strapi.middlewares.compose(policies), action], o => _.isFunction(o)),
|
||||
validate: validate
|
||||
validate
|
||||
}, _.isEmpty));
|
||||
} catch (err) {
|
||||
cb(err);
|
||||
@ -245,10 +245,10 @@ module.exports = strapi => {
|
||||
}
|
||||
|
||||
return {
|
||||
route: route,
|
||||
policies: policies,
|
||||
action: action,
|
||||
validate: validate
|
||||
route,
|
||||
policies,
|
||||
action,
|
||||
validate
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ module.exports = strapi => {
|
||||
}
|
||||
|
||||
// Map every template engine in config.
|
||||
_.forEach(opts.map, function (engine) {
|
||||
_.forEach(opts.map, engine => {
|
||||
if (!consolidate.requires[engine]) {
|
||||
|
||||
// Try to require them using `consolidate` or throw an error.
|
||||
|
||||
@ -175,7 +175,7 @@ module.exports = strapi => {
|
||||
function templateConfigurations(object) {
|
||||
// Allow values which looks like such as
|
||||
// an ES6 literal string without parenthesis inside (aka function call).
|
||||
var regex = /^\$\{[^()]*\}$/g;
|
||||
const regex = /^\$\{[^()]*\}$/g;
|
||||
|
||||
return _.mapValues(object, (value, key) => {
|
||||
if (_.isPlainObject(value)) {
|
||||
|
||||
@ -37,7 +37,7 @@ module.exports = class Configuration {
|
||||
// `appPath` is passed from above in case `start` was used.
|
||||
// This is the directory where this Strapi process is being initiated from.
|
||||
// Usually this means `process.cwd()`.
|
||||
appPath: appPath,
|
||||
appPath,
|
||||
|
||||
// Core settings non provided by hooks.
|
||||
host: process.env.HOST || process.env.HOSTNAME || context.config.host || 'localhost',
|
||||
|
||||
@ -175,7 +175,7 @@ module.exports = function (configOverride, cb) {
|
||||
// zero downtime reloads.
|
||||
if (_.isPlainObject(this.config.reload) && !_.isEmpty(this.config.reload) && this.config.reload.workers > 0) {
|
||||
herd(this.config.name)
|
||||
.close(function () {
|
||||
.close(() => {
|
||||
process.send('message');
|
||||
})
|
||||
.timeout(this.config.reload.timeout)
|
||||
|
||||
@ -38,12 +38,12 @@
|
||||
"async": "^2.1.2",
|
||||
"consolidate": "~0.14.0",
|
||||
"herd": "~1.0.0",
|
||||
"kcors": "^2.2.0",
|
||||
"koa": "^2.0.0-alpha.7",
|
||||
"koa-bodyparser": "git@github.com:koajs/bodyparser.git#3.x",
|
||||
"koa-compose": "git@github.com:koajs/compose.git#next",
|
||||
"koa-compress": "git@github.com:koajs/compress.git#v2.x",
|
||||
"koa-convert": "^1.2.0",
|
||||
"koa-cors": "~0.0.16",
|
||||
"koa-favicon": "git@github.com:koajs/favicon.git#v2.x",
|
||||
"koa-i18n": "~1.2.0",
|
||||
"koa-ip": "~0.1.0",
|
||||
|
||||
@ -10,24 +10,24 @@ const strapi = require('../lib/');
|
||||
* is correctly required and loaded inside `strapi`.
|
||||
*/
|
||||
|
||||
describe('application', function () {
|
||||
it('`strapi.app` should be an object', function () {
|
||||
describe('application', () => {
|
||||
it('`strapi.app` should be an object', () => {
|
||||
assert(typeof strapi.app === 'object');
|
||||
});
|
||||
|
||||
it('`strapi.app.use` should be a function', function () {
|
||||
it('`strapi.app.use` should be a function', () => {
|
||||
assert(typeof strapi.app.use === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.app.context` should be an object', function () {
|
||||
it('`strapi.app.context` should be an object', () => {
|
||||
assert(typeof strapi.app.context === 'object');
|
||||
});
|
||||
|
||||
it('`strapi.app.request` should be an object', function () {
|
||||
it('`strapi.app.request` should be an object', () => {
|
||||
assert(typeof strapi.app.request === 'object');
|
||||
});
|
||||
|
||||
it('`strapi.app.response` should be an object', function () {
|
||||
it('`strapi.app.response` should be an object', () => {
|
||||
assert(typeof strapi.app.response === 'object');
|
||||
});
|
||||
});
|
||||
|
||||
@ -9,44 +9,44 @@ const strapi = require('../lib/');
|
||||
* required and loaded.
|
||||
*/
|
||||
|
||||
describe('core', function () {
|
||||
it('`strapi` should be an object', function () {
|
||||
describe('core', () => {
|
||||
it('`strapi` should be an object', () => {
|
||||
assert(typeof strapi === 'object');
|
||||
});
|
||||
|
||||
it('`strapi.load` should be a function', function () {
|
||||
it('`strapi.load` should be a function', () => {
|
||||
assert(typeof strapi.load === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.initialize` should be a function', function () {
|
||||
it('`strapi.initialize` should be a function', () => {
|
||||
assert(typeof strapi.initialize === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.exposeGlobals` should be a function', function () {
|
||||
it('`strapi.exposeGlobals` should be a function', () => {
|
||||
assert(typeof strapi.exposeGlobals === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.isLocalStrapiValid` should be a function', function () {
|
||||
it('`strapi.isLocalStrapiValid` should be a function', () => {
|
||||
assert(typeof strapi.isLocalStrapiValid === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.isStrapiAppSync` should be a function', function () {
|
||||
it('`strapi.isStrapiAppSync` should be a function', () => {
|
||||
assert(typeof strapi.isStrapiAppSync === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.runBootstrap` should be a function', function () {
|
||||
it('`strapi.runBootstrap` should be a function', () => {
|
||||
assert(typeof strapi.runBootstrap === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.server` should be a object', function () {
|
||||
it('`strapi.server` should be a object', () => {
|
||||
assert(typeof strapi.server === 'object');
|
||||
});
|
||||
|
||||
it('`strapi.start` should be a function', function () {
|
||||
it('`strapi.start` should be a function', () => {
|
||||
assert(typeof strapi.start === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.stop` should be a function', function () {
|
||||
it('`strapi.stop` should be a function', () => {
|
||||
assert(typeof strapi.stop === 'function');
|
||||
});
|
||||
});
|
||||
|
||||
@ -8,24 +8,24 @@ const strapi = require('../lib/');
|
||||
* Make sure the logger works correctly.
|
||||
*/
|
||||
|
||||
describe('logger', function () {
|
||||
it('`strapi.log` should be an object', function () {
|
||||
describe('logger', () => {
|
||||
it('`strapi.log` should be an object', () => {
|
||||
assert(typeof strapi.log === 'object');
|
||||
});
|
||||
|
||||
it('`strapi.log.verbose` should be a function', function () {
|
||||
it('`strapi.log.verbose` should be a function', () => {
|
||||
assert(typeof strapi.log.verbose === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.log.info` should be a function', function () {
|
||||
it('`strapi.log.info` should be a function', () => {
|
||||
assert(typeof strapi.log.info === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.log.warn` should be a function', function () {
|
||||
it('`strapi.log.warn` should be a function', () => {
|
||||
assert(typeof strapi.log.warn === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.log.error` should be a function', function () {
|
||||
it('`strapi.log.error` should be a function', () => {
|
||||
assert(typeof strapi.log.error === 'function');
|
||||
});
|
||||
});
|
||||
|
||||
@ -10,80 +10,80 @@ const strapi = require('../lib/');
|
||||
* correctly required and loaded inside `strapi`.
|
||||
*/
|
||||
|
||||
describe('middlewares', function () {
|
||||
it('`strapi.middlewares` should be an object', function () {
|
||||
describe('middlewares', () => {
|
||||
it('`strapi.middlewares` should be an object', () => {
|
||||
assert(typeof strapi.middlewares === 'object');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.bodyparser` should be a function', function () {
|
||||
it('`strapi.middlewares.bodyparser` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.bodyparser === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.compose` should be a function', function () {
|
||||
it('`strapi.middlewares.compose` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.compose === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.compress` should be a function', function () {
|
||||
it('`strapi.middlewares.compress` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.compress === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.cors` should be a function', function () {
|
||||
assert(typeof strapi.middlewares.cors === 'function');
|
||||
it('`strapi.middlewares.kcors` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.kcors === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.favicon` should be a function', function () {
|
||||
it('`strapi.middlewares.favicon` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.favicon === 'function');
|
||||
});
|
||||
|
||||
// it('`strapi.middlewares.graphql` should be a function', function () {
|
||||
// it('`strapi.middlewares.graphql` should be a function', () => {
|
||||
// assert(typeof strapi.middlewares.graphql === 'function');
|
||||
// });
|
||||
|
||||
it('`strapi.middlewares.i18n` should be a function', function () {
|
||||
it('`strapi.middlewares.i18n` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.i18n === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.ip` should be a function', function () {
|
||||
it('`strapi.middlewares.ip` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.ip === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.locale` should be a function', function () {
|
||||
it('`strapi.middlewares.locale` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.locale === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.lusca` should be a function', function () {
|
||||
it('`strapi.middlewares.lusca` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.lusca === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.proxy` should be a function', function () {
|
||||
it('`strapi.middlewares.proxy` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.proxy === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.responseTime` should be a function', function () {
|
||||
it('`strapi.middlewares.responseTime` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.responseTime === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.joiRouter` should be a function', function () {
|
||||
it('`strapi.middlewares.joiRouter` should be a function', () => {
|
||||
// assert(typeof strapi.middlewares.joiRouter === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.send` should be a function', function () {
|
||||
it('`strapi.middlewares.send` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.send === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.session` should be a function', function () {
|
||||
it('`strapi.middlewares.session` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.session === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.sslify` should be a function', function () {
|
||||
it('`strapi.middlewares.sslify` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.sslify === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.static` should be a function', function () {
|
||||
it('`strapi.middlewares.static` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.static === 'function');
|
||||
});
|
||||
|
||||
it('`strapi.middlewares.views` should be a function', function () {
|
||||
it('`strapi.middlewares.views` should be a function', () => {
|
||||
assert(typeof strapi.middlewares.views === 'function');
|
||||
});
|
||||
});
|
||||
|
||||
@ -5,4 +5,4 @@ if [ -z "$TEST_GREP" ]; then
|
||||
TEST_GREP=""
|
||||
fi
|
||||
|
||||
node node_modules/mocha/bin/_mocha `scripts/_get-test-directories.sh` --opts test/mocha.opts --grep "$TEST_GREP"
|
||||
node --harmony-async-await node_modules/mocha/bin/_mocha `scripts/_get-test-directories.sh` --opts test/mocha.opts --grep "$TEST_GREP"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user