Skip to content

Commit 2ddcf84

Browse files
committed
cleanup code of gruntfile
1 parent 1331470 commit 2ddcf84

1 file changed

Lines changed: 53 additions & 47 deletions

File tree

gruntfile.js

Lines changed: 53 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
11
const path = require('path')
22
const ChildProcess = require('child_process')
33
const packager = require('electron-packager')
4-
const fs = require('fs')
5-
if (process.platform === 'darwin') {
6-
const appdmg = require('appdmg')
7-
}
4+
const appdmg = process.platform === 'darwin'
5+
? require('appdmg')
6+
: null
87

98
module.exports = function (grunt) {
10-
if (process.platform === 'win32') auth_code = grunt.file.readJSON('secret/auth_code.json')
9+
var auth_code
10+
try {
11+
auth_code = grunt.file.readJSON('secret/auth_code.json')
12+
} catch (e) {
13+
if (e.origError.code === 'ENOENT') {
14+
console.warn('secret/auth_code.json is not found. CodeSigning is not available.')
15+
}
16+
}
17+
const OSX_COMMON_NAME = auth_code != null ? auth_code.OSX_COMMON_NAME : ''
18+
const WIN_CERT_PASSWORD = auth_code != null ? auth_code.WIN_CERT_PASSWORD : ''
1119

1220
var initConfig = {
1321
pkg: grunt.file.readJSON('package.json'),
@@ -21,23 +29,23 @@ module.exports = function (grunt) {
2129
iconUrl: path.join(__dirname, 'resources/app.ico'),
2230
setupIcon: path.join(__dirname, 'resources/dmg.ico'),
2331
certificateFile: path.join(__dirname, 'secret', 'authenticode_cer.p12'),
24-
certificatePassword: auth_code.win_cert_pw,
32+
certificatePassword: WIN_CERT_PASSWORD,
2533
noMsi: true
2634
}
2735
}
2836
}
2937
grunt.initConfig(initConfig)
30-
3138
grunt.loadNpmTasks('grunt-electron-installer')
3239

3340
grunt.registerTask('compile', function () {
3441
var done = this.async()
35-
var execPath = path.join('node_modules', '.bin', 'webpack') + ' --config webpack.config.production.js'
42+
var execPath = path.join('node_modules', '.bin', 'webpack') + ' --config webpack-production.config.js'
3643
grunt.log.writeln(execPath)
3744
ChildProcess.exec(execPath,
3845
{
3946
env: Object.assign({}, process.env, {
40-
BABEL_ENV: 'production'
47+
BABEL_ENV: 'production',
48+
NODE_ENV: 'production'
4149
})
4250
},
4351
function (err, stdout, stderr) {
@@ -54,32 +62,6 @@ module.exports = function (grunt) {
5462
)
5563
})
5664

57-
grunt.registerTask('zip', function (platform) {
58-
var done = this.async()
59-
switch (platform) {
60-
case 'osx':
61-
var execPath = 'cd dist/Boostnote-darwin-x64 && zip -r -y -q ../Boostnote-mac.zip Boostnote.app'
62-
grunt.log.writeln(execPath)
63-
ChildProcess.exec(execPath,
64-
function (err, stdout, stderr) {
65-
grunt.log.writeln(stdout)
66-
67-
if (err) {
68-
grunt.log.writeln(err)
69-
grunt.log.writeln(stderr)
70-
done(false)
71-
return
72-
}
73-
done()
74-
}
75-
)
76-
break
77-
default:
78-
done()
79-
return
80-
}
81-
})
82-
8365
grunt.registerTask('pack', function (platform) {
8466
grunt.log.writeln(path.join(__dirname, 'dist'))
8567
var done = this.async()
@@ -146,17 +128,17 @@ module.exports = function (grunt) {
146128
return
147129
}
148130

149-
ChildProcess.exec('codesign --verbose --deep --force --sign \"\" dist/Boostnote-darwin-x64/Boostnote.app', function (err, stdout, stderr) {
150-
grunt.log.writeln(stdout)
151-
152-
if (err) {
153-
grunt.log.writeln(err)
154-
grunt.log.writeln(stderr)
155-
done(false)
156-
return
157-
}
158-
done()
159-
})
131+
ChildProcess.exec(`codesign --verbose --deep --force --sign \"${OSX_COMMON_NAME}\" dist/Boostnote-darwin-x64/Boostnote.app`,
132+
function (err, stdout, stderr) {
133+
grunt.log.writeln(stdout)
134+
if (err) {
135+
grunt.log.writeln(err)
136+
grunt.log.writeln(stderr)
137+
done(false)
138+
return
139+
}
140+
done()
141+
})
160142
})
161143

162144
grunt.registerTask('create-osx-installer', function () {
@@ -186,6 +168,31 @@ module.exports = function (grunt) {
186168
})
187169
})
188170

171+
grunt.registerTask('zip', function (platform) {
172+
var done = this.async()
173+
switch (platform) {
174+
case 'osx':
175+
var execPath = 'cd dist/Boostnote-darwin-x64 && zip -r -y -q ../Boostnote-mac.zip Boostnote.app'
176+
grunt.log.writeln(execPath)
177+
ChildProcess.exec(execPath,
178+
function (err, stdout, stderr) {
179+
grunt.log.writeln(stdout)
180+
if (err) {
181+
grunt.log.writeln(err)
182+
grunt.log.writeln(stderr)
183+
done(false)
184+
return
185+
}
186+
done()
187+
}
188+
)
189+
break
190+
default:
191+
done()
192+
return
193+
}
194+
})
195+
189196
grunt.registerTask('build', function (platform) {
190197
if (!platform) {
191198
platform = process.platform === 'darwin' ? 'osx' : process.platform === 'win32' ? 'win' : null
@@ -200,6 +207,5 @@ module.exports = function (grunt) {
200207
}
201208
})
202209

203-
// Default task(s).
204210
grunt.registerTask('default', ['build'])
205211
}

0 commit comments

Comments
 (0)