Skip to content

Commit

Permalink
chore: update build config
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Jan 15, 2020
1 parent 8785179 commit 6186c7e
Showing 1 changed file with 30 additions and 7 deletions.
37 changes: 30 additions & 7 deletions build/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,12 @@ const i18n = new VueI18n({
const router = new VueRouter({
mode: 'history',
routes: [{ path: '/*', component: Test }],
routes: [{
path: '/test',
component: () => import('../components/test/index.vue'),
}, {
path: '/*', component: Test
}],
});
const store = new Vuex.Store({
Expand Down Expand Up @@ -113,12 +118,14 @@ const renderTemplate = name => {
Tooltip: 'tooltip', // for DemoBox
};

const demoPaths = fs.readdirSync(path.join(__dirname, `../components/${name}/demo`));

demoPaths.forEach(demoPath => {
const demo = fs
.readFileSync(path.join(__dirname, `../components/${name}/demo/${demoPath}`))
.toString();
const demoPaths = fs
.readdirSync(path.join(__dirname, `../components/${name}/demo`))
.map(p => `../components/${name}/demo/${p}`);
const testPaths = fs
.readdirSync(path.join(__dirname, `../components/test`))
.map(p => `../components/test/${p}`);
[...demoPaths, ...testPaths].forEach(demoPath => {
const demo = fs.readFileSync(path.join(__dirname, demoPath)).toString();

const componentsInDemo = demo.match(/a-(\w+(-\w+)*)/g) || [];
componentsInDemo.forEach(name => {
Expand Down Expand Up @@ -147,6 +154,22 @@ const renderTemplate = name => {
fs.writeFileSync(OUTPUT_PATH, template);
};

function fsExistsSync(path) {
try {
fs.accessSync(path, fs.F_OK);
} catch (e) {
return false;
}
return true;
}

if (!fsExistsSync(path.join(__dirname, '../components/test/index.vue'))) {
if (!fsExistsSync(path.join(__dirname, '../components/test'))) {
fs.mkdirSync(path.join(__dirname, '../components/test'));
}
fs.writeFileSync(path.join(__dirname, '../components/test/index.vue'), `<template></template>`);
}

let demoWatcher;

chokidar.watch(configPath, { ignoreInitial: true }).on('change', async () => {
Expand Down

0 comments on commit 6186c7e

Please sign in to comment.