diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..1a01981 --- /dev/null +++ b/.npmignore @@ -0,0 +1,10 @@ +#Testing, not relevant to end user +test/ +.travis.yml +.jshintrc + +#Not relevant to npm users +bower.json + +#IDE +.idea/ diff --git a/.travis.yml b/.travis.yml index 8692976..9bf327d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ language: node_js node_js: - - "0.12" + - "4.2.4" before_script: - npm install -g grunt-cli diff --git a/Gruntfile.js b/Gruntfile.js index b9da4fb..1eef85c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,28 +1,16 @@ - -const SRC_DIR = './form-validator/src/'; -const MODULE_DIR = './form-validator/'; -const LANG_DIR = './form-validator/lang/'; -const MAIN_PLUGIN_FILE = 'form-validator/jquery.form-validator.min.js'; -const JS_EXTENSION = '.js'; -const DEV_EXTENSION = '.dev.js'; +//TODO: During next major version bump change to /dist. Leaving at ./form-validator for backwards +//compatibility +const DIST_DIR = './form-validator'; +const MAIN_PLUGIN_FILE = 'jquery.form-validator'; +const SRC_DIR = './src'; +const MAIN_DIR = '/main/'; +const MODULE_DIR = '/modules'; +const LANG_DIR = '/lang'; +const CSS_FILE = 'theme-default.css'; +const CORE_VALIDATORS = 'core-validators.js'; //must come at end of concatted file +const coreValidatorsPath = SRC_DIR + MAIN_DIR + CORE_VALIDATORS; var fs = require('fs'), - filesToBuild = { - uglify: {}, - concat: { - main:{ - src:[SRC_DIR+'core-validators.js'], - dest: MAIN_PLUGIN_FILE - } - }, - devFiles: [] - }, - isJavascriptFile = function(fileName) { - return fileName.substr(-3) == JS_EXTENSION; - }, - isDevFile = function(fileName) { - return fileName.substr(-1 * DEV_EXTENSION.length) == DEV_EXTENSION; - }, readFile = function (file) { return fs.readFileSync(file, 'utf-8'); }, @@ -30,42 +18,7 @@ var fs = require('fs'), 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) { - fs.readdirSync(path).forEach(function (fileName) { - if (isDevFile(fileName)) { - var name = fileName.substr(0, fileName.length - DEV_EXTENSION.length), - fullPath = path + name + JS_EXTENSION; - - filesToBuild.uglify[fullPath] = [fullPath]; - filesToBuild.concat['file' + name] = { - src: [path + fileName], - dest: path + name + JS_EXTENSION - }; - filesToBuild.devFiles.push(path + fileName); - } - }); - }); - // Gather up all source files that will added to minified core library - fs.readdirSync(SRC_DIR).forEach(function (fileName) { - var fullPath = SRC_DIR + fileName; - if (isJavascriptFile(fileName) && filesToBuild.concat.main.src.indexOf(fullPath) == -1) { - filesToBuild.concat.main.src.unshift(fullPath); - } - }); - - // Add options for concat ang ugligy - 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) { grunt.initConfig({ @@ -74,7 +27,7 @@ module.exports = function (grunt) { // 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" + @@ -84,27 +37,71 @@ module.exports = function (grunt) { " */\n" }, - // Concat definitions. - concat: filesToBuild.concat, + concat: { + main:{ + files: [ + //This concatenates the core validators file after the other files + //Per: http://gruntjs.com/configuring-tasks + { + src: [SRC_DIR + MAIN_DIR+'*.js', '!' + coreValidatorsPath, coreValidatorsPath], + dest: DIST_DIR + '/' + MAIN_PLUGIN_FILE + '.js' + }, + { + src: [SRC_DIR + MAIN_DIR+'*.js', '!' + coreValidatorsPath, coreValidatorsPath], + dest: DIST_DIR + '/' + MAIN_PLUGIN_FILE + '.min.js' + }] + }, + options: { + banner: "<%= meta.banner %>" + } + }, + cssmin: { + target: { + files: [ + { + dest: DIST_DIR, + src: CSS_FILE, + cwd: SRC_DIR, + expand: true, + ext: '.min.css' + } + ] + } + }, // Lint definitions jshint: { - files: [MODULE_DIR+"*"+DEV_EXTENSION, SRC_DIR+"*.js"], + files: [SRC_DIR + '/*'], options: { - jshintrc: ".jshintrc" + jshintrc: ".jshintrc", + ignores: [SRC_DIR + '/' + CSS_FILE] } }, // Minify definitions - uglify: filesToBuild.uglify, + uglify: { + options: { + banner: "<%= meta.banner %>" + }, + main: { + files: [ + { + expand: true, + cwd: DIST_DIR + '/', + src: ['**/*.js', '!' + MAIN_PLUGIN_FILE +'.js'], + dest: DIST_DIR + '/' + } + ] + } + }, - // watch for changes to source - // Better than calling grunt a million times - // (call 'grunt watch') watch: { - files: [SRC_DIR+'/*', LANG_DIR+'/*', MODULE_DIR+'/*'], - tasks: ['build'], - options : { nospawn : true } + files: [SRC_DIR + '/**'], + tasks: ['test'], + options: { + nospawn: true, + livereload: true + } }, // Unit tests @@ -117,17 +114,57 @@ module.exports = function (grunt) { server: { options: { port: 8000, - base: '.', - keepalive: true + base: '.' } } - } + }, + + copy: { + main: { + files: [ + { + src: SRC_DIR + '/' + CSS_FILE, + dest: DIST_DIR + '/' + CSS_FILE + }, + { + cwd: SRC_DIR + '/' + MODULE_DIR, + src: '**', + dest: DIST_DIR + '/', + expand: true + }, + { + cwd: SRC_DIR + '/' + LANG_DIR, + src: '**', + dest: DIST_DIR + LANG_DIR +'/', + expand: true + }] + } + }, + + clean: [DIST_DIR + '/'], + umd: { + main: { + options: { + src: DIST_DIR + '/**/*.js', + dest: './', + deps: { + default: ['jQuery'], + amd: [{'jquery': 'jQuery'}], + cjs: [{'jquery': 'jQuery'}] + } + } + } + } }); +} + +module.exports = function (grunt) { + initializeGruntConfig(grunt); /* - * Change to new version or the next version number in all files - * containing the version definition + * 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. */ grunt.registerTask('version', 'Bump up the version number, or change version name by adding --new-version=3.1.0', function () { var pkg = grunt.config.get('pkg'), @@ -142,21 +179,9 @@ module.exports = function (grunt) { } grunt.log.writeln('* Moving from version ' + currentVersion + ' to ' + newVersion); - var fromVersion = '@version ' + currentVersion, - toVersion = '@version ' + newVersion; - - // replace version in config files and dev-files - fs.readdirSync(SRC_DIR).forEach(function(file) { - if (isJavascriptFile(file)) { - replaceInFile(SRC_DIR+file, fromVersion, toVersion); - } - }); - filesToBuild.devFiles.forEach(function (filePath) { - replaceInFile(filePath, fromVersion, toVersion); - }); - - replaceInFile('package.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"'); + replaceInFile('package.json', '"version": "' + currentVersion + '"', + '"version": "' + newVersion + '"'); replaceInFile('formvalidator.jquery.json', '"version": "' + currentVersion + '"', '"version": "' + newVersion + '"'); // Set new version globally (can later on be used by concat/uglify) @@ -164,16 +189,20 @@ module.exports = function (grunt) { grunt.config.set('pkg', pkg); }); - + grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks("grunt-contrib-concat"); + grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks("grunt-contrib-jshint"); grunt.loadNpmTasks("grunt-contrib-uglify"); grunt.loadNpmTasks("grunt-contrib-watch"); grunt.loadNpmTasks('grunt-contrib-connect'); grunt.loadNpmTasks('grunt-contrib-qunit'); - - grunt.registerTask("build", ["version", "concat", "uglify"]); - grunt.registerTask('test', ['concat', 'jshint', 'qunit']); - grunt.registerTask("default", ["test", "build"]); - + grunt.loadNpmTasks('grunt-contrib-cssmin'); + grunt.loadNpmTasks('grunt-umd'); + + grunt.registerTask("build-production", ["version", "test", "uglify"]); + grunt.registerTask('build', ['concat', 'copy', 'umd', 'cssmin']); + grunt.registerTask('test', ['build','jshint', 'qunit']); + grunt.registerTask("default", ["test", "connect", "watch"]); + grunt.registerTask("prepublish", ["test", "uglify"]); }; diff --git a/README.md b/README.md index 33f8169..e1e957b 100644 --- a/README.md +++ b/README.md @@ -1,10 +1,14 @@ -# jQuery Form Validator +# jQuery Form Validator [DISCONTINUED] -jQuery Form Validator is a **feature rich and multilingual** jQuery plugin that makes it easy to validate user input while keeping your HTML markup clean from javascript code. Even though this plugin has a wide range of validation functions it's **designed to require as little network traffic as possible**. This is achieved by grouping together validation functions in "modules", making it possible to load only those functions that's needed to validate a particular form. +*Validation framework that let's you configure, rather than code, your validation logic.* -**Form demos and full documentation available at http://formvalidator.net/** +I started writing this plugin back in 2009 and it has given me much joy over the years. But all good things must come to an end and now it's time for this plugin to pull in its oars and go down with history. -[](https://travis-ci.org/victorjonsson/jQuery-Form-Validator/builds/) +**This plugin is no longer being developed!** It supports jQuery v. 1.8 >= 2.2.4. No pull requests will become merged in but feel free to fork and do whatever you like! + +[](https://travis-ci.org/victorjonsson/jQuery-Form-Validator/builds/) + +[](https://www.npmjs.com/package/jquery-form-validator) *Usage example* @@ -29,7 +33,6 @@ jQuery Form Validator is a **feature rich and multilingual** jQuery plugin that - - -