forked from thomaswilburn/Caret
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
129 lines (115 loc) · 4.12 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
module.exports = function(grunt) {
var exec = require("child_process").exec;
var path = require("path");
var fs = require("fs");
var Zip = require("jszip");
grunt.loadNpmTasks("grunt-contrib-less");
grunt.loadNpmTasks("grunt-contrib-watch");
grunt.initConfig({
less: {
light: {
files: {
"css/caret.css": "css/seed.less",
"css/caret-twilight.css": "css/seed-twilight.less",
"css/caret-dark.css": "css/seed-dark.less"
}
}
},
watch: {
css: {
files: ["css/*.less"],
tasks: ["less"]
},
options: {
spawn: false
}
},
copy: [
"config/**",
"_locales/**",
"js/**",
"css/*.css",//leave the LESS behind
"**/*.html",//both main.html and the templates
"templates/*",
"require.js",
"background.js",
"installer.js",
"./*.png", //in case we add images at some point
"!node_modules/**"
]
});
grunt.registerTask("default", ["less", "watch"]);
grunt.registerTask("prep", ["less", "cleanup", "copyUnpacked"]);
grunt.registerTask("package", ["prep", "chrome", "webstore", "compress:store"]);
grunt.registerTask("store", ["prep", "webstore", "compress:store"]);
grunt.registerTask("crx", ["prep", "chrome"]);
grunt.registerTask("copyUnpacked", "Copies files to the build directory", function() {
var srcPatterns = grunt.config.get("copy");
var files = grunt.file.expandMapping(srcPatterns, "./build/unpacked", {
filter: "isFile"
});
files.forEach(function(f) {
grunt.file.copy(f.src[0], f.dest);
});
});
grunt.registerTask("compress", "Generates the store .zip file", function() {
var zipfile = new Zip();
var files = grunt.file.expand({ filter: "isFile", cwd: "./build/unpacked" }, "**/*");
files.forEach(function(file) {
var buffer = fs.readFileSync(path.join("./build/unpacked", file));
zipfile.file(file, buffer);
});
var zipped = zipfile.generate({
type: "nodebuffer",
compression: "DEFLATE",
compressionOptions: { level: 8 }
});
fs.writeFileSync("./build/caret.zip", zipped);
});
grunt.registerTask("chrome", "Makes a new CRX package", function() {
var manifest = JSON.parse(fs.readFileSync("./manifest.json"));
manifest.icons["128"] = "icon-128-inverted.png";
fs.writeFileSync("./build/unpacked/manifest.json", JSON.stringify(manifest, null, 2));
//perform the Chrome packaging
var c = this.async();
var here = fs.realpathSync(__dirname);
var chrome = {
win32: '"' + (process.env["ProgramFiles(x86)"] || process.env.ProgramFiles) + "\\Google\\Chrome\\Application\\chrome.exe" + '"',
linux: "/opt/google/chrome/google-chrome",
osx: "Beats me."
};
var cmd = [ chrome[process.platform] ];
cmd.push("--pack-extension=" + path.join(here, "build/unpacked"));
cmd.push("--pack-extension-key=" + path.join(here, "../Caret.pem"));
cmd = cmd.join(" ");
exec(cmd,function(err, out, stderr) {
if (err) {
console.log("Unable to run Chrome for CRX packaging.");
return c();
}
fs.renameSync("./build/unpacked.crx", "./build/Caret.crx");
c();
});
});
grunt.registerTask("webstore", "Prepares the manifest for the web store", function() {
var manifest = JSON.parse(fs.readFileSync("./manifest.json"));
delete manifest.update_url;
delete manifest.key;
manifest = JSON.stringify(manifest, null, 2);
fs.writeFileSync("./build/unpacked/manifest.json", manifest);
});
grunt.registerTask("cleanup", "Removes the build/unpacked directory", function() {
var c = this.async();
exec("rm -rf ./build/*", c);
});
grunt.registerTask("checkLocale", "Finds unregistered strings for a given locale; checkLocale:XX for a language code XX", function(language) {
var english = require("./_locales/en/messages.json");
var other = require(`./_locales/${language}/messages.json`);
console.log(`Checking ${language} against English string file`);
for (var k in english) {
if (!(k in other)) {
console.log(`- Missing string: ${k}`);
}
}
})
};