diff --git a/src/index.ts b/src/index.ts index 121b212..b321444 100755 --- a/src/index.ts +++ b/src/index.ts @@ -28,16 +28,20 @@ const currentWorkingDirectory = process.cwd(); const configPath = join(currentWorkingDirectory, ".hendrixrc.js"); +const noop = () => {}; + const DEFAULT_CONFIG = { - templatesPath: "hendrix", + generatorsPath: "hendrix", outputPaths: {}, - renderTemplate: render + renderTemplate: render, + onPostHelp: noop }; const { - templatesPath = "hendrix", + generatorsPath = "hendrix", outputPaths = {}, - renderTemplate = render + renderTemplate = render, + onPostHelp = noop } = safeRequire(configPath, DEFAULT_CONFIG); const prettifyAvailableGenerators = pipe( @@ -49,7 +53,7 @@ const prettifyAvailableGenerators = pipe( const getAvailableGenerators = () => { const availableGenerators = readdirSync( - join(currentWorkingDirectory, templatesPath), + join(currentWorkingDirectory, generatorsPath), { withFileTypes: true } @@ -129,7 +133,7 @@ const customFileName = ({ templateFileName, fileName }) => { }; const createTemplatesDirectoryIfDoesNotExist = () => { - const templatesDirectoryExists = existsSync(templatesPath); + const templatesDirectoryExists = existsSync(generatorsPath); if (templatesDirectoryExists) { return new Promise(resolve => resolve()); @@ -148,7 +152,7 @@ const createTemplatesDirectoryIfDoesNotExist = () => { const examplesPath = join(__dirname, `../examples-${templateType}`); return new Promise((resolve, reject) => { - return ncp(examplesPath, templatesPath, error => { + return ncp(examplesPath, generatorsPath, error => { if (error) { console.error(error); reject(error); @@ -157,7 +161,7 @@ const createTemplatesDirectoryIfDoesNotExist = () => { console.log( addMargin( chalk.green( - `Successfully created new templates directory at "${templatesPath}" with some examples!` + `Successfully created new templates directory at "${generatorsPath}" with some examples!` ) ) ); @@ -176,7 +180,7 @@ const createTemplatesDirectoryIfDoesNotExist = () => { }; const generateFiles = ({ template, outputPath, name, variables }) => { - const templateFilesPath = join(templatesPath, template); + const templateFilesPath = join(generatorsPath, template); createTemplatesDirectoryIfDoesNotExist() .then(() => { @@ -264,10 +268,14 @@ const main = () => { cli.on("--help", () => { displayAvailableGenerators(availableGenerators); + + onPostHelp(); }); if (noCommandsEntered) { cli.outputHelp(); + + onPostHelp(); } cli.parse(process.argv); diff --git a/test/renderTemplate.spec.ts b/test/renderTemplate.spec.ts index 1c4ab5e..0b599d5 100644 --- a/test/renderTemplate.spec.ts +++ b/test/renderTemplate.spec.ts @@ -24,7 +24,7 @@ describe("supports other template engines with `templateRender` function on conf const { compile } = require('handlebars'); module.exports = { - templatesPath: 'examples-handlebars', + generatorsPath: 'examples-handlebars', outputPaths: { reactClass: "test-output", reactClassWithVariables: "test-output"}, renderTemplate: (templateContent, context) => compile(templateContent)(context) };`); @@ -68,7 +68,7 @@ describe("supports other template engines with `templateRender` function on conf const { compile } = require('ejs'); module.exports = { - templatesPath: 'examples-ejs', + generatorsPath: 'examples-ejs', outputPaths: { reactClass: "test-output", reactClassWithVariables: "test-output" }, renderTemplate: (templateContent, context) => compile(templateContent)(context) };`); diff --git a/test/utils.ts b/test/utils.ts index c46f180..8671384 100644 --- a/test/utils.ts +++ b/test/utils.ts @@ -71,7 +71,7 @@ export const copyTemplatesDirectory = outputPath => { export const createConfigFile = ( configFileContent = ` module.exports = { - templatesPath: "test-examples", + generatorsPath: "test-examples", outputPaths: { reactClass: "test-output", reactClassWithVariables: "test-output"