This repository has been archived by the owner on Nov 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
dev.js
62 lines (55 loc) · 1.54 KB
/
dev.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const { remove, existsSync } = require('fs-extra');
const { resolve } = require('path');
const { execSync } = require('child_process');
const chalk = require('chalk');
async function detectPackageManager() {
const { promisify } = require('util');
const { exec: defaultExec } = require('child_process');
const cwd = process.cwd();
const exec = promisify(defaultExec);
let pm = 'yarn';
try {
await exec(`${pm} -v`, { cwd });
} catch (_) {
pm = 'pnpm';
try {
await exec(`${pm} -v`, { cwd });
} catch (_ignore) {
pm = 'npm';
try {
await exec(`${pm} -v`, { cwd });
} catch (_) {
pm = undefined;
}
}
}
if (pm === undefined) {
console.log(chalk.red('No available package manager! (`yarn`, `pnpm` or `npm` is needed)'));
process.exit(1);
}
return pm;
}
async function dev() {
process.env.NODE_ENV = 'testing';
let example = 'with-javascript';
if (3 <= process.argv.length) {
const newExample = process.argv[2];
if (!existsSync(resolve(__dirname, `examples/${newExample}`))) {
console.log(chalk.red(`Not found examples/${newExample}`));
console.log('');
process.exit(1);
}
example = newExample;
}
await remove('workspace');
execSync('node ' + resolve(__dirname, 'bin/nuxtron') + ` init workspace --example ${example}`, {
cwd: __dirname,
stdio: 'inherit',
});
const pm = await detectPackageManager();
execSync(`${pm} install && ${pm} run dev`, {
cwd: resolve(__dirname, 'workspace'),
stdio: 'inherit',
});
}
dev();