mirror of
https://github.com/di-sukharev/opencommit.git
synced 2026-01-12 15:18:24 -05:00
* fix(commit.ts): improve user confirmation handling by exiting on cancel actions to prevent unintended behavior refactor(commit.ts): streamline conditional checks for user confirmations to enhance code readability and maintainability * refactor(commit.ts): rename spinner variables for clarity and consistency in commit message generation process fix(commit.ts): ensure proper stopping of spinners in case of errors during commit message generation and committing process * refactor(config.ts): extract default configuration to a constant for better maintainability and readability refactor(config.ts): improve initGlobalConfig function to accept a configPath parameter for flexibility feat(config.ts): enhance getConfig function to support separate paths for global and environment configurations test(config.test.ts): update tests to reflect changes in config handling and ensure proper functionality style(utils.ts): clean up code formatting for consistency and readability style(tsconfig.json): adjust formatting in tsconfig.json for better clarity and maintainability * fix(utils.ts): add existsSync check before removing temp directory to prevent errors if directory does not exist (#401) --------- Co-authored-by: Takanori Matsumoto <matscube@gmail.com>
33 lines
789 B
TypeScript
33 lines
789 B
TypeScript
import { existsSync, mkdtemp, rm, writeFile } from 'fs';
|
|
import { tmpdir } from 'os';
|
|
import path from 'path';
|
|
import { promisify } from 'util';
|
|
const fsMakeTempDir = promisify(mkdtemp);
|
|
const fsRemove = promisify(rm);
|
|
const fsWriteFile = promisify(writeFile);
|
|
|
|
/**
|
|
* Prepare tmp file for the test
|
|
*/
|
|
export async function prepareFile(
|
|
fileName: string,
|
|
content: string
|
|
): Promise<{
|
|
filePath: string;
|
|
cleanup: () => Promise<void>;
|
|
}> {
|
|
const tempDir = await fsMakeTempDir(path.join(tmpdir(), 'opencommit-test-'));
|
|
const filePath = path.resolve(tempDir, fileName);
|
|
await fsWriteFile(filePath, content);
|
|
const cleanup = async () => {
|
|
if (existsSync(tempDir)) {
|
|
await fsRemove(tempDir, { recursive: true });
|
|
}
|
|
};
|
|
|
|
return {
|
|
filePath,
|
|
cleanup
|
|
};
|
|
}
|