From 3bc021f8139258dd362a7f2867e14d1bc9560312 Mon Sep 17 00:00:00 2001 From: Kazuki Yamada Date: Mon, 12 Aug 2024 18:34:47 +0900 Subject: [PATCH] refact: Rename command to action --- .../defaultActionRunner.ts} | 6 +++--- .../initActionRunner.ts} | 2 +- .../versionActionRunner.ts} | 2 +- src/cli/cliRunner.ts | 12 ++++++------ .../defaultActionRunner.test.ts} | 14 +++++++------- .../initActionRunner.test.ts} | 12 ++++++------ .../versionActionRunner.test.ts} | 6 +++--- 7 files changed, 27 insertions(+), 27 deletions(-) rename src/cli/{commands/defaultCommandRunner.ts => actions/defaultActionRunner.ts} (93%) rename src/cli/{commands/initCommandRunner.ts => actions/initActionRunner.ts} (97%) rename src/cli/{commands/versionCommandRunner.ts => actions/versionActionRunner.ts} (74%) rename tests/cli/{commands/defaultCommandRunner.test.ts => actions/defaultActionRunner.test.ts} (87%) rename tests/cli/{commands/initCommandRunner.test.ts => actions/initActionRunner.test.ts} (88%) rename tests/cli/{commands/versionCommandRunner.test.ts => actions/versionActionRunner.test.ts} (81%) diff --git a/src/cli/commands/defaultCommandRunner.ts b/src/cli/actions/defaultActionRunner.ts similarity index 93% rename from src/cli/commands/defaultCommandRunner.ts rename to src/cli/actions/defaultActionRunner.ts index 49282618..7f64e6ee 100644 --- a/src/cli/commands/defaultCommandRunner.ts +++ b/src/cli/actions/defaultActionRunner.ts @@ -11,10 +11,10 @@ import { loadFileConfig, mergeConfigs } from '../../config/configLoader.js'; import { logger } from '../../shared/logger.js'; import { CliOptions } from '../cliRunner.js'; import { getVersion } from '../../core/file/packageJsonParser.js'; -import Spinner from './../cliSpinner.js'; -import { printSummary, printTopFiles, printCompletion, printSecurityCheck } from './../cliPrinter.js'; +import Spinner from '../cliSpinner.js'; +import { printSummary, printTopFiles, printCompletion, printSecurityCheck } from '../cliPrinter.js'; -export const runDefaultCommand = async (directory: string, cwd: string, options: CliOptions): Promise => { +export const runDefaultAction = async (directory: string, cwd: string, options: CliOptions): Promise => { const version = await getVersion(); logger.log(pc.dim(`\n📦 Repopack v${version}\n`)); diff --git a/src/cli/commands/initCommandRunner.ts b/src/cli/actions/initActionRunner.ts similarity index 97% rename from src/cli/commands/initCommandRunner.ts rename to src/cli/actions/initActionRunner.ts index d9a2effc..fbb74807 100644 --- a/src/cli/commands/initCommandRunner.ts +++ b/src/cli/actions/initActionRunner.ts @@ -6,7 +6,7 @@ import { logger } from '../../shared/logger.js'; import { RepopackConfigFile, RepopackOutputStyle } from '../../config/configTypes.js'; import { defaultConfig } from '../../config/defaultConfig.js'; -export const runInitCommand = async (rootDir: string): Promise => { +export const runInitAction = async (rootDir: string): Promise => { const configPath = path.join(rootDir, 'repopack.config.json'); try { diff --git a/src/cli/commands/versionCommandRunner.ts b/src/cli/actions/versionActionRunner.ts similarity index 74% rename from src/cli/commands/versionCommandRunner.ts rename to src/cli/actions/versionActionRunner.ts index 44b3be19..2311875e 100644 --- a/src/cli/commands/versionCommandRunner.ts +++ b/src/cli/actions/versionActionRunner.ts @@ -1,7 +1,7 @@ import { getVersion } from '../../core/file/packageJsonParser.js'; import { logger } from '../../shared/logger.js'; -export const runVersionCommand = async (): Promise => { +export const runVersionAction = async (): Promise => { const version = await getVersion(); logger.log(version); }; diff --git a/src/cli/cliRunner.ts b/src/cli/cliRunner.ts index 8f30a018..4debcf5f 100644 --- a/src/cli/cliRunner.ts +++ b/src/cli/cliRunner.ts @@ -3,9 +3,9 @@ import { program, OptionValues } from 'commander'; import { RepopackOutputStyle } from '../config/configTypes.js'; import { getVersion } from '../core/file/packageJsonParser.js'; import { handleError } from '../shared/errorHandler.js'; -import { runInitCommand } from './commands/initCommandRunner.js'; -import { runVersionCommand } from './commands/versionCommandRunner.js'; -import { runDefaultCommand } from './commands/defaultCommandRunner.js'; +import { runInitAction } from './actions/initActionRunner.js'; +import { runVersionAction } from './actions/versionActionRunner.js'; +import { runDefaultAction } from './actions/defaultActionRunner.js'; export interface CliOptions extends OptionValues { version?: boolean; @@ -48,14 +48,14 @@ export async function run() { const executeAction = async (directory: string, cwd: string, options: CliOptions) => { if (options.version) { - await runVersionCommand(); + await runVersionAction(); return; } if (options.init) { - await runInitCommand(cwd); + await runInitAction(cwd); return; } - await runDefaultCommand(directory, cwd, options); + await runDefaultAction(directory, cwd, options); }; diff --git a/tests/cli/commands/defaultCommandRunner.test.ts b/tests/cli/actions/defaultActionRunner.test.ts similarity index 87% rename from tests/cli/commands/defaultCommandRunner.test.ts rename to tests/cli/actions/defaultActionRunner.test.ts index 98235da1..1d4eb8a9 100644 --- a/tests/cli/commands/defaultCommandRunner.test.ts +++ b/tests/cli/actions/defaultActionRunner.test.ts @@ -1,5 +1,5 @@ import { expect, describe, it, vi, beforeEach, afterEach } from 'vitest'; -import { runDefaultCommand } from '../../../src/cli/commands/defaultCommandRunner.js'; +import { runDefaultAction } from '../../../src/cli/actions/defaultActionRunner.js'; import * as packager from '../../../src/core/packager.js'; import * as configLoader from '../../../src/config/configLoader.js'; import * as packageJsonParser from '../../../src/core/file/packageJsonParser.js'; @@ -11,7 +11,7 @@ vi.mock('../../../src/config/configLoader'); vi.mock('../../../src/core/file/packageJsonParser'); vi.mock('../../../src/shared/logger'); -describe('defaultCommandRunner', () => { +describe('defaultActionRunner', () => { beforeEach(() => { vi.resetAllMocks(); vi.mocked(packageJsonParser.getVersion).mockResolvedValue('1.0.0'); @@ -52,7 +52,7 @@ describe('defaultCommandRunner', () => { verbose: true, }; - await runDefaultCommand('.', process.cwd(), options); + await runDefaultAction('.', process.cwd(), options); expect(packageJsonParser.getVersion).toHaveBeenCalled(); expect(logger.logger.setVerbose).toHaveBeenCalledWith(true); @@ -66,7 +66,7 @@ describe('defaultCommandRunner', () => { include: '*.js,*.ts', }; - await runDefaultCommand('.', process.cwd(), options); + await runDefaultAction('.', process.cwd(), options); expect(configLoader.mergeConfigs).toHaveBeenCalledWith( expect.anything(), @@ -81,7 +81,7 @@ describe('defaultCommandRunner', () => { ignore: 'node_modules,*.log', }; - await runDefaultCommand('.', process.cwd(), options); + await runDefaultAction('.', process.cwd(), options); expect(configLoader.mergeConfigs).toHaveBeenCalledWith( expect.anything(), @@ -98,7 +98,7 @@ describe('defaultCommandRunner', () => { style: 'xml', }; - await runDefaultCommand('.', process.cwd(), options); + await runDefaultAction('.', process.cwd(), options); expect(configLoader.mergeConfigs).toHaveBeenCalledWith( expect.anything(), @@ -115,6 +115,6 @@ describe('defaultCommandRunner', () => { const options: CliOptions = {}; - await expect(runDefaultCommand('.', process.cwd(), options)).rejects.toThrow('Test error'); + await expect(runDefaultAction('.', process.cwd(), options)).rejects.toThrow('Test error'); }); }); diff --git a/tests/cli/commands/initCommandRunner.test.ts b/tests/cli/actions/initActionRunner.test.ts similarity index 88% rename from tests/cli/commands/initCommandRunner.test.ts rename to tests/cli/actions/initActionRunner.test.ts index 0dc4e4e3..5fb06847 100644 --- a/tests/cli/commands/initCommandRunner.test.ts +++ b/tests/cli/actions/initActionRunner.test.ts @@ -1,13 +1,13 @@ import * as fs from 'node:fs/promises'; import { expect, describe, it, vi, beforeEach, afterEach } from 'vitest'; import * as prompts from '@clack/prompts'; -import { runInitCommand } from '../../../src/cli/commands/initCommandRunner.js'; +import { runInitAction } from '../../../src/cli/actions/initActionRunner.js'; import { logger } from '../../../src/shared/logger.js'; vi.mock('node:fs/promises'); vi.mock('@clack/prompts'); -describe('initCommandRunner', () => { +describe('initActionRunner', () => { beforeEach(() => { vi.resetAllMocks(); }); @@ -23,7 +23,7 @@ describe('initCommandRunner', () => { outputStyle: 'xml', }); - await runInitCommand('/test/dir'); + await runInitAction('/test/dir'); expect(fs.writeFile).toHaveBeenCalledWith( '/test/dir/repopack.config.json', @@ -39,7 +39,7 @@ describe('initCommandRunner', () => { vi.mocked(fs.access).mockResolvedValue(undefined); const loggerSpy = vi.spyOn(logger, 'warn').mockImplementation(vi.fn()); - await runInitCommand('/test/dir'); + await runInitAction('/test/dir'); expect(fs.writeFile).not.toHaveBeenCalled(); expect(loggerSpy).toHaveBeenCalledWith(expect.stringContaining('already exists')); @@ -53,7 +53,7 @@ describe('initCommandRunner', () => { const loggerSpy = vi.spyOn(logger, 'error').mockImplementation(vi.fn()); - await runInitCommand('/test/dir'); + await runInitAction('/test/dir'); expect(fs.writeFile).not.toHaveBeenCalled(); @@ -68,6 +68,6 @@ describe('initCommandRunner', () => { }); vi.mocked(fs.writeFile).mockRejectedValue(new Error('Write error')); - await runInitCommand('/test/dir'); + await runInitAction('/test/dir'); }); }); diff --git a/tests/cli/commands/versionCommandRunner.test.ts b/tests/cli/actions/versionActionRunner.test.ts similarity index 81% rename from tests/cli/commands/versionCommandRunner.test.ts rename to tests/cli/actions/versionActionRunner.test.ts index a748e35f..615a0cb8 100644 --- a/tests/cli/commands/versionCommandRunner.test.ts +++ b/tests/cli/actions/versionActionRunner.test.ts @@ -1,11 +1,11 @@ import { expect, describe, it, vi, beforeEach, afterEach } from 'vitest'; -import { runVersionCommand } from '../../../src/cli/commands/versionCommandRunner.js'; +import { runVersionAction } from '../../../src/cli/actions/versionActionRunner.js'; import * as packageJsonParser from '../../../src/core/file/packageJsonParser.js'; import { logger } from '../../../src/shared/logger.js'; vi.mock('../../../src/core/file/packageJsonParser'); -describe('versionCommandRunner', () => { +describe('versionActionRunner', () => { beforeEach(() => { vi.resetAllMocks(); }); @@ -18,7 +18,7 @@ describe('versionCommandRunner', () => { vi.mocked(packageJsonParser.getVersion).mockResolvedValue('1.2.3'); const loggerSpy = vi.spyOn(logger, 'log').mockImplementation(vi.fn()); - await runVersionCommand(); + await runVersionAction(); expect(packageJsonParser.getVersion).toHaveBeenCalled(); expect(loggerSpy).toHaveBeenCalledWith('1.2.3');