-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from zambezi/refactor-async
Big refactor to use async/await for control flow
- Loading branch information
Showing
11 changed files
with
231 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"presets": ["es2015"], | ||
"plugins": | ||
[ "transform-async-functions" | ||
, "transform-regenerator" | ||
, "transform-es2015-modules-commonjs" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,45 +4,50 @@ | |
"bin": { | ||
"ez-build": "bin/ez-build.js" | ||
}, | ||
"version": "0.2.4", | ||
"version": "0.3.0-refactor-async.1", | ||
"description": "The Zambezi build process", | ||
"devDependencies": { | ||
"babel-cli": "^6.5.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.0" | ||
"babel-plugin-transform-async-functions": "^6.8.0", | ||
"babel-plugin-transform-es2015-modules-commonjs": "^6.5.0", | ||
"babel-plugin-transform-regenerator": "^6.9.0", | ||
"depcheck": "0.6.3" | ||
}, | ||
"dependencies": { | ||
"ansicolors": "0.3.2", | ||
"async": "1.5.2", | ||
"babel-core": "^6.5.0", | ||
"babel-core": "6.5.0", | ||
"babel-plugin-transform-es2015-modules-amd": "^6.5.0", | ||
"babel-polyfill": "6.5.0", | ||
"babel-polyfill": "^6.5.0", | ||
"babel-preset-es2015": "^6.5.0", | ||
"bunyan": "1.6.0", | ||
"chokidar": "1.4.2", | ||
"commander": "^2.9.0", | ||
"glob": "^6.0.4", | ||
"mkdirp": "0.5.1", | ||
"output-file-sync": "1.1.1", | ||
"pkginfo": "^0.3.1", | ||
"postcss": "5.0.16", | ||
"postcss-cssnext": "2.4.0", | ||
"postcss-import": "8.0.2", | ||
"postcss-url": "5.1.1", | ||
"read-package-json": "^2.0.3", | ||
"requirejs": "^2.1.22", | ||
"semver": "^5.1.0", | ||
"commander": "2.9.0", | ||
"funkis": "0.2.0", | ||
"glob": "6.0.4", | ||
"output-file": "1.1.1", | ||
"pkginfo": "0.3.1", | ||
"postcss": "^5.0.16", | ||
"postcss-cssnext": "^2.4.0", | ||
"postcss-import": "^8.0.2", | ||
"postcss-url": "^5.1.1", | ||
"read-package-json": "2.0.3", | ||
"source-map-support": "0.4.0", | ||
"strip-ansi": "3.0.0", | ||
"thenify": "3.2.0", | ||
"window-size": "0.2.0" | ||
}, | ||
"scripts": { | ||
"dev": "npm run build -- --watch", | ||
"build": "babel src -d lib --presets es2015 --plugins transform-es2015-modules-commonjs --source-maps", | ||
"prepublish": "npm run build" | ||
"build": "babel src -d lib --source-maps", | ||
"depcheck": "depcheck . --ignores-dirs=lib", | ||
"prepublish": "npm run depcheck && npm run build" | ||
}, | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "[email protected]:zambezi/ez-build.git" | ||
}, | ||
"engines": { | ||
"node": ">=4" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,9 @@ | ||
import { readFile } from 'fs' | ||
import { slurp } from '../util/file' | ||
import { extname } from 'path' | ||
|
||
export default function configure(pkg, opts) { | ||
return (name, input, done) => { | ||
readFile(input, (error, data) => { | ||
if (error) { | ||
done(error) | ||
} else { | ||
done(null, { files: { [`${name}${extname(input)}`]: data } }) | ||
} | ||
}) | ||
return async function process(name, input) { | ||
let data = await slurp(input) | ||
return { files: { [`${name}${extname(input)}`]: data } } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,26 @@ | ||
import postcss from 'postcss' | ||
import cssimport from 'postcss-import' | ||
import cssnext from 'postcss-cssnext' | ||
import { readFile } from 'fs' | ||
import { slurp } from '../util/file' | ||
import { relative } from 'path' | ||
|
||
export default function configure(pkg, opts) { | ||
const cc = postcss([cssimport, cssnext]) | ||
, map = opts.debug? { inline: false } : false | ||
|
||
return (name, file, done) => { | ||
readFile(file, (error, data) => { | ||
const to = `${opts.lib}/${relative(opts.src, file)}` | ||
cc.process(data, { from: file, to, map }) | ||
.then(result => { | ||
let output = | ||
{ messages: result.messages | ||
, files: { [`${name}.css`]: result.css } | ||
} | ||
return async function process(name, file) { | ||
let data = await slurp(file) | ||
const to = `${opts.lib}/${relative(opts.src, file)}` | ||
let result = await cc.process(data, { from: file, to, map }) | ||
let output = | ||
{ messages: result.messages | ||
, files: { [`${name}.css`]: result.css } | ||
} | ||
|
||
if (opts.debug) { | ||
output.files[`${name}.css.map`] = JSON.stringify(result.map) | ||
} | ||
if (opts.debug) { | ||
output.files[`${name}.css.map`] = JSON.stringify(result.map) | ||
} | ||
|
||
done(null, output) | ||
}) | ||
.catch(done) | ||
}) | ||
return output | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.