1- const fs = require ( "fs" ) ;
2- const path = require ( " path" ) ;
3- const inquirer = require ( " inquirer" ) ;
4- const chalk = require ( " chalk" ) ;
1+ const fs = require ( 'fs' ) ;
2+ const path = require ( ' path' ) ;
3+ const inquirer = require ( ' inquirer' ) ;
4+ const chalk = require ( ' chalk' ) ;
55const prompt = inquirer . createPromptModule ( ) ;
6- const yaml = require ( " js-yaml" ) ;
7- const slugify = require ( " slugify" ) ;
6+ const yaml = require ( ' js-yaml' ) ;
7+ const slugify = require ( ' slugify' ) ;
88const { execSync } = require ( 'child_process' ) ;
99
10- const swaggerRepo = require ( " swagger-repo" ) ;
10+ const swaggerRepo = require ( ' swagger-repo' ) ;
1111
1212const {
1313 copy,
@@ -16,29 +16,28 @@ const {
1616 getGhPagesBaseUrl,
1717 validateSpecFileName,
1818 getCurrentGitHubRepo
19- } = require ( " ./lib/utils" ) ;
19+ } = require ( ' ./lib/utils' ) ;
2020
21- const { installDeps } = require ( " ./lib/install-deps" ) ;
21+ const { installDeps } = require ( ' ./lib/install-deps' ) ;
2222
23- const REDOCLY_RC = " .redoclyrc" ;
23+ const REDOCLY_RC = ' .redoclyrc' ;
2424
2525async function ask ( ) {
26- console . log ( " Welcome to the " + chalk . green ( " OpenAPI-Repo" ) + " generator!" ) ;
26+ console . log ( ' Welcome to the ' + chalk . green ( ' OpenAPI-Repo' ) + ' generator!' ) ;
2727
2828 const { haveSpec } = await prompt ( {
29- type : " confirm" ,
30- name : " haveSpec" ,
31- message : " Do you already have OpenAPI/Swagger spec for your API?" ,
29+ type : ' confirm' ,
30+ name : ' haveSpec' ,
31+ message : ' Do you already have OpenAPI/Swagger spec for your API?' ,
3232 default : false
3333 } ) ;
3434
3535 let specFileName ;
3636 if ( haveSpec ) {
3737 specFileName = ( await prompt ( {
38- type : "input" ,
39- name : "specFileName" ,
40- message :
41- "Please specify the path to the OpenAPI spec (local file):" ,
38+ type : 'input' ,
39+ name : 'specFileName' ,
40+ message : 'Please specify the path to the OpenAPI spec (local file):' ,
4241 validate ( fileName ) {
4342 return validateSpecFileName ( fileName ) ;
4443 }
@@ -47,58 +46,56 @@ async function ask() {
4746
4847 let spec ;
4948 if ( haveSpec ) {
50- spec = yaml . safeLoad ( fs . readFileSync ( specFileName , " utf8" ) ) ;
49+ spec = yaml . safeLoad ( fs . readFileSync ( specFileName , ' utf8' ) ) ;
5150 }
5251
5352 const { apiTitle } = await prompt ( {
54- type : " input" ,
55- name : " apiTitle" ,
56- message : " API Name:" ,
53+ type : ' input' ,
54+ name : ' apiTitle' ,
55+ message : ' API Name:' ,
5756 default : haveSpec ? spec . title : undefined ,
5857 validate : i => ( i . length > 0 ? true : `API Name can't be empty` )
5958 } ) ;
6059
6160 const { splitSpec } = await prompt ( {
62- type : " confirm" ,
63- name : " splitSpec" ,
61+ type : ' confirm' ,
62+ name : ' splitSpec' ,
6463 message : `Split spec into separate files: paths/*, definitions/* ${ chalk . yellow (
65- " [Experimental]"
64+ ' [Experimental]'
6665 ) } ?`,
6766 default : true
6867 } ) ;
6968
7069 const { codeSamples } = await prompt ( {
71- type : " confirm" ,
72- name : " codeSamples" ,
70+ type : ' confirm' ,
71+ name : ' codeSamples' ,
7372 message : `Prepare manual code samples folder?` ,
7473 default : true
7574 } ) ;
7675
7776 const { swaggerUI } = await prompt ( {
78- type : " confirm" ,
79- name : " swaggerUI" ,
77+ type : ' confirm' ,
78+ name : ' swaggerUI' ,
8079 message : `Install SwaggerUI?` ,
8180 default : false
8281 } ) ;
8382
8483 const { travis } = await prompt ( {
85- type : " confirm" ,
86- name : " travis" ,
84+ type : ' confirm' ,
85+ name : ' travis' ,
8786 message : `Set up Travis CI?` ,
8887 default : true
8988 } ) ;
9089
9190 let repo ;
9291 if ( travis ) {
9392 repo = ( await prompt ( {
94- type : "input" ,
95- name : "repo" ,
96- message : `Specify name of GitHub repo in format ${ chalk . blue (
97- "User/Repo"
98- ) } :`,
93+ type : 'input' ,
94+ name : 'repo' ,
95+ message : `Specify name of GitHub repo in format ${ chalk . blue ( 'User/Repo' ) } :` ,
9996 default : getCurrentGitHubRepo ,
10097 validate : function ( input ) {
101- return input . indexOf ( "/" ) > 0 ? true : 'Repo Name must contain "/"' ;
98+ return input . indexOf ( '/' ) > 0 ? true : 'Repo Name must contain "/"' ;
10299 }
103100 } ) ) . repo ;
104101 }
@@ -117,21 +114,20 @@ async function ask() {
117114function printSuccess ( opts , root ) {
118115 let travisNote = '' ;
119116 if ( opts . travis ) {
120- travisNote = `We generated ${ chalk . blue ( '.travis' ) } for you. Follow steps from ${ chalk . blue ( 'README.md' ) } to finish Travis CI setup`
117+ travisNote = `We generated ${ chalk . blue ( '.travis' ) } for you. Follow steps from ${ chalk . blue (
118+ 'README.md'
119+ ) } to finish Travis CI setup`;
121120 }
122121
123- console . log ( `${ chalk . green ( "Success!" ) } Created ${ chalk . green (
124- path . basename ( root )
125- ) } at ${ chalk . blue ( root ) }
122+ console . log (
123+ `${ chalk . green ( 'Success!' ) } Created ${ chalk . green ( path . basename ( root ) ) } at ${ chalk . blue ( root ) }
126124Inside that directory, you can run several commands:
127125
128126 ${ chalk . blue ( `npm start` ) }
129127 Starts the development server.
130128
131129 ${ chalk . blue ( `npm run build` ) }
132- Bundles the spec and prepares ${ chalk . blue (
133- "web_deploy"
134- ) } folder with static assets.
130+ Bundles the spec and prepares ${ chalk . blue ( 'web_deploy' ) } folder with static assets.
135131
136132 ${ chalk . blue ( `npm test` ) }
137133 Validates the spec.
@@ -141,30 +137,26 @@ Inside that directory, you can run several commands:
141137
142138We suggest that you begin by typing:
143139
144- ${ chalk . blue ( "cd" ) } ${ path . basename ( root ) }
145- ${ chalk . blue ( "npm start" ) } ` + ( travisNote ? '\n\n' + travisNote : '' ) ) ;
140+ ${ chalk . blue ( 'cd' ) } ${ path . basename ( root ) }
141+ ${ chalk . blue ( 'npm start' ) } ` + ( travisNote ? '\n\n' + travisNote : '' )
142+ ) ;
146143}
147144
148145async function run ( ) {
149146 const specRoot = process . argv [ 2 ] ;
150147
151148 if ( ! specRoot ) {
152149 console . log ( `Please specify the spec directory:
153- ${ chalk . blue ( " create-openapi-repo" ) } <spec-directory>
150+ ${ chalk . blue ( ' create-openapi-repo' ) } <spec-directory>
154151
155152For example:
156- ${ chalk . blue ( " create-openapi-repo" ) } my-spec` ) ;
153+ ${ chalk . blue ( ' create-openapi-repo' ) } my-spec` ) ;
157154
158155 process . exit ( 1 ) ;
159156 }
160157
161- if (
162- fs . existsSync ( specRoot ) &&
163- fs . existsSync ( path . join ( specRoot , REDOCLY_RC ) )
164- ) {
165- console . log ( `The directory ${ chalk . green (
166- specRoot
167- ) } already contains ${ chalk . green ( REDOCLY_RC ) }
158+ if ( fs . existsSync ( specRoot ) && fs . existsSync ( path . join ( specRoot , REDOCLY_RC ) ) ) {
159+ console . log ( `The directory ${ chalk . green ( specRoot ) } already contains ${ chalk . green ( REDOCLY_RC ) }
168160
169161Choose another directory or remove contents.
170162` ) ;
@@ -185,52 +177,50 @@ Choose another directory or remove contents.
185177
186178 let { specFileName } = opts ;
187179 if ( ! specFileName ) {
188- specFileName = require . resolve ( " openapi-template" ) ;
180+ specFileName = require . resolve ( ' openapi-template' ) ;
189181 }
190182
191183 process . chdir ( specRoot ) ;
192184
193- console . log (
194- `\nCreating a new OpenAPI repo in ${ chalk . blue ( path . resolve ( "." ) ) } \n`
195- ) ;
196- await copy ( ".gitignore" ) ;
197- await copy ( "LICENSE" ) ;
198- await render ( "package.json" , data ) ;
199- await render ( "README.md" , data ) ;
200- await copy ( "spec/README.md" ) ;
185+ console . log ( `\nCreating a new OpenAPI repo in ${ chalk . blue ( path . resolve ( '.' ) ) } \n` ) ;
186+ await copy ( '.gitignore' ) ;
187+ await copy ( 'LICENSE' ) ;
188+ await render ( 'package.json' , data ) ;
189+ await render ( 'README.md' , data ) ;
190+ await copy ( 'spec/README.md' ) ;
201191
202192 if ( opts . splitSpec ) {
203- copyDirSync ( " spec/definitions" ) ;
204- copyDirSync ( " spec/paths" ) ;
193+ copyDirSync ( ' spec/definitions' ) ;
194+ copyDirSync ( ' spec/paths' ) ;
205195 }
206196
207197 if ( opts . codeSamples ) {
208- copyDirSync ( " spec/code_samples" ) ;
198+ copyDirSync ( ' spec/code_samples' ) ;
209199 }
210200
211201 if ( opts . travis ) {
212- await copy ( " .travis.yml" ) ;
202+ await copy ( ' .travis.yml' ) ;
213203 }
214204
215- copyDirSync ( " web" ) ;
205+ copyDirSync ( ' web' ) ;
216206
217207 swaggerRepo . syncWithSpec ( fs . readFileSync ( specFileName ) . toString ( ) ) ;
218208
219209 fs . writeFileSync ( REDOCLY_RC , yaml . safeDump ( opts , { skipInvalid : true } ) ) ;
220210
221- console . log ( " Installing packages. This might take a couple of minutes.\n" ) ;
211+ console . log ( ' Installing packages. This might take a couple of minutes.\n' ) ;
222212
223213 await installDeps ( '@^2.0.0-rc.2' ) ;
224214 console . log ( ) ;
225215
226216 try {
227- execSync ( `git init` , { stdio : 'inherit' } ) ;
217+ execSync ( `git init` , { stdio : 'inherit' } ) ;
228218 execSync ( `git add . && git commit -m "Initial commit from create-openapi-repo"` ) ;
229- } catch ( e ) {
219+ } catch ( e ) {
230220 // skip error
231221 }
232222
233- printSuccess ( opts , path . resolve ( "." ) ) ;
223+ printSuccess ( opts , path . resolve ( '.' ) ) ;
234224}
235225
236226try {
0 commit comments