ccommit 4.2.0-canary.1 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/lib/index.ts DELETED
@@ -1,107 +0,0 @@
1
- const COMMANDS = {
2
- COMMIT: "commit",
3
- HOOK: "hook",
4
- LIST: "list",
5
- };
6
- const COMMIT_FORMATS = {
7
- CONVENTIONAL: "conventional",
8
- CONVENTIONAL_NO_EMOJI: "conventional-no-emoji",
9
- GITMOJI: "gitmoji",
10
- };
11
-
12
- const COMMIT_MODES = {
13
- CLIENT: "client",
14
- HOOK: "hook",
15
- };
16
-
17
- const FIND_BY = {
18
- EMOJI: "emoji",
19
- TYPE: "type",
20
- };
21
-
22
- const FLAGS = Object.freeze({
23
- BREAKING: "breaking",
24
- COMMIT: "commit",
25
- DRYRUN: "dryrun",
26
- EMOJI: "emoji",
27
- HELP: "help",
28
- HOOK: "hook",
29
- LIST: "list",
30
- SKIP: "skip",
31
- VERSION: "version",
32
- });
33
-
34
- const FORMAT = {
35
- [COMMIT_FORMATS.CONVENTIONAL]: "{type}{scope}{breaking}: {emoji}{title}",
36
- [COMMIT_FORMATS.CONVENTIONAL_NO_EMOJI]: "{type}{scope}{breaking}: {title}",
37
- [COMMIT_FORMATS.GITMOJI]: "{emoji}{breaking}{scope}{title}",
38
- };
39
-
40
- const LOGS = {
41
- MESSAGES: {
42
- COMMAND_LINE_WITHOUT_REQUIRED: "❯ Command line option requires both: --title, --type",
43
- COMMIT_FAIL: `❯ \n
44
- ❯ Oops! An error occurred. There is likely additional logging output above.\n
45
- ❯ You can run the same commit with this command:\n
46
- ❯ \t
47
- {REPLACE}
48
- `,
49
- GENERATOR_TAKING_OVER: "❯ Generator will take it from here (CTRL+C to quit)",
50
- MODE_CONFLICT: "❯ Please choose one or the other: --commit, -c | --hook, -u",
51
- REPLACE: "{REPLACE}",
52
- STAGED_FILES: "❯ There are no staged files for git. Did you mean to do a dry-run (-n)?",
53
- TYPE_INCORRECT: "❯ There is no gitmoji/type associated with: {REPLACE}",
54
- },
55
- TYPES: {
56
- ERROR: "error",
57
- INFO: "info",
58
- SUCCESS: "success",
59
- WARNING: "warning",
60
- },
61
- };
62
-
63
- const OPTIONS = Object.freeze({
64
- FORMAT: "format",
65
- MESSAGE: "message",
66
- SCOPE: "scope",
67
- TITLE: "title",
68
- TYPE: "type",
69
- });
70
-
71
- const SCOPE = {
72
- MAX: 12,
73
- MIN: 3,
74
- };
75
-
76
- const SEMVER = {
77
- MAJOR: "major",
78
- MINOR: "minor",
79
- NULL: "null",
80
- PATCH: "patch",
81
- };
82
-
83
- const TITLE = {
84
- MAX: 48,
85
- MAX_SWAG: 40,
86
- MIN: 3,
87
- MIN_SWAG: 15,
88
- };
89
-
90
- const TYPE = {
91
- MAX: 15,
92
- };
93
-
94
- export {
95
- COMMANDS,
96
- COMMIT_FORMATS,
97
- COMMIT_MODES,
98
- FIND_BY,
99
- FLAGS,
100
- FORMAT,
101
- LOGS,
102
- OPTIONS,
103
- SCOPE,
104
- SEMVER,
105
- TITLE,
106
- TYPE,
107
- };
@@ -1,43 +0,0 @@
1
- /*!
2
- * reference: https://github.com/carloscuesta/gitmoji-cli
3
- */
4
- import fs from "node:fs";
5
- import process from "node:process";
6
-
7
- import { execa } from "execa";
8
-
9
- const cancelIfRebasing = (): Promise<void> =>
10
- execa("git", ["rev-parse", "--absolute-git-dir"]).then(({ stdout: gitDirectory }) => {
11
- // see https://stackoverflow.com/questions/3921409/how-to-know-if-there-is-a-git-rebase-in-progress
12
- // to understand how a rebase is detected
13
- if (
14
- fs.existsSync(gitDirectory + "/rebase-merge") ||
15
- fs.existsSync(gitDirectory + "/rebase-apply")
16
- ) {
17
- process.exit(0);
18
- }
19
- });
20
-
21
- const COMMIT_MESSAGE_SOURCE = 4;
22
-
23
- const cancelIfAmending = (): Promise<void> =>
24
- new Promise<void>((resolve) => {
25
- /*
26
- from https://git-scm.com/docs/githooks#_prepare_commit_msg
27
- the commit message source is passed as second argument and corresponding 4 for ccommit
28
- `gitmoji --hook $1 $2`
29
- */
30
- const commitMessageSource: string = process.argv[COMMIT_MESSAGE_SOURCE];
31
- if (
32
- commitMessageSource &&
33
- (commitMessageSource.startsWith("commit") || commitMessageSource.startsWith("merge"))
34
- ) {
35
- process.exit(0);
36
- }
37
- resolve();
38
- });
39
-
40
- // I avoid Promise.all to avoid race condition in future cancel callbacks
41
- const cancelIfNeeded = (): Promise<void> => cancelIfAmending().then(cancelIfRebasing);
42
-
43
- export { COMMIT_MESSAGE_SOURCE, cancelIfAmending, cancelIfNeeded, cancelIfRebasing };
@@ -1,23 +0,0 @@
1
- import Fuse from "fuse.js";
2
-
3
- const options = {
4
- keys: [
5
- {
6
- name: "type",
7
- weight: 0.44,
8
- },
9
- {
10
- name: "description",
11
- weight: 0.56,
12
- },
13
- ],
14
- threshold: 0.4,
15
- };
16
-
17
- const filterGitmojis = (input: string, gitmojis: any) => {
18
- const fuse = new Fuse(gitmojis, options);
19
-
20
- return input ? fuse.search(input).map((gitmoji) => gitmoji.item) : gitmojis;
21
- };
22
-
23
- export { filterGitmojis };
@@ -1,8 +0,0 @@
1
- import commitTypes from "../data/types.ts";
2
-
3
- const findBy = (str, from, to): string | undefined => {
4
- const key = commitTypes.findIndex((el) => el[from] === str);
5
- return commitTypes[key]?.[to];
6
- };
7
-
8
- export { findBy };
@@ -1,80 +0,0 @@
1
- import process from "node:process";
2
-
3
- import { COMMIT_FORMATS, COMMIT_MODES, FLAGS, LOGS, OPTIONS } from "../lib/index.ts";
4
- import { generateLog, getStagedFiles } from "./index.ts";
5
-
6
- const getOptionsForCommand = (command: string, flags: any): any => {
7
- const commandsWithOptions = [FLAGS.COMMIT, FLAGS.HOOK];
8
-
9
- // @ts-ignore
10
- if (commandsWithOptions.includes(command)) {
11
- const options = {
12
- dryrun: flags[FLAGS.DRYRUN],
13
- emoji: flags[FLAGS.EMOJI],
14
- // options
15
- format:
16
- flags[OPTIONS.FORMAT] === COMMIT_FORMATS.CONVENTIONAL
17
- ? flags[FLAGS.EMOJI]
18
- ? COMMIT_FORMATS.CONVENTIONAL
19
- : COMMIT_FORMATS.CONVENTIONAL_NO_EMOJI
20
- : COMMIT_FORMATS.GITMOJI,
21
- message: flags[OPTIONS.MESSAGE],
22
- mode: command === FLAGS.HOOK ? COMMIT_MODES.HOOK : COMMIT_MODES.CLIENT,
23
- scope: flags[OPTIONS.SCOPE],
24
- skip: flags[FLAGS.SKIP],
25
- title: flags[OPTIONS.TITLE],
26
- type: flags[OPTIONS.TYPE],
27
- };
28
-
29
- return options;
30
- }
31
-
32
- return null;
33
- };
34
-
35
- // @todo(lint) complexity: 11
36
- // oxlint-disable-next-line complexity
37
- const findCommand = (cli: any, options: any): void => {
38
- const flags = cli.flags;
39
- const commandFlag = Object.keys(flags)
40
- .map((flag) => flags[flag] && flag)
41
- .find((flag) => options[flag]);
42
-
43
- const filesChanged = getStagedFiles();
44
-
45
- if (!flags[FLAGS.DRYRUN] && !filesChanged) {
46
- console.log(generateLog(LOGS.TYPES.ERROR, LOGS.MESSAGES.STAGED_FILES));
47
- process.exit(2);
48
- }
49
-
50
- if (flags[FLAGS.COMMIT] && flags[FLAGS.HOOK]) {
51
- console.log(generateLog(LOGS.TYPES.ERROR, LOGS.MESSAGES.MODE_CONFLICT));
52
- process.exit(2);
53
- }
54
-
55
- if (
56
- flags[OPTIONS.MESSAGE] ||
57
- flags[OPTIONS.SCOPE] ||
58
- flags[OPTIONS.TITLE] ||
59
- flags[OPTIONS.TYPE]
60
- ) {
61
- flags[FLAGS.SKIP] = true;
62
- }
63
-
64
- if (flags[FLAGS.SKIP]) {
65
- if (flags[OPTIONS.TITLE] && flags[OPTIONS.TYPE]) {
66
- flags[FLAGS.SKIP] = true;
67
- } else {
68
- flags[FLAGS.SKIP] = false;
69
- console.log(generateLog(LOGS.TYPES.ERROR, LOGS.MESSAGES.COMMAND_LINE_WITHOUT_REQUIRED));
70
- flags[OPTIONS.TITLE] = undefined;
71
- flags[OPTIONS.TYPE] = undefined;
72
- }
73
- }
74
-
75
- const commandOptions = getOptionsForCommand(commandFlag, flags);
76
-
77
- return options[commandFlag] ? options[commandFlag](commandOptions) : cli.showHelp();
78
- };
79
-
80
- export { findCommand };
@@ -1,51 +0,0 @@
1
- import { COMMIT_FORMATS, FORMAT, TYPE } from "../lib/index.ts";
2
-
3
- const formatCliEmoji = ({ emoji, emojiLength }) =>
4
- emojiLength === 0 ? `${emoji} ` : `${emoji} `;
5
-
6
- const formatCliType = (type) => type?.padEnd(TYPE.MAX);
7
-
8
- const formatCliTypes = (commitTypes: any) => {
9
- // console.log(`EMOJI TYPE DESCRIPTION`)
10
- // console.log(`----- ---- -----------`)
11
- return commitTypes.map(({ description, emoji, emojiLength, type }) => {
12
- console.log(
13
- `${formatCliEmoji({
14
- emoji,
15
- emojiLength,
16
- })} ${formatCliType(type)} ${description}`,
17
- );
18
- });
19
- };
20
-
21
- // oxlint-disable-next-line complexity
22
- const formatCommitSubject = (options, answers) => {
23
- const format = FORMAT[options?.format];
24
-
25
- // @note(ccommit) two spaces after emoji
26
- const emoji = answers?.gitmoji ? `${answers?.gitmoji} ` : "";
27
-
28
- let scope = answers?.scope
29
- ? `(${answers?.scope.replace(/ {2}/g, "--").replace(/ /g, "-").toLowerCase().trim()})`
30
- : "";
31
- // @note(ccommit) only add space to scope if format is: gitmoji
32
- scope = scope && options?.format === COMMIT_FORMATS.GITMOJI ? `${scope} ` : scope;
33
-
34
- /**
35
- * @todo(ccommit) breaking identification in commit subject
36
- */
37
- // const breaking = answers?.breaking
38
- // ? options?.format === COMMIT_FORMATS.GITMOJI
39
- // ? `💥 `
40
- // : '!'
41
- // : ''
42
-
43
- return format
44
- .replace(/\{emoji\}/g, emoji)
45
- .replace(/\{scope\}/g, scope)
46
- .replace(/\{breaking\}/g, "")
47
- .replace(/\{title\}/g, answers?.title)
48
- .replace(/\{type\}/g, answers?.type);
49
- };
50
-
51
- export { formatCliEmoji, formatCliType, formatCliTypes, formatCommitSubject };
@@ -1,40 +0,0 @@
1
- import colors from "ansi-colors";
2
-
3
- import { LOGS } from "../lib/index.ts";
4
-
5
- type GenerateLog = (type: string, message: string, replace?: string) => void;
6
- /**
7
- * @todo(ccommit) this is a bit much, can we reduce?
8
- */
9
- const generateLog: GenerateLog = (type, message, replace) => {
10
- let msg = replace ? message.replace(/\{REPLACE\}/g, replace) : message;
11
- msg = `\n${msg}\n`;
12
-
13
- if (type === LOGS.TYPES.ERROR) {
14
- return colors.magenta.bold(msg);
15
- }
16
- if (type === LOGS.TYPES.INFO) {
17
- return colors.blue.bold(msg);
18
- }
19
- if (type === LOGS.TYPES.WARNING) {
20
- return colors.yellow.bold(msg);
21
- }
22
- return colors.green.bold(msg);
23
- };
24
-
25
- const generateCount: GenerateLog = (type, message, replace) => {
26
- const msg = replace ? message.replace(/\{REPLACE\}/g, replace) : message;
27
-
28
- if (type === LOGS.TYPES.ERROR) {
29
- return colors.red.bold(msg);
30
- }
31
- if (type === LOGS.TYPES.INFO) {
32
- return colors.white.bold(msg);
33
- }
34
- if (type === LOGS.TYPES.WARNING) {
35
- return colors.yellow.bold(msg);
36
- }
37
- return colors.green.bold(msg);
38
- };
39
-
40
- export { generateCount, generateLog };
@@ -1,17 +0,0 @@
1
- import { LOGS, TITLE } from "../lib/index.ts";
2
- import { generateCount } from "./index.ts";
3
-
4
- const getCharsLeft = (str: string) => {
5
- const chars = str.length;
6
- const message = chars.toString();
7
- let logType = LOGS.TYPES.SUCCESS;
8
-
9
- if (chars < TITLE.MIN || chars > TITLE.MAX) {
10
- logType = LOGS.TYPES.ERROR;
11
- } else if (chars < TITLE.MIN_SWAG || chars > TITLE.MAX_SWAG) {
12
- logType = LOGS.TYPES.WARNING;
13
- }
14
- return generateCount(logType, LOGS.MESSAGES.REPLACE, message);
15
- };
16
-
17
- export { getCharsLeft };
@@ -1,12 +0,0 @@
1
- import { execSync } from "node:child_process";
2
-
3
- const getGitRootDir = () => {
4
- const devNull = process.platform === "win32" ? " nul" : "/dev/null";
5
- const dir = execSync("git rev-parse --show-toplevel 2>" + devNull)
6
- .toString()
7
- .trim();
8
-
9
- return dir;
10
- };
11
-
12
- export { getGitRootDir };
@@ -1,24 +0,0 @@
1
- import { execSync } from "node:child_process";
2
-
3
- const getIssueTracker = () => {
4
- let branch: any,
5
- init = "";
6
-
7
- // branch = 'ABC-123'
8
- branch = execSync("git rev-parse --abbrev-ref HEAD");
9
- branch = branch.toString().trim().split("/");
10
- const branchType = branch[0];
11
- const branchName = !branch[1] ? branchType : branch[1];
12
-
13
- const it = branchName.split("-");
14
- const itProject = it[0];
15
- const itNumber = !it[1] ? itProject : it[1];
16
- const itTicket = `${itProject}-${itNumber}`;
17
-
18
- if (!isNaN(parseFloat(itNumber)) && isFinite(parseFloat(itNumber))) {
19
- init = itTicket;
20
- }
21
- return init;
22
- };
23
-
24
- export { getIssueTracker };
@@ -1,9 +0,0 @@
1
- import { execSync } from "node:child_process";
2
-
3
- const getStagedFiles = () => {
4
- const stagedFiles = execSync("git diff --name-only --staged").toString().trim();
5
-
6
- return !!stagedFiles;
7
- };
8
-
9
- export { getStagedFiles };
@@ -1,17 +0,0 @@
1
- export {
2
- COMMIT_MESSAGE_SOURCE,
3
- cancelIfAmending,
4
- cancelIfNeeded,
5
- cancelIfRebasing,
6
- } from "./cancel-if.ts";
7
- export { filterGitmojis } from "./filter.ts";
8
- export { findBy } from "./find-by.ts";
9
- export { findCommand } from "./find-command.ts";
10
- export { formatCliEmoji, formatCliType, formatCliTypes, formatCommitSubject } from "./format.ts";
11
- export { generateCount, generateLog } from "./generate-log.ts";
12
- export { getCharsLeft } from "./get-chars-left.ts";
13
- export { getGitRootDir } from "./get-git-root-dir.ts";
14
- export { getIssueTracker } from "./get-issue-tracker.ts";
15
- export { getStagedFiles } from "./get-staged-files.ts";
16
- export { printDryRun } from "./print-dry-run.ts";
17
- export { registerHookInterruptionHandler } from "./register-hook-interruption-handler.ts";
@@ -1,7 +0,0 @@
1
- import colors from "ansi-colors";
2
-
3
- const printDryRun = (v) => {
4
- console.log(colors.magenta.bold(`❯ dry-run mode: ${v}\n`));
5
- };
6
-
7
- export { printDryRun };
@@ -1,16 +0,0 @@
1
- /*!
2
- * reference: https://github.com/carloscuesta/gitmoji-cli
3
- */
4
- import process from "node:process";
5
-
6
- import colors from "ansi-colors";
7
-
8
- const registerHookInterruptionHandler = () => {
9
- // Allow to interrupt the hook without cancelling the commit
10
- process.on("SIGINT", () => {
11
- console.log(colors.magenta.bold("❯ [ccommit] interrupted"));
12
- process.exit(0);
13
- });
14
- };
15
-
16
- export { registerHookInterruptionHandler };
package/tsconfig.json DELETED
@@ -1,9 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "outDir": "./dist",
4
- "rootDir": "./src"
5
- },
6
- "exclude": ["node_modules", "release.config.js"],
7
- "extends": "@jeromefitz/tsconfig/src/node24.json",
8
- "include": ["src"]
9
- }
package/tsdown.config.ts DELETED
@@ -1,44 +0,0 @@
1
- import { readFileSync, writeFileSync } from "node:fs";
2
-
3
- import type { UserConfig } from "tsdown";
4
- import { defineConfig } from "tsdown";
5
-
6
- import { config as _config } from "../../tsdown.config.ts";
7
-
8
- const GITMOJI_CLI_LICENSE = `MIT License
9
-
10
- Copyright (c) 2016-2022 Carlos Cuesta
11
-
12
- Permission is hereby granted, free of charge, to any person obtaining a copy
13
- of this software and associated documentation files (the "Software"), to deal
14
- in the Software without restriction, including without limitation the rights
15
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
16
- copies of the Software, and to permit persons to whom the Software is
17
- furnished to do so, subject to the following conditions:
18
-
19
- The above copyright notice and this permission notice shall be included in all
20
- copies or substantial portions of the Software.
21
-
22
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
- SOFTWARE.
29
- `;
30
-
31
- const entry = ["src/index.ts"];
32
- const config: UserConfig = {
33
- ..._config,
34
- entry,
35
- onSuccess: () => {
36
- const license = readFileSync("../../LICENSE", "utf8");
37
- writeFileSync("./dist/index.mjs.LICENSE.txt", `${license}\n${GITMOJI_CLI_LICENSE}`);
38
- },
39
- treeshake: true,
40
- };
41
-
42
- export default defineConfig({
43
- ...config,
44
- });
File without changes
File without changes
File without changes