@strapi/generators 5.54.0 → 5.55.1
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.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -1
- package/dist/plops/content-type.d.ts.map +1 -1
- package/dist/plops/content-type.js +41 -11
- package/dist/plops/content-type.js.map +1 -1
- package/dist/plops/content-type.mjs +40 -11
- package/dist/plops/content-type.mjs.map +1 -1
- package/dist/plops/prompts/get-folder-prompts.d.ts +14 -0
- package/dist/plops/prompts/get-folder-prompts.d.ts.map +1 -0
- package/dist/plops/prompts/get-folder-prompts.js +105 -0
- package/dist/plops/prompts/get-folder-prompts.js.map +1 -0
- package/dist/plops/prompts/get-folder-prompts.mjs +103 -0
- package/dist/plops/prompts/get-folder-prompts.mjs.map +1 -0
- package/dist/plops/utils/content-structure.d.ts +42 -0
- package/dist/plops/utils/content-structure.d.ts.map +1 -0
- package/dist/plops/utils/content-structure.js +260 -0
- package/dist/plops/utils/content-structure.js.map +1 -0
- package/dist/plops/utils/content-structure.mjs +247 -0
- package/dist/plops/utils/content-structure.mjs.map +1 -0
- package/package.json +5 -5
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,qBAiBlB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,MAAM,qBAiBlB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAYF,eAAO,MAAM,QAAQ,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAC1D,eAAe,MAAM,EACrB,SAAS,CAAC,EACV,oBAAmD,eAAoB;;EAoDxE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -75,6 +75,10 @@ const registerHandlebarsHelpers = (helpers)=>{
|
|
|
75
75
|
// Executes generator actions: add or modify files as specified
|
|
76
76
|
const executeActions = async (actions, options, dir)=>{
|
|
77
77
|
for (const action of actions){
|
|
78
|
+
if (typeof action === 'function') {
|
|
79
|
+
await action(options);
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
78
82
|
const outputPath = handlebars__default.default.compile(action.path)(options);
|
|
79
83
|
const fullPath = node_path.join(dir, 'src', outputPath);
|
|
80
84
|
if (action.type === 'add' && action.templateFile) {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname, resolve } 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
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname, resolve } 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 GeneratorFileAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\ntype GeneratorAction = GeneratorFileAction | ((options: Record<string, any>) => unknown);\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 const resolvedDir = resolve(dir);\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(resolvedDir, '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, resolvedDir);\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 if (typeof action === 'function') {\n await action(options);\n continue;\n }\n\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","resolvedDir","resolve","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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
package/dist/index.mjs
CHANGED
|
@@ -68,6 +68,10 @@ const registerHandlebarsHelpers = (helpers)=>{
|
|
|
68
68
|
// Executes generator actions: add or modify files as specified
|
|
69
69
|
const executeActions = async (actions, options, dir)=>{
|
|
70
70
|
for (const action of actions){
|
|
71
|
+
if (typeof action === 'function') {
|
|
72
|
+
await action(options);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
71
75
|
const outputPath = handlebars.compile(action.path)(options);
|
|
72
76
|
const fullPath = join(dir, 'src', outputPath);
|
|
73
77
|
if (action.type === 'add' && action.templateFile) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname, resolve } 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
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../src/index.ts"],"sourcesContent":["import { join, dirname, resolve } 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 GeneratorFileAction = {\n type: 'add' | 'modify';\n path: string;\n templateFile?: string;\n data?: Record<string, any>;\n transform?: (content: string) => string;\n};\n\ntype GeneratorAction = GeneratorFileAction | ((options: Record<string, any>) => unknown);\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 const resolvedDir = resolve(dir);\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(resolvedDir, '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, resolvedDir);\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 if (typeof action === 'function') {\n await action(options);\n continue;\n }\n\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","resolvedDir","resolve","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,KAAKC,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,GAAU;AACd,gBAAA,GAAGH,GAAG;gBACNI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A,CAAOM,YAAY,EAAE;AAChD,YAAA,MAAMC,YAAAA,GAAe/C,IAAAA,CAAKC,SAAAA,EAAWuC,MAAAA,CAAOM,YAAY,CAAA;AACxD,YAAA,MAAME,eAAAA,GAAkB,MAAMC,EAAAA,CAAGC,QAAQ,CAACH,YAAAA,EAAc,MAAA,CAAA;YACxD,MAAMI,QAAAA,GAAWb,UAAAA,CAAWI,OAAO,CAACM,eAAAA,CAAAA;AACpC,YAAA,MAAMI,SAASD,QAAAA,CAAS;AAAE,gBAAA,GAAG9C,OAAO;AAAE,gBAAA,GAAGmC,OAAOa;AAAK,aAAA,CAAA;YAErD,MAAMJ,EAAAA,CAAGK,SAAS,CAACC,OAAAA,CAAQX,QAAAA,CAAAA,CAAAA;YAC3B,MAAMK,EAAAA,CAAGO,SAAS,CAACZ,QAAAA,EAAUQ,MAAAA,CAAAA;AAC/B,QAAA;QAEA,IAAIZ,MAAAA,CAAOK,IAAI,KAAK,QAAA,EAAU;AAC5B,YAAA,IAAI,MAAMI,EAAAA,CAAGQ,UAAU,CAACb,QAAAA,CAAAA,EAAW;AACjC,gBAAA,MAAMc,OAAAA,GAAU,MAAMT,EAAAA,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,EAAAA,CAAGO,SAAS,CAACZ,QAAAA,EAAUe,QAAAA,CAAAA;AAC/B,YAAA;AACF,QAAA;AACF,IAAA;AACF,CAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-type.d.ts","sourceRoot":"","sources":["../../src/plops/content-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"content-type.d.ts","sourceRoot":"","sources":["../../src/plops/content-type.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAc,MAAM,MAAM,CAAC;yBAiBpC,MAAM,WAAW;AAAjC,wBAkRE"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var path = require('path');
|
|
4
4
|
var slugify = require('@sindresorhus/slugify');
|
|
5
|
+
var handlebars = require('handlebars');
|
|
5
6
|
var fs = require('fs-extra');
|
|
6
7
|
var utils = require('@strapi/utils');
|
|
7
8
|
var getDestinationPrompts = require('./prompts/get-destination-prompts.js');
|
|
@@ -11,11 +12,14 @@ var ctNamesPrompts = require('./prompts/ct-names-prompts.js');
|
|
|
11
12
|
var kindPrompts = require('./prompts/kind-prompts.js');
|
|
12
13
|
var getAttributesPrompts = require('./prompts/get-attributes-prompts.js');
|
|
13
14
|
var bootstrapApiPrompts = require('./prompts/bootstrap-api-prompts.js');
|
|
15
|
+
var getFolderPrompts = require('./prompts/get-folder-prompts.js');
|
|
14
16
|
var extendPluginIndexFiles = require('./utils/extend-plugin-index-files.js');
|
|
17
|
+
var contentStructure = require('./utils/content-structure.js');
|
|
15
18
|
|
|
16
19
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
17
20
|
|
|
18
21
|
var slugify__default = /*#__PURE__*/_interopDefault(slugify);
|
|
22
|
+
var handlebars__default = /*#__PURE__*/_interopDefault(handlebars);
|
|
19
23
|
var fs__default = /*#__PURE__*/_interopDefault(fs);
|
|
20
24
|
|
|
21
25
|
var generateContentType = ((plop)=>{
|
|
@@ -57,9 +61,14 @@ var generateContentType = ((plop)=>{
|
|
|
57
61
|
},
|
|
58
62
|
...bootstrapApiPrompts
|
|
59
63
|
]);
|
|
64
|
+
const folder = await getFolderPrompts(inquirer, plop, {
|
|
65
|
+
destination: api.destination,
|
|
66
|
+
kind: config.kind
|
|
67
|
+
});
|
|
60
68
|
return {
|
|
61
69
|
...config,
|
|
62
70
|
...api,
|
|
71
|
+
...folder,
|
|
63
72
|
attributes
|
|
64
73
|
};
|
|
65
74
|
},
|
|
@@ -92,10 +101,20 @@ var generateContentType = ((plop)=>{
|
|
|
92
101
|
plugin: answers.plugin,
|
|
93
102
|
filePath
|
|
94
103
|
}, plop);
|
|
104
|
+
const { singularName } = answers;
|
|
105
|
+
const schemaActionPath = `${filePath}/content-types/{{ singularName }}/schema.json`;
|
|
106
|
+
let uid;
|
|
107
|
+
if (answers.destination === 'new') {
|
|
108
|
+
uid = `api::${answers.id}.${singularName}`;
|
|
109
|
+
} else if (answers.api) {
|
|
110
|
+
uid = `api::${answers.api}.${singularName}`;
|
|
111
|
+
} else if (answers.plugin) {
|
|
112
|
+
uid = `plugin::${answers.plugin}.${singularName}`;
|
|
113
|
+
}
|
|
95
114
|
const baseActions = [
|
|
96
115
|
{
|
|
97
116
|
type: 'add',
|
|
98
|
-
path:
|
|
117
|
+
path: schemaActionPath,
|
|
99
118
|
templateFile: `templates/${language}/content-type.schema.json.hbs`,
|
|
100
119
|
data: {
|
|
101
120
|
collectionName: slugify__default.default(answers.pluralName, {
|
|
@@ -107,7 +126,7 @@ var generateContentType = ((plop)=>{
|
|
|
107
126
|
if (Object.entries(attributes).length > 0) {
|
|
108
127
|
baseActions.push({
|
|
109
128
|
type: 'modify',
|
|
110
|
-
path:
|
|
129
|
+
path: schemaActionPath,
|
|
111
130
|
transform (template) {
|
|
112
131
|
const parsedTemplate = JSON.parse(template);
|
|
113
132
|
parsedTemplate.attributes = attributes;
|
|
@@ -140,15 +159,6 @@ var generateContentType = ((plop)=>{
|
|
|
140
159
|
});
|
|
141
160
|
}
|
|
142
161
|
if (answers.bootstrapApi) {
|
|
143
|
-
const { singularName } = answers;
|
|
144
|
-
let uid;
|
|
145
|
-
if (answers.destination === 'new') {
|
|
146
|
-
uid = `api::${answers.id}.${singularName}`;
|
|
147
|
-
} else if (answers.api) {
|
|
148
|
-
uid = `api::${answers.api}.${singularName}`;
|
|
149
|
-
} else if (answers.plugin) {
|
|
150
|
-
uid = `plugin::${answers.plugin}.${singularName}`;
|
|
151
|
-
}
|
|
152
162
|
baseActions.push({
|
|
153
163
|
type: 'add',
|
|
154
164
|
path: `${filePath}/controllers/{{ singularName }}.${language}`,
|
|
@@ -238,6 +248,26 @@ var generateContentType = ((plop)=>{
|
|
|
238
248
|
});
|
|
239
249
|
}
|
|
240
250
|
}
|
|
251
|
+
if (answers.folder) {
|
|
252
|
+
if (!uid) {
|
|
253
|
+
throw new Error('Cannot assign a folder: could not determine the content type uid from the given destination.');
|
|
254
|
+
}
|
|
255
|
+
const contentTypeAlreadyExists = fs__default.default.existsSync(path.join(plop.getDestBasePath(), handlebars__default.default.compile(schemaActionPath)(answers)));
|
|
256
|
+
if (contentTypeAlreadyExists) {
|
|
257
|
+
throw new Error(`Content type "${uid}" already exists — refusing to reassign its folder from the generator.`);
|
|
258
|
+
}
|
|
259
|
+
const assignedUid = uid;
|
|
260
|
+
const commitFolderAssignment = contentStructure.planContentTypeToFolder({
|
|
261
|
+
destBasePath: plop.getDestBasePath(),
|
|
262
|
+
folder: answers.folder,
|
|
263
|
+
kind: answers.kind,
|
|
264
|
+
uid: assignedUid
|
|
265
|
+
});
|
|
266
|
+
baseActions.push(()=>{
|
|
267
|
+
commitFolderAssignment();
|
|
268
|
+
return `assigned "${assignedUid}" to folder`;
|
|
269
|
+
});
|
|
270
|
+
}
|
|
241
271
|
return baseActions;
|
|
242
272
|
}
|
|
243
273
|
});
|
|
@@ -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';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport getGeneratorLanguage from './utils/get-generator-language';\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 language = getGeneratorLanguage({ plugin: answers.plugin, filePath }, plop);\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","language","getGeneratorLanguage","plugin","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;4BAC/B,OAAO,6BAAA;AACT,wBAAA;AAEA,wBAAA,MAAMG,OAAAA,GAAUC,SAAAA,CAAK3B,IAAAA,CAAKa,eAAe,EAAA,EAAI,KAAA,CAAA;AAC7C,wBAAA,MAAMe,MAAAA,GAAS,MAAMC,mBAAAA,CAAGC,UAAU,CAACJ,OAAAA,CAAAA;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EAAE9B,QAAAA,CAAAA,CAAU;wCAC1DK,YAAAA,EAAc,CAAC,UAAU,EAAEL,QAAAA,CAAS,iCAAiC,EAAEA,QAAAA,CAAS,IAAI,CAAC;wCACrFM,IAAAA,EAAM;4CAAEjD,IAAAA,EAAMyE;AAAU,yCAAA;wCACxBR,YAAAA,EAAc;AAChB,qCAAA,CAAA;AACF,gCAAA;AACF,4BAAA,CAAA,CAAA;AACF,wBAAA;AAEAnB,wBAAAA,WAAAA,CAAYU,IAAI,CAAC;4BACfxD,IAAAA,EAAM,QAAA;AACN+C,4BAAAA,IAAAA,EAAM,CAAA,EAAGN,QAAAA,CAAS,CAAC,EAAEzC,IAAAA,CAAK,CAAC,EAAEA,IAAAA,KAAS,QAAA,GAAW,cAAA,GAAiB,EAAA,CAAG,MAAM,EAAE2C,QAAAA,CAAAA,CAAU;AACvFc,4BAAAA,SAAAA,CAAAA,CAAUC,QAAgB,EAAA;AACxB,gCAAA,IAAI1D,SAAS,QAAA,EAAU;AACrB,oCAAA,OAAOkE,oCAAaR,QAAAA,EAAU;wCAC5B1D,IAAAA,EAAM,QAAA;AACNG,wCAAAA,YAAAA,EAAcL,QAAQK;AACxB,qCAAA,CAAA;AACF,gCAAA;AAEA,gCAAA,OAAO+D,oCAAaR,QAAAA,EAAU;oCAC5B1D,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,OAAO2C,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 handlebars from 'handlebars';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport getGeneratorLanguage from './utils/get-generator-language';\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 getFolderPrompts from './prompts/get-folder-prompts';\nimport { appendToFile } from './utils/extend-plugin-index-files';\nimport { planContentTypeToFolder } from './utils/content-structure';\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 const folder = await getFolderPrompts(inquirer, plop, {\n destination: api.destination,\n kind: config.kind,\n });\n\n return {\n ...config,\n ...api,\n ...folder,\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 language = getGeneratorLanguage({ plugin: answers.plugin, filePath }, plop);\n\n const { singularName } = answers;\n\n const schemaActionPath = `${filePath}/content-types/{{ singularName }}/schema.json`;\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 const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: schemaActionPath,\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: schemaActionPath,\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 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 if (answers.folder) {\n if (!uid) {\n throw new Error(\n 'Cannot assign a folder: could not determine the content type uid from the given destination.'\n );\n }\n\n const contentTypeAlreadyExists = fs.existsSync(\n join(plop.getDestBasePath(), handlebars.compile(schemaActionPath)(answers))\n );\n\n if (contentTypeAlreadyExists) {\n throw new Error(\n `Content type \"${uid}\" already exists — refusing to reassign its folder from the generator.`\n );\n }\n\n const assignedUid = uid;\n\n const commitFolderAssignment = planContentTypeToFolder({\n destBasePath: plop.getDestBasePath(),\n folder: answers.folder,\n kind: answers.kind,\n uid: assignedUid,\n });\n\n baseActions.push(() => {\n commitFolderAssignment();\n\n return `assigned \"${assignedUid}\" to folder`;\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","folder","getFolderPrompts","kind","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","language","getGeneratorLanguage","plugin","schemaActionPath","uid","id","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists","contentTypeAlreadyExists","handlebars","compile","assignedUid","commitFolderAssignment","planContentTypeToFolder","destBasePath"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAkBA,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;AA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C,CAAA;AAEhG,gBAAA;AAEA,gBAAA,MAAMiC,WAAAA,GAAcjC,GAAAA;AAEpB,gBAAA,MAAMkC,yBAAyBC,wCAAAA,CAAwB;AACrDC,oBAAAA,YAAAA,EAAcvG,KAAKa,eAAe,EAAA;AAClC6B,oBAAAA,MAAAA,EAAQ3B,QAAQ2B,MAAM;AACtBE,oBAAAA,IAAAA,EAAM7B,QAAQ6B,IAAI;oBAClBuB,GAAAA,EAAKiC;AACP,iBAAA,CAAA;AAEA/B,gBAAAA,WAAAA,CAAYU,IAAI,CAAC,IAAA;AACfsB,oBAAAA,sBAAAA,EAAAA;AAEA,oBAAA,OAAO,CAAC,UAAU,EAAED,WAAAA,CAAY,WAAW,CAAC;AAC9C,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAO/B,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { join } from 'path';
|
|
2
2
|
import slugify from '@sindresorhus/slugify';
|
|
3
|
+
import handlebars from 'handlebars';
|
|
3
4
|
import fs from 'fs-extra';
|
|
4
5
|
import { strings } from '@strapi/utils';
|
|
5
6
|
import getDestinationPrompts from './prompts/get-destination-prompts.mjs';
|
|
@@ -9,7 +10,9 @@ import questions from './prompts/ct-names-prompts.mjs';
|
|
|
9
10
|
import questions$1 from './prompts/kind-prompts.mjs';
|
|
10
11
|
import getAttributesPrompts from './prompts/get-attributes-prompts.mjs';
|
|
11
12
|
import questions$2 from './prompts/bootstrap-api-prompts.mjs';
|
|
13
|
+
import getFolderPrompts from './prompts/get-folder-prompts.mjs';
|
|
12
14
|
import { appendToFile } from './utils/extend-plugin-index-files.mjs';
|
|
15
|
+
import { planContentTypeToFolder } from './utils/content-structure.mjs';
|
|
13
16
|
|
|
14
17
|
var generateContentType = ((plop)=>{
|
|
15
18
|
// Model generator
|
|
@@ -50,9 +53,14 @@ var generateContentType = ((plop)=>{
|
|
|
50
53
|
},
|
|
51
54
|
...questions$2
|
|
52
55
|
]);
|
|
56
|
+
const folder = await getFolderPrompts(inquirer, plop, {
|
|
57
|
+
destination: api.destination,
|
|
58
|
+
kind: config.kind
|
|
59
|
+
});
|
|
53
60
|
return {
|
|
54
61
|
...config,
|
|
55
62
|
...api,
|
|
63
|
+
...folder,
|
|
56
64
|
attributes
|
|
57
65
|
};
|
|
58
66
|
},
|
|
@@ -85,10 +93,20 @@ var generateContentType = ((plop)=>{
|
|
|
85
93
|
plugin: answers.plugin,
|
|
86
94
|
filePath
|
|
87
95
|
}, plop);
|
|
96
|
+
const { singularName } = answers;
|
|
97
|
+
const schemaActionPath = `${filePath}/content-types/{{ singularName }}/schema.json`;
|
|
98
|
+
let uid;
|
|
99
|
+
if (answers.destination === 'new') {
|
|
100
|
+
uid = `api::${answers.id}.${singularName}`;
|
|
101
|
+
} else if (answers.api) {
|
|
102
|
+
uid = `api::${answers.api}.${singularName}`;
|
|
103
|
+
} else if (answers.plugin) {
|
|
104
|
+
uid = `plugin::${answers.plugin}.${singularName}`;
|
|
105
|
+
}
|
|
88
106
|
const baseActions = [
|
|
89
107
|
{
|
|
90
108
|
type: 'add',
|
|
91
|
-
path:
|
|
109
|
+
path: schemaActionPath,
|
|
92
110
|
templateFile: `templates/${language}/content-type.schema.json.hbs`,
|
|
93
111
|
data: {
|
|
94
112
|
collectionName: slugify(answers.pluralName, {
|
|
@@ -100,7 +118,7 @@ var generateContentType = ((plop)=>{
|
|
|
100
118
|
if (Object.entries(attributes).length > 0) {
|
|
101
119
|
baseActions.push({
|
|
102
120
|
type: 'modify',
|
|
103
|
-
path:
|
|
121
|
+
path: schemaActionPath,
|
|
104
122
|
transform (template) {
|
|
105
123
|
const parsedTemplate = JSON.parse(template);
|
|
106
124
|
parsedTemplate.attributes = attributes;
|
|
@@ -133,15 +151,6 @@ var generateContentType = ((plop)=>{
|
|
|
133
151
|
});
|
|
134
152
|
}
|
|
135
153
|
if (answers.bootstrapApi) {
|
|
136
|
-
const { singularName } = answers;
|
|
137
|
-
let uid;
|
|
138
|
-
if (answers.destination === 'new') {
|
|
139
|
-
uid = `api::${answers.id}.${singularName}`;
|
|
140
|
-
} else if (answers.api) {
|
|
141
|
-
uid = `api::${answers.api}.${singularName}`;
|
|
142
|
-
} else if (answers.plugin) {
|
|
143
|
-
uid = `plugin::${answers.plugin}.${singularName}`;
|
|
144
|
-
}
|
|
145
154
|
baseActions.push({
|
|
146
155
|
type: 'add',
|
|
147
156
|
path: `${filePath}/controllers/{{ singularName }}.${language}`,
|
|
@@ -231,6 +240,26 @@ var generateContentType = ((plop)=>{
|
|
|
231
240
|
});
|
|
232
241
|
}
|
|
233
242
|
}
|
|
243
|
+
if (answers.folder) {
|
|
244
|
+
if (!uid) {
|
|
245
|
+
throw new Error('Cannot assign a folder: could not determine the content type uid from the given destination.');
|
|
246
|
+
}
|
|
247
|
+
const contentTypeAlreadyExists = fs.existsSync(join(plop.getDestBasePath(), handlebars.compile(schemaActionPath)(answers)));
|
|
248
|
+
if (contentTypeAlreadyExists) {
|
|
249
|
+
throw new Error(`Content type "${uid}" already exists — refusing to reassign its folder from the generator.`);
|
|
250
|
+
}
|
|
251
|
+
const assignedUid = uid;
|
|
252
|
+
const commitFolderAssignment = planContentTypeToFolder({
|
|
253
|
+
destBasePath: plop.getDestBasePath(),
|
|
254
|
+
folder: answers.folder,
|
|
255
|
+
kind: answers.kind,
|
|
256
|
+
uid: assignedUid
|
|
257
|
+
});
|
|
258
|
+
baseActions.push(()=>{
|
|
259
|
+
commitFolderAssignment();
|
|
260
|
+
return `assigned "${assignedUid}" to folder`;
|
|
261
|
+
});
|
|
262
|
+
}
|
|
234
263
|
return baseActions;
|
|
235
264
|
}
|
|
236
265
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-type.mjs","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';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport getGeneratorLanguage from './utils/get-generator-language';\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 language = getGeneratorLanguage({ plugin: answers.plugin, filePath }, plop);\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","language","getGeneratorLanguage","plugin","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,SAAAA;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,OAAAA,CAAQC,WAAW,CAACF,KAAAA,CAAAA,EAAQ;4BAC/B,OAAO,6BAAA;AACT,wBA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mjs","sources":["../../src/plops/content-type.ts"],"sourcesContent":["import { join } from 'path';\nimport type { NodePlopAPI, ActionType } from 'plop';\nimport slugify from '@sindresorhus/slugify';\nimport handlebars from 'handlebars';\nimport fs from 'fs-extra';\nimport { strings } from '@strapi/utils';\n\nimport getDestinationPrompts from './prompts/get-destination-prompts';\nimport getFilePath from './utils/get-file-path';\nimport getGeneratorLanguage from './utils/get-generator-language';\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 getFolderPrompts from './prompts/get-folder-prompts';\nimport { appendToFile } from './utils/extend-plugin-index-files';\nimport { planContentTypeToFolder } from './utils/content-structure';\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 const folder = await getFolderPrompts(inquirer, plop, {\n destination: api.destination,\n kind: config.kind,\n });\n\n return {\n ...config,\n ...api,\n ...folder,\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 language = getGeneratorLanguage({ plugin: answers.plugin, filePath }, plop);\n\n const { singularName } = answers;\n\n const schemaActionPath = `${filePath}/content-types/{{ singularName }}/schema.json`;\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 const baseActions: Array<ActionType> = [\n {\n type: 'add',\n path: schemaActionPath,\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: schemaActionPath,\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 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 if (answers.folder) {\n if (!uid) {\n throw new Error(\n 'Cannot assign a folder: could not determine the content type uid from the given destination.'\n );\n }\n\n const contentTypeAlreadyExists = fs.existsSync(\n join(plop.getDestBasePath(), handlebars.compile(schemaActionPath)(answers))\n );\n\n if (contentTypeAlreadyExists) {\n throw new Error(\n `Content type \"${uid}\" already exists — refusing to reassign its folder from the generator.`\n );\n }\n\n const assignedUid = uid;\n\n const commitFolderAssignment = planContentTypeToFolder({\n destBasePath: plop.getDestBasePath(),\n folder: answers.folder,\n kind: answers.kind,\n uid: assignedUid,\n });\n\n baseActions.push(() => {\n commitFolderAssignment();\n\n return `assigned \"${assignedUid}\" to folder`;\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","folder","getFolderPrompts","kind","actions","reduce","object","answer","val","attributeType","enum","split","map","item","trim","allowedTypes","multiple","Object","assign","attributeName","filePath","getFilePath","language","getGeneratorLanguage","plugin","schemaActionPath","uid","id","baseActions","path","templateFile","data","collectionName","slugify","pluralName","separator","entries","length","push","transform","template","parsedTemplate","JSON","parse","stringify","indexPath","existsSync","skipIfExists","appendToFile","bootstrapApi","indexFiles","forEach","routeIndexFiles","routeType","routeTypeIndexPath","routeTypeExists","contentTypeAlreadyExists","handlebars","compile","assignedUid","commitFolderAssignment","planContentTypeToFolder","destBasePath"],"mappings":";;;;;;;;;;;;;;;;AAkBA,0BAAe,CAAA,CAACA,IAAAA,GAAAA;;IAEdA,IAAAA,C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AA,CAAAA,CAAAA,CAAAA;AAGpE,gBAAA,IAAIkF,wBAAAA,EAA0B;AAC5B,oBAAA,MAAM,IAAIzD,KAAAA,CACR,CAAC,cAAc,EAAE2B,GAAAA,CAAI,sEAAsE,CAAC,CAAA;AAEhG,gBAAA;AAEA,gBAAA,MAAMiC,WAAAA,GAAcjC,GAAAA;AAEpB,gBAAA,MAAMkC,yBAAyBC,uBAAAA,CAAwB;AACrDC,oBAAAA,YAAAA,EAAcvG,KAAKa,eAAe,EAAA;AAClC6B,oBAAAA,MAAAA,EAAQ3B,QAAQ2B,MAAM;AACtBE,oBAAAA,IAAAA,EAAM7B,QAAQ6B,IAAI;oBAClBuB,GAAAA,EAAKiC;AACP,iBAAA,CAAA;AAEA/B,gBAAAA,WAAAA,CAAYU,IAAI,CAAC,IAAA;AACfsB,oBAAAA,sBAAAA,EAAAA;AAEA,oBAAA,OAAO,CAAC,UAAU,EAAED,WAAAA,CAAY,WAAW,CAAC;AAC9C,gBAAA,CAAA,CAAA;AACF,YAAA;YAEA,OAAO/B,WAAAA;AACT,QAAA;AACF,KAAA,CAAA;AACF,CAAA;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { NodePlopAPI } from 'plop';
|
|
2
|
+
import { type FolderSelection } from '../utils/content-structure';
|
|
3
|
+
interface FolderPromptContext {
|
|
4
|
+
destination?: string;
|
|
5
|
+
kind: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Asks where to place the generated content type in the content-structure folder tree.
|
|
9
|
+
*/
|
|
10
|
+
declare const getFolderPrompts: (inquirer: any, plop: NodePlopAPI, { kind, destination }: FolderPromptContext) => Promise<{
|
|
11
|
+
folder?: FolderSelection;
|
|
12
|
+
}>;
|
|
13
|
+
export default getFolderPrompts;
|
|
14
|
+
//# sourceMappingURL=get-folder-prompts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-folder-prompts.d.ts","sourceRoot":"","sources":["../../../src/plops/prompts/get-folder-prompts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAExC,OAAO,EAML,KAAK,eAAe,EACrB,MAAM,4BAA4B,CAAC;AAMpC,UAAU,mBAAmB;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;GAEG;AACH,QAAA,MAAM,gBAAgB,GACpB,UAAU,GAAG,EACb,MAAM,WAAW,EACjB,uBAAuB,mBAAmB,KACzC,OAAO,CAAC;IAAE,MAAM,CAAC,EAAE,eAAe,CAAA;CAAE,CA8FtC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
|