@strapi/generators 5.48.0 → 5.49.0
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.js +14 -9
- package/dist/index.js.map +1 -1
- package/dist/plopfile.js +5 -1
- package/dist/plopfile.js.map +1 -1
- package/dist/plops/api.js +12 -7
- package/dist/plops/api.js.map +1 -1
- package/dist/plops/content-type.js +15 -9
- package/dist/plops/content-type.js.map +1 -1
- package/dist/plops/controller.js +8 -3
- package/dist/plops/controller.js.map +1 -1
- package/dist/plops/middleware.js +8 -3
- package/dist/plops/middleware.js.map +1 -1
- package/dist/plops/migration.js +5 -1
- package/dist/plops/migration.js.map +1 -1
- package/dist/plops/policy.js +8 -3
- package/dist/plops/policy.js.map +1 -1
- package/dist/plops/prompts/ct-names-prompts.js +7 -2
- package/dist/plops/prompts/ct-names-prompts.js.map +1 -1
- package/dist/plops/prompts/get-destination-prompts.js +9 -5
- package/dist/plops/prompts/get-destination-prompts.js.map +1 -1
- package/dist/plops/service.js +8 -3
- package/dist/plops/service.js.map +1 -1
- package/dist/plops/utils/extend-plugin-index-files.js +16 -12
- package/dist/plops/utils/extend-plugin-index-files.js.map +1 -1
- package/dist/plops/utils/extend-plugin-index-files.mjs +6 -6
- package/dist/plops/utils/extend-plugin-index-files.mjs.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -4,6 +4,11 @@ var node_path = require('node:path');
|
|
|
4
4
|
var handlebars = require('handlebars');
|
|
5
5
|
var fs = require('fs-extra');
|
|
6
6
|
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var handlebars__default = /*#__PURE__*/_interopDefault(handlebars);
|
|
10
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
11
|
+
|
|
7
12
|
// Starts the Plop CLI programmatically
|
|
8
13
|
const runCLI = async ()=>{
|
|
9
14
|
const { Plop, run } = await import('plop');
|
|
@@ -64,29 +69,29 @@ const generate = async (generatorName, options, { dir = process.cwd(), plopFile
|
|
|
64
69
|
};
|
|
65
70
|
};
|
|
66
71
|
const registerHandlebarsHelpers = (helpers)=>{
|
|
67
|
-
Object.entries(helpers).forEach(([name, fn])=>
|
|
72
|
+
Object.entries(helpers).forEach(([name, fn])=>handlebars__default.default.registerHelper(name, fn));
|
|
68
73
|
};
|
|
69
74
|
// Executes generator actions: add or modify files as specified
|
|
70
75
|
const executeActions = async (actions, options, dir)=>{
|
|
71
76
|
for (const action of actions){
|
|
72
|
-
const outputPath =
|
|
77
|
+
const outputPath = handlebars__default.default.compile(action.path)(options);
|
|
73
78
|
const fullPath = node_path.join(dir, 'src', outputPath);
|
|
74
79
|
if (action.type === 'add' && action.templateFile) {
|
|
75
80
|
const templatePath = node_path.join(__dirname, action.templateFile);
|
|
76
|
-
const templateContent = await
|
|
77
|
-
const compiled =
|
|
81
|
+
const templateContent = await fs__default.default.readFile(templatePath, 'utf8');
|
|
82
|
+
const compiled = handlebars__default.default.compile(templateContent);
|
|
78
83
|
const output = compiled({
|
|
79
84
|
...options,
|
|
80
85
|
...action.data
|
|
81
86
|
});
|
|
82
|
-
await
|
|
83
|
-
await
|
|
87
|
+
await fs__default.default.ensureDir(node_path.dirname(fullPath));
|
|
88
|
+
await fs__default.default.writeFile(fullPath, output);
|
|
84
89
|
}
|
|
85
90
|
if (action.type === 'modify') {
|
|
86
|
-
if (await
|
|
87
|
-
const content = await
|
|
91
|
+
if (await fs__default.default.pathExists(fullPath)) {
|
|
92
|
+
const content = await fs__default.default.readFile(fullPath, 'utf8');
|
|
88
93
|
const modified = action.transform ? action.transform(content) : content;
|
|
89
|
-
await
|
|
94
|
+
await fs__default.default.writeFile(fullPath, modified);
|
|
90
95
|
}
|
|
91
96
|
}
|
|
92
97
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname } from 'node:path';\nimport handlebars from 'handlebars';\nimport fs from 'fs-extra';\n\n// Starts the Plop CLI programmatically\nexport const runCLI = async () => {\n const { Plop, run } = await import('plop');\n\n Plop.prepare(\n {\n configPath: join(__dirname, 'plopfile.js'),\n },\n (env) => {\n Plop.execute(env, [], (env, argv) => {\n const options = {\n ...env,\n dest: join(process.cwd(), 'src'), // this will make the destination path to be based on the cwd when calling the wrapper\n };\n return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes\n });\n }\n );\n};\n\ntype GenerateOptions = {\n dir?: string;\n plopFile?: string;\n};\n\ntype GeneratorAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\nexport const generate = async <T extends Record<string, any>>(\n generatorName: string,\n options: T,\n { dir = process.cwd(), plopFile = 'plopfile.js' }: GenerateOptions = {}\n) => {\n // Resolve the absolute path to the plopfile (generator definitions)\n const plopfilePath = join(__dirname, plopFile);\n // Dynamically require the plopfile module.\n // Note: This allows loading either CommonJS or transpiled ESM plopfiles.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const plopModule = require(plopfilePath);\n\n // Internal objects to store registered generators and helpers.\n // These will be populated by the plopfile when it is executed.\n const generators: Record<string, any> = {};\n const helpers: Record<string, any> = {};\n\n // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.\n // This allows the plopfile to register generators and helpers as it would in a real Plop environment.\n const plopApi = {\n setGenerator(name: string, config: any) {\n generators[name] = config;\n },\n setHelper(name: string, fn: any) {\n helpers[name] = fn;\n },\n getDestBasePath() {\n return join(dir, 'src');\n },\n setWelcomeMessage() {}, // no-op\n };\n\n // Execute the plopfile, passing in our API.\n // This will populate the `generators` and `helpers` objects.\n // Support both CommonJS and ESM default exports.\n if (typeof plopModule.default === 'function') {\n plopModule.default(plopApi);\n } else {\n plopModule(plopApi);\n }\n\n const generator = generators[generatorName];\n if (!generator) {\n throw new Error(`Generator \"${generatorName}\" not found`);\n }\n\n registerHandlebarsHelpers(helpers);\n const actions: GeneratorAction[] =\n typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];\n\n await executeActions(actions, options, dir);\n\n return { success: true };\n};\n\nconst registerHandlebarsHelpers = (helpers: Record<string, any>) => {\n Object.entries(helpers).forEach(([name, fn]) => handlebars.registerHelper(name, fn));\n};\n\n// Executes generator actions: add or modify files as specified\nconst executeActions = async (\n actions: GeneratorAction[],\n options: Record<string, any>,\n dir: string\n) => {\n for (const action of actions) {\n const outputPath = handlebars.compile(action.path)(options);\n const fullPath = join(dir, 'src', outputPath);\n\n if (action.type === 'add' && action.templateFile) {\n const templatePath = join(__dirname, action.templateFile);\n const templateContent = await fs.readFile(templatePath, 'utf8');\n const compiled = handlebars.compile(templateContent);\n const output = compiled({ ...options, ...action.data });\n\n await fs.ensureDir(dirname(fullPath));\n await fs.writeFile(fullPath, output);\n }\n\n if (action.type === 'modify') {\n if (await fs.pathExists(fullPath)) {\n const content = await fs.readFile(fullPath, 'utf8');\n const modified = action.transform ? action.transform(content) : content;\n await fs.writeFile(fullPath, modified);\n }\n }\n }\n};\n"],"names":["runCLI","Plop","run","prepare","configPath","join","__dirname","env","execute","argv","options","dest","process","cwd","generate","generatorName","dir","plopFile","plopfilePath","plopModule","require","generators","helpers","plopApi","setGenerator","name","config","setHelper","fn","getDestBasePath","setWelcomeMessage","default","generator","Error","registerHandlebarsHelpers","actions","executeActions","success","Object","entries","forEach","handlebars","registerHelper","action","outputPath","compile","path","fullPath","type","templateFile","templatePath","templateContent","fs","readFile","compiled","output","data","ensureDir","dirname","writeFile","pathExists","content","modified","transform"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname } from 'node:path';\nimport handlebars from 'handlebars';\nimport fs from 'fs-extra';\n\n// Starts the Plop CLI programmatically\nexport const runCLI = async () => {\n const { Plop, run } = await import('plop');\n\n Plop.prepare(\n {\n configPath: join(__dirname, 'plopfile.js'),\n },\n (env) => {\n Plop.execute(env, [], (env, argv) => {\n const options = {\n ...env,\n dest: join(process.cwd(), 'src'), // this will make the destination path to be based on the cwd when calling the wrapper\n };\n return run(options, argv, true); // Pass the third argument 'true' for passArgsBeforeDashes\n });\n }\n );\n};\n\ntype GenerateOptions = {\n dir?: string;\n plopFile?: string;\n};\n\ntype GeneratorAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\nexport const generate = async <T extends Record<string, any>>(\n generatorName: string,\n options: T,\n { dir = process.cwd(), plopFile = 'plopfile.js' }: GenerateOptions = {}\n) => {\n // Resolve the absolute path to the plopfile (generator definitions)\n const plopfilePath = join(__dirname, plopFile);\n // Dynamically require the plopfile module.\n // Note: This allows loading either CommonJS or transpiled ESM plopfiles.\n // eslint-disable-next-line @typescript-eslint/no-var-requires\n const plopModule = require(plopfilePath);\n\n // Internal objects to store registered generators and helpers.\n // These will be populated by the plopfile when it is executed.\n const generators: Record<string, any> = {};\n const helpers: Record<string, any> = {};\n\n // Minimal mock Plop API implementation, exposing only the methods needed by our plopfile.\n // This allows the plopfile to register generators and helpers as it would in a real Plop environment.\n const plopApi = {\n setGenerator(name: string, config: any) {\n generators[name] = config;\n },\n setHelper(name: string, fn: any) {\n helpers[name] = fn;\n },\n getDestBasePath() {\n return join(dir, 'src');\n },\n setWelcomeMessage() {}, // no-op\n };\n\n // Execute the plopfile, passing in our API.\n // This will populate the `generators` and `helpers` objects.\n // Support both CommonJS and ESM default exports.\n if (typeof plopModule.default === 'function') {\n plopModule.default(plopApi);\n } else {\n plopModule(plopApi);\n }\n\n const generator = generators[generatorName];\n if (!generator) {\n throw new Error(`Generator \"${generatorName}\" not found`);\n }\n\n registerHandlebarsHelpers(helpers);\n const actions: GeneratorAction[] =\n typeof generator.actions === 'function' ? generator.actions(options) : generator.actions || [];\n\n await executeActions(actions, options, dir);\n\n return { success: true };\n};\n\nconst registerHandlebarsHelpers = (helpers: Record<string, any>) => {\n Object.entries(helpers).forEach(([name, fn]) => handlebars.registerHelper(name, fn));\n};\n\n// Executes generator actions: add or modify files as specified\nconst executeActions = async (\n actions: GeneratorAction[],\n options: Record<string, any>,\n dir: string\n) => {\n for (const action of actions) {\n const outputPath = handlebars.compile(action.path)(options);\n const fullPath = join(dir, 'src', outputPath);\n\n if (action.type === 'add' && action.templateFile) {\n const templatePath = join(__dirname, action.templateFile);\n const templateContent = await fs.readFile(templatePath, 'utf8');\n const compiled = handlebars.compile(templateContent);\n const output = compiled({ ...options, ...action.data });\n\n await fs.ensureDir(dirname(fullPath));\n await fs.writeFile(fullPath, output);\n }\n\n if (action.type === 'modify') {\n if (await fs.pathExists(fullPath)) {\n const content = await fs.readFile(fullPath, 'utf8');\n const modified = action.transform ? action.transform(content) : content;\n await fs.writeFile(fullPath, modified);\n }\n }\n }\n};\n"],"names":["runCLI","Plop","run","prepare","configPath","join","__dirname","env","execute","argv","options","dest","process","cwd","generate","generatorName","dir","plopFile","plopfilePath","plopModule","require","generators","helpers","plopApi","setGenerator","name","config","setHelper","fn","getDestBasePath","setWelcomeMessage","default","generator","Error","registerHandlebarsHelpers","actions","executeActions","success","Object","entries","forEach","handlebars","registerHelper","action","outputPath","compile","path","fullPath","type","templateFile","templatePath","templateContent","fs","readFile","compiled","output","data","ensureDir","dirname","writeFile","pathExists","content","modified","transform"],"mappings":";;;;;;;;;;;AAIA;MACaA,MAAAA,GAAS,UAAA;IACpB,MAAM,EAAEC,IAAI,EAAEC,GAAG,EAAE,GAAG,MAAM,OAAO,MAAA,CAAA;AAEnCD,IAAAA,IAAAA,CAAKE,OAAO,CACV;AACEC,QAAAA,UAAAA,EAAYC,eAAKC,SAAAA,EAAW,aAAA;AAC9B,KAAA,EACA,CAACC,GAAAA,GAAAA;AACCN,QAAAA,IAAAA,CAAKO,OAAO,CAACD,GAAAA,EAAK,EAAE,EAAE,CAACA,GAAAA,EAAKE,IAAAA,GAAAA;AAC1B,YAAA,MAAMC,OAAAA,G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A,GAAkB,MAAMC,mBAAAA,CAAGC,QAAQ,CAACH,YAAAA,EAAc,MAAA,CAAA;YACxD,MAAMI,QAAAA,GAAWb,2BAAAA,CAAWI,OAAO,CAACM,eAAAA,CAAAA;AACpC,YAAA,MAAMI,SAASD,QAAAA,CAAS;AAAE,gBAAA,GAAG5C,OAAO;AAAE,gBAAA,GAAGiC,OAAOa;AAAK,aAAA,CAAA;YAErD,MAAMJ,mBAAAA,CAAGK,SAAS,CAACC,iBAAAA,CAAQX,QAAAA,CAAAA,CAAAA;YAC3B,MAAMK,mBAAAA,CAAGO,SAAS,CAACZ,QAAAA,EAAUQ,MAAAA,CAAAA;AAC/B,QAAA;QAEA,IAAIZ,MAAAA,CAAOK,IAAI,KAAK,QAAA,EAAU;AAC5B,YAAA,IAAI,MAAMI,mBAAAA,CAAGQ,UAAU,CAACb,QAAAA,CAAAA,EAAW;AACjC,gBAAA,MAAMc,OAAAA,GAAU,MAAMT,mBAAAA,CAAGC,QAAQ,CAACN,QAAAA,EAAU,MAAA,CAAA;AAC5C,gBAAA,MAAMe,WAAWnB,MAAAA,CAAOoB,SAAS,GAAGpB,MAAAA,CAAOoB,SAAS,CAACF,OAAAA,CAAAA,GAAWA,OAAAA;gBAChE,MAAMT,mBAAAA,CAAGO,SAAS,CAACZ,QAAAA,EAAUe,QAAAA,CAAAA;AAC/B,YAAA;AACF,QAAA;AACF,IAAA;AACF,CAAA;;;;;"}
|
package/dist/plopfile.js
CHANGED
|
@@ -9,10 +9,14 @@ var middleware = require('./plops/middleware.js');
|
|
|
9
9
|
var migration = require('./plops/migration.js');
|
|
10
10
|
var service = require('./plops/service.js');
|
|
11
11
|
|
|
12
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
|
|
14
|
+
var pluralize__default = /*#__PURE__*/_interopDefault(pluralize);
|
|
15
|
+
|
|
12
16
|
var plopfile = ((plop)=>{
|
|
13
17
|
// Plop config
|
|
14
18
|
plop.setWelcomeMessage('Strapi Generators');
|
|
15
|
-
plop.setHelper('pluralize', (text)=>
|
|
19
|
+
plop.setHelper('pluralize', (text)=>pluralize__default.default(text));
|
|
16
20
|
// Generators
|
|
17
21
|
api(plop);
|
|
18
22
|
controller(plop);
|
package/dist/plopfile.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plopfile.js","sources":["../src/plopfile.ts"],"sourcesContent":["import pluralize from 'pluralize';\nimport type { NodePlopAPI } from 'plop';\n\nimport generateApi from './plops/api';\nimport generateController from './plops/controller';\nimport generateContentType from './plops/content-type';\nimport generatePolicy from './plops/policy';\nimport generateMiddleware from './plops/middleware';\nimport generateMigration from './plops/migration';\nimport generateService from './plops/service';\n\nexport default (plop: NodePlopAPI) => {\n // Plop config\n plop.setWelcomeMessage('Strapi Generators');\n plop.setHelper('pluralize', (text: string) => pluralize(text));\n\n // Generators\n generateApi(plop);\n generateController(plop);\n generateContentType(plop);\n generatePolicy(plop);\n generateMiddleware(plop);\n generateMigration(plop);\n generateService(plop);\n};\n"],"names":["plop","setWelcomeMessage","setHelper","text","pluralize","generateApi","generateController","generateContentType","generatePolicy","generateMiddleware","generateMigration","generateService"],"mappings":"
|
|
1
|
+
{"version":3,"file":"plopfile.js","sources":["../src/plopfile.ts"],"sourcesContent":["import pluralize from 'pluralize';\nimport type { NodePlopAPI } from 'plop';\n\nimport generateApi from './plops/api';\nimport generateController from './plops/controller';\nimport generateContentType from './plops/content-type';\nimport generatePolicy from './plops/policy';\nimport generateMiddleware from './plops/middleware';\nimport generateMigration from './plops/migration';\nimport generateService from './plops/service';\n\nexport default (plop: NodePlopAPI) => {\n // Plop config\n plop.setWelcomeMessage('Strapi Generators');\n plop.setHelper('pluralize', (text: string) => pluralize(text));\n\n // Generators\n generateApi(plop);\n generateController(plop);\n generateContentType(plop);\n generatePolicy(plop);\n generateMiddleware(plop);\n generateMigration(plop);\n generateService(plop);\n};\n"],"names":["plop","setWelcomeMessage","setHelper","text","pluralize","generateApi","generateController","generateContentType","generatePolicy","generateMiddleware","generateMigration","generateService"],"mappings":";;;;;;;;;;;;;;;AAWA,eAAe,CAAA,CAACA,IAAAA,GAAAA;;AAEdA,IAAAA,IAAAA,CAAKC,iBAAiB,CAAC,mBAAA,CAAA;AACvBD,IAAAA,IAAAA,CAAKE,SAAS,CAAC,WAAA,EAAa,CAACC,OAAiBC,0BAAAA,CAAUD,IAAAA,CAAAA,CAAAA;;IAGxDE,GAAAA,CAAYL,IAAAA,CAAAA;IACZM,UAAAA,CAAmBN,IAAAA,CAAAA;IACnBO,WAAAA,CAAoBP,IAAAA,CAAAA;IACpBQ,MAAAA,CAAeR,IAAAA,CAAAA;IACfS,UAAAA,CAAmBT,IAAAA,CAAAA;IACnBU,SAAAA,CAAkBV,IAAAA,CAAAA;IAClBW,OAAAA,CAAgBX,IAAAA,CAAAA;AAClB,CAAA;;;;"}
|
package/dist/plops/api.js
CHANGED
|
@@ -7,6 +7,11 @@ var validateInput = require('./utils/validate-input.js');
|
|
|
7
7
|
var getFilePath = require('./utils/get-file-path.js');
|
|
8
8
|
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
9
9
|
|
|
10
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
+
|
|
12
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
13
|
+
var tsUtils__default = /*#__PURE__*/_interopDefault(tsUtils);
|
|
14
|
+
|
|
10
15
|
var generateApi = ((plop)=>{
|
|
11
16
|
// API generator
|
|
12
17
|
plop.setGenerator('api', {
|
|
@@ -30,11 +35,11 @@ var generateApi = ((plop)=>{
|
|
|
30
35
|
message: 'Plugin name',
|
|
31
36
|
async choices () {
|
|
32
37
|
const pluginsPath = path.join(plop.getDestBasePath(), 'plugins');
|
|
33
|
-
const exists = await
|
|
38
|
+
const exists = await fs__default.default.pathExists(pluginsPath);
|
|
34
39
|
if (!exists) {
|
|
35
40
|
throw Error('Couldn\'t find a "plugins" directory');
|
|
36
41
|
}
|
|
37
|
-
const pluginsDir = await
|
|
42
|
+
const pluginsDir = await fs__default.default.readdir(pluginsPath, {
|
|
38
43
|
withFileTypes: true
|
|
39
44
|
});
|
|
40
45
|
const pluginsDirContent = pluginsDir.filter((fd)=>fd.isDirectory());
|
|
@@ -51,11 +56,11 @@ var generateApi = ((plop)=>{
|
|
|
51
56
|
}
|
|
52
57
|
const filePath = getFilePath(answers.destination || (answers.isPluginApi && answers.plugin ? 'plugin' : 'api'));
|
|
53
58
|
const currentDir = process.cwd();
|
|
54
|
-
let language =
|
|
59
|
+
let language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
55
60
|
if (answers.plugin) {
|
|
56
61
|
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
57
62
|
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
58
|
-
language =
|
|
63
|
+
language = tsUtils__default.default.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
59
64
|
}
|
|
60
65
|
const baseActions = [
|
|
61
66
|
{
|
|
@@ -82,7 +87,7 @@ var generateApi = ((plop)=>{
|
|
|
82
87
|
];
|
|
83
88
|
indexFiles.forEach((type)=>{
|
|
84
89
|
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
85
|
-
const exists =
|
|
90
|
+
const exists = fs__default.default.existsSync(indexPath);
|
|
86
91
|
if (!exists && type !== 'routes') {
|
|
87
92
|
baseActions.push({
|
|
88
93
|
type: 'add',
|
|
@@ -93,7 +98,7 @@ var generateApi = ((plop)=>{
|
|
|
93
98
|
}
|
|
94
99
|
if (type === 'routes') {
|
|
95
100
|
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
96
|
-
const exists =
|
|
101
|
+
const exists = fs__default.default.existsSync(indexPath);
|
|
97
102
|
if (!exists) {
|
|
98
103
|
baseActions.push({
|
|
99
104
|
type: 'add',
|
|
@@ -108,7 +113,7 @@ var generateApi = ((plop)=>{
|
|
|
108
113
|
];
|
|
109
114
|
routeIndexFiles.forEach((routeType)=>{
|
|
110
115
|
const routeTypeIndexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/${routeType}/index.${language}`);
|
|
111
|
-
const routeTypeExists =
|
|
116
|
+
const routeTypeExists = fs__default.default.existsSync(routeTypeIndexPath);
|
|
112
117
|
if (!routeTypeExists) {
|
|
113
118
|
baseActions.push({
|
|
114
119
|
type: 'add',
|
package/dist/plops/api.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,IAAAA,CAAKC,YAAY,CAAC,KAAA,EAAO;QACvBC,WAAAA,EAAa,sBAAA;QACbC,OAAAA,EAAS;AACP,YAAA;gBACEC,IAAAA,EAAM,OAAA;gBACNC,IAAAA,EAAM,IAAA;gBACNC,OAAAA,EAAS,UAAA;gBACTC,QAAAA,EAAU,CAACC,QAAUC,aAAAA,CAAcD,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAAA,EAAM,SAAA;gBACNC,IAAAA,EAAM,aAAA;gBACNC,OAAAA,EAAS;AACX,aAAA;AACA,YAAA;gBACEI,IAAAA,EAAM,CAACC,OAAAA,GAAYA,OAAAA,CAAQC,WAAW;gBACtCR,IAAAA,EAAM,MAAA;gBACNC,IAAAA,EAAM,QAAA;gBACNC,OAAAA,EAAS,aAA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B,EAAA;AACxB,4BAAA,IAAIrD,SAAS,QAAA,EAAU;AACrB,gCAAA,OAAOsD,oCAAaD,QAAAA,EAAU;oCAAErD,IAAAA,EAAM,QAAA;AAAUuD,oCAAAA,YAAAA,EAAchD,QAAQiD;AAAG,iCAAA,CAAA;AAC3E,4BAAA;AAEA,4BAAA,OAAOF,oCAAaD,QAAAA,EAAU;gCAAErD,IAAAA,EAAM,OAAA;AAASuD,gCAAAA,YAAAA,EAAchD,QAAQiD;AAAG,6BAAA,CAAA;AAC1E,wBAAA;AACF,qBAAA,CAAA;AACF,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAOlB,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
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,IAAAA,CAAKC,YAAY,CAAC,KAAA,EAAO;QACvBC,WAAAA,EAAa,sBAAA;QACbC,OAAAA,EAAS;AACP,YAAA;gBACEC,IAAAA,EAAM,OAAA;gBACNC,IAAAA,EAAM,IAAA;gBACNC,OAAAA,EAAS,UAAA;gBACTC,QAAAA,EAAU,CAACC,QAAUC,aAAAA,CAAcD,KAAAA;AACrC,aAAA;AACA,YAAA;gBACEJ,IAAAA,EAAM,SAAA;gBACNC,IAAAA,EAAM,aAAA;gBACNC,OAAAA,EAAS;AACX,aAAA;AACA,YAAA;gBACEI,IAAAA,EAAM,CAACC,OAAAA,GAAYA,OAAAA,C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,GAAiB,EAAA,CAAG,MAAM,EAAEiC,QAAAA,CAAAA,CAAU;AACvFmB,wBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,4BAAA,IAAIrD,SAAS,QAAA,EAAU;AACrB,gCAAA,OAAOsD,oCAAaD,QAAAA,EAAU;oCAAErD,IAAAA,EAAM,QAAA;AAAUuD,oCAAAA,YAAAA,EAAchD,QAAQiD;AAAG,iCAAA,CAAA;AAC3E,4BAAA;AAEA,4BAAA,OAAOF,oCAAaD,QAAAA,EAAU;gCAAErD,IAAAA,EAAM,OAAA;AAASuD,gCAAAA,YAAAA,EAAchD,QAAQiD;AAAG,6BAAA,CAAA;AAC1E,wBAAA;AACF,qBAAA,CAAA;AACF,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAOlB,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -13,6 +13,12 @@ var getAttributesPrompts = require('./prompts/get-attributes-prompts.js');
|
|
|
13
13
|
var bootstrapApiPrompts = require('./prompts/bootstrap-api-prompts.js');
|
|
14
14
|
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
15
15
|
|
|
16
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
|
+
|
|
18
|
+
var slugify__default = /*#__PURE__*/_interopDefault(slugify);
|
|
19
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
20
|
+
var tsUtils__default = /*#__PURE__*/_interopDefault(tsUtils);
|
|
21
|
+
|
|
16
22
|
var generateContentType = ((plop)=>{
|
|
17
23
|
// Model generator
|
|
18
24
|
plop.setGenerator('content-type', {
|
|
@@ -36,11 +42,11 @@ var generateContentType = ((plop)=>{
|
|
|
36
42
|
return 'Value must be in kebab-case';
|
|
37
43
|
}
|
|
38
44
|
const apiPath = path.join(plop.getDestBasePath(), 'api');
|
|
39
|
-
const exists = await
|
|
45
|
+
const exists = await fs__default.default.pathExists(apiPath);
|
|
40
46
|
if (!exists) {
|
|
41
47
|
return true;
|
|
42
48
|
}
|
|
43
|
-
const apiDir = await
|
|
49
|
+
const apiDir = await fs__default.default.readdir(apiPath, {
|
|
44
50
|
withFileTypes: true
|
|
45
51
|
});
|
|
46
52
|
const apiDirContent = apiDir.filter((fd)=>fd.isDirectory());
|
|
@@ -84,11 +90,11 @@ var generateContentType = ((plop)=>{
|
|
|
84
90
|
}, {});
|
|
85
91
|
const filePath = getFilePath(answers.destination);
|
|
86
92
|
const currentDir = process.cwd();
|
|
87
|
-
let language =
|
|
93
|
+
let language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
88
94
|
if (answers.plugin) {
|
|
89
95
|
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
90
96
|
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
91
|
-
language =
|
|
97
|
+
language = tsUtils__default.default.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
92
98
|
}
|
|
93
99
|
const baseActions = [
|
|
94
100
|
{
|
|
@@ -96,7 +102,7 @@ var generateContentType = ((plop)=>{
|
|
|
96
102
|
path: `${filePath}/content-types/{{ singularName }}/schema.json`,
|
|
97
103
|
templateFile: `templates/${language}/content-type.schema.json.hbs`,
|
|
98
104
|
data: {
|
|
99
|
-
collectionName:
|
|
105
|
+
collectionName: slugify__default.default(answers.pluralName, {
|
|
100
106
|
separator: '_'
|
|
101
107
|
})
|
|
102
108
|
}
|
|
@@ -115,7 +121,7 @@ var generateContentType = ((plop)=>{
|
|
|
115
121
|
}
|
|
116
122
|
if (answers.plugin) {
|
|
117
123
|
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/content-types/index.${language}`);
|
|
118
|
-
const exists =
|
|
124
|
+
const exists = fs__default.default.existsSync(indexPath);
|
|
119
125
|
if (!exists) {
|
|
120
126
|
// Create index file if it doesn't exist
|
|
121
127
|
baseActions.push({
|
|
@@ -177,7 +183,7 @@ var generateContentType = ((plop)=>{
|
|
|
177
183
|
];
|
|
178
184
|
indexFiles.forEach((type)=>{
|
|
179
185
|
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
180
|
-
const exists =
|
|
186
|
+
const exists = fs__default.default.existsSync(indexPath);
|
|
181
187
|
if (!exists && type !== 'routes') {
|
|
182
188
|
baseActions.push({
|
|
183
189
|
type: 'add',
|
|
@@ -188,7 +194,7 @@ var generateContentType = ((plop)=>{
|
|
|
188
194
|
}
|
|
189
195
|
if (type === 'routes') {
|
|
190
196
|
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/index.${language}`);
|
|
191
|
-
const exists =
|
|
197
|
+
const exists = fs__default.default.existsSync(indexPath);
|
|
192
198
|
if (!exists) {
|
|
193
199
|
baseActions.push({
|
|
194
200
|
type: 'add',
|
|
@@ -203,7 +209,7 @@ var generateContentType = ((plop)=>{
|
|
|
203
209
|
];
|
|
204
210
|
routeIndexFiles.forEach((routeType)=>{
|
|
205
211
|
const routeTypeIndexPath = path.join(plop.getDestBasePath(), `${filePath}/${type}/${routeType}/index.${language}`);
|
|
206
|
-
const routeTypeExists =
|
|
212
|
+
const routeTypeExists = fs__default.default.existsSync(routeTypeIndexPath);
|
|
207
213
|
if (!routeTypeExists) {
|
|
208
214
|
baseActions.push({
|
|
209
215
|
type: 'add',
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-type.js","sources":["../../src/plops/content-type.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport ctNamesPrompts from './prompts/ct-names-prompts';\nimport kindPrompts from './prompts/kind-prompts';\nimport getAttributesPrompts from './prompts/get-attributes-prompts';\nimport bootstrapApiPrompts from './prompts/bootstrap-api-prompts';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Model generator\n plop.setGenerator('content-type', {\n description: 'Generate a content type for an API',\n async prompts(inquirer) {\n const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);\n const attributes = await getAttributesPrompts(inquirer);\n\n const api = await inquirer.prompt([\n ...getDestinationPrompts('model', plop.getDestBasePath()),\n {\n when: (answers) => answers.destination === 'new',\n type: 'input',\n name: 'id',\n default: config.singularName,\n message: 'Name of the new API?',\n async validate(input) {\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n const apiPath = join(plop.getDestBasePath(), 'api');\n const exists = await fs.pathExists(apiPath);\n\n if (!exists) {\n return true;\n }\n\n const apiDir = await fs.readdir(apiPath, { withFileTypes: true });\n const apiDirContent = apiDir.filter((fd) => fd.isDirectory());\n\n if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {\n throw new Error('This name is already taken.');\n }\n\n return true;\n },\n },\n ...bootstrapApiPrompts,\n ]);\n\n return {\n ...config,\n ...api,\n attributes,\n };\n },\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const attributes = answers.attributes.reduce((object: any, answer: any) => {\n const val: any = { type: answer.attributeType };\n\n if (answer.attributeType === 'enumeration') {\n val.enum = answer.enum.split(',').map((item: string) => item.trim());\n }\n\n if (answer.attributeType === 'media') {\n val.allowedTypes = ['images', 'files', 'videos', 'audios'];\n val.multiple = answer.multiple;\n }\n\n return Object.assign(object, { [answer.attributeName]: val }, {});\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}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.plugin) {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/content-types/index.${language}`\n );\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}/content-types/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new content type to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/index.${language}`,\n transform(template: string) {\n return appendToFile(template, {\n type: 'content-type',\n singularName: answers.singularName,\n });\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n\n if (answers.plugin) {\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(\n plop.getDestBasePath(),\n `${filePath}/${type}/index.${language}`\n );\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, {\n type: 'routes',\n singularName: answers.singularName,\n });\n }\n\n return appendToFile(template, {\n type: 'index',\n singularName: answers.singularName,\n });\n },\n });\n });\n }\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","inquirer","config","prompt","ctNamesPrompts","kindPrompts","attributes","getAttributesPrompts","api","getDestinationPrompts","getDestBasePath","when","answers","destination","type","name","default","singularName","message","validate","input","strings","isKebabCase","apiPath","join","exists","fs","pathExists","apiDir","readdir","withFileTypes","apiDirContent","filter","fd","isDirectory","findIndex","dir","Error","bootstrapApiPrompts","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","replace","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","uid","id","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists"],"mappings":";;;;;;;;;;;;;;;AAeA,0BAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAAA,CAAKC,YAAY,CAAC,cAAA,EAAgB;QAChCC,WAAAA,EAAa,oCAAA;AACb,QAAA,MAAMC,SAAQC,QAAQ,EAAA;AACpB,YAAA,MAAMC,MAAAA,GAAS,MAAMD,QAAAA,CAASE,MAAM,CAAC;AAAIC,gBAAAA,GAAAA,cAAAA;AAAmBC,gBAAAA,GAAAA;AAAY,aAAA,CAAA;YACxE,MAAMC,UAAAA,GAAa,MAAMC,oBAAAA,CAAqBN,QAAAA,CAAAA;AAE9C,YAAA,MAAMO,GAAAA,GAAM,MAAMP,QAAAA,CAASE,MAAM,CAAC;mBAC7BM,qBAAAA,CAAsB,OAAA,EAASZ,KAAKa,eAAe,EAAA,CAAA;AACtD,gBAAA;AACEC,oBAAAA,IAAAA,EAAM,CAACC,OAAAA,GAAYA,OAAAA,CAAQC,WAAW,KAAK,KAAA;oBAC3CC,IAAAA,EAAM,OAAA;oBACNC,IAAAA,EAAM,IAAA;AACNC,oBAAAA,OAAAA,EAASd,OAAOe,YAAY;oBAC5BC,OAAAA,EAAS,sBAAA;AACT,oBAAA,MAAMC,UAASC,KAAK,EAAA;AAClB,wBAAA,IAAI,CAACC,aAAAA,CAAQC,WAAW,CAACF,KAAAA,CAAAA,EAAQ;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,YAAAA,EAAcL,QAAQK;AACxB,qCAAA,CAAA;AACF,gCAAA;AAEA,gCAAA,OAAOqE,oCAAaR,QAAAA,EAAU;oCAC5BhE,IAAAA,EAAM,OAAA;AACNG,oCAAAA,YAAAA,EAAcL,QAAQK;AACxB,iCAAA,CAAA;AACF,4BAAA;AACF,yBAAA,CAAA;AACF,oBAAA,CAAA,CAAA;AACF,gBAAA;AACF,YAAA;YAEA,OAAOiD,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
1
|
+
{"version":3,"file":"content-type.js","sources":["../../src/plops/content-type.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\nimport tsUtils from '@strapi/typescript-utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport ctNamesPrompts from './prompts/ct-names-prompts';\nimport kindPrompts from './prompts/kind-prompts';\nimport getAttributesPrompts from './prompts/get-attributes-prompts';\nimport bootstrapApiPrompts from './prompts/bootstrap-api-prompts';\nimport { appendToFile } from './utils/extend-plugin-index-files';\n\nexport default (plop: NodePlopAPI) => {\n // Model generator\n plop.setGenerator('content-type', {\n description: 'Generate a content type for an API',\n async prompts(inquirer) {\n const config = await inquirer.prompt([...ctNamesPrompts, ...kindPrompts]);\n const attributes = await getAttributesPrompts(inquirer);\n\n const api = await inquirer.prompt([\n ...getDestinationPrompts('model', plop.getDestBasePath()),\n {\n when: (answers) => answers.destination === 'new',\n type: 'input',\n name: 'id',\n default: config.singularName,\n message: 'Name of the new API?',\n async validate(input) {\n if (!strings.isKebabCase(input)) {\n return 'Value must be in kebab-case';\n }\n\n const apiPath = join(plop.getDestBasePath(), 'api');\n const exists = await fs.pathExists(apiPath);\n\n if (!exists) {\n return true;\n }\n\n const apiDir = await fs.readdir(apiPath, { withFileTypes: true });\n const apiDirContent = apiDir.filter((fd) => fd.isDirectory());\n\n if (apiDirContent.findIndex((dir) => dir.name === input) !== -1) {\n throw new Error('This name is already taken.');\n }\n\n return true;\n },\n },\n ...bootstrapApiPrompts,\n ]);\n\n return {\n ...config,\n ...api,\n attributes,\n };\n },\n actions(answers) {\n if (!answers) {\n return [];\n }\n\n const attributes = answers.attributes.reduce((object: any, answer: any) => {\n const val: any = { type: answer.attributeType };\n\n if (answer.attributeType === 'enumeration') {\n val.enum = answer.enum.split(',').map((item: string) => item.trim());\n }\n\n if (answer.attributeType === 'media') {\n val.allowedTypes = ['images', 'files', 'videos', 'audios'];\n val.multiple = answer.multiple;\n }\n\n return Object.assign(object, { [answer.attributeName]: val }, {});\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}/content-types/{{ singularName }}/schema.json`,\n templateFile: `templates/${language}/content-type.schema.json.hbs`,\n data: {\n collectionName: slugify(answers.pluralName, { separator: '_' }),\n },\n },\n ];\n\n if (Object.entries(attributes).length > 0) {\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/{{ singularName }}/schema.json`,\n transform(template: string) {\n const parsedTemplate = JSON.parse(template);\n parsedTemplate.attributes = attributes;\n return JSON.stringify(parsedTemplate, null, 2);\n },\n });\n }\n\n if (answers.plugin) {\n const indexPath = join(\n plop.getDestBasePath(),\n `${filePath}/content-types/index.${language}`\n );\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}/content-types/index.${language}`,\n templateFile: `templates/${language}/plugin/plugin.index.${language}.hbs`,\n skipIfExists: true,\n });\n }\n\n // Append the new content type to the index.ts file\n baseActions.push({\n type: 'modify',\n path: `${filePath}/content-types/index.${language}`,\n transform(template: string) {\n return appendToFile(template, {\n type: 'content-type',\n singularName: answers.singularName,\n });\n },\n });\n }\n\n if (answers.bootstrapApi) {\n const { singularName } = answers;\n\n let uid;\n if (answers.destination === 'new') {\n uid = `api::${answers.id}.${singularName}`;\n } else if (answers.api) {\n uid = `api::${answers.api}.${singularName}`;\n } else if (answers.plugin) {\n uid = `plugin::${answers.plugin}.${singularName}`;\n }\n\n baseActions.push(\n {\n type: 'add',\n path: `${filePath}/controllers/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-controller.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/services/{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-service.${language}.hbs`,\n data: { uid },\n },\n {\n type: 'add',\n path: `${filePath}/routes/${answers.plugin ? 'content-api/' : ''}{{ singularName }}.${language}`,\n templateFile: `templates/${language}/core-router.${language}.hbs`,\n data: { uid },\n }\n );\n\n if (answers.plugin) {\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(\n plop.getDestBasePath(),\n `${filePath}/${type}/index.${language}`\n );\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, {\n type: 'routes',\n singularName: answers.singularName,\n });\n }\n\n return appendToFile(template, {\n type: 'index',\n singularName: answers.singularName,\n });\n },\n });\n });\n }\n }\n\n return baseActions;\n },\n });\n};\n"],"names":["plop","setGenerator","description","prompts","inquirer","config","prompt","ctNamesPrompts","kindPrompts","attributes","getAttributesPrompts","api","getDestinationPrompts","getDestBasePath","when","answers","destination","type","name","default","singularName","message","validate","input","strings","isKebabCase","apiPath","join","exists","fs","pathExists","apiDir","readdir","withFileTypes","apiDirContent","filter","fd","isDirectory","findIndex","dir","Error","bootstrapApiPrompts","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","currentDir","process","cwd","language","tsUtils","isUsingTypeScriptSync","plugin","pluginServerDir","replace","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","uid","id","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAeA,0BAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAAA,CAAKC,YAAY,CAAC,cAAA,EAAgB;QAChCC,WAAAA,EAAa,oCAAA;AACb,QAAA,MAAMC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AAA,CAAAA,CAAU;wCAC1DQ,YAAAA,EAAc,CAAC,UAAU,EAAER,QAAAA,CAAS,iCAAiC,EAAEA,QAAAA,CAAS,IAAI,CAAC;wCACrFS,IAAAA,EAAM;4CAAEvD,IAAAA,EAAM+E;AAAU,yCAAA;wCACxBR,YAAAA,EAAc;AAChB,qCAAA,CAAA;AACF,gCAAA;AACF,4BAAA,CAAA,CAAA;AACF,wBAAA;AAEAnB,wBAAAA,WAAAA,CAAYU,IAAI,CAAC;4BACf9D,IAAAA,EAAM,QAAA;AACNqD,4BAAAA,IAAAA,EAAM,CAAA,EAAGZ,QAAAA,CAAS,CAAC,EAAEzC,IAAAA,CAAK,CAAC,EAAEA,IAAAA,KAAS,QAAA,GAAW,cAAA,GAAiB,EAAA,CAAG,MAAM,EAAE8C,QAAAA,CAAAA,CAAU;AACvFiB,4BAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,gCAAA,IAAIhE,SAAS,QAAA,EAAU;AACrB,oCAAA,OAAOwE,oCAAaR,QAAAA,EAAU;wCAC5BhE,IAAAA,EAAM,QAAA;AACNG,wCAAAA,YAAAA,EAAcL,QAAQK;AACxB,qCAAA,CAAA;AACF,gCAAA;AAEA,gCAAA,OAAOqE,oCAAaR,QAAAA,EAAU;oCAC5BhE,IAAAA,EAAM,OAAA;AACNG,oCAAAA,YAAAA,EAAcL,QAAQK;AACxB,iCAAA,CAAA;AACF,4BAAA;AACF,yBAAA,CAAA;AACF,oBAAA,CAAA,CAAA;AACF,gBAAA;AACF,YAAA;YAEA,OAAOiD,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
package/dist/plops/controller.js
CHANGED
|
@@ -8,6 +8,11 @@ var getFilePath = require('./utils/get-file-path.js');
|
|
|
8
8
|
var validateInput = require('./utils/validate-input.js');
|
|
9
9
|
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
10
10
|
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var tsUtils__default = /*#__PURE__*/_interopDefault(tsUtils);
|
|
14
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
15
|
+
|
|
11
16
|
var generateController = ((plop)=>{
|
|
12
17
|
// Controller generator
|
|
13
18
|
plop.setGenerator('controller', {
|
|
@@ -27,11 +32,11 @@ var generateController = ((plop)=>{
|
|
|
27
32
|
}
|
|
28
33
|
const filePath = getFilePath(answers.destination);
|
|
29
34
|
const currentDir = process.cwd();
|
|
30
|
-
let language =
|
|
35
|
+
let language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
31
36
|
if (answers.plugin) {
|
|
32
37
|
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
33
38
|
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
34
|
-
language =
|
|
39
|
+
language = tsUtils__default.default.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
35
40
|
}
|
|
36
41
|
const baseActions = [
|
|
37
42
|
{
|
|
@@ -42,7 +47,7 @@ var generateController = ((plop)=>{
|
|
|
42
47
|
];
|
|
43
48
|
if (answers.plugin) {
|
|
44
49
|
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/controllers/index.${language}`);
|
|
45
|
-
const exists =
|
|
50
|
+
const exists = fs__default.default.existsSync(indexPath);
|
|
46
51
|
if (!exists) {
|
|
47
52
|
// Create index file if it doesn't exist
|
|
48
53
|
baseActions.push({
|
|
@@ -1 +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":"
|
|
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,IAAAA,CAAKC,YAAY,CAAC,YAAA,EAAc;QAC9BC,WAAAA,EAAa,kCAAA;QACbC,OAAAA,EAAS;AACP,YAAA;gBACEC,IAAAA,EAAM,OAAA;gBACNC,IAAAA,EAAM,IAAA;gBACNC,OAAAA,EAAS,iBAAA;gBACTC,QAAAA,EAAU,CAACC,QAAUC,aAAAA,CAAcD,KAAAA;AACrC,aAAA;eACGE,qBAAAA,CAAsB,YAAA,EAAcV,KAAKW,eAAe,EAAA;AAC5D,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAAA,EAAS;AACZ,gBAAA,OAAO,EAAE;AACX,YAAA;YAEA,MAAMC,QAAAA,GAAWC,WAAAA,CAAYF,OAAAA,CAAQG,WAAW,CAAA;YAChD,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,IAAIC,QAAAA,GAAWC,wBAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAA,GAAO,IAAA;YAElE,IAAIJ,OAAAA,CAAQU,MAAM,EAAE;;gBAElB,MAAMC,eAAAA,GAAkBC,SAAAA,CACtBR,UAAAA,EACA,KAAA,EACAH,QAAAA,CAASY,OAAO,CAAC,cAAA,EAAgBb,OAAAA,CAAQU,MAAM,CAAA,EAC/C,KAAA,CAAA;AAEFH,gBAAAA,QAAAA,GAAWC,wBAAAA,CAAQC,qBAAqB,CAACE,eAAAA,CAAAA,GAAmB,IAAA,GAAO,IAAA;AACrE,YAAA;AAEA,YAAA,MAA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A;YAEA,OAAOb,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
package/dist/plops/middleware.js
CHANGED
|
@@ -8,6 +8,11 @@ var validateInput = require('./utils/validate-input.js');
|
|
|
8
8
|
var getFilePath = require('./utils/get-file-path.js');
|
|
9
9
|
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
10
10
|
|
|
11
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
12
|
+
|
|
13
|
+
var tsUtils__default = /*#__PURE__*/_interopDefault(tsUtils);
|
|
14
|
+
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
15
|
+
|
|
11
16
|
var generateMiddleware = ((plop)=>{
|
|
12
17
|
// middleware generator
|
|
13
18
|
plop.setGenerator('middleware', {
|
|
@@ -29,11 +34,11 @@ var generateMiddleware = ((plop)=>{
|
|
|
29
34
|
}
|
|
30
35
|
const filePath = getFilePath(answers.destination);
|
|
31
36
|
const currentDir = process.cwd();
|
|
32
|
-
let language =
|
|
37
|
+
let language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
33
38
|
if (answers.plugin) {
|
|
34
39
|
// The tsconfig in plugins is located just outside the server src, not in the root of the plugin.
|
|
35
40
|
const pluginServerDir = path.join(currentDir, 'src', filePath.replace('{{ plugin }}', answers.plugin), '../');
|
|
36
|
-
language =
|
|
41
|
+
language = tsUtils__default.default.isUsingTypeScriptSync(pluginServerDir) ? 'ts' : 'js';
|
|
37
42
|
}
|
|
38
43
|
const baseActions = [
|
|
39
44
|
{
|
|
@@ -44,7 +49,7 @@ var generateMiddleware = ((plop)=>{
|
|
|
44
49
|
];
|
|
45
50
|
if (answers.plugin) {
|
|
46
51
|
const indexPath = path.join(plop.getDestBasePath(), `${filePath}/middlewares/index.${language}`);
|
|
47
|
-
const exists =
|
|
52
|
+
const exists = fs__default.default.existsSync(indexPath);
|
|
48
53
|
if (!exists) {
|
|
49
54
|
// Create index file if it doesn't exist
|
|
50
55
|
baseActions.push({
|
|
@@ -1 +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":"
|
|
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,IAAAA,CAAKC,YAAY,CAAC,YAAA,EAAc;QAC9BC,WAAAA,EAAa,kCAAA;QACbC,OAAAA,EAAS;AACP,YAAA;gBACEC,IAAAA,EAAM,OAAA;gBACNC,IAAAA,EAAM,MAAA;gBACNC,OAAAA,EAAS,iBAAA;gBACTC,QAAAA,EAAU,CAACC,QAAUC,aAAAA,CAAcD,KAAAA;AACrC,aAAA;eACGE,qBAAAA,CAAsB,YAAA,EAAcV,IAAAA,CAAKW,eAAe,EAAA,EAAI;gBAAEC,UAAAA,EAAY;AAAK,aAAA;AACnF,SAAA;AACDC,QAAAA,OAAAA,CAAAA,CAAQC,OAAO,EAAA;AACb,YAAA,IAAI,CAACA,OAAAA,EAAS;AACZ,gBAAA,OAAO,EAAE;AACX,YAAA;YAEA,MAAMC,QAAAA,GAAWC,WAAAA,CAAYF,OAAAA,CAAQG,WAAW,CAAA;YAChD,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,Y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AAA;AACF,gBAAA;;AAGAR,gBAAAA,WAAAA,CAAYO,IAAI,CAAC;oBACf/B,IAAAA,EAAM,QAAA;AACNyB,oBAAAA,IAAAA,EAAM,CAAA,EAAGd,QAAAA,CAAS,mBAAmB,EAAEM,QAAAA,CAAAA,CAAU;AACjDgB,oBAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,wBAAA,OAAOC,oCAAaD,QAAAA,EAAU;4BAAElC,IAAAA,EAAM,OAAA;AAASoC,4BAAAA,YAAAA,EAAc1B,QAAQT;AAAK,yBAAA,CAAA;AAC5E,oBAAA;AACF,iBAAA,CAAA;AACF,YAAA;YAEA,OAAOuB,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
package/dist/plops/migration.js
CHANGED
|
@@ -4,6 +4,10 @@ var tsUtils = require('@strapi/typescript-utils');
|
|
|
4
4
|
var validateFileNameInput = require('./utils/validate-file-name-input.js');
|
|
5
5
|
var getFormattedDate = require('./utils/get-formatted-date.js');
|
|
6
6
|
|
|
7
|
+
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
8
|
+
|
|
9
|
+
var tsUtils__default = /*#__PURE__*/_interopDefault(tsUtils);
|
|
10
|
+
|
|
7
11
|
var generateMigration = ((plop)=>{
|
|
8
12
|
// Migration generator
|
|
9
13
|
plop.setGenerator('migration', {
|
|
@@ -18,7 +22,7 @@ var generateMigration = ((plop)=>{
|
|
|
18
22
|
],
|
|
19
23
|
actions () {
|
|
20
24
|
const currentDir = process.cwd();
|
|
21
|
-
const language =
|
|
25
|
+
const language = tsUtils__default.default.isUsingTypeScriptSync(currentDir) ? 'ts' : 'js';
|
|
22
26
|
const timestamp = getFormattedDate();
|
|
23
27
|
return [
|
|
24
28
|
{
|
|
@@ -1 +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":"
|
|
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,IAAAA,CAAKC,YAAY,CAAC,WAAA,EAAa;QAC7BC,WAAAA,EAAa,sBAAA;QACbC,OAAAA,EAAS;AACP,YAAA;gBACEC,IAAAA,EAAM,OAAA;gBACNC,IAAAA,EAAM,MAAA;gBACNC,OAAAA,EAAS,gBAAA;gBACTC,QAAAA,EAAU,CAACC,QAAUC,qBAAAA,CAAsBD,KAAAA;AAC7C;AACD,SAAA;AACDE,QAAAA,OAAAA,CAAAA,GAAAA;YACE,MAAMC,UAAAA,GAAaC,QAAQC,GAAG,EAAA;AAC9B,YAAA,MAAMC,QAAAA,GAAWC,wBAAAA,CAAQC,qBAAqB,CAACL,cAAc,IAAA,GAAO,IAAA;AACpE,YAAA,MAAMM,SAAAA,GAAYC,gBAAAA,EAAAA;YAElB,OAAO;AACL,gBAAA;oBACEd,IAAAA,EAAM,KAAA;AACNe,oBAAAA,IAAAA,EAAM,GAAGR,UAAAA,CAAW,qBAAqB,EAAEM,SAAAA,CAAU,YAAY,EAAEH,QAAAA,CAAAA,CAAU;oBAC7EM,YAAAA,EAAc,CAAC,UAAU,EAAEN,QAAAA,CAAS,WAAW,EAAEA,QAAAA,CAAS,IAAI;AAChE;AACD,aAAA;AACH,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|