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

View File

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