92 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-08-18 18:10:24 +02:00
'use strict';
const { join } = require('path');
module.exports = function(plop) {
// Service generator
plop.setGenerator('service', {
2021-08-19 11:49:55 +02:00
description: 'Generate a service for an API',
2021-08-18 18:10:24 +02:00
prompts: [
{
type: 'input',
name: 'id',
2021-08-19 11:49:55 +02:00
message: 'Service name',
2021-08-18 18:10:24 +02:00
},
],
actions: [
{
type: 'add',
path: join(process.cwd(), 'api/{{id}}/services/{{id}}.js'),
templateFile: 'templates/service.js.hbs',
},
],
});
2021-08-19 14:15:25 +02:00
// Model generator
plop.setGenerator('model', {
description: 'application model logic',
prompts: [
{
type: 'input',
name: 'id',
message: 'Model name',
},
{
type: 'confirm',
name: 'useDraftAndPublish',
message: 'Use draft and publish?',
},
],
actions: [
{
type: 'add',
path: join(process.cwd(), 'api/{{id}}/models/{{id}}.js'),
templateFile: 'templates/model.js.hbs',
},
{
type: 'add',
path: join(process.cwd(), 'api/{{id}}/models/{{id}}.settings.json'),
templateFile: 'templates/model.settings.json.hbs',
},
],
});
// Controller generator
plop.setGenerator('controller', {
description: 'Generate a controller for an API',
prompts: [
{
type: 'input',
name: 'id',
message: 'Controller name',
},
],
actions: [
{
type: 'add',
path: join(process.cwd(), 'api/{{id}}/controllers/{{id}}.js'),
templateFile: 'templates/controller.js.hbs',
},
],
});
// Policy generator
plop.setGenerator('policy', {
description: 'Generate a policy',
prompts: [
{
type: 'input',
name: 'id',
message: 'Policy name',
},
],
actions: [
{
type: 'add',
path: join(process.cwd(), 'config/policies/{{id}}.js'),
templateFile: 'templates/policy.js.hbs',
},
],
});
2021-08-18 18:10:24 +02:00
};