mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(cli): optimize gen style deps map
This commit is contained in:
parent
6a8a9a6f79
commit
0bdad6f97c
@ -1,4 +1,3 @@
|
|||||||
import { start, error, success } from 'signale';
|
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { clean } from './clean';
|
import { clean } from './clean';
|
||||||
import { remove, copy, readdirSync } from 'fs-extra';
|
import { remove, copy, readdirSync } from 'fs-extra';
|
||||||
@ -11,6 +10,7 @@ import { genStyleDepsMap } from '../compiler/gen-style-deps-map';
|
|||||||
import { genComponentStyle } from '../compiler/gen-component-style';
|
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 {
|
||||||
|
logger,
|
||||||
isDir,
|
isDir,
|
||||||
isSfc,
|
isSfc,
|
||||||
isStyle,
|
isStyle,
|
||||||
@ -53,56 +53,56 @@ async function compileDir(dir: string) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function buildESModuleOutputs() {
|
async function buildESModuleOutputs() {
|
||||||
await copy(SRC_DIR, ES_DIR);
|
await copy(SRC_DIR, ES_DIR);
|
||||||
|
|
||||||
start('Build esmodule outputs');
|
logger.start('Build esmodule outputs');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setModuleEnv('esmodule');
|
setModuleEnv('esmodule');
|
||||||
await compileDir(ES_DIR);
|
await compileDir(ES_DIR);
|
||||||
success('Build esmodule outputs');
|
logger.success('Build esmodule outputs');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error('Build esmodule outputs');
|
logger.error('Build esmodule outputs');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function buildCommonjsOutputs() {
|
async function buildCommonjsOutputs() {
|
||||||
await copy(SRC_DIR, LIB_DIR);
|
await copy(SRC_DIR, LIB_DIR);
|
||||||
|
|
||||||
start('Build commonjs outputs');
|
logger.start('Build commonjs outputs');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
setModuleEnv('commonjs');
|
setModuleEnv('commonjs');
|
||||||
await compileDir(LIB_DIR);
|
await compileDir(LIB_DIR);
|
||||||
success('Build commonjs outputs');
|
logger.success('Build commonjs outputs');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error('Build commonjs outputs');
|
logger.error('Build commonjs outputs');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function buildStyleEntry() {
|
async function buildStyleEntry() {
|
||||||
start('Build style entry');
|
logger.start('Build style entry');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
genStyleDepsMap();
|
await genStyleDepsMap();
|
||||||
genComponentStyle();
|
genComponentStyle();
|
||||||
success('Build style entry');
|
logger.success('Build style entry');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error('Build style entry');
|
logger.error('Build style entry');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function buildPackedOutputs() {
|
async function buildPackedOutputs() {
|
||||||
start('Build packed outputs');
|
logger.start('Build packed outputs');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
genPackageEntry();
|
genPackageEntry();
|
||||||
await compilePackage(false);
|
await compilePackage(false);
|
||||||
await compilePackage(true);
|
await compilePackage(true);
|
||||||
success('Build packed outputs');
|
logger.success('Build packed outputs');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
error('Build packed outputs');
|
logger.error('Build packed outputs');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import signale from 'signale';
|
import { logger } from '../common';
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs-extra';
|
||||||
|
|
||||||
const commitRE = /^(revert: )?(fix|feat|docs|perf|test|types|build|chore|refactor|breaking change)(\(.+\))?: .{1,50}/;
|
const commitRE = /^(revert: )?(fix|feat|docs|perf|test|types|build|chore|refactor|breaking change)(\(.+\))?: .{1,50}/;
|
||||||
const mergeRE = /Merge branch /;
|
const mergeRE = /Merge branch /;
|
||||||
@ -9,7 +9,7 @@ export function commitLint() {
|
|||||||
const commitMsg = readFileSync(gitParams, 'utf-8').trim();
|
const commitMsg = readFileSync(gitParams, 'utf-8').trim();
|
||||||
|
|
||||||
if (!commitRE.test(commitMsg) || !mergeRE.test(commitMsg)) {
|
if (!commitRE.test(commitMsg) || !mergeRE.test(commitMsg)) {
|
||||||
signale.error(`Error: invalid commit message: "${commitMsg}".
|
logger.error(`Error: invalid commit message: "${commitMsg}".
|
||||||
|
|
||||||
Proper commit message format is required for automated changelog generation.
|
Proper commit message format is required for automated changelog generation.
|
||||||
|
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
import { start, error, success } from 'signale';
|
|
||||||
import { lint as stylelint } from 'stylelint';
|
import { lint as stylelint } from 'stylelint';
|
||||||
import { CLIEngine } from 'eslint';
|
import { CLIEngine } from 'eslint';
|
||||||
|
import { logger } from '../common';
|
||||||
import { SCRIPT_EXTS } from '../common/constant';
|
import { SCRIPT_EXTS } from '../common/constant';
|
||||||
|
|
||||||
function lintScript() {
|
function lintScript() {
|
||||||
start('ESLint Start');
|
logger.start('ESLint Start');
|
||||||
|
|
||||||
const cli = new CLIEngine({
|
const cli = new CLIEngine({
|
||||||
fix: true,
|
fix: true,
|
||||||
@ -19,15 +19,15 @@ function lintScript() {
|
|||||||
// output lint errors
|
// output lint errors
|
||||||
const formatted = formatter(report.results);
|
const formatted = formatter(report.results);
|
||||||
if (formatted) {
|
if (formatted) {
|
||||||
error('ESLint Failed');
|
logger.error('ESLint Failed');
|
||||||
console.log(formatter(report.results));
|
console.log(formatter(report.results));
|
||||||
} else {
|
} else {
|
||||||
success('ESLint Passed');
|
logger.success('ESLint Passed');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function lintStyle() {
|
function lintStyle() {
|
||||||
start('Stylelint Start');
|
logger.start('Stylelint Start');
|
||||||
|
|
||||||
stylelint({
|
stylelint({
|
||||||
fix: true,
|
fix: true,
|
||||||
@ -35,10 +35,10 @@ function lintStyle() {
|
|||||||
files: ['src/**/*.css', 'src/**/*.less', 'src/**/*.scss', 'src/**/*.vue']
|
files: ['src/**/*.css', 'src/**/*.less', 'src/**/*.scss', 'src/**/*.vue']
|
||||||
}).then(result => {
|
}).then(result => {
|
||||||
if (result.errored) {
|
if (result.errored) {
|
||||||
error('Stylelint Failed');
|
logger.error('Stylelint Failed');
|
||||||
console.log(result.output);
|
console.log(result.output);
|
||||||
} else {
|
} else {
|
||||||
success('Stylelint Passed');
|
logger.success('Stylelint Passed');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
|
import logger from 'signale';
|
||||||
import decamelize from 'decamelize';
|
import decamelize from 'decamelize';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { get } from 'lodash';
|
import { get } from 'lodash';
|
||||||
import { readdirSync, existsSync, lstatSync, readFileSync } from 'fs-extra';
|
import { readdirSync, existsSync, lstatSync, readFileSync } from 'fs-extra';
|
||||||
import { CONFIG, SRC_DIR, WEBPACK_CONFIG_FILE } from './constant';
|
import { CONFIG, SRC_DIR, WEBPACK_CONFIG_FILE } from './constant';
|
||||||
|
|
||||||
|
logger.config({
|
||||||
|
displayTimestamp: true
|
||||||
|
});
|
||||||
|
|
||||||
export const EXT_REGEXP = /\.\w+$/;
|
export const EXT_REGEXP = /\.\w+$/;
|
||||||
export const SFC_REGEXP = /\.(vue)$/;
|
export const SFC_REGEXP = /\.(vue)$/;
|
||||||
export const DEMO_REGEXP = /\/demo$/;
|
export const DEMO_REGEXP = /\/demo$/;
|
||||||
@ -114,4 +119,4 @@ export function getCssLang(): string {
|
|||||||
return preprocessor;
|
return preprocessor;
|
||||||
}
|
}
|
||||||
|
|
||||||
export { decamelize };
|
export { logger, decamelize };
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import webpack from 'webpack';
|
import webpack from 'webpack';
|
||||||
import WebpackDevServer from 'webpack-dev-server';
|
import WebpackDevServer from 'webpack-dev-server';
|
||||||
import { getPort } from 'portfinder';
|
import { getPort } from 'portfinder';
|
||||||
import { buildESModuleOutputs } from '../commands/build';
|
import { logger } from '../common';
|
||||||
import { genPackageEntry } from './gen-package-entry';
|
import { genPackageEntry } from './gen-package-entry';
|
||||||
import { genPacakgeStyle } from './gen-package-style';
|
import { genPacakgeStyle } from './gen-package-style';
|
||||||
import { genSiteMobileShared } from './gen-site-mobile-shared';
|
import { genSiteMobileShared } from './gen-site-mobile-shared';
|
||||||
@ -11,6 +11,8 @@ import { siteDevConfig } from '../config/webpack.site.dev';
|
|||||||
import { sitePrdConfig } from '../config/webpack.site.prd';
|
import { sitePrdConfig } from '../config/webpack.site.prd';
|
||||||
|
|
||||||
function watch() {
|
function watch() {
|
||||||
|
logger.start('Start development');
|
||||||
|
|
||||||
const server = new WebpackDevServer(
|
const server = new WebpackDevServer(
|
||||||
webpack(siteDevConfig),
|
webpack(siteDevConfig),
|
||||||
(siteDevConfig as any).devServer
|
(siteDevConfig as any).devServer
|
||||||
@ -48,8 +50,7 @@ function build() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function compileSite(production = false) {
|
export async function compileSite(production = false) {
|
||||||
await buildESModuleOutputs();
|
await genStyleDepsMap();
|
||||||
genStyleDepsMap();
|
|
||||||
genPackageEntry();
|
genPackageEntry();
|
||||||
genPacakgeStyle();
|
genPacakgeStyle();
|
||||||
genSiteMobileShared();
|
genSiteMobileShared();
|
||||||
|
@ -4,19 +4,66 @@
|
|||||||
|
|
||||||
import dependencyTree from 'dependency-tree';
|
import dependencyTree from 'dependency-tree';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import { getComponents } from '../common';
|
import { compileJs } from './compile-js';
|
||||||
import { existsSync, writeFileSync, ensureDirSync } from 'fs-extra';
|
import { compileSfc } from './compile-sfc';
|
||||||
import { ES_DIR, DIST_DIR, STYPE_DEPS_JSON_FILE } from '../common/constant';
|
import { compileStyle } from './compile-style';
|
||||||
|
import {
|
||||||
|
logger,
|
||||||
|
isDir,
|
||||||
|
isSfc,
|
||||||
|
isStyle,
|
||||||
|
isScript,
|
||||||
|
getComponents
|
||||||
|
} from '../common';
|
||||||
|
import { SRC_DIR, DIST_DIR, STYPE_DEPS_JSON_FILE } from '../common/constant';
|
||||||
|
import {
|
||||||
|
copy,
|
||||||
|
existsSync,
|
||||||
|
readdirSync,
|
||||||
|
writeFileSync,
|
||||||
|
ensureDirSync
|
||||||
|
} from 'fs-extra';
|
||||||
|
|
||||||
interface DependencyObj {
|
interface DependencyObj {
|
||||||
[k: string]: DependencyObj;
|
[k: string]: DependencyObj;
|
||||||
}
|
}
|
||||||
|
|
||||||
const components = getComponents();
|
const components = getComponents();
|
||||||
|
const TEMP_DIR = join(DIST_DIR, 'temp');
|
||||||
|
|
||||||
|
async function compileTempDir(dir: string) {
|
||||||
|
const files = readdirSync(dir);
|
||||||
|
|
||||||
|
await Promise.all(
|
||||||
|
files.map(filename => {
|
||||||
|
const filePath = join(dir, filename);
|
||||||
|
|
||||||
|
if (isDir(filePath)) {
|
||||||
|
return compileTempDir(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (filename.indexOf('index') !== -1) {
|
||||||
|
if (isSfc(filePath)) {
|
||||||
|
return compileSfc(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isScript(filePath)) {
|
||||||
|
return compileJs(filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isStyle(filePath)) {
|
||||||
|
return compileStyle(filePath);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Promise.resolve();
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
function matchPath(path: string, component: string): boolean {
|
function matchPath(path: string, component: string): boolean {
|
||||||
return path
|
return path
|
||||||
.replace(ES_DIR, '')
|
.replace(TEMP_DIR, '')
|
||||||
.split('/')
|
.split('/')
|
||||||
.includes(component);
|
.includes(component);
|
||||||
}
|
}
|
||||||
@ -35,7 +82,7 @@ function search(tree: DependencyObj, component: string, checkList: string[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getStylePath(component: string) {
|
function getStylePath(component: string) {
|
||||||
return join(ES_DIR, `${component}/index.css`);
|
return join(TEMP_DIR, `${component}/index.css`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkStyleExists(component: string) {
|
function checkStyleExists(component: string) {
|
||||||
@ -48,8 +95,8 @@ function analyzeDeps(component: string) {
|
|||||||
|
|
||||||
search(
|
search(
|
||||||
dependencyTree({
|
dependencyTree({
|
||||||
directory: ES_DIR,
|
directory: TEMP_DIR,
|
||||||
filename: join(ES_DIR, component, 'index.js'),
|
filename: join(TEMP_DIR, component, 'index.js'),
|
||||||
filter: path => !~path.indexOf('node_modules')
|
filter: path => !~path.indexOf('node_modules')
|
||||||
}),
|
}),
|
||||||
component,
|
component,
|
||||||
@ -100,9 +147,14 @@ function getSequence(depsMap: DepsMap) {
|
|||||||
return sequence;
|
return sequence;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function genStyleDepsMap() {
|
export async function genStyleDepsMap() {
|
||||||
|
logger.start('Analyze dependencies');
|
||||||
|
|
||||||
const map = {} as DepsMap;
|
const map = {} as DepsMap;
|
||||||
|
|
||||||
|
await copy(SRC_DIR, TEMP_DIR);
|
||||||
|
await compileTempDir(TEMP_DIR);
|
||||||
|
|
||||||
components.filter(checkStyleExists).forEach(component => {
|
components.filter(checkStyleExists).forEach(component => {
|
||||||
map[component] = analyzeDeps(component);
|
map[component] = analyzeDeps(component);
|
||||||
});
|
});
|
||||||
@ -121,4 +173,6 @@ export function genStyleDepsMap() {
|
|||||||
STYPE_DEPS_JSON_FILE,
|
STYPE_DEPS_JSON_FILE,
|
||||||
JSON.stringify({ map, sequence }, null, 2)
|
JSON.stringify({ map, sequence }, null, 2)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
logger.success('Analyze dependencies');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user