refactor(@vant/cli): migrate to ESM package

This commit is contained in:
chenjiahan
2021-10-28 20:09:00 +08:00
committed by neverland
parent eec2ac4c0f
commit 1b45f38133
50 changed files with 255 additions and 196 deletions
+5 -5
View File
@@ -1,10 +1,10 @@
import { emptyDir } from 'fs-extra';
import { setNodeEnv } from '../common';
import { compileSite } from '../compiler/compile-site';
import { SITE_DIST_DIR } from '../common/constant';
import fse from 'fs-extra';
import { setNodeEnv } from '../common/index.js';
import { compileSite } from '../compiler/compile-site.js';
import { SITE_DIST_DIR } from '../common/constant.js';
export async function buildSite() {
setNodeEnv('production');
await emptyDir(SITE_DIST_DIR);
await fse.emptyDir(SITE_DIST_DIR);
await compileSite(true);
}
+18 -16
View File
@@ -1,20 +1,20 @@
import execa from 'execa';
import { join, relative } from 'path';
import { remove, copy, readdir, existsSync } from 'fs-extra';
import { clean } from './clean';
import { CSS_LANG } from '../common/css';
import { ora, consola } from '../common/logger';
import { installDependencies } from '../common/manager';
import { compileSfc } from '../compiler/compile-sfc';
import { compileStyle } from '../compiler/compile-style';
import { compileScript } from '../compiler/compile-script';
import { compilePackage } from '../compiler/compile-package';
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 { genPackageStyle } from '../compiler/gen-package-style';
import { genVeturConfig } from '../compiler/gen-vetur-config';
import fse from 'fs-extra';
import { clean } from './clean.js';
import { CSS_LANG } from '../common/css.js';
import { ora, consola } from '../common/logger.js';
import { installDependencies } from '../common/manager.js';
import { compileSfc } from '../compiler/compile-sfc.js';
import { compileStyle } from '../compiler/compile-style.js';
import { compileScript } from '../compiler/compile-script.js';
import { compilePackage } from '../compiler/compile-package.js';
import { genPackageEntry } from '../compiler/gen-package-entry.js';
import { genStyleDepsMap } from '../compiler/gen-style-deps-map.js';
import { genComponentStyle } from '../compiler/gen-component-style.js';
import { SRC_DIR, LIB_DIR, ES_DIR } from '../common/constant.js';
import { genPackageStyle } from '../compiler/gen-package-style.js';
import { genVeturConfig } from '../compiler/gen-vetur-config.js';
import {
isDir,
isSfc,
@@ -26,7 +26,9 @@ import {
setNodeEnv,
setModuleEnv,
setBuildTarget,
} from '../common';
} from '../common/index.js';
const { remove, copy, readdir, existsSync } = fse;
async function compileFile(filePath: string) {
if (isScript(filePath)) {
+6 -4
View File
@@ -1,10 +1,12 @@
import { join } from 'path';
import { ROOT } from '../common/constant';
import { ora, slimPath } from '../common/logger';
import { createWriteStream, readFileSync } from 'fs-extra';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
import { ROOT } from '../common/constant.js';
import { ora, slimPath } from '../common/logger.js';
import { createWriteStream, readFileSync } from 'fs';
import conventionalChangelog from 'conventional-changelog';
const DIST_FILE = join(ROOT, './changelog.generated.md');
const __dirname = dirname(fileURLToPath(import.meta.url));
const MAIN_TEMPLATE = join(__dirname, '../../template/changelog-main.hbs');
const HEADER_TEMPLATE = join(__dirname, '../../template/changelog-header.hbs');
const COMMIT_TEMPLATE = join(__dirname, '../../template/changelog-commit.hbs');
+4 -2
View File
@@ -1,11 +1,13 @@
import { remove } from 'fs-extra';
import fse from 'fs-extra';
import {
ES_DIR,
LIB_DIR,
DIST_DIR,
VETUR_DIR,
SITE_DIST_DIR,
} from '../common/constant';
} from '../common/constant.js';
const { remove } = fse;
export async function clean() {
await Promise.all([
@@ -1,7 +1,8 @@
import { readFileSync } from 'fs-extra';
import { consola } from '../common/logger';
import { readFileSync } from 'fs';
import { consola } from '../common/logger.js';
const commitRE = /^(revert: )?(fix|feat|docs|perf|test|types|style|build|chore|release|refactor|breaking change)(\(.+\))?: .{1,50}/;
const commitRE =
/^(revert: )?(fix|feat|docs|perf|test|types|style|build|chore|release|refactor|breaking change)(\(.+\))?: .{1,50}/;
const mergeRE = /Merge /;
export function commitLint(gitParams: string) {
+2 -2
View File
@@ -1,5 +1,5 @@
import { setNodeEnv } from '../common';
import { compileSite } from '../compiler/compile-site';
import { setNodeEnv } from '../common/index.js';
import { compileSite } from '../compiler/compile-site.js';
export async function dev() {
setNodeEnv('development');
+12 -7
View File
@@ -1,7 +1,11 @@
import { runCLI } from 'jest';
import { setNodeEnv } from '../common';
import { genPackageEntry } from '../compiler/gen-package-entry';
import { ROOT, JEST_CONFIG_FILE, PACKAGE_ENTRY_FILE } from '../common/constant';
import jest from 'jest';
import { setNodeEnv } from '../common/index.js';
import { genPackageEntry } from '../compiler/gen-package-entry.js';
import {
ROOT,
JEST_CONFIG_FILE,
PACKAGE_ENTRY_FILE,
} from '../common/constant.js';
export function test(command: any) {
setNodeEnv('test');
@@ -13,18 +17,19 @@ export function test(command: any) {
const config = {
rootDir: ROOT,
watch: command.watch,
debug: command.debug,
config: JEST_CONFIG_FILE,
runInBand: command.runInBand,
clearCache: command.clearCache,
changedSince: command.changedSince,
logHeapUsage: command.logHeapUsage,
runInBand: command.runInBand,
debug: command.debug,
// make jest tests faster
// see: https://ivantanev.com/make-jest-faster/
maxWorkers: '50%',
} as any;
runCLI(config, [ROOT])
jest
.runCLI(config, [ROOT])
.then((response) => {
if (!response.results.success && !command.watch) {
process.exit(1);
+2 -2
View File
@@ -1,6 +1,6 @@
import execa from 'execa';
import { consola, ora } from '../common/logger';
import { SCRIPT_EXTS } from '../common/constant';
import { consola, ora } from '../common/logger.js';
import { SCRIPT_EXTS } from '../common/constant.js';
type RunCommandMessages = {
start: string;
+3 -1
View File
@@ -1,7 +1,9 @@
/* eslint-disable no-template-curly-in-string */
import releaseIt from 'release-it';
import { join } from 'path';
import { join, dirname } from 'path';
import { fileURLToPath } from 'url';
const __dirname = dirname(fileURLToPath(import.meta.url));
const PLUGIN_PATH = join(__dirname, '../compiler/vant-cli-release-plugin.js');
export async function release(command: { tag?: string }) {