Skip to content

Commit fc15b0c

Browse files
committed
Merge pull request victorjonsson#404 from ray-print/150307/804pm
Add UMD to module files
2 parents a87b9ce + d586e44 commit fc15b0c

30 files changed

+1455
-1429
lines changed

Gruntfile.js

Lines changed: 77 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards
22
//compatibility
33
const DIST_DIR = './form-validator';
4-
const MAIN_PLUGIN_FILE = './form-validator/jquery.form-validator';
4+
const MAIN_PLUGIN_FILE = 'jquery.form-validator';
55
const SRC_DIR = './src';
66
const MAIN_DIR = '/main/';
7-
const MODULE_DIR = '/modules/';
8-
const LANG_DIR = '/lang/';
7+
const MODULE_DIR = '/modules';
8+
const LANG_DIR = '/lang';
99
const CSS_FILE = 'theme-default.css';
10+
const CORE_VALIDATORS = 'core-validators.js'; //must come at end of concatted file
11+
const coreValidatorsPath = SRC_DIR + MAIN_DIR + CORE_VALIDATORS;
1012

1113
var fs = require('fs'),
1214
readFile = function (file) {
@@ -16,7 +18,8 @@ var fs = require('fs'),
1618
fs.writeFileSync(path, readFile(path).replace(from, to));
1719
};
1820

19-
function initializeGruntConfig(grunt, filesToBuild) {
21+
function initializeGruntConfig(grunt) {
22+
2023
grunt.initConfig({
2124

2225
// Import package manifest
@@ -34,12 +37,36 @@ function initializeGruntConfig(grunt, filesToBuild) {
3437
" */\n"
3538
},
3639

37-
// Concat definitions.
38-
concat: filesToBuild.concat,
40+
concat: {
41+
main:{
42+
files: [
43+
//This concatenates the core validators file after the other files
44+
//Per: http://gruntjs.com/configuring-tasks
45+
{
46+
src: [SRC_DIR + MAIN_DIR+'*.js', '!' + coreValidatorsPath, coreValidatorsPath],
47+
dest: DIST_DIR + '/' + MAIN_PLUGIN_FILE + '.js'
48+
},
49+
{
50+
src: [SRC_DIR + MAIN_DIR+'*.js', '!' + coreValidatorsPath, coreValidatorsPath],
51+
dest: DIST_DIR + '/' + MAIN_PLUGIN_FILE + '.min.js'
52+
}]
53+
},
54+
options: {
55+
banner: "<%= meta.banner %>"
56+
}
57+
},
3958

4059
cssmin: {
4160
target: {
42-
files: filesToBuild.cssFiles
61+
files: [
62+
{
63+
dest: DIST_DIR,
64+
src: CSS_FILE,
65+
cwd: SRC_DIR,
66+
expand: true,
67+
ext: '.min.css'
68+
}
69+
]
4370
}
4471
},
4572
// Lint definitions
@@ -52,7 +79,21 @@ function initializeGruntConfig(grunt, filesToBuild) {
5279
},
5380

5481
// Minify definitions
55-
uglify: filesToBuild.uglify,
82+
uglify: {
83+
options: {
84+
banner: "<%= meta.banner %>"
85+
},
86+
main: {
87+
files: [
88+
{
89+
expand: true,
90+
cwd: DIST_DIR + '/',
91+
src: ['**/*.js', '!' + MAIN_PLUGIN_FILE +'.js'],
92+
dest: DIST_DIR + '/'
93+
}
94+
]
95+
}
96+
},
5697

5798
// watch for changes to source
5899
// Better than calling grunt a million times
@@ -79,97 +120,49 @@ function initializeGruntConfig(grunt, filesToBuild) {
79120
}
80121
},
81122

123+
copy: {
124+
main: {
125+
files: [
126+
{
127+
src: SRC_DIR + '/' + CSS_FILE,
128+
dest: DIST_DIR + '/' + CSS_FILE
129+
},
130+
{
131+
cwd: SRC_DIR + '/' + MODULE_DIR,
132+
src: '**',
133+
dest: DIST_DIR + '/',
134+
expand: true
135+
},
136+
{
137+
cwd: SRC_DIR + '/' + LANG_DIR,
138+
src: '**',
139+
dest: DIST_DIR + LANG_DIR +'/',
140+
expand: true
141+
}]
142+
}
143+
},
144+
82145
clean: [DIST_DIR + '/'],
146+
83147
umd: {
84148
main: {
85149
options: {
86-
src: MAIN_PLUGIN_FILE + '.js',
150+
src: DIST_DIR + '/**/*.js',
151+
dest: './',
87152
deps: {
88153
default: ['jQuery'],
89154
amd: [{'jquery': 'jQuery'}],
90155
cjs: [{'jquery': 'jQuery'}]
91156
}
92157
}
93-
},
94-
minified: {
95-
options: {
96-
src: MAIN_PLUGIN_FILE + '.min.js',
97-
deps: {
98-
default: ['$'],
99-
amd: [{'jquery': 'jQuery'}],
100-
cjs: [{'jquery': 'jQuery'}]
101-
}
102-
}
103158
}
104159
}
105160
});
106161
}
107162

108163
module.exports = function (grunt) {
109-
var filesToBuild = {
110-
uglify: {},
111-
concat: {
112-
main:{
113-
src: [SRC_DIR + MAIN_DIR+'core-validators.js'],
114-
dest: MAIN_PLUGIN_FILE + '.js'
115-
}
116-
}
117-
};
118-
// Gather up all module and language files
119-
[MODULE_DIR, LANG_DIR].forEach(function (path) {
120-
var srcPath = SRC_DIR + path;
121-
var distPath = DIST_DIR + path;
122-
if (path === MODULE_DIR) {
123-
distPath = DIST_DIR + '/';
124-
}
125-
126-
fs.readdirSync(srcPath).forEach(function (fileName) {
127-
var fullPath = srcPath + fileName;
128-
filesToBuild.uglify[distPath + fileName] = fullPath;
129-
filesToBuild.concat[fullPath] = {
130-
src: [fullPath],
131-
dest: distPath + fileName
132-
};
133-
});
134-
});
135-
filesToBuild.concat[CSS_FILE] = {
136-
src: [SRC_DIR + '/' + CSS_FILE],
137-
dest: DIST_DIR + '/' + CSS_FILE
138-
};
139-
// Gather up all source files that will added to minified core library
140-
fs.readdirSync(SRC_DIR + MAIN_DIR).forEach(function (fileName) {
141-
var fullPath = SRC_DIR + MAIN_DIR + fileName;
142-
if (filesToBuild.concat.main.src.indexOf(fullPath) === -1) {
143-
filesToBuild.concat.main.src.unshift(fullPath);
144-
}
145-
});
146-
147-
filesToBuild.cssFiles = [];
148-
filesToBuild.cssFiles.push({
149-
dest: DIST_DIR,
150-
src: CSS_FILE,
151-
cwd: SRC_DIR,
152-
expand: true,
153-
ext: '.min.css'
154-
});
155-
156-
// Add options for concat and uglify
157-
filesToBuild.concat.options = {
158-
banner: "<%= meta.banner %>"
159-
};
160-
filesToBuild.uglify.options = {
161-
banner: "<%= meta.banner %>"
162-
};
163-
164-
// Add main script to uglify
165-
filesToBuild.uglify[MAIN_PLUGIN_FILE + '.js'] = {
166-
src: MAIN_PLUGIN_FILE + '.js',
167-
expand: true,
168-
extDot: 'last',
169-
ext: '.min.js'
170-
};
171164

172-
initializeGruntConfig(grunt, filesToBuild);
165+
initializeGruntConfig(grunt);
173166
/*
174167
* Change to new version or the next version number. The project must be built again after this task
175168
* in order for the version change to take effect.
@@ -199,6 +192,7 @@ module.exports = function (grunt) {
199192

200193
grunt.loadNpmTasks('grunt-contrib-clean');
201194
grunt.loadNpmTasks("grunt-contrib-concat");
195+
grunt.loadNpmTasks('grunt-contrib-copy');
202196
grunt.loadNpmTasks("grunt-contrib-jshint");
203197
grunt.loadNpmTasks("grunt-contrib-uglify");
204198
grunt.loadNpmTasks("grunt-contrib-watch");
@@ -208,7 +202,7 @@ module.exports = function (grunt) {
208202
grunt.loadNpmTasks('grunt-umd');
209203

210204
grunt.registerTask("build-production", ["version", "test", "uglify"]);
211-
grunt.registerTask('test', ['concat', 'umd', 'cssmin','jshint', 'qunit']);
205+
grunt.registerTask('test', ['concat', 'copy', 'umd', 'cssmin','jshint', 'qunit']);
212206
grunt.registerTask("default", ["test", "watch"]);
213207
grunt.registerTask("prepublish", ["test", "uglify"]);
214208
};

form-validator/brazil.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

form-validator/date.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)