This repository has been archived by the owner on Jul 24, 2023. It is now read-only.
forked from bcjordan/chrome-serial-app
/
Gruntfile.js
193 lines (173 loc) · 4.34 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
'use strict';
module.exports = function (grunt) {
const buildConfig = require('./build-config.js');
const pemFile = buildConfig.chrome_signing_pem.replace('~', process.env['HOME']);
require('load-grunt-tasks')(grunt);
const deployBuild = grunt.cli.tasks.length && grunt.cli.tasks[0] === 'deploy';
const pluginFolder = require('path').resolve() + '/dist';
const manifest = grunt.file.readJSON('app/manifest.json');
const packagePrefix = 'package/CDOSerialTest-' + (deployBuild ? parseInt(manifest.version, 10) + 1 : manifest.version);
// Define the configuration for all the tasks
grunt.initConfig({
browserify: {
app: {
src: [deployBuild ?
'app/scripts/ExtensionController.js' :
'app/scripts/DevExtensionController.js'
],
dest: 'dist/scripts/app.bundled.js',
options: {
transform: [
'babelify'
],
watch: true,
browserifyOptions: {
// Adds inline source map to bundled package
debug: !deployBuild,
},
}
}
},
// Watches files for changes and runs tasks based on the changed files
watch: {
js: {
files: ['app/scripts/{,*/}*.js'],
tasks: ['browserify', 'copy'],
options: {
livereload: {
port: 35730
}
}
},
gruntfile: {
files: ['Gruntfile.js']
},
},
// Empties folders to start fresh
clean: {
dist: {
files: [{
dot: true,
src: [
'dist/*',
'package/*',
]
}]
}
},
// Make sure code styles are up to par and there are no obvious mistakes
jshint: {
options: {
jshintrc: '.jshintrc',
reporter: require('jshint-stylish')
},
all: [
'Gruntfile.js',
'app/scripts/{,*/}*.js',
'!app/scripts/vendor/*',
'test/spec/{,*/}*.js'
]
},
copy: {
dist: {
files: [{
expand: true,
dot: true,
cwd: 'app',
dest: 'dist',
src: [
'*.{ico,png,txt}',
'manifest.json',
'images/{,*/}*.{webp,gif,png}',
'styles/fonts/{,*/}*.*',
'_locales/{,*/}*.json',
'{,*/}*.js'
]
}]
},
},
concurrent: {
chromeOpenLiveReload: ['exec:appOpen', 'watch'],
options: {
logConcurrentOutput: true
}
},
// Update build number, potentially exclude given script
chromeManifest: {
dist: {
options: {
buildnumber: true,
background: {
target: 'scripts/app.bundled.js',
}
},
src: 'app',
dest: 'dist'
}
},
// Compress files in dist to make installable Chrome Apps package
compress: {
dist: {
options: {
archive: function () {
return packagePrefix + '.zip';
}
},
files: [{
expand: true,
cwd: 'dist/',
src: ['**'],
dest: ''
}]
}
},
// Generates .crx bundle signed with pemfile
crx: {
dist: {
"src": "dist/**/*",
"dest": packagePrefix + '.crx',
"options": {
"privateKey": pemFile,
}
}
},
exec: {
appOpen: {
cmd: `/Applications/Google\\ Chrome.app/Contents/MacOS/Google\\ Chrome --load-and-launch-app="${pluginFolder}"`
},
checkPemSpecified: {
cmd: function () {
if (!!pemFile) {
throw 'No .pem signing file path specified.';
}
return true;
}
}
}
});
grunt.registerTask('checkPemSpecified', 'Confirms .pem file is specified, complaining if not.',
function () {
if (pemFile) {
return true;
}
grunt.log.writeln('Create a .pem file at https://developer.chrome.com/extensions/packaging#creating');
grunt.log.writeln('And link to it in build-config.js');
return false;
});
grunt.registerTask('build', [
'clean:dist',
'browserify',
'copy'
]);
grunt.registerTask('deploy', [
'checkPemSpecified',
'chromeManifest:dist',
'build',
'compress:dist',
'crx:dist'
]);
grunt.registerTask('default', [
'build',
'concurrent:chromeOpenLiveReload'
]);
};