-
Notifications
You must be signed in to change notification settings - Fork 4
/
Gruntfile.js
123 lines (117 loc) · 4.1 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
module.exports = function (grunt) {
// grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('grunt-jest');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
manifest: grunt.file.readJSON('extension/manifest.json'),
firefoxManifest: grunt.file.readJSON('extension/firefox-manifest.json'),
jest: {
all: {
options: {
coverage: true,
testPathPattern: /.*-test.js/,
},
},
},
compress: {
main: {
options: {
archive: 'dist/Trello-Folds-<%= pkg.version %>.zip',
},
files: [
{ expand: true, cwd: 'dist/tmp/chrome/', src: ['**'], dest: '/' },
],
},
firefox: {
options: {
archive: 'dist/Trello-Folds-Firefox-<%= pkg.version %>.zip',
},
files: [
{ expand: true, cwd: 'dist/tmp/firefox/', src: ['**'], dest: '/' },
],
},
},
copy: {
chrome: {
files: [
{
expand: true, cwd: 'extension/', src: ['**', '!firefox-manifest.json'],
dest: 'dist/tmp/chrome',
},
],
},
firefox: {
files: [
{
expand: true, cwd: 'extension/', src: ['**', '!manifest.json'],
dest: 'dist/tmp/firefox',
rename: function (dest, src) {
return `${dest}/${src.replace('firefox-manifest', 'manifest')}`;
},
},
],
},
},
});
grunt.registerTask('default', 'test');
grunt.registerTask('test', 'Runs Jest tests', () => {
grunt.task.run('jest:all');
});
grunt.registerTask('create-chrome-extension', 'copy:chrome');
grunt.registerTask('create-firefox-extension', 'copy:firefox');
grunt.registerTask('package-chrome', 'compress:main');
grunt.registerTask('package-firefox', 'compress:firefox');
grunt.registerTask('delete-tmp-folder', 'Deletes the temporary folder', () => {
grunt.file.delete('dist/tmp');
});
grunt.registerTask('version-check',
'Checks that package.json and manifest.json version matches', () => {
const packageVer = grunt.config('pkg').version;
const chromeVer = grunt.config('manifest').version;
const firefoxVer = grunt.config('firefoxManifest').version;
if (packageVer !== chromeVer) {
grunt.log.error(`package.json [${packageVer}] and `
+ ` Chrome manifest.json [${chromeVer}] versions do not match`);
return false;
}
if (packageVer !== firefoxVer) {
grunt.log.error(`package.json [${packageVer}] and `
+ ` Firefox manifest.json [${firefoxVer}] versions do not match`);
return false;
}
grunt.log.writeln(`Versions match: ${packageVer}`);
return true;
});
grunt.registerTask('build', (browser) => {
if (browser && !['chrome', 'firefox'].includes(browser)) {
grunt.log.error('Build should be called with no args or "chrome" or "firefox"');
return false;
}
grunt.task.run('version-check');
const packageVersion = grunt.config('pkg').version;
if (!browser || browser === 'chrome') {
if (grunt.file.exists(`dist/Trello-Folds-${packageVersion}.zip`)) {
grunt.fail.warn('File already exists');
}
// TODO Disabled because of Jest issue: https://github.com/ionic-team/stencil/issues/2168
// grunt.option('reporter', 'progress');
// grunt.task.run('test');
grunt.task.run('create-chrome-extension');
grunt.task.run('package-chrome');
}
if (!browser || browser === 'firefox') {
if (grunt.file.exists(`dist/Trello-Folds-Firefox-${packageVersion}.zip`)) {
grunt.fail.warn('File already exists');
}
// TODO Disabled because of Jest issue: https://github.com/ionic-team/stencil/issues/2168
// grunt.option('reporter', 'progress');
// grunt.task.run('test');
grunt.task.run('create-firefox-extension');
grunt.task.run('package-firefox');
}
grunt.task.run('delete-tmp-folder');
return true;
});
};