forked from iwaffles/numbro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
160 lines (147 loc) · 4.54 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
var fs = require('fs');
var path = require('path');
module.exports = function(grunt) {
'use strict';
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
copy: {
main: {
files: [
{src: 'numbro.js', dest: 'dist/numbro.js'},
]
}
},
concat: {
languages: {
src: [
'languages/**/!(index).js',
],
dest: 'dist/languages.js',
},
},
uglify: {
target: {
files: [
{ src: [ 'dist/languages.js' ], dest: 'dist/languages.min.js', },
{ src: [ 'numbro.js' ], dest: 'dist/numbro.min.js', },
].concat( fs.readdirSync('./languages').map(function (fileName) {
var lang = path.basename(fileName, '.js');
return {
src: [path.join('languages/', fileName)],
dest: path.join('dist/languages/', lang + '.min.js'),
};
}))
},
options: {
preserveComments: 'some',
},
},
bump: {
options: {
files: [
'package.json',
'bower.json',
'component.json',
'numbro.js',
],
updateConfigs: ['pkg'],
commit: false,
createTag: false,
push: false,
globalReplace: true,
regExp: new RegExp('([\'|\"]?version[\'|\"]?[ ]*[:=][ ]*[\'|\"]?)'+
'(\\d+\\.\\d+\\.\\d+(-\\.\\d+)?(-\\d+)?)[\\d||A-a|.|-]*([\'|\"]?)')
},
},
confirm: {
release: {
options: {
question: 'Are you sure you want to publish a new release' +
' with version <%= pkg.version %>? (yes/no)',
continue: function(answer) {
return ['yes', 'y'].indexOf(answer.toLowerCase()) !== -1;
}
}
}
},
release:{
options: {
bump: false,
commit: false,
tagName: '<%= version %>',
},
},
nodeunit: {
all: ['tests/**/*.js'],
},
jshint: {
options: {
jshintrc : '.jshintrc'
},
all: [
'Gruntfile.js',
'numbro.js',
'languages/**/*.js'
]
},
jscs: {
src: [
'Gruntfile.js',
'numbro.js',
'languages/**/*.js'
],
options: {
config: '.jscsrc',
esnext: true, // If you use ES6 http://jscs.info/overview.html#esnext
verbose: true, // If you need output with rule names http://jscs.info/overview.html#verbose
validateIndentation: 4
}
}
});
grunt.loadNpmTasks('grunt-contrib-nodeunit');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-confirm');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-jscs');
grunt.registerTask('default', [
'test'
]);
grunt.registerTask('lint', [
'jshint',
'jscs'
]);
grunt.registerTask('test', [
'lint',
'nodeunit'
]);
grunt.registerTask('build', [
'test',
'languages',
'copy:main',
'concat',
'uglify'
]);
// wrap grunt-release with confirmation
grunt.registerTask('publish', [
'confirm:release',
'release',
]);
// This creates an index file for the languages
grunt.registerTask('languages', function() {
var dir = './languages';
var langFiles = fs.readdirSync(dir).filter(function(file) {
if(file !== 'index.js') {
return true;
}
}).map(function(file) {
return 'exports[\'' + file.replace('.js', '') + '\'] = require(\'./' + file + '\');';
}).join('\n');
fs.writeFileSync(dir + '/index.js', langFiles);
});
// Travis CI task.
grunt.registerTask('travis', ['test']);
};