@@ -50,12 +50,12 @@ module.exports.getConfig = async() => {
5050/**
5151 * Initializes a config for the tool by copying an example config
5252 *
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
5454 * @param {Object } [options] - any options required
5555 * @param {boolean } [options.global] - if true, the config will be placed in the current users home directory
5656 * @returns {Promise<void> } - When complete
5757 */
58- module . exports . initialize = async function ( example , options = { } ) {
58+ module . exports . initialize = async function ( example = false , options = { } ) {
5959 const exampleDir = `${ __dirname } /../../example-configs` ;
6060 let path ;
6161
@@ -73,14 +73,29 @@ module.exports.initialize = async function(example, options = {}) {
7373 throw new Error ( 'Config file already exists. Please remove it if you\'d like to initialize a new config.' ) ;
7474 }
7575
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' , '' ) ) ;
7976
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+ }
8298 }
8399
84- // copy the example to the desired location
85- fs . copyFileSync ( `${ exampleDir } /${ example } .json` , path ) ;
100+
86101} ;
0 commit comments