@@ -83,17 +83,20 @@ export default async ({
8383 let importExactDevDeps = ( [ ] as string [ ] ) . concat ( exactDevDeps ) ;
8484
8585 let packageJSON = await readRawPackageJson ( dir ) ;
86+ if ( ! packageJSON . version ) {
87+ warn ( interactive , chalk . yellow ( `Please set the ${ chalk . green ( '"version"' ) } in your application's package.json` ) ) ;
88+ }
8689 if ( packageJSON . config && packageJSON . config . forge ) {
8790 if ( packageJSON . config . forge . makers ) {
88- warn ( interactive , chalk . green ( 'It looks like this project is already configured for Electron Forge' ) ) ;
91+ warn ( interactive , chalk . green ( 'Existing Electron Forge configuration detected ' ) ) ;
8992 if ( typeof shouldContinueOnExisting === 'function' ) {
9093 if ( ! ( await shouldContinueOnExisting ( ) ) ) {
9194 // TODO: figure out if we can just return early here
9295 // eslint-disable-next-line no-process-exit
9396 process . exit ( 0 ) ;
9497 }
9598 }
96- } else if ( typeof packageJSON . config . forge === 'string' ) {
99+ } else if ( ! ( typeof packageJSON . config . forge === 'object' ) ) {
97100 warn (
98101 interactive ,
99102 chalk . yellow (
@@ -187,23 +190,23 @@ export default async ({
187190 await installDepList ( dir , importExactDevDeps , DepType . DEV , DepVersionRestriction . EXACT ) ;
188191 } ) ;
189192
190- packageJSON = await readRawPackageJson ( dir ) ;
191-
192- if ( ! packageJSON . version ) {
193- warn ( interactive , chalk . yellow ( 'Please set the "version" in your application\'s package.json' ) ) ;
194- }
195-
196- packageJSON . config = packageJSON . config || { } ;
197- const templatePackageJSON = await readRawPackageJson ( baseTemplate . templateDir ) ;
198- if ( packageJSON . config . forge ) {
199- if ( typeof packageJSON . config . forge !== 'string' ) {
200- packageJSON . config . forge = merge ( templatePackageJSON . config . forge , packageJSON . config . forge ) ;
193+ await asyncOra ( 'Copying base template Forge configuration' , async ( ) => {
194+ const pathToTemplateConfig = path . resolve ( baseTemplate . templateDir , 'forge.config.js' ) ;
195+
196+ // if there's an existing config.forge object in package.json
197+ if ( packageJSON ?. config ?. forge && typeof packageJSON . config . forge === 'object' ) {
198+ d ( 'detected existing Forge config in package.json, merging with base template Forge config' ) ;
199+ // eslint-disable-next-line @typescript-eslint/no-var-requires
200+ const templateConfig = require ( path . resolve ( baseTemplate . templateDir , 'forge.config.js' ) ) ;
201+ packageJSON = await readRawPackageJson ( dir ) ;
202+ merge ( templateConfig , packageJSON . config . forge ) ; // mutates the templateConfig object
203+ await writeChanges ( ) ;
204+ // otherwise, write to forge.config.js
205+ } else {
206+ d ( 'writing new forge.config.js' ) ;
207+ await fs . copyFile ( pathToTemplateConfig , path . resolve ( dir , 'forge.config.js' ) ) ;
201208 }
202- } else {
203- packageJSON . config . forge = templatePackageJSON . config . forge ;
204- }
205-
206- await writeChanges ( ) ;
209+ } ) ;
207210
208211 await asyncOra ( 'Fixing .gitignore' , async ( ) => {
209212 if ( await fs . pathExists ( path . resolve ( dir , '.gitignore' ) ) ) {
@@ -218,8 +221,8 @@ export default async ({
218221 interactive ,
219222 `
220223
221- We have ATTEMPTED to convert your app to be in a format that electron-forge understands.
224+ We have attempted to convert your app to be in a format that Electron Forge understands.
222225
223- Thanks for using ${ chalk . green ( 'Electron Forge' ) } !!! `
226+ Thanks for using ${ chalk . green ( 'Electron Forge' ) } !`
224227 ) ;
225228} ;
0 commit comments