diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 0000000..56cbb6e --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + extends: 'kswedberg/es5', + rules: { + 'comma-dangle': ['warn', 'never'] + } +}; diff --git a/.jscsrc b/.jscsrc new file mode 100644 index 0000000..d458b8c --- /dev/null +++ b/.jscsrc @@ -0,0 +1,88 @@ +{ + "requireCurlyBraces": [ + "if", + "else", + "for", + "while", + "do", + "try", + "catch" + ], + "requireSpaceAfterKeywords": [ + "if", + "else", + "for", + "while", + "do", + "switch", + "case", + "return", + "try", + "catch", + "typeof" + ], + "requireSpaceBeforeBlockStatements": true, + "requireParenthesesAroundIIFE": true, + "requireSpacesInConditionalExpression": true, + "disallowSpacesInNamedFunctionExpression": { + "beforeOpeningRoundBrace": true + }, + "disallowSpacesInFunctionDeclaration": { + "beforeOpeningRoundBrace": true + }, + "requireSpaceBetweenArguments": true, + "requireBlocksOnNewline": true, + "disallowEmptyBlocks": true, + "disallowSpacesInsideArrayBrackets": true, + "disallowSpacesInsideParentheses": true, + "disallowDanglingUnderscores": true, + "requireCommaBeforeLineBreak": true, + "disallowSpacesInCallExpression": true, + "disallowSpaceAfterPrefixUnaryOperators": true, + "disallowSpaceBeforePostfixUnaryOperators": true, + "disallowSpaceBeforeBinaryOperators": [ + "," + ], + "requireSpacesInForStatement": true, + "requireSpaceBeforeBinaryOperators": true, + "requireSpaceAfterBinaryOperators": true, + "disallowKeywords": [ + "with" + ], + "disallowMixedSpacesAndTabs": true, + "disallowTrailingWhitespace": true, + "disallowKeywordsOnNewLine": [ + "else" + ], + "requireLineFeedAtFileEnd": true, + "requireCapitalizedConstructors": true, + "requireDotNotation": true, + "disallowNewlineBeforeBlockStatements": true, + "disallowMultipleLineStrings": true, + "requireSpaceBeforeObjectValues": true, + "validateQuoteMarks": "'", + "requireSpaceAfterLineComment": true, + "validateIndentation": 2, + "validateLineBreaks": "LF", + "disallowSpacesInFunction": { + "beforeOpeningRoundBrace": true + }, + "requireSpacesInFunction": { + "beforeOpeningCurlyBrace": true + }, + "disallowMultipleLineBreaks": true, + "disallowYodaConditions": true, + "disallowFunctionDeclarations": true, + "disallowMultipleVarDecl": "exceptUndefined", + "requirePaddingNewlinesBeforeKeywords": [ + "do", + "for", + "if", + "switch", + "try", + "void", + "while", + "return" + ], + "excludeFiles": ["**/node_modules/**", "**/min/**", "**/*.min.js"] +} diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..18d3e4e --- /dev/null +++ b/.npmignore @@ -0,0 +1,5 @@ +demo +node_modules +lib +bower.json +smooth-scroll.jquery.json diff --git a/.nvmrc b/.nvmrc new file mode 100644 index 0000000..b6a7d89 --- /dev/null +++ b/.nvmrc @@ -0,0 +1 @@ +16 diff --git a/Gruntfile.js b/Gruntfile.js index 4999080..9a733e6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,55 +1,60 @@ -/*global module:false*/ - module.exports = function(grunt) { - - // Because I'm lazy - var _ = grunt.util._; + var pkg = grunt.file.readJSON('package.json'); var marked = require('marked'); - // var hl = require('highlight').Highlight; var hl = require('node-syntaxhighlighter'); + marked.setOptions({ highlight: function(code, lang) { - lang = lang || 'javascript'; - lang = hl.getLanguage(lang); + var language = hl.getLanguage(lang || 'javascript'); - return hl.highlight(code, lang); + return hl.highlight(code, language); }, gfm: true }); // Project configuration. grunt.initConfig({ - bower: './bower.json', - pkg: grunt.file.readJSON('smooth-scroll.jquery.json'), + pluginName: 'smooth-scroll', + pkg: pkg, meta: { banner: '/*!<%= "\\n" %>' + - ' * <%= pkg.title || pkg.name %> - v<%= pkg.version %> - ' + + ' * <%= pkg.title %> - v<%= pkg.version %> - ' + '<%= grunt.template.today("yyyy-mm-dd") + "\\n" %>' + '<%= pkg.homepage ? " * " + pkg.homepage + "\\n" : "" %>' + ' * Copyright (c) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>' + '<%= "\\n" %>' + - ' * Licensed <%= _.pluck(pkg.licenses, "type").join(", ") %>' + - ' (<%= _.pluck(pkg.licenses, "url").join(", ") %>)' + + ' * Licensed <%= pkg.license %>' + '<%= "\\n" %>' + ' */' + '<%= "\\n\\n" %>' }, - concat: { + concat: { all: { - src: ['src/jquery.<%= pkg.name %>.js'], - dest: 'jquery.<%= pkg.name %>.js' + src: ['src/jquery.<%= pluginName %>.js'], + dest: 'jquery.<%= pluginName %>.js' }, options: { stripBanners: true, - banner: '<%= meta.banner %>' + banner: '<%= meta.banner %>', + process: function(src) { + var umdHead = grunt.file.read('lib/tmpl/umdhead.tpl'); + var umdFoot = grunt.file.read('lib/tmpl/umdfoot.tpl'); + + var ret = src + .replace('(function($) {', umdHead) + .replace('})(jQuery);', umdFoot); + + return ret; + } } }, uglify: { all: { files: { - 'jquery.<%= pkg.name %>.min.js': ['<%= concat.all.dest %>'] + 'jquery.<%= pluginName %>.min.js': ['<%= concat.all.dest %>'] }, options: { - preserveComments: 'some' + banner: '<%= meta.banner %>' + // preserveComments: /\/\*[\s\S]*/ } } }, @@ -64,24 +69,14 @@ module.exports = function(grunt) { } }, - shell: { - rsync: { - // command is set by setshell:rsync. - stdout: true - } - }, - setshell: { - rsync: { - file: 'gitignore/settings.json', - cmdAppend: '<%= pkg.name %>/' - } - }, jshint: { all: ['Gruntfile.js', 'src/**/*.js'], options: { curly: true, - // eqeqeq: true, - // immed: true, + devel: true, + eqeqeq: true, + unused: true, + immed: true, latedef: true, newcap: true, noarg: true, @@ -96,100 +91,74 @@ module.exports = function(grunt) { } } }, + eslint: { + target: ['Gruntfile.js', 'src/**/*.js', 'test/**/*.js'], + options: { + fix: true + // configFile: '.eslintrc.js', + } + }, version: { - patch: { + src: { + src: ['src/jquery.<%= pluginName %>.js'] + }, + banners: { + pkg: pkg, src: [ - '<%= pkg.name %>.jquery.json', - 'package.json', - 'src/jquery.<%= pkg.name %>.js', - 'jquery.<%= pkg.name %>.js' + 'jquery.<%= pluginName %>.js', + 'jquery.<%= pluginName %>.min.js' ], options: { - release: 'patch' + prefix: '- v' } }, - same: { - src: ['package.json', 'src/jquery.<%= pkg.name %>.js', 'jquery.<%= pkg.name %>.js'] - }, - bannerPatch: { - src: ['jquery.<%= pkg.name %>.js'], - options: { - prefix: '- v', - release: 'patch' - } + package: { + src: ['package.json'] } } }); - grunt.registerMultiTask( 'setshell', 'Set grunt shell commands', function() { - var settings, cmd, - tgt = this.target, - cmdLabel = 'shell.' + tgt + '.command', - file = this.data.file, - append = this.data.cmdAppend || ''; - - if ( !grunt.file.exists(file) ) { - grunt.warn('File does not exist: ' + file); - } - - settings = grunt.file.readJSON(file); - if (!settings[tgt]) { - grunt.warn('No ' + tgt + ' property found in ' + file); - } - - cmd = settings[tgt] + append; - grunt.config(cmdLabel, cmd); - grunt.log.writeln( ('Setting ' + cmdLabel + ' to:').cyan ); - - grunt.log.writeln(cmd); + grunt.registerTask('docs', 'Convert readme.md to html and concat with header and footer for index.html', function() { + var readme = grunt.file.read('readme.md'); + var head = grunt.template.process(grunt.file.read('lib/tmpl/header.tpl')); + var foot = grunt.file.read('lib/tmpl/footer.tpl'); + var doc = marked(readme); + grunt.file.write('index.html', head + doc + foot); }); - grunt.registerTask( 'deploy', ['setshell:rsync', 'shell:rsync']); - - grunt.registerTask( 'bower', 'Update bower.json', function() { - var comp = grunt.config('bower'), - pkgName = grunt.config('pkg').name, - pkg = grunt.file.readJSON(pkgName + '.jquery.json'), - json = {}; + grunt.registerTask('updateBower', 'Update bower.json to match package.json', function() { + var pkg = require('./package.json'); + var props = ['name', 'main', 'homepage', 'version', 'repository', 'dependencies', 'keywords', 'license']; + var json = { + description: 'Easy implementation of smooth scrolling for same-page links' + }; - ['name', 'version', 'dependencies'].forEach(function(el) { - json[el] = pkg[el]; + props.forEach(function(item) { + if (pkg[item]) { + json[item] = pkg[item]; + } }); - _.extend(json, { - main: grunt.config('concat.all.dest'), - ignore: [ - 'demo/', - 'lib/', - 'src/', - '*.json' - ] - }); - json.name = 'jquery.' + json.name; + json.authors = [pkg.author]; + json.moduleType = ['amd', 'node']; + json.ignore = ['demo/', 'lib/', 'src/', 'test/', '**/.*', 'Gruntfile.js', 'package.json']; - grunt.file.write( comp, JSON.stringify(json, null, 2) ); - grunt.log.writeln( "File '" + comp + "' updated." ); + grunt.file.write('bower.json', JSON.stringify(json, null, 2)); }); - grunt.registerTask('docs', 'Convert readme.md to html and concat with header and footer for index.html', function() { - var readme = grunt.file.read('readme.md'), - head = grunt.template.process(grunt.file.read('lib/tmpl/header.tpl')), - foot = grunt.file.read('lib/tmpl/footer.tpl'), - doc = marked(readme); - + grunt.registerTask('lint', ['eslint']); + grunt.registerTask('build', ['lint', 'concat', 'version', 'updateBower', 'uglify', 'docs']); + grunt.registerTask('default', ['build']); - grunt.file.write('index.html', head + doc + foot); + ['patch', 'minor', 'major'].forEach(function(release) { + grunt.registerTask(release, ['lint', 'version:src:' + release, 'concat', 'uglify', 'version:banners:' + release, 'version:package:' + release, 'updateBower']); }); - grunt.registerTask('build', ['jshint', 'concat', 'version:same', 'bower', 'uglify', 'docs']); - grunt.registerTask('patch', ['jshint', 'concat', 'version:bannerPatch', 'version:patch', 'bower', 'uglify']); - grunt.registerTask('default', ['build']); - + grunt.loadNpmTasks('grunt-eslint'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-concat'); grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-version'); - grunt.loadNpmTasks('grunt-shell'); }; diff --git a/bower.json b/bower.json index cb4b9d2..e8a5183 100644 --- a/bower.json +++ b/bower.json @@ -1,14 +1,41 @@ { - "name": "jquery.smooth-scroll", - "version": "1.4.11", + "description": "Easy implementation of smooth scrolling for same-page links", + "name": "jquery-smooth-scroll", + "main": "jquery.smooth-scroll.js", + "homepage": "https://github.com/kswedberg/jquery-smooth-scroll", + "version": "2.2.0", + "repository": { + "type": "git", + "url": "https://github.com/kswedberg/jquery-smooth-scroll" + }, "dependencies": { - "jquery": ">=1.3" + "jquery": ">=1.7.0" }, - "main": "jquery.smooth-scroll.js", + "keywords": [ + "jQuery", + "jquery-plugin", + "scroll", + "animation" + ], + "license": "MIT", + "authors": [ + { + "name": "Karl Swedberg", + "email": "kswedberg@gmail.com", + "url": "https://karlswedberg.com/" + } + ], + "moduleType": [ + "amd", + "node" + ], "ignore": [ "demo/", "lib/", "src/", - "*.json" + "test/", + "**/.*", + "Gruntfile.js", + "package.json" ] } \ No newline at end of file diff --git a/demo/bbq-fixed.html b/demo/bbq-fixed.html index 4a657e3..2bb41b1 100644 --- a/demo/bbq-fixed.html +++ b/demo/bbq-fixed.html @@ -46,8 +46,7 @@
+