Skip to content

Commit

Permalink
binary
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 20, 2019
1 parent 696e9ba commit 4b98dd7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
41 changes: 41 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -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));
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -24,13 +25,18 @@
"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",
"object-inspect": "^1.6.0",
"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"
}
}

0 comments on commit 4b98dd7

Please sign in to comment.