[bugfix] missing style entry in dist lib

This commit is contained in:
陈嘉涵 2018-04-17 15:00:53 +08:00
parent 6d9b3a744c
commit 4179bc45ec
3 changed files with 35 additions and 28 deletions

View File

@ -8,34 +8,40 @@ const components = require('./get-components')();
const dependencyTree = require('dependency-tree'); const dependencyTree = require('dependency-tree');
const SEP = path.sep; const SEP = path.sep;
components.forEach(componentName => { function build(folder, isESModule) {
const esDir = path.resolve(__dirname, '../../es'); const dir = path.resolve(__dirname, '../../', folder);
const content = analyzeDependencies(componentName, esDir).map(component => `import '../../vant-css/${component}.css';`); components.forEach(componentName => {
fs.outputFileSync(path.join(esDir, componentName, './style/index.js'), content.join('\n')); const content = analyzeDependencies(componentName, dir)
}); .map(component => isESModule ? `import '../../vant-css/${component}.css';` : `require('../../vant-css/${component}.css');`);
fs.outputFileSync(path.join(dir, componentName, './style/index.js'), content.join('\n'));
});
// Analyze component dependencies // Analyze component dependencies
function analyzeDependencies(componentName, esDir) { function analyzeDependencies(componentName, dir) {
const checkList = ['base']; const checkList = ['base'];
const whiteList = ['icon', 'loading', 'cell', 'button']; const whiteList = ['icon', 'loading', 'cell', 'button'];
search(dependencyTree({ search(dependencyTree({
directory: esDir, directory: dir,
filename: path.resolve(esDir, componentName, 'index.js'), filename: path.resolve(dir, componentName, 'index.js'),
filter: path => path.indexOf(`vant${SEP}es${SEP}`) !== -1 filter: path => path.indexOf(`vant${SEP}${folder}${SEP}`) !== -1
}), checkList, whiteList); }), checkList, whiteList);
return checkList.filter(component => checkComponentHasStyle(component)); return checkList.filter(component => checkComponentHasStyle(component));
} }
function search(tree, checkList, whiteList) { function search(tree, checkList, whiteList) {
tree && Object.keys(tree).forEach(key => { tree && Object.keys(tree).forEach(key => {
search(tree[key], checkList, whiteList); search(tree[key], checkList, whiteList);
const component = key.split(`${SEP}vant${SEP}es${SEP}`)[1].replace(`${SEP}index.js`, '').replace(`mixins${SEP}`, ''); const component = key.split(`${SEP}vant${SEP}${folder}${SEP}`)[1].replace(`${SEP}index.js`, '').replace(`mixins${SEP}`, '');
if (checkList.indexOf(component) === -1 && whiteList.indexOf(component) === -1) { if (checkList.indexOf(component) === -1 && whiteList.indexOf(component) === -1) {
checkList.push(component); checkList.push(component);
} }
}); });
}
function checkComponentHasStyle(componentName) {
return fs.existsSync(path.join(__dirname, `../../${folder}/vant-css/`, `${componentName}.css`));
}
} }
function checkComponentHasStyle(componentName) { build('es', true);
return fs.existsSync(path.join(__dirname, '../../es/vant-css/', `${componentName}.css`)); build('lib');
}

View File

@ -25,6 +25,7 @@ gulp.task('compile', () => {
gulp.task('lib', ['compile'], () => { gulp.task('lib', ['compile'], () => {
const ttf = glob.sync(resolve('./src/*.ttf')); const ttf = glob.sync(resolve('./src/*.ttf'));
ttf.forEach(ttf => fs.copy(ttf, './lib/' + path.parse(ttf).base)); ttf.forEach(ttf => fs.copy(ttf, './lib/' + path.parse(ttf).base));
fs.copy('./lib', '../../lib/vant-css');
fs.copy('./lib', '../../es/vant-css'); fs.copy('./lib', '../../es/vant-css');
}); });