Skip to content

Commit 28e7358

Browse files
committed
Add clean task, add minified and non-minified CSS in production
It also may make sense to have a non-minified JS in production because those using build tools will probably be minifying their production builds, but not minifying their dev builds, so it'd be easier for them to have a non-minified version. Remove version number from dev CSS file
1 parent d9c086e commit 28e7358

File tree

3 files changed

+71
-69
lines changed

3 files changed

+71
-69
lines changed

Gruntfile.js

Lines changed: 70 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards
2-
//compabilitiy
2+
//compatibility
33
const DIST_DIR = './form-validator';
44
const MAIN_PLUGIN_FILE = 'form-validator/jquery.form-validator.min.js';
55
const SRC_DIR = './src';
@@ -8,78 +8,23 @@ const MODULE_DIR = '/modules/';
88
const LANG_DIR = '/lang/';
99
const CSS_FILE = 'theme-default.css';
1010

11-
1211
var fs = require('fs'),
13-
filesToBuild = {
14-
uglify: {},
15-
concat: {
16-
main:{
17-
src: [SRC_DIR + MAIN_DIR+'core-validators.js'],
18-
dest: MAIN_PLUGIN_FILE
19-
}
20-
}
21-
},
2212
readFile = function (file) {
2313
return fs.readFileSync(file, 'utf-8');
2414
},
2515
replaceInFile = function (path, from, to) {
2616
fs.writeFileSync(path, readFile(path).replace(from, to));
2717
};
2818

29-
module.exports = function (grunt) {
30-
// Gather up all module and language files
31-
[MODULE_DIR, LANG_DIR].forEach(function (path) {
32-
var srcPath = SRC_DIR + path;
33-
var distPath = DIST_DIR + path;
34-
if (path === MODULE_DIR) {
35-
distPath = DIST_DIR + '/';
36-
}
37-
38-
fs.readdirSync(srcPath).forEach(function (fileName) {
39-
var fullPath = srcPath + fileName;
40-
filesToBuild.uglify[distPath + fileName] = fullPath;
41-
filesToBuild.concat[fullPath] = {
42-
src: [fullPath],
43-
dest: distPath + fileName
44-
};
45-
});
46-
});
47-
48-
// Gather up all source files that will added to minified core library
49-
fs.readdirSync(SRC_DIR + MAIN_DIR).forEach(function (fileName) {
50-
var fullPath = SRC_DIR + MAIN_DIR + fileName;
51-
if (filesToBuild.concat.main.src.indexOf(fullPath) === -1) {
52-
filesToBuild.concat.main.src.unshift(fullPath);
53-
}
54-
});
55-
56-
filesToBuild.cssFiles = [];
57-
filesToBuild.cssFiles.push({
58-
dest: DIST_DIR,
59-
src: CSS_FILE,
60-
cwd: SRC_DIR,
61-
expand: true
62-
});
63-
64-
// Add options for concat and uglify
65-
filesToBuild.concat.options = {
66-
banner: "<%= meta.banner %>"
67-
};
68-
filesToBuild.uglify.options = {
69-
banner: "<%= meta.banner %>"
70-
};
71-
72-
// Add main script to uglify
73-
filesToBuild.uglify[MAIN_PLUGIN_FILE] = MAIN_PLUGIN_FILE;
74-
19+
function initializeGruntConfig(grunt, filesToBuild) {
7520
grunt.initConfig({
7621

7722
// Import package manifest
7823
pkg: grunt.file.readJSON("package.json"),
7924

8025
// Banner definitions
8126
meta: {
82-
banner: "/**\n" +
27+
banner: "/** File generated by Grunt -- do not modify\n" +
8328
" * <%= (pkg.title || pkg.name).toUpperCase() %>\n" +
8429
" *\n" +
8530
" * @version <%= pkg.version %>\n" +
@@ -93,9 +38,9 @@ module.exports = function (grunt) {
9338
concat: filesToBuild.concat,
9439

9540
cssmin: {
96-
target: {
97-
files: filesToBuild.cssFiles
98-
}
41+
target: {
42+
files: filesToBuild.cssFiles
43+
}
9944
},
10045
// Lint definitions
10146
jshint: {
@@ -115,7 +60,7 @@ module.exports = function (grunt) {
11560
watch: {
11661
files: [SRC_DIR + '/**'],
11762
tasks: ['test'],
118-
options : { nospawn : true }
63+
options: { nospawn: true}
11964
},
12065

12166
// Unit tests
@@ -132,10 +77,72 @@ module.exports = function (grunt) {
13277
keepalive: true
13378
}
13479
}
80+
},
81+
82+
clean: [DIST_DIR + '/']
83+
});
84+
}
85+
86+
module.exports = function (grunt) {
87+
var filesToBuild = {
88+
uglify: {},
89+
concat: {
90+
main:{
91+
src: [SRC_DIR + MAIN_DIR+'core-validators.js'],
92+
dest: MAIN_PLUGIN_FILE
93+
}
94+
}
95+
};
96+
// Gather up all module and language files
97+
[MODULE_DIR, LANG_DIR].forEach(function (path) {
98+
var srcPath = SRC_DIR + path;
99+
var distPath = DIST_DIR + path;
100+
if (path === MODULE_DIR) {
101+
distPath = DIST_DIR + '/';
102+
}
103+
104+
fs.readdirSync(srcPath).forEach(function (fileName) {
105+
var fullPath = srcPath + fileName;
106+
filesToBuild.uglify[distPath + fileName] = fullPath;
107+
filesToBuild.concat[fullPath] = {
108+
src: [fullPath],
109+
dest: distPath + fileName
110+
};
111+
});
112+
});
113+
filesToBuild.concat[CSS_FILE] = {
114+
src: [SRC_DIR + '/' + CSS_FILE],
115+
dest: DIST_DIR + '/' + CSS_FILE
116+
};
117+
// Gather up all source files that will added to minified core library
118+
fs.readdirSync(SRC_DIR + MAIN_DIR).forEach(function (fileName) {
119+
var fullPath = SRC_DIR + MAIN_DIR + fileName;
120+
if (filesToBuild.concat.main.src.indexOf(fullPath) === -1) {
121+
filesToBuild.concat.main.src.unshift(fullPath);
135122
}
123+
});
136124

125+
filesToBuild.cssFiles = [];
126+
filesToBuild.cssFiles.push({
127+
dest: DIST_DIR,
128+
src: CSS_FILE,
129+
cwd: SRC_DIR,
130+
expand: true,
131+
ext: '.min.css'
137132
});
138133

134+
// Add options for concat and uglify
135+
filesToBuild.concat.options = {
136+
banner: "<%= meta.banner %>"
137+
};
138+
filesToBuild.uglify.options = {
139+
banner: "<%= meta.banner %>"
140+
};
141+
142+
// Add main script to uglify
143+
filesToBuild.uglify[MAIN_PLUGIN_FILE] = MAIN_PLUGIN_FILE;
144+
145+
initializeGruntConfig(grunt, filesToBuild);
139146
/*
140147
* Change to new version or the next version number. The project must be built again after this task
141148
* in order for the version change to take effect.
@@ -163,7 +170,7 @@ module.exports = function (grunt) {
163170
grunt.config.set('pkg', pkg);
164171
});
165172

166-
173+
grunt.loadNpmTasks('grunt-contrib-clean');
167174
grunt.loadNpmTasks("grunt-contrib-concat");
168175
grunt.loadNpmTasks("grunt-contrib-jshint");
169176
grunt.loadNpmTasks("grunt-contrib-uglify");
@@ -174,6 +181,4 @@ module.exports = function (grunt) {
174181
grunt.registerTask("build-production", ["version", "cssmin", "test", "uglify"]);
175182
grunt.registerTask('test', ['concat', 'cssmin','jshint', 'qunit']);
176183
grunt.registerTask("default", ["test", "watch"]);
177-
//TODO: add clean task, don't minify CSS in dev build, ?remove volo (its {version} is busted anyway)
178-
//Add unminified CSS to prod build
179184
};

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,11 @@
2121
"url": "http://victorjonsson.se"
2222
},
2323
"homepage": "http://formvalidator.net/",
24-
"volo": {
25-
"url": "https://raw.githubusercontent.com/lagden/jQuery-Form-Validator/{version}/form-validator/jquery.form-validator.js"
26-
},
2724
"license": "MIT",
2825
"devDependencies": {
2926
"grunt": "~0.4.5",
3027
"grunt-cli": "~0.1.13",
28+
"grunt-contrib-clean": "~1.0.0",
3129
"grunt-contrib-concat": "^0.5.1",
3230
"grunt-contrib-connect": "^0.11.2",
3331
"grunt-contrib-cssmin": "~0.14.0",

src/theme-default.css

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

0 commit comments

Comments
 (0)