[breaking change] rebuild style struct (#2021)

This commit is contained in:
neverland
2018-11-03 21:08:06 +08:00
committed by GitHub
parent a5576762d8
commit 11ce2a602f
165 changed files with 1371 additions and 4729 deletions
+32 -9
View File
@@ -6,15 +6,17 @@ const fs = require('fs-extra');
const path = require('path');
const components = require('./get-components')();
const dependencyTree = require('dependency-tree');
const whiteList = ['info', 'icon', 'loading', 'cell', 'button'];
const whiteList = ['info', 'icon', 'loading', 'cell', 'cell-group', 'button'];
const dir = path.join(__dirname, '../es');
components.forEach(component => {
const deps = analyzeDependencies(component);
const deps = analyzeDependencies(component).map(dep =>
getStyleRelativePath(component, dep)
);
const esEntry = path.join(dir, component, 'style/index.js');
const libEntry = path.join(__dirname, '../lib', component, 'style/index.js');
const esContent = deps.map(dep => `import '../../vant-css/${dep}.css';`).join('\n');
const libContent = deps.map(dep => `require('../../vant-css/${dep}.css');`).join('\n');
const esContent = deps.map(dep => `import '${dep}';`).join('\n');
const libContent = deps.map(dep => `require('${dep}');`).join('\n');
fs.outputFileSync(esEntry, esContent);
fs.outputFileSync(libEntry, libContent);
@@ -45,17 +47,38 @@ function search(tree, component, checkList) {
Object.keys(tree).forEach(key => {
search(tree[key], component, checkList);
components
.filter(item => key.replace(dir, '').split('/').includes(item))
.filter(item =>
key
.replace(dir, '')
.split('/')
.includes(item)
)
.forEach(item => {
if (!checkList.includes(item) && !whiteList.includes(item) && item !== component) {
if (
!checkList.includes(item) &&
!whiteList.includes(item) &&
item !== component
) {
checkList.push(item);
}
});
});
}
function checkComponentHasStyle(component) {
return fs.existsSync(
path.join(__dirname, `../es/vant-css/`, `${component}.css`)
function getStylePath(component) {
if (component === 'base') {
return path.join(__dirname, '../es/style/base.css');
}
return path.join(__dirname, `../es/${component}/index.css`);
}
function getStyleRelativePath(component, style) {
return path.relative(
path.join(__dirname, `../es/${component}/style`),
getStylePath(style)
);
}
function checkComponentHasStyle(component) {
return fs.existsSync(getStylePath(component));
}