From f34febe418159aa03a890098926090965aba7333 Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Fri, 7 Feb 2020 11:50:02 +0800 Subject: [PATCH 1/2] perf: set demo id with component name when run dev --- site/components/demoBox.vue | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/site/components/demoBox.vue b/site/components/demoBox.vue index dd80b537f4..095cf4d5d4 100644 --- a/site/components/demoBox.vue +++ b/site/components/demoBox.vue @@ -55,6 +55,7 @@ import animate from 'antd/_util/openAnimation'; import BaseMixin from 'antd/_util/BaseMixin'; import { isZhCN } from '../util'; +import { dev } from '../../build/config'; export default { name: 'DemoBox', mixins: [BaseMixin], @@ -81,7 +82,12 @@ export default { .split(' ') .join('-') .toLowerCase(); - const id = ['components', name.replace(/-cn\/?$/, ''), 'demo', ...usTitle.split(' ')] + const id = [ + 'components', + name.replace(/-cn\/?$/, '') || dev.componentName, + 'demo', + ...usTitle.split(' '), + ] .join('-') .toLowerCase(); From cbef1af8f232a81752156023dd37d853d9368e35 Mon Sep 17 00:00:00 2001 From: Amour1688 Date: Fri, 7 Feb 2020 11:51:44 +0800 Subject: [PATCH 2/2] perf: find parent component when only secondary component used in demo --- build/config.js | 4 +++- build/dev.js | 50 ++++++++++++++++++++++++++++++------------------- 2 files changed, 34 insertions(+), 20 deletions(-) diff --git a/build/config.js b/build/config.js index 56e7d12c65..f9333a91da 100644 --- a/build/config.js +++ b/build/config.js @@ -1,3 +1,5 @@ module.exports = { - devComponent: 'menu', + dev: { + componentName: 'tree', // dev components + }, }; diff --git a/build/dev.js b/build/dev.js index 6232e00c12..0d0a3e0d83 100644 --- a/build/dev.js +++ b/build/dev.js @@ -11,7 +11,19 @@ const devWebpack = require('./webpack.dev.conf'); const configPath = path.join(__dirname, './config.js'); -let { devComponent } = require('./config'); +/** + * a-bc-d --> aBcD + * @param {string} s + */ +const camelize = s => s.replace(/-(\w)/g, ($, $1) => $1.toUpperCase()); + +/** + * radio-group --> radio + * @param {string} s + */ +const getUpper = s => s.replace(/(-[a-z]*)/g, ''); + +let { componentName } = require('./config').dev; const componentsInPrototype = ['Modal', 'message', 'notification']; @@ -116,6 +128,7 @@ const generateInstall = components => const renderTemplate = name => { const components = { Tooltip: 'tooltip', // for DemoBox + Icon: 'icon', // Basic }; const demoPaths = fs @@ -128,16 +141,20 @@ const renderTemplate = name => { const demo = fs.readFileSync(path.join(__dirname, demoPath)).toString(); const componentsInDemo = demo.match(/a-(\w+(-\w+)*)/g) || []; - componentsInDemo.forEach(n => { - const componentName = n.replace(/-(\w)/g, ($, $1) => $1.toUpperCase()).replace(/^a/, ''); - - if (componentsInPrototype.includes(componentName)) { - return; - } + componentsInDemo.forEach(name => { + const dirName = name.replace(/^a-/, ''); + const componentName = camelize(name).replace(/^a/, ''); + const upperComponentDir = getUpper(dirName); + const upperComponentName = upperComponentDir.replace(/^[a-z]/, $ => $.toUpperCase()); - const componentPath = path.join(__dirname, `../components/${n.replace(/^a-/, '')}`); + const componentPath = path.join(__dirname, `../components/${dirName}`); if (fs.existsSync(componentPath)) { - components[componentName] = n.replace(/^a-/, ''); + if (componentsInPrototype.includes(componentName)) { + return; + } + components[componentName] = dirName; + } else if (fs.existsSync(path.join(__dirname, `../components/${upperComponentDir}`))) { + components[upperComponentName] = upperComponentDir; } }); }); @@ -173,24 +190,19 @@ if (!fsExistsSync(path.join(__dirname, '../components/test/index.vue'))) { let demoWatcher; chokidar.watch(configPath, { ignoreInitial: true }).on('change', async () => { - devComponent = importFresh(configPath).devComponent; + ({ componentName } = importFresh(configPath).dev); demoWatcher && (await demoWatcher.close()); - demoWatcher = chokidar.watch(path.join(__dirname, `../components/${devComponent}/demo`)); + demoWatcher = chokidar.watch(path.join(__dirname, `../components/${componentName}/demo`)); demoWatcher.on('change', () => { - renderTemplate(devComponent); + renderTemplate(componentName); }); - renderTemplate(devComponent); -}); - -testWatcher = chokidar.watch(path.join(__dirname, `../components/test`)); -testWatcher.on('change', () => { - renderTemplate(devComponent); + renderTemplate(componentName); }); -renderTemplate(devComponent); +renderTemplate(componentName); const compiler = webpack(devWebpack);