This repository has been archived by the owner on Aug 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Gruntfile.js
114 lines (102 loc) · 3.48 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
module.exports = function(grunt) {
var shell = require('shelljs');
var semver = require('semver');
var DISTDIR = 'dist';
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
jshint: {
options: {
reporter: require('jshint-stylish')
},
all: ['Gruntfile.js',
'src/*.js']
},
compass: {
dist: {
options: {
sassDir: 'src',
cssDir: 'dist'
}
}
},
watch: {
css: {
files: '**/*.scss',
tasks: ['compass']
}
},
uglify: {
minify: {
options: {
mangle: false
},
files: {
'dist/magic_search.min.js': ['src/magic_search.js'],
'dist/magic_search_bootstrap.min.js': ['src/magic_search_bootstrap.js']
}
}
},
copy: {
dist: {
cwd: './src/',
expand: true,
flatten: true,
src: ['*.js', '*.html', '*.scss'],
dest: 'dist/'
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-compass');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.registerTask('dist', ['compass', 'copy', 'uglify']);
grunt.registerTask('default', ['dist']);
function run(cmd, msg){
shell.exec(cmd, {silent:true});
grunt.log.ok('cmd : '+cmd);
if( msg ){
grunt.log.ok(msg);
}
}
grunt.registerTask('release-prepare', 'Set up submodule to receive a new release', function() {
// Make sure we have the submodule in dist
run("git submodule init");
run("git submodule update");
run("cd dist; git checkout master");
// Bump version
var newVer = grunt.config('pkg').version;
var comp = grunt.file.readJSON(DISTDIR+"/bower.json");
grunt.log.writeln("Package version: " + newVer);
grunt.log.writeln("Component version: " + comp.version);
if (!semver.gt(newVer, comp.version)) {
grunt.warn("Need to up-version package.json first!");
}
});
grunt.registerTask('release-commit', 'push new build to bower component repo', function() {
// Stamp version
var newVer = grunt.config('pkg').version;
var comp = grunt.file.readJSON(DISTDIR+"/bower.json");
grunt.log.writeln("Package version: " + newVer);
grunt.log.writeln("Component version: " + comp.version);
if (!semver.gt(newVer, comp.version)) {
grunt.warn("Need to up-version package.json first!");
}
comp.version = newVer;
grunt.file.write(DISTDIR+"/bower.json", JSON.stringify(comp, null, ' ')+'\n');
// Commit submodule
// Tag submodule
run('cd dist; git commit -a -m"Build version '+ newVer +'"', "Commited to bower repo");
run('cd dist; git tag ' + newVer + ' -m"Release version '+ newVer +'"', "Tagged bower repo");
// Commit and tag this.
run('git commit -a -m"Build version '+ newVer +'"', "Commited to source repo");
run('git tag ' + newVer + ' -m"Release version '+ newVer +'"', "Tagged source repo");
run("git submodule update");
// push?
grunt.log.ok("DON'T FORGET TO PUSH BOTH!");
});
grunt.registerTask('release', 'build and push to the bower component repo',
['release-prepare', 'dist', 'release-commit']);
};