Compare commits

..

5 Commits

Author SHA1 Message Date
di-sukharev
3705a66ada 0.0.14 2023-03-06 21:33:06 +08:00
di-sukharev
bdb8da49b7 * 🚀 chore(cli.ts): change file mode from 100644 to 100755
This commit changes the file mode of cli.ts from 100644 to 100755. This change allows the file to be executable.
2023-03-06 21:33:00 +08:00
di-sukharev
6e896ec428 * 🐛 fix(githook.ts): fix HOOK_PATH import path
The import path for HOOK_PATH was incorrect, causing the file to not be found. The path has been updated to correctly reference the cli.cjs file.
2023-03-06 21:07:03 +08:00
di-sukharev
9ce961ccc0 0.0.13 2023-03-06 21:03:28 +08:00
di-sukharev
1a2f6416cc * 🐛 fix(githook.ts): fix file path in URL constructor
The file path in the URL constructor was incorrect, causing the file to not be found. The file path has been corrected to point to the correct location.
2023-03-06 21:03:25 +08:00
4 changed files with 60 additions and 48 deletions

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "open-commit",
"version": "0.0.12",
"version": "0.0.14",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "open-commit",
"version": "0.0.12",
"version": "0.0.14",
"license": "ISC",
"dependencies": {
"@clack/prompts": "^0.6.1",

View File

@@ -1,6 +1,6 @@
{
"name": "opencommit",
"version": "0.0.12",
"version": "0.0.14",
"description": "AI generates conventional commits with mind-blowing accuracy.",
"keywords": [
"git",

0
src/cli.ts Normal file → Executable file
View File

View File

@@ -19,59 +19,71 @@ export const hookCommand = command(
name: 'hook',
parameters: ['<set/unset>']
},
async (argv) => {
const HOOK_PATH = fileURLToPath(new URL('./out/cli.cjs', import.meta.url));
(argv) => {
const HOOK_PATH = fileURLToPath(new URL('cli.cjs', import.meta.url));
try {
await assertGitRepo();
(async () => {
try {
await assertGitRepo();
const { setUnset: mode } = argv._;
const { setUnset: mode } = argv._;
if (mode === 'set') {
intro(`setting opencommit as '${HOOK_NAME}' hook`);
if (isHookExists) {
const realPath = await fs.realpath(SYMLINK_URL);
if (mode === 'set') {
intro(`setting opencommit as '${HOOK_NAME}' hook`);
if (realPath === HOOK_PATH)
return outro(`opencommit is already set as '${HOOK_NAME}'`);
if (isHookExists) {
let realPath;
try {
realPath = await fs.realpath(SYMLINK_URL);
console.log(123, { realPath });
} catch (error) {
console.log(321, { realPath });
outro(error as string);
realPath = null;
}
throw new Error(
`Different ${HOOK_NAME} is already set. Remove it before setting opencommit as '${HOOK_NAME}' hook.`
);
if (realPath === HOOK_PATH)
return outro(`opencommit is already set as '${HOOK_NAME}'`);
throw new Error(
`Different ${HOOK_NAME} is already set. Remove it before setting opencommit as '${HOOK_NAME}' hook.`
);
}
await fs.mkdir(path.dirname(SYMLINK_URL), { recursive: true });
await fs.symlink(HOOK_PATH, SYMLINK_URL, 'file');
await fs.chmod(SYMLINK_URL, 0o755);
return outro(`${chalk.green('✔')} Hook set`);
}
await fs.mkdir(path.dirname(SYMLINK_URL), { recursive: true });
await fs.symlink(HOOK_PATH, SYMLINK_URL, 'file');
await fs.chmod(SYMLINK_URL, 0o755);
if (mode === 'unset') {
intro(`unsetting opencommit as '${HOOK_NAME}' hook`);
return outro(`${chalk.green('✔')} Hook set`);
if (!isHookExists) {
return outro(
`opencommit wasn't previously set as '${HOOK_NAME}' hook, nothing to remove`
);
}
const realpath = await fs.realpath(SYMLINK_URL);
if (realpath !== HOOK_PATH) {
return outro(
`opencommit wasn't previously set as '${HOOK_NAME}' hook, but different hook was, if you want to remove it — do it manually`
);
}
await fs.rm(SYMLINK_URL);
return outro(`${chalk.green('✔')} Hook is removed`);
}
throw new Error(
`unsupported mode: ${mode}. Supported modes are: 'set' or 'unset'`
);
} catch (error) {
outro(`${chalk.red('✖')} ${error}`);
process.exit(1);
}
if (mode === 'unset') {
intro(`unsetting opencommit as '${HOOK_NAME}' hook`);
if (!isHookExists) {
return outro(
`opencommit wasn't previously set as '${HOOK_NAME}' hook, nothing to remove`
);
}
const realpath = await fs.realpath(SYMLINK_URL);
if (realpath !== HOOK_PATH) {
return outro(
`opencommit wasn't previously set as '${HOOK_NAME}' hook, but different hook was, if you want to remove it — do it manually`
);
}
await fs.rm(SYMLINK_URL);
return outro(`${chalk.green('✔')} Hook is removed`);
}
throw new Error(
`unsupported mode: ${mode}. Supported modes are: 'set' or 'unset'`
);
} catch (error) {
outro(`${chalk.red('✖')} ${error}`);
process.exit(1);
}
})();
}
);