chore(cli): improve build tasks

This commit is contained in:
陈嘉涵
2020-01-15 14:50:04 +08:00
parent 6104ecb352
commit ed51b08011
3 changed files with 114 additions and 123 deletions
-16
View File
@@ -1,5 +1,4 @@
import { join } from 'path';
import { execSync } from 'child_process';
import {
lstatSync,
existsSync,
@@ -156,19 +155,4 @@ 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 { getVantConfig };
+36
View File
@@ -0,0 +1,36 @@
// @ts-ignore
import execa from 'execa';
import { consola } from './logger';
import { execSync } from 'child_process';
let hasYarnCache: boolean;
export function hasYarn() {
if (hasYarnCache === undefined) {
try {
execSync('yarn --version', { stdio: 'ignore' });
hasYarnCache = true;
} catch (e) {
hasYarnCache = false;
}
}
return hasYarnCache;
}
export async function installDependencies() {
consola.info('Install Dependencies\n');
try {
const manager = hasYarn() ? 'yarn' : 'npm';
await execa(manager, ['install', '--prod=false'], {
stdio: 'inherit'
});
console.log('');
} catch (err) {
console.log(err);
throw err;
}
}