From c230708562e240031814c4a5707d96ffbc8da114 Mon Sep 17 00:00:00 2001 From: ZIA-Hans <1025013204@qq.com> Date: Thu, 28 Mar 2024 15:15:24 +0800 Subject: [PATCH] feat(cli): update cli to let it can create html souce code template --- packages/banana-cli/bin/index.js | 15 ++++++++++++++- packages/banana-cli/templates/docs/htmlSource.js | 6 ++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 packages/banana-cli/templates/docs/htmlSource.js diff --git a/packages/banana-cli/bin/index.js b/packages/banana-cli/bin/index.js index dd2a73be..5a3a1263 100755 --- a/packages/banana-cli/bin/index.js +++ b/packages/banana-cli/bin/index.js @@ -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))) { @@ -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, @@ -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('----------------------------------------'); diff --git a/packages/banana-cli/templates/docs/htmlSource.js b/packages/banana-cli/templates/docs/htmlSource.js new file mode 100644 index 00000000..8f5efd96 --- /dev/null +++ b/packages/banana-cli/templates/docs/htmlSource.js @@ -0,0 +1,6 @@ +/* eslint-disable no-undef */ +const htmlSourceTemplate = (componentName) => ` + basicUsage +`; + +module.exports = htmlSourceTemplate;