@@ -83,17 +83,20 @@ export default async ({
83
83
let importExactDevDeps = ( [ ] as string [ ] ) . concat ( exactDevDeps ) ;
84
84
85
85
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
+ }
86
89
if ( packageJSON . config && packageJSON . config . forge ) {
87
90
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 ' ) ) ;
89
92
if ( typeof shouldContinueOnExisting === 'function' ) {
90
93
if ( ! ( await shouldContinueOnExisting ( ) ) ) {
91
94
// TODO: figure out if we can just return early here
92
95
// eslint-disable-next-line no-process-exit
93
96
process . exit ( 0 ) ;
94
97
}
95
98
}
96
- } else if ( typeof packageJSON . config . forge === 'string' ) {
99
+ } else if ( ! ( typeof packageJSON . config . forge === 'object' ) ) {
97
100
warn (
98
101
interactive ,
99
102
chalk . yellow (
@@ -187,23 +190,23 @@ export default async ({
187
190
await installDepList ( dir , importExactDevDeps , DepType . DEV , DepVersionRestriction . EXACT ) ;
188
191
} ) ;
189
192
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' ) ) ;
201
208
}
202
- } else {
203
- packageJSON . config . forge = templatePackageJSON . config . forge ;
204
- }
205
-
206
- await writeChanges ( ) ;
209
+ } ) ;
207
210
208
211
await asyncOra ( 'Fixing .gitignore' , async ( ) => {
209
212
if ( await fs . pathExists ( path . resolve ( dir , '.gitignore' ) ) ) {
@@ -218,8 +221,8 @@ export default async ({
218
221
interactive ,
219
222
`
220
223
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.
222
225
223
- Thanks for using ${ chalk . green ( 'Electron Forge' ) } !!! `
226
+ Thanks for using ${ chalk . green ( 'Electron Forge' ) } !`
224
227
) ;
225
228
} ;
0 commit comments