cloud.js to contain download and upload
This commit is contained in:
parent
6398d7509c
commit
314ef35360
41
lib/cloud.js
Normal file
41
lib/cloud.js
Normal file
@ -0,0 +1,41 @@
|
||||
import { createRelease, downloadAsset, getRelease, uploadAsset } from './github.js';
|
||||
import assert from 'assert';
|
||||
import { version } from '../package.json';
|
||||
|
||||
function uniqueName (remote, names) {
|
||||
if (names.indexOf(remote) < 0) return remote;
|
||||
let name;
|
||||
let counter = 0;
|
||||
while (true) {
|
||||
name = `${remote}-${counter}`;
|
||||
if (names.indexOf(name) < 0) return name;
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
export async function upload (local, remote) {
|
||||
const tag = `v${version}`;
|
||||
let release = await getRelease(tag);
|
||||
if (!release) release = await createRelease(tag);
|
||||
const names = release.assets.map(({ name }) => {
|
||||
assert(name);
|
||||
return name;
|
||||
});
|
||||
const name = uniqueName(remote, names);
|
||||
await uploadAsset(local, release, name);
|
||||
}
|
||||
|
||||
export async function download (remote, local) {
|
||||
const tag = `v${version}`;
|
||||
const release = await getRelease(tag);
|
||||
if (!release) return false;
|
||||
const assets = release.assets.filter(({ name }) => {
|
||||
assert(name);
|
||||
return name === remote;
|
||||
});
|
||||
if (!assets.length) return false;
|
||||
assert(assets.length === 1);
|
||||
const asset = assets[0];
|
||||
await downloadAsset(asset, local);
|
||||
return true;
|
||||
}
|
||||
17
lib/index.js
17
lib/index.js
@ -1,29 +1,14 @@
|
||||
import * as system from './system.js';
|
||||
import { downloadAsset, getRelease } from './github.js';
|
||||
import { exists, mkdirp } from 'fs-promise';
|
||||
import { hostArch, hostPlatform } from './system.js'; // eslint-disable-line no-duplicate-imports
|
||||
import { localPlace, remotePlace } from './places.js';
|
||||
import assert from 'assert';
|
||||
import { download } from './cloud.js';
|
||||
import patchesJson from '../patches/patches.json';
|
||||
import path from 'path';
|
||||
import semver from 'semver';
|
||||
import { version } from '../package.json';
|
||||
|
||||
async function download (remote, local) {
|
||||
const tag = `v${version}`;
|
||||
const release = await getRelease(tag);
|
||||
if (!release) return false;
|
||||
const assets = release.assets.filter(({ name }) => {
|
||||
assert(name);
|
||||
return name === remote;
|
||||
});
|
||||
if (!assets.length) return false;
|
||||
assert(assets.length === 1);
|
||||
const asset = assets[0];
|
||||
await downloadAsset(asset, local);
|
||||
return true;
|
||||
}
|
||||
|
||||
export async function need ({
|
||||
nodeRange = 'latest', platform = hostPlatform,
|
||||
arch = hostArch, dontTakeLocal, dontDownload, dontBuild
|
||||
|
||||
@ -1,35 +1,11 @@
|
||||
import { createRelease, getRelease, uploadAsset } from './github.js';
|
||||
import { hostPlatform, targetArchs } from './system.js';
|
||||
import { localPlace, remotePlace } from './places.js';
|
||||
import assert from 'assert';
|
||||
import build from './build.js';
|
||||
import chalk from 'chalk';
|
||||
import patchesJson from '../patches/patches.json';
|
||||
import { upload } from './cloud.js';
|
||||
import { version } from '../package.json';
|
||||
|
||||
function uniqueName (remote, names) {
|
||||
if (names.indexOf(remote) < 0) return remote;
|
||||
let name;
|
||||
let counter = 0;
|
||||
while (true) {
|
||||
name = `${remote}-${counter}`;
|
||||
if (names.indexOf(name) < 0) return name;
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
async function upload (local, remote) {
|
||||
const tag = `v${version}`;
|
||||
let release = await getRelease(tag);
|
||||
if (!release) release = await createRelease(tag);
|
||||
const names = release.assets.map(({ name }) => {
|
||||
assert(name);
|
||||
return name;
|
||||
});
|
||||
const name = uniqueName(remote, names);
|
||||
await uploadAsset(local, release, name);
|
||||
}
|
||||
|
||||
function isBrokenBuild (nodeVersion, targetArch) {
|
||||
if (/^v?0/.test(nodeVersion) &&
|
||||
/^arm/.test(targetArch)) return true;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user