@strapi/generators 4.10.1 → 4.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/files/js/plugin/.editorconfig +7 -0
- package/dist/files/js/plugin/.gitattributes +103 -0
- package/dist/files/ts/plugin/.editorconfig +7 -0
- package/dist/files/ts/plugin/.gitattributes +103 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -0
- package/dist/plopfile.d.ts +3 -0
- package/dist/plopfile.js +29 -0
- package/dist/plopfile.js.map +1 -0
- package/dist/plops/api.d.ts +3 -0
- package/dist/plops/api.js +79 -0
- package/dist/plops/api.js.map +1 -0
- package/dist/plops/content-type.d.ts +3 -0
- package/dist/plops/content-type.js +135 -0
- package/dist/plops/content-type.js.map +1 -0
- package/dist/plops/controller.d.ts +3 -0
- package/dist/plops/controller.js +40 -0
- package/dist/plops/controller.js.map +1 -0
- package/dist/plops/middleware.d.ts +3 -0
- package/dist/plops/middleware.js +40 -0
- package/dist/plops/middleware.js.map +1 -0
- package/dist/plops/migration.d.ts +3 -0
- package/dist/plops/migration.js +35 -0
- package/dist/plops/migration.js.map +1 -0
- package/dist/plops/plugin.d.ts +3 -0
- package/dist/plops/plugin.js +84 -0
- package/dist/plops/plugin.js.map +1 -0
- package/dist/plops/policy.d.ts +3 -0
- package/dist/plops/policy.js +40 -0
- package/dist/plops/policy.js.map +1 -0
- package/dist/plops/prompts/bootstrap-api-prompts.d.ts +3 -0
- package/dist/plops/prompts/bootstrap-api-prompts.js +12 -0
- package/dist/plops/prompts/bootstrap-api-prompts.js.map +1 -0
- package/dist/plops/prompts/ct-names-prompts.d.ts +3 -0
- package/dist/plops/prompts/ct-names-prompts.js +45 -0
- package/dist/plops/prompts/ct-names-prompts.js.map +1 -0
- package/dist/plops/prompts/draft-and-publish-prompts.d.ts +3 -0
- package/dist/plops/prompts/draft-and-publish-prompts.js +12 -0
- package/dist/plops/prompts/draft-and-publish-prompts.js.map +1 -0
- package/dist/plops/prompts/get-attributes-prompts.d.ts +3 -0
- package/dist/plops/prompts/get-attributes-prompts.js +95 -0
- package/dist/plops/prompts/get-attributes-prompts.js.map +1 -0
- package/dist/plops/prompts/get-destination-prompts.d.ts +5 -0
- package/dist/plops/prompts/get-destination-prompts.js +72 -0
- package/dist/plops/prompts/get-destination-prompts.js.map +1 -0
- package/dist/plops/prompts/kind-prompts.d.ts +3 -0
- package/dist/plops/prompts/kind-prompts.js +21 -0
- package/dist/plops/prompts/kind-prompts.js.map +1 -0
- package/dist/plops/service.d.ts +3 -0
- package/dist/plops/service.js +38 -0
- package/dist/plops/service.js.map +1 -0
- package/dist/plops/utils/get-file-path.d.ts +2 -0
- package/dist/plops/utils/get-file-path.js +15 -0
- package/dist/plops/utils/get-file-path.js.map +1 -0
- package/dist/plops/utils/get-formatted-date.d.ts +2 -0
- package/dist/plops/utils/get-formatted-date.js +9 -0
- package/dist/plops/utils/get-formatted-date.js.map +1 -0
- package/dist/plops/utils/validate-attribute-input.d.ts +2 -0
- package/dist/plops/utils/validate-attribute-input.js +10 -0
- package/dist/plops/utils/validate-attribute-input.js.map +1 -0
- package/dist/plops/utils/validate-file-name-input.d.ts +2 -0
- package/dist/plops/utils/validate-file-name-input.js +10 -0
- package/dist/plops/utils/validate-file-name-input.js.map +1 -0
- package/dist/plops/utils/validate-input.d.ts +2 -0
- package/dist/plops/utils/validate-input.js +10 -0
- package/dist/plops/utils/validate-input.js.map +1 -0
- package/package.json +22 -5
- package/.eslintignore +0 -3
- package/.eslintrc.js +0 -4
- package/lib/index.js +0 -37
- package/lib/plopfile.js +0 -28
- package/lib/plops/__tests__/content-type.test.js +0 -179
- package/lib/plops/api.js +0 -82
- package/lib/plops/content-type.js +0 -148
- package/lib/plops/controller.js +0 -36
- package/lib/plops/middleware.js +0 -36
- package/lib/plops/migration.js +0 -33
- package/lib/plops/plugin.js +0 -91
- package/lib/plops/policy.js +0 -36
- package/lib/plops/prompts/bootstrap-api-prompts.js +0 -10
- package/lib/plops/prompts/ct-names-prompts.js +0 -44
- package/lib/plops/prompts/draft-and-publish-prompts.js +0 -10
- package/lib/plops/prompts/get-attributes-prompts.js +0 -105
- package/lib/plops/prompts/get-destination-prompts.js +0 -79
- package/lib/plops/prompts/kind-prompts.js +0 -17
- package/lib/plops/service.js +0 -34
- package/lib/plops/utils/__tests__/get-file-path.test.js +0 -25
- package/lib/plops/utils/get-file-path.js +0 -17
- package/lib/plops/utils/get-formatted-date.js +0 -8
- package/lib/plops/utils/validate-attribute-input.js +0 -11
- package/lib/plops/utils/validate-file-name-input.js +0 -11
- package/lib/plops/utils/validate-input.js +0 -11
- /package/{lib → dist}/files/js/plugin/admin/src/components/Initializer/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/admin/src/components/PluginIcon/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/admin/src/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/admin/src/pages/App/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/admin/src/pages/HomePage/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/admin/src/pluginId.js +0 -0
- /package/{lib → dist}/files/js/plugin/admin/src/translations/en.json +0 -0
- /package/{lib → dist}/files/js/plugin/admin/src/translations/fr.json +0 -0
- /package/{lib → dist}/files/js/plugin/admin/src/utils/getTrad.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/bootstrap.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/config/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/content-types/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/controllers/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/controllers/my-controller.js.hbs +0 -0
- /package/{lib → dist}/files/js/plugin/server/destroy.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/middlewares/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/policies/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/register.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/routes/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/services/index.js +0 -0
- /package/{lib → dist}/files/js/plugin/server/services/my-service.js +0 -0
- /package/{lib → dist}/files/js/plugin/strapi-admin.js +0 -0
- /package/{lib → dist}/files/js/plugin/strapi-server.js +0 -0
- /package/{lib → dist}/files/ts/plugin/admin/src/components/Initializer/index.tsx +0 -0
- /package/{lib → dist}/files/ts/plugin/admin/src/components/PluginIcon/index.tsx +0 -0
- /package/{lib → dist}/files/ts/plugin/admin/src/index.tsx +0 -0
- /package/{lib → dist}/files/ts/plugin/admin/src/pages/App/index.tsx +0 -0
- /package/{lib → dist}/files/ts/plugin/admin/src/pages/HomePage/index.tsx +0 -0
- /package/{lib → dist}/files/ts/plugin/admin/src/pluginId.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/admin/src/translations/en.json +0 -0
- /package/{lib → dist}/files/ts/plugin/admin/src/translations/fr.json +0 -0
- /package/{lib → dist}/files/ts/plugin/admin/src/utils/getTrad.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/custom.d.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/bootstrap.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/config/index.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/content-types/index.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/controllers/index.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/controllers/my-controller.ts.hbs +0 -0
- /package/{lib → dist}/files/ts/plugin/server/destroy.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/index.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/middlewares/index.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/policies/index.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/register.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/routes/index.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/services/index.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/server/services/my-service.ts +0 -0
- /package/{lib → dist}/files/ts/plugin/strapi-admin.js +0 -0
- /package/{lib → dist}/files/ts/plugin/strapi-server.js +0 -0
- /package/{lib → dist}/files/ts/plugin/tsconfig.json +0 -0
- /package/{lib → dist}/files/ts/plugin/tsconfig.server.json +0 -0
- /package/{lib → dist}/templates/js/README.md.hbs +0 -0
- /package/{lib → dist}/templates/js/collection-type-routes.js.hbs +0 -0
- /package/{lib → dist}/templates/js/content-type.schema.json.hbs +0 -0
- /package/{lib → dist}/templates/js/controller.js.hbs +0 -0
- /package/{lib → dist}/templates/js/core-controller.js.hbs +0 -0
- /package/{lib → dist}/templates/js/core-router.js.hbs +0 -0
- /package/{lib → dist}/templates/js/core-service.js.hbs +0 -0
- /package/{lib → dist}/templates/js/middleware.js.hbs +0 -0
- /package/{lib → dist}/templates/js/migration.js.hbs +0 -0
- /package/{lib → dist}/templates/js/plugin-package.json.hbs +0 -0
- /package/{lib → dist}/templates/js/policy.js.hbs +0 -0
- /package/{lib → dist}/templates/js/service.js.hbs +0 -0
- /package/{lib → dist}/templates/js/single-route.js.hbs +0 -0
- /package/{lib → dist}/templates/js/single-type-routes.js.hbs +0 -0
- /package/{lib → dist}/templates/ts/README.md.hbs +0 -0
- /package/{lib → dist}/templates/ts/collection-type-routes.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/content-type.schema.json.hbs +0 -0
- /package/{lib → dist}/templates/ts/controller.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/core-controller.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/core-router.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/core-service.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/middleware.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/migration.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/plugin-package.json.hbs +0 -0
- /package/{lib → dist}/templates/ts/policy.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/service.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/single-route.ts.hbs +0 -0
- /package/{lib → dist}/templates/ts/single-type-routes.ts.hbs +0 -0
package/lib/plops/plugin.js
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const chalk = require('chalk');
|
|
4
|
-
const { isUsingTypeScriptSync } = require('@strapi/typescript-utils');
|
|
5
|
-
const { isKebabCase, toKebabCase } = require('@strapi/utils');
|
|
6
|
-
|
|
7
|
-
const validateInput = require('./utils/validate-input');
|
|
8
|
-
|
|
9
|
-
const LANGUAGES = {
|
|
10
|
-
javascript: 'JavaScript',
|
|
11
|
-
typescript: 'TypeScript',
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const logInstructions = (pluginName, { language }) => {
|
|
15
|
-
const maxLength = ` resolve: './src/plugins/${pluginName}'`.length;
|
|
16
|
-
const separator = Array(maxLength).fill('─').join('');
|
|
17
|
-
|
|
18
|
-
const exportInstruction = language === 'js' ? 'module.exports =' : 'export default';
|
|
19
|
-
|
|
20
|
-
return `
|
|
21
|
-
You can now enable your plugin by adding the following in ${chalk.yellow(
|
|
22
|
-
`./config/plugins.${language}`
|
|
23
|
-
)}
|
|
24
|
-
${separator}
|
|
25
|
-
${exportInstruction} {
|
|
26
|
-
${chalk.gray('// ...')}
|
|
27
|
-
${chalk.green(`'${pluginName}'`)}: {
|
|
28
|
-
enabled: ${chalk.yellow(true)},
|
|
29
|
-
resolve: ${chalk.yellow(`'./src/plugins/${pluginName}'`)}
|
|
30
|
-
},
|
|
31
|
-
${chalk.gray('// ...')}
|
|
32
|
-
}
|
|
33
|
-
${separator}
|
|
34
|
-
`;
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
module.exports = (plop) => {
|
|
38
|
-
// Plugin generator
|
|
39
|
-
plop.setGenerator('plugin', {
|
|
40
|
-
description: 'Generate a basic plugin',
|
|
41
|
-
prompts: [
|
|
42
|
-
{
|
|
43
|
-
type: 'input',
|
|
44
|
-
name: 'pluginName',
|
|
45
|
-
message: 'Plugin name',
|
|
46
|
-
validate: (input) => validateInput(input),
|
|
47
|
-
},
|
|
48
|
-
{
|
|
49
|
-
type: 'list',
|
|
50
|
-
name: 'language',
|
|
51
|
-
message: 'Choose your preferred language',
|
|
52
|
-
choices: Object.values(LANGUAGES),
|
|
53
|
-
default: LANGUAGES.javascript,
|
|
54
|
-
},
|
|
55
|
-
],
|
|
56
|
-
actions(answers) {
|
|
57
|
-
const isTypescript = answers.language === LANGUAGES.typescript;
|
|
58
|
-
const language = isTypescript ? 'ts' : 'js';
|
|
59
|
-
const projectLanguage = isUsingTypeScriptSync(process.cwd()) ? 'ts' : 'js';
|
|
60
|
-
|
|
61
|
-
if (!isKebabCase(answers.pluginName)) {
|
|
62
|
-
answers.pluginName = toKebabCase(answers.pluginName);
|
|
63
|
-
console.log(
|
|
64
|
-
chalk.yellow(
|
|
65
|
-
`Strapi only supports kebab-cased names for plugins.\nYour plugin has been automatically renamed to "${answers.pluginName}".`
|
|
66
|
-
)
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return [
|
|
71
|
-
{
|
|
72
|
-
type: 'addMany',
|
|
73
|
-
destination: 'plugins/{{ pluginName }}',
|
|
74
|
-
base: `files/${language}/plugin`,
|
|
75
|
-
templateFiles: `files/${language}/plugin/**`,
|
|
76
|
-
},
|
|
77
|
-
{
|
|
78
|
-
type: 'add',
|
|
79
|
-
path: 'plugins/{{ pluginName }}/README.md',
|
|
80
|
-
templateFile: `templates/${language}/README.md.hbs`,
|
|
81
|
-
},
|
|
82
|
-
{
|
|
83
|
-
type: 'add',
|
|
84
|
-
path: 'plugins/{{ pluginName }}/package.json',
|
|
85
|
-
templateFile: `templates/${language}/plugin-package.json.hbs`,
|
|
86
|
-
},
|
|
87
|
-
() => plop.renderString(logInstructions(answers.pluginName, { language: projectLanguage })),
|
|
88
|
-
];
|
|
89
|
-
},
|
|
90
|
-
});
|
|
91
|
-
};
|
package/lib/plops/policy.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
4
|
-
|
|
5
|
-
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
6
|
-
const validateInput = require('./utils/validate-input');
|
|
7
|
-
const getFilePath = require('./utils/get-file-path');
|
|
8
|
-
|
|
9
|
-
module.exports = (plop) => {
|
|
10
|
-
// Policy generator
|
|
11
|
-
plop.setGenerator('policy', {
|
|
12
|
-
description: 'Generate a policy for an API',
|
|
13
|
-
prompts: [
|
|
14
|
-
{
|
|
15
|
-
type: 'input',
|
|
16
|
-
name: 'id',
|
|
17
|
-
message: 'Policy name',
|
|
18
|
-
validate: (input) => validateInput(input),
|
|
19
|
-
},
|
|
20
|
-
...getDestinationPrompts('policy', plop.getDestBasePath(), { rootFolder: true }),
|
|
21
|
-
],
|
|
22
|
-
actions(answers) {
|
|
23
|
-
const filePath = getFilePath(answers.destination);
|
|
24
|
-
const currentDir = process.cwd();
|
|
25
|
-
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
26
|
-
|
|
27
|
-
return [
|
|
28
|
-
{
|
|
29
|
-
type: 'add',
|
|
30
|
-
path: `${filePath}/policies/{{ id }}.${language}`,
|
|
31
|
-
templateFile: `templates/${language}/policy.${language}.hbs`,
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const pluralize = require('pluralize');
|
|
4
|
-
const slugify = require('@sindresorhus/slugify');
|
|
5
|
-
const { isKebabCase } = require('@strapi/utils');
|
|
6
|
-
|
|
7
|
-
module.exports = [
|
|
8
|
-
{
|
|
9
|
-
type: 'input',
|
|
10
|
-
name: 'displayName',
|
|
11
|
-
message: 'Content type display name',
|
|
12
|
-
validate: (input) => !!input,
|
|
13
|
-
},
|
|
14
|
-
{
|
|
15
|
-
type: 'input',
|
|
16
|
-
name: 'singularName',
|
|
17
|
-
message: 'Content type singular name',
|
|
18
|
-
default: (answers) => slugify(answers.displayName),
|
|
19
|
-
validate(input) {
|
|
20
|
-
if (!isKebabCase(input)) {
|
|
21
|
-
return 'Value must be in kebab-case';
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return true;
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
type: 'input',
|
|
29
|
-
name: 'pluralName',
|
|
30
|
-
message: 'Content type plural name',
|
|
31
|
-
default: (answers) => pluralize(answers.singularName),
|
|
32
|
-
validate(input, answers) {
|
|
33
|
-
if (answers.singularName === input) {
|
|
34
|
-
return 'Singular and plural names cannot be the same';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if (!isKebabCase(input)) {
|
|
38
|
-
return 'Value must be in kebab-case';
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return true;
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
];
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const validateAttributeInput = require('../utils/validate-attribute-input');
|
|
4
|
-
|
|
5
|
-
const DEFAULT_TYPES = [
|
|
6
|
-
// advanced types
|
|
7
|
-
'media',
|
|
8
|
-
|
|
9
|
-
// scalar types
|
|
10
|
-
'string',
|
|
11
|
-
'text',
|
|
12
|
-
'richtext',
|
|
13
|
-
'json',
|
|
14
|
-
'enumeration',
|
|
15
|
-
'password',
|
|
16
|
-
'email',
|
|
17
|
-
'integer',
|
|
18
|
-
'biginteger',
|
|
19
|
-
'float',
|
|
20
|
-
'decimal',
|
|
21
|
-
'date',
|
|
22
|
-
'time',
|
|
23
|
-
'datetime',
|
|
24
|
-
'timestamp',
|
|
25
|
-
'boolean',
|
|
26
|
-
];
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @param {import('inquirer').Inquirer} inquirer
|
|
30
|
-
* @returns {Promise<Record<string, string>[]>}
|
|
31
|
-
*/
|
|
32
|
-
module.exports = async (inquirer) => {
|
|
33
|
-
const { addAttributes } = await inquirer.prompt([
|
|
34
|
-
{
|
|
35
|
-
type: 'confirm',
|
|
36
|
-
name: 'addAttributes',
|
|
37
|
-
message: 'Do you want to add attributes?',
|
|
38
|
-
},
|
|
39
|
-
]);
|
|
40
|
-
|
|
41
|
-
const attributes = [];
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param {import('inquirer').Inquirer} inquirer
|
|
45
|
-
* @returns {Promise<void>}
|
|
46
|
-
*/
|
|
47
|
-
const createNewAttributes = async (inquirer) => {
|
|
48
|
-
const answers = await inquirer.prompt([
|
|
49
|
-
{
|
|
50
|
-
type: 'input',
|
|
51
|
-
name: 'attributeName',
|
|
52
|
-
message: 'Name of attribute',
|
|
53
|
-
validate: (input) => validateAttributeInput(input),
|
|
54
|
-
},
|
|
55
|
-
{
|
|
56
|
-
type: 'list',
|
|
57
|
-
name: 'attributeType',
|
|
58
|
-
message: 'What type of attribute',
|
|
59
|
-
pageSize: DEFAULT_TYPES.length,
|
|
60
|
-
choices: DEFAULT_TYPES.map((type) => {
|
|
61
|
-
return { name: type, value: type };
|
|
62
|
-
}),
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
when: (answers) => answers.attributeType === 'enumeration',
|
|
66
|
-
type: 'input',
|
|
67
|
-
name: 'enum',
|
|
68
|
-
message: 'Add values separated by a comma',
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
when: (answers) => answers.attributeType === 'media',
|
|
72
|
-
type: 'list',
|
|
73
|
-
name: 'multiple',
|
|
74
|
-
message: 'Choose media type',
|
|
75
|
-
choices: [
|
|
76
|
-
{ name: 'Multiple', value: true },
|
|
77
|
-
{ name: 'Single', value: false },
|
|
78
|
-
],
|
|
79
|
-
},
|
|
80
|
-
{
|
|
81
|
-
type: 'confirm',
|
|
82
|
-
name: 'addAttributes',
|
|
83
|
-
message: 'Do you want to add another attribute?',
|
|
84
|
-
},
|
|
85
|
-
]);
|
|
86
|
-
|
|
87
|
-
attributes.push(answers);
|
|
88
|
-
|
|
89
|
-
if (!answers.addAttributes) {
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
await createNewAttributes(inquirer);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
if (addAttributes) {
|
|
97
|
-
await createNewAttributes(inquirer);
|
|
98
|
-
} else {
|
|
99
|
-
console.warn(
|
|
100
|
-
`You won't be able to manage entries from the admin, you can still add attributes later from the content type builder.`
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return attributes;
|
|
105
|
-
};
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { join } = require('path');
|
|
4
|
-
const fs = require('fs-extra');
|
|
5
|
-
|
|
6
|
-
module.exports = (action, basePath, { rootFolder = false } = {}) => {
|
|
7
|
-
return [
|
|
8
|
-
{
|
|
9
|
-
type: 'list',
|
|
10
|
-
name: 'destination',
|
|
11
|
-
message: `Where do you want to add this ${action}?`,
|
|
12
|
-
choices: [
|
|
13
|
-
...(rootFolder
|
|
14
|
-
? [
|
|
15
|
-
{
|
|
16
|
-
name: `Add ${action} to root of project`,
|
|
17
|
-
value: 'root',
|
|
18
|
-
},
|
|
19
|
-
]
|
|
20
|
-
: [
|
|
21
|
-
{
|
|
22
|
-
name: `Add ${action} to new API`,
|
|
23
|
-
value: 'new',
|
|
24
|
-
},
|
|
25
|
-
]),
|
|
26
|
-
{ name: `Add ${action} to an existing API`, value: 'api' },
|
|
27
|
-
{ name: `Add ${action} to an existing plugin`, value: 'plugin' },
|
|
28
|
-
],
|
|
29
|
-
},
|
|
30
|
-
{
|
|
31
|
-
when: (answers) => answers.destination === 'api',
|
|
32
|
-
type: 'list',
|
|
33
|
-
message: 'Which API is this for?',
|
|
34
|
-
name: 'api',
|
|
35
|
-
async choices() {
|
|
36
|
-
const apiPath = join(basePath, 'api');
|
|
37
|
-
const exists = await fs.pathExists(apiPath);
|
|
38
|
-
|
|
39
|
-
if (!exists) {
|
|
40
|
-
throw Error('Couldn\'t find an "api" directory');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const apiDir = await fs.readdir(apiPath, { withFileTypes: true });
|
|
44
|
-
const apiDirContent = apiDir.filter((fd) => fd.isDirectory());
|
|
45
|
-
|
|
46
|
-
if (apiDirContent.length === 0) {
|
|
47
|
-
throw Error('The "api" directory is empty');
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return apiDirContent;
|
|
51
|
-
},
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
when: (answers) => answers.destination === 'plugin',
|
|
55
|
-
type: 'list',
|
|
56
|
-
message: 'Which plugin is this for?',
|
|
57
|
-
name: 'plugin',
|
|
58
|
-
async choices() {
|
|
59
|
-
const pluginsPath = join(basePath, 'plugins');
|
|
60
|
-
const exists = await fs.pathExists(pluginsPath);
|
|
61
|
-
|
|
62
|
-
if (!exists) {
|
|
63
|
-
throw Error('Couldn\'t find a "plugins" directory');
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const pluginsDir = await fs.readdir(pluginsPath);
|
|
67
|
-
const pluginsDirContent = pluginsDir.filter((api) =>
|
|
68
|
-
fs.lstatSync(join(pluginsPath, api)).isDirectory()
|
|
69
|
-
);
|
|
70
|
-
|
|
71
|
-
if (pluginsDirContent.length === 0) {
|
|
72
|
-
throw Error('The "plugins" directory is empty');
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
return pluginsDirContent;
|
|
76
|
-
},
|
|
77
|
-
},
|
|
78
|
-
];
|
|
79
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const validateInput = require('../utils/validate-input');
|
|
4
|
-
|
|
5
|
-
module.exports = [
|
|
6
|
-
{
|
|
7
|
-
type: 'list',
|
|
8
|
-
name: 'kind',
|
|
9
|
-
message: 'Please choose the model type',
|
|
10
|
-
default: 'collectionType',
|
|
11
|
-
choices: [
|
|
12
|
-
{ name: 'Collection Type', value: 'collectionType' },
|
|
13
|
-
{ name: 'Single Type', value: 'singleType' },
|
|
14
|
-
],
|
|
15
|
-
validate: (input) => validateInput(input),
|
|
16
|
-
},
|
|
17
|
-
];
|
package/lib/plops/service.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
4
|
-
|
|
5
|
-
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
6
|
-
const getFilePath = require('./utils/get-file-path');
|
|
7
|
-
|
|
8
|
-
module.exports = (plop) => {
|
|
9
|
-
// Service generator
|
|
10
|
-
plop.setGenerator('service', {
|
|
11
|
-
description: 'Generate a service for an API',
|
|
12
|
-
prompts: [
|
|
13
|
-
{
|
|
14
|
-
type: 'input',
|
|
15
|
-
name: 'id',
|
|
16
|
-
message: 'Service name',
|
|
17
|
-
},
|
|
18
|
-
...getDestinationPrompts('service', plop.getDestBasePath()),
|
|
19
|
-
],
|
|
20
|
-
actions(answers) {
|
|
21
|
-
const filePath = getFilePath(answers.destination);
|
|
22
|
-
const currentDir = process.cwd();
|
|
23
|
-
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
24
|
-
|
|
25
|
-
return [
|
|
26
|
-
{
|
|
27
|
-
type: 'add',
|
|
28
|
-
path: `${filePath}/services/{{ id }}.${language}`,
|
|
29
|
-
templateFile: `templates/${language}/service.${language}.hbs`,
|
|
30
|
-
},
|
|
31
|
-
];
|
|
32
|
-
},
|
|
33
|
-
});
|
|
34
|
-
};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const getFilePath = require('../get-file-path');
|
|
4
|
-
|
|
5
|
-
describe('Get-File-Path util', () => {
|
|
6
|
-
test('with destination set as api', () => {
|
|
7
|
-
const filePath = getFilePath('api');
|
|
8
|
-
expect(filePath).toBe(`api/{{ api }}`);
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
test('with destination set as plugin', () => {
|
|
12
|
-
const filePath = getFilePath('plugin');
|
|
13
|
-
expect(filePath).toBe(`plugins/{{ plugin }}/server`);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test('with destination set as root', () => {
|
|
17
|
-
const filePath = getFilePath('root');
|
|
18
|
-
expect(filePath).toBe(`./`);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('with empty destination string', () => {
|
|
22
|
-
const filePath = getFilePath('');
|
|
23
|
-
expect(filePath).toBe(`api/{{ id }}`);
|
|
24
|
-
});
|
|
25
|
-
});
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
module.exports = (destination) => {
|
|
4
|
-
if (destination === 'api') {
|
|
5
|
-
return `api/{{ api }}`;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (destination === 'plugin') {
|
|
9
|
-
return `plugins/{{ plugin }}/server`;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
if (destination === 'root') {
|
|
13
|
-
return './';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return `api/{{ id }}`;
|
|
17
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|