Skip to content

Commit

Permalink
feat(install): detect incorrect Go version
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Nov 2, 2019
1 parent 726a297 commit 6fb3722
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions lib/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,27 @@ export default async function installMain(progname, rawArgs, priv) {
cp.on('exit', resolve);
cp.on('error', () => resolve(-1));
});


const spawnOutput = (cmd, args = [], opts = {}) => new Promise((resolve, reject) => {
let buf = '';
const cp = spawn(cmd, args, { ...opts, stdio: ['inherit', 'pipe', 'inherit' ] });
cp.stdout.on('data', chunk => buf += String(chunk));
cp.on('exit', () => resolve(buf));
cp.on('error', () => resolve(buf));
});

// Install Yarn.
const pmRet = await pspawn('yarn', ['--version']);
if (pmRet !== 0) {
await pspawn('npm', ['install', '-g', 'yarn'], { stdio: 'inherit' });
}
const pm = 'yarn';

// FIXME: Check for version 1.13.
const goRet = await pspawn('go', ['version']);
const goCmd = goRet === 0 && pspawn('npm', ['install'], { cwd: '.agservers', stdio: 'inherit' });
// Check for golang version 1.12+.
const goVsn = await spawnOutput('go', ['version']);
const match = goVsn.match(/^go version go1\.(\d+)\./);
const goCmd = match && Number(match[1]) >= 12 &&
pspawn('npm', ['install'], { cwd: '.agservers', stdio: 'inherit' });

await Promise.all([
pspawn(pm, ['install'], { cwd: 'ui', stdio: 'inherit' }),
Expand All @@ -34,7 +44,7 @@ export default async function installMain(progname, rawArgs, priv) {
]);

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.yellow(`To run Agoric locally you will need to install Go 1.12+ and rerun '${progname} install'`));
} else {
// FIXME: Build the wallet
await pspawn(pm, ['install'], { cwd: '.agservers/node_modules/@agoric/wallet-frontend' });
Expand Down

0 comments on commit 6fb3722

Please sign in to comment.