chore(cli): rename some files
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
/**
|
||||
* Build style entry of all components
|
||||
*/
|
||||
|
||||
import { join, relative } from 'path';
|
||||
import { outputFileSync } from 'fs-extra';
|
||||
import { getComponents } from '../common';
|
||||
import { getStyleExt } from './gen-package-style';
|
||||
import { ES_DIR, LIB_DIR, STYPE_DEPS_JSON_FILE } from '../common/constant';
|
||||
|
||||
function getDeps(component: string): string[] {
|
||||
// eslint-disable-next-line
|
||||
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
|
||||
|
||||
if (styleDepsJson.map[component]) {
|
||||
return [...styleDepsJson.map[component], component];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
function getPath(component: string, ext = '.css') {
|
||||
return join(ES_DIR, `${component}/index${ext}`);
|
||||
}
|
||||
|
||||
function getRelativePath(component: string, style: string, ext: string) {
|
||||
return relative(join(ES_DIR, `${component}/style`), getPath(style, ext));
|
||||
}
|
||||
|
||||
function genEntry(component: string, filename: string, ext = '') {
|
||||
const deps = getDeps(component);
|
||||
const depsPath = deps.map(dep => getRelativePath(component, dep, ext));
|
||||
|
||||
const esEntry = join(ES_DIR, component, `style/${filename}`);
|
||||
const libEntry = join(LIB_DIR, component, `style/${filename}`);
|
||||
|
||||
const esContent = depsPath.map(dep => `import '${dep}';`).join('\n');
|
||||
const libContent = depsPath.map(dep => `require('${dep}');`).join('\n');
|
||||
|
||||
outputFileSync(esEntry, esContent);
|
||||
outputFileSync(libEntry, libContent);
|
||||
}
|
||||
|
||||
export function genComponentStyle() {
|
||||
const ext = getStyleExt();
|
||||
const components = getComponents();
|
||||
|
||||
components.forEach(component => {
|
||||
genEntry(component, 'index.js', '.css');
|
||||
|
||||
if (ext !== 'css') {
|
||||
genEntry(component, ext + '.js', '.' + ext);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -9,21 +9,22 @@ import {
|
||||
STYPE_DEPS_JSON_FILE
|
||||
} from '../common/constant';
|
||||
|
||||
// eslint-disable-next-line
|
||||
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
|
||||
|
||||
function getStyleExt(): string {
|
||||
export function getStyleExt(): string {
|
||||
const preprocessor = get(CONFIG, 'build.css.preprocessor', 'less');
|
||||
|
||||
if (preprocessor === 'sass') {
|
||||
return '.scss';
|
||||
return 'scss';
|
||||
}
|
||||
|
||||
return `.${preprocessor}`;
|
||||
return preprocessor;
|
||||
}
|
||||
|
||||
export function genPacakgeStyle() {
|
||||
const ext = getStyleExt();
|
||||
// eslint-disable-next-line
|
||||
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
|
||||
|
||||
const ext = '.' + getStyleExt();
|
||||
|
||||
const content = styleDepsJson.sequence
|
||||
.map((name: string) => `@import "${join(SRC_DIR, `${name}/index${ext}`)}";`)
|
||||
.join('\n');
|
||||
|
||||
+1
-1
@@ -53,7 +53,7 @@ function genExportConfig() {
|
||||
return 'export { config };';
|
||||
}
|
||||
|
||||
export function genDesktopEntry() {
|
||||
export function genSiteDesktopShared() {
|
||||
const components = getComponents();
|
||||
const documents = resolveDocuments(components);
|
||||
|
||||
+1
-1
@@ -61,7 +61,7 @@ function genCode(components: string[]) {
|
||||
)}\n${genConfig(demos)}\n`;
|
||||
}
|
||||
|
||||
export function genMobileEntry() {
|
||||
export function genSiteMobileShared() {
|
||||
const components = getComponents();
|
||||
const code = genCode(components);
|
||||
|
||||
@@ -61,52 +61,53 @@ function analyzeDeps(component: string) {
|
||||
|
||||
type DepsMap = Record<string, string[]>;
|
||||
|
||||
function sortComponentsByDeps(depsMap: DepsMap) {
|
||||
const result: string[] = [];
|
||||
const record: string[] = [];
|
||||
function getSequence(depsMap: DepsMap) {
|
||||
const sequence: string[] = [];
|
||||
const record = new Set();
|
||||
|
||||
function add(item: string) {
|
||||
const deps = depsMap[item];
|
||||
|
||||
if (result.includes(item) || !deps) {
|
||||
if (sequence.includes(item) || !deps) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (record.includes(item)) {
|
||||
result.push(item);
|
||||
if (record.has(item)) {
|
||||
sequence.push(item);
|
||||
return;
|
||||
}
|
||||
|
||||
record.push(item);
|
||||
record.add(item);
|
||||
|
||||
if (!deps.length) {
|
||||
result.push(item);
|
||||
sequence.push(item);
|
||||
return;
|
||||
}
|
||||
|
||||
deps.forEach(add);
|
||||
|
||||
if (result.includes(item)) {
|
||||
if (sequence.includes(item)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const maxIndex = Math.max(...deps.map(dep => result.indexOf(dep)));
|
||||
const maxIndex = Math.max(...deps.map(dep => sequence.indexOf(dep)));
|
||||
|
||||
result.splice(maxIndex + 1, 0, item);
|
||||
sequence.splice(maxIndex + 1, 0, item);
|
||||
}
|
||||
|
||||
components.forEach(add);
|
||||
|
||||
return result;
|
||||
return sequence;
|
||||
}
|
||||
|
||||
export function genDepsMap() {
|
||||
const map = components.filter(checkStyleExists).reduce((map, component) => {
|
||||
map[component] = analyzeDeps(component);
|
||||
return map;
|
||||
}, {} as DepsMap);
|
||||
export function genStyleDepsMap() {
|
||||
const map = {} as DepsMap;
|
||||
|
||||
const sequence = sortComponentsByDeps(map);
|
||||
components.filter(checkStyleExists).forEach(component => {
|
||||
map[component] = analyzeDeps(component);
|
||||
});
|
||||
|
||||
const sequence = getSequence(map);
|
||||
|
||||
Object.keys(map).forEach(key => {
|
||||
map[key] = map[key].sort(
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
/* eslint-disable no-use-before-define */
|
||||
/**
|
||||
* Build style entry of all components
|
||||
*/
|
||||
|
||||
import { sep, join, relative } from 'path';
|
||||
import { existsSync, outputFileSync } from 'fs-extra';
|
||||
import { getComponents } from '../common';
|
||||
import { ES_DIR, LIB_DIR } from '../common/constant';
|
||||
import dependencyTree from 'dependency-tree';
|
||||
|
||||
interface DependencyObj {
|
||||
[k: string]: DependencyObj;
|
||||
}
|
||||
|
||||
const components = getComponents();
|
||||
|
||||
// replace seq for windows
|
||||
function replaceSeq(path: string) {
|
||||
return path.split(sep).join('/');
|
||||
}
|
||||
|
||||
function genEntry(component: string, filename: string, ext = '') {
|
||||
const deps = analyzeDeps(component).map(dep =>
|
||||
getStyleRelativePath(component, dep, ext)
|
||||
);
|
||||
|
||||
const esEntry = join(ES_DIR, component, `style/${filename}`);
|
||||
const libEntry = join(LIB_DIR, component, `style/${filename}`);
|
||||
|
||||
const esContent = deps.map(dep => `import '${dep}';`).join('\n');
|
||||
const libContent = deps.map(dep => `require('${dep}');`).join('\n');
|
||||
|
||||
outputFileSync(esEntry, esContent);
|
||||
outputFileSync(libEntry, libContent);
|
||||
}
|
||||
|
||||
// analyze component dependencies
|
||||
function analyzeDeps(component: string) {
|
||||
const checkList = ['base'];
|
||||
|
||||
search(
|
||||
dependencyTree({
|
||||
directory: ES_DIR,
|
||||
filename: join(ES_DIR, component, 'index.js'),
|
||||
filter: path => !~path.indexOf('node_modules')
|
||||
}),
|
||||
component,
|
||||
checkList
|
||||
);
|
||||
|
||||
checkList.push(component);
|
||||
|
||||
return checkList.filter(checkStyleExists);
|
||||
}
|
||||
|
||||
function search(tree: DependencyObj, component: string, checkList: string[]) {
|
||||
Object.keys(tree).forEach(key => {
|
||||
search(tree[key], component, checkList);
|
||||
components
|
||||
.filter(item =>
|
||||
key
|
||||
.replace(ES_DIR, '')
|
||||
.split('/')
|
||||
.includes(item)
|
||||
)
|
||||
.forEach(item => {
|
||||
if (!checkList.includes(item) && item !== component) {
|
||||
checkList.push(item);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getStylePath(component: string, ext = '.css') {
|
||||
if (component === 'base') {
|
||||
return join(ES_DIR, `style/base${ext}`);
|
||||
}
|
||||
|
||||
return join(ES_DIR, `${component}/index${ext}`);
|
||||
}
|
||||
|
||||
function getStyleRelativePath(component: string, style: string, ext: string) {
|
||||
return replaceSeq(
|
||||
relative(join(ES_DIR, `${component}/style`), getStylePath(style, ext))
|
||||
);
|
||||
}
|
||||
|
||||
function checkStyleExists(component: string) {
|
||||
return existsSync(getStylePath(component));
|
||||
}
|
||||
|
||||
export function genStyleEntry() {
|
||||
components.forEach(component => {
|
||||
genEntry(component, 'index.js', '.css');
|
||||
genEntry(component, 'less.js', '.less');
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user