Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: unifiedjs/unified-args
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 8e9db336bb0110b4d46d3673d7d138c2e56de687
Choose a base ref
...
head repository: unifiedjs/unified-args
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 52d145d6e359e4f43d797d458a9667deee09d826
Choose a head ref

Commits on Jul 19, 2017

  1. Fix prettifying of markdown

    wooorm committed Jul 19, 2017
    Copy the full SHA
    381f1b3 View commit details

Commits on Nov 17, 2017

  1. Replace custom JSON parsing with JSON5

    This drops support for automatic camel-casing of properties, and also
    removes support for dash-cased identifiers.
    
    Closes GH-16.
    wooorm committed Nov 17, 2017
    Copy the full SHA
    0693817 View commit details
  2. Update dev-dependencies

    wooorm committed Nov 17, 2017
    Copy the full SHA
    ea05603 View commit details
  3. Update unified-engine

    wooorm committed Nov 17, 2017
    Copy the full SHA
    dca5942 View commit details
  4. Update Node in Travis

    wooorm committed Nov 17, 2017
    Copy the full SHA
    fa72b1c View commit details
  5. Add skip_cleanup to Travis

    wooorm committed Nov 17, 2017
    Copy the full SHA
    26d66ec View commit details
  6. 5.0.0

    wooorm committed Nov 17, 2017
    Copy the full SHA
    834b649 View commit details
  7. Copy the full SHA
    1aca62b View commit details

Commits on Dec 8, 2017

  1. Fix link

    wooorm committed Dec 8, 2017
    Copy the full SHA
    b0ad11b View commit details

Commits on Jan 18, 2018

  1. Copy the full SHA
    b752e4e View commit details
  2. 5.1.0

    wooorm committed Jan 18, 2018
    Copy the full SHA
    29c338d View commit details

Commits on May 10, 2018

  1. Copy the full SHA
    4873cea View commit details
  2. Update Node in Travis

    wooorm committed May 10, 2018
    Copy the full SHA
    364bbcc View commit details
  3. Add .npmrc

    wooorm committed May 10, 2018
    Copy the full SHA
    fb6f785 View commit details
  4. Add yarn.lock to .gitignore

    wooorm committed May 10, 2018
    Copy the full SHA
    ce3bbce View commit details
  5. Update camelcase, chokidar, and json5

    Closes GH-19.
    wooorm committed May 10, 2018
    Copy the full SHA
    a7d8020 View commit details
  6. Update dev-dependencies

    wooorm committed May 10, 2018
    Copy the full SHA
    b1ae985 View commit details
  7. Refactor code-style

    wooorm committed May 10, 2018
    Copy the full SHA
    4852b1a View commit details
  8. Use stdout(4) instead of stderr(4) for -v, -h

    Closes GH-18.
    wooorm committed May 10, 2018
    Copy the full SHA
    9a86af8 View commit details
  9. Update unified-engine

    wooorm committed May 10, 2018
    Copy the full SHA
    cfde7a0 View commit details
  10. 6.0.0

    wooorm committed May 10, 2018
    Copy the full SHA
    d2faaef View commit details

Commits on Jun 13, 2019

  1. Update dev-dependencies

    wooorm committed Jun 13, 2019
    Copy the full SHA
    072a421 View commit details
  2. Update json5

    wooorm committed Jun 13, 2019
    Copy the full SHA
    2875873 View commit details
  3. Update chokidar

    wooorm committed Jun 13, 2019
    Copy the full SHA
    ec31cc0 View commit details
  4. Move LICENSE > license

    wooorm committed Jun 13, 2019
    Copy the full SHA
    8c83000 View commit details
  5. Move URLs to HTTPS

    wooorm committed Jun 13, 2019
    Copy the full SHA
    9b20b7e View commit details
  6. Fix tests on Windows

    wooorm committed Jun 13, 2019
    Copy the full SHA
    d22b55a View commit details
  7. Update Node in Travis

    wooorm committed Jun 13, 2019
    Copy the full SHA
    93250eb View commit details
  8. Add Windows to Travis

    wooorm committed Jun 13, 2019
    Copy the full SHA
    7f911be View commit details
  9. Refactor comments

    wooorm committed Jun 13, 2019
    Copy the full SHA
    f65e28e View commit details
  10. Refactor prose

    wooorm committed Jun 13, 2019
    Copy the full SHA
    3ef82d6 View commit details

Commits on Jun 14, 2019

  1. Fix tests on Windows

    Closes GH-21.
    wooorm authored Jun 14, 2019
    Copy the full SHA
    972ef63 View commit details

Commits on Jun 25, 2019

  1. Update dev-dependencies

    wooorm committed Jun 25, 2019
    Copy the full SHA
    bf6d6eb View commit details
  2. Update unified-engine

    wooorm committed Jun 25, 2019
    Copy the full SHA
    03081cc View commit details
  3. Fix support for --file-path

    Closes GH-22.
    wooorm committed Jun 25, 2019
    Copy the full SHA
    daef413 View commit details
  4. 7.0.0

    wooorm committed Jun 25, 2019
    Copy the full SHA
    f5f698c View commit details

Commits on Jun 26, 2019

  1. Fix tests on Windows

    wooorm committed Jun 26, 2019
    Copy the full SHA
    07807e0 View commit details

Commits on Jul 1, 2019

  1. Copy the full SHA
    bdbeb64 View commit details
  2. 7.1.0

    wooorm committed Jul 1, 2019
    Copy the full SHA
    5717d7d View commit details

Commits on Mar 27, 2020

  1. Copy the full SHA
    3b29b76 View commit details
  2. Update dev-dependencies

    wooorm committed Mar 27, 2020
    Copy the full SHA
    9bd3480 View commit details
  3. Remove xtend

    wooorm committed Mar 27, 2020
    Copy the full SHA
    fa520ed View commit details
  4. Remove touch

    wooorm committed Mar 27, 2020
    Copy the full SHA
    f886736 View commit details
  5. Refactor tests

    wooorm committed Mar 27, 2020
    Copy the full SHA
    906132b View commit details
  6. Update chalk

    wooorm committed Mar 27, 2020
    Copy the full SHA
    69f2638 View commit details
  7. Refactor prose

    wooorm committed Mar 27, 2020
    Copy the full SHA
    e66fcf0 View commit details
  8. Fix tests on Windows

    wooorm committed Mar 27, 2020
    Copy the full SHA
    19d965a View commit details

Commits on Mar 30, 2020

  1. Update dev-dependencies

    wooorm committed Mar 30, 2020
    Copy the full SHA
    c6c51f0 View commit details
  2. Update unified-engine

    wooorm committed Mar 30, 2020
    Copy the full SHA
    f074ac9 View commit details
  3. Add types

    Related-to unifiedjs/unified-engine#46.
    Closes GH-23.
    
    Reviewed-by: Titus Wormer <tituswormer@gmail.com>
    ChristianMurphy authored Mar 30, 2020
    Copy the full SHA
    2cd7dc6 View commit details
13 changes: 13 additions & 0 deletions .github/workflows/bb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: bb
on:
issues:
types: [opened, reopened, edited, closed, labeled, unlabeled]
pull_request_target:
types: [opened, reopened, edited, closed, labeled, unlabeled]
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: unifiedjs/beep-boop-beta@main
with:
repo-token: ${{secrets.GITHUB_TOKEN}}
36 changes: 36 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: main
on:
- pull_request
- push
jobs:
main:
name: ${{matrix.node}}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm test
- uses: codecov/codecov-action@v1
strategy:
matrix:
node:
- lts/erbium
- node
windows:
name: ${{matrix.node}}
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: dcodeIO/setup-node-nvm@master
with:
node-version: ${{matrix.node}}
- run: npm install
- run: npm run test-api
strategy:
matrix:
node:
- lts/erbium
- node
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.DS_Store
*.log
.nyc_output/
coverage/
node_modules/
.DS_Store
*.d.ts
*.log
yarn.lock
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage/
*.md
13 changes: 0 additions & 13 deletions .travis.yml

This file was deleted.

7 changes: 5 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
'use strict';
module.exports = require('./lib/index.js');
/**
* @typedef {import('./lib/index.js').Options} Options
*/

export {args} from './lib/index.js'
243 changes: 135 additions & 108 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,156 +1,183 @@
'use strict';

var stream = require('stream');
var engine = require('unified-engine');
var chalk = require('chalk');
var chokidar = require('chokidar');
var options = require('./options');

module.exports = start;

/* No-op. */
var noop = Function.prototype;

/* Fake TTY stream. */
var ttyStream = new stream.Readable();
ttyStream.isTTY = true;

/* Exit, lazily, with the correct exit status code. */
var exitStatus = 0;

process.on('exit', onexit);

/* Handle uncaught errors, such as from unexpected async
* behaviour. */
process.on('uncaughtException', fail);

/* Start the CLI. */
function start(configuration) {
var config;
var output;
var watcher;
/**
* @typedef {import('unified-engine').Options} EngineOptions
* @typedef {import('unified-engine').Context} EngineContext
* @typedef {import('unified-engine').Callback} EngineCallback
* @typedef {import('./options.js').Options} Options
*/

import process from 'node:process'
import stream from 'node:stream'
import chalk from 'chalk'
import chokidar from 'chokidar'
import {engine} from 'unified-engine'
import {options} from './options.js'

// Fake TTY stream.
const ttyStream = Object.assign(new stream.Readable(), {isTTY: true})

// Exit, lazily, with the correct exit status code.
let exitStatus = 0

process.on('exit', onexit)

// Handle uncaught errors, such as from unexpected async behaviour.
process.on('uncaughtException', fail)

/**
* Start the CLI.
*
* @param {Options} cliConfig
*/
export function args(cliConfig) {
/** @type {EngineOptions & {help: boolean, helpMessage: string, watch: boolean, version: boolean}} */
let config
/** @type {chokidar.FSWatcher|undefined} */
let watcher
/** @type {boolean|string|undefined} */
let output

try {
config = options(process.argv.slice(2), configuration);
} catch (err) {
return fail(err, true);
// @ts-expect-error: Close enough.
config = options(process.argv.slice(2), cliConfig)
} catch (error) {
return fail(error, true)
}

if (config.help) {
process.stderr.write([
'Usage: ' + configuration.name + ' [options] [path | glob ...]',
'',
' ' + configuration.description,
'',
'Options:',
'',
config.helpMessage
].join('\n') + '\n', noop);

return;
process.stdout.write(
[
'Usage: ' + cliConfig.name + ' [options] [path | glob ...]',
'',
' ' + cliConfig.description,
'',
'Options:',
'',
config.helpMessage,
''
].join('\n'),
noop
)

return
}

if (config.version) {
process.stderr.write(configuration.version + '\n', noop);
process.stdout.write(cliConfig.version + '\n', noop)

return;
return
}

/* Modify `config` for watching. */
// Modify `config` for watching.
if (config.watch) {
output = config.output;
output = config.output

/* Do not read from stdin(4). */
config.streamIn = ttyStream;
// Do not read from stdin(4).
config.streamIn = ttyStream

/* Do not write to stdout(4). */
config.out = false;
// Do not write to stdout(4).
config.out = false

process.stderr.write(
chalk.bold('Watching...') + ' (press CTRL+C to exit)\n',
noop
);
)

/* Prevent infinite loop if set to regeneration. */
// Prevent infinite loop if set to regeneration.
if (output === true) {
config.output = false;
config.output = false

process.stderr.write(
chalk.yellow('Note') + ': Ignoring `--output` until exit.\n',
noop
);
)
}
}

/* Subscribe a chokidar watcher to all processed files. */
// Initial run.
engine(config, done)

/**
* Handle complete run.
*
* @type {EngineCallback}
*/
function done(error, code, context) {
if (error) {
clean()
fail(error)
} else {
exitStatus = code || 0

if (config.watch && !watcher && context) {
subscribe(context)
}
}
}

// Clean the watcher.
function clean() {
if (watcher) {
watcher.close()
watcher = undefined
}
}

/**
* Subscribe a chokidar watcher to all processed files.
*
* @param {EngineContext} context
*/
function subscribe(context) {
watcher = chokidar
.watch(context.fileSet.origins, {
cwd: config.cwd,
ignoreInitial: true
})
// @ts-expect-error: `fileSet` is available.
.watch(context.fileSet.origins, {cwd: config.cwd, ignoreInitial: true})
.on('error', done)
.on('change', onchange);

process.on('SIGINT', onsigint);

function onchange(filePath) {
config.files = [filePath];
.on('change', (filePath) => {
config.files = [filePath]
engine(config, done)
})

engine(config, done);
}
process.on('SIGINT', onsigint)

/**
* Handle a SIGINT.
*/
function onsigint() {
/* Hide the `^C` in terminal. */
process.stderr.write('\n', noop);
// Hide the `^C` in terminal.
process.stderr.write('\n', noop)

clean();
clean()

/* Do another process if `output` specified regeneration. */
// Do another process if `output` specified regeneration.
if (output === true) {
config.output = output;
config.watch = false;
engine(config, done);
config.output = output
config.watch = false
engine(config, done)
}
}
}

/* Initial run */
engine(config, done);

/* Handle complete run. */
function done(err, code, context) {
if (err) {
clean();
fail(err);
} else {
exitStatus = code;

if (config.watch && !watcher) {
subscribe(context);
}
}
}

/* Clean the watcher. */
function clean() {
if (watcher) {
watcher.close();
watcher = null;
}
}
}

/* Print an error, optionally with stack. */
function fail(err, pretty) {
var message = (pretty ? String(err).trim() : err.stack) || err;
/**
* Print an error, optionally with stack.
*
* @param {Error} error
* @param {boolean} [pretty=false]
*/
function fail(error, pretty) {
// Old versions of Node
/* c8 ignore next 1 */
const message = String((pretty ? error : error.stack) || error)

exitStatus = 1;
exitStatus = 1

process.stderr.write(message.trim() + '\n', noop);
process.stderr.write(message.trim() + '\n', noop)
}

function onexit() {
/* eslint-disable unicorn/no-process-exit */
process.exit(exitStatus);
process.exit(exitStatus)
/* eslint-enable unicorn/no-process-exit */
}

function noop() {}
Loading