mirror of
https://github.com/strapi/strapi.git
synced 2025-10-03 04:13:51 +00:00
Merge branch 'master' into feature/missing-auth-mutations
This commit is contained in:
commit
b15db81adb
@ -11,6 +11,7 @@ const path = require('path');
|
|||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const pluralize = require('pluralize');
|
const pluralize = require('pluralize');
|
||||||
|
const { nameToSlug } = require('strapi-utils');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This `before` function is run before generating targets.
|
* This `before` function is run before generating targets.
|
||||||
@ -26,7 +27,7 @@ module.exports = (scope, cb) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Format `id`.
|
// Format `id`.
|
||||||
const name = scope.name || _.trim(_.camelCase(scope.id));
|
const name = scope.name || nameToSlug(scope.id);
|
||||||
const environment = process.env.NODE_ENV || 'development';
|
const environment = process.env.NODE_ENV || 'development';
|
||||||
|
|
||||||
scope.contentTypeKind = scope.args.kind || 'collectionType';
|
scope.contentTypeKind = scope.args.kind || 'collectionType';
|
||||||
@ -58,12 +59,6 @@ module.exports = (scope, cb) => {
|
|||||||
filePath,
|
filePath,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Humanize output.
|
|
||||||
_.defaults(scope, {
|
|
||||||
humanizeId: name,
|
|
||||||
humanizedPath: filePath,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Validate optional attribute arguments.
|
// Validate optional attribute arguments.
|
||||||
const invalidAttributes = [];
|
const invalidAttributes = [];
|
||||||
|
|
||||||
@ -79,9 +74,7 @@ module.exports = (scope, cb) => {
|
|||||||
|
|
||||||
// Handle invalid attributes.
|
// Handle invalid attributes.
|
||||||
if (!parts[1] || !parts[0]) {
|
if (!parts[1] || !parts[0]) {
|
||||||
invalidAttributes.push(
|
invalidAttributes.push('Error: Invalid attribute notation `' + attribute + '`.');
|
||||||
'Error: Invalid attribute notation `' + attribute + '`.'
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,9 +119,7 @@ module.exports = (scope, cb) => {
|
|||||||
: _.snakeCase(pluralize(name));
|
: _.snakeCase(pluralize(name));
|
||||||
|
|
||||||
// Set description
|
// Set description
|
||||||
scope.description = _.has(scope.args, 'description')
|
scope.description = _.has(scope.args, 'description') ? scope.args.description : '';
|
||||||
? scope.args.description
|
|
||||||
: '';
|
|
||||||
|
|
||||||
// Get default connection
|
// Get default connection
|
||||||
try {
|
try {
|
||||||
@ -137,13 +128,7 @@ module.exports = (scope, cb) => {
|
|||||||
try {
|
try {
|
||||||
scope.connection = JSON.parse(
|
scope.connection = JSON.parse(
|
||||||
fs.readFileSync(
|
fs.readFileSync(
|
||||||
path.resolve(
|
path.resolve(scope.rootPath, 'config', 'environments', environment, 'database.json')
|
||||||
scope.rootPath,
|
|
||||||
'config',
|
|
||||||
'environments',
|
|
||||||
environment,
|
|
||||||
'database.json'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
).defaultConnection;
|
).defaultConnection;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.11",
|
"lodash": "^4.17.11",
|
||||||
"pluralize": "^7.0.0"
|
"pluralize": "^7.0.0",
|
||||||
|
"strapi-utils": "^3.0.0-beta.19.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"no tests yet\""
|
"test": "echo \"no tests yet\""
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const { nameToSlug } = require('strapi-utils');
|
||||||
/* eslint-disable prefer-template */
|
/* eslint-disable prefer-template */
|
||||||
/**
|
/**
|
||||||
* This `before` function is run before generating targets.
|
* This `before` function is run before generating targets.
|
||||||
@ -22,18 +23,15 @@ module.exports = (scope, cb) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format `id`.
|
||||||
|
const name = scope.name || nameToSlug(scope.id);
|
||||||
|
|
||||||
// `scope.args` are the raw command line arguments.
|
// `scope.args` are the raw command line arguments.
|
||||||
_.defaults(scope, {
|
_.defaults(scope, {
|
||||||
id: _.trim(_.deburr(scope.id)),
|
name,
|
||||||
api: scope.id,
|
api: scope.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Determine default values based on the available scope.
|
|
||||||
_.defaults(scope, {
|
|
||||||
globalID: _.upperFirst(_.camelCase(scope.id)),
|
|
||||||
ext: '.js',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Determine the destination path.
|
// Determine the destination path.
|
||||||
let filePath;
|
let filePath;
|
||||||
if (scope.args.api) {
|
if (scope.args.api) {
|
||||||
@ -43,20 +41,14 @@ module.exports = (scope, cb) => {
|
|||||||
} else if (scope.args.extend) {
|
} else if (scope.args.extend) {
|
||||||
filePath = `./extensions/${scope.args.extend}/controllers`;
|
filePath = `./extensions/${scope.args.extend}/controllers`;
|
||||||
} else {
|
} else {
|
||||||
filePath = `./api/${scope.id}/controllers`;
|
filePath = `./api/${name}/controllers`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
||||||
_.defaults(scope, {
|
_.defaults(scope, {
|
||||||
rootPath: scope.rootPath,
|
rootPath: scope.rootPath,
|
||||||
filePath,
|
filePath,
|
||||||
filename: scope.globalID + scope.ext,
|
filename: `${name}.js`,
|
||||||
});
|
|
||||||
|
|
||||||
// Humanize output.
|
|
||||||
_.defaults(scope, {
|
|
||||||
humanizeId: _.camelCase(scope.id).toLowerCase(),
|
|
||||||
humanizedPath: '`' + scope.filePath + '`',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger callback with no error to proceed.
|
// Trigger callback with no error to proceed.
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
"lib": "./lib"
|
"lib": "./lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.11"
|
"lodash": "^4.17.11",
|
||||||
|
"strapi-utils": "^3.0.0-beta.19.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"no tests yet\""
|
"test": "echo \"no tests yet\""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of functions called "actions" for `<%= globalID %>`
|
* A set of functions called "actions" for `<%= name %>`
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -11,6 +11,7 @@ const path = require('path');
|
|||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
const pluralize = require('pluralize');
|
const pluralize = require('pluralize');
|
||||||
|
const { nameToSlug, nameToCollectionName } = require('strapi-utils');
|
||||||
|
|
||||||
// Fetch stub attribute template on initial load.
|
// Fetch stub attribute template on initial load.
|
||||||
const attributeTemplate = fs.readFileSync(
|
const attributeTemplate = fs.readFileSync(
|
||||||
@ -34,41 +35,31 @@ module.exports = (scope, cb) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format `id`.
|
||||||
|
const name = scope.name || nameToSlug(scope.id);
|
||||||
|
|
||||||
// `scope.args` are the raw command line arguments.
|
// `scope.args` are the raw command line arguments.
|
||||||
_.defaults(scope, {
|
_.defaults(scope, {
|
||||||
id: _.trim(_.deburr(scope.id)),
|
name,
|
||||||
idPluralized: pluralize.plural(_.trim(_.deburr(scope.id))),
|
|
||||||
environment: process.env.NODE_ENV || 'development',
|
environment: process.env.NODE_ENV || 'development',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Determine default values based on the available scope.
|
|
||||||
_.defaults(scope, {
|
|
||||||
globalID: _.upperFirst(_.camelCase(scope.id)),
|
|
||||||
ext: '.js',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Determine the destination path.
|
// Determine the destination path.
|
||||||
let filePath;
|
let filePath;
|
||||||
if (scope.args.api) {
|
if (scope.args.api) {
|
||||||
filePath = `./api/${scope.args.api}`;
|
filePath = `./api/${scope.args.api}/models`;
|
||||||
} else if (scope.args.plugin) {
|
} else if (scope.args.plugin) {
|
||||||
filePath = `./plugins/${scope.args.plugin}/models`;
|
filePath = `./plugins/${scope.args.plugin}/models`;
|
||||||
} else {
|
} else {
|
||||||
filePath = `./api/${scope.id}`;
|
filePath = `./api/${name}/models`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
||||||
_.defaults(scope, {
|
_.defaults(scope, {
|
||||||
rootPath: scope.rootPath,
|
rootPath: scope.rootPath,
|
||||||
filePath,
|
filePath,
|
||||||
filename: scope.globalID + scope.ext,
|
filename: `${name}.js`,
|
||||||
filenameSettings: scope.globalID + '.settings.json',
|
filenameSettings: `${name}.settings.json`,
|
||||||
});
|
|
||||||
|
|
||||||
// Humanize output.
|
|
||||||
_.defaults(scope, {
|
|
||||||
humanizeId: _.camelCase(scope.id).toLowerCase(),
|
|
||||||
humanizedPath: '`' + scope.filePath + '`',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Validate optional attribute arguments.
|
// Validate optional attribute arguments.
|
||||||
@ -82,9 +73,7 @@ module.exports = (scope, cb) => {
|
|||||||
|
|
||||||
// Handle invalid attributes.
|
// Handle invalid attributes.
|
||||||
if (!parts[1] || !parts[0]) {
|
if (!parts[1] || !parts[0]) {
|
||||||
invalidAttributes.push(
|
invalidAttributes.push('Error: Invalid attribute notation `' + attribute + '`.');
|
||||||
'Error: Invalid attribute notation `' + attribute + '`.'
|
|
||||||
);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,12 +86,10 @@ module.exports = (scope, cb) => {
|
|||||||
// Set collectionName
|
// Set collectionName
|
||||||
scope.collectionName = _.has(scope.args, 'collectionName')
|
scope.collectionName = _.has(scope.args, 'collectionName')
|
||||||
? scope.args.collectionName
|
? scope.args.collectionName
|
||||||
: undefined;
|
: nameToCollectionName(pluralize(scope.id));
|
||||||
|
|
||||||
// Set description
|
// Set description
|
||||||
scope.description = _.has(scope.args, 'description')
|
scope.description = _.has(scope.args, 'description') ? scope.args.description : undefined;
|
||||||
? scope.args.description
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
// Handle invalid action arguments.
|
// Handle invalid action arguments.
|
||||||
// Send back invalidActions.
|
// Send back invalidActions.
|
||||||
@ -141,13 +128,7 @@ module.exports = (scope, cb) => {
|
|||||||
scope.args.connection ||
|
scope.args.connection ||
|
||||||
JSON.parse(
|
JSON.parse(
|
||||||
fs.readFileSync(
|
fs.readFileSync(
|
||||||
path.resolve(
|
path.resolve(scope.rootPath, 'config', 'environments', scope.environment, 'database.json')
|
||||||
scope.rootPath,
|
|
||||||
'config',
|
|
||||||
'environments',
|
|
||||||
scope.environment,
|
|
||||||
'database.json'
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
).defaultConnection ||
|
).defaultConnection ||
|
||||||
'';
|
'';
|
||||||
|
@ -16,7 +16,10 @@ module.exports = {
|
|||||||
templatesDirectory: scope => {
|
templatesDirectory: scope => {
|
||||||
try {
|
try {
|
||||||
// Try to reach the path. If it fail, throw an error.
|
// Try to reach the path. If it fail, throw an error.
|
||||||
fs.accessSync(path.resolve(__dirname, '..', 'templates', scope.args.tpl), fs.constants.R_OK | fs.constants.W_OK);
|
fs.accessSync(
|
||||||
|
path.resolve(__dirname, '..', 'templates', scope.args.tpl),
|
||||||
|
fs.constants.R_OK | fs.constants.W_OK
|
||||||
|
);
|
||||||
|
|
||||||
return path.resolve(__dirname, '..', 'templates', scope.args.tpl);
|
return path.resolve(__dirname, '..', 'templates', scope.args.tpl);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -26,11 +29,11 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
before: require('./before'),
|
before: require('./before'),
|
||||||
targets: {
|
targets: {
|
||||||
':filePath/models/:filename': {
|
':filePath/:filename': {
|
||||||
template: 'model.template'
|
template: 'model.template',
|
||||||
},
|
},
|
||||||
':filePath/models/:filenameSettings': {
|
':filePath/:filenameSettings': {
|
||||||
template: 'model.settings.template'
|
template: 'model.settings.template',
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.11",
|
"lodash": "^4.17.11",
|
||||||
"pluralize": "^7.0.0"
|
"pluralize": "^7.0.0",
|
||||||
|
"strapi-utils": "^3.0.0-beta.19.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"no tests yet\""
|
"test": "echo \"no tests yet\""
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"kind": "collectionType",
|
||||||
"connection": "<%= connection %>",
|
"connection": "<%= connection %>",
|
||||||
"collectionName": "<%= collectionName || idPluralized %>",
|
"collectionName": "<%= collectionName %>",
|
||||||
"info": {
|
"info": {
|
||||||
"name": "<%= id %>",
|
"name": "<%= id %>",
|
||||||
"description": "<%= description %>"
|
"description": "<%= description %>"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lifecycle callbacks for the `<%= globalID %>` model.
|
* Lifecycle callbacks for the `<%= name %>` model.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"kind": "collectionType",
|
||||||
"connection": "<%= connection %>",
|
"connection": "<%= connection %>",
|
||||||
"collectionName": "<%= collectionName || '' %>",
|
"collectionName": "<%= collectionName %>",
|
||||||
"info": {
|
"info": {
|
||||||
"name": "<%= id %>",
|
"name": "<%= id %>",
|
||||||
"description": "<%= description %>"
|
"description": "<%= description %>"
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lifecycle callbacks for the `<%= globalID %>` model.
|
* Lifecycle callbacks for the `<%= name %>` model.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -7,14 +7,16 @@
|
|||||||
module.exports = scope => {
|
module.exports = scope => {
|
||||||
function generateRoutes() {
|
function generateRoutes() {
|
||||||
return {
|
return {
|
||||||
routes: [{
|
routes: [
|
||||||
method: 'GET',
|
{
|
||||||
path: '/',
|
method: 'GET',
|
||||||
handler: scope.globalID + '.index',
|
path: '/',
|
||||||
config: {
|
handler: scope.name + '.index',
|
||||||
policies: []
|
config: {
|
||||||
}
|
policies: [],
|
||||||
}]
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const { nameToSlug } = require('strapi-utils');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This `before` function is run before generating targets.
|
* This `before` function is run before generating targets.
|
||||||
@ -22,20 +23,12 @@ module.exports = (scope, cb) => {
|
|||||||
return cb.invalid('Usage: `$ strapi generate:plugin pluginName`');
|
return cb.invalid('Usage: `$ strapi generate:plugin pluginName`');
|
||||||
}
|
}
|
||||||
|
|
||||||
// `scope.args` are the raw command line arguments.
|
// Format `id`.
|
||||||
_.defaults(scope, {
|
const name = scope.name || nameToSlug(scope.id);
|
||||||
id: _.trim(_.deburr(scope.id)),
|
|
||||||
});
|
|
||||||
|
|
||||||
// Determine default values based on the available scope.
|
|
||||||
_.defaults(scope, {
|
|
||||||
globalID: _.upperFirst(_.camelCase(scope.id)),
|
|
||||||
ext: '.js',
|
|
||||||
});
|
|
||||||
|
|
||||||
// Plugin info.
|
// Plugin info.
|
||||||
_.defaults(scope, {
|
_.defaults(scope, {
|
||||||
name: scope.args.name || scope.id,
|
name,
|
||||||
author: scope.author || 'A Strapi developer',
|
author: scope.author || 'A Strapi developer',
|
||||||
email: scope.email || '',
|
email: scope.email || '',
|
||||||
year: new Date().getFullYear(),
|
year: new Date().getFullYear(),
|
||||||
@ -44,23 +37,15 @@ module.exports = (scope, cb) => {
|
|||||||
|
|
||||||
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
||||||
_.defaults(scope, {
|
_.defaults(scope, {
|
||||||
filename: `${scope.globalID}${scope.ext}`,
|
filename: `${name}.js`,
|
||||||
});
|
filePath: './plugins',
|
||||||
|
|
||||||
// Humanize output.
|
|
||||||
_.defaults(scope, {
|
|
||||||
humanizeId: scope.id.toLowerCase(),
|
|
||||||
humanizedPath: '`./plugins`',
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const pluginDir = path.resolve(scope.rootPath, 'plugins');
|
const pluginDir = path.resolve(scope.rootPath, 'plugins');
|
||||||
fs.ensureDirSync(pluginDir);
|
fs.ensureDirSync(pluginDir);
|
||||||
|
|
||||||
// Copy the admin files.
|
// Copy the admin files.
|
||||||
fs.copySync(
|
fs.copySync(path.resolve(__dirname, '..', 'files'), path.resolve(pluginDir, name));
|
||||||
path.resolve(__dirname, '..', 'files'),
|
|
||||||
path.resolve(pluginDir, scope.humanizeId)
|
|
||||||
);
|
|
||||||
|
|
||||||
// Trigger callback with no error to proceed.
|
// Trigger callback with no error to proceed.
|
||||||
return cb.success();
|
return cb.success();
|
||||||
|
@ -19,42 +19,42 @@ module.exports = {
|
|||||||
templatesDirectory: path.resolve(__dirname, '..', 'templates'),
|
templatesDirectory: path.resolve(__dirname, '..', 'templates'),
|
||||||
before: require('./before'),
|
before: require('./before'),
|
||||||
targets: {
|
targets: {
|
||||||
'plugins/:humanizeId/.gitignore': {
|
'plugins/:name/.gitignore': {
|
||||||
copy: 'gitignore',
|
copy: 'gitignore',
|
||||||
},
|
},
|
||||||
|
|
||||||
// Use the default `controller` file as a template for
|
// Use the default `controller` file as a template for
|
||||||
// every generated controller.
|
// every generated controller.
|
||||||
'plugins/:humanizeId/controllers/:filename': {
|
'plugins/:name/controllers/:filename': {
|
||||||
template: 'controller.template',
|
template: 'controller.template',
|
||||||
},
|
},
|
||||||
|
|
||||||
// every generated controller.
|
// every generated controller.
|
||||||
'plugins/:humanizeId/services/:filename': {
|
'plugins/:name/services/:filename': {
|
||||||
template: 'service.template',
|
template: 'service.template',
|
||||||
},
|
},
|
||||||
|
|
||||||
// Generate routes.
|
// Generate routes.
|
||||||
'plugins/:humanizeId/config/routes.json': {
|
'plugins/:name/config/routes.json': {
|
||||||
jsonfile: routesJSON,
|
jsonfile: routesJSON,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Main package.
|
// Main package.
|
||||||
'plugins/:humanizeId/package.json': {
|
'plugins/:name/package.json': {
|
||||||
jsonfile: packageJSON,
|
jsonfile: packageJSON,
|
||||||
},
|
},
|
||||||
|
|
||||||
// Copy dot files.
|
// Copy dot files.
|
||||||
'plugins/:humanizeId/.editorconfig': {
|
'plugins/:name/.editorconfig': {
|
||||||
copy: 'editorconfig',
|
copy: 'editorconfig',
|
||||||
},
|
},
|
||||||
|
|
||||||
'plugins/:humanizeId/.gitattributes': {
|
'plugins/:name/.gitattributes': {
|
||||||
copy: 'gitattributes',
|
copy: 'gitattributes',
|
||||||
},
|
},
|
||||||
|
|
||||||
// Copy Markdown files with some information.
|
// Copy Markdown files with some information.
|
||||||
'plugins/:humanizeId/README.md': {
|
'plugins/:name/README.md': {
|
||||||
template: 'README.md',
|
template: 'README.md',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fs-extra": "^8.0.1",
|
"fs-extra": "^8.0.1",
|
||||||
"lodash": "^4.17.11"
|
"lodash": "^4.17.11",
|
||||||
|
"strapi-utils": "^3.0.0-beta.19.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"no tests yet\""
|
"test": "echo \"no tests yet\""
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
/**
|
/**
|
||||||
* <%= filename %> controller
|
* <%= filename %> controller
|
||||||
*
|
*
|
||||||
* @description: A set of functions called "actions" of the `<%= humanizeId %>` plugin.
|
* @description: A set of functions called "actions" of the `<%= name %>` plugin.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const { nameToSlug } = require('strapi-utils');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This `before` function is run before generating targets.
|
* This `before` function is run before generating targets.
|
||||||
@ -18,9 +19,14 @@ const _ = require('lodash');
|
|||||||
/* eslint-disable prefer-template */
|
/* eslint-disable prefer-template */
|
||||||
module.exports = (scope, cb) => {
|
module.exports = (scope, cb) => {
|
||||||
if (!scope.rootPath || !scope.id) {
|
if (!scope.rootPath || !scope.id) {
|
||||||
return cb.invalid('Usage: `$ strapi generate:policy policyName --api apiName --plugin pluginName`');
|
return cb.invalid(
|
||||||
|
'Usage: `$ strapi generate:policy policyName --api apiName --plugin pluginName`'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format `id`.
|
||||||
|
const name = scope.name || nameToSlug(scope.id);
|
||||||
|
|
||||||
let filePath;
|
let filePath;
|
||||||
if (scope.args.api) {
|
if (scope.args.api) {
|
||||||
filePath = `./api/${scope.args.api}/config/policies`;
|
filePath = `./api/${scope.args.api}/config/policies`;
|
||||||
@ -30,21 +36,11 @@ module.exports = (scope, cb) => {
|
|||||||
filePath = './config/policies';
|
filePath = './config/policies';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determine default values based on the available scope.
|
|
||||||
_.defaults(scope, {
|
|
||||||
ext: '.js'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
||||||
_.defaults(scope, {
|
_.defaults(scope, {
|
||||||
|
name,
|
||||||
filePath,
|
filePath,
|
||||||
filename: scope.id + scope.ext
|
filename: `${name}.js`,
|
||||||
});
|
|
||||||
|
|
||||||
// Humanize output.
|
|
||||||
_.defaults(scope, {
|
|
||||||
humanizeId: scope.id,
|
|
||||||
humanizedPath: '`' + scope.filePath + '`'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger callback with no error to proceed.
|
// Trigger callback with no error to proceed.
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
"lib": "./lib"
|
"lib": "./lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.11"
|
"lodash": "^4.17.11",
|
||||||
|
"strapi-utils": "^3.0.0-beta.19.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"no tests yet\""
|
"test": "echo \"no tests yet\""
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
// Public node modules.
|
// Public node modules.
|
||||||
const _ = require('lodash');
|
const _ = require('lodash');
|
||||||
|
const { nameToSlug } = require('strapi-utils');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This `before` function is run before generating targets.
|
* This `before` function is run before generating targets.
|
||||||
@ -18,19 +19,18 @@ const _ = require('lodash');
|
|||||||
/* eslint-disable prefer-template */
|
/* eslint-disable prefer-template */
|
||||||
module.exports = (scope, cb) => {
|
module.exports = (scope, cb) => {
|
||||||
if (!scope.rootPath || !scope.id) {
|
if (!scope.rootPath || !scope.id) {
|
||||||
return cb.invalid('Usage: `$ strapi generate:service serviceName --api apiName --plugin pluginName`');
|
return cb.invalid(
|
||||||
|
'Usage: `$ strapi generate:service serviceName --api apiName --plugin pluginName`'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Format `id`.
|
||||||
|
const name = scope.name || nameToSlug(scope.id);
|
||||||
|
|
||||||
// `scope.args` are the raw command line arguments.
|
// `scope.args` are the raw command line arguments.
|
||||||
_.defaults(scope, {
|
_.defaults(scope, {
|
||||||
id: _.trim(_.deburr(scope.id)),
|
name,
|
||||||
api: scope.args.api || scope.id
|
api: scope.args.api || scope.id,
|
||||||
});
|
|
||||||
|
|
||||||
// Determine default values based on the available scope.
|
|
||||||
_.defaults(scope, {
|
|
||||||
globalID: _.upperFirst(_.camelCase(scope.id)),
|
|
||||||
ext: '.js'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Determine the destination path.
|
// Determine the destination path.
|
||||||
@ -40,20 +40,14 @@ module.exports = (scope, cb) => {
|
|||||||
} else if (scope.args.plugin) {
|
} else if (scope.args.plugin) {
|
||||||
filePath = `./plugins/${scope.args.plugin}/services`;
|
filePath = `./plugins/${scope.args.plugin}/services`;
|
||||||
} else {
|
} else {
|
||||||
filePath = `./api/${scope.id}/services`;
|
filePath = `./api/${name}/services`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
// Take another pass to take advantage of the defaults absorbed in previous passes.
|
||||||
_.defaults(scope, {
|
_.defaults(scope, {
|
||||||
rootPath: scope.rootPath,
|
rootPath: scope.rootPath,
|
||||||
filePath,
|
filePath,
|
||||||
filename: scope.globalID + scope.ext
|
filename: `${name}.js`,
|
||||||
});
|
|
||||||
|
|
||||||
// Humanize output.
|
|
||||||
_.defaults(scope, {
|
|
||||||
humanizeId: _.camelCase(scope.id).toLowerCase(),
|
|
||||||
humanizedPath: '`' + scope.filePath + '`'
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Trigger callback with no error to proceed.
|
// Trigger callback with no error to proceed.
|
||||||
|
@ -16,7 +16,10 @@ module.exports = {
|
|||||||
templatesDirectory: scope => {
|
templatesDirectory: scope => {
|
||||||
try {
|
try {
|
||||||
// Try to reach the path. If it fail, throw an error.
|
// Try to reach the path. If it fail, throw an error.
|
||||||
fs.accessSync(path.resolve(__dirname, '..', 'templates', scope.args.tpl), fs.constants.R_OK | fs.constants.W_OK);
|
fs.accessSync(
|
||||||
|
path.resolve(__dirname, '..', 'templates', scope.args.tpl),
|
||||||
|
fs.constants.R_OK | fs.constants.W_OK
|
||||||
|
);
|
||||||
|
|
||||||
return path.resolve(__dirname, '..', 'templates', scope.args.tpl);
|
return path.resolve(__dirname, '..', 'templates', scope.args.tpl);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@ -26,8 +29,8 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
before: require('./before'),
|
before: require('./before'),
|
||||||
targets: {
|
targets: {
|
||||||
'api/:api/services/:filename': {
|
':filePath/:filename': {
|
||||||
template: 'service.template'
|
template: 'service.template',
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
"lib": "./lib"
|
"lib": "./lib"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lodash": "^4.17.11"
|
"lodash": "^4.17.11",
|
||||||
|
"strapi-utils": "^3.0.0-beta.19.3"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "echo \"no tests yet\""
|
"test": "echo \"no tests yet\""
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `<%= globalID %>` service.
|
* `<%= name %>` service.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `<%= globalID %>` service.
|
* `<%= name %>` service.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -30,7 +30,7 @@ function generate(generator, scope, cb) {
|
|||||||
const sb = reportback.extend(cb, {
|
const sb = reportback.extend(cb, {
|
||||||
error: cb.error,
|
error: cb.error,
|
||||||
invalid: cb.invalid,
|
invalid: cb.invalid,
|
||||||
alreadyExists: 'error'
|
alreadyExists: 'error',
|
||||||
});
|
});
|
||||||
|
|
||||||
// Resolve string shorthand for generator defs
|
// Resolve string shorthand for generator defs
|
||||||
@ -38,119 +38,151 @@ function generate(generator, scope, cb) {
|
|||||||
if (typeof generator === 'string') {
|
if (typeof generator === 'string') {
|
||||||
const generatorName = generator;
|
const generatorName = generator;
|
||||||
generator = {
|
generator = {
|
||||||
generator: generatorName
|
generator: generatorName,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Run the generator's `before()` method proceeding.
|
// Run the generator's `before()` method proceeding.
|
||||||
generator.before(scope, reportback.extend({
|
generator.before(
|
||||||
error: sb.error,
|
scope,
|
||||||
invalid: sb.invalid,
|
reportback.extend({
|
||||||
success: () => {
|
error: sb.error,
|
||||||
|
invalid: sb.invalid,
|
||||||
|
success: () => {
|
||||||
|
// Process all of the generator's targets concurrently.
|
||||||
|
async.each(
|
||||||
|
Object.keys(generator.targets),
|
||||||
|
(keyPath, asyncEachCb) => {
|
||||||
|
const asyncEachSb = reportback.extend(asyncEachCb);
|
||||||
|
|
||||||
// Process all of the generator's targets concurrently.
|
// Create a new scope object for this target,
|
||||||
async.each(Object.keys(generator.targets), (keyPath, asyncEachCb) => {
|
// with references to the important bits of the original
|
||||||
const asyncEachSb = reportback.extend(asyncEachCb);
|
// (depth will be passed-by-value, but that's what we want).
|
||||||
|
// Then generate the target, passing along a reference to
|
||||||
// Create a new scope object for this target,
|
// the base `generate` method to allow for recursive generators.
|
||||||
// with references to the important bits of the original
|
const target = generator.targets[keyPath];
|
||||||
// (depth will be passed-by-value, but that's what we want).
|
if (!target) {
|
||||||
// Then generate the target, passing along a reference to
|
return asyncEachSb(
|
||||||
// the base `generate` method to allow for recursive generators.
|
new Error(
|
||||||
const target = generator.targets[keyPath];
|
'Error: Invalid target: {"' + keyPath + '": ' + util.inspect(target) + '}'
|
||||||
if (!target) {
|
)
|
||||||
return asyncEachSb(new Error('Error: Invalid target: {"' + keyPath + '": ' + util.inspect(target) + '}'));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Input tolerance.
|
|
||||||
if (keyPath === '') {
|
|
||||||
keyPath = '.';
|
|
||||||
}
|
|
||||||
|
|
||||||
// Interpret `keyPath` using Express's parameterized route conventions,
|
|
||||||
// first parsing params, then replacing them with their proper values from scope.
|
|
||||||
const params = [];
|
|
||||||
pathRegexp(keyPath, params);
|
|
||||||
let err;
|
|
||||||
const parsedKeyPath = _.reduce(params, (memoKeyPath, param) => {
|
|
||||||
if (err) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const paramMatchExpr = ':' + param.name;
|
|
||||||
let actualParamValue = scope[param.name];
|
|
||||||
if (!actualParamValue) {
|
|
||||||
err = new Error(
|
|
||||||
'generator error:\n' +
|
|
||||||
'A scope variable (`' + param.name + '`) was referenced in target: `' + memoKeyPath + '`,\n' +
|
|
||||||
'but `' + param.name + '` does not exist in the generator\'s scope.'
|
|
||||||
);
|
);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
actualParamValue = String(actualParamValue);
|
|
||||||
|
|
||||||
return memoKeyPath.replace(paramMatchExpr, actualParamValue);
|
// Input tolerance.
|
||||||
} catch (e) {
|
if (keyPath === '') {
|
||||||
err = new Error('Error: Could not parse target key ' + memoKeyPath);
|
keyPath = '.';
|
||||||
err.message = e;
|
}
|
||||||
return false;
|
|
||||||
|
// Interpret `keyPath` using Express's parameterized route conventions,
|
||||||
|
// first parsing params, then replacing them with their proper values from scope.
|
||||||
|
const params = [];
|
||||||
|
pathRegexp(keyPath, params);
|
||||||
|
let err;
|
||||||
|
const parsedKeyPath = _.reduce(
|
||||||
|
params,
|
||||||
|
(memoKeyPath, param) => {
|
||||||
|
if (err) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const paramMatchExpr = ':' + param.name;
|
||||||
|
let actualParamValue = scope[param.name];
|
||||||
|
if (!actualParamValue) {
|
||||||
|
err = new Error(
|
||||||
|
'generator error:\n' +
|
||||||
|
'A scope variable (`' +
|
||||||
|
param.name +
|
||||||
|
'`) was referenced in target: `' +
|
||||||
|
memoKeyPath +
|
||||||
|
'`,\n' +
|
||||||
|
'but `' +
|
||||||
|
param.name +
|
||||||
|
"` does not exist in the generator's scope."
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
actualParamValue = String(actualParamValue);
|
||||||
|
|
||||||
|
return memoKeyPath.replace(paramMatchExpr, actualParamValue);
|
||||||
|
} catch (e) {
|
||||||
|
err = new Error('Error: Could not parse target key ' + memoKeyPath);
|
||||||
|
err.message = e;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
keyPath
|
||||||
|
);
|
||||||
|
if (!parsedKeyPath) {
|
||||||
|
return asyncEachSb(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create path from `rootPath` to `keyPath` to use as the `rootPath`
|
||||||
|
// for any generators or helpers in this target
|
||||||
|
// (use a copy so that child generators don't mutate the scope).
|
||||||
|
const targetScope = _.merge({}, scope, {
|
||||||
|
rootPath: path.resolve(scope.rootPath, parsedKeyPath),
|
||||||
|
|
||||||
|
// Include reference to original keypath for error reporting.
|
||||||
|
keyPath,
|
||||||
|
});
|
||||||
|
|
||||||
|
// If `target` is an array, run each item.
|
||||||
|
if (_.isArray(target)) {
|
||||||
|
async.eachSeries(
|
||||||
|
target,
|
||||||
|
(targetItem, asyncEachSeriesCb) => {
|
||||||
|
generateTarget(
|
||||||
|
{
|
||||||
|
target: targetItem,
|
||||||
|
parent: generator,
|
||||||
|
scope: _.cloneDeep(targetScope),
|
||||||
|
recursiveGenerate: generate,
|
||||||
|
},
|
||||||
|
asyncEachSeriesCb
|
||||||
|
);
|
||||||
|
},
|
||||||
|
asyncEachSb
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, just run the single target generator/helper.
|
||||||
|
generateTarget(
|
||||||
|
{
|
||||||
|
target,
|
||||||
|
parent: generator,
|
||||||
|
scope: targetScope,
|
||||||
|
recursiveGenerate: generate,
|
||||||
|
},
|
||||||
|
asyncEachSb
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
err => {
|
||||||
|
// Expose a `error` handler in generators.
|
||||||
|
if (err) {
|
||||||
|
const errorFn =
|
||||||
|
generator.error ||
|
||||||
|
function defaultError(err, scope, _cb) {
|
||||||
|
return _cb(err);
|
||||||
|
};
|
||||||
|
return errorFn(err, scope, sb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expose a `after` handler in generators (on success only).
|
||||||
|
const afterFn =
|
||||||
|
generator.after ||
|
||||||
|
function defaultAfter(scope, _cb) {
|
||||||
|
return _cb();
|
||||||
|
};
|
||||||
|
return afterFn(scope, sb);
|
||||||
}
|
}
|
||||||
}, keyPath);
|
);
|
||||||
if (!parsedKeyPath) {
|
|
||||||
return asyncEachSb(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create path from `rootPath` to `keyPath` to use as the `rootPath`
|
|
||||||
// for any generators or helpers in this target
|
|
||||||
// (use a copy so that child generators don't mutate the scope).
|
|
||||||
const targetScope = _.merge({}, scope, {
|
|
||||||
rootPath: path.resolve(scope.rootPath, parsedKeyPath),
|
|
||||||
|
|
||||||
// Include reference to original keypath for error reporting.
|
|
||||||
keyPath
|
|
||||||
});
|
|
||||||
|
|
||||||
// If `target` is an array, run each item.
|
|
||||||
if (_.isArray(target)) {
|
|
||||||
async.eachSeries(target, (targetItem, asyncEachSeriesCb) => {
|
|
||||||
generateTarget({
|
|
||||||
target: targetItem,
|
|
||||||
parent: generator,
|
|
||||||
scope: _.cloneDeep(targetScope),
|
|
||||||
recursiveGenerate: generate
|
|
||||||
}, asyncEachSeriesCb);
|
|
||||||
}, asyncEachSb);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, just run the single target generator/helper.
|
|
||||||
generateTarget({
|
|
||||||
target,
|
|
||||||
parent: generator,
|
|
||||||
scope: targetScope,
|
|
||||||
recursiveGenerate: generate
|
|
||||||
}, asyncEachSb);
|
|
||||||
},
|
},
|
||||||
|
})
|
||||||
err => {
|
);
|
||||||
|
|
||||||
// Expose a `error` handler in generators.
|
|
||||||
if (err) {
|
|
||||||
const errorFn = generator.error || function defaultError(err, scope, _cb) {
|
|
||||||
return _cb(err);
|
|
||||||
};
|
|
||||||
return errorFn(err, scope, sb);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Expose a `after` handler in generators (on success only).
|
|
||||||
const afterFn = generator.after || function defaultAfter(scope, _cb) {
|
|
||||||
return _cb();
|
|
||||||
};
|
|
||||||
return afterFn(scope, sb);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = generate;
|
module.exports = generate;
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const { join } = require('path');
|
const { join } = require('path');
|
||||||
|
|
||||||
const { nameToSlug } = require('../utils/helpers');
|
const { nameToSlug } = require('strapi-utils');
|
||||||
const createBuilder = require('./schema-builder');
|
const createBuilder = require('./schema-builder');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,7 +7,7 @@ const generator = require('strapi-generate');
|
|||||||
const createBuilder = require('./schema-builder');
|
const createBuilder = require('./schema-builder');
|
||||||
const apiHandler = require('./api-handler');
|
const apiHandler = require('./api-handler');
|
||||||
const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes');
|
const { formatAttributes, replaceTemporaryUIDs } = require('../utils/attributes');
|
||||||
const { nameToSlug } = require('../utils/helpers');
|
const { nameToSlug } = require('strapi-utils');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format a contentType info to be used by the front-end
|
* Format a contentType info to be used by the front-end
|
||||||
|
@ -5,7 +5,7 @@ const _ = require('lodash');
|
|||||||
const pluralize = require('pluralize');
|
const pluralize = require('pluralize');
|
||||||
|
|
||||||
const { isConfigurable } = require('../../utils/attributes');
|
const { isConfigurable } = require('../../utils/attributes');
|
||||||
const { nameToSlug, nameToCollectionName } = require('../../utils/helpers');
|
const { nameToSlug, nameToCollectionName } = require('strapi-utils');
|
||||||
const createSchemaHandler = require('./schema-handler');
|
const createSchemaHandler = require('./schema-handler');
|
||||||
|
|
||||||
module.exports = function createComponentBuilder() {
|
module.exports = function createComponentBuilder() {
|
||||||
|
@ -5,7 +5,7 @@ const _ = require('lodash');
|
|||||||
const pluralize = require('pluralize');
|
const pluralize = require('pluralize');
|
||||||
|
|
||||||
const { isRelation, toUID, isConfigurable } = require('../../utils/attributes');
|
const { isRelation, toUID, isConfigurable } = require('../../utils/attributes');
|
||||||
const { nameToSlug, nameToCollectionName } = require('../../utils/helpers');
|
const { nameToSlug, nameToCollectionName } = require('strapi-utils');
|
||||||
const { typeKinds } = require('../../controllers/validation/constants');
|
const { typeKinds } = require('../../controllers/validation/constants');
|
||||||
const createSchemaHandler = require('./schema-handler');
|
const createSchemaHandler = require('./schema-handler');
|
||||||
|
|
||||||
@ -69,9 +69,7 @@ module.exports = function createComponentBuilder() {
|
|||||||
'default'
|
'default'
|
||||||
);
|
);
|
||||||
|
|
||||||
const defaultCollectionName = `${nameToCollectionName(
|
const defaultCollectionName = `${nameToCollectionName(pluralize(infos.name))}`;
|
||||||
pluralize(infos.name)
|
|
||||||
)}`;
|
|
||||||
|
|
||||||
// support self referencing content type relation
|
// support self referencing content type relation
|
||||||
Object.keys(infos.attributes).forEach(key => {
|
Object.keys(infos.attributes).forEach(key => {
|
||||||
@ -125,31 +123,18 @@ module.exports = function createComponentBuilder() {
|
|||||||
return _.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);
|
return _.has(oldAttributes, key) && !isConfigurable(oldAttributes[key]);
|
||||||
});
|
});
|
||||||
|
|
||||||
const newKeys = _.difference(
|
const newKeys = _.difference(Object.keys(newAttributes), Object.keys(oldAttributes));
|
||||||
Object.keys(newAttributes),
|
|
||||||
Object.keys(oldAttributes)
|
|
||||||
);
|
|
||||||
|
|
||||||
const deletedKeys = _.difference(
|
const deletedKeys = _.difference(Object.keys(oldAttributes), Object.keys(newAttributes));
|
||||||
Object.keys(oldAttributes),
|
|
||||||
Object.keys(newAttributes)
|
|
||||||
);
|
|
||||||
|
|
||||||
const remainingKeys = _.intersection(
|
const remainingKeys = _.intersection(Object.keys(oldAttributes), Object.keys(newAttributes));
|
||||||
Object.keys(oldAttributes),
|
|
||||||
Object.keys(newAttributes)
|
|
||||||
);
|
|
||||||
|
|
||||||
// remove old relations
|
// remove old relations
|
||||||
deletedKeys.forEach(key => {
|
deletedKeys.forEach(key => {
|
||||||
const attribute = oldAttributes[key];
|
const attribute = oldAttributes[key];
|
||||||
|
|
||||||
// if the old relation has a target attribute. we need to remove it
|
// if the old relation has a target attribute. we need to remove it
|
||||||
if (
|
if (isConfigurable(attribute) && isRelation(attribute) && _.has(attribute, 'via')) {
|
||||||
isConfigurable(attribute) &&
|
|
||||||
isRelation(attribute) &&
|
|
||||||
_.has(attribute, 'via')
|
|
||||||
) {
|
|
||||||
this.unsetRelation(attribute);
|
this.unsetRelation(attribute);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -172,15 +157,11 @@ module.exports = function createComponentBuilder() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isRelation(oldAttribute) && isRelation(newAttribute)) {
|
if (isRelation(oldAttribute) && isRelation(newAttribute)) {
|
||||||
if (
|
if (_.has(oldAttribute, 'via') && oldAttribute.via !== newAttribute.targetAttribute) {
|
||||||
_.has(oldAttribute, 'via') &&
|
|
||||||
oldAttribute.via !== newAttribute.targetAttribute
|
|
||||||
) {
|
|
||||||
this.unsetRelation(oldAttribute);
|
this.unsetRelation(oldAttribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
newAttribute.autoPopulate =
|
newAttribute.autoPopulate = newAttribute.autoPopulate || oldAttribute.autoPopulate;
|
||||||
newAttribute.autoPopulate || oldAttribute.autoPopulate;
|
|
||||||
|
|
||||||
return this.setRelation({
|
return this.setRelation({
|
||||||
key,
|
key,
|
||||||
@ -239,16 +220,9 @@ module.exports = function createComponentBuilder() {
|
|||||||
* @param {Object} options options
|
* @param {Object} options options
|
||||||
* @param {string} options.name component name
|
* @param {string} options.name component name
|
||||||
*/
|
*/
|
||||||
const createContentTypeUID = ({ name }) =>
|
const createContentTypeUID = ({ name }) => `application::${nameToSlug(name)}.${nameToSlug(name)}`;
|
||||||
`application::${nameToSlug(name)}.${nameToSlug(name)}`;
|
|
||||||
|
|
||||||
const generateRelation = ({
|
const generateRelation = ({ key, attribute, plugin, modelName, targetAttribute = {} }) => {
|
||||||
key,
|
|
||||||
attribute,
|
|
||||||
plugin,
|
|
||||||
modelName,
|
|
||||||
targetAttribute = {},
|
|
||||||
}) => {
|
|
||||||
const opts = {
|
const opts = {
|
||||||
via: key,
|
via: key,
|
||||||
plugin,
|
plugin,
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const slugify = require('@sindresorhus/slugify');
|
|
||||||
|
|
||||||
const escapeNewlines = (content = '', placeholder = '\n') => {
|
const escapeNewlines = (content = '', placeholder = '\n') => {
|
||||||
return content.replace(/[\r\n]+/g, placeholder);
|
return content.replace(/[\r\n]+/g, placeholder);
|
||||||
};
|
};
|
||||||
@ -26,13 +24,8 @@ const deepTrimObject = attribute => {
|
|||||||
* Converts a name to a slug
|
* Converts a name to a slug
|
||||||
* @param {string} name a name to convert
|
* @param {string} name a name to convert
|
||||||
*/
|
*/
|
||||||
const nameToSlug = name => slugify(name, { separator: '-' });
|
|
||||||
|
|
||||||
const nameToCollectionName = name => slugify(name, { separator: '_' });
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
escapeNewlines,
|
escapeNewlines,
|
||||||
deepTrimObject,
|
deepTrimObject,
|
||||||
nameToSlug,
|
|
||||||
nameToCollectionName,
|
|
||||||
};
|
};
|
||||||
|
@ -48,8 +48,8 @@ module.exports = {
|
|||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
// Default values.
|
// Default values.
|
||||||
options = _.isObject(options) ? options : {};
|
options = _.isObject(options) ? options : {};
|
||||||
options.from = options.from || config.amazon_ses_default_from;
|
options.from = config.amazon_ses_default_from || options.from;
|
||||||
options.replyTo = options.replyTo || config.amazon_ses_default_replyto;
|
options.replyTo = config.amazon_ses_default_replyto || options.replyTo;
|
||||||
options.text = options.text || options.html;
|
options.text = options.text || options.html;
|
||||||
options.html = options.html || options.text;
|
options.html = options.html || options.text;
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@ const models = require('./models');
|
|||||||
const policy = require('./policy');
|
const policy = require('./policy');
|
||||||
const templateConfiguration = require('./templateConfiguration');
|
const templateConfiguration = require('./templateConfiguration');
|
||||||
const { yup, formatYupErrors } = require('./validators');
|
const { yup, formatYupErrors } = require('./validators');
|
||||||
|
const { nameToSlug, nameToCollectionName } = require('./stringFormatting');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
yup,
|
yup,
|
||||||
@ -29,4 +30,6 @@ module.exports = {
|
|||||||
parseMultipartData,
|
parseMultipartData,
|
||||||
sanitizeEntity,
|
sanitizeEntity,
|
||||||
parseType,
|
parseType,
|
||||||
|
nameToSlug,
|
||||||
|
nameToCollectionName,
|
||||||
};
|
};
|
||||||
|
12
packages/strapi-utils/lib/stringFormatting.js
Normal file
12
packages/strapi-utils/lib/stringFormatting.js
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
const slugify = require('@sindresorhus/slugify');
|
||||||
|
|
||||||
|
const nameToSlug = name => slugify(name, { separator: '-' });
|
||||||
|
|
||||||
|
const nameToCollectionName = name => slugify(name, { separator: '_' });
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
nameToSlug,
|
||||||
|
nameToCollectionName,
|
||||||
|
};
|
@ -14,6 +14,7 @@
|
|||||||
},
|
},
|
||||||
"main": "./lib",
|
"main": "./lib",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@sindresorhus/slugify": "^0.11.0",
|
||||||
"date-fns": "^2.8.1",
|
"date-fns": "^2.8.1",
|
||||||
"lodash": "4.17.12",
|
"lodash": "4.17.12",
|
||||||
"pino": "^4.7.1",
|
"pino": "^4.7.1",
|
||||||
|
@ -56,14 +56,8 @@ module.exports = function(id, cliArguments) {
|
|||||||
|
|
||||||
if (scope.generatorType !== 'new') {
|
if (scope.generatorType !== 'new') {
|
||||||
logger.info(
|
logger.info(
|
||||||
'Generated a new ' +
|
`Generated a new ${scope.generatorType} \`${scope.name}\` at \`${scope.filePath}\`.`
|
||||||
scope.generatorType +
|
);
|
||||||
' `' +
|
|
||||||
scope.humanizeId +
|
|
||||||
'` at ' +
|
|
||||||
scope.humanizedPath +
|
|
||||||
'.'
|
|
||||||
); // eslint-disable-line prefer-template
|
|
||||||
}
|
}
|
||||||
|
|
||||||
process.exit(0);
|
process.exit(0);
|
||||||
|
21
yarn.lock
21
yarn.lock
@ -2408,6 +2408,22 @@
|
|||||||
escape-string-regexp "^1.0.5"
|
escape-string-regexp "^1.0.5"
|
||||||
lodash.deburr "^4.1.0"
|
lodash.deburr "^4.1.0"
|
||||||
|
|
||||||
|
"@sindresorhus/slugify@^0.11.0":
|
||||||
|
version "0.11.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sindresorhus/slugify/-/slugify-0.11.0.tgz#642acb99adefa4187285fd17de88745afc161de8"
|
||||||
|
integrity sha512-ECTZT6z1hYDsopRh8GECaQ5L6hoJHVd4uq5hPi8se9GB31tgtZfnlM8G64hZVhJNmtJ9eIK0SuNhtsaPQStXEQ==
|
||||||
|
dependencies:
|
||||||
|
"@sindresorhus/transliterate" "^0.1.0"
|
||||||
|
escape-string-regexp "^2.0.0"
|
||||||
|
|
||||||
|
"@sindresorhus/transliterate@^0.1.0":
|
||||||
|
version "0.1.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/@sindresorhus/transliterate/-/transliterate-0.1.0.tgz#c063bfc4102783fb19c91c2f8c1efb3adfb754be"
|
||||||
|
integrity sha512-bO6v0M0EuJPjm5Ntfow4nk+r3EZQ41n0ahvAmh766FzPqlm6V/2uDc01vZI3gLeI/1lgV2BTMb6QvxOk9z73ng==
|
||||||
|
dependencies:
|
||||||
|
escape-string-regexp "^2.0.0"
|
||||||
|
lodash.deburr "^4.1.0"
|
||||||
|
|
||||||
"@snyk/cli-interface@1.5.0":
|
"@snyk/cli-interface@1.5.0":
|
||||||
version "1.5.0"
|
version "1.5.0"
|
||||||
resolved "https://registry.yarnpkg.com/@snyk/cli-interface/-/cli-interface-1.5.0.tgz#b9dbe6ebfb86e67ffabf29d4e0d28a52670ac456"
|
resolved "https://registry.yarnpkg.com/@snyk/cli-interface/-/cli-interface-1.5.0.tgz#b9dbe6ebfb86e67ffabf29d4e0d28a52670ac456"
|
||||||
@ -6943,6 +6959,11 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5:
|
|||||||
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4"
|
||||||
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
|
integrity sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=
|
||||||
|
|
||||||
|
escape-string-regexp@^2.0.0:
|
||||||
|
version "2.0.0"
|
||||||
|
resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-2.0.0.tgz#a30304e99daa32e23b2fd20f51babd07cffca344"
|
||||||
|
integrity sha512-UpzcLCXolUWcNu5HtVMHYdXJjArjsF9C0aNnquZYY4uW/Vu0miy5YoWvbV345HauVvcAUnpRuhMMcqTcGOY2+w==
|
||||||
|
|
||||||
escodegen@1.8.x:
|
escodegen@1.8.x:
|
||||||
version "1.8.1"
|
version "1.8.1"
|
||||||
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.8.1.tgz#5a5b53af4693110bebb0867aa3430dd3b70a1018"
|
resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.8.1.tgz#5a5b53af4693110bebb0867aa3430dd3b70a1018"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user