@strapi/generators 0.0.0-next.e41415e8ff5f565ff959667d5c5ba4f20bee013c → 0.0.0-next.e5b87a54008c9de2b3286a4774635dcf69895d9b
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/LICENSE +18 -3
- package/dist/index.d.ts +10 -5
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +92 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +94 -0
- package/dist/index.mjs.map +1 -0
- package/dist/plopfile.d.ts +2 -1
- package/dist/plopfile.d.ts.map +1 -0
- package/dist/plopfile.js +24 -26
- package/dist/plopfile.js.map +1 -1
- package/dist/plopfile.mjs +25 -0
- package/dist/plopfile.mjs.map +1 -0
- package/dist/plops/api.d.ts +2 -1
- package/dist/plops/api.d.ts.map +1 -0
- package/dist/plops/api.js +107 -37
- package/dist/plops/api.js.map +1 -1
- package/dist/plops/api.mjs +147 -0
- package/dist/plops/api.mjs.map +1 -0
- package/dist/plops/content-type.d.ts +2 -1
- package/dist/plops/content-type.d.ts.map +1 -0
- package/dist/plops/content-type.js +170 -60
- package/dist/plops/content-type.js.map +1 -1
- package/dist/plops/content-type.mjs +243 -0
- package/dist/plops/content-type.mjs.map +1 -0
- package/dist/plops/controller.d.ts +2 -1
- package/dist/plops/controller.d.ts.map +1 -0
- package/dist/plops/controller.js +54 -21
- package/dist/plops/controller.js.map +1 -1
- package/dist/plops/controller.mjs +71 -0
- package/dist/plops/controller.mjs.map +1 -0
- package/dist/plops/middleware.d.ts +2 -1
- package/dist/plops/middleware.d.ts.map +1 -0
- package/dist/plops/middleware.js +56 -21
- package/dist/plops/middleware.js.map +1 -1
- package/dist/plops/middleware.mjs +73 -0
- package/dist/plops/middleware.mjs.map +1 -0
- package/dist/plops/migration.d.ts +2 -1
- package/dist/plops/migration.d.ts.map +1 -0
- package/dist/plops/migration.js +19 -19
- package/dist/plops/migration.js.map +1 -1
- package/dist/plops/migration.mjs +33 -0
- package/dist/plops/migration.mjs.map +1 -0
- package/dist/plops/policy.d.ts +2 -1
- package/dist/plops/policy.d.ts.map +1 -0
- package/dist/plops/policy.js +56 -21
- package/dist/plops/policy.js.map +1 -1
- package/dist/plops/policy.mjs +73 -0
- package/dist/plops/policy.mjs.map +1 -0
- package/dist/plops/prompts/bootstrap-api-prompts.d.ts +7 -2
- package/dist/plops/prompts/bootstrap-api-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/bootstrap-api-prompts.js +7 -6
- package/dist/plops/prompts/bootstrap-api-prompts.js.map +1 -1
- package/dist/plops/prompts/bootstrap-api-prompts.mjs +11 -0
- package/dist/plops/prompts/bootstrap-api-prompts.mjs.map +1 -0
- package/dist/plops/prompts/ct-names-prompts.d.ts +19 -2
- package/dist/plops/prompts/ct-names-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/ct-names-prompts.js +19 -20
- package/dist/plops/prompts/ct-names-prompts.js.map +1 -1
- package/dist/plops/prompts/ct-names-prompts.mjs +42 -0
- package/dist/plops/prompts/ct-names-prompts.mjs.map +1 -0
- package/dist/plops/prompts/get-attributes-prompts.d.ts +9 -2
- package/dist/plops/prompts/get-attributes-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/get-attributes-prompts.js +36 -30
- package/dist/plops/prompts/get-attributes-prompts.js.map +1 -1
- package/dist/plops/prompts/get-attributes-prompts.mjs +99 -0
- package/dist/plops/prompts/get-attributes-prompts.mjs.map +1 -0
- package/dist/plops/prompts/get-destination-prompts.d.ts +25 -2
- package/dist/plops/prompts/get-destination-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/get-destination-prompts.js +47 -41
- package/dist/plops/prompts/get-destination-prompts.js.map +1 -1
- package/dist/plops/prompts/get-destination-prompts.mjs +76 -0
- package/dist/plops/prompts/get-destination-prompts.mjs.map +1 -0
- package/dist/plops/prompts/kind-prompts.d.ts +12 -2
- package/dist/plops/prompts/kind-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/kind-prompts.js +17 -12
- package/dist/plops/prompts/kind-prompts.js.map +1 -1
- package/dist/plops/prompts/kind-prompts.mjs +24 -0
- package/dist/plops/prompts/kind-prompts.mjs.map +1 -0
- package/dist/plops/service.d.ts +2 -1
- package/dist/plops/service.d.ts.map +1 -0
- package/dist/plops/service.js +53 -20
- package/dist/plops/service.js.map +1 -1
- package/dist/plops/service.mjs +69 -0
- package/dist/plops/service.mjs.map +1 -0
- package/dist/plops/utils/extend-plugin-index-files.d.ts +8 -0
- package/dist/plops/utils/extend-plugin-index-files.d.ts.map +1 -0
- package/dist/plops/utils/extend-plugin-index-files.js +356 -0
- package/dist/plops/utils/extend-plugin-index-files.js.map +1 -0
- package/dist/plops/utils/extend-plugin-index-files.mjs +335 -0
- package/dist/plops/utils/extend-plugin-index-files.mjs.map +1 -0
- package/dist/plops/utils/get-file-path.d.ts +2 -1
- package/dist/plops/utils/get-file-path.d.ts.map +1 -0
- package/dist/plops/utils/get-file-path.js +9 -7
- package/dist/plops/utils/get-file-path.js.map +1 -1
- package/dist/plops/utils/get-file-path.mjs +15 -0
- package/dist/plops/utils/get-file-path.mjs.map +1 -0
- package/dist/plops/utils/get-formatted-date.d.ts +1 -0
- package/dist/plops/utils/get-formatted-date.d.ts.map +1 -0
- package/dist/plops/utils/get-formatted-date.js +8 -9
- package/dist/plops/utils/get-formatted-date.js.map +1 -1
- package/dist/plops/utils/get-formatted-date.mjs +6 -0
- package/dist/plops/utils/get-formatted-date.mjs.map +1 -0
- package/dist/plops/utils/validate-attribute-input.d.ts +1 -0
- package/dist/plops/utils/validate-attribute-input.d.ts.map +1 -0
- package/dist/plops/utils/validate-attribute-input.js +7 -5
- package/dist/plops/utils/validate-attribute-input.js.map +1 -1
- package/dist/plops/utils/validate-attribute-input.mjs +10 -0
- package/dist/plops/utils/validate-attribute-input.mjs.map +1 -0
- package/dist/plops/utils/validate-file-name-input.d.ts +1 -0
- package/dist/plops/utils/validate-file-name-input.d.ts.map +1 -0
- package/dist/plops/utils/validate-file-name-input.js +7 -5
- package/dist/plops/utils/validate-file-name-input.js.map +1 -1
- package/dist/plops/utils/validate-file-name-input.mjs +10 -0
- package/dist/plops/utils/validate-file-name-input.mjs.map +1 -0
- package/dist/plops/utils/validate-input.d.ts +1 -0
- package/dist/plops/utils/validate-input.d.ts.map +1 -0
- package/dist/plops/utils/validate-input.js +7 -5
- package/dist/plops/utils/validate-input.js.map +1 -1
- package/dist/plops/utils/validate-input.mjs +10 -0
- package/dist/plops/utils/validate-input.mjs.map +1 -0
- package/dist/templates/js/content-type.schema.json.hbs +0 -1
- package/dist/templates/js/plugin/plugin.routes.index.js.hbs +12 -0
- package/dist/templates/js/plugin/plugin.routes.type.index.js.hbs +6 -0
- package/dist/templates/ts/content-type.schema.json.hbs +0 -1
- package/dist/templates/ts/core-controller.ts.hbs +1 -1
- package/dist/templates/ts/middleware.ts.hbs +2 -2
- package/dist/templates/ts/plugin/plugin.routes.index.ts.hbs +9 -0
- package/dist/templates/ts/plugin/plugin.routes.type.index.ts.hbs +4 -0
- package/package.json +25 -17
- package/dist/files/js/plugin/.editorconfig +0 -7
- package/dist/files/js/plugin/.gitattributes +0 -103
- package/dist/files/js/plugin/admin/src/components/Initializer/index.js +0 -26
- package/dist/files/js/plugin/admin/src/components/PluginIcon/index.js +0 -12
- package/dist/files/js/plugin/admin/src/index.js +0 -63
- package/dist/files/js/plugin/admin/src/pages/App/index.js +0 -25
- package/dist/files/js/plugin/admin/src/pages/HomePage/index.js +0 -20
- package/dist/files/js/plugin/admin/src/pluginId.js +0 -5
- package/dist/files/js/plugin/admin/src/translations/en.json +0 -1
- package/dist/files/js/plugin/admin/src/translations/fr.json +0 -1
- package/dist/files/js/plugin/admin/src/utils/getTrad.js +0 -5
- package/dist/files/js/plugin/server/bootstrap.js +0 -5
- package/dist/files/js/plugin/server/config/index.js +0 -6
- package/dist/files/js/plugin/server/controllers/index.js +0 -7
- package/dist/files/js/plugin/server/controllers/my-controller.js.hbs +0 -10
- package/dist/files/js/plugin/server/destroy.js +0 -5
- package/dist/files/js/plugin/server/index.js +0 -25
- package/dist/files/js/plugin/server/middlewares/index.js +0 -3
- package/dist/files/js/plugin/server/policies/index.js +0 -3
- package/dist/files/js/plugin/server/register.js +0 -5
- package/dist/files/js/plugin/server/routes/index.js +0 -10
- package/dist/files/js/plugin/server/services/index.js +0 -7
- package/dist/files/js/plugin/server/services/my-service.js +0 -7
- package/dist/files/js/plugin/strapi-admin.js +0 -3
- package/dist/files/js/plugin/strapi-server.js +0 -3
- package/dist/files/ts/plugin/.editorconfig +0 -7
- package/dist/files/ts/plugin/.gitattributes +0 -103
- package/dist/files/ts/plugin/admin/src/components/Initializer/index.tsx +0 -24
- package/dist/files/ts/plugin/admin/src/components/PluginIcon/index.tsx +0 -12
- package/dist/files/ts/plugin/admin/src/index.tsx +0 -67
- package/dist/files/ts/plugin/admin/src/pages/App/index.tsx +0 -25
- package/dist/files/ts/plugin/admin/src/pages/HomePage/index.tsx +0 -19
- package/dist/files/ts/plugin/admin/src/pluginId.ts +0 -5
- package/dist/files/ts/plugin/admin/src/translations/en.json +0 -1
- package/dist/files/ts/plugin/admin/src/translations/fr.json +0 -1
- package/dist/files/ts/plugin/admin/src/utils/getTrad.ts +0 -5
- package/dist/files/ts/plugin/custom.d.ts +0 -5
- package/dist/files/ts/plugin/server/bootstrap.ts +0 -5
- package/dist/files/ts/plugin/server/config/index.ts +0 -4
- package/dist/files/ts/plugin/server/controllers/index.ts +0 -5
- package/dist/files/ts/plugin/server/controllers/my-controller.ts.hbs +0 -10
- package/dist/files/ts/plugin/server/destroy.ts +0 -5
- package/dist/files/ts/plugin/server/index.ts +0 -23
- package/dist/files/ts/plugin/server/middlewares/index.ts +0 -1
- package/dist/files/ts/plugin/server/policies/index.ts +0 -1
- package/dist/files/ts/plugin/server/register.ts +0 -5
- package/dist/files/ts/plugin/server/routes/index.ts +0 -10
- package/dist/files/ts/plugin/server/services/index.ts +0 -5
- package/dist/files/ts/plugin/server/services/my-service.ts +0 -7
- package/dist/files/ts/plugin/strapi-admin.js +0 -3
- package/dist/files/ts/plugin/strapi-server.js +0 -3
- package/dist/files/ts/plugin/tsconfig.json +0 -20
- package/dist/files/ts/plugin/tsconfig.server.json +0 -25
- package/dist/plops/plugin.d.ts +0 -3
- package/dist/plops/plugin.js +0 -84
- package/dist/plops/plugin.js.map +0 -1
- package/dist/plops/prompts/draft-and-publish-prompts.d.ts +0 -3
- package/dist/plops/prompts/draft-and-publish-prompts.js +0 -12
- package/dist/plops/prompts/draft-and-publish-prompts.js.map +0 -1
- package/dist/templates/js/README.md.hbs +0 -3
- package/dist/templates/js/plugin-package.json.hbs +0 -42
- package/dist/templates/ts/README.md.hbs +0 -3
- package/dist/templates/ts/plugin-package.json.hbs +0 -51
- /package/dist/{files/js/plugin/server/content-types/index.js → templates/js/plugin/plugin.index.js.hbs} +0 -0
- /package/dist/{files/ts/plugin/server/content-types/index.ts → templates/ts/plugin/plugin.index.ts.hbs} +0 -0
package/dist/plops/api.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var path = require('path');
|
|
4
|
+
var fs = require('fs-extra');
|
|
5
|
+
var tsUtils = require('@strapi/typescript-utils');
|
|
6
|
+
var validateInput = require('./utils/validate-input.js');
|
|
7
|
+
var getFilePath = require('./utils/get-file-path.js');
|
|
8
|
+
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
9
|
+
|
|
10
|
+
var generateApi = ((plop)=>{
|
|
11
11
|
// API generator
|
|
12
12
|
plop.setGenerator('api', {
|
|
13
13
|
description: 'Generate a basic API',
|
|
@@ -16,64 +16,134 @@ exports.default = (plop) => {
|
|
|
16
16
|
type: 'input',
|
|
17
17
|
name: 'id',
|
|
18
18
|
message: 'API name',
|
|
19
|
-
validate: (input)
|
|
19
|
+
validate: (input)=>validateInput(input)
|
|
20
20
|
},
|
|
21
21
|
{
|
|
22
22
|
type: 'confirm',
|
|
23
23
|
name: 'isPluginApi',
|
|
24
|
-
message: 'Is this API for a plugin?'
|
|
24
|
+
message: 'Is this API for a plugin?'
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
|
-
when: (answers)
|
|
27
|
+
when: (answers)=>answers.isPluginApi,
|
|
28
28
|
type: 'list',
|
|
29
29
|
name: 'plugin',
|
|
30
30
|
message: 'Plugin name',
|
|
31
|
-
async choices() {
|
|
32
|
-
const pluginsPath =
|
|
33
|
-
const exists = await
|
|
31
|
+
async choices () {
|
|
32
|
+
const pluginsPath = path.join(plop.getDestBasePath(), 'plugins');
|
|
33
|
+
const exists = await fs.pathExists(pluginsPath);
|
|
34
34
|
if (!exists) {
|
|
35
35
|
throw Error('Couldn\'t find a "plugins" directory');
|
|
36
36
|
}
|
|
37
|
-
const pluginsDir = await
|
|
38
|
-
|
|
37
|
+
const pluginsDir = await fs.readdir(pluginsPath, {
|
|
38
|
+
withFileTypes: true
|
|
39
|
+
});
|
|
40
|
+
const pluginsDirContent = pluginsDir.filter((fd)=>fd.isDirectory());
|
|
39
41
|
if (pluginsDirContent.length === 0) {
|
|
40
42
|
throw Error('The "plugins" directory is empty');
|
|
41
43
|
}
|
|
42
44
|
return pluginsDirContent;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
45
47
|
],
|
|
46
|
-
actions(answers) {
|
|
48
|
+
actions (answers) {
|
|
47
49
|
if (!answers) {
|
|
48
50
|
return [];
|
|
49
51
|
}
|
|
50
|
-
const filePath = answers.isPluginApi && answers.plugin ? '
|
|
52
|
+
const filePath = getFilePath(answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'api'));
|
|
51
53
|
const currentDir = process.cwd();
|
|
52
|
-
|
|
54
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
55
|
+
if (answers.plugin) {
|
|
56
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
57
|
+
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
58
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
59
|
+
}
|
|
53
60
|
const baseActions = [
|
|
54
61
|
{
|
|
55
62
|
type: 'add',
|
|
56
63
|
path: `${filePath}/controllers/{{ id }}.${language}`,
|
|
57
|
-
templateFile: `templates/${language}/controller.${language}.hbs
|
|
64
|
+
templateFile: `templates/${language}/controller.${language}.hbs`
|
|
58
65
|
},
|
|
59
66
|
{
|
|
60
67
|
type: 'add',
|
|
61
68
|
path: `${filePath}/services/{{ id }}.${language}`,
|
|
62
|
-
templateFile: `templates/${language}/service.${language}.hbs
|
|
69
|
+
templateFile: `templates/${language}/service.${language}.hbs`
|
|
63
70
|
},
|
|
64
|
-
];
|
|
65
|
-
if (answers.isPluginApi) {
|
|
66
|
-
return baseActions;
|
|
67
|
-
}
|
|
68
|
-
return [
|
|
69
71
|
{
|
|
70
72
|
type: 'add',
|
|
71
|
-
path: `${filePath}/routes/{{ id }}.${language}`,
|
|
72
|
-
templateFile: `templates/${language}/single-route.${language}.hbs
|
|
73
|
-
}
|
|
74
|
-
...baseActions,
|
|
73
|
+
path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ id }}.${language}`,
|
|
74
|
+
templateFile: `templates/${language}/single-route.${language}.hbs`
|
|
75
|
+
}
|
|
75
76
|
];
|
|
76
|
-
|
|
77
|
+
if (answers.isPluginApi) {
|
|
78
|
+
const indexFiles = [
|
|
79
|
+
'controllers',
|
|
80
|
+
'services',
|
|
81
|
+
'routes'
|
|
82
|
+
];
|
|
83
|
+
indexFiles.forEach((type)=>{
|
|
84
|
+
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
85
|
+
const exists = fs.existsSync(indexPath);
|
|
86
|
+
if (!exists && type !== 'routes') {
|
|
87
|
+
baseActions.push({
|
|
88
|
+
type: 'add',
|
|
89
|
+
path: `${filePath}/${type}/index.${language}`,
|
|
90
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
91
|
+
skipIfExists: true
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
if (type === 'routes') {
|
|
95
|
+
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
96
|
+
const exists = fs.existsSync(indexPath);
|
|
97
|
+
if (!exists) {
|
|
98
|
+
baseActions.push({
|
|
99
|
+
type: 'add',
|
|
100
|
+
path: `${filePath}/${type}/index.${language}`,
|
|
101
|
+
templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,
|
|
102
|
+
skipIfExists: true
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
const routeIndexFiles = [
|
|
106
|
+
'content-api',
|
|
107
|
+
'admin'
|
|
108
|
+
];
|
|
109
|
+
routeIndexFiles.forEach((routeType)=>{
|
|
110
|
+
const routeTypeIndexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/${routeType}/index.${language}`);
|
|
111
|
+
const routeTypeExists = fs.existsSync(routeTypeIndexPath);
|
|
112
|
+
if (!routeTypeExists) {
|
|
113
|
+
baseActions.push({
|
|
114
|
+
type: 'add',
|
|
115
|
+
path: `${filePath}/${type}/${routeType}/index.${language}`,
|
|
116
|
+
templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,
|
|
117
|
+
data: {
|
|
118
|
+
type: routeType
|
|
119
|
+
},
|
|
120
|
+
skipIfExists: true
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
baseActions.push({
|
|
126
|
+
type: 'modify',
|
|
127
|
+
path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,
|
|
128
|
+
transform (template) {
|
|
129
|
+
if (type === 'routes') {
|
|
130
|
+
return extendPluginIndexFiles.appendToFile(template, {
|
|
131
|
+
type: 'routes',
|
|
132
|
+
singularName: answers.id
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
return extendPluginIndexFiles.appendToFile(template, {
|
|
136
|
+
type: 'index',
|
|
137
|
+
singularName: answers.id
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return baseActions;
|
|
144
|
+
}
|
|
77
145
|
});
|
|
78
|
-
};
|
|
79
|
-
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
module.exports = generateApi;
|
|
149
|
+
//# sourceMappingURL=api.js.map
|
package/dist/plops/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/plops/api.ts"],"names":[],"mappings":";;;;;AACA,+BAA4B;AAC5B,wDAA0B;AAC1B,gFAA+C;AAE/C,4EAAmD;AAEnD,kBAAe,CAAC,IAAiB,EAAE,EAAE;IACnC,gBAAgB;IAChB,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE;QACvB,WAAW,EAAE,sBAAsB;QACnC,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,IAAI;gBACV,OAAO,EAAE,UAAU;gBACnB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,wBAAa,EAAC,KAAK,CAAC;aAC1C;YACD;gBACE,IAAI,EAAE,SAAS;gBACf,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,2BAA2B;aACrC;YACD;gBACE,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW;gBACtC,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,QAAQ;gBACd,OAAO,EAAE,aAAa;gBACtB,KAAK,CAAC,OAAO;oBACX,MAAM,WAAW,GAAG,IAAA,WAAI,EAA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YAAY,EAAE,aAAa,QAAQ,YAAY,QAAQ,MAAM;iBAC9D;aACF,CAAC;YAEF,IAAI,OAAO,CAAC,WAAW,EAAE;gBACvB,OAAO,WAAW,CAAC;aACpB;YAED,OAAO;gBACL;oBACE,IAAI,EAAE,KAAK;oBACX,IAAI,EAAE,GAAG,QAAQ,oBAAoB,QAAQ,EAAE;oBAC/C,YAAY,EAAE,aAAa,QAAQ,iBAAiB,QAAQ,MAAM;iBACnE;gBACD,GAAG,WAAW;aACf,CAAC;QACJ,CAAC;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"api.js","sources":["../../src/plops/api.ts"],"sourcesContent":["import { join } from 'path';\nimport type { ActionType, NodePlopAPI } from 'plop';\nimport fs from 'fs-extra';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // API generator\n plop.setGenerator('api', {\n description: 'Generate a basic API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'API name',\n validate: (input) => validateInput(input),\n },\n {\n type: 'confirm',\n name: 'isPluginApi',\n message: 'Is this API for a plugin?',\n },\n {\n when: (answers) => answers.isPluginApi,\n type: 'list',\n name: 'plugin',\n message: 'Plugin name',\n async choices() {\n const pluginsPath = join(plop.getDestBasePath(), 'plugins');\n const exists = await fs.pathExists(pluginsPath);\n if (!exists) {\n throw Error('Couldn\\'t find a \"plugins\" directory');\n }\n\n const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });\n const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());\n\n if (pluginsDirContent.length === 0) {\n throw Error('The \"plugins\" directory is empty');\n }\n\n return pluginsDirContent;\n },\n },\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(\n answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'api')\n );\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ id }}.${language}`,\n templateFile: `templates/${language}/service.${language}.hbs`,\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ id }}.${language}`,\n templateFile: `templates/${language}/single-route.${language}.hbs`,\n },\n ];\n\n if (answers.isPluginApi) {\n const indexFiles = ['controllers', 'services', 'routes'];\n\n indexFiles.forEach((type) => {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists && type !== 'routes') {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n if (type === 'routes') {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n const routeIndexFiles = ['content-api', 'admin'];\n\n routeIndexFiles.forEach((routeType) => {\n const routeTypeIndexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/${routeType}/index.${language}`\n );\n const routeTypeExists = fs.existsSync(routeTypeIndexPath);\n\n if (!routeTypeExists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/${routeType}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,\n data: { type: routeType },\n skipIfExists: true,\n });\n }\n });\n }\n\n baseActions.push({\n type: 'modify',\n path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,\n transform(template: string) {\n if (type === 'routes') {\n return appendToFile(template, { type: 'routes', singularName: answers.id });\n }\n\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","when","answers","isPluginApi","choices","pluginsPath","join","getDestBasePath","exists","fs","pathExists","Error","pluginsDir","readdir","withFileTypes","pluginsDirContent","filter","fd","isDirectory","length","actions","filePath","getFilePath","destination","plugin","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","pluginServerDir","replace","baseActions","path","templateFile","indexFiles","forEach","indexPath","existsSync","push","skipIfExists","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists","data","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;;AASA,kBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,KAAO,EAAA;QACvBC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,UAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAM,EAAA,SAAA;gBACNC,IAAM,EAAA,aAAA;gBACNC,OAAS,EAAA;AACX,aAAA;AACA,YAAA;gBACEI,IAAM,EAAA,CAACC,OAAYA,GAAAA,OAAAA,CAAQC,WAAW;gBACtCR,IAAM,EAAA,MAAA;gBACNC,IAAM,EAAA,QAAA;gBACNC,OAAS,EAAA,aAAA;gBACT,MAAMO,OAAAA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AG,iCAAA,CAAA;AAC3E;AAEA,4BAAA,OAAOF,oCAAaD,QAAU,EAAA;gCAAErD,IAAM,EAAA,OAAA;AAASuD,gCAAAA,YAAAA,EAAchD,QAAQiD;AAAG,6BAAA,CAAA;AAC1E;AACF,qBAAA,CAAA;AACF,iBAAA,CAAA;AACF;YAEA,OAAOlB,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import { join } from 'path';
|
|
2
|
+
import fs from 'fs-extra';
|
|
3
|
+
import tsUtils from '@strapi/typescript-utils';
|
|
4
|
+
import validateInput from './utils/validate-input.mjs';
|
|
5
|
+
import getFilePath from './utils/get-file-path.mjs';
|
|
6
|
+
import { appendToFile } from './utils/extend-plugin-index-files.mjs';
|
|
7
|
+
|
|
8
|
+
var generateApi = ((plop)=>{
|
|
9
|
+
// API generator
|
|
10
|
+
plop.setGenerator('api', {
|
|
11
|
+
description: 'Generate a basic API',
|
|
12
|
+
prompts: [
|
|
13
|
+
{
|
|
14
|
+
type: 'input',
|
|
15
|
+
name: 'id',
|
|
16
|
+
message: 'API name',
|
|
17
|
+
validate: (input)=>validateInput(input)
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
type: 'confirm',
|
|
21
|
+
name: 'isPluginApi',
|
|
22
|
+
message: 'Is this API for a plugin?'
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
when: (answers)=>answers.isPluginApi,
|
|
26
|
+
type: 'list',
|
|
27
|
+
name: 'plugin',
|
|
28
|
+
message: 'Plugin name',
|
|
29
|
+
async choices () {
|
|
30
|
+
const pluginsPath = join(plop.getDestBasePath(), 'plugins');
|
|
31
|
+
const exists = await fs.pathExists(pluginsPath);
|
|
32
|
+
if (!exists) {
|
|
33
|
+
throw Error('Couldn\'t find a "plugins" directory');
|
|
34
|
+
}
|
|
35
|
+
const pluginsDir = await fs.readdir(pluginsPath, {
|
|
36
|
+
withFileTypes: true
|
|
37
|
+
});
|
|
38
|
+
const pluginsDirContent = pluginsDir.filter((fd)=>fd.isDirectory());
|
|
39
|
+
if (pluginsDirContent.length === 0) {
|
|
40
|
+
throw Error('The "plugins" directory is empty');
|
|
41
|
+
}
|
|
42
|
+
return pluginsDirContent;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
],
|
|
46
|
+
actions (answers) {
|
|
47
|
+
if (!answers) {
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
const filePath = getFilePath(answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'api'));
|
|
51
|
+
const currentDir = process.cwd();
|
|
52
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
53
|
+
if (answers.plugin) {
|
|
54
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
55
|
+
const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
56
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
57
|
+
}
|
|
58
|
+
const baseActions = [
|
|
59
|
+
{
|
|
60
|
+
type: 'add',
|
|
61
|
+
path: `${filePath}/controllers/{{ id }}.${language}`,
|
|
62
|
+
templateFile: `templates/${language}/controller.${language}.hbs`
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'add',
|
|
66
|
+
path: `${filePath}/services/{{ id }}.${language}`,
|
|
67
|
+
templateFile: `templates/${language}/service.${language}.hbs`
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
type: 'add',
|
|
71
|
+
path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ id }}.${language}`,
|
|
72
|
+
templateFile: `templates/${language}/single-route.${language}.hbs`
|
|
73
|
+
}
|
|
74
|
+
];
|
|
75
|
+
if (answers.isPluginApi) {
|
|
76
|
+
const indexFiles = [
|
|
77
|
+
'controllers',
|
|
78
|
+
'services',
|
|
79
|
+
'routes'
|
|
80
|
+
];
|
|
81
|
+
indexFiles.forEach((type)=>{
|
|
82
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
83
|
+
const exists = fs.existsSync(indexPath);
|
|
84
|
+
if (!exists && type !== 'routes') {
|
|
85
|
+
baseActions.push({
|
|
86
|
+
type: 'add',
|
|
87
|
+
path: `${filePath}/${type}/index.${language}`,
|
|
88
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
89
|
+
skipIfExists: true
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
if (type === 'routes') {
|
|
93
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
94
|
+
const exists = fs.existsSync(indexPath);
|
|
95
|
+
if (!exists) {
|
|
96
|
+
baseActions.push({
|
|
97
|
+
type: 'add',
|
|
98
|
+
path: `${filePath}/${type}/index.${language}`,
|
|
99
|
+
templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,
|
|
100
|
+
skipIfExists: true
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const routeIndexFiles = [
|
|
104
|
+
'content-api',
|
|
105
|
+
'admin'
|
|
106
|
+
];
|
|
107
|
+
routeIndexFiles.forEach((routeType)=>{
|
|
108
|
+
const routeTypeIndexPath = join(plop.getDestBasePath(), `${filePath}/${type}/${routeType}/index.${language}`);
|
|
109
|
+
const routeTypeExists = fs.existsSync(routeTypeIndexPath);
|
|
110
|
+
if (!routeTypeExists) {
|
|
111
|
+
baseActions.push({
|
|
112
|
+
type: 'add',
|
|
113
|
+
path: `${filePath}/${type}/${routeType}/index.${language}`,
|
|
114
|
+
templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,
|
|
115
|
+
data: {
|
|
116
|
+
type: routeType
|
|
117
|
+
},
|
|
118
|
+
skipIfExists: true
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
baseActions.push({
|
|
124
|
+
type: 'modify',
|
|
125
|
+
path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,
|
|
126
|
+
transform (template) {
|
|
127
|
+
if (type === 'routes') {
|
|
128
|
+
return appendToFile(template, {
|
|
129
|
+
type: 'routes',
|
|
130
|
+
singularName: answers.id
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
return appendToFile(template, {
|
|
134
|
+
type: 'index',
|
|
135
|
+
singularName: answers.id
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
return baseActions;
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
export { generateApi as default };
|
|
147
|
+
//# sourceMappingURL=api.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.mjs","sources":["../../src/plops/api.ts"],"sourcesContent":["import { join } from 'path';\nimport type { ActionType, NodePlopAPI } from 'plop';\nimport fs from 'fs-extra';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport validateInput from './utils/validate-input';\nimport getFilePath from './utils/get-file-path';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // API generator\n plop.setGenerator('api', {\n description: 'Generate a basic API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'API name',\n validate: (input) => validateInput(input),\n },\n {\n type: 'confirm',\n name: 'isPluginApi',\n message: 'Is this API for a plugin?',\n },\n {\n when: (answers) => answers.isPluginApi,\n type: 'list',\n name: 'plugin',\n message: 'Plugin name',\n async choices() {\n const pluginsPath = join(plop.getDestBasePath(), 'plugins');\n const exists = await fs.pathExists(pluginsPath);\n if (!exists) {\n throw Error('Couldn\\'t find a \"plugins\" directory');\n }\n\n const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });\n const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());\n\n if (pluginsDirContent.length === 0) {\n throw Error('The \"plugins\" directory is empty');\n }\n\n return pluginsDirContent;\n },\n },\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(\n answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'api')\n );\n const currentDir = process.cwd();\n let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n\n if (answers.plugin) {\n // The tsconfig in plugins is located just outside the server src, not in the root of the plugin.\n const pluginServerDir = join(\n currentDir,\n 'src',\n filePath.replace('{{ plugin }}', answers.plugin),\n '../'\n );\n language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';\n }\n\n const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: `${filePath}/controllers/{{ id }}.${language}`,\n templateFile: `templates/${language}/controller.${language}.hbs`,\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ id }}.${language}`,\n templateFile: `templates/${language}/service.${language}.hbs`,\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ id }}.${language}`,\n templateFile: `templates/${language}/single-route.${language}.hbs`,\n },\n ];\n\n if (answers.isPluginApi) {\n const indexFiles = ['controllers', 'services', 'routes'];\n\n indexFiles.forEach((type) => {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists && type !== 'routes') {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n if (type === 'routes') {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n const routeIndexFiles = ['content-api', 'admin'];\n\n routeIndexFiles.forEach((routeType) => {\n const routeTypeIndexPath = join(\n plop.getDestBasePath(),\n `${filePath}/${type}/${routeType}/index.${language}`\n );\n const routeTypeExists = fs.existsSync(routeTypeIndexPath);\n\n if (!routeTypeExists) {\n baseActions.push({\n type: 'add',\n path: `${filePath}/${type}/${routeType}/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.routes.type.index.${language}.hbs`,\n data: { type: routeType },\n skipIfExists: true,\n });\n }\n });\n }\n\n baseActions.push({\n type: 'modify',\n path: `${filePath}/${type}/${type === 'routes' ? 'content-api/' : ''}index.${language}`,\n transform(template: string) {\n if (type === 'routes') {\n return appendToFile(template, { type: 'routes', singularName: answers.id });\n }\n\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","when","answers","isPluginApi","choices","pluginsPath","join","getDestBasePath","exists","fs","pathExists","Error","pluginsDir","readdir","withFileTypes","pluginsDirContent","filter","fd","isDirectory","length","actions","filePath","getFilePath","destination","plugin","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","pluginServerDir","replace","baseActions","path","templateFile","indexFiles","forEach","indexPath","existsSync","push","skipIfExists","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists","data","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;AASA,kBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,KAAO,EAAA;QACvBC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,UAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAM,EAAA,SAAA;gBACNC,IAAM,EAAA,aAAA;gBACNC,OAAS,EAAA;AACX,aA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