@@ -7,6 +7,7 @@ const appdmg = require('appdmg');
7
7
const plist = require ( 'plist' ) ;
8
8
const Ora = require ( 'ora' ) ;
9
9
const execa = require ( 'execa' ) ;
10
+ const composeIcon = require ( './compose-icon' ) ;
10
11
11
12
if ( process . platform !== 'darwin' ) {
12
13
console . error ( 'macOS only' ) ;
@@ -56,94 +57,106 @@ try {
56
57
57
58
const appInfo = plist . parse ( infoPlist ) ;
58
59
const appName = appInfo . CFBundleDisplayName || appInfo . CFBundleName ;
59
- // ` const appIconName = appInfo.CFBundleIconFile.replace(/\.icns/, '');
60
+ const appIconName = appInfo . CFBundleIconFile . replace ( / \. i c n s / , '' ) ;
60
61
const dmgPath = path . join ( destPath , `${ appName } ${ appInfo . CFBundleShortVersionString } .dmg` ) ;
61
62
62
63
const ora = new Ora ( 'Creating DMG' ) ;
63
64
ora . start ( ) ;
64
65
65
- if ( cli . flags . overwrite ) {
66
- try {
67
- fs . unlinkSync ( dmgPath ) ;
68
- } catch ( _ ) { }
69
- }
70
-
71
- const ee = appdmg ( {
72
- target : dmgPath ,
73
- basepath : process . cwd ( ) ,
74
- specification : {
75
- title : appName ,
76
- // Disabled because of #16
77
- // icon: path.join(appPath, 'Contents/Resources', `${appIconName}.icns`),
78
- //
79
- // Use transparent background and `background-color` option when this is fixed:
80
- // https://github.com/LinusU/node-appdmg/issues/135
81
- background : path . join ( __dirname , 'assets/dmg-background.png' ) ,
82
- 'icon-size' : 160 ,
83
- format : 'ULFO' ,
84
- window : {
85
- size : {
86
- width : 660 ,
87
- height : 400
88
- }
89
- } ,
90
- contents : [
91
- {
92
- x : 180 ,
93
- y : 170 ,
94
- type : 'file' ,
95
- path : appPath
96
- } ,
97
- {
98
- x : 480 ,
99
- y : 170 ,
100
- type : 'link' ,
101
- path : '/Applications'
102
- }
103
- ]
66
+ async function init ( ) {
67
+ if ( cli . flags . overwrite ) {
68
+ try {
69
+ fs . unlinkSync ( dmgPath ) ;
70
+ } catch ( _ ) { }
104
71
}
105
- } ) ;
106
72
107
- ee . on ( 'progress' , info => {
108
- if ( info . type === 'step-begin' ) {
109
- ora . text = info . title ;
110
- }
111
- } ) ;
73
+ ora . text = 'Creating icon' ;
74
+ const composedIconPath = await composeIcon ( path . join ( appPath , 'Contents/Resources' , `${ appIconName } .icns` ) ) ;
75
+
76
+ const ee = appdmg ( {
77
+ target : dmgPath ,
78
+ basepath : process . cwd ( ) ,
79
+ specification : {
80
+ title : appName ,
81
+ icon : composedIconPath ,
82
+ //
83
+ // Use transparent background and `background-color` option when this is fixed:
84
+ // https://github.com/LinusU/node-appdmg/issues/135
85
+ background : path . join ( __dirname , 'assets/dmg-background.png' ) ,
86
+ 'icon-size' : 160 ,
87
+ format : 'ULFO' ,
88
+ window : {
89
+ size : {
90
+ width : 660 ,
91
+ height : 400
92
+ }
93
+ } ,
94
+ contents : [
95
+ {
96
+ x : 180 ,
97
+ y : 170 ,
98
+ type : 'file' ,
99
+ path : appPath
100
+ } ,
101
+ {
102
+ x : 480 ,
103
+ y : 170 ,
104
+ type : 'link' ,
105
+ path : '/Applications'
106
+ }
107
+ ]
108
+ }
109
+ } ) ;
112
110
113
- ee . on ( 'finish' , async ( ) => {
114
- ora . text = 'Code signing DMG' ;
115
-
116
- try {
117
- let identity ;
118
- const { stdout} = await execa ( 'security' , [ 'find-identity' , '-v' , '-p' , 'codesigning' ] ) ;
119
- if ( stdout . includes ( 'Developer ID Application:' ) ) {
120
- identity = 'Developer ID Application' ;
121
- } else if ( stdout . includes ( 'Mac Developer:' ) ) {
122
- identity = 'Mac Developer' ;
123
- } else {
124
- const err = new Error ( ) ;
125
- err . stderr = 'No usable identity found' ;
126
- throw err ;
111
+ ee . on ( 'progress' , info => {
112
+ if ( info . type === 'step-begin' ) {
113
+ ora . text = info . title ;
127
114
}
115
+ } ) ;
116
+
117
+ ee . on ( 'finish' , async ( ) => {
118
+ try {
119
+ ora . text = 'Replacing DMG icon' ;
120
+ // Seticon is a native tool to change files icons (Source: https://github.com/sveinbjornt/osxiconutils)
121
+ await execa ( path . join ( __dirname , 'seticon' ) , [ composedIconPath , dmgPath ] ) ;
122
+
123
+ ora . text = 'Code signing DMG' ;
124
+ let identity ;
125
+ const { stdout} = await execa ( 'security' , [ 'find-identity' , '-v' , '-p' , 'codesigning' ] ) ;
126
+ if ( stdout . includes ( 'Developer ID Application:' ) ) {
127
+ identity = 'Developer ID Application' ;
128
+ } else if ( stdout . includes ( 'Mac Developer:' ) ) {
129
+ identity = 'Mac Developer' ;
130
+ } else {
131
+ const err = new Error ( ) ;
132
+ err . stderr = 'No usable identity found' ;
133
+ throw err ;
134
+ }
128
135
129
- await execa ( 'codesign' , [ '--sign' , identity , dmgPath ] ) ;
130
- const { stderr} = await execa ( 'codesign' , [ dmgPath , '--display' , '--verbose=2' ] ) ;
136
+ await execa ( 'codesign' , [ '--sign' , identity , dmgPath ] ) ;
137
+ const { stderr} = await execa ( 'codesign' , [ dmgPath , '--display' , '--verbose=2' ] ) ;
138
+
139
+ const match = / ^ A u t h o r i t y = ( .* ) $ / m. exec ( stderr ) ;
140
+ if ( ! match ) {
141
+ ora . fail ( 'Not code signed' ) ;
142
+ process . exit ( 1 ) ;
143
+ }
131
144
132
- const match = / ^ A u t h o r i t y = ( .* ) $ / m. exec ( stderr ) ;
133
- if ( ! match ) {
134
- ora . fail ( 'Not code signed' ) ;
135
- process . exit ( 1 ) ;
145
+ ora . info ( `Code signing identity: ${ match [ 1 ] } ` ) . start ( ) ;
146
+ ora . succeed ( 'DMG created' ) ;
147
+ } catch ( error ) {
148
+ ora . fail ( `Code signing failed. The DMG is fine, just not code signed.\n${ error . stderr . trim ( ) } ` ) ;
149
+ process . exit ( 2 ) ;
136
150
}
151
+ } ) ;
137
152
138
- ora . info ( `Code signing identity: ${ match [ 1 ] } ` ) . start ( ) ;
139
- ora . succeed ( 'DMG created' ) ;
140
- } catch ( error ) {
141
- ora . fail ( `Code signing failed. The DMG is fine, just not code signed.\n${ error . stderr . trim ( ) } ` ) ;
142
- process . exit ( 2 ) ;
143
- }
144
- } ) ;
153
+ ee . on ( 'error' , error => {
154
+ ora . fail ( error ) ;
155
+ process . exit ( 1 ) ;
156
+ } ) ;
157
+ }
145
158
146
- ee . on ( 'error' , error => {
159
+ init ( ) . catch ( error => {
147
160
ora . fail ( error ) ;
148
161
process . exit ( 1 ) ;
149
162
} ) ;
0 commit comments