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 new file mode 100644 index 0000000..9bf327d --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +language: node_js +node_js: + - "4.2.4" +before_script: + - npm install -g grunt-cli diff --git a/Gruntfile.js b/Gruntfile.js index 6be70ec..1eef85c 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,136 +1,208 @@ +//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 : {}, - devFiles : [] + readFile = function (file) { + return fs.readFileSync(file, 'utf-8'); + }, + replaceInFile = function (path, from, to) { + fs.writeFileSync(path, readFile(path).replace(from, to)); + }; + +function initializeGruntConfig(grunt) { + + grunt.initConfig({ + + // Import package manifest + pkg: grunt.file.readJSON("package.json"), + + // Banner definitions + meta: { + banner: "/** File generated by Grunt -- do not modify\n" + + " * <%= (pkg.title || pkg.name).toUpperCase() %>\n" + + " *\n" + + " * @version <%= pkg.version %>\n" + + " * @website <%= pkg.homepage %>\n" + + " * @author <%= pkg.author.name %>, <%= pkg.author.url %>\n" + + " * @license <%= pkg.license %>\n" + + " */\n" }, - readFile = function(file) { - return fs.readFileSync(file, 'utf-8'); + + 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 %>" + } }, - replaceInFile = function(path, from, to) { - fs.writeFileSync(path, readFile(path).replace(from, to)); - }; - -module.exports = function(grunt) { - - // Gather up all js files - ['form-validator/', 'form-validator/lang/'].forEach(function(path) { - fs.readdirSync(path).forEach(function(fileName) { - if(fileName.substr(-7) == '.dev.js') { - var name = fileName.substr(0, fileName.length - 7); - filesToBuild.uglify[path + name + '.js'] = [path + name + '.js']; - filesToBuild.concat['file'+name] = { - src : [path + fileName], - dest: path + name + '.js' - } - filesToBuild.devFiles.push( path + fileName ); + + cssmin: { + target: { + files: [ + { + dest: DIST_DIR, + src: CSS_FILE, + cwd: SRC_DIR, + expand: true, + ext: '.min.css' + } + ] } - }); - }); + }, + // Lint definitions + jshint: { + files: [SRC_DIR + '/*'], + options: { + jshintrc: ".jshintrc", + ignores: [SRC_DIR + '/' + CSS_FILE] + } + }, + + // Minify definitions + uglify: { + options: { + banner: "<%= meta.banner %>" + }, + main: { + files: [ + { + expand: true, + cwd: DIST_DIR + '/', + src: ['**/*.js', '!' + MAIN_PLUGIN_FILE +'.js'], + dest: DIST_DIR + '/' + } + ] + } + }, - // Add options for concat ang ugligy - filesToBuild.concat.options = { - banner: "<%= meta.banner %>" - }; - filesToBuild.uglify.options = { - banner: "<%= meta.banner %>" - }; - - // Add main script to concat/uglify - filesToBuild.uglify['form-validator/jquery.form-validator.min.js'] = 'form-validator/jquery.form-validator.min.js'; - filesToBuild.concat.main = { - src : ['form-validator/jquery.form-validator.js'], - dest : 'form-validator/jquery.form-validator.min.js' - } - - grunt.initConfig({ - - // Import package manifest - pkg: grunt.file.readJSON("package.json"), - - // Banner definitions - meta: { - banner: "/**\n" + - " * <%= (pkg.title || pkg.name).toUpperCase() %>\n" + - " *\n" + - " * @website by <%= pkg.author.homepage %>\n" + - " * @license <%= pkg.license %>\n" + - " * @version <%= pkg.version %>\n" + - " */\n" - }, - - // Concat definitions. The only purpose of this - // is to create a distribution file out - // of files name *.dev.js - concat: filesToBuild.concat, - - // Lint definitions - jshint: { - files: ["form-validator/*.dev.js", "form-validator/jquery.form-validator.js"], - options: { - jshintrc: ".jshintrc" - } - }, - - // Minify definitions - uglify: filesToBuild.uglify, - - // watch for changes to source - // Better than calling grunt a million times - // (call 'grunt watch') - watch: { - files: ['form-validator/*'], - tasks: ['default'] - }, + watch: { + files: [SRC_DIR + '/**'], + tasks: ['test'], + options: { + nospawn: true, + livereload: true + } + }, + // Unit tests qunit: { all: ['test/qunit.html'] - } + }, - }); + // Standalone servers + connect: { + server: { + options: { + port: 8000, + 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() { + 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'), - currentVersion = pkg.version, - newVersion = grunt.option('new-version'); - - - if( !newVersion ) { - var versionParts = currentVersion.split('.'), - newSubVersion = parseInt(versionParts.splice(versionParts.length-1, 1)[0]) + 1; - newSubVersion = newSubVersion < 10 && newSubVersion > 0 ? '0'+newSubVersion : newSubVersion.toString(); - newVersion = versionParts.join('.') + '.' + newSubVersion; + currentVersion = pkg.version, + newVersion = grunt.option('new-version'); + + if (!newVersion) { + var versionParts = currentVersion.split('.'), + newSubVersion = parseInt(versionParts.splice(versionParts.length - 1, 1)[0]) + 1; + newSubVersion = newSubVersion < 10 && newSubVersion > 0 ? '0' + newSubVersion : newSubVersion.toString(); + newVersion = versionParts.join('.') + '.' + newSubVersion; } - grunt.log.writeln('* Moving from version '+currentVersion+' to '+newVersion); + grunt.log.writeln('* Moving from version ' + currentVersion + ' to ' + newVersion); - // replace version in config files and dev-files - replaceInFile('form-validator/jquery.form-validator.min.js', '@version '+currentVersion, '@version '+newVersion); - replaceInFile('form-validator/jquery.form-validator.js', '@version '+currentVersion, '@version '+newVersion); - replaceInFile('package.json', '"version": "'+currentVersion+'"', '"version": "'+newVersion+'"'); - replaceInFile('formvalidator.jquery.json', '"version": "'+currentVersion+'"', '"version": "'+newVersion+'"'); - filesToBuild.devFiles.forEach(function(filePath) { - replaceInFile(filePath, '@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) pkg.version = newVersion; grunt.config.set('pkg', pkg); }); - - grunt.loadNpmTasks("grunt-contrib-concat"); - grunt.loadNpmTasks("grunt-contrib-jshint"); - grunt.loadNpmTasks("grunt-contrib-uglify"); - grunt.loadNpmTasks("grunt-contrib-watch"); + 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", ["qunit", "version", "concat", "uglify"]); - grunt.registerTask("default", ["jshint", "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 271b14a..e1e957b 100644 --- a/README.md +++ b/README.md @@ -1,8 +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 jQuery 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. + +**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* @@ -27,7 +33,6 @@ jQuery Form Validator is a **feature rich and multilingual** jQuery plugin that - - -