diff --git a/.babelrc b/.babelrc deleted file mode 100644 index 10e5039..0000000 --- a/.babelrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "plugins": [ - "transform-runtime" - ], - "presets": [ - [ - "es2015", - { - "modules": false - } - ] - ] -} diff --git a/.eslintignore b/.eslintignore index 4aecb50..207b110 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,3 +1,2 @@ dist/ - Gruntfile.js diff --git a/.eslintrc.json b/.eslintrc.json index c7c2dad..375d28d 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,19 +1,17 @@ { - "extends": "notninja/es6", + "extends": "notninja/es5", "env": { "browser": true, "node": true }, - "parser": "babel-eslint", - "parserOptions": { - "sourceType": "module" - }, "rules": { "max-params": [ "error", 5 ], "no-bitwise": "off", + "no-empty-function": "off", + "no-invalid-this": "off", "no-unused-vars": [ "warn", { diff --git a/.travis.yml b/.travis.yml index 261c239..7404b99 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,13 @@ sudo: false language: node_js node_js: - - "0.10" - - "0.12" - "4" - "6" + - "8" +before_script: + - npm install -g npm@latest script: - - npm test + - npm run ci env: - CXX=g++-4.8 addons: diff --git a/CHANGES.md b/CHANGES.md index 55b5aef..b8629d7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,10 @@ +## Version 3.0.0, 2017.06.01 + +* Reduce size of distribution files [#59](https://github.com/neocotic/qrious/issues/59) (**breaking change**) +* Drop support for Node.js < 4 [#74](https://github.com/neocotic/qrious/issues/74) (**breaking change**) +* Remove QRious.DEFAULTS [#77](https://github.com/neocotic/qrious/issues/77) (**breaking change**) +* Rewrite code in ES5 [#81](https://github.com/neocotic/qrious/issues/81) (**breaking change**) + ## Version 2.3.0, 2017.05.31 * Enable setting of multiple properties at once resulting in a single re-render [#69](https://github.com/neocotic/qrious/issues/69) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9f59a18..5b7515c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,16 +16,15 @@ $ npm install $ npm test ``` -This will recompile the distribution files as well so feel free to make use of the `demo.html` to test your changes -locally before committing. +You must have at least [Node.js](https://nodejs.org) version 4 or newer and [npm](https://npmjs.com) installed version 5 +or newer installed. -If you're using a version of [Node.js](https://nodejs.org) that is older than 0.12, then linting is not performed by -this step. Please consider upgrading to at least 0.12 or your pull request may fail on the CI build. +Feel free to make use of the `demo.html` to test your changes locally before committing. You will need to rebuild the +distribution files in order to see your changes in the `demo.html`, but you can do so by running the following command: -Likewise, [Node.js](https://nodejs.org) versions older than 0.10 will also not be able to compile the source code using -[Rollup](http://rollupjs.org) so the test suite will not be executed against any changes you've made to `src/**.js`. For -this reason, 0.10 is not supported from a development perspective, but our CI builds do run the test suite against the -pre-compiled code for this version to ensure that it works. +``` bash +$ npm run build +``` All pull requests should be made to the `develop` branch. diff --git a/Gruntfile.js b/Gruntfile.js index 7d26356..46e4a78 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -20,176 +20,104 @@ 'use strict'; module.exports = function(grunt) { - var babel; - var commonjs; - var nodeResolve; - var semver = require('semver'); - var uglify; - - var bannerLarge = [ - '/*', - ' * QRious v<%= pkg.version %>', - ' * Copyright (C) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>', - ' * Copyright (C) 2010 Tom Zerucha', - ' *', - ' * This program is free software: you can redistribute it and/or modify', - ' * it under the terms of the GNU General Public License as published by', - ' * the Free Software Foundation, either version 3 of the License, or', - ' * (at your option) any later version.', - ' *', - ' * This program is distributed in the hope that it will be useful,', - ' * but WITHOUT ANY WARRANTY; without even the implied warranty of', - ' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the', - ' * GNU General Public License for more details.', - ' *', - ' * You should have received a copy of the GNU General Public License', - ' * along with this program. If not, see .', - ' */' - ].join('\n'); - var bannerSmall = [ - '/*! QRious v<%= pkg.version %> | (C) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %> | GPL v3 License', - 'Based on jsqrencode | (C) 2010 tz@execpc.com | GPL v3 License', - '*/' - ].join('\n'); + var commonjs = require('rollup-plugin-commonjs'); + var nodeResolve = require('rollup-plugin-node-resolve'); + var uglify = require('rollup-plugin-uglify'); grunt.initConfig({ pkg: grunt.file.readJSON('package.json'), - watch: { - all: { - files: [ 'src/**/*.js' ], - tasks: [ 'test' ] - } - } - }); - - var buildTasks = [ 'compile' ]; - var compileTasks = []; - var testTasks = [ 'compile' ]; - - if (semver.satisfies(process.version, '>=0.12')) { - babel = require('rollup-plugin-babel'); - commonjs = require('rollup-plugin-commonjs'); - nodeResolve = require('rollup-plugin-node-resolve'); - uglify = require('rollup-plugin-uglify'); + clean: { + build: [ 'dist/**' ] + }, - compileTasks.push('clean', 'rollup'); - - grunt.config.merge({ - clean: { - build: [ 'dist/**' ] - }, - - rollup: { - cjs: { - options: { - format: 'cjs', - sourceMap: true, - sourceMapRelativePaths: true, - banner: bannerLarge, - external: [ 'canvas' ], - plugins: function() { - return [ - nodeResolve({ - jsnext: true, - main: true - }), - commonjs(), - babel({ - exclude: [ 'node_modules/**' ], - runtimeHelpers: true - }) - ]; - } - }, - files: { - 'dist/cjs/qrious.js': 'src/runtime/node.js' - } - }, - umdDevelopment: { - options: { - format: 'umd', - moduleId: 'qrious', - moduleName: 'QRious', - sourceMap: true, - sourceMapRelativePaths: true, - banner: bannerLarge, - plugins: function() { - return [ - nodeResolve({ - jsnext: true, - main: true - }), - commonjs(), - babel({ - exclude: [ 'node_modules/**' ], - runtimeHelpers: true - }) - ]; - } - }, - files: { - 'dist/umd/qrious.js': 'src/runtime/browser.js' + eslint: { + target: [ 'src/**/*.js' ] + }, + + rollup: { + umdDevelopment: { + options: { + format: 'umd', + moduleId: 'qrious', + moduleName: 'QRious', + sourceMap: true, + sourceMapRelativePaths: true, + banner: [ + '/*', + ' * QRious v<%= pkg.version %>', + ' * Copyright (C) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %>', + ' * Copyright (C) 2010 Tom Zerucha', + ' *', + ' * This program is free software: you can redistribute it and/or modify', + ' * it under the terms of the GNU General Public License as published by', + ' * the Free Software Foundation, either version 3 of the License, or', + ' * (at your option) any later version.', + ' *', + ' * This program is distributed in the hope that it will be useful,', + ' * but WITHOUT ANY WARRANTY; without even the implied warranty of', + ' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the', + ' * GNU General Public License for more details.', + ' *', + ' * You should have received a copy of the GNU General Public License', + ' * along with this program. If not, see .', + ' */' + ].join('\n'), + plugins: function() { + return [ + nodeResolve({ main: true }), + commonjs() + ]; } }, - umdProduction: { - options: { - format: 'umd', - moduleId: 'qrious', - moduleName: 'QRious', - sourceMap: true, - sourceMapRelativePaths: true, - banner: bannerSmall, - plugins: function() { - return [ - nodeResolve({ - jsnext: true, - main: true - }), - commonjs(), - babel({ - exclude: [ 'node_modules/**' ], - runtimeHelpers: true - }), - uglify({ - output: { - comments: function(node, comment) { - return comment.type === 'comment2' && /^\!/.test(comment.value); - } + files: { + 'dist/qrious.js': 'src/runtime/browser.js' + } + }, + umdProduction: { + options: { + format: 'umd', + moduleId: 'qrious', + moduleName: 'QRious', + sourceMap: true, + sourceMapRelativePaths: true, + banner: [ + '/*! QRious v<%= pkg.version %> | (C) <%= grunt.template.today("yyyy") %> <%= pkg.author.name %> | GPL v3 License', + 'Based on jsqrencode | (C) 2010 tz@execpc.com | GPL v3 License', + '*/' + ].join('\n'), + plugins: function() { + return [ + nodeResolve({ main: true }), + commonjs(), + uglify({ + output: { + comments: function(node, comment) { + return comment.type === 'comment2' && /^\!/.test(comment.value); } - }) - ]; - } - }, - files: { - 'dist/umd/qrious.min.js': 'src/runtime/browser.js' + } + }) + ]; } + }, + files: { + 'dist/qrious.min.js': 'src/runtime/browser.js' } } - }); - - grunt.loadNpmTasks('grunt-contrib-clean'); - grunt.loadNpmTasks('grunt-rollup'); - } else { - grunt.log.writeln('"clean" and "rollup" tasks are disabled because Node.js version is <0.12! Please consider upgrading Node.js...'); - } - - if (semver.satisfies(process.version, '>=4')) { - compileTasks.unshift('eslint'); - - grunt.config.set('eslint', { - target: [ 'src/**/*.js' ] - }); + }, - grunt.loadNpmTasks('grunt-eslint'); - } else { - grunt.log.writeln('"eslint" task is disabled because Node.js version is <4! Please consider upgrading Node.js...'); - } + watch: { + all: { + files: [ 'src/**/*.js' ], + tasks: [ 'eslint' ] + } + } + }); - grunt.loadNpmTasks('grunt-contrib-watch'); + require('load-grunt-tasks')(grunt); - grunt.registerTask('default', [ 'build' ]); - grunt.registerTask('build', buildTasks); - grunt.registerTask('compile', compileTasks); - grunt.registerTask('test', testTasks); + grunt.registerTask('default', [ 'ci' ]); + grunt.registerTask('build', [ 'eslint', 'clean:build', 'rollup' ]); + grunt.registerTask('ci', [ 'eslint', 'clean', 'rollup' ]); + grunt.registerTask('test', [ 'eslint' ]); }; diff --git a/README.md b/README.md index eed4b68..dd3d124 100644 --- a/README.md +++ b/README.md @@ -10,6 +10,7 @@ [![Chat](https://img.shields.io/gitter/room/neocotic/qrious.svg?style=flat-square)](https://gitter.im/neocotic/qrious) [![Build Status](https://img.shields.io/travis/neocotic/qrious/develop.svg?style=flat-square)](https://travis-ci.org/neocotic/qrious) +[![Dependency Status](https://img.shields.io/david/neocotic/qrious.svg?style=flat-square)](https://david-dm.org/neocotic/qrious) [![Optional Dependency Status](https://img.shields.io/david/optional/neocotic/qrious.svg?style=flat-square)](https://david-dm.org/neocotic/qrious?type=optional) [![Dev Dependency Status](https://img.shields.io/david/dev/neocotic/qrious.svg?style=flat-square)](https://david-dm.org/neocotic/qrious?type=dev) [![License](https://img.shields.io/npm/l/qrious.svg?style=flat-square)](https://github.com/neocotic/qrious/blob/master/LICENSE.md) @@ -38,8 +39,8 @@ you want to install that way instead of using `npm`. If you want to simply download the file to be used in the browser you can find them below: -* [Development Version](https://cdn.rawgit.com/neocotic/qrious/master/dist/umd/qrious.js) (123kb - [Source Map](https://cdn.rawgit.com/neocotic/qrious/master/dist/umd/qrious.js.map)) -* [Production Version](https://cdn.rawgit.com/neocotic/qrious/master/dist/umd/qrious.min.js) (37kb - [Source Map](https://cdn.rawgit.com/neocotic/qrious/master/dist/umd/qrious.min.js.map)) +* [Development Version](https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.js) (123kb - [Source Map](https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.js.map)) +* [Production Version](https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.min.js) (37kb - [Source Map](https://cdn.rawgit.com/neocotic/qrious/master/dist/qrious.min.js.map)) ### Node.js Dependencies @@ -106,17 +107,18 @@ Open up `demo.html` in your browser to play around a bit. Simply create an instance of `QRious` and you've done most of the work. You can control many aspects of the QR code using the following fields on your instance: -| Field | Type | Description | Default | -| --------------- | ------ | -------------------------------------------------- | ------------- | -| background | String | Background color of the QR code | `"white"` | -| backgroundAlpha | Number | Background alpha of the QR code | `1.0` | -| foreground | String | Foreground color of the QR code | `"black"` | -| foregroundAlpha | Number | Foreground alpha of the QR code | `1.0` | -| level | String | Error correction level of the QR code (L, M, Q, H) | `"L"` | -| mime | String | MIME type used to render the image for the QR code | `"image/png"` | -| padding | Number | Padding for the QR code (pixels) | `null` (auto) | -| size | Number | Size of the QR code (pixels) | `100` | -| value | String | Value encoded within the QR code | `""` | +| Field | Type | Description | Default | Read Only | +| --------------- | ------- | -------------------------------------------------- | ------------- | --------- | +| background | String | Background color of the QR code | `"white"` | No | +| backgroundAlpha | Number | Background alpha of the QR code | `1.0` | No | +| element | Element | Element to render the QR code | `` | Yes | +| foreground | String | Foreground color of the QR code | `"black"` | No | +| foregroundAlpha | Number | Foreground alpha of the QR code | `1.0` | No | +| level | String | Error correction level of the QR code (L, M, Q, H) | `"L"` | No | +| mime | String | MIME type used to render the image for the QR code | `"image/png"` | No | +| padding | Number | Padding for the QR code (pixels) | `null` (auto) | No | +| size | Number | Size of the QR code (pixels) | `100` | No | +| value | String | Value encoded within the QR code | `""` | No | ``` javascript const qr = new QRious(); @@ -164,9 +166,10 @@ const qr = new QRious({ ``` You can also pass in an `element` option to the constructor which can be used to generate the QR code using an existing -DOM element. `element` must either be a `` element or an `` element which can then be accessed via the -`canvas` or `image` fields on the instance respectively. An element will be created for whichever one isn't provided or -for both if no `element` is specified, which means that they can be appeneded to the document at a later time. +DOM element, which is the only time that you can specify read only options. `element` must either be a `` +element or an `` element which can then be accessed via the `canvas` or `image` fields on the instance +respectively. An element will be created for whichever one isn't provided or for both if no `element` is specified, +which means that they can be appended to the document at a later time. ``` javascript const qr = new QRious({ @@ -212,7 +215,7 @@ The current version of `QRious`. ``` javascript QRious.VERSION; -//=> "2.3.0" +//=> "3.0.0" ``` ## Migrating from v1 diff --git a/bower.json b/bower.json index 1ad975e..8f01fe7 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "qrious", - "version": "2.3.0", + "version": "3.0.0", "description": "Library for QR code generation using canvas", "homepage": "https://github.com/neocotic/qrious", "authors": [ @@ -22,7 +22,7 @@ "type": "git", "url": "https://github.com/neocotic/qrious.git" }, - "main": "dist/umd/qrious.js", + "main": "dist/qrious.js", "ignore": [ "src/", ".*", diff --git a/demo.html b/demo.html index 7f35ab9..5dd99af 100644 --- a/demo.html +++ b/demo.html @@ -143,7 +143,7 @@ - +