From 4b98dd7088cd2f308a4e5d5e52a9f73704783d64 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 20 Feb 2019 00:33:58 -0800 Subject: [PATCH] binary --- bin.js | 41 +++++++++++++++++++++++++++++++++++++++++ package.json | 8 +++++++- 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100755 bin.js diff --git a/bin.js b/bin.js new file mode 100755 index 0000000..812c995 --- /dev/null +++ b/bin.js @@ -0,0 +1,41 @@ +#!/usr/bin/env node + +'use strict'; + +const promisify = require('util.promisify'); +const chalk = require('chalk'); +const finder = require('find-package-json'); + +const path = require('path'); +const writeFile = promisify(require('fs').writeFile); + +const { filename } = finder(process.cwd()).next(); + +const getLockfile = require('./getLockfile'); + +const { argv: { output, date, package: pkg } } = require('yargs') + .help() + .option('date', { + type: 'string', + describe: '“now”, or a date (same format as `new Date()`)', + demandOption: true, + coerce(arg) { return arg === 'now' ? arg : new Date(arg); }, + }) + .option('package', { + type: 'string', + describe: 'path to a `package.json` file', + normalize: true, + coerce(arg) { return path.resolve(arg); }, + }) + .default('package', filename, path.relative(process.cwd(), filename)) + .option('output', { + alias: 'o', + describe: 'output file path', + normalize: true, + demandOption: true, + }) + +getLockfile(pkg, date === 'now' ? undefined : date, console.log.bind(console)) + .then(lockfile => writeFile(output, lockfile)) + .then(() => { console.log(chalk.green('Lockfile contents written!')); }) + .catch(err => console.error(err)); diff --git a/package.json b/package.json index bd5b6ae..e449ceb 100644 --- a/package.json +++ b/package.json @@ -2,6 +2,7 @@ "name": "npm-lockfile", "version": "0.0.0", "description": "Safely generate an npm lockfile and output it to the filename of your choice.", + "bin": "./bin.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -24,6 +25,7 @@ "homepage": "https://github.com/ljharb/npm-lockfile#readme", "dependencies": { "chalk": "^2.4.2", + "find-package-json": "^1.2.0", "fs-copy-file": "^2.1.2", "is-date-object": "^1.0.1", "node-cleanup": "^2.1.2", @@ -31,6 +33,10 @@ "rimraf": "^2.6.3", "semver": "^5.6.0", "tmp": "0.0.33", - "util.promisify": "^1.0.0" + "util.promisify": "^1.0.0", + "yargs": "^13.2.1" + }, + "engines": { + "node": ">= 6" } }