Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add timeout option and progress bar #63

Merged
merged 2 commits into from
Nov 11, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/cli-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@
"@wirelineio/registry-client": "^1.1.0-beta.0",
"assert": "^2.0.0",
"chance": "^1.1.3",
"cli-progress": "^3.8.2",
"express": "^4.17.1",
"fs-extra": "^8.1.0",
"get-folder-size": "^2.0.1",
"hypercore-crypto": "^1.0.0",
"ipfs-http-client": "^42.0.0",
"ipfs-http-client": "^48.0.0",
"js-yaml": "^3.13.1",
"lodash-clean": "^2.2.1",
"lodash.defaultsdeep": "^4.6.1",
Expand Down
27 changes: 19 additions & 8 deletions packages/cli-app/src/handlers/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,46 @@ import IpfsHttpClient, { globSource } from 'ipfs-http-client';
import path from 'path';
import semverInc from 'semver/functions/inc';
import set from 'lodash.set';
import pify from 'pify';
import folderSize from 'get-folder-size';
import cliProgress from 'cli-progress';

import { log } from '@dxos/debug';
import { readFile, writeFile } from '@dxos/cli-core';

import { APP_CONFIG_FILENAME } from '../config';

const getFolderSize = pify(folderSize);

const DEFAULT_DIST_PATH = 'dist';

export const publish = config => async ({ path: distPath = DEFAULT_DIST_PATH }) => {
export const publish = config => async ({ timeout, path: distPath = DEFAULT_DIST_PATH }) => {
const appConfig = await readFile(APP_CONFIG_FILENAME);
log(`Publishing ${appConfig.name}...`);

const ipfsServer = config.get('services.ipfs.server');
assert(ipfsServer, 'Invalid IPFS Server.');

const ipfs = IpfsHttpClient(ipfsServer);
const ipfs = IpfsHttpClient({
url: ipfsServer,
timeout: timeout || '10m'
});

const publishFolder = path.join(process.cwd(), appConfig.publish || distPath);

const uploadedFiles = [];
const source = globSource(publishFolder, { recursive: true });
const total = await getFolderSize(publishFolder);

const bar = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
bar.start(total, 0);

// eslint-disable-next-line
for await (const file of ipfs.add(globSource(publishFolder, { recursive: true }))) {
uploadedFiles.push(file.cid.toString());
}
const addResult = await ipfs.add(source, { progress: bytes => bar.update(bytes) });

assert(uploadedFiles.length, 'No files to upload.');
bar.update(total);
bar.stop();

const cid = uploadedFiles.pop();
const cid = addResult.cid.toString();

// Update CID in app.yml.
set(appConfig, 'package["/"]', cid);
Expand Down
9 changes: 7 additions & 2 deletions packages/cli-app/src/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export const AppModule = ({ config }) => {
command: ['publish'],
describe: 'Publish Application to IPFS.',
builder: yargs => yargs
.option('path', { type: 'string' }),
.option('path', { type: 'string' })
.option('timeout', { type: 'string', default: '10m' }),
handler: asyncHandler(publish(config))
})

Expand Down Expand Up @@ -77,7 +78,11 @@ export const AppModule = ({ config }) => {
.version(false)
.option('gas', { type: 'string' })
.option('fees', { type: 'string' })
.option('name', { type: 'array' }),
.option('name', { type: 'array' })
.option('version', { type: 'string' })
.option('id', { type: 'string' })
.option('namespace', { type: 'string' })
.option('timeout', { type: 'string', default: '10m' }),
handler: asyncHandler(async argv => {
log('Preparing to deploy...');
await build(config, { getAppRecord, getPublicUrl })(argv);
Expand Down
2 changes: 1 addition & 1 deletion packages/cli-pad/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"@dxos/debug": "^1.0.0-beta.67",
"@wirelineio/registry-client": "^1.1.0-beta.0",
"assert": "^2.0.0",
"ipfs-http-client": "^42.0.0",
"ipfs-http-client": "^48.0.0",
"js-yaml": "^3.13.1",
"lodash-clean": "^2.2.1",
"lodash.isequal": "^4.5.0",
Expand Down
7 changes: 5 additions & 2 deletions packages/cli-pad/src/handlers/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ import { PAD_CONFIG_FILENAME } from '../config';

const DEFAULT_DIST_PATH = 'dist';

export const publish = config => async ({ path: distPath = DEFAULT_DIST_PATH }) => {
export const publish = config => async ({ timeout, path: distPath = DEFAULT_DIST_PATH }) => {
const appConfig = await readFile(PAD_CONFIG_FILENAME);
log(`Publishing ${appConfig.name}...`);

const ipfsServer = config.get('services.ipfs.server');
assert(ipfsServer, 'Invalid IPFS Server.');

const ipfs = IpfsHttpClient(ipfsServer);
const ipfs = IpfsHttpClient({
url: ipfsServer,
timeout: timeout || '10m'
});

const publishFolder = path.join(process.cwd(), appConfig.publish || distPath);

Expand Down
10 changes: 8 additions & 2 deletions packages/cli-pad/src/modules/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const AppModule = ({ config }) => {
command: ['publish'],
describe: 'Publish Pad to IPFS.',
builder: yargs => yargs
.option('path', { type: 'string' }),
.option('path', { type: 'string' })
.option('timeout', { type: 'string', default: '10m' }),
handler: asyncHandler(publish(config))
})

Expand All @@ -73,8 +74,13 @@ export const AppModule = ({ config }) => {
builder: yargs => yargs
.strict(false)
.version(false)
.option('name', { type: 'string' })
.option('version', { type: 'string' })
.option('id', { type: 'string' })
.option('namespace', { type: 'string' })
.option('gas', { type: 'string' })
.option('fees', { type: 'string' }),
.option('fees', { type: 'string' })
.option('timeout', { type: 'string', default: '10m' }),
handler: asyncHandler(async argv => {
log('Preparing to deploy...');
await build(config, { getPadRecord })(argv);
Expand Down
Loading