-
Notifications
You must be signed in to change notification settings - Fork 36
/
Gruntfile.js
151 lines (133 loc) · 4.29 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
var src = ['./ng-rollbar.js'];
var dst = './ng-rollbar.js';
var lodash = require('lodash');
var https = require('https');
var fs = require('fs'),
byline = require('byline');
module.exports = function(grunt) {
grunt.initConfig({
bwr: grunt.file.readJSON('bower.json'),
jshint: {
files: src
},
release: {
options: {
npm: true,
npmtag: false,
commit: false,
file: 'package.json',
additionalFiles: ['bower.json'],
beforeBump: ['fail', 'jshint'],
afterBump: [
'ngAnnotate',
'uglify',
'gitcommit:for-release'
],
}
},
ngAnnotate: {
options: {
singleQuotes: true,
},
app: {
files: {
'ng-rollbar.min.js': src
},
},
},
uglify: {
options: {
mangle: true,
sourceMap: true,
banner: '/**\n' +
' * @license <%= bwr.name %> <%= bwr.version %> (<%= grunt.template.today("dd-mm-yyyy") %>)\n' +
' * (c) 2015-2017 IdentPro GmbH\n' +
' * License: MIT\n' +
' */'
},
my_target: {
files: {
'ng-rollbar.min.js': ['ng-rollbar.min.js']
}
}
},
gitcommit: {
'for-release': {
options: {
message: 'adding generated files for release preparation'
},
files: {
src: [dst, 'bower.json', 'package.json', 'ng-rollbar.min.js', 'ng-rollbar.min.js.map']
}
},
'lib-update': {
options: {
message: 'integrated rollar snippet in version <here-to-be-specific-version>'
},
files: {
src: [dst]
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-ng-annotate');
grunt.loadNpmTasks('grunt-git');
grunt.registerTask('default', ['jshint']);
grunt.registerTask('update-lib', 'integrate a new rollbar client lib version', function(version) {
// Tell grunt this task is asynchronous.
var done = this.async();
grunt.log.writeln("starting update-lib with version: " + version);
var url = "https://raw.githubusercontent.com/rollbar/rollbar.js/master/dist/rollbar.snippet.js";
grunt.log.writeln("requesting '" + url + "' ...");
var lib = "";
https.get(url, function(res) {
grunt.log.writeln("Got response: " + res.statusCode);
var snippetCode = "";
res.on('data', function(snippet) {
snippetCode += snippet;
})
res.on('end', function() {
var stream = byline(fs.createReadStream(dst, { encoding: 'utf8' }), { keepEmptyLines: true });
var newFileContent = "";
var waiting = false;
stream.on('data', function(line) {
if(line.indexOf("/* rollbar client lib end */") > -1) {
grunt.log.writeln("found /* rollbar client lib end */")
waiting = false;
}
if(!waiting) { newFileContent += line + "\n" }
if(line.indexOf("/* rollbar client lib start */") > -1) {
grunt.log.writeln("found /* rollbar client lib start */")
grunt.log.writeln("inserting new lib snippet")
waiting = true;
newFileContent += ' // ' + url + "\n"
newFileContent += ' ' + snippetCode + "\n"
}
});
stream.on('end', function() {
grunt.log.writeln("overwriting ng-rollbar.js with new lib");
fs.writeFile(dst, newFileContent.trim() + "\n");
// commit changes
grunt.config('gitcommit.lib-update.options.message', "integrated rollbar snippet in version " + version);
grunt.task.run('gitcommit:lib-update');
done();
});
});
}).on('error', function(e) {
grunt.log.writeln("Got error: " + e.message);
});
});
grunt.registerTask('help', 'display help message', function() {
grunt.log.writeln("How to release a new version");
grunt.log.writeln("----------------------------");
grunt.log.writeln();
grunt.log.writeln("1. upgrade the lib by doing");
grunt.log.writeln(" $> grunt update-lib:1.x.y");
grunt.log.writeln();
grunt.log.writeln("2. release");
grunt.log.writeln(" $> grunt release:(major/minor/patch)");
});
}