Skip to content

Commit

Permalink
feat: polish link-cli a little
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfig committed Mar 16, 2020
1 parent e810b87 commit ffbd029
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions scripts/link-cli.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,31 @@ const fs = require('fs');
const path = require('path');

try {
const script = process.argv[2] || '/usr/local/bin/agoric';
const script = process.argv[2] || `${process.env.HOME || '/usr/local'}/bin/agoric`;
const cli = path.resolve(__dirname, '../packages/agoric-cli/bin/agoric');

const bindir = path.dirname(script);
const PATH = process.env.PATH;
if (!PATH) {
console.warn('$PATH is not set, cannot verify');
} else {
// Attempt Windows compatibility.
const sep = PATH.includes(';') ? ';' : ':';
if (!PATH.split(sep).includes(bindir)) {
console.warn(`Script directory ${bindir} does not appear in $PATH`);
let advice;
if (sep === ';') {
advice = `setx PATH "%PATH%${sep}${bindir}"`;
} else {
advice = `export PATH=$PATH${sep}${bindir}`;
}
console.log(`(You may want to \`${advice}' to add it to your PATH environment variable)`);
}
}

console.log(`ensuring ${bindir} exists`);
fs.mkdirSync(bindir, { recursive: true });

const content = `\
#! /bin/sh
# AUTOMATICALLY GENERATED by ${process.argv[1]}
Expand All @@ -15,7 +38,7 @@ exec ${cli} --sdk \${1+"\$@"}
console.log(`creating ${script}`);
fs.writeFileSync(script, content);
fs.chmodSync(script, '0755');
} catch (e) {
} catch (err) {
console.error(err);
process.exit(1);
}
Expand Down

0 comments on commit ffbd029

Please sign in to comment.