Skip to content

Commit

Permalink
improvement(configuration): change templatesPath to generatorsPath
Browse files Browse the repository at this point in the history
Configuration for the folder that contains all of the generators is now called `generatorsPath. This
is a breaking change, but makes things much more clear that it holds the generators, and each
generator has a list of template files.

BREAKING CHANGE: `templatesPath` is now called `generatorsPath` in the configuration
  • Loading branch information
seanWLawrence committed Nov 7, 2019
1 parent 49efec0 commit 3bd7b58
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 12 deletions.
26 changes: 17 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -49,7 +53,7 @@ const prettifyAvailableGenerators = pipe(

const getAvailableGenerators = () => {
const availableGenerators = readdirSync(
join(currentWorkingDirectory, templatesPath),
join(currentWorkingDirectory, generatorsPath),
{
withFileTypes: true
}
Expand Down Expand Up @@ -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());
Expand All @@ -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);
Expand All @@ -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!`
)
)
);
Expand All @@ -176,7 +180,7 @@ const createTemplatesDirectoryIfDoesNotExist = () => {
};

const generateFiles = ({ template, outputPath, name, variables }) => {
const templateFilesPath = join(templatesPath, template);
const templateFilesPath = join(generatorsPath, template);

createTemplatesDirectoryIfDoesNotExist()
.then(() => {
Expand Down Expand Up @@ -264,10 +268,14 @@ const main = () => {

cli.on("--help", () => {
displayAvailableGenerators(availableGenerators);

onPostHelp();
});

if (noCommandsEntered) {
cli.outputHelp();

onPostHelp();
}

cli.parse(process.argv);
Expand Down
4 changes: 2 additions & 2 deletions test/renderTemplate.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
};`);
Expand Down Expand Up @@ -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)
};`);
Expand Down
2 changes: 1 addition & 1 deletion test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 3bd7b58

Please sign in to comment.