Skip to content

Commit

Permalink
feat(install): npm/yarn install
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 2, 2019
1 parent 2d19210 commit ad66d97
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 1,346 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ integration-test/transform-tests/output

# generated Sphinx/ReadTheDocs files
/docs/build/
/foo
/demo
39 changes: 39 additions & 0 deletions lib/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import parseArgs from 'minimist';
import chalk from 'chalk';
import { spawn } from 'child_process';
import { promises as fs } from 'fs';
import { resolve } from 'any-promise';

export default async function installMain(progname, rawArgs, priv) {
const { console, error } = priv;
const {
_: args,
} = parseArgs(rawArgs);

let uiPackager = 'npm';
try {
await fs.stat('ui/yarn.lock');
uiPackager = 'yarn';
} catch (e) {}

const pspawn = (...args) => new Promise((resolve, reject) => {
const cp = spawn(...args);
cp.on('exit', resolve);
cp.on('error', () => resolve(-1));
});
const ret = await pspawn('nogo', ['version']);

const goCmd = ret === 0 && pspawn('npm', ['install'], { cwd: '.agservers', stdio: 'inherit' });

const children = await Promise.all([
pspawn(uiPackager, ['install'], { cwd: 'ui', stdio: 'inherit' }),
pspawn('npm', ['install'], { cwd: 'api', stdio: 'inherit' }),
pspawn('npm', ['install'], { cwd: 'contract', stdio: 'inherit' }),
goCmd,
]);

if (!goCmd) {
console.log(chalk.bold.yellow(`To run Agoric locally you will need to install Go and rerun '${progname} install'`));
}
console.log(chalk.bold.green('Done installing'));
}
23 changes: 13 additions & 10 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ const main = async (progname, rawArgs, privs) => {
stopEarly: true,
});

const insistIsBasedir = async () => {
const isNotBasedir = async () => {
try {
await fs.promises.stat('.agservers');
return false;
} catch (e) {
error(`current directory wasn't created by '${progname} init'`);
return usage(1);
}
};

Expand All @@ -28,15 +30,19 @@ const main = async (progname, rawArgs, privs) => {

const usage = status => {
if (status) {
console.error(chalk.bold(`Type '${progname} --help' for more information.`));
console.error(chalk.bold.yellow(`Type '${progname} --help' for more information.`));
return status;
}
console.log(`\
Usage: ${progname} [command] [...args]
Manage the Agoric Javascript smart contract platform.
help display this help and exit
deploy upload dapp to started Agoric servers
help display this help and exit
init initialize a dapp project
install load dapp dependencies
start run Agoric servers
`);
return 0;
};
Expand All @@ -58,14 +64,11 @@ help display this help and exit
case 'help':
return usage(0);
case 'deploy':
await insistIsBasedir();
return subMain((await import('./deploy')).default, args);
return await isNotBasedir() || subMain((await import('./deploy')).default, args);
case 'install':
return await isNotBasedir() || subMain((await import('./install')).default, args);
case 'start':
await insistIsBasedir();
return subMain((await import('./start')).default, args);
// TODO
case 'template':
return subMain((await import('./template')).default, args);
return await isNotBasedir() || subMain((await import('./start')).default, args);
case 'init':
return subMain((await import('./init')).default, args);
default:
Expand Down
Loading

0 comments on commit ad66d97

Please sign in to comment.