(plopfilePath = "", plopCfg = {})
| 16 | dlv(obj, propertyPath.replace("[", ".").replace("]", ""), defaultValue); |
| 17 | |
| 18 | async function nodePlop(plopfilePath = "", plopCfg = {}) { |
| 19 | let pkgJson = {}; |
| 20 | let defaultInclude = { generators: true }; |
| 21 | |
| 22 | let welcomeMessage; |
| 23 | const { destBasePath, force } = plopCfg; |
| 24 | const generators = {}; |
| 25 | const partials = {}; |
| 26 | const actionTypes = {}; |
| 27 | const helpers = Object.assign( |
| 28 | { |
| 29 | pkg: (propertyPath) => dlvBrackets(pkgJson, propertyPath, ""), |
| 30 | }, |
| 31 | bakedInHelpers, |
| 32 | ); |
| 33 | const baseHelpers = Object.keys(helpers); |
| 34 | |
| 35 | const setPrompt = inquirer.registerPrompt; |
| 36 | const setWelcomeMessage = (message) => { |
| 37 | welcomeMessage = message; |
| 38 | }; |
| 39 | const setHelper = (name, fn) => { |
| 40 | helpers[name] = fn; |
| 41 | }; |
| 42 | const setPartial = (name, str) => { |
| 43 | partials[name] = str; |
| 44 | }; |
| 45 | const setActionType = (name, fn) => { |
| 46 | actionTypes[name] = fn; |
| 47 | }; |
| 48 | |
| 49 | function renderString(template, data) { |
| 50 | Object.keys(helpers).forEach((h) => |
| 51 | handlebars.registerHelper(h, helpers[h]), |
| 52 | ); |
| 53 | Object.keys(partials).forEach((p) => |
| 54 | handlebars.registerPartial(p, partials[p]), |
| 55 | ); |
| 56 | return handlebars.compile(template)(data); |
| 57 | } |
| 58 | |
| 59 | const getWelcomeMessage = () => welcomeMessage; |
| 60 | const getHelper = (name) => helpers[name]; |
| 61 | const getPartial = (name) => partials[name]; |
| 62 | const getActionType = (name) => actionTypes[name]; |
| 63 | const getGenerator = (name) => generators[name]; |
| 64 | function setGenerator(name = "", config = {}) { |
| 65 | // if no name is provided, use a default |
| 66 | name = name || `generator-${Object.keys(generators).length + 1}`; |
| 67 | |
| 68 | // add the generator to this context |
| 69 | generators[name] = Object.assign(config, { |
| 70 | name: name, |
| 71 | basePath: plopfilePath, |
| 72 | }); |
| 73 | |
| 74 | return generators[name]; |
| 75 | } |
no test coverage detected
searching dependent graphs…