forked from CartoDB/cartodb
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathGruntfile.js
191 lines (156 loc) · 7.45 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
var _ = require('underscore');
var timer = require("grunt-timer");
var jasmineCfg = require('./lib/build/tasks/jasmine.js');
/**
* CartoDB UI assets generation
*/
module.exports = function(grunt) {
if (timer) timer.init(grunt);
var ROOT_ASSETS_DIR = './public/assets/';
var ASSETS_DIR = './public/assets/<%= pkg.version %>';
// use grunt --environment production
var env = './config/grunt_' + (grunt.option('environment') || 'development') + '.json';
if (grunt.file.exists(env)) {
env = grunt.file.readJSON(env)
} else {
throw grunt.util.error(env +' file is missing! See '+ env +'.sample for how it should look like');
}
var aws = {};
if (grunt.file.exists('./lib/build/grunt-aws.json')) {
aws = grunt.file.readJSON('./lib/build/grunt-aws.json');
}
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
aws: aws,
env: env,
assets_dir: ASSETS_DIR,
root_assets_dir: ROOT_ASSETS_DIR,
// Concat task
concat: require('./lib/build/tasks/concat').task(),
// JST generation task
jst: require('./lib/build/tasks/jst').task(),
// Compass files generation
compass: require('./lib/build/tasks/compass').task(),
// Copy assets (stylesheets, javascripts, images...)
copy: require('./lib/build/tasks/copy').task(grunt),
// Watch actions
watch: require('./lib/build/tasks/watch.js').task(),
// Clean folders before other tasks
clean: require('./lib/build/tasks/clean').task(),
jasmine: jasmineCfg,
s3: require('./lib/build/tasks/s3.js').task(),
exorcise: require('./lib/build/tasks/exorcise.js').task(),
uglify: require('./lib/build/tasks/uglify.js').task(),
browserify: require('./lib/build/tasks/browserify.js').task(),
connect: require('./lib/build/tasks/connect.js').task(),
availabletasks: require('./lib/build/tasks/availabletasks.js').task()
});
// $ grunt availabletasks
grunt.loadNpmTasks('grunt-available-tasks');
// Load Grunt tasks
require('load-grunt-tasks')(grunt);
require('./lib/build/tasks/manifest').register(grunt, ASSETS_DIR);
// builds cdb
grunt.registerTask('cdb', "builds cartodb.js", function() {
var done = this.async();
require("child_process").exec('make update_cdb', function (error, stdout, stderr) {
if (error) {
grunt.log.fail('cartodb.js not updated (due to '+ stdout +", "+ stderr +")");
} else {
grunt.log.ok('cartodb.js updated');
}
done();
});
});
grunt.registerTask('invalidate', "invalidate cache", function() {
var done = this.async();
var cmd = grunt.template.process("curl -H 'Fastly-Key: <%= aws.FASTLY_API_KEY %>' -X POST 'https://api.fastly.com/service/<%= aws.FASTLY_CARTODB_SERVICE %>/purge_all'");
console.log(cmd);
require("child_process").exec(cmd, function(error, stdout, stderr) {
if (!error) {
grunt.log.ok('CDN invalidated (fastly) -> ' + stdout);
} else {
grunt.log.error('CDN not invalidated (fastly)');
}
done();
});
});
grunt.registerTask('config', "generates assets config for current configuration", function() {
// Set assets url for static assets in our app
var config = grunt.template.process("cdb.config.set('assets_url', '<%= env.http_path_prefix %>/assets/<%= pkg.version %>');");
config += grunt.template.process("\nconsole.log('cartodbui v<%= pkg.version %>');");
grunt.file.write("lib/build/app_config.js", config);
});
grunt.registerTask('check_release', "checks release can be done", function() {
if (env === 'development') {
grunt.log.error("you can't release running development enviorment");
return false;
}
grunt.log.ok("************************************************");
grunt.log.ok(" you are going to deploy to " + env );
grunt.log.ok("************************************************");
});
grunt.event.on('watch', function(action, filepath) {
// configure copy vendor to only run on changed file
var cfg = grunt.config.get('copy.vendor');
if (filepath.indexOf(cfg.cwd) !== -1) {
grunt.config('copy.vendor.src', filepath.replace(cfg.cwd, ''));
} else {
grunt.config('copy.vendor.src', []);
}
// configure copy app to only run on changed file
var files = grunt.config.get('copy.app.files');
for (var i = 0; i < files.length; ++i) {
var cfg = grunt.config.get('copy.app.files.' + i);
if (filepath.indexOf(cfg.cwd) !== -1) {
grunt.config('copy.app.files.' + i + '.src', filepath.replace(cfg.cwd, ''));
} else {
grunt.config('copy.app.files.' + i + '.src', []);
}
}
});
grunt.registerTask('setConfig', 'Set a config property', function(name, val) {
grunt.config.set(name, val);
});
grunt.registerTask('jasmine-server', function () {
grunt.log.writeln('Deprecated, just use `grunt dev`, open http://localhost:8089 (if not opened automatically)');
});
grunt.registerTask('lint', 'lint source files', function () {
var done = this.async();
require('child_process').exec('PATH=$(npm bin):$PATH semistandard', function (error, stdout, stderr) {
if (error) {
grunt.log.fail(error);
// Filter out lines that are ignored,
// e.g. "src/foobar.js:0:0: File ignored because of your .eslintignore file. Use --no-ignore to override."
grunt.log.fail(stdout.replace(/.+--no-ignore.+(\r?\n|\r)/g, ''));
grunt.fail.warn('try `node_modules/.bin/semistandard --format src/filename.js` to auto-format code (you might still need to fix some things manually).');
} else {
grunt.log.ok('All linted files OK!');
grunt.log.writeln('Note that files listed in .eslintignore are not linted');
}
done();
});
});
// Order in terms of task dependencies
grunt.registerTask('js', ['cdb', 'browserify', 'concat:js', 'jst']);
grunt.registerTask('pre_default', ['clean', 'config', 'js']);
grunt.registerTask('test', '(CI env) Re-build JS files and run all tests. ' +
'For manual testing use `grunt jasmine` directly', ['lint', 'pre_default', 'jasmine']);
grunt.registerTask('css_editor_3', ['copy:cartofonts', 'copy:iconfont', 'copy:cartoassets', 'copy:perfect_scrollbar', 'copy:deep_insights', 'copy:cartodbjs_v4']);
grunt.registerTask('css', ['copy:vendor', 'css_editor_3', 'copy:app', 'compass', 'concat:css']);
grunt.registerTask('default', ['pre_default', 'css', 'manifest']);
grunt.registerTask('minimize', ['default', 'copy:js', 'exorcise', 'uglify']);
grunt.registerTask('release', ['check_release', 'minimize', 's3', 'invalidate']);
grunt.registerTask('build-jasmine-specrunners', _
.chain(jasmineCfg)
.keys()
.map(function (name) {
return ['jasmine', name, 'build'].join(':');
})
.value());
grunt.registerTask('dev', 'Typical task for frontend development (watch JS/CSS changes)',
['setConfig:env.browserify_watch:true', 'browserify', 'build-jasmine-specrunners', 'connect', 'watch']);
grunt.registerTask('sourcemaps', 'generate sourcemaps, to be used w/ trackjs.com for bughunting',
['setConfig:assets_dir:./tmp/sourcemaps', 'config', 'js', 'copy:js', 'exorcise', 'uglify']);
};