forked from kashiif/copy-urls-expert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
123 lines (104 loc) · 3.42 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
"use strict";
/**************************************
* Author: Kashif Iqbal Khan
* Email: [email protected]
* License: MIT
* Copyright (c) 2013 Kashif Iqbal Khan
**************************************/
module.exports = function(grunt) {
var path = require("path");
var pkg = grunt.file.readJSON("package.json"),
srcDir = "src/", // Path of directory where source code resides
distdir = "dist/",
tempDir = distdir + "temp/",
versionForFileSystem = pkg.version.replace(/\./g, "-");
// Project configuration.
grunt.initConfig({
pkg: pkg,
clean: {
prod: [tempDir, distdir]
},
// Copy files to tempDir, and only change things in there
copy: {
common: {
files: [
{expand: true, cwd: srcDir, src : ["chrome.manifest" ], dest: tempDir },
{expand: true, cwd: srcDir, src : ["**/*.css","**/*.js","**/*.jsm", "**/*.xul", "**/*.png","**/*.jpg"], dest: tempDir }
]
},
prod: {
files: [
{expand: true, cwd: srcDir, src : ["**/*.dtd", "**/*.properties", "!**/*_amo_*.dtd"], dest: tempDir }
]
},
babelzilla: {
files: [
{expand: true, cwd: srcDir, src : ["**/*.dtd", "**/*.properties", "**/cue_translator.txt"], dest: tempDir }
]
}
},
"string-replace": {
install_rdf: { /* Task to replace tokens in install.rdf */
options: {
replacements: [
{
pattern: /\<em\:creator\>.+\<\/em\:creator\>/g,
replacement: "<em:creator>" + pkg.author.name + "</em:creator>"
},
{
pattern: /\<em\:homepageURL\>.*\<\/em\:homepageURL\>/g,
replacement: "<em:homepageURL>" + pkg.homepage + "</em:homepageURL>"
},
{
pattern: /\<em\:description\>.*\<\/em\:description\>/g,
replacement: "<em:description>" + pkg.description + "</em:description>"
}
]
},
src: srcDir + "install.rdf",
dest: tempDir + "install.rdf"
},
all_files: { /* Task to replace tokens in all files */
options: {
replacements: [{
pattern: /___version___/g,
replacement: pkg.version
},
{
pattern: /__version__/g,
replacement: versionForFileSystem
}]
},
files: [
{expand: true, cwd: tempDir, src : ["**/*.*", "!**/*.png", "!**/*.jpg", "!**/*.jpeg", "!**/*.gif" ], dest: tempDir }
]
}
},
compress: {
prod: {
options: {
archive: distdir + pkg.name + "-" + pkg.version + ".xpi",
mode: "zip"
},
files: [ { expand: true, cwd: tempDir, src: "**/**" }]
}
}
});
grunt.loadNpmTasks("grunt-contrib-clean");
grunt.loadNpmTasks("grunt-contrib-copy");
grunt.loadNpmTasks("grunt-string-replace");
grunt.loadNpmTasks("grunt-contrib-compress");
// $: grunt bump
grunt.loadNpmTasks("grunt-bump");
grunt.registerTask("renameVersionDir", "renames the __version__ directory", function() {
var fs = require("fs");
var oldName = path.resolve(path.join(tempDir, "__version__")),
newName = path.resolve(path.join(tempDir, versionForFileSystem));
if (fs.existsSync(oldName)) {
fs.renameSync(oldName, newName);
}
});
// Default task(s).
grunt.registerTask("default", ["clean", "copy:common", "copy:prod", "string-replace", "renameVersionDir", "compress"]);
grunt.registerTask("babelzilla", ["clean", "copy:common", "copy:babelzilla", "string-replace", "renameVersionDir", "compress"]);
};