2
2
'use strict' ;
3
3
4
4
/* eslint-disable no-console */
5
- const fs = require ( 'fs-extra' ) ;
5
+ const exec = require ( 'child_process' ) . exec ;
6
+ const fs = require ( 'fs' ) ;
6
7
const path = require ( 'path' ) ;
8
+ const temp = require ( 'temp' ) ;
7
9
const util = require ( 'util' ) ;
8
- const exec = require ( 'child_process' ) . exec ;
9
10
const version = require ( '../../package.json' ) . version ;
10
11
11
- const documentationPath = './ docs/documentation';
12
- const outputPath = '/tmp/documentation/' ;
12
+ const documentationPath = path . join ( __dirname , '../../ docs/documentation') ;
13
+ const outputPath = temp . mkdirSync ( 'angular-cli-docs' ) ;
13
14
14
- function createTempDirectory ( ) {
15
- return new Promise ( ( resolve , reject ) => {
16
- fs . emptyDir ( outputPath , ( error ) => {
17
- if ( error ) {
18
- reject ( error ) ;
19
- }
20
- resolve ( ) ;
21
- } )
22
- } ) ;
23
- }
24
15
25
16
function execute ( command ) {
26
17
return new Promise ( ( resolve , reject ) => {
@@ -33,10 +24,6 @@ function execute(command) {
33
24
} ) ;
34
25
}
35
26
36
- function gitClone ( url , directory ) {
37
- return execute ( util . format ( 'git clone %s %s' , url , directory ) ) ;
38
- }
39
-
40
27
function readFiles ( directory , filelist ) {
41
28
if ( directory [ directory . length - 1 ] != '/' ) {
42
29
directory = directory . concat ( '/' ) ;
@@ -76,7 +63,7 @@ function copyFile(from, to, linksToReplace) {
76
63
const r = new RegExp ( str , 'gi' ) ;
77
64
fileData = fileData . replace ( r , link . newName ) ;
78
65
} ) ;
79
- fs . outputFile ( to , fileData , ( error2 ) => {
66
+ fs . writeFile ( to , fileData , ( error2 ) => {
80
67
if ( error2 ) {
81
68
reject ( error2 ) ;
82
69
}
@@ -89,7 +76,9 @@ function copyFile(from, to, linksToReplace) {
89
76
function createFiles ( ) {
90
77
const files = readFiles ( documentationPath ) || [ ] ;
91
78
const linksToReplace = checkNameLinks ( files ) ;
92
- const copies = files . map ( ( { originalPath, newPath } ) => copyFile ( originalPath , newPath , linksToReplace ) ) ;
79
+ const copies = files . map ( ( { originalPath, newPath } ) => {
80
+ return copyFile ( originalPath , newPath , linksToReplace )
81
+ } ) ;
93
82
return Promise . all ( copies ) ;
94
83
}
95
84
@@ -107,19 +96,17 @@ function checkNameLinks(files) {
107
96
} , [ ] ) ;
108
97
}
109
98
110
- ( function ( ) {
111
- Promise . resolve ( )
112
- . then ( ( ) => createTempDirectory ( ) )
113
- . then ( ( ) => gitClone ( 'https://github.com/angular/angular-cli.wiki' , outputPath ) )
114
- . then ( ( ) => createFiles ( ) )
115
- . then ( ( ) => process . chdir ( outputPath ) )
116
- . then ( ( ) => execute ( 'git add .' ) )
117
- . then ( ( ) => execute ( `git commit -m ${ version } ` ) )
118
- . then ( ( ) => execute ( 'git status' ) )
119
- . then ( ( data ) => {
120
- console . log ( data ) ;
121
- } )
122
- . catch ( ( error ) => {
123
- console . log ( 'error' , error ) ;
124
- } )
125
- } ) ( ) ;
99
+ Promise . resolve ( )
100
+ . then ( ( ) => console . log ( `Documentation Path: ${ documentationPath } ` ) )
101
+ . then ( ( ) => console . log ( `Wiki path: ${ outputPath } ` ) )
102
+ . then ( ( ) => console . log ( 'Cloning...' ) )
103
+ . then ( ( ) => execute ( `git clone "https://github.com/angular/angular-cli.wiki" ${ outputPath } ` ) )
104
+ . then ( ( ) => console . log ( 'Copying Files...' ) )
105
+ . then ( ( ) => createFiles ( ) )
106
+ . then ( ( ) => process . chdir ( outputPath ) )
107
+ . then ( ( ) => console . log ( 'Committing...' ) )
108
+ . then ( ( ) => execute ( 'git add .' ) )
109
+ . then ( ( ) => execute ( `git commit -m "${ version } "` ) )
110
+ . then ( ( ) => execute ( 'git push' ) )
111
+ . then ( ( ) => console . log ( 'Done...' ) )
112
+ . catch ( err => console . error ( `Error:\n${ err . message } ` ) ) ;
0 commit comments