This repository has been archived by the owner on Apr 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 311
/
Gruntfile.js
executable file
·209 lines (182 loc) · 7.63 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
var execSync = require('child_process').execSync;
var path = require('path');
var shell = require('shelljs');
var APPVERSION = '0.4.5';
var ELECTRONVERSION = '1.6.1';
var isRelease = (process.argv[2] === 'release');
module.exports = function(grunt) {
var electronBuild = ''
if (process.platform === 'darwin') {
electronBuild = 'osxBuild'
} else if (process.platform === 'linux') {
electronBuild = 'nixBuild'
} else {
electronBuild = 'winBuild'
}
var osxArchive = './installers/osx64/PhoneGap-Desktop-Beta-' + APPVERSION + '-mac.zip';
var winArchive = './installers/win32/PhoneGap-Desktop-Beta-' + APPVERSION + '-win.zip';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
'electron': {
osxBuild: {
options: {
name: 'PhoneGap',
dir: './www',
out: './build',
version: ELECTRONVERSION,
platform: 'darwin',
arch: 'x64',
icon: './www/img/app-icons/icon.icns',
asar: false
}
},
winBuild: {
options: {
name: 'PhoneGap',
dir: './www',
out: './build',
version: ELECTRONVERSION,
platform: 'win32',
arch: 'ia32',
icon: './www/img/app-icons/icon.ico',
asar: { unpackDir:'{bin,node_modules/adm-zip,node_modules/adm-zip/**}' }
}
},
nixBuild: {
options:{
name: 'PhoneGap',
dir: './www',
out: './build',
version: ELECTRONVERSION,
platform: 'linux',
arch: 'x64'
}
}
}
});
// Load the grunt plugins.
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-less');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-electron');
// Register the task to install dependencies.
grunt.task.registerTask('install-dependencies', function() {
execSync('node src/js/download-node.js');
var npmInstall = 'npm install';
if (isRelease) {
npmInstall += ' --production';
}
execSync(npmInstall, { cwd: './www' });
// npm/phonegap workarounds are for Windows, Mac can install normally
if ((process.platform === 'darwin' || process.platform === 'linux') && isRelease) {
var config = JSON.parse(grunt.file.read('./src/config/package.json'));
var pgVersion = config.devDependencies.phonegap;
execSync('npm install npm@3.10.3 phonegap@' + pgVersion, { cwd: './www' });
}
});
// Clean old files
grunt.task.registerTask('clean-old-files', function() {
// clean build directories
shell.rm('-rf', './build');
// if we are using debugMac/debugWin commands, don't remove files
if (process.argv[2] && process.argv[2].includes('debug'))
return;
// clean node binary
var nodePath = './www/bin/node';
shell.rm('-rf', (process.platform === 'darwin') ? nodePath : (nodePath + '.exe'));
// clean node dependencies
shell.rm('-rf', './www/node_modules');
// clean installers directory for release builds
if (isRelease) {
shell.rm('-rf', './installers');
}
});
// start the local server for update checker
grunt.task.registerTask('start-localhost', function() {
shell.exec('node ./update-server/server.js');
});
// create the OSX DMG installer
grunt.task.registerTask('osx-installer', function() {
if (process.platform === 'darwin' && isRelease) {
// OSX code signing
var signConfig = grunt.file.readJSON("sign-config.json");
shell.exec("codesign --verbose --deep --force --sign " + "'"+signConfig.certName+"'" + " build/PhoneGap-darwin-x64/PhoneGap.app");
shell.exec("codesign --verbose --verify build/PhoneGap-darwin-x64/PhoneGap.app");
shell.exec("codesign -vv -d build/PhoneGap-darwin-x64/PhoneGap.app");
shell.exec("codesign --verbose --force --sign " + "'"+signConfig.certName+"'" + " build/PhoneGap-darwin-x64/PhoneGap.app/Contents/MacOS/PhoneGap");
shell.exec("codesign --verbose --verify build/PhoneGap-darwin-x64/PhoneGap.app/Contents/MacOS/PhoneGap");
shell.exec('bash ./res/installers/osx/package-pgd.sh');
}
});
grunt.task.registerTask('copy-package-json', function() {
if (isRelease) {
// disable the dev console before copying the package.json to www folder
var config = grunt.file.read('./src/config/package.json');
var releaseConfig = config.replace('"devTools" : true', '"devTools" : false');
grunt.file.write('./www/package.json', releaseConfig);
} else {
// copy package.json to www folder
grunt.file.copy('./src/config/package.json', './www/package.json');
}
});
grunt.task.registerTask('copy-win-downloadPG-version', function() {
// copy pinned phonegap version to Windows downloadPG.js
if (process.platform === 'win32') {
var filePath = './build/PhoneGap-win32-ia32/resources/app.asar.unpacked/bin/downloadPG.js';
var pgVersion = require('./src/config/package.json').devDependencies.phonegap;
var downloadPG = grunt.file.read(filePath);
var downloadPGpinned = downloadPG.replace('REPLACE_ME', pgVersion);
grunt.file.write(filePath, downloadPGpinned);
} else {
console.log('Skipping: Not on Windows');
}
});
// copy the EULA into the installer folders and reference docs to final app bundles
grunt.task.registerTask('copy-license-docs', function() {
grunt.file.copy('./src/license.rtf', './res/installers/osx/license.rtf');
grunt.file.copy('./src/license.txt', './res/installers/win/license.txt');
if (process.platform === 'win32') {
var buildPath = './build/PhoneGap-win32-ia32/';
grunt.file.copy('./README.md', path.join(buildPath, 'README.md'));
grunt.file.copy('./INSTALL', path.join(buildPath, 'INSTALL'));
}
});
// Open the built app
grunt.task.registerTask('open', function() {
// disabling on Windows for now, will re-evaluate in the future
var opener = require('opener'),
macPath = 'build/PhoneGap-darwin-x64/PhoneGap.app';
opener(macPath);
});
// default - runs the dev build
grunt.registerTask(
'default',
[
'clean-old-files',
'copy-package-json',
'install-dependencies',
'electron:' + electronBuild,
'copy-license-docs',
'copy-win-downloadPG-version',
'open'//,
//'start-localhost'
]
);
// production build task
grunt.registerTask(
'release',
[
'clean-old-files',
'copy-package-json',
'install-dependencies',
'electron:' + electronBuild,
'copy-license-docs',
'copy-win-downloadPG-version',
'osx-installer',
'open'
]
);
grunt.registerTask('debugMac',['clean-old-files','electron:osxBuild','open']);
grunt.registerTask('debugWin',['clean-old-files','electron:winBuild','copy-win-downloadPG-version','open']);
};