Skip to content

perf: find parent component when only secondary component used in demo #1680

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

Merged
merged 2 commits into from
Feb 7, 2020
Merged
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
4 changes: 3 additions & 1 deletion build/config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module.exports = {
devComponent: 'menu',
dev: {
componentName: 'tree', // dev components
},
};
50 changes: 31 additions & 19 deletions build/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'];

Expand Down Expand Up @@ -116,6 +128,7 @@ const generateInstall = components =>
const renderTemplate = name => {
const components = {
Tooltip: 'tooltip', // for DemoBox
Icon: 'icon', // Basic
};

const demoPaths = fs
Expand All @@ -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;
}
});
});
Expand Down Expand Up @@ -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);

Expand Down
8 changes: 7 additions & 1 deletion site/components/demoBox.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -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();

Expand Down