This repository has been archived by the owner on Jul 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 126
/
Gruntfile.js
133 lines (122 loc) · 4.56 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
module.exports = function (grunt) {
grunt.initConfig({
ts: {
default: {
tsconfig: "./tsconfig.json"
}
},
copy: {
static: {
files: [
{ expand: true, src: ["**"], cwd: "src/static/", dest: "dist/ff/" },
],
},
chromeOpera: {
files: [
{ expand: true, src: ["**"], cwd: "dist/ff/", dest: "dist/chrome-opera/" },
]
}
},
clean: {
all: {
src: ["dist", "zip"]
}
},
watch: {
tsfiles: {
files: "src/**/*.ts",
tasks: ["tslint:dev", "ts", "rollup", "fill-content-script", "copy:chromeOpera", "fix-chrome-opera"],
options: {
spawn: false,
}
},
static: {
files: "src/static/**/*",
tasks: ["copy:static", "fix-chrome-opera"]
}
},
compress: {
ff: {
options: {
archive: "dist/zip/firefox.zip"
},
files: [
{ src: ["**/*"], dest: "/", cwd: "dist/ff/", expand: true },
]
},
chromeOpera: {
options: {
archive: "dist/zip/chromeOpera.zip"
},
files: [
{ src: ["**/*"], dest: "/", cwd: "dist/chrome-opera/", expand: true },
]
},
},
tslint: {
dev: {
files: {
src: "src/**/*.ts"
}
},
prod: {
options: {
configuration: "tslint.prod.json"
},
files: {
src: "src/**/*.ts"
}
}
},
rollup: {
options: {
format: 'iife'
},
injected: {
src: 'dist/modulesjs/injected_script.js',
dest: 'dist/ff/injected_script.js'
},
background: {
src: 'dist/modulesjs/background.js',
dest: 'dist/ff/background.js'
},
opt: {
src: 'dist/modulesjs/options.js',
dest: 'dist/ff/options.js'
}
}
});
grunt.loadNpmTasks("grunt-ts");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.loadNpmTasks("grunt-contrib-compress");
grunt.loadNpmTasks("grunt-tslint");
grunt.loadNpmTasks('grunt-rollup');
grunt.registerTask("build", ["generate-tslint-prod", "tslint:prod", "clean", "ts", "rollup", "fill-content-script", "copy", "fix-chrome-opera", "compress"]);
grunt.registerTask("default", ["clean", "tslint:dev", "ts", "rollup", "fill-content-script", "copy", "fix-chrome-opera", "watch"]);
grunt.registerTask("generate-tslint-prod", "Generate the tslint file for prod", function () {
let tslint = grunt.file.readJSON("tslint.json");
delete tslint.rules["no-debugger"];
delete tslint.rules["no-console"];
grunt.file.write("tslint.prod.json", JSON.stringify(tslint, null, 2));
});
grunt.registerTask("fix-chrome-opera", "Fix the manifest for Chrome and Opera", function () {
let manifest = grunt.file.readJSON("dist/chrome-opera/manifest.json");
// fix manifest
delete manifest.applications;
manifest.permissions = manifest.permissions.filter(p => p != "tabs");
grunt.file.write("dist/chrome-opera/manifest.json", JSON.stringify(manifest, null, 2));
});
grunt.registerTask("fill-content-script", "Adds the injected script data into the content script file", function () {
// this file is already rolled up
const injected = grunt.file.read("dist/ff/injected_script.js");
// this only works because it doesn't load modules, otherwise
// we'd need to grab it from ff... but that may have already been filled
let content = grunt.file.read("dist/modulesjs/content_script.js");
// escape the dollar sign to avoid replacements: https://es.stackoverflow.com/a/267800/11272
content = content.replace('return "placeholder";', injected.replace(/\$/g, "$$$$"));
grunt.file.write("dist/ff/content_script.js", content);
grunt.file.delete("dist/ff/injected_script.js");
})
};