Skip to content

Commit

Permalink
feat(#111): parse args & print version
Browse files Browse the repository at this point in the history
  • Loading branch information
jannis-baum committed Jul 19, 2024
1 parent 4e89db7 commit 8ef57c4
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,39 @@ export const { clientsAt, messageClientsAt } = setupSockets(

const address = `http://localhost:${config.port}`;
const handleArgs = async () => {
await Promise.all(
process.argv.slice(2).map(async (path) => {
if (path.startsWith('-')) return;
if (!existsSync(path)) {
console.log(`File not found: ${path}`);
return;
try {
const args = process.argv.slice(2);
const options = args.filter((arg) => arg.startsWith('-'));
for (const option of options) {
switch (option) {
case '-v':
case '--version':
console.log(`vivify-server ${process.env.VERSION ?? 'dev'}`);
break;
default:
console.log(`unknown option "${option}"`);
}
const target = preferredPath(presolve(path));
const url = `${address}${pathToURL(target)}`;
await open(url);
}),
);
if (process.env['NODE_ENV'] !== 'development') {
// - viv executable waits for this string and then stops printing
// vivify-server's output and terminates
// - the string itself is not shown to the user
console.log('STARTUP COMPLETE');
}

const paths = args.filter((arg) => !arg.startsWith('-'));
await Promise.all(
paths.map(async (path) => {
if (!existsSync(path)) {
console.log(`File not found: ${path}`);
return;
}
const target = preferredPath(presolve(path));
const url = `${address}${pathToURL(target)}`;
await open(url);
}),
);
} finally {
if (process.env['NODE_ENV'] !== 'development') {
// - viv executable waits for this string and then stops printing
// vivify-server's output and terminates
// - the string itself is not shown to the user
console.log('STARTUP COMPLETE');
}
}
};

Expand Down

0 comments on commit 8ef57c4

Please sign in to comment.