@strapi/generators 0.0.0-next.f45143c5e2a8a9d85691d0abf79a3f42024a0c71 → 0.0.0-next.f5b09a8e61e059f02784478e27c310c6290be088
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/.gitattributes +103 -0
- package/{lib → dist}/files/js/plugin/admin/src/index.js +2 -4
- package/{lib → dist}/files/js/plugin/server/register.js +1 -1
- package/dist/files/ts/plugin/.gitattributes +103 -0
- package/{lib → dist}/files/ts/plugin/admin/src/index.tsx +1 -1
- package/{lib → dist}/files/ts/plugin/server/register.ts +1 -1
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +29 -0
- package/dist/index.mjs.map +1 -0
- package/dist/plopfile.d.ts +4 -0
- package/dist/plopfile.d.ts.map +1 -0
- package/dist/plopfile.js +703 -0
- package/dist/plopfile.js.map +1 -0
- package/dist/plopfile.mjs +679 -0
- package/dist/plopfile.mjs.map +1 -0
- package/dist/plops/api.d.ts +4 -0
- package/dist/plops/api.d.ts.map +1 -0
- package/dist/plops/content-type.d.ts +4 -0
- package/dist/plops/content-type.d.ts.map +1 -0
- package/dist/plops/controller.d.ts +4 -0
- package/dist/plops/controller.d.ts.map +1 -0
- package/dist/plops/middleware.d.ts +4 -0
- package/dist/plops/middleware.d.ts.map +1 -0
- package/dist/plops/migration.d.ts +4 -0
- package/dist/plops/migration.d.ts.map +1 -0
- package/dist/plops/plugin.d.ts +4 -0
- package/dist/plops/plugin.d.ts.map +1 -0
- package/dist/plops/policy.d.ts +4 -0
- package/dist/plops/policy.d.ts.map +1 -0
- package/dist/plops/prompts/bootstrap-api-prompts.d.ts +4 -0
- package/dist/plops/prompts/bootstrap-api-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/ct-names-prompts.d.ts +4 -0
- package/dist/plops/prompts/ct-names-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/draft-and-publish-prompts.d.ts +4 -0
- package/dist/plops/prompts/draft-and-publish-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/get-attributes-prompts.d.ts +4 -0
- package/dist/plops/prompts/get-attributes-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/get-destination-prompts.d.ts +6 -0
- package/dist/plops/prompts/get-destination-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/kind-prompts.d.ts +4 -0
- package/dist/plops/prompts/kind-prompts.d.ts.map +1 -0
- package/dist/plops/service.d.ts +4 -0
- package/dist/plops/service.d.ts.map +1 -0
- package/dist/plops/utils/get-file-path.d.ts +3 -0
- package/dist/plops/utils/get-file-path.d.ts.map +1 -0
- package/dist/plops/utils/get-formatted-date.d.ts +3 -0
- package/dist/plops/utils/get-formatted-date.d.ts.map +1 -0
- package/dist/plops/utils/validate-attribute-input.d.ts +3 -0
- package/dist/plops/utils/validate-attribute-input.d.ts.map +1 -0
- package/dist/plops/utils/validate-file-name-input.d.ts +3 -0
- package/dist/plops/utils/validate-file-name-input.d.ts.map +1 -0
- package/dist/plops/utils/validate-input.d.ts +3 -0
- package/dist/plops/utils/validate-input.d.ts.map +1 -0
- package/{lib → dist}/templates/js/plugin-package.json.hbs +5 -5
- package/{lib → dist}/templates/ts/plugin-package.json.hbs +7 -7
- package/package.json +27 -7
- 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/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/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/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/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/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/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
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const { readFile, remove, stat } = require('fs-extra');
|
|
5
|
-
const strapiGenerators = require('../../index');
|
|
6
|
-
|
|
7
|
-
describe('Content Type Generator', () => {
|
|
8
|
-
const outputDirectory = path.join(__dirname, 'output');
|
|
9
|
-
|
|
10
|
-
afterEach(async () => {
|
|
11
|
-
await remove(outputDirectory);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('it generates the schema', async () => {
|
|
15
|
-
await strapiGenerators.generate(
|
|
16
|
-
'content-type',
|
|
17
|
-
{
|
|
18
|
-
displayName: 'testContentType',
|
|
19
|
-
singularName: 'testContentType',
|
|
20
|
-
pluralName: 'testContentTypes',
|
|
21
|
-
kind: 'singleType',
|
|
22
|
-
id: 'testContentType',
|
|
23
|
-
useDraftAndPublish: false,
|
|
24
|
-
destination: 'new',
|
|
25
|
-
bootstrapApi: false,
|
|
26
|
-
attributes: [],
|
|
27
|
-
},
|
|
28
|
-
{ dir: outputDirectory }
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
const generatedSchemaPath = path.join(
|
|
32
|
-
outputDirectory,
|
|
33
|
-
'src/api/testContentType',
|
|
34
|
-
'content-types/testContentType/schema.json'
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
expect((await stat(generatedSchemaPath)).isFile()).toBeTruthy();
|
|
38
|
-
|
|
39
|
-
const fileContent = await readFile(generatedSchemaPath, 'utf-8');
|
|
40
|
-
|
|
41
|
-
expect(fileContent).not.toBeNull();
|
|
42
|
-
|
|
43
|
-
const schema = JSON.parse(fileContent.toString());
|
|
44
|
-
|
|
45
|
-
expect(schema).toStrictEqual({
|
|
46
|
-
kind: 'singleType',
|
|
47
|
-
collectionName: 'test_content_types',
|
|
48
|
-
info: {
|
|
49
|
-
singularName: 'testContentType',
|
|
50
|
-
pluralName: 'testContentTypes',
|
|
51
|
-
displayName: 'testContentType',
|
|
52
|
-
},
|
|
53
|
-
options: {
|
|
54
|
-
draftAndPublish: false,
|
|
55
|
-
comment: '',
|
|
56
|
-
},
|
|
57
|
-
attributes: {},
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('it scaffolds a new API', async () => {
|
|
62
|
-
await strapiGenerators.generate(
|
|
63
|
-
'content-type',
|
|
64
|
-
{
|
|
65
|
-
displayName: 'testContentType',
|
|
66
|
-
singularName: 'testContentType',
|
|
67
|
-
pluralName: 'testContentTypes',
|
|
68
|
-
kind: 'singleType',
|
|
69
|
-
id: 'testContentType',
|
|
70
|
-
useDraftAndPublish: false,
|
|
71
|
-
destination: 'new',
|
|
72
|
-
bootstrapApi: true,
|
|
73
|
-
attributes: [],
|
|
74
|
-
},
|
|
75
|
-
{ dir: outputDirectory }
|
|
76
|
-
);
|
|
77
|
-
const generatedApiPath = path.join(outputDirectory, 'src/api/testContentType');
|
|
78
|
-
|
|
79
|
-
expect((await stat(generatedApiPath)).isDirectory()).toBeTruthy();
|
|
80
|
-
expect(
|
|
81
|
-
(await stat(path.join(generatedApiPath, 'controllers/testContentType.js'))).isFile()
|
|
82
|
-
).toBeTruthy();
|
|
83
|
-
expect(
|
|
84
|
-
(await stat(path.join(generatedApiPath, 'services/testContentType.js'))).isFile()
|
|
85
|
-
).toBeTruthy();
|
|
86
|
-
expect(
|
|
87
|
-
(await stat(path.join(generatedApiPath, 'routes/testContentType.js'))).isFile()
|
|
88
|
-
).toBeTruthy();
|
|
89
|
-
|
|
90
|
-
const controller = await readFile(
|
|
91
|
-
path.join(generatedApiPath, 'controllers/testContentType.js')
|
|
92
|
-
);
|
|
93
|
-
const router = await readFile(path.join(generatedApiPath, 'routes/testContentType.js'));
|
|
94
|
-
const service = await readFile(path.join(generatedApiPath, 'services/testContentType.js'));
|
|
95
|
-
|
|
96
|
-
expect(controller.toString()).toMatchInlineSnapshot(`
|
|
97
|
-
"'use strict';
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* testContentType controller
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
const { createCoreController } = require('@strapi/strapi').factories;
|
|
104
|
-
|
|
105
|
-
module.exports = createCoreController('api::testContentType.testContentType');
|
|
106
|
-
"
|
|
107
|
-
`);
|
|
108
|
-
expect(router.toString()).toMatchInlineSnapshot(`
|
|
109
|
-
"'use strict';
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* testContentType router.
|
|
113
|
-
*/
|
|
114
|
-
|
|
115
|
-
const { createCoreRouter } = require('@strapi/strapi').factories;
|
|
116
|
-
|
|
117
|
-
module.exports = createCoreRouter('api::testContentType.testContentType');
|
|
118
|
-
"
|
|
119
|
-
`);
|
|
120
|
-
expect(service.toString()).toMatchInlineSnapshot(`
|
|
121
|
-
"'use strict';
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* testContentType service.
|
|
125
|
-
*/
|
|
126
|
-
|
|
127
|
-
const { createCoreService } = require('@strapi/strapi').factories;
|
|
128
|
-
|
|
129
|
-
module.exports = createCoreService('api::testContentType.testContentType');
|
|
130
|
-
"
|
|
131
|
-
`);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('it generates the schema, then adds the attributes', async () => {
|
|
135
|
-
await strapiGenerators.generate(
|
|
136
|
-
'content-type',
|
|
137
|
-
{
|
|
138
|
-
displayName: 'testContentType',
|
|
139
|
-
singularName: 'testContentType',
|
|
140
|
-
pluralName: 'testContentTypes',
|
|
141
|
-
kind: 'singleType',
|
|
142
|
-
id: 'testContentType',
|
|
143
|
-
useDraftAndPublish: false,
|
|
144
|
-
destination: 'new',
|
|
145
|
-
bootstrapApi: false,
|
|
146
|
-
attributes: [
|
|
147
|
-
{
|
|
148
|
-
attributeName: 'name',
|
|
149
|
-
attributeType: 'string',
|
|
150
|
-
},
|
|
151
|
-
{
|
|
152
|
-
attributeName: 'email',
|
|
153
|
-
attributeType: 'string',
|
|
154
|
-
},
|
|
155
|
-
],
|
|
156
|
-
},
|
|
157
|
-
{ dir: outputDirectory }
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const generatedSchemaPath = path.join(
|
|
161
|
-
outputDirectory,
|
|
162
|
-
'src/api/testContentType',
|
|
163
|
-
'content-types/testContentType/schema.json'
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
expect((await stat(generatedSchemaPath)).isFile()).toBeTruthy();
|
|
167
|
-
|
|
168
|
-
const fileContent = await readFile(generatedSchemaPath, 'utf-8');
|
|
169
|
-
|
|
170
|
-
expect(fileContent).not.toBeNull();
|
|
171
|
-
|
|
172
|
-
const schema = JSON.parse(fileContent.toString());
|
|
173
|
-
|
|
174
|
-
expect(schema.attributes).toStrictEqual({
|
|
175
|
-
email: { type: 'string' },
|
|
176
|
-
name: { type: 'string' },
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
package/lib/plops/api.js
DELETED
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { join } = require('path');
|
|
4
|
-
const fs = require('fs-extra');
|
|
5
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
6
|
-
|
|
7
|
-
const validateInput = require('./utils/validate-input');
|
|
8
|
-
|
|
9
|
-
module.exports = (plop) => {
|
|
10
|
-
// API generator
|
|
11
|
-
plop.setGenerator('api', {
|
|
12
|
-
description: 'Generate a basic API',
|
|
13
|
-
prompts: [
|
|
14
|
-
{
|
|
15
|
-
type: 'input',
|
|
16
|
-
name: 'id',
|
|
17
|
-
message: 'API name',
|
|
18
|
-
validate: (input) => validateInput(input),
|
|
19
|
-
},
|
|
20
|
-
{
|
|
21
|
-
type: 'confirm',
|
|
22
|
-
name: 'isPluginApi',
|
|
23
|
-
message: 'Is this API for a plugin?',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
when: (answers) => answers.isPluginApi,
|
|
27
|
-
type: 'list',
|
|
28
|
-
name: 'plugin',
|
|
29
|
-
message: 'Plugin name',
|
|
30
|
-
async choices() {
|
|
31
|
-
const pluginsPath = join(plop.getDestBasePath(), 'plugins');
|
|
32
|
-
const exists = await fs.pathExists(pluginsPath);
|
|
33
|
-
|
|
34
|
-
if (!exists) {
|
|
35
|
-
throw Error('Couldn\'t find a "plugins" directory');
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const pluginsDir = await fs.readdir(pluginsPath, { withFileTypes: true });
|
|
39
|
-
const pluginsDirContent = pluginsDir.filter((fd) => fd.isDirectory());
|
|
40
|
-
|
|
41
|
-
if (pluginsDirContent.length === 0) {
|
|
42
|
-
throw Error('The "plugins" directory is empty');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return pluginsDirContent;
|
|
46
|
-
},
|
|
47
|
-
},
|
|
48
|
-
],
|
|
49
|
-
actions(answers) {
|
|
50
|
-
const filePath =
|
|
51
|
-
answers.isPluginApi && answers.plugin ? 'plugins/{{ plugin }}' : 'api/{{ id }}';
|
|
52
|
-
const currentDir = process.cwd();
|
|
53
|
-
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
54
|
-
|
|
55
|
-
const baseActions = [
|
|
56
|
-
{
|
|
57
|
-
type: 'add',
|
|
58
|
-
path: `${filePath}/controllers/{{ id }}.${language}`,
|
|
59
|
-
templateFile: `templates/${language}/controller.${language}.hbs`,
|
|
60
|
-
},
|
|
61
|
-
{
|
|
62
|
-
type: 'add',
|
|
63
|
-
path: `${filePath}/services/{{ id }}.${language}`,
|
|
64
|
-
templateFile: `templates/${language}/service.${language}.hbs`,
|
|
65
|
-
},
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
if (answers.isPluginApi) {
|
|
69
|
-
return baseActions;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
return [
|
|
73
|
-
{
|
|
74
|
-
type: 'add',
|
|
75
|
-
path: `${filePath}/routes/{{ id }}.${language}`,
|
|
76
|
-
templateFile: `templates/${language}/single-route.${language}.hbs`,
|
|
77
|
-
},
|
|
78
|
-
...baseActions,
|
|
79
|
-
];
|
|
80
|
-
},
|
|
81
|
-
});
|
|
82
|
-
};
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const { join } = require('path');
|
|
4
|
-
const slugify = require('@sindresorhus/slugify');
|
|
5
|
-
const fs = require('fs-extra');
|
|
6
|
-
const { isKebabCase } = require('@strapi/utils');
|
|
7
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
8
|
-
|
|
9
|
-
const getDestinationPrompts = require('./prompts/get-destination-prompts');
|
|
10
|
-
const getFilePath = require('./utils/get-file-path');
|
|
11
|
-
const ctNamesPrompts = require('./prompts/ct-names-prompts');
|
|
12
|
-
const kindPrompts = require('./prompts/kind-prompts');
|
|
13
|
-
const draftAndPublishPrompts = require('./prompts/draft-and-publish-prompts');
|
|
14
|
-
const getAttributesPrompts = require('./prompts/get-attributes-prompts');
|
|
15
|
-
const bootstrapApiPrompts = require('./prompts/bootstrap-api-prompts');
|
|
16
|
-
|
|
17
|
-
module.exports = (plop) => {
|
|
18
|
-
// Model generator
|
|
19
|
-
plop.setGenerator('content-type', {
|
|
20
|
-
description: 'Generate a content type for an API',
|
|
21
|
-
async prompts(inquirer) {
|
|
22
|
-
const config = await inquirer.prompt([
|
|
23
|
-
...ctNamesPrompts,
|
|
24
|
-
...kindPrompts,
|
|
25
|
-
...draftAndPublishPrompts,
|
|
26
|
-
]);
|
|
27
|
-
const attributes = await getAttributesPrompts(inquirer);
|
|
28
|
-
|
|
29
|
-
const api = await inquirer.prompt([
|
|
30
|
-
...getDestinationPrompts('model', plop.getDestBasePath()),
|
|
31
|
-
{
|
|
32
|
-
when: (answers) => answers.destination === 'new',
|
|
33
|
-
type: 'input',
|
|
34
|
-
name: 'id',
|
|
35
|
-
default: config.singularName,
|
|
36
|
-
message: 'Name of the new API?',
|
|
37
|
-
async validate(input) {
|
|
38
|
-
if (!isKebabCase(input)) {
|
|
39
|
-
return 'Value must be in kebab-case';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const apiPath = join(plop.getDestBasePath(), 'api');
|
|
43
|
-
const exists = await fs.pathExists(apiPath);
|
|
44
|
-
|
|
45
|
-
if (!exists) {
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const apiDir = await fs.readdir(apiPath, { withFileTypes: true });
|
|
50
|
-
const apiDirContent = apiDir.filter((fd) => fd.isDirectory());
|
|
51
|
-
|
|
52
|
-
if (apiDirContent.findIndex((api) => api.name === input) !== -1) {
|
|
53
|
-
throw new Error('This name is already taken.');
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return true;
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
...bootstrapApiPrompts,
|
|
60
|
-
]);
|
|
61
|
-
|
|
62
|
-
return {
|
|
63
|
-
...config,
|
|
64
|
-
...api,
|
|
65
|
-
attributes,
|
|
66
|
-
};
|
|
67
|
-
},
|
|
68
|
-
actions(answers) {
|
|
69
|
-
const attributes = answers.attributes.reduce((object, answer) => {
|
|
70
|
-
const val = { type: answer.attributeType };
|
|
71
|
-
|
|
72
|
-
if (answer.attributeType === 'enumeration') {
|
|
73
|
-
val.enum = answer.enum.split(',').map((item) => item.trim());
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
if (answer.attributeType === 'media') {
|
|
77
|
-
val.allowedTypes = ['images', 'files', 'videos', 'audios'];
|
|
78
|
-
val.multiple = answer.multiple;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return Object.assign(object, { [answer.attributeName]: val }, {});
|
|
82
|
-
}, {});
|
|
83
|
-
|
|
84
|
-
const filePath = getFilePath(answers.destination);
|
|
85
|
-
const currentDir = process.cwd();
|
|
86
|
-
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
87
|
-
|
|
88
|
-
const baseActions = [
|
|
89
|
-
{
|
|
90
|
-
type: 'add',
|
|
91
|
-
path: `${filePath}/content-types/{{ singularName }}/schema.json`,
|
|
92
|
-
templateFile: `templates/${language}/content-type.schema.json.hbs`,
|
|
93
|
-
data: {
|
|
94
|
-
collectionName: slugify(answers.pluralName, { separator: '_' }),
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
if (Object.entries(attributes).length > 0) {
|
|
100
|
-
baseActions.push({
|
|
101
|
-
type: 'modify',
|
|
102
|
-
path: `${filePath}/content-types/{{ singularName }}/schema.json`,
|
|
103
|
-
transform(template) {
|
|
104
|
-
const parsedTemplate = JSON.parse(template);
|
|
105
|
-
parsedTemplate.attributes = attributes;
|
|
106
|
-
return JSON.stringify(parsedTemplate, null, 2);
|
|
107
|
-
},
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
if (answers.bootstrapApi) {
|
|
112
|
-
const { singularName } = answers;
|
|
113
|
-
|
|
114
|
-
let uid;
|
|
115
|
-
if (answers.destination === 'new') {
|
|
116
|
-
uid = `api::${answers.id}.${singularName}`;
|
|
117
|
-
} else if (answers.api) {
|
|
118
|
-
uid = `api::${answers.api}.${singularName}`;
|
|
119
|
-
} else if (answers.plugin) {
|
|
120
|
-
uid = `plugin::${answers.plugin}.${singularName}`;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
baseActions.push(
|
|
124
|
-
{
|
|
125
|
-
type: 'add',
|
|
126
|
-
path: `${filePath}/controllers/{{ singularName }}.${language}`,
|
|
127
|
-
templateFile: `templates/${language}/core-controller.${language}.hbs`,
|
|
128
|
-
data: { uid },
|
|
129
|
-
},
|
|
130
|
-
{
|
|
131
|
-
type: 'add',
|
|
132
|
-
path: `${filePath}/services/{{ singularName }}.${language}`,
|
|
133
|
-
templateFile: `templates/${language}/core-service.${language}.hbs`,
|
|
134
|
-
data: { uid },
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
type: 'add',
|
|
138
|
-
path: `${filePath}/routes/{{ singularName }}.${language}`,
|
|
139
|
-
templateFile: `templates/${language}/core-router.${language}.hbs`,
|
|
140
|
-
data: { uid },
|
|
141
|
-
}
|
|
142
|
-
);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
return baseActions;
|
|
146
|
-
},
|
|
147
|
-
});
|
|
148
|
-
};
|
package/lib/plops/controller.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 getFilePath = require('./utils/get-file-path');
|
|
7
|
-
const validateInput = require('./utils/validate-input');
|
|
8
|
-
|
|
9
|
-
module.exports = (plop) => {
|
|
10
|
-
// Controller generator
|
|
11
|
-
plop.setGenerator('controller', {
|
|
12
|
-
description: 'Generate a controller for an API',
|
|
13
|
-
prompts: [
|
|
14
|
-
{
|
|
15
|
-
type: 'input',
|
|
16
|
-
name: 'id',
|
|
17
|
-
message: 'Controller name',
|
|
18
|
-
validate: (input) => validateInput(input),
|
|
19
|
-
},
|
|
20
|
-
...getDestinationPrompts('controller', plop.getDestBasePath()),
|
|
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}/controllers/{{ id }}.${language}`,
|
|
31
|
-
templateFile: `templates/${language}/controller.${language}.hbs`,
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
};
|
package/lib/plops/middleware.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
|
-
// middleware generator
|
|
11
|
-
plop.setGenerator('middleware', {
|
|
12
|
-
description: 'Generate a middleware for an API',
|
|
13
|
-
prompts: [
|
|
14
|
-
{
|
|
15
|
-
type: 'input',
|
|
16
|
-
name: 'name',
|
|
17
|
-
message: 'Middleware name',
|
|
18
|
-
validate: (input) => validateInput(input),
|
|
19
|
-
},
|
|
20
|
-
...getDestinationPrompts('middleware', 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}/middlewares/{{ name }}.${language}`,
|
|
31
|
-
templateFile: `templates/${language}/middleware.${language}.hbs`,
|
|
32
|
-
},
|
|
33
|
-
];
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
};
|
package/lib/plops/migration.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const tsUtils = require('@strapi/typescript-utils');
|
|
4
|
-
const validateFileNameInput = require('./utils/validate-file-name-input');
|
|
5
|
-
const getFormattedDate = require('./utils/get-formatted-date');
|
|
6
|
-
|
|
7
|
-
module.exports = (plop) => {
|
|
8
|
-
// Migration generator
|
|
9
|
-
plop.setGenerator('migration', {
|
|
10
|
-
description: 'Generate a migration',
|
|
11
|
-
prompts: [
|
|
12
|
-
{
|
|
13
|
-
type: 'input',
|
|
14
|
-
name: 'name',
|
|
15
|
-
message: 'Migration name',
|
|
16
|
-
validate: (input) => validateFileNameInput(input),
|
|
17
|
-
},
|
|
18
|
-
],
|
|
19
|
-
actions() {
|
|
20
|
-
const currentDir = process.cwd();
|
|
21
|
-
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
22
|
-
const timestamp = getFormattedDate();
|
|
23
|
-
|
|
24
|
-
return [
|
|
25
|
-
{
|
|
26
|
-
type: 'add',
|
|
27
|
-
path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
|
|
28
|
-
templateFile: `templates/${language}/migration.${language}.hbs`,
|
|
29
|
-
},
|
|
30
|
-
];
|
|
31
|
-
},
|
|
32
|
-
});
|
|
33
|
-
};
|
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
|
-
];
|