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

feat(agoric-cli): be more reusable and tolerant to missing dirs #1464

Merged
merged 2 commits into from
Aug 14, 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
40 changes: 1 addition & 39 deletions packages/agoric-cli/bin/agoric
Original file line number Diff line number Diff line change
@@ -1,40 +1,2 @@
#!/usr/bin/env node

const esmRequire = require('esm')(module);

esmRequire('@agoric/install-ses');

const path = require('path');
const WebSocket = require('ws');
const { spawn } = require('child_process');
const fs = require('fs').promises;
const os = require('os');

// Configure logs.
esmRequire('../lib/anylogger-agoric.js');
const anylogger = require('anylogger');

const main = esmRequire('../lib/main.js').default;

const log = anylogger('agoric');
const progname = path.basename(process.argv[1]);

const stdout = str => process.stdout.write(str);
const makeWebSocket = (...args) => new WebSocket(...args);

const rawArgs = process.argv.slice(2);
main(progname, rawArgs, {
anylogger,
stdout,
makeWebSocket,
fs,
os,
process,
spawn,
}).then(
res => res === undefined || process.exit(res),
rej => {
log.error(rej);
process.exit(2);
},
);
require('esm')(module)('../lib/entrypoint');
37 changes: 37 additions & 0 deletions packages/agoric-cli/lib/entrypoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import '@agoric/install-ses';

import path from 'path';
import WebSocket from 'ws';
import { spawn } from 'child_process';
import rawFs from 'fs';
import os from 'os';

// Configure logs.
import './anylogger-agoric';
import anylogger from 'anylogger';

import main from './main';

const fs = rawFs.promises;
const log = anylogger('agoric');
const progname = path.basename(process.argv[1]);

const stdout = str => process.stdout.write(str);
const makeWebSocket = (...args) => new WebSocket(...args);

const rawArgs = process.argv.slice(2);
main(progname, rawArgs, {
anylogger,
stdout,
makeWebSocket,
fs,
os,
process,
spawn,
}).then(
res => res === undefined || process.exit(res),
rej => {
log.error(rej);
process.exit(2);
},
);
32 changes: 23 additions & 9 deletions packages/agoric-cli/lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ export default async function installMain(progname, rawArgs, powers, opts) {
});

const rimraf = file => pspawn('rm', ['-rf', file]);
const subdirs = ['.', '_agstate/agoric-servers', 'contract', 'api'].sort();
const existingSubdirs = await Promise.all(
['.', '_agstate/agoric-servers', 'contract', 'api']
.sort()
.map(async subd => {
const exists = await fs.stat(subd).catch(_ => false);
return exists && subd;
}),
);
const subdirs = existingSubdirs.filter(subd => subd);

const linkFolder = path.resolve(`_agstate/yarn-links`);
const linkFlags = [`--link-folder=${linkFolder}`, 'link'];
Expand All @@ -33,7 +41,7 @@ export default async function installMain(progname, rawArgs, powers, opts) {
const dir = `${sdkPackagesDir}/${pkg}`;
const packageJSON = await fs
.readFile(`${dir}/package.json`)
.catch(_ => undefined);
.catch(err => log('error reading', `${dir}/package.json`, err));
if (!packageJSON) {
return undefined;
}
Expand Down Expand Up @@ -74,7 +82,10 @@ export default async function installMain(progname, rawArgs, powers, opts) {

// Update all the package dependencies according to the SDK.
const pjson = `${subdir}/package.json`;
const packageJSON = await fs.readFile(pjson);
const packageJSON = await fs.readFile(pjson).catch(_ => undefined);
if (!packageJSON) {
return;
}
const pj = JSON.parse(packageJSON);
for (const section of ['dependencies', 'devDependencies']) {
const deps = pj[section];
Expand Down Expand Up @@ -115,19 +126,22 @@ export default async function installMain(progname, rawArgs, powers, opts) {
);
}

if (await pspawn('yarn', [linkFlags[0], 'install'], { stdio: 'inherit' })) {
const yarnInstall = await pspawn('yarn', [linkFlags[0], 'install'], {
stdio: 'inherit',
});
if (yarnInstall) {
// Try to install via Yarn.
log.error('Cannot yarn install');
return 1;
}

if (
await pspawn('yarn', [linkFlags[0], 'install'], {
// Try to install via Yarn.
const yarnInstallUi = await (subdirs.includes('ui') &&
pspawn('yarn', [linkFlags[0], 'install'], {
stdio: 'inherit',
cwd: 'ui',
})
) {
// Try to install via Yarn.
}));
if (yarnInstallUi) {
log.warn('Cannot yarn install in ui directory');
return 1;
}
Expand Down
1 change: 1 addition & 0 deletions packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"dependencies": {
"@agoric/bundle-source": "^1.1.6",
"@agoric/install-ses": "^0.2.0",
"@agoric/captp": "^1.3.3",
"@agoric/promise-kit": "^0.1.3",
"@iarna/toml": "^2.2.3",
Expand Down
7 changes: 2 additions & 5 deletions packages/dapp-svelte-wallet/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@agoric/captp": "^1.3.3",
"@rollup/plugin-commonjs": "^12.0.0",
"@rollup/plugin-node-resolve": "^8.0.0",
"livereload-js": "file:livereload-js-v3.3.1.tgz",
"livereload-js": "https://github.com/agoric-labs/livereload-js",
"rollup": "^2.3.4",
"rollup-plugin-livereload": "^1.0.0",
"rollup-plugin-svelte": "^5.0.3",
Expand All @@ -28,8 +28,5 @@
},
"files": [
"public"
],
"dependencies": {
"livereload-js": "https://github.com/agoric-labs/livereload-js"
}
]
}