mirror of
https://github.com/youzan/vant.git
synced 2025-10-20 10:44:59 +00:00
feat(cli): support build types (#8264)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import execa from 'execa';
|
||||
import chokidar from 'chokidar';
|
||||
import { join, relative } from 'path';
|
||||
import { remove, copy, readdirSync } from 'fs-extra';
|
||||
import { remove, copy, readdirSync, existsSync } from 'fs-extra';
|
||||
import { clean } from './clean';
|
||||
import { CSS_LANG } from '../common/css';
|
||||
import { ora, consola, slimPath } from '../common/logger';
|
||||
@@ -63,50 +64,58 @@ async function compileDir(dir: string) {
|
||||
);
|
||||
}
|
||||
|
||||
async function buildEs() {
|
||||
async function copySourceCode() {
|
||||
await copy(SRC_DIR, ES_DIR);
|
||||
await copy(SRC_DIR, LIB_DIR);
|
||||
}
|
||||
|
||||
async function buildESMOutputs() {
|
||||
setModuleEnv('esmodule');
|
||||
setBuildTarget('package');
|
||||
await copy(SRC_DIR, ES_DIR);
|
||||
await compileDir(ES_DIR);
|
||||
}
|
||||
|
||||
async function buildLib() {
|
||||
async function buildCJSOutputs() {
|
||||
setModuleEnv('commonjs');
|
||||
setBuildTarget('package');
|
||||
await copy(SRC_DIR, LIB_DIR);
|
||||
await compileDir(LIB_DIR);
|
||||
}
|
||||
|
||||
async function buildTypeDeclarations() {
|
||||
const tsConfig = join(process.cwd(), 'tsconfig.declaration.json');
|
||||
|
||||
if (existsSync(tsConfig)) {
|
||||
await execa('tsc', ['-p', tsConfig]);
|
||||
}
|
||||
}
|
||||
|
||||
async function buildStyleEntry() {
|
||||
await genStyleDepsMap();
|
||||
genComponentStyle();
|
||||
}
|
||||
|
||||
async function buildPackageEntry() {
|
||||
async function buildPackageScriptEntry() {
|
||||
const esEntryFile = join(ES_DIR, 'index.js');
|
||||
const libEntryFile = join(LIB_DIR, 'index.js');
|
||||
const styleEntryFile = join(LIB_DIR, `index.${CSS_LANG}`);
|
||||
|
||||
genPackageEntry({
|
||||
outputPath: esEntryFile,
|
||||
pathResolver: (path: string) => `./${relative(SRC_DIR, path)}`,
|
||||
});
|
||||
|
||||
setModuleEnv('esmodule');
|
||||
await compileJs(esEntryFile);
|
||||
await copy(esEntryFile, libEntryFile);
|
||||
}
|
||||
|
||||
async function buildPackageStyleEntry() {
|
||||
const styleEntryFile = join(LIB_DIR, `index.${CSS_LANG}`);
|
||||
|
||||
genPackageStyle({
|
||||
outputPath: styleEntryFile,
|
||||
pathResolver: (path: string) => path.replace(SRC_DIR, '.'),
|
||||
});
|
||||
|
||||
setModuleEnv('commonjs');
|
||||
await copy(esEntryFile, libEntryFile);
|
||||
await compileJs(libEntryFile);
|
||||
await compileStyle(styleEntryFile);
|
||||
}
|
||||
|
||||
async function buildPackages() {
|
||||
async function buildBundledOutputs() {
|
||||
setModuleEnv('esmodule');
|
||||
await compilePackage(false);
|
||||
await compilePackage(true);
|
||||
@@ -115,24 +124,36 @@ async function buildPackages() {
|
||||
|
||||
const tasks = [
|
||||
{
|
||||
text: 'Build ESModule Outputs',
|
||||
task: buildEs,
|
||||
text: 'Copy Source Code',
|
||||
task: copySourceCode,
|
||||
},
|
||||
{
|
||||
text: 'Build Commonjs Outputs',
|
||||
task: buildLib,
|
||||
text: 'Build Package Script Entry',
|
||||
task: buildPackageScriptEntry,
|
||||
},
|
||||
{
|
||||
text: 'Build Style Entry',
|
||||
text: 'Build Component Style Entry',
|
||||
task: buildStyleEntry,
|
||||
},
|
||||
{
|
||||
text: 'Build Package Entry',
|
||||
task: buildPackageEntry,
|
||||
text: 'Build Package Style Entry',
|
||||
task: buildPackageStyleEntry,
|
||||
},
|
||||
{
|
||||
text: 'Build Packed Outputs',
|
||||
task: buildPackages,
|
||||
text: 'Build Type Declarations',
|
||||
task: buildTypeDeclarations,
|
||||
},
|
||||
{
|
||||
text: 'Build ESModule Outputs',
|
||||
task: buildESMOutputs,
|
||||
},
|
||||
{
|
||||
text: 'Build CommonJS Outputs',
|
||||
task: buildCJSOutputs,
|
||||
},
|
||||
{
|
||||
text: 'Build Bundled Outputs',
|
||||
task: buildBundledOutputs,
|
||||
},
|
||||
];
|
||||
|
||||
|
Reference in New Issue
Block a user