Remove SparoCommandSelector.ts in favor of explicit entry points

This commit is contained in:
Pete Gonzalez 2024-02-29 22:53:06 -08:00
parent dc29742953
commit 61ac8b6447
4 changed files with 23 additions and 48 deletions

View file

@ -1,2 +1,2 @@
#!/usr/bin/env node
require('../lib/start.js');
require('../lib/start-ci.js');

View file

@ -1,45 +0,0 @@
import * as path from 'path';
import { Sparo, type ILaunchOptions } from 'sparo-lib';
import { SparoPackage } from './SparoPackage';
type CommandName = 'sparo' | 'sparo-ci' | undefined;
export class SparoCommandSelector {
public static async executeAsync(): Promise<void> {
const commandName: CommandName = SparoCommandSelector._getCommandName();
const launchOptions: ILaunchOptions = {
callerPackageJson: SparoPackage._sparoPackageJson
};
switch (commandName) {
case 'sparo-ci': {
await Sparo.launchSparoCIAsync(launchOptions);
break;
}
default: {
await Sparo.launchSparoAsync(launchOptions);
break;
}
}
}
private static _getCommandName(): CommandName {
if (process.argv.length >= 2) {
// Example:
// argv[0]: "C:\\Program Files\\nodejs\\node.exe"
// argv[1]: "C:\\Program Files\\nodejs\\node_modules\\sparo\\bin\\sparo"
const basename: string = path.basename(process.argv[1]).toUpperCase();
switch (basename) {
case 'SPARO': {
return 'sparo';
}
case 'SPARO-CI': {
return 'sparo-ci';
}
default: {
break;
}
}
}
return undefined;
}
}

View file

@ -0,0 +1,14 @@
import { Sparo, type ILaunchOptions } from 'sparo-lib';
import { SparoPackage } from './SparoPackage';
process.exitCode = 1;
const launchOptions: ILaunchOptions = {
callerPackageJson: SparoPackage._sparoPackageJson
};
Sparo.launchSparoCIAsync(launchOptions)
.then(() => {
process.exitCode = 0;
})
.catch(console.error);

View file

@ -1,7 +1,13 @@
import { SparoCommandSelector } from './SparoCommandSelector';
import { Sparo, type ILaunchOptions } from 'sparo-lib';
import { SparoPackage } from './SparoPackage';
process.exitCode = 1;
SparoCommandSelector.executeAsync()
const launchOptions: ILaunchOptions = {
callerPackageJson: SparoPackage._sparoPackageJson
};
Sparo.launchSparoAsync(launchOptions)
.then(() => {
process.exitCode = 0;
})