diff --git a/apps/sparo-lib/.eslintrc.js b/apps/sparo-lib/.eslintrc.js new file mode 100644 index 0000000..612bb5d --- /dev/null +++ b/apps/sparo-lib/.eslintrc.js @@ -0,0 +1,19 @@ +// This is a workaround for https://github.com/eslint/eslint/issues/3458 +require('@rushstack/heft-node-rig/profiles/default/includes/eslint/patch/modern-module-resolution'); +// This is a workaround for https://github.com/microsoft/rushstack/issues/3021 +require('@rushstack/heft-node-rig/profiles/default/includes/eslint/patch/custom-config-package-names'); + +module.exports = { + extends: [ + '@rushstack/heft-node-rig/profiles/default/includes/eslint/profile/node-trusted-tool', + '@rushstack/heft-node-rig/profiles/default/includes/eslint/mixins/friendly-locals' + ], + parserOptions: { tsconfigRootDir: __dirname }, + + overrides: [ + { + files: ['*.ts', '*.tsx'], + rules: {} + } + ] +}; diff --git a/apps/sparo-lib/.npmignore b/apps/sparo-lib/.npmignore new file mode 100644 index 0000000..e42f0c3 --- /dev/null +++ b/apps/sparo-lib/.npmignore @@ -0,0 +1,32 @@ +# THIS IS A STANDARD TEMPLATE FOR .npmignore FILES IN THIS REPO. + +# Ignore all files by default, to avoid accidentally publishing unintended files. +* + +# Use negative patterns to bring back the specific things we want to publish. +!/bin/** +!/lib/** +!/lib-*/** +!/dist/** +!ThirdPartyNotice.txt + +# Ignore certain patterns that should not get published. +/dist/*.stats.* +/lib/**/test/ +/lib-*/**/test/ +*.test.js + +# NOTE: These don't need to be specified, because NPM includes them automatically. +# +# package.json +# README (and its variants) +# CHANGELOG (and its variants) +# LICENSE / LICENCE + +#-------------------------------------------- +# DO NOT MODIFY THE TEMPLATE ABOVE THIS LINE +#-------------------------------------------- + +# (Add your project-specific overrides here) +!/assets/** +/lib-*/** diff --git a/apps/sparo-lib/LICENSE b/apps/sparo-lib/LICENSE new file mode 100644 index 0000000..3bd1dad --- /dev/null +++ b/apps/sparo-lib/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) TikTok Pte. Ltd. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/apps/sparo-lib/README.md b/apps/sparo-lib/README.md new file mode 100644 index 0000000..6f19b06 --- /dev/null +++ b/apps/sparo-lib/README.md @@ -0,0 +1,6 @@ +## sparo-lib + +This is a companion package for the Sparo tool. + +The **sparo-lib** version number is always exactly equal +to the **sparo** version number that it depends on. diff --git a/apps/sparo-lib/config/api-extractor.json b/apps/sparo-lib/config/api-extractor.json new file mode 100644 index 0000000..996e271 --- /dev/null +++ b/apps/sparo-lib/config/api-extractor.json @@ -0,0 +1,19 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json", + + "mainEntryPointFilePath": "/lib/index.d.ts", + + "apiReport": { + "enabled": true, + "reportFolder": "../../../common/reviews/api" + }, + + "docModel": { + "enabled": true, + "apiJsonFilePath": "../../../common/temp/api/.api.json" + }, + + "dtsRollup": { + "enabled": true + } +} diff --git a/apps/sparo-lib/config/jest.config.json b/apps/sparo-lib/config/jest.config.json new file mode 100644 index 0000000..4bb17bd --- /dev/null +++ b/apps/sparo-lib/config/jest.config.json @@ -0,0 +1,3 @@ +{ + "extends": "@rushstack/heft-node-rig/profiles/default/config/jest.config.json" +} diff --git a/apps/sparo-lib/config/rig.json b/apps/sparo-lib/config/rig.json new file mode 100644 index 0000000..58032e0 --- /dev/null +++ b/apps/sparo-lib/config/rig.json @@ -0,0 +1,5 @@ +{ + "$schema": "https://developer.microsoft.com/json-schemas/rig-package/rig.schema.json", + + "rigPackageName": "@rushstack/heft-node-rig" +} diff --git a/apps/sparo-lib/package.json b/apps/sparo-lib/package.json new file mode 100644 index 0000000..ff0d072 --- /dev/null +++ b/apps/sparo-lib/package.json @@ -0,0 +1,31 @@ +{ + "name": "sparo-lib", + "version": "0.0.0", + "description": "A library for writing scripts that interact with the Sparo", + "license": "MIT", + "main": "lib/index.js", + "typings": "dist/sparo-lib.d.ts", + "scripts": { + "_phase:build": "heft run --only build -- --clean", + "_phase:test": "heft run --only test -- --clean", + "test": "heft test --clean", + "build": "heft build --clean" + }, + "dependencies": { + "@rushstack/node-core-library": "~3.64.2", + "git-repo-info": "~2.1.1", + "inversify": "~6.0.2", + "reflect-metadata": "~0.2.1", + "winston": "~3.11.0", + "yargs": "~17.7.2" + }, + "devDependencies": { + "@rushstack/heft": "0.64.3", + "@rushstack/heft-node-rig": "2.4.5", + "@types/heft-jest": "1.0.6", + "@types/node": "20.11.16", + "@types/yargs": "17.0.32", + "eslint": "8.56.0", + "typescript": "~5.3.3" + } +} diff --git a/apps/sparo-lib/src/api/Sparo.ts b/apps/sparo-lib/src/api/Sparo.ts new file mode 100644 index 0000000..e371a84 --- /dev/null +++ b/apps/sparo-lib/src/api/Sparo.ts @@ -0,0 +1,19 @@ +import { SparoCommandLine } from '../cli/SparoCommandLine'; +import { SparoCICommandLine } from '../cli/SparoCICommandLine'; + +/** + * General operations for Sparo engine. + * + * @public + */ +export class Sparo { + private constructor() {} + + public static async launchSparoAsync(): Promise { + await SparoCommandLine.launchAsync(); + } + + public static async launchSparoCIAsync(): Promise { + await SparoCICommandLine.launchAsync(); + } +} diff --git a/apps/sparo/src/api/SparoCI.ts b/apps/sparo-lib/src/cli/SparoCICommandLine.ts similarity index 78% rename from apps/sparo/src/api/SparoCI.ts rename to apps/sparo-lib/src/cli/SparoCICommandLine.ts index 88cf0b3..c74c91c 100644 --- a/apps/sparo/src/api/SparoCI.ts +++ b/apps/sparo-lib/src/cli/SparoCICommandLine.ts @@ -1,18 +1,21 @@ import 'reflect-metadata'; import { getFromContainer, registerClass } from '../di/container'; import { CommandService } from '../services/CommandService'; -import { CI_COMMAND_LIST } from '../commands/cmd-list'; -import { ICommand } from '../commands/base'; +import { CI_COMMAND_LIST } from './commands/cmd-list'; +import { ICommand } from './commands/base'; import { ArgvService } from '../services/ArgvService'; -import { CIHelpCommand } from '../commands/ci-help'; +import { CIHelpCommand } from './commands/ci-help'; +import { GitVersionCompatibility } from '../logic/GitVersionCompatibility'; -class SparoCI { +export class SparoCICommandLine { private _commandsMap: Set = new Set(); private constructor() {} public static async launchAsync(): Promise { - const sparoCI: SparoCI = new SparoCI(); + await GitVersionCompatibility.ensureGitVersionAsync(); + + const sparoCI: SparoCICommandLine = new SparoCICommandLine(); await sparoCI.prepareCommandAsync(); await sparoCI.runAsync(); } @@ -45,5 +48,3 @@ class SparoCI { return this._commandsMap.has(commandName); } } - -export { SparoCI }; diff --git a/apps/sparo/src/api/Sparo.ts b/apps/sparo-lib/src/cli/SparoCommandLine.ts similarity index 81% rename from apps/sparo/src/api/Sparo.ts rename to apps/sparo-lib/src/cli/SparoCommandLine.ts index e28b798..73b0778 100644 --- a/apps/sparo/src/api/Sparo.ts +++ b/apps/sparo-lib/src/cli/SparoCommandLine.ts @@ -3,17 +3,20 @@ import { getFromContainer, registerClass } from '../di/container'; import { GitService } from '../services/GitService'; import { CommandService } from '../services/CommandService'; import { ArgvService } from '../services/ArgvService'; -import { COMMAND_LIST } from '../commands/cmd-list'; -import { HelpCommand } from '../commands/help'; -import { ICommand } from '../commands/base'; +import { COMMAND_LIST } from './commands/cmd-list'; +import { HelpCommand } from './commands/help'; +import { ICommand } from './commands/base'; +import { GitVersionCompatibility } from '../logic/GitVersionCompatibility'; -class Sparo { +export class SparoCommandLine { private _commandsMap: Set = new Set(); private constructor() {} public static async launchAsync(): Promise { - const sparo: Sparo = new Sparo(); + await GitVersionCompatibility.ensureGitVersionAsync(); + + const sparo: SparoCommandLine = new SparoCommandLine(); await sparo.prepareCommandAsync(); await sparo.runAsync(); } @@ -54,5 +57,3 @@ class Sparo { return this._commandsMap.has(commandName); } } - -export { Sparo }; diff --git a/apps/sparo/src/commands/auto-config.ts b/apps/sparo-lib/src/cli/commands/auto-config.ts similarity index 91% rename from apps/sparo/src/commands/auto-config.ts rename to apps/sparo-lib/src/cli/commands/auto-config.ts index ae08c7a..c12dc8d 100644 --- a/apps/sparo/src/commands/auto-config.ts +++ b/apps/sparo-lib/src/cli/commands/auto-config.ts @@ -1,9 +1,9 @@ import { Argv } from 'yargs'; -import { Command } from '../decorator'; +import { Command } from '../../decorator'; import { inject } from 'inversify'; -import { GitService } from '../services/GitService'; +import { GitService } from '../../services/GitService'; import type { ArgumentsCamelCase } from 'yargs'; -import type { LogService } from '../services/LogService'; +import type { LogService } from '../../services/LogService'; import type { ICommand } from './base'; import type { GitRepoInfo } from 'git-repo-info'; diff --git a/apps/sparo/src/commands/base.ts b/apps/sparo-lib/src/cli/commands/base.ts similarity index 89% rename from apps/sparo/src/commands/base.ts rename to apps/sparo-lib/src/cli/commands/base.ts index 6d81ad5..7ab79fe 100644 --- a/apps/sparo/src/commands/base.ts +++ b/apps/sparo-lib/src/cli/commands/base.ts @@ -1,5 +1,5 @@ import type { Argv, ArgumentsCamelCase } from 'yargs'; -import type { LogService } from '../services/LogService'; +import type { LogService } from '../../services/LogService'; export interface ICommand { /** diff --git a/apps/sparo/src/commands/ci-clone.ts b/apps/sparo-lib/src/cli/commands/ci-clone.ts similarity index 88% rename from apps/sparo/src/commands/ci-clone.ts rename to apps/sparo-lib/src/cli/commands/ci-clone.ts index 3eb3dcd..24c064b 100644 --- a/apps/sparo/src/commands/ci-clone.ts +++ b/apps/sparo-lib/src/cli/commands/ci-clone.ts @@ -1,10 +1,10 @@ import { inject } from 'inversify'; -import { Command } from '../decorator'; -import { GitSparseCheckoutService } from '../services/GitSparseCheckoutService'; -import { GitCloneService, ICloneOptions } from '../services/GitCloneService'; +import { Command } from '../../decorator'; +import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService'; +import { GitCloneService, ICloneOptions } from '../../services/GitCloneService'; import type { Argv, ArgumentsCamelCase } from 'yargs'; import type { ICommand } from './base'; -import type { LogService } from '../services/LogService'; +import type { LogService } from '../../services/LogService'; export interface ICloneCommandOptions { full?: boolean; diff --git a/apps/sparo/src/commands/ci-help.ts b/apps/sparo-lib/src/cli/commands/ci-help.ts similarity index 93% rename from apps/sparo/src/commands/ci-help.ts rename to apps/sparo-lib/src/cli/commands/ci-help.ts index a6a1c28..01693b3 100644 --- a/apps/sparo/src/commands/ci-help.ts +++ b/apps/sparo-lib/src/cli/commands/ci-help.ts @@ -1,4 +1,4 @@ -import { Command } from '../decorator'; +import { Command } from '../../decorator'; import type { Argv } from 'yargs'; import type { ICommand } from './base'; diff --git a/apps/sparo/src/commands/ci-sparse.ts b/apps/sparo-lib/src/cli/commands/ci-sparse.ts similarity index 90% rename from apps/sparo/src/commands/ci-sparse.ts rename to apps/sparo-lib/src/cli/commands/ci-sparse.ts index 1eda133..73c5630 100644 --- a/apps/sparo/src/commands/ci-sparse.ts +++ b/apps/sparo-lib/src/cli/commands/ci-sparse.ts @@ -1,8 +1,8 @@ import { inject } from 'inversify'; import type { Argv, ArgumentsCamelCase } from 'yargs'; import { ICommand } from './base'; -import { Command } from '../decorator'; -import { GitSparseCheckoutService } from '../services/GitSparseCheckoutService'; +import { Command } from '../../decorator'; +import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService'; export interface ICISparseCommandOptions { to?: string[]; diff --git a/apps/sparo/src/commands/clone.ts b/apps/sparo-lib/src/cli/commands/clone.ts similarity index 89% rename from apps/sparo/src/commands/clone.ts rename to apps/sparo-lib/src/cli/commands/clone.ts index d48d7f1..8ea5b67 100644 --- a/apps/sparo/src/commands/clone.ts +++ b/apps/sparo-lib/src/cli/commands/clone.ts @@ -1,11 +1,11 @@ import { inject } from 'inversify'; -import { Command } from '../decorator'; +import { Command } from '../../decorator'; import { executeSelfCmd } from './util'; -import { GitSparseCheckoutService } from '../services/GitSparseCheckoutService'; -import { GitCloneService, ICloneOptions } from '../services/GitCloneService'; +import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService'; +import { GitCloneService, ICloneOptions } from '../../services/GitCloneService'; import type { Argv, ArgumentsCamelCase } from 'yargs'; import type { ICommand } from './base'; -import type { LogService } from '../services/LogService'; +import type { LogService } from '../../services/LogService'; export interface ICloneCommandOptions { full?: boolean; diff --git a/apps/sparo/src/commands/cmd-list.ts b/apps/sparo-lib/src/cli/commands/cmd-list.ts similarity index 94% rename from apps/sparo/src/commands/cmd-list.ts rename to apps/sparo-lib/src/cli/commands/cmd-list.ts index aee8ffb..e5b4b45 100644 --- a/apps/sparo/src/commands/cmd-list.ts +++ b/apps/sparo-lib/src/cli/commands/cmd-list.ts @@ -1,4 +1,4 @@ -import { Constructable } from '../di/types'; +import { Constructable } from '../../di/types'; import { CloneCommand } from './clone'; import { HelpCommand } from './help'; import { SparseCommand } from './sparse'; diff --git a/apps/sparo/src/commands/fetch.ts b/apps/sparo-lib/src/cli/commands/fetch.ts similarity index 89% rename from apps/sparo/src/commands/fetch.ts rename to apps/sparo-lib/src/cli/commands/fetch.ts index 9e19d58..f108248 100644 --- a/apps/sparo/src/commands/fetch.ts +++ b/apps/sparo-lib/src/cli/commands/fetch.ts @@ -1,11 +1,11 @@ import { inject } from 'inversify'; -import { Command } from '../decorator'; -import { GitService } from '../services/GitService'; +import { Command } from '../../decorator'; +import { GitService } from '../../services/GitService'; import type { Argv, ArgumentsCamelCase } from 'yargs'; import type { GitRepoInfo } from 'git-repo-info'; import type { ICommand } from './base'; -import type { LogService } from '../services/LogService'; +import type { LogService } from '../../services/LogService'; export interface IFetchCommandOptions { all?: boolean; diff --git a/apps/sparo/src/commands/help.ts b/apps/sparo-lib/src/cli/commands/help.ts similarity index 93% rename from apps/sparo/src/commands/help.ts rename to apps/sparo-lib/src/cli/commands/help.ts index 08ebee5..a355485 100644 --- a/apps/sparo/src/commands/help.ts +++ b/apps/sparo-lib/src/cli/commands/help.ts @@ -1,4 +1,4 @@ -import { Command } from '../decorator'; +import { Command } from '../../decorator'; import { Argv } from 'yargs'; import type { ICommand } from './base'; diff --git a/apps/sparo/src/commands/purge.ts b/apps/sparo-lib/src/cli/commands/purge.ts similarity index 81% rename from apps/sparo/src/commands/purge.ts rename to apps/sparo-lib/src/cli/commands/purge.ts index c5ec242..57c6147 100644 --- a/apps/sparo/src/commands/purge.ts +++ b/apps/sparo-lib/src/cli/commands/purge.ts @@ -2,9 +2,9 @@ import { inject } from 'inversify'; import { type ArgumentsCamelCase } from 'yargs'; import { ICommand } from './base'; -import { Command } from '../decorator'; -import { GitSparseCheckoutService } from '../services/GitSparseCheckoutService'; -import { LocalState } from '../logic/LocalState'; +import { Command } from '../../decorator'; +import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService'; +import { LocalState } from '../../logic/LocalState'; export interface ISparseCommandOptions { profile: string[]; diff --git a/apps/sparo/src/commands/sparse-add.ts b/apps/sparo-lib/src/cli/commands/sparse-add.ts similarity index 90% rename from apps/sparo/src/commands/sparse-add.ts rename to apps/sparo-lib/src/cli/commands/sparse-add.ts index 11b1d77..9563be9 100644 --- a/apps/sparo/src/commands/sparse-add.ts +++ b/apps/sparo-lib/src/cli/commands/sparse-add.ts @@ -2,8 +2,8 @@ import { inject } from 'inversify'; import type { Argv, ArgumentsCamelCase } from 'yargs'; import { ICommand } from './base'; -import { Command } from '../decorator'; -import { GitSparseCheckoutService } from '../services/GitSparseCheckoutService'; +import { Command } from '../../decorator'; +import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService'; export interface ISparseCommandOptions { profile: string; diff --git a/apps/sparo/src/commands/sparse-list.ts b/apps/sparo-lib/src/cli/commands/sparse-list.ts similarity index 89% rename from apps/sparo/src/commands/sparse-list.ts rename to apps/sparo-lib/src/cli/commands/sparse-list.ts index 2aba2cc..8ac2907 100644 --- a/apps/sparo/src/commands/sparse-list.ts +++ b/apps/sparo-lib/src/cli/commands/sparse-list.ts @@ -1,11 +1,11 @@ import childProcess from 'child_process'; import type { Argv, ArgumentsCamelCase } from 'yargs'; -import { SparseProfileService } from '../services/SparseProfileService'; +import { SparseProfileService } from '../../services/SparseProfileService'; import { ICommand } from './base'; -import { Command } from '../decorator'; +import { Command } from '../../decorator'; import { inject } from 'inversify'; -import { GitSparseCheckoutService } from '../services/GitSparseCheckoutService'; -import type { LogService } from '../services/LogService'; +import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService'; +import type { LogService } from '../../services/LogService'; export interface IProject { name: string; diff --git a/apps/sparo/src/commands/sparse.ts b/apps/sparo-lib/src/cli/commands/sparse.ts similarity index 90% rename from apps/sparo/src/commands/sparse.ts rename to apps/sparo-lib/src/cli/commands/sparse.ts index 37cc435..b73e6c1 100644 --- a/apps/sparo/src/commands/sparse.ts +++ b/apps/sparo-lib/src/cli/commands/sparse.ts @@ -1,8 +1,8 @@ import { inject } from 'inversify'; import type { Argv, ArgumentsCamelCase } from 'yargs'; import { ICommand } from './base'; -import { Command } from '../decorator'; -import { GitSparseCheckoutService } from '../services/GitSparseCheckoutService'; +import { Command } from '../../decorator'; +import { GitSparseCheckoutService } from '../../services/GitSparseCheckoutService'; export interface ISparseCommandOptions { profile: string[]; diff --git a/apps/sparo/src/commands/util.ts b/apps/sparo-lib/src/cli/commands/util.ts similarity index 100% rename from apps/sparo/src/commands/util.ts rename to apps/sparo-lib/src/cli/commands/util.ts diff --git a/apps/sparo/src/decorator/index.ts b/apps/sparo-lib/src/decorator/index.ts similarity index 100% rename from apps/sparo/src/decorator/index.ts rename to apps/sparo-lib/src/decorator/index.ts diff --git a/apps/sparo/src/decorator/test/__fixture__/service.ts b/apps/sparo-lib/src/decorator/test/__fixture__/service.ts similarity index 100% rename from apps/sparo/src/decorator/test/__fixture__/service.ts rename to apps/sparo-lib/src/decorator/test/__fixture__/service.ts diff --git a/apps/sparo/src/decorator/test/decorator.test.ts b/apps/sparo-lib/src/decorator/test/decorator.test.ts similarity index 100% rename from apps/sparo/src/decorator/test/decorator.test.ts rename to apps/sparo-lib/src/decorator/test/decorator.test.ts diff --git a/apps/sparo/src/di/container.ts b/apps/sparo-lib/src/di/container.ts similarity index 100% rename from apps/sparo/src/di/container.ts rename to apps/sparo-lib/src/di/container.ts diff --git a/apps/sparo/src/di/types.ts b/apps/sparo-lib/src/di/types.ts similarity index 100% rename from apps/sparo/src/di/types.ts rename to apps/sparo-lib/src/di/types.ts diff --git a/apps/sparo-lib/src/index.ts b/apps/sparo-lib/src/index.ts new file mode 100644 index 0000000..1e5c623 --- /dev/null +++ b/apps/sparo-lib/src/index.ts @@ -0,0 +1 @@ +export { Sparo } from './api/Sparo'; diff --git a/apps/sparo-lib/src/logic/GitVersionCompatibility.ts b/apps/sparo-lib/src/logic/GitVersionCompatibility.ts new file mode 100644 index 0000000..ff8780f --- /dev/null +++ b/apps/sparo-lib/src/logic/GitVersionCompatibility.ts @@ -0,0 +1,25 @@ +import 'reflect-metadata'; +import { getFromContainer } from '../di/container'; +import { GitService } from '../services/GitService'; + +/** + * This class provides the useful function to check git version. + */ +export class GitVersionCompatibility { + private constructor() {} + + public static async ensureGitVersionAsync(): Promise { + const gitService: GitService = await getFromContainer(GitService); + const gitVersion: [number, number, number] | undefined = gitService.getGitVersion(); + if (!gitVersion) { + throw new Error(`Fail to get git version`); + } + + const [major, minor, patch] = gitVersion; + if (major < 2 || minor < 32) { + throw new Error( + `git version is too low. The minimal git version is >=2.32.0. Your git version is ${major}.${minor}.${patch}. Please upgrade git.` + ); + } + } +} diff --git a/apps/sparo/src/logic/LocalState.ts b/apps/sparo-lib/src/logic/LocalState.ts similarity index 100% rename from apps/sparo/src/logic/LocalState.ts rename to apps/sparo-lib/src/logic/LocalState.ts diff --git a/apps/sparo/src/logic/SparseProfile.ts b/apps/sparo-lib/src/logic/SparseProfile.ts similarity index 100% rename from apps/sparo/src/logic/SparseProfile.ts rename to apps/sparo-lib/src/logic/SparseProfile.ts diff --git a/apps/sparo/src/logic/Stopwatch.ts b/apps/sparo-lib/src/logic/Stopwatch.ts similarity index 100% rename from apps/sparo/src/logic/Stopwatch.ts rename to apps/sparo-lib/src/logic/Stopwatch.ts diff --git a/apps/sparo/src/schemas/sparse-profile.schema.json b/apps/sparo-lib/src/schemas/sparse-profile.schema.json similarity index 100% rename from apps/sparo/src/schemas/sparse-profile.schema.json rename to apps/sparo-lib/src/schemas/sparse-profile.schema.json diff --git a/apps/sparo/src/services/ArgvService.ts b/apps/sparo-lib/src/services/ArgvService.ts similarity index 100% rename from apps/sparo/src/services/ArgvService.ts rename to apps/sparo-lib/src/services/ArgvService.ts diff --git a/apps/sparo/src/services/CommandService.ts b/apps/sparo-lib/src/services/CommandService.ts similarity index 97% rename from apps/sparo/src/services/CommandService.ts rename to apps/sparo-lib/src/services/CommandService.ts index e75bd1a..25ca159 100644 --- a/apps/sparo/src/services/CommandService.ts +++ b/apps/sparo-lib/src/services/CommandService.ts @@ -1,6 +1,6 @@ import { inject } from 'inversify'; import type { Argv } from 'yargs'; -import type { ICommand } from '../commands/base'; +import type { ICommand } from '../cli/commands/base'; import { HelpTextService } from './HelpTextService'; import { LogService } from './LogService'; import { Service } from '../decorator'; diff --git a/apps/sparo/src/services/GitCloneService.ts b/apps/sparo-lib/src/services/GitCloneService.ts similarity index 100% rename from apps/sparo/src/services/GitCloneService.ts rename to apps/sparo-lib/src/services/GitCloneService.ts diff --git a/apps/sparo/src/services/GitService.ts b/apps/sparo-lib/src/services/GitService.ts similarity index 100% rename from apps/sparo/src/services/GitService.ts rename to apps/sparo-lib/src/services/GitService.ts diff --git a/apps/sparo/src/services/GitSparseCheckoutService.ts b/apps/sparo-lib/src/services/GitSparseCheckoutService.ts similarity index 100% rename from apps/sparo/src/services/GitSparseCheckoutService.ts rename to apps/sparo-lib/src/services/GitSparseCheckoutService.ts diff --git a/apps/sparo/src/services/HelpTextService.ts b/apps/sparo-lib/src/services/HelpTextService.ts similarity index 100% rename from apps/sparo/src/services/HelpTextService.ts rename to apps/sparo-lib/src/services/HelpTextService.ts diff --git a/apps/sparo/src/services/LogService.ts b/apps/sparo-lib/src/services/LogService.ts similarity index 100% rename from apps/sparo/src/services/LogService.ts rename to apps/sparo-lib/src/services/LogService.ts diff --git a/apps/sparo/src/services/SparseProfileService.ts b/apps/sparo-lib/src/services/SparseProfileService.ts similarity index 100% rename from apps/sparo/src/services/SparseProfileService.ts rename to apps/sparo-lib/src/services/SparseProfileService.ts diff --git a/apps/sparo/src/services/test/GitService.test.ts b/apps/sparo-lib/src/services/test/GitService.test.ts similarity index 100% rename from apps/sparo/src/services/test/GitService.test.ts rename to apps/sparo-lib/src/services/test/GitService.test.ts diff --git a/apps/sparo-lib/tsconfig.json b/apps/sparo-lib/tsconfig.json new file mode 100644 index 0000000..549aa5b --- /dev/null +++ b/apps/sparo-lib/tsconfig.json @@ -0,0 +1,9 @@ +{ + "$schema": "http://json.schemastore.org/tsconfig", + + "extends": "./node_modules/@rushstack/heft-node-rig/profiles/default/tsconfig-base.json", + "compilerOptions": { + "resolveJsonModule": true, + "types": ["node", "heft-jest"] + } +} diff --git a/apps/sparo/bin/sparo b/apps/sparo/bin/sparo index eef2fc2..aee68e8 100644 --- a/apps/sparo/bin/sparo +++ b/apps/sparo/bin/sparo @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('../lib-commonjs/start.js'); +require('../lib/start.js'); diff --git a/apps/sparo/bin/sparo-ci b/apps/sparo/bin/sparo-ci index eef2fc2..aee68e8 100644 --- a/apps/sparo/bin/sparo-ci +++ b/apps/sparo/bin/sparo-ci @@ -1,2 +1,2 @@ #!/usr/bin/env node -require('../lib-commonjs/start.js'); +require('../lib/start.js'); diff --git a/apps/sparo/config/jest.config.json b/apps/sparo/config/jest.config.json index fd09492..4bb17bd 100644 --- a/apps/sparo/config/jest.config.json +++ b/apps/sparo/config/jest.config.json @@ -1,17 +1,3 @@ { - "extends": "@rushstack/heft-node-rig/profiles/default/config/jest.config.json", - - "roots": ["/lib-commonjs"], - - "testMatch": ["/lib-commonjs/**/*.test.js"], - - "collectCoverageFrom": [ - "lib-commonjs/**/*.js", - "!lib-commonjs/**/*.d.ts", - "!lib-commonjs/**/*.test.js", - "!lib-commonjs/**/test/**", - "!lib-commonjs/**/__tests__/**", - "!lib-commonjs/**/__fixtures__/**", - "!lib-commonjs/**/__mocks__/**" - ] + "extends": "@rushstack/heft-node-rig/profiles/default/config/jest.config.json" } diff --git a/apps/sparo/package.json b/apps/sparo/package.json index 3454429..4b42218 100644 --- a/apps/sparo/package.json +++ b/apps/sparo/package.json @@ -31,23 +31,18 @@ "scripts": { "_phase:build": "heft run --only build -- --clean", "_phase:test": "heft run --only test -- --clean", + "test": "heft test --clean", "build": "heft build --clean" }, "dependencies": { - "@rushstack/node-core-library": "~3.64.2", - "git-repo-info": "~2.1.1", - "inversify": "~6.0.2", - "reflect-metadata": "~0.2.1", - "winston": "~3.11.0", - "yargs": "~17.7.2" + "sparo-lib": "workspace:*" }, "devDependencies": { - "@rushstack/heft": "~0.64.3", - "@rushstack/heft-node-rig": "~2.4.5", + "@rushstack/heft": "0.64.3", + "@rushstack/heft-node-rig": "2.4.5", "@types/heft-jest": "1.0.6", "@types/node": "20.11.16", - "@types/yargs": "17.0.32", - "eslint": "~8.56.0", + "eslint": "8.56.0", "typescript": "~5.3.3" }, "preferGlobal": true diff --git a/apps/sparo/src/SparoCommandSelector.ts b/apps/sparo/src/SparoCommandSelector.ts index b904046..997436d 100644 --- a/apps/sparo/src/SparoCommandSelector.ts +++ b/apps/sparo/src/SparoCommandSelector.ts @@ -1,44 +1,24 @@ import * as path from 'path'; -import 'reflect-metadata'; -import { Sparo } from './api/Sparo'; -import { SparoCI } from './api/SparoCI'; -import { GitService } from './services/GitService'; -import { getFromContainer } from './di/container'; +import { Sparo } from 'sparo-lib'; type CommandName = 'sparo' | 'sparo-ci' | undefined; export class SparoCommandSelector { public static async executeAsync(): Promise { - await SparoCommandSelector._ensureGitVersionAsync(); - const commandName: CommandName = SparoCommandSelector._getCommandName(); switch (commandName) { case 'sparo-ci': { - await SparoCI.launchAsync(); + await Sparo.launchSparoCIAsync(); break; } default: { - await Sparo.launchAsync(); + await Sparo.launchSparoAsync(); + break; } } } - private static async _ensureGitVersionAsync(): Promise { - const gitService: GitService = await getFromContainer(GitService); - const gitVersion: [number, number, number] | undefined = gitService.getGitVersion(); - if (!gitVersion) { - throw new Error(`Fail to get git version`); - } - - const [major, minor, patch] = gitVersion; - if (major < 2 || minor < 32) { - throw new Error( - `git version is too low. The minimal git version is >=2.32.0. Your git version is ${major}.${minor}.${patch}. Please upgrade git.` - ); - } - } - private static _getCommandName(): CommandName { if (process.argv.length >= 2) { // Example: diff --git a/apps/sparo/tsconfig.json b/apps/sparo/tsconfig.json index c2649a0..549aa5b 100644 --- a/apps/sparo/tsconfig.json +++ b/apps/sparo/tsconfig.json @@ -4,7 +4,6 @@ "extends": "./node_modules/@rushstack/heft-node-rig/profiles/default/tsconfig-base.json", "compilerOptions": { "resolveJsonModule": true, - "outDir": "lib-commonjs", "types": ["node", "heft-jest"] } } diff --git a/common/config/rush/pnpm-lock.yaml b/common/config/rush/pnpm-lock.yaml index 73f09cf..540e2e3 100644 --- a/common/config/rush/pnpm-lock.yaml +++ b/common/config/rush/pnpm-lock.yaml @@ -9,6 +9,31 @@ importers: .: {} ../../apps/sparo: + dependencies: + sparo-lib: + specifier: workspace:* + version: link:../sparo-lib + devDependencies: + '@rushstack/heft': + specifier: 0.64.3 + version: 0.64.3(@types/node@20.11.16) + '@rushstack/heft-node-rig': + specifier: 2.4.5 + version: 2.4.5(@rushstack/heft@0.64.3)(@types/node@20.11.16) + '@types/heft-jest': + specifier: 1.0.6 + version: 1.0.6 + '@types/node': + specifier: 20.11.16 + version: 20.11.16 + eslint: + specifier: 8.56.0 + version: 8.56.0 + typescript: + specifier: ~5.3.3 + version: 5.3.3 + + ../../apps/sparo-lib: dependencies: '@rushstack/node-core-library': specifier: ~3.64.2 @@ -30,10 +55,10 @@ importers: version: 17.7.2 devDependencies: '@rushstack/heft': - specifier: ~0.64.3 + specifier: 0.64.3 version: 0.64.3(@types/node@20.11.16) '@rushstack/heft-node-rig': - specifier: ~2.4.5 + specifier: 2.4.5 version: 2.4.5(@rushstack/heft@0.64.3)(@types/node@20.11.16) '@types/heft-jest': specifier: 1.0.6 @@ -45,7 +70,7 @@ importers: specifier: 17.0.32 version: 17.0.32 eslint: - specifier: ~8.56.0 + specifier: 8.56.0 version: 8.56.0 typescript: specifier: ~5.3.3 @@ -545,7 +570,7 @@ packages: '@jest/console': 29.7.0 '@jest/reporters': 29.5.0 '@jest/test-result': 29.7.0 - '@jest/transform': 29.5.0 + '@jest/transform': 29.7.0 '@jest/types': 29.6.3 '@types/node': 20.11.16 ansi-escapes: 4.3.2 @@ -558,11 +583,11 @@ packages: jest-haste-map: 29.7.0 jest-message-util: 29.7.0 jest-regex-util: 29.6.3 - jest-resolve: 29.5.0 + jest-resolve: 29.7.0 jest-resolve-dependencies: 29.7.0 jest-runner: 29.7.0 jest-runtime: 29.7.0 - jest-snapshot: 29.5.0 + jest-snapshot: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 jest-watcher: 29.7.0 @@ -639,7 +664,7 @@ packages: '@bcoe/v8-coverage': 0.2.3 '@jest/console': 29.7.0 '@jest/test-result': 29.7.0 - '@jest/transform': 29.5.0 + '@jest/transform': 29.7.0 '@jest/types': 29.6.3 '@jridgewell/trace-mapping': 0.3.22 '@types/node': 20.11.16 @@ -2897,7 +2922,7 @@ packages: jest-environment-node: 29.7.0 jest-get-type: 29.6.3 jest-regex-util: 29.6.3 - jest-resolve: 29.5.0 + jest-resolve: 29.7.0 jest-runner: 29.7.0 jest-util: 29.7.0 jest-validate: 29.7.0 @@ -3168,7 +3193,7 @@ packages: '@babel/traverse': 7.23.9 '@babel/types': 7.23.9 '@jest/expect-utils': 29.7.0 - '@jest/transform': 29.5.0 + '@jest/transform': 29.7.0 '@jest/types': 29.6.3 '@types/babel__traverse': 7.20.5 '@types/prettier': 2.7.3 diff --git a/common/git-hooks/pre-commit b/common/git-hooks/pre-commit old mode 100644 new mode 100755 diff --git a/common/reviews/api/sparo-lib.api.md b/common/reviews/api/sparo-lib.api.md new file mode 100644 index 0000000..110d98d --- /dev/null +++ b/common/reviews/api/sparo-lib.api.md @@ -0,0 +1,17 @@ +## API Report File for "sparo-lib" + +> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/). + +```ts + +// @public +export class Sparo { + // (undocumented) + static launchSparoAsync(): Promise; + // (undocumented) + static launchSparoCIAsync(): Promise; +} + +// (No @packageDocumentation comment for this package) + +``` diff --git a/rush.json b/rush.json index f6f038a..40ee45a 100644 --- a/rush.json +++ b/rush.json @@ -437,6 +437,10 @@ { "packageName": "sparo", "projectFolder": "apps/sparo" + }, + { + "packageName": "sparo-lib", + "projectFolder": "apps/sparo-lib" } ] }