forked from CodeboxIDE/codebox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
274 lines (245 loc) · 8.14 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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
module.exports = function (grunt) {
var fs = require('fs');
var path = require("path");
var pkg = require("./package.json");
var _ = require('lodash');
// Path to the client src
var clientPath = path.resolve(__dirname, "client");
// Constants
var NW_VERSION = "0.8.4";
// Load grunt modules
grunt.loadNpmTasks('hr.js');
grunt.loadNpmTasks('grunt-exec');
grunt.loadNpmTasks('grunt-contrib-compress');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-copy');
// Init GRUNT configuraton
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
hr: {
build: {
// Base directory for the application
"base": clientPath,
// Application name
"name": "Codebox",
// Mode debug
"debug": process.env.CLIENT_DEBUG != null,
// Main entry point for application
"main": "main",
"index": grunt.file.read(path.resolve(clientPath, "index.html")),
// Build output directory
"build": path.resolve(clientPath, "build"),
// Static files mappage
"static": {
"images": path.resolve(clientPath, "resources", "images"),
"fonts": path.resolve(clientPath, "resources", "fonts")
},
// Stylesheet entry point
"style": path.resolve(clientPath, "resources/stylesheets/main.less"),
// Modules paths
'paths': {
'moment': 'vendors/moment'
},
"shim": {
'resources/resources': {
deps: [
'vendors/bootstrap/carousel',
'vendors/bootstrap/dropdown',
'vendors/bootstrap/button',
'vendors/bootstrap/modal',
'vendors/bootstrap/affix',
'vendors/bootstrap/alert',
'vendors/bootstrap/collapse',
'vendors/bootstrap/tooltip',
'vendors/bootstrap/popover',
'vendors/bootstrap/scrollspy',
'vendors/bootstrap/tab',
'vendors/bootstrap/transition',
'vendors/taphold'
]
},
'vendors/socket.io': {
exports: 'io'
},
'vendors/crypto': {
exports: 'CryptoJS'
},
'vendors/diff_match_patch': {
exports: 'diff_match_patch'
},
'vendors/mousetrap': {
exports: 'Mousetrap'
},
'vendors/filer': {
exports: 'Filer',
deps: [
'vendors/idb.filesystem'
]
}
},
'args': {
'version': pkg.version,
'debug': process.env.CLIENT_DEBUG != null
},
'options': {
}
}
},
exec: {
publish: {
command: "npm publish",
cwd: '.tmp/',
stdout: true,
stderr: true
},
build_files_editor: {
command: "npm install",
cwd: './addons/cb.files.editor/',
stdout: true,
stderr: true
},
clean_addons: {
command: "rm -rf */**/addon-built.js ./addons/**/node_modules",
cwd: '.',
stdout: true,
stderr: true
},
clean_addons_tmp: {
command: "rm -rf */**/addon-built.js",
cwd: '.tmp/',
stdout: true,
stderr: true
}
},
copy: {
// Copy most files over
tmp: {
expand: true,
dot: false,
cwd: './',
dest: '.tmp/',
src: [
// Most files except the ones below
"./**",
// Ignore gitignore
"!.gitignore",
// Ignore dev related things
"!./tmp/**",
"!./.git/**",
"!./.addons/**",
"!./appBuilds/**",
// grunt.file.copy duplicates symbolic and hard links
// so we need to copy it with the shell
"!./extras/**",
// Only take "./client/build"
"!./client/**",
"./client/build/**",
// Ignore some build time only modules
"./node_modules/.bin/**",
"!./node_modules/grunt/**",
"!./node_modules/grunt-*/**",
"!./node_modules/hr.js/**",
// Exclude test directories from node modules
"!./node_modules/**/test/**",
],
// Preserve permissions
options: {
mode: true
}
}
},
compress: {
tmp: {
options: {
mode: 'gzip',
pretty: true
},
expand: true,
src: [
// Codebox Built addons
'.tmp/addons/*/addon-built.js',
// Ace source
'.tmp/addons/cb.files.editor/ace/**',
// HR.js application
'.tmp/client/build/static/application.{js,css}'
],
filter: function(src) {
// Compressable file formats
if(!_.contains([
'js',
'css',
'svg',
'less',
'html',
'snippets'
],
path.extname(src).slice(1)
)) return false;
try {
// We don't want to gzip tiny files
// Skip files < 10kb
return fs.statSync(src).size > 10*1024;
} catch(err) {}
return false;
}
}
},
clean: {
tmp: ['.tmp/']
},
buildAddons: {
tmp: {
addonsFolder: ".tmp/addons/"
},
dev: {
addonsFolder: "./addons/",
force: false
}
}
});
// Load in any and all tasks in the `tasks` folder
grunt.loadTasks('tasks');
// Rebuild all addons
grunt.registerTask('rebuildAddons', [
'exec:clean_addons',
'buildAddons:dev'
]);
// Build
grunt.registerTask('build', [
'hr',
'exec:build_files_editor',
'buildAddons:dev'
]);
// Build tmp directory
grunt.registerTask('tmp', [
'build',
'clean:tmp',
'copy:tmp',
'exec:clean_addons_tmp',
'buildAddons:tmp',
'compress:tmp'
]);
// Publish to NPM
grunt.registerTask('publish', [
'tmp',
'exec:publish',
'clean:tmp'
]);
// Run
grunt.registerTask('run', function() {
var done = this.async();
var options = this.options({});
grunt.util.spawn({
cmd: "node",
opts: {
cwd: path.resolve(__dirname),
stdio: 'inherit'
},
args: ["./bin/codebox.js", "run"]
}, done);
});
grunt.registerTask('default', [
'build',
'run'
]);
};