-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathgenerate-local.js
executable file
·105 lines (81 loc) · 2.74 KB
/
generate-local.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/env node
import chalk from 'chalk';
import commandExists from 'command-exists';
import execa from 'execa';
import fsExtra from 'fs-extra';
import path from 'path';
const { copyFileSync, ensureFileSync, existsSync, removeSync } = fsExtra;
const docsPath = '../ember-api-docs-data';
import { program, Option, InvalidArgumentError } from 'commander';
function exit() {
console.log(...arguments);
process.exit(1);
}
function semverVersion(value) {
if (!/^\d+\.\d+\.\d+$/.test(value)) {
throw new InvalidArgumentError('Not a correctly defined semver version i.e. major.minor.patch');
}
return value;
}
program
.addOption(
new Option('-p, --project <project>', 'the project that you want to run this for')
.choices(['ember', 'ember-data'])
.makeOptionMandatory(),
)
.requiredOption('-v, --version <version>', 'project version', semverVersion);
program.parse();
const options = program.opts();
const { project, version } = options;
async function runCmd(cmd, path, args = []) {
console.log(chalk.underline(`Running '${chalk.green(cmd)}' in ${path}`));
const executedCmd = await execa(cmd, args, { cwd: path, shell: true, stdio: 'inherit' });
if (executedCmd.failed) {
console.error(executedCmd.stdout);
console.error(executedCmd.stderr);
process.exit(1);
}
console.log(executedCmd.stdout + '\n');
}
try {
await commandExists('pnpm');
} catch (e) {
exit(chalk.red('We need pnpm installed globally for this script to work'));
}
let emberProjectPath = path.join('../', 'ember.js');
let emberDataProjectPath = path.join('../', 'data');
let checkIfProjectDirExists = dirPath => {
if (!existsSync(dirPath)) {
exit(chalk.yellow(`Please checkout the ${project} project at ${dirPath}`));
}
};
let buildDocs = async projDirPath => {
checkIfProjectDirExists(projDirPath);
if (project === 'ember') {
await runCmd('corepack', projDirPath, ['pnpm', 'install']);
} else {
await runCmd('corepack', projDirPath, ['pnpm', 'install']);
}
await runCmd(
project === 'ember' ? 'corepack pnpm run docs' : 'corepack pnpm run build:docs',
projDirPath,
);
let destination = `${docsPath}/s3-docs/v${version}/${project}-docs.json`;
ensureFileSync(destination);
const projYuiDocFile = destination;
removeSync(projYuiDocFile);
removeSync(`${docsPath}/json-docs/${project}/${version}`);
const yuiDocFile = path.join(
projDirPath,
project === 'ember' ? 'docs/data.json' : 'packages/-ember-data/dist/docs/data.json',
);
copyFileSync(yuiDocFile, projYuiDocFile);
};
let dirMap = {
ember: emberProjectPath,
'ember-data': emberDataProjectPath,
};
await buildDocs(dirMap[project]);
await execa('pnpm', ['run', 'start', '--projects', project, '--version', version], {
stdio: 'inherit',
});