introducing 'dryRun'
This commit is contained in:
parent
69f6b5742d
commit
82255d5cb9
14
lib/index.js
14
lib/index.js
@ -13,8 +13,8 @@ import { version } from '../package.json';
|
||||
|
||||
const cloud = new Cloud({ owner: 'zeit', repo: 'pkg-fetch' });
|
||||
|
||||
export async function need (opts = {}) {
|
||||
let { nodeRange, platform, arch, forceFetch, forceBuild } = opts;
|
||||
export async function need (opts = {}) { // eslint-disable-line complexity
|
||||
let { nodeRange, platform, arch, forceFetch, forceBuild, dryRun } = opts;
|
||||
if (!nodeRange) throw wasReported('nodeRange not specified');
|
||||
if (!platform) throw wasReported('platform not specified');
|
||||
if (!arch) throw wasReported('arch not specified');
|
||||
@ -45,24 +45,29 @@ export async function need (opts = {}) {
|
||||
let fetchFailed;
|
||||
if (!forceBuild) {
|
||||
if (await exists(fetched)) {
|
||||
if (dryRun) return 'exists';
|
||||
return fetched;
|
||||
}
|
||||
}
|
||||
if (!forceFetch) {
|
||||
if (await exists(built)) {
|
||||
if (dryRun) return 'exists';
|
||||
if (forceBuild) log.info('Reusing base binaries built locally:', built);
|
||||
return built;
|
||||
}
|
||||
}
|
||||
if (!forceBuild) {
|
||||
if (dryRun) return 'fetched';
|
||||
log.info('Fetching base binaries to:', path.dirname(fetched));
|
||||
if (await cloud.download(remote, fetched)) return fetched;
|
||||
fetchFailed = true;
|
||||
}
|
||||
if (fetchFailed) {
|
||||
if (!dryRun && fetchFailed) {
|
||||
log.info('Not found in GitHub releases:', JSON.stringify(remote));
|
||||
}
|
||||
log.info('Building base binary from source:', path.basename(built));
|
||||
if (!dryRun) {
|
||||
log.info('Building base binary from source:', path.basename(built));
|
||||
}
|
||||
if (hostPlatform !== platform) {
|
||||
throw wasReported(`Not able to build for '${opts.platform}' here, only for '${hostPlatform}'`);
|
||||
}
|
||||
@ -70,6 +75,7 @@ export async function need (opts = {}) {
|
||||
throw wasReported(`Unknown arch '${opts.arch}'. Specify ${knownArchs.join(', ')}`);
|
||||
}
|
||||
|
||||
if (dryRun) return 'built';
|
||||
await build(nodeVersion, arch, built);
|
||||
return built;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user