Skip to content

Commit

Permalink
Merge pull request #107 from ZIA-Hans/feat/update-cli
Browse files Browse the repository at this point in the history
feat(cli): update cli to let it can create html souce code template
  • Loading branch information
FriedRiceNoodles authored Mar 28, 2024
2 parents ac286d7 + c230708 commit d7cc97e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/banana-cli/bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const toCamelCase = require('../templates/toCamelCase.js');
const prettierConfig = prettier.resolveConfig.sync(process.cwd());

const createComponent = async () => {
const checkDirs = ['packages/banana/src', 'packages/banana-react/src', 'docs/example'];
const checkDirs = ['packages/banana/src', 'packages/banana-react/src', 'docs/example', 'public'];

for (const dir of checkDirs) {
if (!fs.existsSync(path.resolve(process.cwd(), dir))) {
Expand Down Expand Up @@ -218,6 +218,7 @@ const createComponent = async () => {

fs.mkdirSync(path.resolve(process.cwd(), 'docs/example', toCamelCase(name)));
fs.mkdirSync(path.resolve(process.cwd(), 'docs/example', toCamelCase(name), 'demos'));
fs.mkdirSync(path.resolve(process.cwd(), 'public', toCamelCase(name)));
const basicUsage = require('../templates/docs/basicUsage.js')(name);
const formattedBasicUsage = prettier.format(basicUsage, {
...prettierConfig,
Expand All @@ -237,6 +238,18 @@ const createComponent = async () => {
fs.writeFileSync(path.resolve(process.cwd(), 'docs/example', toCamelCase(name), 'index.md'), formattedIndex);
console.log(`✅ Created 'docs/example/${toCamelCase(name)}/index.md'`);

const htmlSourceCode = require('../templates/docs/htmlSource.js')(name);
const formattedHtmlSourceCode = prettier.format(htmlSourceCode, {
...prettierConfig,
parser: 'html',
});
fs.writeFileSync(
path.resolve(process.cwd(), `public`, toCamelCase(name), 'basicUsage.html'),
formattedHtmlSourceCode,
);

console.log(`✅ Created 'public/${toCamelCase(name)}/basicUsage.html`);

console.log('----------------------------------------');
console.log('📝 Docs created successfully.');
console.log('----------------------------------------');
Expand Down
6 changes: 6 additions & 0 deletions packages/banana-cli/templates/docs/htmlSource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* eslint-disable no-undef */
const htmlSourceTemplate = (componentName) => `
<b-${componentName}>basicUsage</b-${componentName}>
`;

module.exports = htmlSourceTemplate;

0 comments on commit d7cc97e

Please sign in to comment.