forked from RobinHerbots/Inputmask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
128 lines (120 loc) · 5.04 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
module.exports = function (grunt) {
function createBanner(fileName) {
return '/*!\n' +
'* ' + fileName + '\n' +
'* http://github.com/RobinHerbots/jquery.inputmask\n' +
'* Copyright (c) 2010 - <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>\n' +
'* Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php)\n' +
'* Version: <%= pkg.version %>\n' +
'*/\n';
}
function createUglifyConfig(path) {
var uglifyConfig = {};
var srcFiles = grunt.file.expand(path + "/*.js");
for (var srcNdx in srcFiles) {
var dstFile = srcFiles[srcNdx].replace("js/", ""),
dstFileMin = dstFile.replace(".js", ".min.js");
wrapAMDLoader(srcFiles[srcNdx], "build/" + dstFile, dstFile.indexOf("extension") == -1 ? ["jquery"] : ["jquery", "./jquery.inputmask"]);
uglifyConfig[dstFile] = {
dest: 'dist/inputmask/' + dstFile,
src: "build/" + dstFile,
options: { banner: createBanner(dstFile), beautify: true, mangle: false, preserveComments: "some", ASCIIOnly: true }
};
uglifyConfig[dstFileMin] = {
dest: 'dist/inputmask/' + dstFileMin,
src: "build/" + dstFile,
options: { banner: createBanner(dstFileMin), preserveComments: "some", ASCIIOnly: true }
};
}
srcFiles = grunt.file.expand(path + "/*.extensions.js");
srcFiles.splice(0, 0, "js/jquery.inputmask.js");
uglifyConfig["inputmaskbundle"] = {
files: {
'dist/<%= pkg.name %>.bundle.js': srcFiles
},
options: { banner: createBanner('<%= pkg.name %>.bundle'), beautify: true, mangle: false, preserveComments: "some", ASCIIOnly: true }
}
uglifyConfig["inputmaskbundlemin"] = {
files: {
'dist/<%= pkg.name %>.bundle.min.js': srcFiles
},
options: { banner: createBanner('<%= pkg.name %>.bundle'), preserveComments: "some", ASCIIOnly: true }
}
return uglifyConfig;
}
function wrapAMDLoader(src, dst, dependencies) {
function stripClosureExecution() {
return srcFile.replace(new RegExp("\\(jQuery\\).*$"), "");
}
var srcFile = grunt.file.read(src),
dstContent = "(function (factory) {" +
"if (typeof define === 'function' && define.amd) {" +
"define(" + JSON.stringify(dependencies) + ", factory);" +
"} else {" +
"factory(jQuery);" +
"}}\n" + stripClosureExecution() + ");";
grunt.file.write(dst, dstContent);
}
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: createUglifyConfig("js"),
clean: ["dist"],
qunit: {
files: ['qunit/qunit.html']
},
bump: {
options: {
files: ['package.json', 'bower.json', 'composer.json', 'component.json'],
updateConfigs: ['pkg'],
commit: false,
createTag: false,
push: false
}
},
release: {
options: {
bump: false,
commitMessage: 'jquery.inputmask <%= version %>'
}
},
nugetpack: {
dist: {
src: function () { return process.platform === "linux" ? 'nuget/jquery.inputmask.linux.nuspec' : 'nuget/jquery.inputmask.nuspec'; }(),
dest: 'dist/',
options: {
version: '<%= pkg.version %>'
}
}
},
nugetpush: {
dist: {
src: 'dist/jQuery.InputMask.<%= pkg.version %>.nupkg'
}
},
shell: {
options: {
stderr: false
},
gitcommitchanges: {
command: ['git add .',
'git reset -- package.json',
'git commit -m "jquery.inputmask <%= pkg.version %>"'
].join('&&')
}
}
});
// Load the plugin that provides the tasks.
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-contrib-qunit');
grunt.loadNpmTasks('grunt-bump');
grunt.loadNpmTasks('grunt-release');
grunt.loadNpmTasks('grunt-nuget');
grunt.loadNpmTasks('grunt-shell');
grunt.registerTask('publish:patch', ['clean', 'bump:patch', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
grunt.registerTask('publish:minor', ['clean', 'bump:minor', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
grunt.registerTask('publish:major', ['clean', 'bump:major', 'uglify', 'shell:gitcommitchanges', 'release', 'nugetpack', 'nugetpush']);
// Default task(s).
grunt.registerTask('default', ['bump:prerelease','clean', 'uglify']);
};