@@ -13,6 +13,7 @@ import * as os from 'os';
13
13
import * as path from 'path' ;
14
14
import { packages } from '../lib/packages' ;
15
15
import build from './build' ;
16
+ import create from './create' ;
16
17
17
18
18
19
function _copy ( from : string , to : string ) {
@@ -33,17 +34,17 @@ function _copy(from: string, to: string) {
33
34
34
35
35
36
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
+ } ) ;
37
41
38
42
if ( status != 0 ) {
39
43
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
- }
45
44
throw error ;
46
45
}
46
+
47
+ return stdout . toString ( 'utf-8' ) ;
47
48
}
48
49
49
50
@@ -69,17 +70,44 @@ export default async function(opts: SnapshotsOptions, logger: logging.Logger) {
69
70
|| ''
70
71
) . trim ( ) ;
71
72
72
- logger . info ( 'Setting up global git name.' ) ;
73
73
if ( githubToken ) {
74
+ logger . info ( 'Setting up global git name.' ) ;
74
75
_exec ( 'git' , [ 'config' , '--global' , 'user.email' , '[email protected] ' ] , { } , logger ) ;
75
76
_exec ( 'git' , [ 'config' , '--global' , 'user.name' , 'Angular Builds' ] , { } , logger ) ;
76
77
_exec ( 'git' , [ 'config' , '--global' , 'push.default' , 'simple' ] , { } , logger ) ;
77
78
}
78
79
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
+
79
87
// Run build.
80
88
logger . info ( 'Building...' ) ;
81
89
await build ( { snapshot : true } , logger . createChild ( 'build' ) ) ;
82
90
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
+
83
111
for ( const packageName of Object . keys ( packages ) ) {
84
112
const pkg = packages [ packageName ] ;
85
113
@@ -119,4 +147,6 @@ export default async function(opts: SnapshotsOptions, logger: logging.Logger) {
119
147
_exec ( 'git' , [ 'push' , 'origin' ] , { cwd : destPath } , publishLogger ) ;
120
148
_exec ( 'git' , [ 'push' , '--tags' , 'origin' ] , { cwd : destPath } , publishLogger ) ;
121
149
}
150
+
151
+ return 0 ;
122
152
}
0 commit comments