mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
chore(cli): rename some files
This commit is contained in:
parent
afc6113938
commit
736bac00b9
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import VanDoc from './components';
|
import VanDoc from './components';
|
||||||
import { config } from 'desktop-entry';
|
import { config } from 'site-desktop-shared';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import decamelize from 'decamelize';
|
import decamelize from 'decamelize';
|
||||||
import { documents } from 'desktop-entry';
|
import { documents } from 'site-desktop-shared';
|
||||||
|
|
||||||
const routes = [];
|
const routes = [];
|
||||||
const names = Object.keys(documents);
|
const names = Object.keys(documents);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { config } from 'mobile-entry';
|
import { config } from 'site-mobile-shared';
|
||||||
import DemoHomeNav from './DemoHomeNav';
|
import DemoHomeNav from './DemoHomeNav';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import decamelize from 'decamelize';
|
import decamelize from 'decamelize';
|
||||||
import DemoHome from './components/DemoHome';
|
import DemoHome from './components/DemoHome';
|
||||||
import { demos } from 'mobile-entry';
|
import { demos } from 'site-mobile-shared';
|
||||||
|
|
||||||
const routes = [];
|
const routes = [];
|
||||||
const names = Object.keys(demos);
|
const names = Object.keys(demos);
|
||||||
|
@ -7,8 +7,9 @@ import { remove, copy, readdirSync } from 'fs-extra';
|
|||||||
import { compileJs } from '../compiler/compile-js';
|
import { compileJs } from '../compiler/compile-js';
|
||||||
import { compileSfc } from '../compiler/compile-sfc';
|
import { compileSfc } from '../compiler/compile-sfc';
|
||||||
import { compileStyle } from '../compiler/compile-style';
|
import { compileStyle } from '../compiler/compile-style';
|
||||||
import { genStyleEntry } from '../compiler/gen-style-entry';
|
|
||||||
import { genPackageEntry } from '../compiler/gen-package-entry';
|
import { genPackageEntry } from '../compiler/gen-package-entry';
|
||||||
|
import { genStyleDepsMap } from '../compiler/gen-style-deps-map';
|
||||||
|
import { genComponentStyle } from '../compiler/gen-component-style';
|
||||||
import { SRC_DIR, LIB_DIR, ES_DIR } from '../common/constant';
|
import { SRC_DIR, LIB_DIR, ES_DIR } from '../common/constant';
|
||||||
import {
|
import {
|
||||||
isDir,
|
isDir,
|
||||||
@ -99,7 +100,8 @@ export async function buildStyleEntry() {
|
|||||||
start('Build style entry');
|
start('Build style entry');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
genStyleEntry();
|
genStyleDepsMap();
|
||||||
|
genComponentStyle();
|
||||||
success('Build style entry');
|
success('Build style entry');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error('Build style entry');
|
error('Build style entry');
|
||||||
|
@ -6,9 +6,9 @@ import { buildESModuleOutputs } from './build';
|
|||||||
import { siteDevConfig } from '../config/webpack.site.dev';
|
import { siteDevConfig } from '../config/webpack.site.dev';
|
||||||
import { genPackageEntry } from '../compiler/gen-package-entry';
|
import { genPackageEntry } from '../compiler/gen-package-entry';
|
||||||
import { genPacakgeStyle } from '../compiler/gen-package-style';
|
import { genPacakgeStyle } from '../compiler/gen-package-style';
|
||||||
import { genMobileEntry } from '../compiler/gen-mobile-entry';
|
import { genSiteMobileShared } from '../compiler/gen-site-mobile-shared';
|
||||||
import { genDesktopEntry } from '../compiler/gen-desktop-entry';
|
import { genSiteDesktopShared } from '../compiler/gen-site-desktop-shared';
|
||||||
import { genDepsMap } from '../compiler/gen-style-deps-map';
|
import { genStyleDepsMap } from '../compiler/gen-style-deps-map';
|
||||||
|
|
||||||
function runWebpack() {
|
function runWebpack() {
|
||||||
const server = new WebpackDevServer(
|
const server = new WebpackDevServer(
|
||||||
@ -38,10 +38,10 @@ function runWebpack() {
|
|||||||
export async function dev() {
|
export async function dev() {
|
||||||
await clean();
|
await clean();
|
||||||
await buildESModuleOutputs();
|
await buildESModuleOutputs();
|
||||||
genDepsMap();
|
genStyleDepsMap();
|
||||||
genPackageEntry();
|
genPackageEntry();
|
||||||
genPacakgeStyle();
|
genPacakgeStyle();
|
||||||
genMobileEntry();
|
genSiteMobileShared();
|
||||||
genDesktopEntry();
|
genSiteDesktopShared();
|
||||||
runWebpack();
|
runWebpack();
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ export const CONFIG_DIR = join(__dirname, '../config');
|
|||||||
|
|
||||||
export const PACKAGE_ENTRY_FILE = join(DIST_DIR, 'package-entry.js');
|
export const PACKAGE_ENTRY_FILE = join(DIST_DIR, 'package-entry.js');
|
||||||
export const PACKAGE_STYLE_FILE = join(DIST_DIR, 'package-style.css');
|
export const PACKAGE_STYLE_FILE = join(DIST_DIR, 'package-style.css');
|
||||||
export const MOBILE_ENTRY_FILE = join(DIST_DIR, 'mobile-entry.js');
|
export const MOBILE_ENTRY_FILE = join(DIST_DIR, 'site-mobile-shared.js');
|
||||||
export const DESKTOP_ENTRY_FILE = join(DIST_DIR, 'desktop-entry.js');
|
export const DESKTOP_ENTRY_FILE = join(DIST_DIR, 'site-desktop-shared.js');
|
||||||
export const STYPE_DEPS_JSON_FILE = join(DIST_DIR, 'style-deps.json');
|
export const STYPE_DEPS_JSON_FILE = join(DIST_DIR, 'style-deps.json');
|
||||||
|
|
||||||
export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
export const JEST_CONFIG_FILE = join(CONFIG_DIR, 'jest.config.js');
|
||||||
|
55
packages/vant-cli/src/compiler/gen-component-style.ts
Normal file
55
packages/vant-cli/src/compiler/gen-component-style.ts
Normal file
@ -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
|
STYPE_DEPS_JSON_FILE
|
||||||
} from '../common/constant';
|
} from '../common/constant';
|
||||||
|
|
||||||
// eslint-disable-next-line
|
export function getStyleExt(): string {
|
||||||
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
|
|
||||||
|
|
||||||
function getStyleExt(): string {
|
|
||||||
const preprocessor = get(CONFIG, 'build.css.preprocessor', 'less');
|
const preprocessor = get(CONFIG, 'build.css.preprocessor', 'less');
|
||||||
|
|
||||||
if (preprocessor === 'sass') {
|
if (preprocessor === 'sass') {
|
||||||
return '.scss';
|
return 'scss';
|
||||||
}
|
}
|
||||||
|
|
||||||
return `.${preprocessor}`;
|
return preprocessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genPacakgeStyle() {
|
export function genPacakgeStyle() {
|
||||||
const ext = getStyleExt();
|
// eslint-disable-next-line
|
||||||
|
const styleDepsJson = require(STYPE_DEPS_JSON_FILE);
|
||||||
|
|
||||||
|
const ext = '.' + getStyleExt();
|
||||||
|
|
||||||
const content = styleDepsJson.sequence
|
const content = styleDepsJson.sequence
|
||||||
.map((name: string) => `@import "${join(SRC_DIR, `${name}/index${ext}`)}";`)
|
.map((name: string) => `@import "${join(SRC_DIR, `${name}/index${ext}`)}";`)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
|
@ -53,7 +53,7 @@ function genExportConfig() {
|
|||||||
return 'export { config };';
|
return 'export { config };';
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genDesktopEntry() {
|
export function genSiteDesktopShared() {
|
||||||
const components = getComponents();
|
const components = getComponents();
|
||||||
const documents = resolveDocuments(components);
|
const documents = resolveDocuments(components);
|
||||||
|
|
@ -61,7 +61,7 @@ function genCode(components: string[]) {
|
|||||||
)}\n${genConfig(demos)}\n`;
|
)}\n${genConfig(demos)}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genMobileEntry() {
|
export function genSiteMobileShared() {
|
||||||
const components = getComponents();
|
const components = getComponents();
|
||||||
const code = genCode(components);
|
const code = genCode(components);
|
||||||
|
|
@ -61,52 +61,53 @@ function analyzeDeps(component: string) {
|
|||||||
|
|
||||||
type DepsMap = Record<string, string[]>;
|
type DepsMap = Record<string, string[]>;
|
||||||
|
|
||||||
function sortComponentsByDeps(depsMap: DepsMap) {
|
function getSequence(depsMap: DepsMap) {
|
||||||
const result: string[] = [];
|
const sequence: string[] = [];
|
||||||
const record: string[] = [];
|
const record = new Set();
|
||||||
|
|
||||||
function add(item: string) {
|
function add(item: string) {
|
||||||
const deps = depsMap[item];
|
const deps = depsMap[item];
|
||||||
|
|
||||||
if (result.includes(item) || !deps) {
|
if (sequence.includes(item) || !deps) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (record.includes(item)) {
|
if (record.has(item)) {
|
||||||
result.push(item);
|
sequence.push(item);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
record.push(item);
|
record.add(item);
|
||||||
|
|
||||||
if (!deps.length) {
|
if (!deps.length) {
|
||||||
result.push(item);
|
sequence.push(item);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
deps.forEach(add);
|
deps.forEach(add);
|
||||||
|
|
||||||
if (result.includes(item)) {
|
if (sequence.includes(item)) {
|
||||||
return;
|
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);
|
components.forEach(add);
|
||||||
|
|
||||||
return result;
|
return sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genDepsMap() {
|
export function genStyleDepsMap() {
|
||||||
const map = components.filter(checkStyleExists).reduce((map, component) => {
|
const map = {} as DepsMap;
|
||||||
map[component] = analyzeDeps(component);
|
|
||||||
return 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 => {
|
Object.keys(map).forEach(key => {
|
||||||
map[key] = map[key].sort(
|
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');
|
|
||||||
});
|
|
||||||
}
|
|
@ -23,8 +23,8 @@ export const siteDevConfig = merge(
|
|||||||
},
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
'mobile-entry': MOBILE_ENTRY_FILE,
|
'site-mobile-shared': MOBILE_ENTRY_FILE,
|
||||||
'desktop-entry': DESKTOP_ENTRY_FILE
|
'site-desktop-shared': DESKTOP_ENTRY_FILE
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user