1
- import { accessSync } from "fs"
2
1
import * as path from "path"
3
- import { DEFAULT_APP_DIR_NAME , installDependencies , log , getElectronVersion , readPackageJson } from "./util"
2
+ import { computeDefaultAppDirectory , installDependencies , log , getElectronVersion , readPackageJson , use , warn } from "./util"
4
3
import { all , executeFinally } from "./promise"
5
4
import { EventEmitter } from "events"
6
5
import { Promise as BluebirdPromise } from "bluebird"
7
6
import { InfoRetriever } from "./repositoryInfo"
8
7
import { AppMetadata , DevMetadata , Platform } from "./metadata"
9
- import { PackagerOptions , PlatformPackager , BuildInfo , ArtifactCreated , use } from "./platformPackager"
8
+ import { PackagerOptions , PlatformPackager , BuildInfo , ArtifactCreated } from "./platformPackager"
10
9
import MacPackager from "./macPackager"
11
10
import { WinPackager } from "./winPackager"
12
11
import * as errorMessages from "./errorMessages"
@@ -22,7 +21,7 @@ function addHandler(emitter: EventEmitter, event: string, handler: Function) {
22
21
23
22
export class Packager implements BuildInfo {
24
23
readonly projectDir : string
25
- readonly appDir : string
24
+ appDir : string
26
25
27
26
metadata : AppMetadata
28
27
devMetadata : DevMetadata
@@ -36,7 +35,9 @@ export class Packager implements BuildInfo {
36
35
//noinspection JSUnusedGlobalSymbols
37
36
constructor ( public options : PackagerOptions , public repositoryInfo : InfoRetriever = null ) {
38
37
this . projectDir = options . projectDir == null ? process . cwd ( ) : path . resolve ( options . projectDir )
39
- this . appDir = this . computeAppDirectory ( )
38
+ if ( this . appDir === this . projectDir ) {
39
+ this . isTwoPackageJsonProjectLayoutUsed = false
40
+ }
40
41
}
41
42
42
43
artifactCreated ( handler : ( event : ArtifactCreated ) => void ) : Packager {
@@ -50,12 +51,12 @@ export class Packager implements BuildInfo {
50
51
51
52
async build ( ) : Promise < any > {
52
53
const devPackageFile = this . devPackageFile
53
- const appPackageFile = this . projectDir === this . appDir ? devPackageFile : path . join ( this . appDir , "package.json" )
54
54
const platforms = this . options . platform
55
55
56
- const metadataList = await BluebirdPromise . map ( Array . from ( new Set ( [ devPackageFile , appPackageFile ] ) ) , readPackageJson )
57
- this . metadata = metadataList [ metadataList . length - 1 ]
58
- this . devMetadata = deepAssign ( metadataList [ 0 ] , this . options . devMetadata )
56
+ this . devMetadata = deepAssign ( await readPackageJson ( devPackageFile ) , this . options . devMetadata )
57
+ this . appDir = await computeDefaultAppDirectory ( this . projectDir , use ( this . devMetadata . directories , it => it . app ) || this . options . appDir )
58
+ const appPackageFile = this . projectDir === this . appDir ? devPackageFile : path . join ( this . appDir , "package.json" )
59
+ this . metadata = appPackageFile === devPackageFile ? this . devMetadata : await readPackageJson ( appPackageFile )
59
60
this . checkMetadata ( appPackageFile , devPackageFile , platforms )
60
61
61
62
this . electronVersion = await getElectronVersion ( this . devMetadata , devPackageFile )
@@ -110,31 +111,6 @@ export class Packager implements BuildInfo {
110
111
}
111
112
}
112
113
113
- // Auto-detect app/ (two package.json project layout (development and app)) or fallback to use working directory if not explicitly specified
114
- private computeAppDirectory ( ) : string {
115
- let customAppPath = this . options . appDir
116
- let required = true
117
- if ( customAppPath == null ) {
118
- customAppPath = DEFAULT_APP_DIR_NAME
119
- required = false
120
- }
121
-
122
- const absoluteAppPath = path . join ( this . projectDir , customAppPath )
123
- try {
124
- accessSync ( absoluteAppPath )
125
- }
126
- catch ( e ) {
127
- if ( required ) {
128
- throw new Error ( customAppPath + " doesn't exists, " + e . message )
129
- }
130
- else {
131
- this . isTwoPackageJsonProjectLayoutUsed = false
132
- return this . projectDir
133
- }
134
- }
135
- return absoluteAppPath
136
- }
137
-
138
114
private checkMetadata ( appPackageFile : string , devAppPackageFile : string , platforms : Array < Platform > ) : void {
139
115
const reportError = ( missedFieldName : string ) => {
140
116
throw new Error ( "Please specify '" + missedFieldName + "' in the application package.json ('" + appPackageFile + "')" )
@@ -156,10 +132,10 @@ export class Packager implements BuildInfo {
156
132
}
157
133
158
134
if ( this . devMetadata . homepage != null ) {
159
- console . warn ( "homepage in the development package.json is deprecated, please move to the application package.json" )
135
+ warn ( "homepage in the development package.json is deprecated, please move to the application package.json" )
160
136
}
161
137
if ( this . devMetadata . license != null ) {
162
- console . warn ( "license in the development package.json is deprecated, please move to the application package.json" )
138
+ warn ( "license in the development package.json is deprecated, please move to the application package.json" )
163
139
}
164
140
}
165
141
0 commit comments