mirror of
https://github.com/youzan/vant.git
synced 2025-12-25 02:02:01 +08:00
feat(cli): install dependencies before build
This commit is contained in:
@@ -51,7 +51,7 @@
|
||||
"@babel/preset-typescript": "^7.7.4",
|
||||
"@nuxt/friendly-errors-webpack-plugin": "^2.5.0",
|
||||
"@types/jest": "^24.0.23",
|
||||
"@vant/eslint-config": "^1.5.0",
|
||||
"@vant/eslint-config": "^1.5.1",
|
||||
"@vant/markdown-loader": "^2.3.0",
|
||||
"@vant/markdown-vetur": "^1.0.0",
|
||||
"@vant/stylelint-config": "^1.1.0",
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -1632,10 +1632,10 @@
|
||||
semver "^6.3.0"
|
||||
tsutils "^3.17.1"
|
||||
|
||||
"@vant/eslint-config@^1.5.0":
|
||||
version "1.5.0"
|
||||
resolved "https://registry.yarnpkg.com/@vant/eslint-config/-/eslint-config-1.5.0.tgz#05d9b2e78d41d570fa411ec82ff0e09996ea69fd"
|
||||
integrity sha512-TO0ab7zsZCq3NPFtjND4BBFBLuzB3sQcgqBk56K9NEMc83xjp6f3wGdUXdYtYqkPtXVx7U1QyLNkDUACMILgRQ==
|
||||
"@vant/eslint-config@^1.5.1":
|
||||
version "1.5.1"
|
||||
resolved "https://registry.yarnpkg.com/@vant/eslint-config/-/eslint-config-1.5.1.tgz#cfa4418b0b43ca0afb7dbda6973b2b1450306fb2"
|
||||
integrity sha512-jGN4GJw+MYeXGH9XsYeaWJMpD8TwS1fx4qw4kGXoud8VM6tMdUToxodzJRERoHlDgnpxsqwd4bOf1aztoVuuHg==
|
||||
dependencies:
|
||||
"@typescript-eslint/eslint-plugin" "^2.12.0"
|
||||
"@typescript-eslint/parser" "^2.12.0"
|
||||
|
||||
Reference in New Issue
Block a user