@strapi/generators 0.0.0-next.f0a0bc26f5ef0693aaea2a616bc6b816cfee54b6 → 0.0.0-next.f0f36e3df4b18f167036dcbca529dcb933bf4e1d
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/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +89 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -29
- package/dist/index.mjs.map +1 -1
- package/dist/plopfile.js +25 -584
- package/dist/plopfile.js.map +1 -1
- package/dist/plopfile.mjs +24 -581
- package/dist/plopfile.mjs.map +1 -1
- package/dist/plops/api.d.ts.map +1 -1
- package/dist/plops/api.js +149 -0
- package/dist/plops/api.js.map +1 -0
- package/dist/plops/api.mjs +147 -0
- package/dist/plops/api.mjs.map +1 -0
- package/dist/plops/content-type.d.ts.map +1 -1
- package/dist/plops/content-type.js +245 -0
- package/dist/plops/content-type.js.map +1 -0
- package/dist/plops/content-type.mjs +243 -0
- package/dist/plops/content-type.mjs.map +1 -0
- package/dist/plops/controller.d.ts.map +1 -1
- package/dist/plops/controller.js +73 -0
- package/dist/plops/controller.js.map +1 -0
- package/dist/plops/controller.mjs +71 -0
- package/dist/plops/controller.mjs.map +1 -0
- package/dist/plops/middleware.d.ts.map +1 -1
- package/dist/plops/middleware.js +75 -0
- package/dist/plops/middleware.js.map +1 -0
- package/dist/plops/middleware.mjs +73 -0
- package/dist/plops/middleware.mjs.map +1 -0
- package/dist/plops/migration.js +35 -0
- package/dist/plops/migration.js.map +1 -0
- package/dist/plops/migration.mjs +33 -0
- package/dist/plops/migration.mjs.map +1 -0
- package/dist/plops/policy.d.ts.map +1 -1
- package/dist/plops/policy.js +75 -0
- package/dist/plops/policy.js.map +1 -0
- package/dist/plops/policy.mjs +73 -0
- package/dist/plops/policy.mjs.map +1 -0
- package/dist/plops/prompts/bootstrap-api-prompts.d.ts +6 -2
- package/dist/plops/prompts/bootstrap-api-prompts.d.ts.map +1 -1
- package/dist/plops/prompts/bootstrap-api-prompts.js +13 -0
- package/dist/plops/prompts/bootstrap-api-prompts.js.map +1 -0
- 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 +18 -2
- package/dist/plops/prompts/ct-names-prompts.d.ts.map +1 -1
- package/dist/plops/prompts/ct-names-prompts.js +44 -0
- package/dist/plops/prompts/ct-names-prompts.js.map +1 -0
- 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 +8 -2
- package/dist/plops/prompts/get-attributes-prompts.d.ts.map +1 -1
- package/dist/plops/prompts/get-attributes-prompts.js +101 -0
- package/dist/plops/prompts/get-attributes-prompts.js.map +1 -0
- 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 +24 -2
- package/dist/plops/prompts/get-destination-prompts.d.ts.map +1 -1
- package/dist/plops/prompts/get-destination-prompts.js +78 -0
- package/dist/plops/prompts/get-destination-prompts.js.map +1 -0
- 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 +11 -2
- package/dist/plops/prompts/kind-prompts.d.ts.map +1 -1
- package/dist/plops/prompts/kind-prompts.js +26 -0
- package/dist/plops/prompts/kind-prompts.js.map +1 -0
- 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.map +1 -1
- package/dist/plops/service.js +71 -0
- package/dist/plops/service.js.map +1 -0
- 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 +1 -1
- package/dist/plops/utils/get-file-path.js +17 -0
- package/dist/plops/utils/get-file-path.js.map +1 -0
- 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.js +8 -0
- package/dist/plops/utils/get-formatted-date.js.map +1 -0
- 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.js +12 -0
- package/dist/plops/utils/validate-attribute-input.js.map +1 -0
- 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.js +12 -0
- package/dist/plops/utils/validate-file-name-input.js.map +1 -0
- 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.js +12 -0
- package/dist/plops/utils/validate-input.js.map +1 -0
- package/dist/plops/utils/validate-input.mjs +10 -0
- package/dist/plops/utils/validate-input.mjs.map +1 -0
- package/dist/templates/js/plugin/plugin.index.js.hbs +3 -0
- 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/core-controller.ts.hbs +1 -1
- package/dist/templates/ts/plugin/plugin.index.ts.hbs +1 -0
- 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 +17 -12
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
|
|
7
|
+
var getFilePath = require('./utils/get-file-path.js');
|
|
8
|
+
var validateInput = require('./utils/validate-input.js');
|
|
9
|
+
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
10
|
+
|
|
11
|
+
var generateController = ((plop)=>{
|
|
12
|
+
// Controller generator
|
|
13
|
+
plop.setGenerator('controller', {
|
|
14
|
+
description: 'Generate a controller for an API',
|
|
15
|
+
prompts: [
|
|
16
|
+
{
|
|
17
|
+
type: 'input',
|
|
18
|
+
name: 'id',
|
|
19
|
+
message: 'Controller name',
|
|
20
|
+
validate: (input)=>validateInput(input)
|
|
21
|
+
},
|
|
22
|
+
...getDestinationPrompts('controller', plop.getDestBasePath())
|
|
23
|
+
],
|
|
24
|
+
actions (answers) {
|
|
25
|
+
if (!answers) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const filePath = getFilePath(answers.destination);
|
|
29
|
+
const currentDir = process.cwd();
|
|
30
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
31
|
+
if (answers.plugin) {
|
|
32
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
33
|
+
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
34
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
35
|
+
}
|
|
36
|
+
const baseActions = [
|
|
37
|
+
{
|
|
38
|
+
type: 'add',
|
|
39
|
+
path: `${filePath}/controllers/{{ id }}.${language}`,
|
|
40
|
+
templateFile: `templates/${language}/controller.${language}.hbs`
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
if (answers.plugin) {
|
|
44
|
+
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);
|
|
45
|
+
const exists = fs.existsSync(indexPath);
|
|
46
|
+
if (!exists) {
|
|
47
|
+
// Create index file if it doesn't exist
|
|
48
|
+
baseActions.push({
|
|
49
|
+
type: 'add',
|
|
50
|
+
path: `${filePath}/controllers/index.${language}`,
|
|
51
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
52
|
+
skipIfExists: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Append the new controller to the index.ts file
|
|
56
|
+
baseActions.push({
|
|
57
|
+
type: 'modify',
|
|
58
|
+
path: `${filePath}/controllers/index.${language}`,
|
|
59
|
+
transform (template) {
|
|
60
|
+
return extendPluginIndexFiles.appendToFile(template, {
|
|
61
|
+
type: 'index',
|
|
62
|
+
singularName: answers.id
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return baseActions;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
module.exports = generateController;
|
|
73
|
+
//# sourceMappingURL=controller.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.js","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\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\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/controllers/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new controller to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/controllers/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,YAAc,EAAA;QAC9BC,WAAa,EAAA,kCAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,E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AAAA,UAAU,CAACH,SAAAA,CAAAA;AAE7B,gBAAA,IAAI,CAACC,MAAQ,EAAA;;AAEXJ,oBAAAA,WAAAA,CAAYO,IAAI,CAAC;wBACf9B,IAAM,EAAA,KAAA;AACNwB,wBAAAA,IAAAA,EAAM,CAAGd,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;wBACjDS,YAAc,EAAA,CAAC,UAAU,EAAET,QAAAA,CAAS,qBAAqB,EAAEA,QAAAA,CAAS,IAAI,CAAC;wBACzEe,YAAc,EAAA;AAChB,qBAAA,CAAA;AACF;;AAGAR,gBAAAA,WAAAA,CAAYO,IAAI,CAAC;oBACf9B,IAAM,EAAA,QAAA;AACNwB,oBAAAA,IAAAA,EAAM,CAAGd,EAAAA,QAAAA,CAAS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,oCAAaD,QAAU,EAAA;4BAAEjC,IAAM,EAAA,OAAA;AAASmC,4BAAAA,YAAAA,EAAc1B,QAAQ2B;AAAG,yBAAA,CAAA;AAC1E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOb,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import tsUtils from '@strapi/typescript-utils';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import getDestinationPrompts from './prompts/get-destination-prompts.mjs';
|
|
5
|
+
import getFilePath from './utils/get-file-path.mjs';
|
|
6
|
+
import validateInput from './utils/validate-input.mjs';
|
|
7
|
+
import { appendToFile } from './utils/extend-plugin-index-files.mjs';
|
|
8
|
+
|
|
9
|
+
var generateController = ((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
|
+
if (!answers) {
|
|
24
|
+
return [];
|
|
25
|
+
}
|
|
26
|
+
const filePath = getFilePath(answers.destination);
|
|
27
|
+
const currentDir = process.cwd();
|
|
28
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
29
|
+
if (answers.plugin) {
|
|
30
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
31
|
+
const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
32
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
33
|
+
}
|
|
34
|
+
const baseActions = [
|
|
35
|
+
{
|
|
36
|
+
type: 'add',
|
|
37
|
+
path: `${filePath}/controllers/{{ id }}.${language}`,
|
|
38
|
+
templateFile: `templates/${language}/controller.${language}.hbs`
|
|
39
|
+
}
|
|
40
|
+
];
|
|
41
|
+
if (answers.plugin) {
|
|
42
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);
|
|
43
|
+
const exists = fs.existsSync(indexPath);
|
|
44
|
+
if (!exists) {
|
|
45
|
+
// Create index file if it doesn't exist
|
|
46
|
+
baseActions.push({
|
|
47
|
+
type: 'add',
|
|
48
|
+
path: `${filePath}/controllers/index.${language}`,
|
|
49
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
50
|
+
skipIfExists: true
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
// Append the new controller to the index.ts file
|
|
54
|
+
baseActions.push({
|
|
55
|
+
type: 'modify',
|
|
56
|
+
path: `${filePath}/controllers/index.${language}`,
|
|
57
|
+
transform (template) {
|
|
58
|
+
return appendToFile(template, {
|
|
59
|
+
type: 'index',
|
|
60
|
+
singularName: answers.id
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return baseActions;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
export { generateController as default };
|
|
71
|
+
//# sourceMappingURL=controller.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller.mjs","sources":["../../src/plops/controller.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport validateInput from './utils/validate-input';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Controller generator\n plop.setGenerator('controller', {\n description: 'Generate a controller for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Controller name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('controller', plop.getDestBasePath()),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\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\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/controllers/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new controller to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/controllers/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,YAAc,EAAA;QAC9BC,WAAa,EAAA,kCAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,iBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;eACGE,qBAAsB,CAAA,YAAA,EAAcV,KAAKW,eAAe,EAAA;AAC5D,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAS,EAAA;AACZ,gBAAA,OAAO,EAAE;AACX;YAEA,MAAMC,QAAAA,GAAWC,WAAYF,CAAAA,OAAAA,CAAQG,WAAW,CAAA;YAChD,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,IAAIC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;YAElE,IAAIJ,OAAAA,CAAQU,MAAM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AS,mBAAmB,EAAEM,QAAU,CAAA,CAAA;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,aAAaD,QAAU,EAAA;4BAAEjC,IAAM,EAAA,OAAA;AAASmC,4BAAAA,YAAAA,EAAc1B,QAAQ2B;AAAG,yBAAA,CAAA;AAC1E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOb,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/plops/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"middleware.d.ts","sourceRoot":"","sources":["../../src/plops/middleware.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;+BAU9B,WAAW;AAAjC,wBAoEE"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
|
|
7
|
+
var validateInput = require('./utils/validate-input.js');
|
|
8
|
+
var getFilePath = require('./utils/get-file-path.js');
|
|
9
|
+
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
10
|
+
|
|
11
|
+
var generateMiddleware = ((plop)=>{
|
|
12
|
+
// middleware generator
|
|
13
|
+
plop.setGenerator('middleware', {
|
|
14
|
+
description: 'Generate a middleware for an API',
|
|
15
|
+
prompts: [
|
|
16
|
+
{
|
|
17
|
+
type: 'input',
|
|
18
|
+
name: 'name',
|
|
19
|
+
message: 'Middleware name',
|
|
20
|
+
validate: (input)=>validateInput(input)
|
|
21
|
+
},
|
|
22
|
+
...getDestinationPrompts('middleware', plop.getDestBasePath(), {
|
|
23
|
+
rootFolder: true
|
|
24
|
+
})
|
|
25
|
+
],
|
|
26
|
+
actions (answers) {
|
|
27
|
+
if (!answers) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const filePath = getFilePath(answers.destination);
|
|
31
|
+
const currentDir = process.cwd();
|
|
32
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
33
|
+
if (answers.plugin) {
|
|
34
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
35
|
+
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
36
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
37
|
+
}
|
|
38
|
+
const baseActions = [
|
|
39
|
+
{
|
|
40
|
+
type: 'add',
|
|
41
|
+
path: `${filePath}/middlewares/{{ name }}.${language}`,
|
|
42
|
+
templateFile: `templates/${language}/middleware.${language}.hbs`
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
if (answers.plugin) {
|
|
46
|
+
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);
|
|
47
|
+
const exists = fs.existsSync(indexPath);
|
|
48
|
+
if (!exists) {
|
|
49
|
+
// Create index file if it doesn't exist
|
|
50
|
+
baseActions.push({
|
|
51
|
+
type: 'add',
|
|
52
|
+
path: `${filePath}/middlewares/index.${language}`,
|
|
53
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
54
|
+
skipIfExists: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// Append the new middleware to the index.ts file
|
|
58
|
+
baseActions.push({
|
|
59
|
+
type: 'modify',
|
|
60
|
+
path: `${filePath}/middlewares/index.${language}`,
|
|
61
|
+
transform (template) {
|
|
62
|
+
return extendPluginIndexFiles.appendToFile(template, {
|
|
63
|
+
type: 'index',
|
|
64
|
+
singularName: answers.name
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return baseActions;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
module.exports = generateMiddleware;
|
|
75
|
+
//# sourceMappingURL=middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.js","sources":["../../src/plops/middleware.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\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 // middleware generator\n plop.setGenerator('middleware', {\n description: 'Generate a middleware for an API',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Middleware name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\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}/middlewares/{{ name }}.${language}`,\n templateFile: `templates/${language}/middleware.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/middlewares/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new middleware to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/middlewares/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.name });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","rootFolder","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName"],"mappings":";;;;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,YAAc,EAAA;QAC9BC,WAAa,EAAA,kCAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,MAAA;gBACNC,OAAS,EAAA,iBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;eACGE,qBAAsB,CAAA,YAAA,EAAcV,IAAKW,CAAAA,eAAe,EAAI,EAAA;gBAAEC,UAAY,EAAA;AAAK,aAAA;AACnF,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAS,EAAA;AACZ,gBAAA,OAAO,EAAE;AACX;YAEA,MAAMC,QAAAA,GAAWC,WAAYF,CAAAA,OAAAA,CAAQG,WAAW,CAAA;YAChD,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,IAAIC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;YAElE,IAAIJ,OAAAA,CAAQU,MAAM,EAAE;;gBAEl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AEM,QAAU,CAAA,CAAA;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,oCAAaD,QAAU,EAAA;4BAAElC,IAAM,EAAA,OAAA;AAASoC,4BAAAA,YAAAA,EAAc1B,QAAQT;AAAK,yBAAA,CAAA;AAC5E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOuB,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import tsUtils from '@strapi/typescript-utils';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import getDestinationPrompts from './prompts/get-destination-prompts.mjs';
|
|
5
|
+
import validateInput from './utils/validate-input.mjs';
|
|
6
|
+
import getFilePath from './utils/get-file-path.mjs';
|
|
7
|
+
import { appendToFile } from './utils/extend-plugin-index-files.mjs';
|
|
8
|
+
|
|
9
|
+
var generateMiddleware = ((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(), {
|
|
21
|
+
rootFolder: true
|
|
22
|
+
})
|
|
23
|
+
],
|
|
24
|
+
actions (answers) {
|
|
25
|
+
if (!answers) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const filePath = getFilePath(answers.destination);
|
|
29
|
+
const currentDir = process.cwd();
|
|
30
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
31
|
+
if (answers.plugin) {
|
|
32
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
33
|
+
const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
34
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
35
|
+
}
|
|
36
|
+
const baseActions = [
|
|
37
|
+
{
|
|
38
|
+
type: 'add',
|
|
39
|
+
path: `${filePath}/middlewares/{{ name }}.${language}`,
|
|
40
|
+
templateFile: `templates/${language}/middleware.${language}.hbs`
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
if (answers.plugin) {
|
|
44
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);
|
|
45
|
+
const exists = fs.existsSync(indexPath);
|
|
46
|
+
if (!exists) {
|
|
47
|
+
// Create index file if it doesn't exist
|
|
48
|
+
baseActions.push({
|
|
49
|
+
type: 'add',
|
|
50
|
+
path: `${filePath}/middlewares/index.${language}`,
|
|
51
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
52
|
+
skipIfExists: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Append the new middleware to the index.ts file
|
|
56
|
+
baseActions.push({
|
|
57
|
+
type: 'modify',
|
|
58
|
+
path: `${filePath}/middlewares/index.${language}`,
|
|
59
|
+
transform (template) {
|
|
60
|
+
return appendToFile(template, {
|
|
61
|
+
type: 'index',
|
|
62
|
+
singularName: answers.name
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return baseActions;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export { generateMiddleware as default };
|
|
73
|
+
//# sourceMappingURL=middleware.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"middleware.mjs","sources":["../../src/plops/middleware.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\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 // middleware generator\n plop.setGenerator('middleware', {\n description: 'Generate a middleware for an API',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Middleware name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('middleware', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const filePath = getFilePath(answers.destination);\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}/middlewares/{{ name }}.${language}`,\n templateFile: `templates/${language}/middleware.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/middlewares/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new middleware to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/middlewares/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.name });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","rootFolder","actions","answers","filePath","getFilePath","destination","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName"],"mappings":";;;;;;;;AAUA,yBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,YAAc,EAAA;QAC9BC,WAAa,EAAA,kCAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,MAAA;gBACNC,OAAS,EAAA,iBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;eACGE,qBAAsB,CAAA,YAAA,EAAcV,IAAKW,CAAAA,eAAe,EAAI,EAAA;gBAAEC,UAAY,EAAA;AAAK,aAAA;AACnF,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAS,EAAA;AACZ,gBAAA,OAAO,EAAE;AACX;YAEA,MAAMC,QAAAA,GAAWC,WAAYF,CAAAA,OAAAA,CAAQG,WAAW,CAAA;YAChD,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,IAAIC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;YAElE,IAAIJ,OAAAA,CAAQU,MAAM,EAAE;;gBAElB,MAAMC,eAAAA,GAAkBC,IACtBR,CAAAA,UAAAA,EACA,KACAH,EAAAA,QAAAA,CAASY,OAAO,CAAC,cAAA,EAAgBb,OAAQU,CAAAA,MAAM,CAC/C,EAAA,KAAA,CAAA;AAEFH,gBAAAA,QAAAA,GAAWC,OAAQC,CAAAA,qBAAqB,CAACE,eAAAA,CAAAA,GAAmB,IAAO,GAAA,IAAA;AACrE;AAEA,YAAA,MAAMG,WAAiC,GAAA;AACrC,gBAAA;oBACExB,IAAM,EAAA,KAAA;AACNyB,oBAAAA,IAAAA,EAAM,CAAG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var tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
var validateFileNameInput = require('./utils/validate-file-name-input.js');
|
|
5
|
+
var getFormattedDate = require('./utils/get-formatted-date.js');
|
|
6
|
+
|
|
7
|
+
var generateMigration = ((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
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
type: 'add',
|
|
26
|
+
path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
|
|
27
|
+
templateFile: `templates/${language}/migration.${language}.hbs`
|
|
28
|
+
}
|
|
29
|
+
];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
module.exports = generateMigration;
|
|
35
|
+
//# sourceMappingURL=migration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.js","sources":["../../src/plops/migration.ts"],"sourcesContent":["import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport validateFileNameInput from './utils/validate-file-name-input';\nimport getFormattedDate from './utils/get-formatted-date';\n\nexport default (plop: NodePlopAPI) => {\n // Migration generator\n plop.setGenerator('migration', {\n description: 'Generate a migration',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Migration name',\n validate: (input) => validateFileNameInput(input),\n },\n ],\n actions() {\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n const timestamp = getFormattedDate();\n\n return [\n {\n type: 'add',\n path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,\n templateFile: `templates/${language}/migration.${language}.hbs`,\n },\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateFileNameInput","actions","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","timestamp","getFormattedDate","path","templateFile"],"mappings":";;;;;;AAKA,wBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,WAAa,EAAA;QAC7BC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,MAAA;gBACNC,OAAS,EAAA,gBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,qBAAsBD,CAAAA,KAAAA;AAC7C;AACD,SAAA;AACDE,QAAAA,OAAAA,CAAAA,GAAAA;YACE,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,MAAMC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;AACpE,YAAA,MAAMM,SAAYC,GAAAA,gBAAAA,EAAAA;YAElB,OAAO;AACL,gBAAA;oBACEd,IAAM,EAAA,KAAA;AACNe,oBAAAA,IAAAA,EAAM,GAAGR,UAAW,CAAA,qBAAqB,EAAEM,SAAU,CAAA,YAAY,EAAEH,QAAU,CAAA,CAAA;oBAC7EM,YAAc,EAAA,CAAC,UAAU,EAAEN,QAAAA,CAAS,WAAW,EAAEA,QAAAA,CAAS,IAAI;AAChE;AACD,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import tsUtils from '@strapi/typescript-utils';
|
|
2
|
+
import validateFileNameInput from './utils/validate-file-name-input.mjs';
|
|
3
|
+
import getFormattedDate from './utils/get-formatted-date.mjs';
|
|
4
|
+
|
|
5
|
+
var generateMigration = ((plop)=>{
|
|
6
|
+
// Migration generator
|
|
7
|
+
plop.setGenerator('migration', {
|
|
8
|
+
description: 'Generate a migration',
|
|
9
|
+
prompts: [
|
|
10
|
+
{
|
|
11
|
+
type: 'input',
|
|
12
|
+
name: 'name',
|
|
13
|
+
message: 'Migration name',
|
|
14
|
+
validate: (input)=>validateFileNameInput(input)
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
actions () {
|
|
18
|
+
const currentDir = process.cwd();
|
|
19
|
+
const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
20
|
+
const timestamp = getFormattedDate();
|
|
21
|
+
return [
|
|
22
|
+
{
|
|
23
|
+
type: 'add',
|
|
24
|
+
path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,
|
|
25
|
+
templateFile: `templates/${language}/migration.${language}.hbs`
|
|
26
|
+
}
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export { generateMigration as default };
|
|
33
|
+
//# sourceMappingURL=migration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migration.mjs","sources":["../../src/plops/migration.ts"],"sourcesContent":["import type { NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport validateFileNameInput from './utils/validate-file-name-input';\nimport getFormattedDate from './utils/get-formatted-date';\n\nexport default (plop: NodePlopAPI) => {\n // Migration generator\n plop.setGenerator('migration', {\n description: 'Generate a migration',\n prompts: [\n {\n type: 'input',\n name: 'name',\n message: 'Migration name',\n validate: (input) => validateFileNameInput(input),\n },\n ],\n actions() {\n const currentDir = process.cwd();\n const language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';\n const timestamp = getFormattedDate();\n\n return [\n {\n type: 'add',\n path: `${currentDir}/database/migrations/${timestamp}.{{ name }}.${language}`,\n templateFile: `templates/${language}/migration.${language}.hbs`,\n },\n ];\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateFileNameInput","actions","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","timestamp","getFormattedDate","path","templateFile"],"mappings":";;;;AAKA,wBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,WAAa,EAAA;QAC7BC,WAAa,EAAA,sBAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,MAAA;gBACNC,OAAS,EAAA,gBAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,qBAAsBD,CAAAA,KAAAA;AAC7C;AACD,SAAA;AACDE,QAAAA,OAAAA,CAAAA,GAAAA;YACE,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,MAAMC,QAAWC,GAAAA,OAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAO,GAAA,IAAA;AACpE,YAAA,MAAMM,SAAYC,GAAAA,gBAAAA,EAAAA;YAElB,OAAO;AACL,gBAAA;oBACEd,IAAM,EAAA,KAAA;AACNe,oBAAAA,IAAAA,EAAM,GAAGR,UAAW,CAAA,qBAAqB,EAAEM,SAAU,CAAA,YAAY,EAAEH,QAAU,CAAA,CAAA;oBAC7EM,YAAc,EAAA,CAAC,UAAU,EAAEN,QAAAA,CAAS,WAAW,EAAEA,QAAAA,CAAS,IAAI;AAChE;AACD,aAAA;AACH;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/plops/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/plops/policy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,MAAM,CAAC;+BAU9B,WAAW;AAAjC,wBAoEE"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var tsUtils = require('@strapi/typescript-utils');
|
|
4
|
+
var path = require('path');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
|
|
7
|
+
var validateInput = require('./utils/validate-input.js');
|
|
8
|
+
var getFilePath = require('./utils/get-file-path.js');
|
|
9
|
+
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
10
|
+
|
|
11
|
+
var generatePolicy = ((plop)=>{
|
|
12
|
+
// Policy generator
|
|
13
|
+
plop.setGenerator('policy', {
|
|
14
|
+
description: 'Generate a policy for an API',
|
|
15
|
+
prompts: [
|
|
16
|
+
{
|
|
17
|
+
type: 'input',
|
|
18
|
+
name: 'id',
|
|
19
|
+
message: 'Policy name',
|
|
20
|
+
validate: (input)=>validateInput(input)
|
|
21
|
+
},
|
|
22
|
+
...getDestinationPrompts('policy', plop.getDestBasePath(), {
|
|
23
|
+
rootFolder: true
|
|
24
|
+
})
|
|
25
|
+
],
|
|
26
|
+
actions (answers) {
|
|
27
|
+
if (!answers) {
|
|
28
|
+
return [];
|
|
29
|
+
}
|
|
30
|
+
const currentDir = process.cwd();
|
|
31
|
+
const filePath = getFilePath(answers.destination);
|
|
32
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
33
|
+
if (answers.plugin) {
|
|
34
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
35
|
+
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
36
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
37
|
+
}
|
|
38
|
+
const baseActions = [
|
|
39
|
+
{
|
|
40
|
+
type: 'add',
|
|
41
|
+
path: `${filePath}/policies/{{ id }}.${language}`,
|
|
42
|
+
templateFile: `templates/${language}/policy.${language}.hbs`
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
if (answers.plugin) {
|
|
46
|
+
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/policies/index.${language}`);
|
|
47
|
+
const exists = fs.existsSync(indexPath);
|
|
48
|
+
if (!exists) {
|
|
49
|
+
// Create index file if it doesn't exist
|
|
50
|
+
baseActions.push({
|
|
51
|
+
type: 'add',
|
|
52
|
+
path: `${filePath}/policies/index.${language}`,
|
|
53
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
54
|
+
skipIfExists: true
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
// Append the new policy to the index.ts file
|
|
58
|
+
baseActions.push({
|
|
59
|
+
type: 'modify',
|
|
60
|
+
path: `${filePath}/policies/index.${language}`,
|
|
61
|
+
transform (template) {
|
|
62
|
+
return extendPluginIndexFiles.appendToFile(template, {
|
|
63
|
+
type: 'index',
|
|
64
|
+
singularName: answers.id
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return baseActions;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
module.exports = generatePolicy;
|
|
75
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","sources":["../../src/plops/policy.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\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 // Policy generator\n plop.setGenerator('policy', {\n description: 'Generate a policy for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Policy name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('policy', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const currentDir = process.cwd();\n const filePath = getFilePath(answers.destination);\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}/policies/{{ id }}.${language}`,\n templateFile: `templates/${language}/policy.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/policies/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/policies/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new policy to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/policies/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","rootFolder","actions","answers","currentDir","process","cwd","filePath","getFilePath","destination","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;;;AAUA,qBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,QAAU,EAAA;QAC1BC,WAAa,EAAA,8BAAA;QACbC,O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AAKW,CAAAA,eAAe,IAAI,CAAGO,EAAAA,QAAAA,CAAS,gBAAgB,EAAEG,QAAU,CAAA,CAAA,CAAA;gBACvF,MAAMW,MAAAA,GAASC,EAAGC,CAAAA,UAAU,CAACH,SAAAA,CAAAA;AAE7B,gBAAA,IAAI,CAACC,MAAQ,EAAA;;AAEXJ,oBAAAA,WAAAA,CAAYO,IAAI,CAAC;wBACf/B,IAAM,EAAA,KAAA;AACNyB,wBAAAA,IAAAA,EAAM,CAAGX,EAAAA,QAAAA,CAAS,gBAAgB,EAAEG,QAAU,CAAA,CAAA;wBAC9CS,YAAc,EAAA,CAAC,UAAU,EAAET,QAAAA,CAAS,qBAAqB,EAAEA,QAAAA,CAAS,IAAI,CAAC;wBACzEe,YAAc,EAAA;AAChB,qBAAA,CAAA;AACF;;AAGAR,gBAAAA,WAAAA,CAAYO,IAAI,CAAC;oBACf/B,IAAM,EAAA,QAAA;AACNyB,oBAAAA,IAAAA,EAAM,CAAGX,EAAAA,QAAAA,CAAS,gBAAgB,EAAEG,QAAU,CAAA,CAAA;AAC9CgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,oCAAaD,QAAU,EAAA;4BAAElC,IAAM,EAAA,OAAA;AAASoC,4BAAAA,YAAAA,EAAc1B,QAAQ2B;AAAG,yBAAA,CAAA;AAC1E;AACF,iBAAA,CAAA;AACF;YAEA,OAAOb,WAAAA;AACT;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import tsUtils from '@strapi/typescript-utils';
|
|
2
|
+
import { join } from 'path';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import getDestinationPrompts from './prompts/get-destination-prompts.mjs';
|
|
5
|
+
import validateInput from './utils/validate-input.mjs';
|
|
6
|
+
import getFilePath from './utils/get-file-path.mjs';
|
|
7
|
+
import { appendToFile } from './utils/extend-plugin-index-files.mjs';
|
|
8
|
+
|
|
9
|
+
var generatePolicy = ((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(), {
|
|
21
|
+
rootFolder: true
|
|
22
|
+
})
|
|
23
|
+
],
|
|
24
|
+
actions (answers) {
|
|
25
|
+
if (!answers) {
|
|
26
|
+
return [];
|
|
27
|
+
}
|
|
28
|
+
const currentDir = process.cwd();
|
|
29
|
+
const filePath = getFilePath(answers.destination);
|
|
30
|
+
let language = tsUtils.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
31
|
+
if (answers.plugin) {
|
|
32
|
+
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
33
|
+
const pluginServerDir = join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
34
|
+
language = tsUtils.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
35
|
+
}
|
|
36
|
+
const baseActions = [
|
|
37
|
+
{
|
|
38
|
+
type: 'add',
|
|
39
|
+
path: `${filePath}/policies/{{ id }}.${language}`,
|
|
40
|
+
templateFile: `templates/${language}/policy.${language}.hbs`
|
|
41
|
+
}
|
|
42
|
+
];
|
|
43
|
+
if (answers.plugin) {
|
|
44
|
+
const indexPath = join(plop.getDestBasePath(), `${filePath}/policies/index.${language}`);
|
|
45
|
+
const exists = fs.existsSync(indexPath);
|
|
46
|
+
if (!exists) {
|
|
47
|
+
// Create index file if it doesn't exist
|
|
48
|
+
baseActions.push({
|
|
49
|
+
type: 'add',
|
|
50
|
+
path: `${filePath}/policies/index.${language}`,
|
|
51
|
+
templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,
|
|
52
|
+
skipIfExists: true
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
// Append the new policy to the index.ts file
|
|
56
|
+
baseActions.push({
|
|
57
|
+
type: 'modify',
|
|
58
|
+
path: `${filePath}/policies/index.${language}`,
|
|
59
|
+
transform (template) {
|
|
60
|
+
return appendToFile(template, {
|
|
61
|
+
type: 'index',
|
|
62
|
+
singularName: answers.id
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
return baseActions;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export { generatePolicy as default };
|
|
73
|
+
//# sourceMappingURL=policy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.mjs","sources":["../../src/plops/policy.ts"],"sourcesContent":["import type { ActionType, NodePlopAPI } from 'plop';\nimport tsUtils from '@strapi/typescript-utils';\nimport { join } from 'path';\nimport fs from 'fs';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\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 // Policy generator\n plop.setGenerator('policy', {\n description: 'Generate a policy for an API',\n prompts: [\n {\n type: 'input',\n name: 'id',\n message: 'Policy name',\n validate: (input) => validateInput(input),\n },\n ...getDestinationPrompts('policy', plop.getDestBasePath(), { rootFolder: true }),\n ],\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const currentDir = process.cwd();\n const filePath = getFilePath(answers.destination);\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}/policies/{{ id }}.${language}`,\n templateFile: `templates/${language}/policy.${language}.hbs`,\n },\n ];\n\n if (answers.plugin) {\n const indexPath = join(plop.getDestBasePath(), `${filePath}/policies/index.${language}`);\n const exists = fs.existsSync(indexPath);\n\n if (!exists) {\n // Create index file if it doesn't exist\n baseActions.push({\n type: 'add',\n path: `${filePath}/policies/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new policy to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/policies/index.${language}`,\n transform(template: string) {\n return appendToFile(template, { type: 'index', singularName: answers.id });\n },\n });\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","type","name","message","validate","input","validateInput","getDestinationPrompts","getDestBasePath","rootFolder","actions","answers","currentDir","process","cwd","filePath","getFilePath","destination","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","join","replace","baseActions","path","templateFile","indexPath","exists","fs","existsSync","push","skipIfExists","transform","template","appendToFile","singularName","id"],"mappings":";;;;;;;;AAUA,qBAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAKC,CAAAA,YAAY,CAAC,QAAU,EAAA;QAC1BC,WAAa,EAAA,8BAAA;QACbC,OAAS,EAAA;AACP,YAAA;gBACEC,IAAM,EAAA,OAAA;gBACNC,IAAM,EAAA,IAAA;gBACNC,OAAS,EAAA,aAAA;gBACTC,QAAU,EAAA,CAACC,QAAUC,aAAcD,CAAAA,KAAAA;AACrC,aAAA;eACGE,qBAAsB,CAAA,QAAA,EAAUV,IAAKW,CAAAA,eAAe,EAAI,EAAA;gBAAEC,UAAY,EAAA;AAAK,aAAA;AAC/E,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAS,EAAA;AACZ,gBAAA,OAAO,EAAE;AACX;YAEA,M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