Skip to content

Commit c2f9e0b

Browse files
committed
ci: generate and publish all commands help in JSON format
1 parent d417fa9 commit c2f9e0b

File tree

1 file changed

+37
-7
lines changed

1 file changed

+37
-7
lines changed

scripts/snapshots.ts

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import * as os from 'os';
1313
import * as path from 'path';
1414
import { packages } from '../lib/packages';
1515
import build from './build';
16+
import create from './create';
1617

1718

1819
function _copy(from: string, to: string) {
@@ -33,17 +34,17 @@ function _copy(from: string, to: string) {
3334

3435

3536
function _exec(command: string, args: string[], opts: { cwd?: string }, logger: logging.Logger) {
36-
const { status, error, stderr } = spawnSync(command, args, { ...opts });
37+
const { status, error, stdout } = spawnSync(command, args, {
38+
stdio: ['ignore', 'pipe', 'inherit'],
39+
...opts,
40+
});
3741

3842
if (status != 0) {
3943
logger.error(`Command failed: ${command} ${args.map(x => JSON.stringify(x)).join(', ')}`);
40-
if (error) {
41-
logger.error('Error: ' + (error ? error.message : 'undefined'));
42-
} else {
43-
logger.error(`STDERR:\n${stderr}`);
44-
}
4544
throw error;
4645
}
46+
47+
return stdout.toString('utf-8');
4748
}
4849

4950

@@ -69,17 +70,44 @@ export default async function(opts: SnapshotsOptions, logger: logging.Logger) {
6970
|| ''
7071
).trim();
7172

72-
logger.info('Setting up global git name.');
7373
if (githubToken) {
74+
logger.info('Setting up global git name.');
7475
_exec('git', ['config', '--global', 'user.email', '[email protected]'], {}, logger);
7576
_exec('git', ['config', '--global', 'user.name', 'Angular Builds'], {}, logger);
7677
_exec('git', ['config', '--global', 'push.default', 'simple'], {}, logger);
7778
}
7879

80+
// Creating a new project and reading the help.
81+
logger.info('Creating temporary project...');
82+
const newProjectTempRoot = fs.mkdtempSync(path.join(os.tmpdir(), 'angular-cli-create-'));
83+
const newProjectName = 'help-project';
84+
const newProjectRoot = path.join(newProjectTempRoot, newProjectName);
85+
await create({ _: [newProjectName] }, logger.createChild('create'), newProjectTempRoot);
86+
7987
// Run build.
8088
logger.info('Building...');
8189
await build({ snapshot: true }, logger.createChild('build'));
8290

91+
logger.info('Gathering JSON Help...');
92+
const ngPath = path.join(newProjectRoot, 'node_modules/.bin/ng');
93+
const helpOutputRoot = path.join(packages['@angular/cli'].dist, 'help');
94+
fs.mkdirSync(helpOutputRoot);
95+
const commands = require('../packages/angular/cli/commands.json');
96+
for (const commandName of Object.keys(commands)) {
97+
const options = { cwd: newProjectRoot };
98+
const childLogger = logger.createChild(commandName);
99+
const stdout = _exec(ngPath, [commandName, '--help-json'], options, childLogger);
100+
if (stdout.trim()) {
101+
fs.writeFileSync(path.join(helpOutputRoot, commandName + '.json'), stdout);
102+
}
103+
}
104+
105+
if (!githubToken) {
106+
logger.info('No token given, skipping actual publishing...');
107+
108+
return 0;
109+
}
110+
83111
for (const packageName of Object.keys(packages)) {
84112
const pkg = packages[packageName];
85113

@@ -119,4 +147,6 @@ export default async function(opts: SnapshotsOptions, logger: logging.Logger) {
119147
_exec('git', ['push', 'origin'], { cwd: destPath }, publishLogger);
120148
_exec('git', ['push', '--tags', 'origin'], { cwd: destPath }, publishLogger);
121149
}
150+
151+
return 0;
122152
}

0 commit comments

Comments
 (0)