Skip to content

Commit

Permalink
refact: Rename command to action
Browse files Browse the repository at this point in the history
  • Loading branch information
yamadashy committed Aug 12, 2024
1 parent 9f13107 commit 3bc021f
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
export const runDefaultAction = async (directory: string, cwd: string, options: CliOptions): Promise<void> => {
const version = await getVersion();

logger.log(pc.dim(`\n📦 Repopack v${version}\n`));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> => {
export const runInitAction = async (rootDir: string): Promise<void> => {
const configPath = path.join(rootDir, 'repopack.config.json');

try {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { getVersion } from '../../core/file/packageJsonParser.js';
import { logger } from '../../shared/logger.js';

export const runVersionCommand = async (): Promise<void> => {
export const runVersionAction = async (): Promise<void> => {
const version = await getVersion();
logger.log(version);
};
12 changes: 6 additions & 6 deletions src/cli/cliRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
};
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -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(),
Expand All @@ -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(),
Expand All @@ -98,7 +98,7 @@ describe('defaultCommandRunner', () => {
style: 'xml',
};

await runDefaultCommand('.', process.cwd(), options);
await runDefaultAction('.', process.cwd(), options);

expect(configLoader.mergeConfigs).toHaveBeenCalledWith(
expect.anything(),
Expand All @@ -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');
});
});
Original file line number Diff line number Diff line change
@@ -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();
});
Expand All @@ -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',
Expand All @@ -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'));
Expand All @@ -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();

Expand All @@ -68,6 +68,6 @@ describe('initCommandRunner', () => {
});
vi.mocked(fs.writeFile).mockRejectedValue(new Error('Write error'));

await runInitCommand('/test/dir');
await runInitAction('/test/dir');
});
});
Original file line number Diff line number Diff line change
@@ -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();
});
Expand All @@ -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');
Expand Down

0 comments on commit 3bc021f

Please sign in to comment.