33 */
44const path = require ( 'path' ) ;
55const { cfx } = require ( '@squirrel-forge/node-cfx' ) ;
6- const { CliInput, Progress, Timer, leadingZeros, StatsDisplay, convertBytes } = require ( '@squirrel-forge/node-util' ) ;
6+ const { CliInput, Progress, Timer, leadingZeros, StatsDisplay, convertBytes, FsInterface } = require ( '@squirrel-forge/node-util' ) ;
77const SimpleWebpack = require ( './classes/SimpleWebpack' ) ;
88
99/**
@@ -59,6 +59,9 @@ module.exports = async function cli() {
5959 // Show config
6060 config : [ '-y' , '--show-config' , false , true ] ,
6161
62+ // Deploy defaults
63+ defaults : [ ' ' , '--defaults' , false , true ] ,
64+
6265 // Do not break on any error, disables the default strict if set
6366 loose : [ '-u' , '--loose' , false , true ] ,
6467
@@ -85,6 +88,39 @@ module.exports = async function cli() {
8588 process . exit ( 0 ) ;
8689 }
8790
91+ // Deploy default configs
92+ if ( options . defaults ) {
93+
94+ /**
95+ * Deploy default config
96+ * @param {string } name - Source name
97+ * @param {string } read - Target name
98+ * @return {Promise<void> } - May throw errors
99+ */
100+ const deployDefaultConfig = async ( name , read ) => {
101+ const data = require ( './' + read ) ;
102+ const resolved = path . resolve ( target , name ) ;
103+ const config_exists = await FsInterface . exists ( resolved ) ;
104+ if ( config_exists ) {
105+ cfx . error ( 'Config file already exists: ' + resolved ) ;
106+ } else {
107+ const wrote = await FsInterface . write ( resolved , JSON . stringify ( data , null , 2 ) ) ;
108+ if ( wrote ) {
109+ cfx . success ( 'Created defaults config: ' + resolved ) ;
110+ } else {
111+ cfx . error ( 'Failed to write config: ' + resolved ) ;
112+ }
113+ }
114+ } ;
115+
116+ // Deploy eslint
117+ await deployDefaultConfig ( '.eslintrc' , 'eslintrc.json' ) ;
118+
119+ // Deploy babel
120+ await deployDefaultConfig ( '.babelrc' , 'babelrc.json' ) ;
121+ process . exit ( 0 ) ;
122+ }
123+
88124 // Init application
89125 const swp = new SimpleWebpack ( cfx ) ;
90126 const swpOptions = { } ;
0 commit comments