-
Notifications
You must be signed in to change notification settings - Fork 263
/
Gruntfile.js
155 lines (138 loc) · 4.39 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
var _ = require('underscore');
var jasmineCfg = require('./grunt/tasks/jasmine');
function getTargetDiff () {
// Detect changed files. If no changes return '.' (all files)
var target = require('child_process').execSync('(git diff --name-only --relative || true;)' +
'| grep \'\\.js\\?$\' || true').toString();
if (target.length === 0) {
target = ['.'];
} else {
target = target.split('\n');
target.splice(-1, 1);
}
return target;
}
/**
* Grunfile runner file for CARTO.js
* framework
*
*/
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
require('time-grunt')(grunt);
var semver = require('semver');
var version = grunt.file.readJSON('package.json').version;
if (!version || !semver.valid(version)) {
grunt.fail.fatal('package.json version is not valid', 1);
}
grunt.initConfig({
secrets: {},
dist: 'dist',
tmp: '.tmp',
version: version,
gitinfo: {},
browserify: require('./grunt/tasks/browserify').task(),
exorcise: require('./grunt/tasks/exorcise').task(),
s3: require('./grunt/tasks/s3').task(version),
fastly: require('./grunt/tasks/fastly').task(),
sass: require('./grunt/tasks/scss').task(),
watch: require('./grunt/tasks/watch').task(),
connect: require('./grunt/tasks/connect').task(),
copy: require('./grunt/tasks/copy').task(),
clean: require('./grunt/tasks/clean').task(),
concat: require('./grunt/tasks/concat').task(),
terser: require('./grunt/tasks/terser').task(),
usebanner: require('./grunt/tasks/usebanner').task(),
cssmin: require('./grunt/tasks/cssmin').task(),
imagemin: require('./grunt/tasks/imagemin').task(),
jasmine: jasmineCfg,
eslint: { target: getTargetDiff() }
});
grunt.registerTask('publish_s3', function (target) {
if (!grunt.file.exists('secrets.json')) {
grunt.fail.fatal('secrets.json file does not exist, copy secrets.example.json and rename it', 1);
}
// Read secrets
grunt.config.set('secrets', grunt.file.readJSON('secrets.json'));
if (!grunt.config('secrets') ||
!grunt.config('secrets').AWS_USER_S3_KEY ||
!grunt.config('secrets').AWS_USER_S3_SECRET ||
!grunt.config('secrets').AWS_S3_BUCKET
) {
grunt.fail.fatal('S3 keys not specified in secrets.json', 1);
}
grunt.task.run([
's3'
]);
});
grunt.registerTask('invalidate', function () {
if (!grunt.file.exists('secrets.json')) {
grunt.fail.fatal('secrets.json file does not exist, copy secrets.example.json and rename it', 1);
}
// Read secrets
grunt.config.set('secrets', grunt.file.readJSON('secrets.json'));
if (!grunt.config('secrets') ||
!grunt.config('secrets').FASTLY_API_KEY ||
!grunt.config('secrets').FASTLY_CARTODB_SERVICE
) {
grunt.fail.fatal('Fastly keys not specified in secrets.json', 1);
}
grunt.task.run([
'fastly'
]);
});
grunt.registerTask('preWatch', function () {
grunt.config('doWatchify', true); // required for browserify to use watch files instead
});
grunt.registerTask('build-jasmine-specrunners', _
.chain(jasmineCfg)
.keys()
.map(function (name) {
return ['jasmine', name, 'build'].join(':');
})
.value());
// Define tasks order for each step as if run in isolation,
// when registering the actual tasks _.uniq is used to discard duplicate tasks from begin run
var allDeps = [
'clean:dist_internal',
'gitinfo',
'copy:fonts'
];
var css = allDeps
.concat([
'sass',
'concat',
'cssmin',
'imagemin'
]);
var js = allDeps
.concat([
'browserify',
'build-jasmine-specrunners'
]);
var buildJS = allDeps
.concat(js)
.concat([
'exorcise',
'terser',
'usebanner'
]);
var devJS = allDeps
.concat('preWatch')
.concat(js);
var watch = [
'connect',
'watch'
];
grunt.registerTask('default', [ 'build' ]);
grunt.registerTask('build', _.uniq(buildJS.concat(css)));
grunt.registerTask('build:js', _.uniq(buildJS));
grunt.registerTask('build:css', _.uniq(css));
grunt.registerTask('test', _.uniq(js.concat([
'eslint',
'jasmine'
])));
grunt.registerTask('dev', _.uniq(css.concat(devJS).concat(watch)));
grunt.registerTask('dev:css', _.uniq(css.concat(watch)));
grunt.registerTask('dev:js', _.uniq(devJS.concat(watch)));
};