Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Improve CLI interface #145

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 32 additions & 10 deletions lib/bin.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
#!/usr/bin/env node

import minimist from 'minimist';
import yargs from 'yargs';

import { hostPlatform, hostArch } from './system';
import { log } from './log';
import { need } from './index';
import { version } from '../package.json';

async function main() {
const argv = minimist(process.argv.slice(2), {
boolean: ['f', 'b'],
string: ['n', 'p', 'a'],
});
const nodeRange = argv.n || argv._.shift();
const platform = argv.p || argv._.shift();
const arch = argv.a || argv._.shift();
const forceFetch = argv.f;
const forceBuild = argv.b;
const { argv } = yargs
.env('PKG_FETCH_OPTION_')
.option('node-range', { alias: 'n', default: 'latest', type: 'string' })
.option('platform', { alias: 'p', default: hostPlatform, type: 'string' })
.option('arch', { alias: 'a', default: hostArch, type: 'string' })
.option('force-fetch', {
alias: 'f',
type: 'boolean',
})
.option('force-build', {
alias: 'b',
type: 'boolean',
})
.conflicts('force-fetch', 'force-build')
.version(version)
.alias('v', 'version')
.help()
.alias('h', 'help');

const {
'node-range': nodeRange,
platform,
arch,
'force-fetch': forceFetch,
'force-build': forceBuild,
} = argv;

const local = await need({
nodeRange,
platform,
arch,
forceFetch,
forceBuild,
});

log.info(local);
}

Expand Down
3 changes: 3 additions & 0 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,9 @@ export async function need(opts: NeedOptions) {

if (!dryRun && fetchFailed) {
log.info('Not found in remote cache:', JSON.stringify(remote));
if (forceFetch) {
throw wasReported(`Failed to fetch.`);
}
}

if (!dryRun) {
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
"expand-template": "^2.0.3",
"fs-extra": "^9.1.0",
"isomorphic-fetch": "^3.0.0",
"minimist": "^1.2.5",
"progress": "^2.0.3",
"request": "^2.88.2",
"request-progress": "^3.0.0",
"semver": "^7.3.5",
"unique-temp-dir": "^1.0.0"
"unique-temp-dir": "^1.0.0",
"yargs": "^16.2.0"
},
"devDependencies": {
"@babel/cli": "^7.13.10",
Expand All @@ -56,11 +56,11 @@
"@types/byline": "^4.2.32",
"@types/fs-extra": "^9.0.9",
"@types/isomorphic-fetch": "^0.0.35",
"@types/minimist": "^1.2.1",
"@types/node": "^14.14.37",
"@types/progress": "^2.0.3",
"@types/request": "^2.48.5",
"@types/semver": "^7.3.4",
"@types/yargs": "^16.0.1",
"@typescript-eslint/eslint-plugin": "^4.19.0",
"@typescript-eslint/parser": "^4.19.0",
"babel-eslint": "^10.1.0",
Expand Down