Skip to content

160224/add clean task and unminified css #392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
142 changes: 76 additions & 66 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,30 @@
//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards
//compabilitiy
//compatibility
const DIST_DIR = './form-validator';
const MAIN_PLUGIN_FILE = 'form-validator/jquery.form-validator.min.js';
const MAIN_PLUGIN_FILE = './form-validator/jquery.form-validator.js';
const SRC_DIR = './src';
const MAIN_DIR = '/main/';
const MODULE_DIR = '/modules/';
const LANG_DIR = '/lang/';
const CSS_FILE = 'theme-default.css';


var fs = require('fs'),
filesToBuild = {
uglify: {},
concat: {
main:{
src: [SRC_DIR + MAIN_DIR+'core-validators.js'],
dest: MAIN_PLUGIN_FILE
}
}
},
readFile = function (file) {
return fs.readFileSync(file, 'utf-8');
},
replaceInFile = function (path, from, to) {
fs.writeFileSync(path, readFile(path).replace(from, to));
};

module.exports = function (grunt) {
// Gather up all module and language files
[MODULE_DIR, LANG_DIR].forEach(function (path) {
var srcPath = SRC_DIR + path;
var distPath = DIST_DIR + path;
if (path === MODULE_DIR) {
distPath = DIST_DIR + '/';
}

fs.readdirSync(srcPath).forEach(function (fileName) {
var fullPath = srcPath + fileName;
filesToBuild.uglify[distPath + fileName] = fullPath;
filesToBuild.concat[fullPath] = {
src: [fullPath],
dest: distPath + fileName
};
});
});

// Gather up all source files that will added to minified core library
fs.readdirSync(SRC_DIR + MAIN_DIR).forEach(function (fileName) {
var fullPath = SRC_DIR + MAIN_DIR + fileName;
if (filesToBuild.concat.main.src.indexOf(fullPath) === -1) {
filesToBuild.concat.main.src.unshift(fullPath);
}
});

filesToBuild.cssFiles = [];
filesToBuild.cssFiles.push({
dest: DIST_DIR,
src: CSS_FILE,
cwd: SRC_DIR,
expand: true
});

// Add options for concat and uglify
filesToBuild.concat.options = {
banner: "<%= meta.banner %>"
};
filesToBuild.uglify.options = {
banner: "<%= meta.banner %>"
};

// Add main script to uglify
filesToBuild.uglify[MAIN_PLUGIN_FILE] = MAIN_PLUGIN_FILE;

function initializeGruntConfig(grunt, filesToBuild) {
grunt.initConfig({

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

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

cssmin: {
target: {
files: filesToBuild.cssFiles
}
target: {
files: filesToBuild.cssFiles
}
},
// Lint definitions
jshint: {
Expand All @@ -115,7 +60,7 @@ module.exports = function (grunt) {
watch: {
files: [SRC_DIR + '/**'],
tasks: ['test'],
options : { nospawn : true }
options: { nospawn: true}
},

// Unit tests
Expand All @@ -132,10 +77,77 @@ module.exports = function (grunt) {
keepalive: true
}
}
},

clean: [DIST_DIR + '/']
});
}

module.exports = function (grunt) {
var filesToBuild = {
uglify: {},
concat: {
main:{
src: [SRC_DIR + MAIN_DIR+'core-validators.js'],
dest: MAIN_PLUGIN_FILE
}
}
};
// Gather up all module and language files
[MODULE_DIR, LANG_DIR].forEach(function (path) {
var srcPath = SRC_DIR + path;
var distPath = DIST_DIR + path;
if (path === MODULE_DIR) {
distPath = DIST_DIR + '/';
}

fs.readdirSync(srcPath).forEach(function (fileName) {
var fullPath = srcPath + fileName;
filesToBuild.uglify[distPath + fileName] = fullPath;
filesToBuild.concat[fullPath] = {
src: [fullPath],
dest: distPath + fileName
};
});
});
filesToBuild.concat[CSS_FILE] = {
src: [SRC_DIR + '/' + CSS_FILE],
dest: DIST_DIR + '/' + CSS_FILE
};
// Gather up all source files that will added to minified core library
fs.readdirSync(SRC_DIR + MAIN_DIR).forEach(function (fileName) {
var fullPath = SRC_DIR + MAIN_DIR + fileName;
if (filesToBuild.concat.main.src.indexOf(fullPath) === -1) {
filesToBuild.concat.main.src.unshift(fullPath);
}
});

filesToBuild.cssFiles = [];
filesToBuild.cssFiles.push({
dest: DIST_DIR,
src: CSS_FILE,
cwd: SRC_DIR,
expand: true,
ext: '.min.css'
});

// Add options for concat and uglify
filesToBuild.concat.options = {
banner: "<%= meta.banner %>"
};
filesToBuild.uglify.options = {
banner: "<%= meta.banner %>"
};

// Add main script to uglify
filesToBuild.uglify[MAIN_PLUGIN_FILE] = {
src: MAIN_PLUGIN_FILE,
expand: true,
extDot: 'last',
ext: '.min.js'
};

initializeGruntConfig(grunt, filesToBuild);
/*
* Change to new version or the next version number. The project must be built again after this task
* in order for the version change to take effect.
Expand Down Expand Up @@ -163,7 +175,7 @@ module.exports = function (grunt) {
grunt.config.set('pkg', pkg);
});


grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks("grunt-contrib-concat");
grunt.loadNpmTasks("grunt-contrib-jshint");
grunt.loadNpmTasks("grunt-contrib-uglify");
Expand All @@ -174,6 +186,4 @@ module.exports = function (grunt) {
grunt.registerTask("build-production", ["version", "cssmin", "test", "uglify"]);
grunt.registerTask('test', ['concat', 'cssmin','jshint', 'qunit']);
grunt.registerTask("default", ["test", "watch"]);
//TODO: add clean task, don't minify CSS in dev build, ?remove volo (its {version} is busted anyway)
//Add unminified CSS to prod build
};
4 changes: 2 additions & 2 deletions form-validator/brazil.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions form-validator/date.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
/** File generated by Grunt -- do not modify
* JQUERY-FORM-VALIDATOR
*
* @version 2.2.188
* @version 2.2.189
* @website http://formvalidator.net/
* @author Victor Jonsson, http://victorjonsson.se
* @license MIT
Expand Down
4 changes: 2 additions & 2 deletions form-validator/file.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions form-validator/html5.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading