forked from gooddata/gooddata-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
284 lines (265 loc) · 9.31 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
275
276
277
278
279
280
281
282
283
284
// Copyright (C) 2007-2014, GoodData(R) Corporation. All rights reserved.
const webpack = require('webpack');
const webpackConfig = require('./webpack.config.js');
module.exports = (grunt) => {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
gitInfo: '',
license: grunt.file.read('tools/license.tmpl'),
eslint: {
options: {
config: '.eslintrc'
},
all: {
src: [
'src/**/*.js',
'test/**/*.js'
]
}
},
copy: {
examples: {
src: 'dist/gooddata.js',
dest: 'examples/gooddata.js'
}
},
karma: {
unit: {
configFile: 'tools/karma.conf.js',
singleRun: false,
autoWatch: true,
background: false
},
ci: {
configFile: 'tools/karma.conf.js',
singleRun: true,
autoWatch: false
}
},
mochaTest: {
test: {
options: {
reporter: 'spec',
quiet: false,
require: [
'babel-register',
'isomorphic-fetch',
() => {
global.expect = require('expect.js');
},
() => {
global.sinon = require('sinon');
}
]
},
src: ['test/*_test.js']
}
},
grizzly: {
options: {
root: 'examples/'
}
},
watch: {
options: {
interval: 500
},
js: {
files: ['src/*.js', 'examples/**/*.js', 'examples/**/*.html', '!examples/gooddata.js'],
tasks: ['webpack:build-dev', 'copy:examples'],
nospawn: true
},
tests: {
files: ['src/*.js', 'test/*_test.js'],
tasks: ['mochaTest:test', 'karma:unit:run'],
nospawn: true
}
},
webpack: {
options: webpackConfig,
'build-dev': {},
build: {
output: {
filename: './dist/gooddata.min.js'
},
plugins: [
new webpack.optimize.UglifyJsPlugin()
].concat(webpackConfig.plugins)
}
},
yuidoc: {
compile: {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
options: {
paths: 'src/',
themedir: 'tools/yuidoc/theme/',
outdir: 'docs/'
}
},
gh_pages: {
name: '<%= pkg.name %>',
description: '<%= pkg.description %>',
version: '<%= pkg.version %>',
url: '<%= pkg.homepage %>',
options: {
paths: 'src/',
themedir: 'tools/yuidoc/theme-gh-pages/',
outdir: 'pages/api/'
}
}
},
bump: {
options: {
files: ['package.json', 'bower.json'],
updateConfigs: ['pkg'], // for a proper banner in disted file
commit: true,
commitMessage: 'Release v%VERSION%',
commitFiles: ['package.json', 'bower.json'],
createTag: true,
tagName: 'v%VERSION%',
push: true,
pushTo: 'upstream'
}
},
'gh-pages': {
options: {
base: 'pages',
message: 'DOC: Updated gh-pages'
},
src: '**/*'
}
});
grunt.registerTask('getGitInfo', 'Get latest commit hash', () => {
const currentTask = grunt.task.current;
const done = currentTask.async();
const child = grunt.util.spawn({
cmd: 'git',
args: ['log', '-1', '--format="%h"']
}, (err, result, code) => {
if (err) {
grunt.fail.fatal(err);
}
grunt.config.set('gitInfo', result.stdout);
done(!code);
});
child.stdout.pipe(process.stdout);
child.stderr.pipe(process.stderr);
});
grunt.loadNpmTasks('grunt-webpack');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-grizzly');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-karma');
grunt.loadNpmTasks('grunt-contrib-yuidoc');
grunt.loadNpmTasks('grunt-gh-pages');
grunt.loadNpmTasks('grunt-mocha-test');
grunt.loadNpmTasks('gruntify-eslint');
grunt.registerTask('default', ['dist']);
grunt.registerTask('dist', [
'getGitInfo',
'eslint',
'webpack:build-dev',
'webpack:build',
'copy'
]);
grunt.registerTask('bump-gh-pages', ['yuidoc:gh_pages', 'gh-pages-clean', 'gh-pages']);
grunt.registerTask('init-bower-repo', 'Initializes repository in ./dist', () => {
const exec = require('child_process').exec;
const gitUri = grunt.file.readJSON('bower.json').repository.url;
const currentTask = grunt.task.current;
const done = currentTask.async();
exec(`${'mkdir -p dist && cd dist && rm -rf ./* && git init && ' +
'git remote add bower '}${gitUri} && ` +
'git pull bower master', (err, stdout, stderr) => {
if (err) {
grunt.fatal('could not init bower repository');
grunt.log.errorlns(stderr);
}
grunt.log.writeln('Inited bower repository in ./dist');
done();
});
});
grunt.registerTask('release-bower-component', 'Tag, commit and push dist files to bower component repo.', () => {
const exec = require('child_process').exec;
const async = require('async');
const currentTask = grunt.task.current;
const done = currentTask.async();
const version = grunt.config.get('pkg.version');
const copyPackageDescriptionStep = (callback) => {
exec('cp bower.json LICENSE.txt dist', (err, stdout, stderr) => {
if (err) {
callback(`Could not copy bower.json or LICENSE.txt to dist${stderr}`);
}
grunt.log.writeln('Copied bower.json and LICENSE.txt to dist');
callback(null);
});
};
const commitBowerReleaseStep = (callback) => {
const commitMsg = grunt.config.get('bump.options.commitMessage').replace('%VERSION%', version);
exec(`cd dist && git add . && git commit -m "${commitMsg}"`, (err, stdout, stderr) => {
if (err) {
callback(`Could not commit${stderr}`);
}
grunt.log.writeln(`Commiting bower release ${version}`);
callback(null);
});
};
const tagBowerReleaseStep = (callback) => {
const tagName = grunt.config.get('bump.options.tagName').replace('%VERSION%', version);
exec(`cd dist && git tag "${tagName}"`, (err, stdout, stderr) => {
if (err) {
callback(`Could not tag${stderr}`);
}
grunt.log.writeln(`Tagging bower release ${version}`);
callback(null);
});
};
const pushBowerComponentStep = (callback) => {
exec('cd dist && git push -u bower master && git push bower --tags', (err, stdout, stderr) => {
if (err) {
callback(`Could not push bower commit and tag${stderr}`);
}
grunt.log.writeln(`Pushed ${version} commit and tag`);
callback(null);
});
};
const cleanupDistStep = (callback) => {
exec('cd dist && rm -rf .git', (err, stdout, stderr) => {
if (err) {
callback(`Could not remove dist/.git files\n${stderr}`);
}
callback(null);
});
};
async.series([
copyPackageDescriptionStep,
commitBowerReleaseStep,
tagBowerReleaseStep,
pushBowerComponentStep,
cleanupDistStep
], (err) => {
if (err) {
grunt.fatal(err);
}
done();
});
});
grunt.registerTask('release', (target) => {
grunt.task.run(
'test-ci',
`bump:${target}`,
'init-bower-repo',
'dist',
'release-bower-component'
);
});
grunt.registerTask('test', ['eslint', 'karma:unit:start', 'watch:tests']);
grunt.registerTask('test-ci', ['eslint', 'karma:ci', 'mochaTest']);
grunt.registerTask('dev', ['grizzly', 'watch:js']);
grunt.registerTask('doc', ['yuidoc']);
grunt.registerTask('validate', ['eslint']);
};