Merge branch 'releases/v4' into v4/ds-migration

This commit is contained in:
Alexandre Bodin 2021-09-29 16:22:30 +02:00
commit 0985c241eb
6 changed files with 17 additions and 11 deletions

View File

@ -9,7 +9,7 @@ const nodePlop = require('node-plop');
*/ */
const runCLI = () => { const runCLI = () => {
Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, env => Plop.launch({ configPath: join(__dirname, 'plopfile.js') }, env =>
run({ ...env, dest: process.cwd() }, undefined, true) run({ ...env, dest: join(process.cwd(), 'src') }, undefined, true)
); );
}; };
@ -21,7 +21,7 @@ const runCLI = () => {
* @param {string} plopOptions.dir base path for plop to generate the files from * @param {string} plopOptions.dir base path for plop to generate the files from
*/ */
const generate = async (generatorName, options, { dir = process.cwd() } = {}) => { const generate = async (generatorName, options, { dir = process.cwd() } = {}) => {
const plop = nodePlop(join(__dirname, 'plopfile.js'), { destBasePath: dir }); const plop = nodePlop(join(__dirname, 'plopfile.js'), { destBasePath: join(dir, 'src') });
const generator = plop.getGenerator(generatorName); const generator = plop.getGenerator(generatorName);
await generator.runActions(options, { await generator.runActions(options, {

View File

@ -4,7 +4,7 @@ const pluralize = require('pluralize');
const generateApi = require('./plops/api'); const generateApi = require('./plops/api');
const generateController = require('./plops/controller'); const generateController = require('./plops/controller');
const generateModel = require('./plops/model'); const generateContentType = require('./plops/content-type');
const generatePlugin = require('./plops/plugin'); const generatePlugin = require('./plops/plugin');
const generatePolicy = require('./plops/policy'); const generatePolicy = require('./plops/policy');
const generateService = require('./plops/service'); const generateService = require('./plops/service');
@ -17,7 +17,7 @@ module.exports = plop => {
// Generators // Generators
generateApi(plop); generateApi(plop);
generateController(plop); generateController(plop);
generateModel(plop); generateContentType(plop);
generatePlugin(plop); generatePlugin(plop);
generatePolicy(plop); generatePolicy(plop);
generateService(plop); generateService(plop);

View File

@ -32,7 +32,7 @@ const promptConfigQuestions = (plop, inquirer) => {
{ {
type: 'input', type: 'input',
name: 'id', name: 'id',
message: 'Model name', message: 'Content type name',
validate: input => validateInput(input), validate: input => validateInput(input),
}, },
{ {
@ -104,8 +104,8 @@ const promptAttributeQuestions = inquirer => {
module.exports = plop => { module.exports = plop => {
// Model generator // Model generator
plop.setGenerator('model', { plop.setGenerator('content-type', {
description: 'Generate a model for an API', description: 'Generate a content type for an API',
async prompts(inquirer) { async prompts(inquirer) {
const config = await promptConfigQuestions(plop, inquirer); const config = await promptConfigQuestions(plop, inquirer);

View File

@ -27,7 +27,7 @@ module.exports = plop => {
return [ return [
{ {
type: 'add', type: 'add',
path: `${filePath}/config/policies/{{id}}.js`, path: `${filePath}/policies/{{id}}.js`,
templateFile: 'templates/policy.js.hbs', templateFile: 'templates/policy.js.hbs',
}, },
]; ];

View File

@ -9,7 +9,7 @@
"name": "{{id}}" "name": "{{id}}"
}, },
"options": { "options": {
"draftAndPublish": {{useDraftAndPublish || false}}, "draftAndPublish": {{ useDraftAndPublish }},
"comment": "" "comment": ""
}, },
"attributes": {} "attributes": {}

View File

@ -4,9 +4,15 @@
* `{{id}}` policy. * `{{id}}` policy.
*/ */
module.exports = async (ctx, next) => { module.exports = async (ctx) => {
// Add your own logic here. // Add your own logic here.
console.log('In {{id}} policy.'); console.log('In {{id}} policy.');
await next(); const canDoSomething = true;
if (canDoSomething) {
return true;
}
return false;
}; };