Skip to content

Commit

Permalink
Drop support for Node.js < 10.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LinusU committed Apr 16, 2020
1 parent 48b4cdc commit a5a8563
Show file tree
Hide file tree
Showing 12 changed files with 4,718 additions and 4,667 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
language: node_js

node_js:
- '4'
- '6'
- '8'
- '10.13.0'
- '10'
- '12'
- 'node'

env:
Expand Down
91 changes: 29 additions & 62 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,52 @@
var spawn = require('child_process').spawn
var fs = require('fs')
var path = require('path')
const childProcess = require('child_process')
const fs = require('fs')
const path = require('path')

require('colors')

function createFolder (folderPath, onDone) {
function createFolder (folderPath) {
console.log('*'.green + ' creating folder: '.grey + folderPath.white)

if (!fs.existsSync(folderPath)) {
fs.mkdirSync(folderPath)
}

onDone()
fs.mkdirSync(folderPath, { recursive: true })
}

function bundle (inputFile, exportName, outputFile, onDone) {
console.log('*'.green + ' bundling: '.grey +
inputFile.white + ' -> '.grey + outputFile.white)
console.log('*'.green + ' bundling: '.grey + inputFile.white + ' -> '.grey + outputFile.white)

var browserify = spawn('node', [
const { status, stderr } = childProcess.spawnSync('node', [
'node_modules/.bin/browserify',
inputFile,
'-s', exportName,
'-d',
'-o', outputFile
])

browserify.stdin.end()
browserify.stdout.pipe(process.stdout)
browserify.stderr.pipe(process.stderr)
browserify.on('exit', function (code) {
if (code) {
console.error('browserify failed!')
process.exit(code)
}

onDone()
})
if (status !== 0) {
console.error(stderr.toString())
process.exit(status)
}
}

function minify (inputFile, outputFile, onDone) {
console.log('*'.green + ' minifying: '.grey +
inputFile.white + ' -> '.grey + outputFile.white)
function minify (inputFile, outputFile) {
console.log('*'.green + ' minifying: '.grey + inputFile.white + ' -> '.grey + outputFile.white)

var uglify = spawn('node', [
const { status, stderr } = childProcess.spawnSync('node', [
'node_modules/.bin/uglifyjs',
'--compress', '--mangle',
'--source-map', outputFile + '.map',
'--source-map-url', path.basename(outputFile) + '.map',
'--', inputFile])

var minStream = fs.createWriteStream(outputFile)
uglify.stdout.pipe(minStream)
uglify.stdin.end()
uglify.on('exit', function (code) {
if (code) {
console.error('uglify failed!')
fs.unlink(outputFile, function () {
process.exit(code)
})
}

onDone()
})
}

var q = [
createFolder.bind(null, './build', done),
bundle.bind(null, 'lib/index.js', 'QRCode', 'build/qrcode.js', done),
bundle.bind(null, 'helper/to-sjis.js', 'QRCode.toSJIS', 'build/qrcode.tosjis.js', done),
minify.bind(null, 'build/qrcode.js', 'build/qrcode.min.js', done),
minify.bind(null, 'build/qrcode.tosjis.js', 'build/qrcode.tosjis.min.js', done)
]

function done () {
var j = q.shift()
if (j) j()
else complete()
}
'--output', outputFile,
'--source-map', `url='${path.basename(outputFile)}.map'`,
'--', inputFile
])

function complete () {
console.log('\nBuild complete =)\n'.green)
if (status !== 0) {
console.error(stderr.toString())
process.exit(status)
}
}

done()
createFolder('./build')
bundle('lib/index.js', 'QRCode', 'build/qrcode.js')
bundle('helper/to-sjis.js', 'QRCode.toSJIS', 'build/qrcode.tosjis.js')
minify('build/qrcode.js', 'build/qrcode.min.js')
minify('build/qrcode.tosjis.js', 'build/qrcode.tosjis.min.js')
console.log('\nBuild complete =)\n'.green)
27 changes: 9 additions & 18 deletions examples/clientsideserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ var http = require('http')
var fs = require('fs')
var QRCode = require('../lib')
var canvasutil = require('canvasutil')
var Canvas = require('canvas')
var Image = Canvas.Image
var { createCanvas, loadImage } = require('canvas')

var path = require('path')

Expand Down Expand Up @@ -73,7 +72,7 @@ effectHandlers.bacon = function (args, cb) {
}

effectHandlers.rounded = function (args, cb) {
var canvas = new Canvas(200, 200)
var canvas = createCanvas(200, 200)
QRCode.toCanvas(canvas, args.text || '', function (err) {
if (err) {
cb(err, canvas)
Expand Down Expand Up @@ -223,12 +222,9 @@ effectHandlers.remoteImage = function (args, cb) {
}

effectHandlers.image = function (args, cb) {
var src = args.src || ''

var img = new Image()
var convert = canvasutil.conversionLib
img.onload = function () {
var canvas = new Canvas(200, 200)
loadImage(args.src || '').then((img) => {
var convert = canvasutil.conversionLib
var canvas = createCanvas(200, 200)
QRCode.toCanvas(canvas, args.text || '', function (err) {
if (err) {
cb(err, false)
Expand All @@ -238,7 +234,7 @@ effectHandlers.image = function (args, cb) {
var codeCtx = canvas.getContext('2d')
var frame = codeCtx.getImageData(0, 0, canvas.width, canvas.width)
var tpx = new canvasutil.PixelCore()
var baconCanvas = new Canvas(canvas.width, canvas.width)
var baconCanvas = createCanvas(canvas.width, canvas.width)
var ctx = baconCanvas.getContext('2d')
var topThreshold = args.darkThreshold || 25
var bottomThreshold = args.lightThreshold || 75
Expand Down Expand Up @@ -294,18 +290,13 @@ effectHandlers.image = function (args, cb) {

cb(null, baconCanvas)
})
}

img.onerror = function (error) {
error.message += ' (' + src + ')'
}, (error) => {
cb(error, null)
}

img.src = src
})
}

effectHandlers.plain = function (args, cb) {
var canvas = new Canvas(200, 200)
var canvas = createCanvas(200, 200)
var text = args.text || ''
QRCode.toCanvas(canvas, text || '', function (err) {
cb(err, canvas)
Expand Down
Loading

0 comments on commit a5a8563

Please sign in to comment.