@carlosbajo/roket-micro
Version:
framework para microservicios con google/pubsub
57 lines (54 loc) • 1.52 kB
JavaScript
const fs = require('fs');
function trimTemplateFile(template) {
return fs.readFileSync(`${__dirname}/${template}`, 'utf8').replace(/\s*$/, '');
}
module.exports = function plopFunction(plop) {
return {
description: 'kafka pub sub generator',
prompts: [
{
type: 'input',
name: 'method',
message: 'name of the method?',
validate: (value) => {
if (!(/^$|-/).test(value)) { return true; }
return 'invalid format';
}
},
{
type: 'input',
name: 'partitions',
message: 'number of partitions?',
validate: (value) => {
if ((/^$|[0-9]/).test(value)) { return true; }
return 'Numeric input';
}
},
{
type: 'input',
name: 'consumer',
message: 'which consumer file will it use?',
validate: (value) => {
if (!(/^$|-/).test(value)) { return true; }
return 'invalid format';
}
},
],
actions: function res(answer) {
const set = [];
set.push({
type: 'modify',
path: `${plop.getPlopfilePath()}/api/consumer/${answer.consumer}.js`,
pattern: /(module.exports = {)/g,
template: trimTemplateFile('consumer.hbs'),
});
set.push({
type: 'modify',
path: `${plop.getPlopfilePath()}/api/config/pubsub.js`,
pattern: /(module.exports = res;)/g,
template: trimTemplateFile('config.hbs'),
});
return set;
}
};
};