-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGruntfile.js
158 lines (122 loc) · 3.66 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
"use strict";
/**************************************
* Author: Kashif Iqbal Khan
* Email: [email protected]
* License: MIT
* Copyright (c) 2013-2014 Kashif Iqbal Khan
**************************************/
var distdir = "dist/",
tempDir = distdir + "temp/",
srcDir = "src/"; // Path of directory where source code resides
module.exports = function(grunt) {
var path = require("path"),
fs = require("fs");
var pkg = grunt.file.readJSON("package.json"),
versionForFileSystem = pkg.version.replace(/\./g, "-");
// Project configuration.
grunt.initConfig({
pkg: pkg,
tempDir: tempDir,
clean: {
prod: [tempDir]
},
// Copy files to tempDir, and only change things in there
copy: {
prod: {
files: [
{expand: true, cwd: srcDir, src : ["**/*.*", "!menu-card.php"], dest: tempDir }
]
},
},
"string-replace": {
plugin_file: { /* Task to replace tokens in plugin file */
options: {
replacements: [{
pattern: /___version___/g,
replacement: pkg.version
}]
},
files: [
{expand: true, dest: tempDir, cwd: tempDir, src : ["*.php"] }
]
}
},
preprocess: {
options: {
// NOTE that if context is defined in the task, it will replace the global context, (not merge it)
// This looks like a grunt bug where deep merging is not performed for options
context : {
}
},
prod: {
options: {
//inline: true,
context : {
PRODUCTION: true
}
},
files: {
"<%=tempDir%>menu-card.php": [ srcDir + "menu-card.php"]
}
},
demo: {
options: {
},
files: {
"<%=tempDir%>menu-card.php": [ srcDir + "menu-card.php"]
}
}
},
"generate-translation": {
full: {
options: {
method:'touch'
},
files: {
"src/lang/menu-card.pot": [ "src/inc/*.php", "!**/index.php"]
}
},
partial: {
files: {
"src/lang/menu-card.pot": [ "src/inc/*.php", "!**/index.php"]
}
}
},
compress: {
prod: {
options: {
archive: distdir + pkg.name + "-" + pkg.version + ".zip",
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-preprocess");
grunt.loadNpmTasks("grunt-contrib-compress");
grunt.loadTasks("./grunt-modules/tasks/");
grunt.registerTask("index-php", "Copies empty index.php file to every folder", function() {
// Force task into async mode and grab a handle to the "done" function.
var done = this.async();
var fs = require('fs'),
copyHelper = require("./grunt-modules/copyhelper");
copyHelper.walk(tempDir, function(error, found) {
if (error) {
grunt.fail.fatal(error);
done();
return;
}
found.dirs.forEach(function(item){
fs.writeFileSync( path.resolve(path.join(item, "index.php")) , "<?php\r\n");
});
done();
});
});
// Default task(s).
grunt.registerTask("default", ["clean", /*"generate-translation:partial",*/ "copy", "preprocess:prod", "string-replace", "index-php", "compress"]);
grunt.registerTask("demo", ["clean", /*"generate-translation:partial",*/ "copy", "preprocess:demo", "string-replace", "index-php", "compress"]);
grunt.registerTask("l8n", ["generate-translation:full"]);
};