diff --git a/plop/{{dashCase title}}.md.txt b/plop/{{dashCase title}}.md.txt new file mode 100644 index 0000000..6d8397c --- /dev/null +++ b/plop/{{dashCase title}}.md.txt @@ -0,0 +1,9 @@ +--- +title: {{titleCase title}} +date: {{date}} +author: Stefan Imhoff +distance: 0 +duration: 0:00 +--- + + diff --git a/plopfile.js b/plopfile.js new file mode 100644 index 0000000..6f71482 --- /dev/null +++ b/plopfile.js @@ -0,0 +1,43 @@ +/* eslint-disable func-names */ +const fs = require('fs'); +const moment = require('moment'); + +const currentDir = process.cwd(); +const templatePath = 'plop'; +const date = moment().format(); +const year = moment().format('YYYY'); + +module.exports = function (plop) { + plop.setGenerator('District', { + description: 'Create a new district', + prompts: [ + { + type: 'input', + name: 'title', + message: 'Title', + validate(value) { + if (/.+/.test(value)) { + return true; + } + return 'Title is required'; + }, + }, + ], + actions() { + process.chdir(plop.getPlopfilePath()); + + return [ + { + type: 'addMany', + destination: `${currentDir}/src/districts/`, + base: `${templatePath}`, + templateFiles: '**/*.txt', + stripExtensions: ['txt'], + data: { + date, + }, + }, + ]; + }, + }); +};