2013-08-22 06:35:47 +00:00
|
|
|
module.exports = function(grunt) {
|
2013-09-11 21:17:27 +00:00
|
|
|
|
|
|
|
var exec = require("child_process").exec;
|
|
|
|
var path = require("path");
|
|
|
|
var fs = require("fs");
|
2014-03-05 23:32:15 +00:00
|
|
|
|
2013-08-22 06:35:47 +00:00
|
|
|
grunt.loadNpmTasks("grunt-contrib-less");
|
|
|
|
grunt.loadNpmTasks("grunt-contrib-watch");
|
2013-09-06 16:28:41 +00:00
|
|
|
grunt.loadNpmTasks("grunt-contrib-compress");
|
2014-03-05 23:32:15 +00:00
|
|
|
|
2013-08-22 06:35:47 +00:00
|
|
|
grunt.initConfig({
|
|
|
|
less: {
|
2013-09-13 22:57:57 +00:00
|
|
|
light: {
|
2013-08-22 06:35:47 +00:00
|
|
|
files: {
|
2013-09-13 22:57:57 +00:00
|
|
|
"css/caret.css": "css/seed.less",
|
|
|
|
"css/caret-dark.css": "css/seed-dark.less"
|
2013-08-22 06:35:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
css: {
|
|
|
|
files: ["css/*.less"],
|
|
|
|
tasks: ["less"]
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
spawn: false
|
|
|
|
}
|
2013-09-06 16:28:41 +00:00
|
|
|
},
|
|
|
|
compress: {
|
2013-09-21 08:29:05 +00:00
|
|
|
store: {
|
2013-09-06 16:28:41 +00:00
|
|
|
options: {
|
|
|
|
archive: "build/caret.zip",
|
2013-09-21 08:29:05 +00:00
|
|
|
pretty: true,
|
|
|
|
level: 2
|
2013-09-06 16:28:41 +00:00
|
|
|
},
|
2013-09-21 08:29:05 +00:00
|
|
|
files: [
|
|
|
|
{cwd: "build/unpacked", expand: true, src: "**", dest: "/", isFile: true}
|
|
|
|
]
|
2013-09-06 16:28:41 +00:00
|
|
|
}
|
2013-09-11 21:17:27 +00:00
|
|
|
},
|
2014-02-28 02:54:37 +00:00
|
|
|
copy: [
|
|
|
|
"config/**",
|
2014-06-30 01:16:50 +00:00
|
|
|
"_locales/**",
|
2014-02-28 02:54:37 +00:00
|
|
|
"js/**",
|
|
|
|
"css/*.css",//leave the LESS behind
|
|
|
|
"**/*.html",//both main.html and the templates
|
|
|
|
"require.js",
|
|
|
|
"background.js",
|
|
|
|
"installer.js",
|
2014-07-17 15:13:30 +00:00
|
|
|
"./*.png", //in case we add images at some point
|
|
|
|
"!node_modules/**"
|
2014-02-28 02:54:37 +00:00
|
|
|
]
|
2013-08-22 06:35:47 +00:00
|
|
|
});
|
2014-03-05 23:32:15 +00:00
|
|
|
|
2013-08-22 06:35:47 +00:00
|
|
|
grunt.registerTask("default", ["less", "watch"]);
|
2013-12-12 04:08:02 +00:00
|
|
|
grunt.registerTask("prep", ["less", "cleanup", "copyUnpacked"]);
|
|
|
|
grunt.registerTask("package", ["prep", "chrome", "webstore", "compress:store"]);
|
2013-12-11 17:19:14 +00:00
|
|
|
grunt.registerTask("store", ["prep", "webstore", "compress:store"]);
|
|
|
|
grunt.registerTask("crx", ["prep", "chrome"]);
|
2014-03-05 23:32:15 +00:00
|
|
|
|
2013-12-12 04:08:02 +00:00
|
|
|
grunt.registerTask("copyUnpacked", "Copies files to the build directory", function() {
|
|
|
|
var srcPatterns = grunt.config.get("copy");
|
2014-07-17 15:13:30 +00:00
|
|
|
var files = grunt.file.expandMapping(srcPatterns, "./build/unpacked", {
|
|
|
|
filter: "isFile"
|
|
|
|
});
|
|
|
|
files.forEach(function(f) {
|
|
|
|
grunt.file.copy(f.src[0], f.dest);
|
2013-12-12 04:08:02 +00:00
|
|
|
});
|
|
|
|
});
|
2013-09-11 21:17:27 +00:00
|
|
|
|
2013-12-11 17:19:14 +00:00
|
|
|
grunt.registerTask("chrome", "Makes a new CRX package", function() {
|
2013-09-21 08:29:05 +00:00
|
|
|
var manifest = JSON.parse(fs.readFileSync("./manifest.json"));
|
2013-09-12 06:29:04 +00:00
|
|
|
manifest.icons["128"] = "icon-128-inverted.png";
|
|
|
|
fs.writeFileSync("./build/unpacked/manifest.json", JSON.stringify(manifest, null, 2));
|
|
|
|
|
|
|
|
//perform the Chrome packaging
|
2013-09-11 21:17:27 +00:00
|
|
|
var c = this.async();
|
|
|
|
var here = fs.realpathSync(__dirname);
|
2013-09-12 16:58:31 +00:00
|
|
|
|
|
|
|
var chrome = {
|
2013-09-12 18:52:49 +00:00
|
|
|
win32: '"' + (process.env["ProgramFiles(x86)"] || process.env.ProgramFiles) + "\\Google\\Chrome\\Application\\chrome.exe" + '"',
|
2014-01-21 16:30:02 +00:00
|
|
|
linux: "/opt/google/chrome/google-chrome",
|
2013-09-13 16:14:46 +00:00
|
|
|
osx: "Beats me."
|
2014-02-27 06:34:02 +00:00
|
|
|
};
|
2013-09-12 16:58:31 +00:00
|
|
|
|
|
|
|
var cmd = [ chrome[process.platform] ];
|
2013-09-11 21:17:27 +00:00
|
|
|
cmd.push("--pack-extension=" + path.join(here, "build/unpacked"));
|
|
|
|
cmd.push("--pack-extension-key=" + path.join(here, "../Caret.pem"));
|
2013-12-11 17:19:14 +00:00
|
|
|
cmd = cmd.join(" ");
|
|
|
|
exec(cmd,function(err, out, stderr) {
|
|
|
|
if (err) {
|
|
|
|
console.log("Unable to run Chrome for CRX packaging.");
|
|
|
|
return c();
|
|
|
|
}
|
2013-09-11 21:17:27 +00:00
|
|
|
fs.renameSync("./build/unpacked.crx", "./build/Caret.crx");
|
|
|
|
c();
|
|
|
|
});
|
|
|
|
});
|
2013-09-21 08:29:05 +00:00
|
|
|
|
|
|
|
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);
|
2014-02-27 06:34:02 +00:00
|
|
|
});
|
2014-03-05 23:32:15 +00:00
|
|
|
|
|
|
|
grunt.registerTask("types", "Update supported file types from ace.json", function() {
|
|
|
|
var json = JSON.parse(fs.readFileSync("config/ace.json", { encoding: "utf8" }));
|
|
|
|
var types = {};
|
|
|
|
json.modes.forEach(function(mode) {
|
|
|
|
mode.extensions.forEach(function(ext) {
|
|
|
|
types[ext] = true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
var manifest = JSON.parse(fs.readFileSync("manifest.json"));
|
2014-03-25 01:54:06 +00:00
|
|
|
manifest.file_handlers.text.extensions.forEach(function(type) {
|
2014-03-25 02:09:53 +00:00
|
|
|
if (!types[type]) console.log("Warning: Extension", type, "does not exist in ace.json");
|
2014-03-25 01:54:06 +00:00
|
|
|
types[type] = true;
|
|
|
|
});
|
2014-03-05 23:32:15 +00:00
|
|
|
manifest.file_handlers.text.extensions = Object.keys(types).sort();
|
2014-03-25 01:54:06 +00:00
|
|
|
var output = JSON.stringify(manifest, null, 2);
|
|
|
|
fs.writeFileSync("manifest.json", output);
|
2014-03-05 23:32:15 +00:00
|
|
|
});
|
|
|
|
|
2013-09-11 14:59:13 +00:00
|
|
|
};
|