Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix node v4 support by using babel-preset-env #874

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{
"presets": ["flow"],
"presets": [
["env", {
"targets": {
"node": 4
},
"include": ["transform-regenerator"]
}],
"flow"
],
"plugins": [
["transform-es2015-modules-commonjs", {
"allowTopLevelThis": true
Expand Down
16 changes: 16 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: 2
machine:
node:
version: 4
environment:
PATH: "${PATH}:${HOME}/${CIRCLE_PROJECT_REPONAME}/node_modules/.bin"
dependencies:
override:
- yarn
cache_directories:
- ~/.cache/yarn
test:
override:
- yarn test-ci
post:
- ./node_modules/.bin/coveralls < coverage/lcov.info
8 changes: 0 additions & 8 deletions circle.yml

This file was deleted.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"babel-generator": "6.25.0",
"babel-plugin-system-import-transformer": "3.1.0",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-polyfill": "^6.23.0",
"babel-preset-env": "^1.6.0",
"babel-preset-es2015": "^6.16.0",
"babel-preset-react": "^6.16.0",
"babel-preset-stage-0": "^6.16.0",
Expand Down Expand Up @@ -39,6 +41,7 @@
"parse-filepath": "^1.0.1",
"pify": "^3.0.0",
"read-pkg-up": "^2.0.0",
"regenerator-runtime": "^0.10.5",
"remark": "^8.0.0",
"remark-html": "6.0.1",
"remark-toc": "^4.0.0",
Expand All @@ -60,7 +63,7 @@
"are-we-flow-yet": "^1.0.0",
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-jest": "^20.0.1",
"babel-jest": "^20.0.3",
"babel-plugin-transform-es2015-modules-commonjs": "^6.24.1",
"babel-preset-flow": "^6.23.0",
"chdir": "0.0.0",
Expand Down
48 changes: 24 additions & 24 deletions src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ module.exports.builder = _.assign(
{
example: 'documentation build foo.js -f md > API.md',
output: {
describe: 'output location. omit for stdout, otherwise is a filename ' +
describe:
'output location. omit for stdout, otherwise is a filename ' +
'for single-file outputs and a directory name for multi-file outputs like html',
default: 'stdout',
alias: 'o'
Expand Down Expand Up @@ -64,21 +65,23 @@ module.exports.handler = function build(argv: Object) {
);
}

function generator() {
return documentation
.build(argv.input, argv)
.then(comments =>
documentation.formats[argv.format](comments, argv).then(onFormatted)
)
.catch(err => {
/* eslint no-console: 0 */
if (err instanceof Error) {
console.error(err.stack);
} else {
console.error(err);
}
process.exit(1);
});
async function generator() {
try {
const comments = await documentation.build(argv.input, argv);
const formatted = await documentation.formats[argv.format](
comments,
argv
);
onFormatted(formatted);
} catch (err) {
/* eslint no-console: 0 */
if (err instanceof Error) {
console.error(err.stack);
} else {
console.error(err);
}
process.exit(1);
}
}

function onFormatted(output) {
Expand All @@ -100,18 +103,15 @@ module.exports.handler = function build(argv: Object) {
}
}

function updateWatcher() {
async function updateWatcher() {
if (!watcher) {
watcher = chokidar.watch(argv.input);
watcher.on('all', _.debounce(generator, 300));
}
documentation
.expandInputs(argv.input, argv)
.then(files =>
watcher.add(
files.map(data => (typeof data === 'string' ? data : data.file))
)
);
const files = await documentation.expandInputs(argv.input, argv);
watcher.add(
files.map(data => (typeof data === 'string' ? data : data.file))
);
}

return generator();
Expand Down
28 changes: 13 additions & 15 deletions src/commands/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module.exports.builder = {};
* @returns {undefined} has side-effects
* @private
*/
module.exports.handler = function(argv: Object) {
module.exports.handler = async function(argv: Object) {
argv._handled = true;
if (!argv.input.length) {
try {
Expand All @@ -32,19 +32,17 @@ module.exports.handler = function(argv: Object) {
);
}
}
documentation
.lint(argv.input, argv)
.then(lintOutput => {
if (lintOutput) {
console.log(lintOutput);
process.exit(1);
} else {
process.exit(0);
}
})
.catch(err => {
/* eslint no-console: 0 */
console.error(err);
try {
const lintOutput = await documentation.lint(argv.input, argv);
if (lintOutput) {
console.log(lintOutput);
process.exit(1);
});
} else {
process.exit(0);
}
} catch (err) {
/* eslint no-console: 0 */
console.error(err);
process.exit(1);
}
};
69 changes: 32 additions & 37 deletions src/commands/readme.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports.builder = {
* @param {Object} argv args from the CLI option parser
* @return {undefined} has the side-effect of writing a file or printing to stdout
*/
module.exports.handler = function readme(argv: Object) {
module.exports.handler = async function readme(argv: Object) {
argv._handled = true;

if (!argv.input.length) {
Expand All @@ -75,44 +75,39 @@ module.exports.handler = function readme(argv: Object) {
}
};

var readmeContent = fs.readFileSync(argv.readmeFile, 'utf8');

documentation
.build(argv.input, argv)
.then(comments => documentation.formats.remark(comments, argv))
.then(docsAst =>
remark()
.use(plugin, {
section: argv.section,
toInject: JSON.parse(docsAst)
})
.process(readmeContent)
)
.then(file => {
var diffOutput = disparity.unified(readmeContent, file.contents, {
paths: [argv.readmeFile, argv.readmeFile]
});
if (!diffOutput.length) {
log(`${argv.readmeFile} is up to date.`);
process.exit(0);
}

if (argv.d) {
log(
chalk.bold(`${argv.readmeFile} needs the following updates:`),
`\n${diffOutput}`
);
process.exit(1);
} else {
log(chalk.bold(`Updating ${argv.readmeFile}`), `\n${diffOutput}`);
}
try {
var readmeContent = fs.readFileSync(argv.readmeFile, 'utf8');
const comments = await documentation.build(argv.input, argv);
const docsAst = await documentation.formats.remark(comments, argv);
const file = await remark()
.use(plugin, {
section: argv.section,
toInject: JSON.parse(docsAst)
})
.process(readmeContent);
var diffOutput = disparity.unified(readmeContent, file.contents, {
paths: [argv.readmeFile, argv.readmeFile]
});
if (!diffOutput.length) {
log(`${argv.readmeFile} is up to date.`);
process.exit(0);
}

fs.writeFileSync(argv.readmeFile, file.contents);
})
.catch(err => {
console.error(err);
if (argv.d) {
log(
chalk.bold(`${argv.readmeFile} needs the following updates:`),
`\n${diffOutput}`
);
process.exit(1);
});
} else {
log(chalk.bold(`Updating ${argv.readmeFile}`), `\n${diffOutput}`);
}

fs.writeFileSync(argv.readmeFile, file.contents);
} catch (err) {
console.error(err);
process.exit(1);
}
};

// wrap the inject utility as an remark plugin
Expand Down
71 changes: 33 additions & 38 deletions src/commands/serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports.builder = _.assign(
* @param {Object} argv cli input
* @returns {undefined} has side effects
*/
module.exports.handler = function serve(argv: Object) {
module.exports.handler = async function serve(argv: Object) {
argv._handled = true;

if (!argv.input.length) {
Expand All @@ -54,48 +54,43 @@ module.exports.handler = function serve(argv: Object) {
}
}

getPort(argv.port).then(port => {
var server = new Server(port);
var watcher;
const port = await getPort(argv.port);
var server = new Server(port);
var watcher;

server.on('listening', function() {
process.stdout.write(`documentation.js serving on port ${port}\n`);
});
server.on('listening', function() {
process.stdout.write(`documentation.js serving on port ${port}\n`);
});

function updateWatcher() {
if (!watcher) {
watcher = chokidar.watch(argv.input);
watcher.on('all', _.debounce(updateServer, 300));
}
async function updateWatcher() {
if (!watcher) {
watcher = chokidar.watch(argv.input);
watcher.on('all', _.debounce(updateServer, 300));
}

documentation
.expandInputs(argv.input, argv)
.then(files => {
watcher.add(
files.map(data => (typeof data === 'string' ? data : data.file))
);
})
.catch(err => {
/* eslint no-console: 0 */
return server.setFiles([errorPage(err)]).start();
});
try {
const files = await documentation.expandInputs(argv.input, argv);
watcher.add(
files.map(data => (typeof data === 'string' ? data : data.file))
);
} catch (err) {
/* eslint no-console: 0 */
return server.setFiles([errorPage(err)]).start();
}
}

function updateServer() {
documentation
.build(argv.input, argv)
.then(comments => documentation.formats.html(comments, argv))
.then(files => {
if (argv.watch) {
updateWatcher();
}
server.setFiles(files).start();
})
.catch(err => {
return server.setFiles([errorPage(err)]).start();
});
async function updateServer() {
try {
const comments = await documentation.build(argv.input, argv);
const files = await documentation.formats.html(comments, argv);
if (argv.watch) {
updateWatcher();
}
server.setFiles(files).start();
} catch (err) {
return server.setFiles([errorPage(err)]).start();
}
}

updateServer();
});
updateServer();
};
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require('babel-polyfill');
var fs = require('fs'),
_ = require('lodash'),
sort = require('./sort'),
Expand Down
Loading