forked from mhemmings/CANDDi_Signature
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGruntfile.js
119 lines (101 loc) · 3.11 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
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
manifest: grunt.file.readJSON('src/manifest.json'),
target: 'target/<%= pkg.name %>-<%= manifest.version %>',
jshint: {
all: [
'Gruntfile.js',
'src/**/*.js',
'src/**/*.json',
'!src/vendor/**/*.js',
'!src/vendor/**/*.json'
]
},
compress: {
zip: {
options: {
archive: '<%= target %>.zip',
mode: 'zip'
},
files: [{
cwd: 'src',
src: '**/*',
dest: '<%= pkg.name %>-<%= manifest.version %>',
expand: true
}]
}
},
});
require('matchdep').filterDev(['grunt-*']).forEach(grunt.loadNpmTasks);
grunt.registerTask('lint', 'jshint');
grunt.registerTask('build', ['bump:cmd', 'default', 'compress']);
grunt.registerTask('default', ['lint']);
/* Using the version format <major>.<minor>.<patch>: grunt bump:[major|minor|patch] */
grunt.registerTask('bump', function (ver) {
if (!ver.match('major|minor|patch|cmd')) {
grunt.log.error('Please use as: Grunt bump:[major|minor|patch]');
return true;
}
if (ver === 'cmd') {
if (grunt.option('no-bump')) {
grunt.log.writeln('Not bumping version');
return true;
}
else if (grunt.option('major')) {
ver = 'major';
}
else if (grunt.option('minor')) {
ver = 'minor';
}
else if (grunt.option('patch')) {
ver = 'patch';
}
else {
grunt.log.writeln('No bump flag passed. Not bumping version.');
return true;
}
}
grunt.log.subhead('Bumping version');
var manifestFile = 'src/manifest.json';
if (!grunt.file.exists(manifestFile)) {
grunt.log.error('No manifest found at: ' + manifestFile);
return true;
}
var manifest = grunt.file.readJSON(manifestFile);
var pkg = grunt.file.readJSON('package.json');
if (pkg.version !== manifest.version) {
grunt.log.error('Package and manifest versions do not currently match.');
return true;
}
if (!pkg.version.match(/^([0-9]+.[0-9]+.[0-9]+)$/)) {
grunt.log.error('Version is in the wrong format. Must be <major>.<minor>.<patch>');
return true;
}
grunt.log.writeln('Old version: ' + pkg.version);
var matched = pkg.version.match(/^([0-9]+).([0-9]+).([0-9]+)$/);
var major = parseInt(matched[1]);
var minor = parseInt(matched[2]);
var patch = parseInt(matched[3]);
switch (ver) {
case 'major':
major++;
minor = patch = 0;
break;
case 'minor':
minor ++;
patch = 0;
break;
case 'patch':
patch++;
break;
}
var newVersion = major + '.' + minor + '.' + patch;
pkg.version = manifest.version = newVersion;
grunt.file.write(manifestFile, JSON.stringify(manifest, null, 2));
grunt.file.write('package.json', JSON.stringify(pkg, null, 2));
grunt.log.oklns('New version: ' + newVersion);
grunt.config.set('pkg', pkg);
grunt.config.set('manifest', manifest);
});
};