-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGruntfile.js
More file actions
112 lines (97 loc) · 4.07 KB
/
Gruntfile.js
File metadata and controls
112 lines (97 loc) · 4.07 KB
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
var exec = require('child_process').exec;
var execSync = require('child_process').execSync;
var fs = require('fs');
module.exports = function(grunt) {
grunt.initConfig({
jshint: {
all: ['Gruntfile.js', 'src/**/*.js', 'test/*.js', 'test/src/**/*.js']
},
uglify: {
dist: {
files: {
'dist/object-keys-mapper.min.js': 'src/object-keys-mapper.js'
}
}
},
usebanner: {
banner: {
options: {
position: 'top',
linebreak: true,
process: function() {
var latestTag = execSync("git describe --tags").toString().split('-')[0];
var firstYear = "2015";
var lastYear = execSync("git log --format='%ai' | head -n 1").toString().split('-')[0];
return "/*\n" +
" * JS Object Keys Mapper v" + latestTag + " (https://github.com/the-software-factory/js-object-keys-mapper)\n" +
" * Copyright (c) " + ((firstYear === lastYear) ? firstYear : (firstYear + "-" + lastYear)) + " Vendini srl <vendini@pec.it>\n" +
" * Licensed under MIT (https://github.com/the-software-factory/js-object-keys-mapper/blob/master/LICENSE.md)\n" +
" */";
}
},
files: {
src: ['dist/object-keys-mapper.min.js']
}
}
},
watch: {
scripts: {
files: ['Gruntfile.js', 'src/**/*.js', 'test/*.js', 'test/src/**/*.js'],
tasks: ['default']
}
},
conventionalChangelog: {
options: {
changelogOpts: {
preset: 'jshint',
releaseCount: 0,
transform: function(commit, cb) {
if (typeof commit.gitTags === 'string') {
var rtag = /tag:\s*[v=]?(.+?)[,\)]/gi;
var match = rtag.exec(commit.gitTags);
rtag.lastIndex = 0;
if (match) {
commit.version = match[1];
}
}
commit.shortDesc += " [" + commit.hash.slice(0, 7) +
"](https://github.com/the-software-factory/js-object-keys-mapper/commit/" + commit.hash + ")";
delete commit.hash;
cb(null, commit);
}
}
},
release: {
src: 'CHANGELOG.md'
}
}
});
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-banner');
grunt.loadNpmTasks('grunt-conventional-changelog');
grunt.registerTask("emptyTheChangelog", function() {
fs.truncateSync(grunt.config.get("conventionalChangelog.release.src"), 0);
});
grunt.registerTask("changelogCommit", function() {
var done = this.async();
var gitAdder = exec('git add CHANGELOG.md');
gitAdder.on("exit", function(exitCode) {
if (exitCode !== 0) {
grunt.fail.fatal("changelogCommit task couldn't exec git add command");
}
var gitCommitter = exec('git commit -m "CHANGELOG.md Updated"');
gitCommitter.on("exit", function(exitCode) {
if (exitCode !== 0) {
grunt.fail.fatal("changelogCommit task couldn't exec git commit command");
}
grunt.log.ok("Changelog commit is ready");
done();
});
});
});
grunt.registerTask("default", ["jshint", "uglify", "usebanner"]);
grunt.registerTask("development", "watch");
grunt.registerTask("changelog", ["emptyTheChangelog", "conventionalChangelog", "changelogCommit"]);
};