forked from alibaba/lowcode-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-demo-project
More file actions
executable file
·55 lines (47 loc) · 1.57 KB
/
run-demo-project
File metadata and controls
executable file
·55 lines (47 loc) · 1.57 KB
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
#!/usr/bin/env node
// @ts-check
const program = require('commander');
const { spawnSync } = require('child_process');
const glob = require('glob');
const fs = require('fs');
const path = require('path');
const _ = require('lodash');
program
.option('--npm <npm>', 'specify the npm command location or alias')
.arguments('<project>')
.action((project, options) => {
try {
if (!fs.existsSync(project)) {
throw new Error(`Project ${project} does not exist`);
}
const getProjectActualPath = [
() => path.resolve(process.cwd(), project),
() =>
path.resolve(
process.cwd(),
path.join(
project,
path.dirname(glob.sync('*/package.json', { cwd: project })[0] || ''),
),
),
]
.map((x) => _.memoize(x))
.find((x) => fs.existsSync(path.join(x(), 'package.json')));
if (!getProjectActualPath) {
throw new Error(`Project ${project} is not a valid project(no package.json)`);
}
const projectActualPath = getProjectActualPath();
if (path.resolve(process.cwd(), project) !== projectActualPath) {
console.log('Changing directory to', path.relative(process.cwd(), projectActualPath));
}
process.chdir(projectActualPath);
const npm = options.npm || 'npm';
const cmd = `${npm} install && ${npm} start`;
console.log('# %s', cmd);
spawnSync(cmd, { stdio: 'inherit', shell: true });
} catch (err) {
console.log(err);
process.exit(1);
}
});
program.parse(process.argv);