Skip to content

Commit

Permalink
Continue Node4 (LTS) Support (#258)
Browse files Browse the repository at this point in the history
* revert to node4 minimum

* remove spreads & destructured assignments
  • Loading branch information
lukeed authored Feb 5, 2017
1 parent aa948a8 commit 48e9ab8
Show file tree
Hide file tree
Showing 16 changed files with 62 additions and 35 deletions.
5 changes: 3 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
language: node_js

node_js:
- "7"
- "6"
- 7
- 6
- 4

git:
depth: 1
Expand Down
1 change: 1 addition & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ environment:
matrix:
- nodejs_version: "7"
- nodejs_version: "6"
- nodejs_version: "4.6"

max_jobs: 4
clone_depth: 1
Expand Down
2 changes: 2 additions & 0 deletions lib/boot.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict"

const Promise = require('bluebird');

function deferAll(obj) {
Expand Down
6 changes: 4 additions & 2 deletions lib/fly.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { resolve } = require("path")
"use strict"

const res = require("path").resolve
const Promise = require("bluebird")
const Emitter = require("events")
const wrapp = require("./wrapp")
Expand All @@ -25,7 +27,7 @@ class Fly extends Emitter {
}

this.file = file
this.root = resolve(opts.cwd || ".")
this.root = res(opts.cwd || ".")

// construct V8 shapes
this.tasks = {}
Expand Down
16 changes: 10 additions & 6 deletions lib/plugins.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
"use strict"

const { dirname, resolve, join } = require("path")
const { flatten, isObject } = require("./fn")
const { coroutine } = require("bluebird")
const p = require("path")
const isObject = require("./fn").isObject
const flatten = require("./fn").flatten
const co = require("bluebird").coroutine
const $ = require("./utils")

const rgx = /^fly-/i
const dirname = p.dirname
const resolve = p.resolve
const join = p.join

/**
* Attempt to dynamically `require()` a file or package
Expand All @@ -19,7 +23,7 @@ function req(name, base) {
} catch (_) {
name = join(base, name)
} finally {
return require(name)
return require(name);
}
} catch (e) {
$.alert(e.message)
Expand Down Expand Up @@ -53,7 +57,7 @@ function getDependencies(pkg) {
* @param {String} dir
* @yield {Object} If found, returns as `{file, data}`
*/
const getPackage = coroutine(function * (dir) {
const getPackage = co(function * (dir) {
// traverse upwards from `dir`
const file = yield $.find("package.json", dir)

Expand All @@ -77,7 +81,7 @@ const getPackage = coroutine(function * (dir) {
* @param {String} flyfile The full `flyfile.js` path
* @return {Array} All loaded plugins.
*/
const load = coroutine(function * (flyfile) {
const load = co(function * (flyfile) {
// find a `package.json`, starting with `flyfile` dir
const pkg = yield getPackage(dirname(flyfile))

Expand Down
2 changes: 1 addition & 1 deletion lib/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const fmt = require("./fmt")
const $ = require("./utils/logging")
const { formatTime } = require("./fn")
const formatTime = require("./fn").formatTime

module.exports = function () {
return this
Expand Down
8 changes: 7 additions & 1 deletion lib/task.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { format, normalize, parse, sep} = require("path")
"use strict"

const p = require("path")
const Promise = require("bluebird")
const wrapp = require("./wrapp")
const util = require("./utils")
Expand All @@ -7,6 +9,10 @@ const $ = require("./fn")

const RGX = /[\\|\/]/g
const co = Promise.coroutine
const normalize = p.normalize
const format = p.format
const parse = p.parse
const sep = p.sep

function Task(fly) {
// construct shape
Expand Down
3 changes: 2 additions & 1 deletion lib/utils/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

const Promise = require("bluebird")
const glob = Promise.promisify(require("glob"))
const { getUniques, toArray } = require("../fn")
const getUniques = require("../fn").getUniques
const toArray = require("../fn").toArray

const isString = val => typeof val === "string"
const hasIgnore = val => val[0] === "!"
Expand Down
6 changes: 4 additions & 2 deletions lib/utils/find.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
"use strict"

const { resolve, normalize } = require("path")
const { promisify } = require("bluebird")
const p = require("path")
const promisify = require("bluebird").promisify
const glob = promisify(require("glob"))
const normalize = p.normalize
const resolve = p.resolve

/**
* Find a file from a given path
Expand Down
6 changes: 3 additions & 3 deletions lib/utils/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
"use strict"

const { coroutine, promisify } = require("bluebird")
const Promise = require("bluebird")
const logging = require("./logging")

module.exports = Object.assign(logging, {
coroutine,
coroutine: Promise.coroutine,
expand: require("./expand"),
find: require("./find"),
promisify,
promisify: Promise.promisify,
read: require("./read"),
trace: require("./trace"),
write: require("./write")
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/logging.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
* - use es2015
*/

const { homedir } = require("os")
const clor = require("clor")
const { getTime } = require("../fn")
const homedir = require("os").homedir
const getTime = require("../fn").getTime

/**
* Apply args to the `console[method]` & Add a date stamp.
Expand Down
13 changes: 7 additions & 6 deletions lib/utils/read.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
"use strict"

const { readFile, stat } = require("fs")
const { coroutine, promisify } = require("bluebird")
const read = promisify(readFile)
const stats = promisify(stat)
const fs = require("fs")
const Promise = require("bluebird")
const stat = Promise.promisify(fs.stat)
const read = Promise.promisify(fs.readFile)
const co = Promise.coroutine

/**
* Return a file's contents. Will not read directory!
* @param {String} file The file's path.
* @param {Object|String} opts See `fs.readFile`.
* @yield {Buffer|String}
*/
module.exports = coroutine(function * (file, opts) {
const s = yield stats(file)
module.exports = co(function * (file, opts) {
const s = yield stat(file)
return s.isFile() ? yield read(file, opts) : null
})
12 changes: 7 additions & 5 deletions lib/utils/write.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"use strict"

const { dirname, normalize } = require("path")
const { coroutine, promisify } = require("bluebird")
const write = promisify(require("fs").writeFile)
const mkdirp = promisify(require("mkdirp"))
const p = require("path")
const Promise = require("bluebird")
const write = Promise.promisify(require("fs").writeFile)
const mkdirp = Promise.promisify(require("mkdirp"))
const normalize = p.normalize
const dirname = p.dirname

/**
* Write to a file with given data.
* Creates ancestor directories if needed.
* @param {String} file The full file"s path.
* @param {String} data The data to write.
*/
module.exports = coroutine(function * (file, data) {
module.exports = Promise.coroutine(function * (file, data) {
try {
file = normalize(file)
yield mkdirp(dirname(file))
Expand Down
8 changes: 6 additions & 2 deletions lib/wrapp.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"use strict"

const Promise = require("bluebird")
const co = Promise.coroutine

Expand All @@ -6,12 +8,14 @@ module.exports = function (opts, func) {
opts = Object.assign({every: 1, files: 1}, opts)
func = opts.func || func

return co(function * (o, ...args) {
return co(function * (o) {
o = o || {}
const args = []
args.push.apply(args, arguments) && args.shift()
// grab alias to chosen source type
const arr = this._[opts.files ? "files" : "globs"]
// wrapper pass all arguments to plugin func
const run = s => co(func).call(this, s, o, ...args)
const run = s => co(func).apply(this, [s, o].concat(args))
// loop thru EACH if `every`, else send full source array
yield (opts.every ? Promise.all(arr.map(run)) : run(arr))
// send back instance allow chain
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,6 @@
"build system"
],
"engines": {
"node": ">= 6"
"node": ">= 4.6"
}
}
3 changes: 2 additions & 1 deletion test/fixtures/alt/local-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

module.exports = function (fly, utils) {
const self = this
fly.plugin("localPlugin", {every: 0}, function * (_, { t }) {
fly.plugin("localPlugin", {every: 0}, function * (_, opts) {
const t = opts.t
t.true("root" in fly && "emit" in fly && "tasks" in fly, "plugin creator receives `fly` instance")
t.true("expand" in utils && "find" in utils && "write" in utils, "plugin creator receives `utils` helpers object")
t.deepEqual(fly, self, "plugin creator context bound to `fly` instance")
Expand Down

0 comments on commit 48e9ab8

Please sign in to comment.