diff --git a/apps/sparo-lib/src/cli/commands/ci-checkout.ts b/apps/sparo-lib/src/cli/commands/ci-checkout.ts new file mode 100644 index 0000000..aef30a8 --- /dev/null +++ b/apps/sparo-lib/src/cli/commands/ci-checkout.ts @@ -0,0 +1,50 @@ +import { inject } from 'inversify'; +import type { Argv, ArgumentsCamelCase } from 'yargs'; +import { ICommand } from './base'; +import { Command } from '../../decorator'; +import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService'; + +export interface ICICheckoutCommandOptions { + to?: string[]; + from?: string[]; +} + +@Command() +export class CICheckoutCommand implements ICommand { + public cmd: string = 'checkout'; + public description: string = + 'Special checkout command for CI. It only accepts project selector suchs as --to and --from now.'; + @inject(GitSparseCheckoutService) private _gitSparseCheckoutService!: GitSparseCheckoutService; + public builder(yargs: Argv): void { + yargs + .option('to', { + type: 'array', + alias: 't', + description: 'See https://rushjs.io/pages/developer/selecting_subsets/#--to for more details.' + }) + .option('from', { + type: 'array', + alias: 'f', + description: 'See https://rushjs.io/pages/developer/selecting_subsets/#--from for more details.' + }) + .check((argv, options) => { + const { to, from } = argv; + const toNum: number = (to || []).length; + const fromNum: number = (from || []).length; + if (toNum === 0 && fromNum === 0) { + throw new Error('At least one of "--to" or "--from" must be specified'); + } + return true; + }); + } + public handler = async (args: ArgumentsCamelCase): Promise => { + const { to, from } = args; + await this._gitSparseCheckoutService.checkoutAsync({ + to, + from + }); + }; + public getHelp(): string { + return 'sparse help'; + } +} diff --git a/apps/sparo-lib/src/cli/commands/ci-sparse.ts b/apps/sparo-lib/src/cli/commands/ci-sparse.ts deleted file mode 100644 index 73c5630..0000000 --- a/apps/sparo-lib/src/cli/commands/ci-sparse.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { inject } from 'inversify'; -import type { Argv, ArgumentsCamelCase } from 'yargs'; -import { ICommand } from './base'; -import { Command } from '../../decorator'; -import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService'; - -export interface ICISparseCommandOptions { - to?: string[]; - from?: string[]; -} - -@Command() -export class CISparseCommand implements ICommand { - public cmd: string = 'sparse'; - public description: string = ''; - @inject(GitSparseCheckoutService) private _gitSparseCheckoutService!: GitSparseCheckoutService; - public builder(yargs: Argv): void { - yargs - .array('to') - .array('from') - .check((argv, options) => { - const { to, from } = argv; - const toNum: number = (to || []).length; - const fromNum: number = (from || []).length; - if (toNum === 0 && fromNum === 0) { - throw new Error('At least one --to or --from must be specified'); - } - return true; - }); - } - public handler = async (args: ArgumentsCamelCase): Promise => { - const { to, from } = args; - await this._gitSparseCheckoutService.checkoutAsync({ - to, - from - }); - }; - public getHelp(): string { - return 'sparse help'; - } -} diff --git a/apps/sparo-lib/src/cli/commands/cmd-list.ts b/apps/sparo-lib/src/cli/commands/cmd-list.ts index ad5a3cd..61cec54 100644 --- a/apps/sparo-lib/src/cli/commands/cmd-list.ts +++ b/apps/sparo-lib/src/cli/commands/cmd-list.ts @@ -5,7 +5,7 @@ import { ListProfilesCommand } from './list-profiles'; import { AutoConfigCommand } from './auto-config'; import { FetchCommand } from './fetch'; import { CIHelpCommand } from './ci-help'; -import { CISparseCommand } from './ci-sparse'; +import { CICheckoutCommand } from './ci-checkout'; import { CICloneCommand } from './ci-clone'; import { CheckoutCommand } from './checkout'; import { GitCloneCommand } from './git-clone'; @@ -33,4 +33,4 @@ export const COMMAND_LIST: Constructable[] = [ GitPullCommand ]; -export const CI_COMMAND_LIST: Constructable[] = [CICloneCommand, CISparseCommand, CIHelpCommand]; +export const CI_COMMAND_LIST: Constructable[] = [CICloneCommand, CICheckoutCommand, CIHelpCommand]; diff --git a/common/changes/sparo/fix-ci-checkout_2024-02-28-22-28.json b/common/changes/sparo/fix-ci-checkout_2024-02-28-22-28.json new file mode 100644 index 0000000..97a092f --- /dev/null +++ b/common/changes/sparo/fix-ci-checkout_2024-02-28-22-28.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "sparo", + "comment": "Support checkout --to or --from in sparo-ci, replacing sparo-ci sparse", + "type": "none" + } + ], + "packageName": "sparo" +} \ No newline at end of file