mirror of
https://github.com/tiktok/sparo.git
synced 2024-11-14 19:35:12 -05:00
Remove SparoCommandSelector.ts in favor of explicit entry points
This commit is contained in:
parent
dc29742953
commit
61ac8b6447
4 changed files with 23 additions and 48 deletions
|
@ -1,2 +1,2 @@
|
|||
#!/usr/bin/env node
|
||||
require('../lib/start.js');
|
||||
require('../lib/start-ci.js');
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
14
apps/sparo/src/start-ci.ts
Normal file
14
apps/sparo/src/start-ci.ts
Normal 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);
|
|
@ -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;
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue