-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathGruntfile.js
More file actions
205 lines (198 loc) · 5.33 KB
/
Gruntfile.js
File metadata and controls
205 lines (198 loc) · 5.33 KB
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
const isWsl = require('is-wsl');
'use strict';
module.exports = function(grunt) {
// Load secrets file if present
var secrets = {};
if (grunt.option('secretsFile')) {
secrets = grunt.file.readJSON(grunt.option('secretsFile'));
}
// Set pdf test file dir
var testPdfDir = {};
if (grunt.option('testPdfDir')) {
testPdfDir = grunt.option('testPdfDir');
}
// Project configuration.
grunt.initConfig({
// TODO: Use pkg data to set version of build
pkg: grunt.file.readJSON('package.json'),
jasmine: {browserifyTest: {options: {specs: 'test/**/*-test.js'}}},
mochaTest: {
test: {
options: {
reporter: 'spec',
quiet: false,
},
src: ['test/**/*-test.js']
}
},
karma: {
options: {configFile: 'karma.conf.js'},
// WSL-specific hacks
wsl: {browsers: ['Chrome_for_WSL']},
linux: {browsers: ['ChromeHeadless_NoSandBox']},
},
clean: {
options: {'force': true},
dist: ['dist/app/'],
karma: ['test/karma/build/'],
},
concat: {
options: {separator: ';'},
loadpdf: {
src: ['app/src/load-pdf.js'],
dest: 'dist/app/load-pdf.js',
},
icon: {
src: ['app/src/show-page-icon.js'],
dest: 'dist/app/icon.js',
},
libs: {
src: ['app/libs/patch-worker.js'],
dest: 'dist/app/libs.js',
},
},
copy: {
dist: {
files: [
{
expand: true,
flatten: true,
src: ['app/images/*', 'app/src/options.*'],
dest: 'dist/app/',
},
],
},
karma: {
files: [
{
expand: true,
flatten: true,
src: testPdfDir + '/**/*.pdf*',
dest: 'test/karma/build',
},
],
},
},
browserify: {
options: {
ignore: [
'entry?name=[hash]-worker.js!./pdf.worker.js',
'node-ensure',
]
},
main: {src: 'app/src/pdf-to-csv.js', dest: 'dist/app/main.js'},
worker_path: {src: 'app/src/load-pdf.js', dest: 'dist/app/load-pdf.js'},
worker: {src: 'app/src/pdf.worker.js', dest: 'dist/app/pdf.worker.js'},
karma: {
src: 'test/karma/pdf-to-csv-spec.js',
dest: 'test/karma/build/karma-spec.js'
},
},
uglify: {
dist: {
files: {
'dist/app/libs.js': ['dist/app/libs.js'],
'dist/app/pdf.worker.js': ['dist/app/pdf.worker.js'],
'dist/app/main.js': ['dist/app/main.js'],
'dist/app/icon.js': ['dist/app/icon.js'],
'dist/app/options.js': ['dist/app/options.js'],
}
}
},
crx: {
extension: {
'src': ['dist/app/*'],
'dest': 'dist/builds/<%= pkg.name %>-<%= pkg.version %>.zip'
}
},
dalek: {
options: {
browser: ['chrome'],
// generate an html & an jUnit report
reporter: ['html', 'junit'],
// don't load config from an Dalekfile
dalekfile: false,
}
},
replace: {
dist: {
options: {
patterns:
[{match: 'version', /* -> */ replacement: '<%= pkg.version %>'}]
},
files: [{
expand: true,
flatten: true,
src: ['app/manifest.json'],
dest: 'dist/app'
}]
}
},
webstore_upload: {
accounts: {
default: {
// account under this section will be used by default
publish: true, // publish item right after uploading. default false
client_id: secrets.client_id,
client_secret: secrets.client_secret,
refresh_token: secrets.refresh_token,
}
},
extensions: {
pdf_to_csv: {
appID: 'jbneodpofmnammepmnejgkacdbjojcgn', // required
zip: 'dist/builds/<%= pkg.name %>-<%= pkg.version %>.zip' // required
}
}
},
trimtrailingspaces: {
main: {
src: ['app/src/**/*.js', 'test/**/*.js'],
options: {
filter: 'isFile',
encoding: 'utf8',
}
}
},
});
['grunt-browserify',
'grunt-contrib-clean',
'grunt-contrib-concat',
'grunt-contrib-copy',
'grunt-contrib-jasmine',
'grunt-contrib-uglify',
'grunt-crx',
'grunt-karma',
'grunt-mocha-test',
'grunt-newer',
'grunt-replace-regex',
'grunt-trimtrailingspaces',
'grunt-webstore-upload',
].forEach((npmTask) => {
grunt.loadNpmTasks(npmTask);
});
// Platform specific registrations
// https://stackoverflow.com/a/32586729/2825055,
// https://stackoverflow.com/a/23848087/2825055
grunt.registerTask('unittests', function() {
if (isWsl) {
grunt.task.run('karma:wsl');
} else {
grunt.task.run('karma:linux');
}
});
// The main grunt tasks, each of which nests the previous one.
// build -> test -> package -> upload
grunt.registerTask(
'build',
[].concat(
'trimtrailingspaces', 'clean:dist', 'replace:dist', 'concat',
'browserify', 'copy:dist'));
grunt.registerTask(
'test',
[].concat(
'build', 'mochaTest', 'clean:karma', 'copy:karma', 'browserify:karma',
'unittests'));
grunt.registerTask('package', [].concat('test', 'copy:dist', 'crx'));
grunt.registerTask('upload', [].concat('package', 'webstore_upload'));
};