perf: find parent component when only secondary component used in demo (#1680)
* perf: set demo id with component name when run dev * perf: find parent component when only secondary component used in demopull/1763/head
parent
ae505396cb
commit
c8cc30beb0
|
@ -1,3 +1,5 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
devComponent: 'menu',
|
dev: {
|
||||||
|
componentName: 'tree', // dev components
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
50
build/dev.js
50
build/dev.js
|
@ -11,7 +11,19 @@ const devWebpack = require('./webpack.dev.conf');
|
||||||
|
|
||||||
const configPath = path.join(__dirname, './config.js');
|
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'];
|
const componentsInPrototype = ['Modal', 'message', 'notification'];
|
||||||
|
|
||||||
|
@ -116,6 +128,7 @@ const generateInstall = components =>
|
||||||
const renderTemplate = name => {
|
const renderTemplate = name => {
|
||||||
const components = {
|
const components = {
|
||||||
Tooltip: 'tooltip', // for DemoBox
|
Tooltip: 'tooltip', // for DemoBox
|
||||||
|
Icon: 'icon', // Basic
|
||||||
};
|
};
|
||||||
|
|
||||||
const demoPaths = fs
|
const demoPaths = fs
|
||||||
|
@ -128,16 +141,20 @@ const renderTemplate = name => {
|
||||||
const demo = fs.readFileSync(path.join(__dirname, demoPath)).toString();
|
const demo = fs.readFileSync(path.join(__dirname, demoPath)).toString();
|
||||||
|
|
||||||
const componentsInDemo = demo.match(/a-(\w+(-\w+)*)/g) || [];
|
const componentsInDemo = demo.match(/a-(\w+(-\w+)*)/g) || [];
|
||||||
componentsInDemo.forEach(n => {
|
componentsInDemo.forEach(name => {
|
||||||
const componentName = n.replace(/-(\w)/g, ($, $1) => $1.toUpperCase()).replace(/^a/, '');
|
const dirName = name.replace(/^a-/, '');
|
||||||
|
const componentName = camelize(name).replace(/^a/, '');
|
||||||
|
const upperComponentDir = getUpper(dirName);
|
||||||
|
const upperComponentName = upperComponentDir.replace(/^[a-z]/, $ => $.toUpperCase());
|
||||||
|
|
||||||
if (componentsInPrototype.includes(componentName)) {
|
const componentPath = path.join(__dirname, `../components/${dirName}`);
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const componentPath = path.join(__dirname, `../components/${n.replace(/^a-/, '')}`);
|
|
||||||
if (fs.existsSync(componentPath)) {
|
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;
|
let demoWatcher;
|
||||||
|
|
||||||
chokidar.watch(configPath, { ignoreInitial: true }).on('change', async () => {
|
chokidar.watch(configPath, { ignoreInitial: true }).on('change', async () => {
|
||||||
devComponent = importFresh(configPath).devComponent;
|
({ componentName } = importFresh(configPath).dev);
|
||||||
|
|
||||||
demoWatcher && (await demoWatcher.close());
|
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', () => {
|
demoWatcher.on('change', () => {
|
||||||
renderTemplate(devComponent);
|
renderTemplate(componentName);
|
||||||
});
|
});
|
||||||
|
|
||||||
renderTemplate(devComponent);
|
renderTemplate(componentName);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWatcher = chokidar.watch(path.join(__dirname, `../components/test`));
|
renderTemplate(componentName);
|
||||||
testWatcher.on('change', () => {
|
|
||||||
renderTemplate(devComponent);
|
|
||||||
});
|
|
||||||
|
|
||||||
renderTemplate(devComponent);
|
|
||||||
|
|
||||||
const compiler = webpack(devWebpack);
|
const compiler = webpack(devWebpack);
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@
|
||||||
import animate from 'antd/_util/openAnimation';
|
import animate from 'antd/_util/openAnimation';
|
||||||
import BaseMixin from 'antd/_util/BaseMixin';
|
import BaseMixin from 'antd/_util/BaseMixin';
|
||||||
import { isZhCN } from '../util';
|
import { isZhCN } from '../util';
|
||||||
|
import { dev } from '../../build/config';
|
||||||
export default {
|
export default {
|
||||||
name: 'DemoBox',
|
name: 'DemoBox',
|
||||||
mixins: [BaseMixin],
|
mixins: [BaseMixin],
|
||||||
|
@ -81,7 +82,12 @@ export default {
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.join('-')
|
.join('-')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
const id = ['components', name.replace(/-cn\/?$/, ''), 'demo', ...usTitle.split(' ')]
|
const id = [
|
||||||
|
'components',
|
||||||
|
name.replace(/-cn\/?$/, '') || dev.componentName,
|
||||||
|
'demo',
|
||||||
|
...usTitle.split(' '),
|
||||||
|
]
|
||||||
.join('-')
|
.join('-')
|
||||||
.toLowerCase();
|
.toLowerCase();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue