From 61ac8b64470f9de288bc0a4a87db00360b7e9335 Mon Sep 17 00:00:00 2001 From: Pete Gonzalez <4673363+octogonz@users.noreply.github.com> Date: Thu, 29 Feb 2024 22:53:06 -0800 Subject: [PATCH] Remove SparoCommandSelector.ts in favor of explicit entry points --- apps/sparo/bin/sparo-ci | 2 +- apps/sparo/src/SparoCommandSelector.ts | 45 -------------------------- apps/sparo/src/start-ci.ts | 14 ++++++++ apps/sparo/src/start.ts | 10 ++++-- 4 files changed, 23 insertions(+), 48 deletions(-) delete mode 100644 apps/sparo/src/SparoCommandSelector.ts create mode 100644 apps/sparo/src/start-ci.ts diff --git a/apps/sparo/bin/sparo-ci b/apps/sparo/bin/sparo-ci index aee68e8..cc7abff 100755 --- a/apps/sparo/bin/sparo-ci +++ b/apps/sparo/bin/sparo-ci @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('../lib/start.js'); +require('../lib/start-ci.js'); diff --git a/apps/sparo/src/SparoCommandSelector.ts b/apps/sparo/src/SparoCommandSelector.ts deleted file mode 100644 index 5639102..0000000 --- a/apps/sparo/src/SparoCommandSelector.ts +++ /dev/null @@ -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 { - 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; - } -} diff --git a/apps/sparo/src/start-ci.ts b/apps/sparo/src/start-ci.ts new file mode 100644 index 0000000..3af7083 --- /dev/null +++ b/apps/sparo/src/start-ci.ts @@ -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); diff --git a/apps/sparo/src/start.ts b/apps/sparo/src/start.ts index 9c409ee..11f40fb 100644 --- a/apps/sparo/src/start.ts +++ b/apps/sparo/src/start.ts @@ -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; })