@@ -50,12 +50,12 @@ module.exports.getConfig = async() => {
50
50
/**
51
51
* Initializes a config for the tool by copying an example config
52
52
*
53
- * @param {string } example - name of the example to base the config on
53
+ * @param {string } [ example] - name of the example to base the config on
54
54
* @param {Object } [options] - any options required
55
55
* @param {boolean } [options.global] - if true, the config will be placed in the current users home directory
56
56
* @returns {Promise<void> } - When complete
57
57
*/
58
- module . exports . initialize = async function ( example , options = { } ) {
58
+ module . exports . initialize = async function ( example = false , options = { } ) {
59
59
const exampleDir = `${ __dirname } /../../example-configs` ;
60
60
let path ;
61
61
@@ -73,14 +73,29 @@ module.exports.initialize = async function(example, options = {}) {
73
73
throw new Error ( 'Config file already exists. Please remove it if you\'d like to initialize a new config.' ) ;
74
74
}
75
75
76
- // check to see if theres an example for the example name the user passed
77
- const examples = fs . readdirSync ( exampleDir )
78
- . map ( ( filename ) => _ . replace ( filename , '.json' , '' ) ) ;
79
76
80
- if ( ! examples . includes ( example ) ) {
81
- throw new Error ( `An example by that name does not exist. Possible examples are: ${ examples . join ( ', ' ) } ` ) ;
77
+
78
+ // no example provided
79
+ if ( ! example ) {
80
+
81
+ // lets just make a blank config file
82
+ fs . writeFileSync ( path , '{\n\n}' ) ;
83
+
84
+ // if we want to use an example
85
+ } else {
86
+
87
+ // check to see if theres an example for the example name the user passed
88
+ const examples = fs . readdirSync ( exampleDir )
89
+ . map ( ( filename ) => _ . replace ( filename , '.json' , '' ) ) ;
90
+
91
+ if ( examples . includes ( example ) ) {
92
+
93
+ // copy the example to the desired location
94
+ fs . copyFileSync ( `${ exampleDir } /${ example } .json` , path ) ;
95
+ } else {
96
+ throw new Error ( `An example by that name does not exist. Possible examples are: ${ examples . join ( ', ' ) } ` ) ;
97
+ }
82
98
}
83
99
84
- // copy the example to the desired location
85
- fs . copyFileSync ( `${ exampleDir } /${ example } .json` , path ) ;
100
+
86
101
} ;
0 commit comments