Skip to content

Commit

Permalink
fix: properly install outside of SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Mar 26, 2020
1 parent 0528854 commit 1087400
Showing 1 changed file with 29 additions and 14 deletions.
43 changes: 29 additions & 14 deletions packages/agoric-cli/lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,55 @@ export default async function installMain(progname, rawArgs, powers, opts) {
cp.on('error', () => resolve(-1));
});

const rimraf = file => pspawn('rm', ['-rf', file]);
const subdirs = ['_agstate/agoric-servers', 'contract', 'api'].sort()

if (opts.sdk) {
const sdkNodeModules = path.resolve(__dirname, '../../../node_modules');
await Promise.all(
['_agstate/agoric-servers', 'contract', 'api'].sort().map(subdir => {
subdirs.map(subdir => {
const nm = `${subdir}/node_modules`;
log(chalk.bold.green(`link SDK ${nm}`));
return fs
.unlink(nm)
.catch(_ => {})
.then(_ => fs.symlink(sdkNodeModules, nm));
log(chalk.bold.green(`removing ${nm}`));
return rimraf(nm).then(_ => {
log(chalk.bold.green(`link SDK ${nm}`));
return fs.symlink(sdkNodeModules, nm);
});
}),
);

log(chalk.bold.green(`link SDK _agstate/agoric-wallet`));
await fs.unlink(`_agstate/agoric-wallet`).catch(_ => {});
await rimraf('_agstate/agoric-wallet');
const agWallet = path.resolve(__dirname, '../agoric-wallet-build');
try {
const agWallet = path.resolve(__dirname, '../../frontend-wallet/build');
await fs.stat(`${agWallet}/index.html`);
await fs.symlink(agWallet, `_agstate/agoric-wallet`);
} catch (e) {
const agWallet = path.resolve(__dirname, '../agoric-wallet-build');
await fs.symlink(agWallet, `_agstate/agoric-wallet`);
}
} else if (await pspawn('yarn', ['install'], { stdio: 'inherit' })) {
// Try to install via Yarn.
log.error('Cannot yarn install');
return 1;
} else {
// Delete any symlinks.
await Promise.all(
subdirs.map(subdir => {
const nm = `${subdir}/node_modules`;
log(chalk.bold.green(`removing ${nm}`));
return fs.unlink(nm).catch(_ => {});
}),
);

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

// FIXME: Copy the agoric-wallet-build more portably
log(chalk.bold.green(`copy bundled _agstate/agoric-wallet`));
await rimraf('_agstate/agoric-wallet');
const agWallet = path.resolve(__dirname, '../agoric-wallet-build');
if (await pspawn('cp', ['-a', agWallet, '_agstate/agoric-wallet'])) {
log.error('Cannot copy _agstate/agoric-wallet');
}
}
log(chalk.bold.green('Done installing'));
log.info(chalk.bold.green('Done installing'));
return 0;
}

0 comments on commit 1087400

Please sign in to comment.