feat(cli): install dependencies before build
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// @ts-ignore
|
||||
import execa from 'execa';
|
||||
import { join, relative } from 'path';
|
||||
import { remove, copy, readdirSync } from 'fs-extra';
|
||||
import { clean } from './clean';
|
||||
@@ -20,11 +22,12 @@ import {
|
||||
isScript,
|
||||
isDemoDir,
|
||||
isTestDir,
|
||||
hasYarn,
|
||||
setNodeEnv,
|
||||
setModuleEnv
|
||||
} from '../common';
|
||||
|
||||
const stepper = getStepper(10);
|
||||
const stepper = getStepper(12);
|
||||
|
||||
async function compileDir(dir: string) {
|
||||
const files = readdirSync(dir);
|
||||
@@ -58,6 +61,23 @@ async function compileDir(dir: string) {
|
||||
);
|
||||
}
|
||||
|
||||
async function installDependencies() {
|
||||
stepper.start('Install Dependencies');
|
||||
|
||||
try {
|
||||
const manager = hasYarn() ? 'yarn' : 'npm';
|
||||
const installProcess = execa(manager, ['install']);
|
||||
|
||||
installProcess.stdout.pipe(process.stdout);
|
||||
await installProcess;
|
||||
|
||||
stepper.success('Install Dependencies');
|
||||
} catch (err) {
|
||||
stepper.error('Install Dependencies', err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
async function buildESModuleOutputs() {
|
||||
stepper.start('Build ESModule Outputs');
|
||||
|
||||
@@ -150,6 +170,7 @@ export async function build() {
|
||||
|
||||
try {
|
||||
await clean();
|
||||
await installDependencies();
|
||||
await buildESModuleOutputs();
|
||||
await buildCommonjsOutputs();
|
||||
await buildStyleEntry();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import decamelize from 'decamelize';
|
||||
import { join } from 'path';
|
||||
import { execSync } from 'child_process';
|
||||
import {
|
||||
lstatSync,
|
||||
existsSync,
|
||||
@@ -128,4 +129,19 @@ export function smartOutputFile(filePath: string, content: string) {
|
||||
outputFileSync(filePath, content);
|
||||
}
|
||||
|
||||
let hasYarnCache: boolean;
|
||||
|
||||
export function hasYarn() {
|
||||
if (hasYarnCache === undefined) {
|
||||
try {
|
||||
execSync('yarn --version', { stdio: 'ignore' });
|
||||
hasYarnCache = true;
|
||||
} catch (e) {
|
||||
hasYarnCache = false;
|
||||
}
|
||||
}
|
||||
|
||||
return hasYarnCache;
|
||||
}
|
||||
|
||||
export { decamelize, getVantConfig };
|
||||
|
||||
Reference in New Issue
Block a user