Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to include a markdown file when creating a component #139

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion generators/component/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ module.exports = class extends Generator {
type: Boolean,
desc: 'Include a JS file'
});

// Allow the user to opt in to a Markdown file.
// --include-markdown
this.option('include-markdown', {
type: Boolean,
desc: 'Include a Markdown file'
});
}

initializing() {
Expand All @@ -48,6 +55,9 @@ module.exports = class extends Generator {

// Check to see if we need to include a JS file.
this.includeJS = this.options.includeJs || false;

// Check to see if we need to include a Markdown file.
this.includeMarkdown = this.options.includeMarkdown || false;
}

// Prompts need at least two arguments passed in to work:
Expand Down Expand Up @@ -99,6 +109,12 @@ ${chalk.blue('Make sure you\'re running this command from your theme root.')}`
type: 'confirm',
message: 'Would you like to include a JavaScript Behavior file?',
default: false
},
{
name: 'includeMarkdown',
type: 'confirm',
message: 'Would you like to include a Markdown file?',
default: false
}];

return this.prompt(prompts).then(function (props) {
Expand All @@ -113,6 +129,8 @@ ${chalk.blue('Make sure you\'re running this command from your theme root.')}`

// See if we need to include a JS behavior file.
this.includeJS = props.includeJSBehavior;
// See if we need to include a Markdown file.
this.includeMarkdown = props.includeMarkdown;

// To access props later use this.props.someAnswer;
this.props = props;
Expand Down Expand Up @@ -217,6 +235,17 @@ ${chalk.blue('Make sure you\'re running this command from your theme root.')}`
}
);
}
if (this.includeMarkdown) {
this.fs.copyTpl(
this.templatePath('_component/_component.md'),
// eslint-disable-next-line max-len
this.destinationPath('src/patterns/components/' + this.componentName.dashed + '/' + this.componentName.dashed + '.md'),
{
name: this.componentName.raw,
dashed: this.componentName.dashed
}
);
}
}

end() {
Expand All @@ -232,7 +261,7 @@ ${chalk.blue('Make sure you\'re running this command from your theme root.')}`
this.log('To generate components faster you can pass in arguments to the subgenerator!');
this.log('For example: 👇');
// eslint-disable-next-line max-len
this.log(chalk.blue(`npm run generate -- --name="${this.componentName.raw}" --theme-name="${this.themeNameMachine}"`));
this.log(chalk.blue(`npm run generate -- --name="${this.componentName.raw}" --theme-name="${this.themeNameMachine} --include-markdown"`));
this.log('Or add a Drupal JavaScript behavior to that with:');
// eslint-disable-next-line max-len
this.log(chalk.blue(`npm run generate -- --name="${this.componentName.raw}" --theme-name="${this.themeNameMachine}" --include-js`));
Expand Down
7 changes: 7 additions & 0 deletions generators/component/templates/_component/_component.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Component: <%= name %>

This is a markdown file for the <%= name %> component.

Use this file to describe the component and its usage.

Update this file as you see fit.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.