* 🚀 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.
This commit is contained in:
di-sukharev
2023-03-06 21:33:00 +08:00
parent 6e896ec428
commit bdb8da49b7
2 changed files with 56 additions and 44 deletions

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) => {
(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);
}
})();
}
);