fork-version 1.7.0 → 1.7.6
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/CHANGELOG.md +48 -0
- package/README.md +42 -9
- package/dist/{chunk-D7324DNL.js → chunk-4M7BP5DG.js} +87 -84
- package/dist/chunk-4M7BP5DG.js.map +1 -0
- package/dist/{chunk-U3KD6MC3.cjs → chunk-JAYAB33O.cjs} +87 -84
- package/dist/chunk-JAYAB33O.cjs.map +1 -0
- package/dist/cli.cjs +126 -55
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +115 -48
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +11 -11
- package/dist/index.d.cts +31 -13
- package/dist/index.d.ts +31 -13
- package/dist/index.js +1 -1
- package/package.json +13 -13
- package/dist/chunk-D7324DNL.js.map +0 -1
- package/dist/chunk-U3KD6MC3.cjs.map +0 -1
package/dist/cli.js
CHANGED
|
@@ -1,67 +1,122 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { getUserConfig, Logger, FileManager, getCurrentVersion, getNextVersion, updateChangelog, commitChanges, tagChanges } from './chunk-
|
|
2
|
+
import { getUserConfig, Logger, FileManager, getCurrentVersion, getNextVersion, updateChangelog, commitChanges, tagChanges } from './chunk-4M7BP5DG.js';
|
|
3
3
|
import { writeFileSync } from 'node:fs';
|
|
4
4
|
import { join } from 'node:path';
|
|
5
|
+
import { ZodError } from 'zod';
|
|
5
6
|
import { execFile } from 'node:child_process';
|
|
7
|
+
import semver from 'semver';
|
|
6
8
|
|
|
7
9
|
var Git = class {
|
|
8
|
-
constructor(config
|
|
10
|
+
constructor(config) {
|
|
9
11
|
this.config = config;
|
|
10
|
-
this.logger = logger;
|
|
11
12
|
this.add = this.add.bind(this);
|
|
12
13
|
this.commit = this.commit.bind(this);
|
|
13
14
|
this.tag = this.tag.bind(this);
|
|
14
|
-
this.
|
|
15
|
+
this.isIgnored = this.isIgnored.bind(this);
|
|
16
|
+
this.getCurrentBranchName = this.getCurrentBranchName.bind(this);
|
|
17
|
+
this.getTags = this.getTags.bind(this);
|
|
18
|
+
this.getLatestTag = this.getLatestTag.bind(this);
|
|
15
19
|
}
|
|
16
|
-
|
|
20
|
+
async execGit(command, args) {
|
|
21
|
+
return new Promise((onResolve, onReject) => {
|
|
22
|
+
execFile(
|
|
23
|
+
"git",
|
|
24
|
+
[command, ...args],
|
|
25
|
+
{
|
|
26
|
+
cwd: this.config.path,
|
|
27
|
+
maxBuffer: Infinity
|
|
28
|
+
},
|
|
29
|
+
(error, stdout, stderr) => {
|
|
30
|
+
if (error) {
|
|
31
|
+
onReject(error);
|
|
32
|
+
} else {
|
|
33
|
+
onResolve(stdout ? stdout : stderr);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
async add(...args) {
|
|
17
40
|
if (this.config.dryRun) {
|
|
18
|
-
return
|
|
41
|
+
return "";
|
|
19
42
|
}
|
|
20
43
|
return this.execGit("add", args.filter(Boolean));
|
|
21
44
|
}
|
|
22
|
-
commit(...args) {
|
|
45
|
+
async commit(...args) {
|
|
23
46
|
if (this.config.dryRun) {
|
|
24
|
-
return
|
|
47
|
+
return "";
|
|
25
48
|
}
|
|
26
49
|
return this.execGit("commit", args.filter(Boolean));
|
|
27
50
|
}
|
|
28
|
-
tag(...args) {
|
|
51
|
+
async tag(...args) {
|
|
29
52
|
if (this.config.dryRun) {
|
|
30
|
-
return
|
|
53
|
+
return "";
|
|
31
54
|
}
|
|
32
55
|
return this.execGit("tag", args.filter(Boolean));
|
|
33
56
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
42
|
-
});
|
|
57
|
+
async isIgnored(file) {
|
|
58
|
+
try {
|
|
59
|
+
await this.execGit("check-ignore", ["--no-index", file]);
|
|
60
|
+
return true;
|
|
61
|
+
} catch (_error) {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
43
64
|
}
|
|
44
|
-
async
|
|
65
|
+
async getCurrentBranchName() {
|
|
45
66
|
return (await this.execGit("rev-parse", ["--abbrev-ref", "HEAD"])).trim();
|
|
46
67
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
/**
|
|
69
|
+
* `getTags` returns valid semver version tags in order of the commit history.
|
|
70
|
+
*
|
|
71
|
+
* Using `git log` to get the commit history, we then parse the tags from the
|
|
72
|
+
* commit details which is expected to be in the following format:
|
|
73
|
+
* @example
|
|
74
|
+
* ```txt
|
|
75
|
+
* commit 3841b1d05750d42197fe958e3d8e06df378a842d (HEAD -> main, tag: 1.0.2)
|
|
76
|
+
* Author: Username <username@example.com>
|
|
77
|
+
* Date: Sat Nov 9 15:00:00 2024 +0000
|
|
78
|
+
*
|
|
79
|
+
* chore(release): 1.2.3
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* - [Functionality extracted from the conventional-changelog - git-semver-tags project](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/index.js)
|
|
83
|
+
* - [conventional-changelog git-semver-tags MIT Licence](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/LICENSE.md)
|
|
84
|
+
*/
|
|
85
|
+
async getTags(tagPrefix) {
|
|
86
|
+
const logOutput = await this.execGit("log", ["--decorate", "--no-color", "--date-order"]);
|
|
87
|
+
const TAG_REGEX = /tag:\s*(.+?)[,)]/gi;
|
|
88
|
+
const tags = [];
|
|
89
|
+
let match = null;
|
|
90
|
+
let tag;
|
|
91
|
+
let tagWithoutPrefix;
|
|
92
|
+
for (const logOutputLine of logOutput.split("\n")) {
|
|
93
|
+
while (match = TAG_REGEX.exec(logOutputLine)) {
|
|
94
|
+
tag = match[1];
|
|
95
|
+
if (tagPrefix) {
|
|
96
|
+
if (tag.startsWith(tagPrefix)) {
|
|
97
|
+
tagWithoutPrefix = tag.replace(tagPrefix, "");
|
|
98
|
+
if (semver.valid(tagWithoutPrefix)) {
|
|
99
|
+
tags.push(tag);
|
|
100
|
+
}
|
|
60
101
|
}
|
|
61
|
-
|
|
102
|
+
} else if (semver.valid(tag)) {
|
|
103
|
+
tags.push(tag);
|
|
62
104
|
}
|
|
63
|
-
|
|
64
|
-
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return tags;
|
|
108
|
+
}
|
|
109
|
+
async getLatestTag(tagPrefix) {
|
|
110
|
+
const tags = await this.getTags(tagPrefix);
|
|
111
|
+
if (!tags.length) return "";
|
|
112
|
+
const cleanedTags = [];
|
|
113
|
+
for (const tag of tags) {
|
|
114
|
+
const cleanedTag = semver.clean(tag.replace(new RegExp(`^${tagPrefix}`), ""));
|
|
115
|
+
if (cleanedTag) {
|
|
116
|
+
cleanedTags.push(cleanedTag);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return cleanedTags.sort(semver.rcompare)[0];
|
|
65
120
|
}
|
|
66
121
|
};
|
|
67
122
|
|
|
@@ -71,18 +126,12 @@ async function runFork() {
|
|
|
71
126
|
const config = await getUserConfig();
|
|
72
127
|
const logger = new Logger(config);
|
|
73
128
|
const fileManager = new FileManager(config, logger);
|
|
74
|
-
const git = new Git(config
|
|
129
|
+
const git = new Git(config);
|
|
75
130
|
logger.log(`Running fork-version - ${(/* @__PURE__ */ new Date()).toUTCString()}`);
|
|
76
|
-
logger.
|
|
77
|
-
const
|
|
78
|
-
for (const file of config.files) {
|
|
79
|
-
if (!await git.shouldIgnore(file)) {
|
|
80
|
-
filesToUpdate.push(file);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
const current = await getCurrentVersion(config, logger, fileManager, filesToUpdate);
|
|
131
|
+
logger.warn(config.dryRun ? "[Dry Run] No changes will be written to disk.\n" : "");
|
|
132
|
+
const current = await getCurrentVersion(config, logger, git, fileManager, config.files);
|
|
84
133
|
const next = await getNextVersion(config, logger, current.version);
|
|
85
|
-
logger.log("Updating
|
|
134
|
+
logger.log("Updating files: ");
|
|
86
135
|
for (const outFile of current.files) {
|
|
87
136
|
logger.log(` - ${outFile.path}`);
|
|
88
137
|
fileManager.write(outFile, next.version);
|
|
@@ -90,7 +139,7 @@ async function runFork() {
|
|
|
90
139
|
await updateChangelog(config, logger, next.version);
|
|
91
140
|
await commitChanges(config, logger, git, current.files, next.version);
|
|
92
141
|
await tagChanges(config, logger, git, next.version);
|
|
93
|
-
const branchName = await git.
|
|
142
|
+
const branchName = await git.getCurrentBranchName();
|
|
94
143
|
logger.log(
|
|
95
144
|
`
|
|
96
145
|
Run \`git push --follow-tags origin ${branchName}\` to push the changes and the tag.`
|
|
@@ -115,6 +164,24 @@ Run \`git push --follow-tags origin ${branchName}\` to push the changes and the
|
|
|
115
164
|
}
|
|
116
165
|
return result;
|
|
117
166
|
}
|
|
118
|
-
runFork()
|
|
167
|
+
runFork().catch((error) => {
|
|
168
|
+
if (error instanceof Error) {
|
|
169
|
+
if (error.cause instanceof ZodError) {
|
|
170
|
+
console.error(error.message);
|
|
171
|
+
for (const err of error.cause.errors) {
|
|
172
|
+
console.log(`${err.path} => ${err.message}`);
|
|
173
|
+
}
|
|
174
|
+
process.exit(3);
|
|
175
|
+
}
|
|
176
|
+
if (error.stack) {
|
|
177
|
+
console.error(error.stack);
|
|
178
|
+
} else {
|
|
179
|
+
console.error(error.message);
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
console.error(error);
|
|
183
|
+
}
|
|
184
|
+
process.exit(1);
|
|
185
|
+
});
|
|
119
186
|
//# sourceMappingURL=cli.js.map
|
|
120
187
|
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
CHAN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,EAAA,MAAM,CACjC,0BAAA,CAAA,GAAA,2CAAA;AAAA,KACJ,CAAA;AAAA,GACD;AAEA,EAAA,MAAA,CAAO,MAAM,CAAgB,aAAA,EAAA,IAAA,CAAK,GAAI,EAAA,GAAI,SAAS,CAAK,GAAA,CAAA,CAAA,CAAA;AAExD,EAAA,MAAM,MAAS,GAAA;AAAA,IACd,MAAA;AAAA,IACA,OAAA;AAAA,IACA,IAAA;AAAA,GACD,CAAA;AAEA,EAAA,IAAI,CAAC,MAAA,CAAO,MAAU,IAAA,MAAA,CAAO,KAAO,EAAA;AACnC,IAAA,aAAA;AAAA,MACC,KAAK,MAAO,CAAA,IAAA,EAAM,gBAAgB,IAAK,CAAA,GAAA,EAAK,CAAiB,eAAA,CAAA,CAAA;AAAA,MAC7D,IAAK,CAAA,SAAA,CAAU,MAAQ,EAAA,IAAA,EAAM,CAAC,CAAA;AAAA,KAC/B,CAAA;AAAA,GACD;AAEA,EAAO,OAAA,MAAA,CAAA;AACR,CAAA;AAEA,OAAQ,EAAA","file":"cli.js","sourcesContent":["import { execFile } from \"node:child_process\";\nimport type { ForkConfig } from \"../config/types\";\nimport type { Logger } from \"./logger\";\n\nexport class Git {\n\tconstructor(\n\t\tprivate config: ForkConfig,\n\t\tprivate logger: Logger,\n\t) {\n\t\tthis.add = this.add.bind(this);\n\t\tthis.commit = this.commit.bind(this);\n\t\tthis.tag = this.tag.bind(this);\n\t\tthis.currentBranch = this.currentBranch.bind(this);\n\t}\n\n\tpublic add(...args: (string | undefined)[]): Promise<string> {\n\t\tif (this.config.dryRun) {\n\t\t\treturn Promise.resolve(\"\");\n\t\t}\n\n\t\treturn this.execGit(\"add\", args.filter(Boolean) as string[]);\n\t}\n\n\tpublic commit(...args: (string | undefined)[]): Promise<string> {\n\t\tif (this.config.dryRun) {\n\t\t\treturn Promise.resolve(\"\");\n\t\t}\n\n\t\treturn this.execGit(\"commit\", args.filter(Boolean) as string[]);\n\t}\n\n\tpublic tag(...args: (string | undefined)[]): Promise<string> {\n\t\tif (this.config.dryRun) {\n\t\t\treturn Promise.resolve(\"\");\n\t\t}\n\n\t\treturn this.execGit(\"tag\", args.filter(Boolean) as string[]);\n\t}\n\n\tpublic shouldIgnore(file: string): Promise<boolean> {\n\t\treturn new Promise((onResolve) => {\n\t\t\texecFile(\"git\", [\"check-ignore\", \"--no-index\", file], { cwd: this.config.path }, (error) => {\n\t\t\t\tif (error) {\n\t\t\t\t\tonResolve(false);\n\t\t\t\t}\n\n\t\t\t\tonResolve(true);\n\t\t\t});\n\t\t});\n\t}\n\n\tpublic async currentBranch(): Promise<string> {\n\t\treturn (await this.execGit(\"rev-parse\", [\"--abbrev-ref\", \"HEAD\"])).trim();\n\t}\n\n\tprivate execGit(command: string, args: string[]): Promise<string> {\n\t\tthis.logger.debug(`[git ${command}] ${args.join(\" \")}`);\n\n\t\treturn new Promise((onResolve, onReject) => {\n\t\t\texecFile(\n\t\t\t\t\"git\",\n\t\t\t\t[command, ...args],\n\t\t\t\t{\n\t\t\t\t\tcwd: this.config.path,\n\t\t\t\t},\n\t\t\t\t(error, stdout, stderr) => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tthis.logger.error(`[git ${command}] `);\n\t\t\t\t\t\tonReject(error);\n\t\t\t\t\t}\n\n\t\t\t\t\tonResolve(stdout ? stdout : stderr);\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n}\n","#!/usr/bin/env node\n\nimport { writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\n\nimport { getUserConfig } from \"./config/user-config\";\nimport { Logger } from \"./utils/logger\";\nimport { FileManager } from \"./strategies/file-manager\";\nimport { Git } from \"./utils/git\";\n\nimport { getCurrentVersion, getNextVersion } from \"./process/version\";\nimport { updateChangelog } from \"./process/changelog\";\nimport { commitChanges } from \"./process/commit\";\nimport { tagChanges } from \"./process/tag\";\n\nasync function runFork() {\n\tconst startTime = Date.now();\n\n\tconst config = await getUserConfig();\n\n\tconst logger = new Logger(config);\n\tconst fileManager = new FileManager(config, logger);\n\tconst git = new Git(config, logger);\n\n\tlogger.log(`Running fork-version - ${new Date().toUTCString()}`);\n\tlogger.log(config.dryRun ? \"[DRY RUN] No changes will be written to disk.\\n\" : \"\");\n\n\t/**\n\t * Get the list of files to update, excluding any files that are ignored by git.\n\t */\n\tconst filesToUpdate: string[] = [];\n\tfor (const file of config.files) {\n\t\tif (!(await git.shouldIgnore(file))) {\n\t\t\tfilesToUpdate.push(file);\n\t\t}\n\t}\n\n\tconst current = await getCurrentVersion(config, logger, fileManager, filesToUpdate);\n\tconst next = await getNextVersion(config, logger, current.version);\n\n\tlogger.log(\"Updating Files: \");\n\tfor (const outFile of current.files) {\n\t\tlogger.log(` - ${outFile.path}`);\n\n\t\tfileManager.write(outFile, next.version);\n\t}\n\n\tawait updateChangelog(config, logger, next.version);\n\tawait commitChanges(config, logger, git, current.files, next.version);\n\tawait tagChanges(config, logger, git, next.version);\n\n\t// Print git push command\n\tconst branchName = await git.currentBranch();\n\tlogger.log(\n\t\t`\\nRun \\`git push --follow-tags origin ${branchName}\\` to push the changes and the tag.`,\n\t);\n\n\t// Print npm publish command\n\tif (current.files.some((file) => file.name === \"package.json\" && file.isPrivate === false)) {\n\t\tconst npmTag = typeof config.preRelease === \"string\" ? config.preRelease : \"prerelease\";\n\t\tlogger.log(\n\t\t\t`${next.releaseType}`.startsWith(\"pre\")\n\t\t\t\t? `Run \\`npm publish --tag ${npmTag}\\` to publish the package.`\n\t\t\t\t: \"Run `npm publish` to publish the package.\",\n\t\t);\n\t}\n\n\tlogger.debug(`Completed in ${Date.now() - startTime} ms`);\n\n\tconst result = {\n\t\tconfig,\n\t\tcurrent,\n\t\tnext,\n\t};\n\n\tif (!config.dryRun && config.debug) {\n\t\twriteFileSync(\n\t\t\tjoin(config.path, `fork-version-${Date.now()}.debug-log.json`),\n\t\t\tJSON.stringify(result, null, 2),\n\t\t);\n\t}\n\n\treturn result;\n}\n\nrunFork();\n"]}
|
|
1
|
+
{"version":3,"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,eAAA,CAAA,CAAA;AAAA,MAC7D,IAAK,CAAA,SAAA,CAAU,MAAQ,EAAA,IAAA,EAAM,CAAC;AAAA,KAC/B;AAAA;AAGD,EAAO,OAAA,MAAA;AACR;AAGA,OAAQ,EAAA,CAAE,KAAM,CAAA,CAAC,KAAuB,KAAA;AACvC,EAAA,IAAI,iBAAiB,KAAO,EAAA;AAE3B,IAAI,IAAA,KAAA,CAAM,iBAAiB,QAAU,EAAA;AACpC,MAAQ,OAAA,CAAA,KAAA,CAAM,MAAM,OAAO,CAAA;AAC3B,MAAW,KAAA,MAAA,GAAA,IAAO,KAAM,CAAA,KAAA,CAAM,MAAQ,EAAA;AACrC,QAAA,OAAA,CAAQ,IAAI,CAAG,EAAA,GAAA,CAAI,IAAI,CAAO,IAAA,EAAA,GAAA,CAAI,OAAO,CAAE,CAAA,CAAA;AAAA;AAE5C,MAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AAAA;AAGf,IAAA,IAAI,MAAM,KAAO,EAAA;AAChB,MAAQ,OAAA,CAAA,KAAA,CAAM,MAAM,KAAK,CAAA;AAAA,KACnB,MAAA;AACN,MAAQ,OAAA,CAAA,KAAA,CAAM,MAAM,OAAO,CAAA;AAAA;AAC5B,GACM,MAAA;AACN,IAAA,OAAA,CAAQ,MAAM,KAAK,CAAA;AAAA;AAEpB,EAAA,OAAA,CAAQ,KAAK,CAAC,CAAA;AACf,CAAC,CAAA","file":"cli.js","sourcesContent":["import { execFile } from \"node:child_process\";\nimport semver from \"semver\";\nimport type { ForkConfig } from \"../config/types\";\n\nexport class Git {\n\tconstructor(private config: Pick<ForkConfig, \"path\" | \"dryRun\">) {\n\t\tthis.add = this.add.bind(this);\n\t\tthis.commit = this.commit.bind(this);\n\t\tthis.tag = this.tag.bind(this);\n\t\tthis.isIgnored = this.isIgnored.bind(this);\n\t\tthis.getCurrentBranchName = this.getCurrentBranchName.bind(this);\n\t\tthis.getTags = this.getTags.bind(this);\n\t\tthis.getLatestTag = this.getLatestTag.bind(this);\n\t}\n\n\tprivate async execGit(command: string, args: string[]): Promise<string> {\n\t\treturn new Promise((onResolve, onReject) => {\n\t\t\texecFile(\n\t\t\t\t\"git\",\n\t\t\t\t[command, ...args],\n\t\t\t\t{\n\t\t\t\t\tcwd: this.config.path,\n\t\t\t\t\tmaxBuffer: Infinity,\n\t\t\t\t},\n\t\t\t\t(error, stdout, stderr) => {\n\t\t\t\t\tif (error) {\n\t\t\t\t\t\tonReject(error);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tonResolve(stdout ? stdout : stderr);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t});\n\t}\n\n\tpublic async add(...args: (string | undefined)[]): Promise<string> {\n\t\tif (this.config.dryRun) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\treturn this.execGit(\"add\", args.filter(Boolean) as string[]);\n\t}\n\n\tpublic async commit(...args: (string | undefined)[]): Promise<string> {\n\t\tif (this.config.dryRun) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\treturn this.execGit(\"commit\", args.filter(Boolean) as string[]);\n\t}\n\n\tpublic async tag(...args: (string | undefined)[]): Promise<string> {\n\t\tif (this.config.dryRun) {\n\t\t\treturn \"\";\n\t\t}\n\n\t\treturn this.execGit(\"tag\", args.filter(Boolean) as string[]);\n\t}\n\n\tpublic async isIgnored(file: string): Promise<boolean> {\n\t\ttry {\n\t\t\tawait this.execGit(\"check-ignore\", [\"--no-index\", file]);\n\n\t\t\treturn true;\n\t\t} catch (_error) {\n\t\t\treturn false;\n\t\t}\n\t}\n\n\tpublic async getCurrentBranchName(): Promise<string> {\n\t\treturn (await this.execGit(\"rev-parse\", [\"--abbrev-ref\", \"HEAD\"])).trim();\n\t}\n\n\t/**\n\t * `getTags` returns valid semver version tags in order of the commit history.\n\t *\n\t * Using `git log` to get the commit history, we then parse the tags from the\n\t * commit details which is expected to be in the following format:\n\t * @example\n\t * ```txt\n\t * commit 3841b1d05750d42197fe958e3d8e06df378a842d (HEAD -> main, tag: 1.0.2)\n\t * Author: Username <username@example.com>\n\t * Date: Sat Nov 9 15:00:00 2024 +0000\n\t *\n\t * chore(release): 1.2.3\n\t * ```\n\t *\n\t * - [Functionality extracted from the conventional-changelog - git-semver-tags project](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/index.js)\n\t * - [conventional-changelog git-semver-tags MIT Licence](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/LICENSE.md)\n\t */\n\tpublic async getTags(tagPrefix: string | undefined): Promise<string[]> {\n\t\tconst logOutput = await this.execGit(\"log\", [\"--decorate\", \"--no-color\", \"--date-order\"]);\n\n\t\t/**\n\t\t * Search for tags in the following formats:\n\t\t * @example \"tag: 1.2.3,\" or \"tag: 1.2.3)\"\n\t\t */\n\t\tconst TAG_REGEX = /tag:\\s*(.+?)[,)]/gi;\n\n\t\tconst tags: string[] = [];\n\t\tlet match: RegExpExecArray | null = null;\n\t\tlet tag: string;\n\t\tlet tagWithoutPrefix: string;\n\n\t\tfor (const logOutputLine of logOutput.split(\"\\n\")) {\n\t\t\twhile ((match = TAG_REGEX.exec(logOutputLine))) {\n\t\t\t\ttag = match[1];\n\n\t\t\t\tif (tagPrefix) {\n\t\t\t\t\tif (tag.startsWith(tagPrefix)) {\n\t\t\t\t\t\ttagWithoutPrefix = tag.replace(tagPrefix, \"\");\n\n\t\t\t\t\t\tif (semver.valid(tagWithoutPrefix)) {\n\t\t\t\t\t\t\ttags.push(tag);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else if (semver.valid(tag)) {\n\t\t\t\t\ttags.push(tag);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn tags;\n\t}\n\n\tpublic async getLatestTag(tagPrefix: string | undefined): Promise<string> {\n\t\tconst tags = await this.getTags(tagPrefix);\n\t\tif (!tags.length) return \"\";\n\n\t\tconst cleanedTags = [];\n\t\tfor (const tag of tags) {\n\t\t\tconst cleanedTag = semver.clean(tag.replace(new RegExp(`^${tagPrefix}`), \"\"));\n\t\t\tif (cleanedTag) {\n\t\t\t\tcleanedTags.push(cleanedTag);\n\t\t\t}\n\t\t}\n\n\t\treturn cleanedTags.sort(semver.rcompare)[0];\n\t}\n}\n","#!/usr/bin/env node\n\nimport { writeFileSync } from \"node:fs\";\nimport { join } from \"node:path\";\nimport { ZodError } from \"zod\";\n\nimport { getUserConfig } from \"./config/user-config\";\nimport { Logger } from \"./utils/logger\";\nimport { FileManager } from \"./files/file-manager\";\nimport { Git } from \"./utils/git\";\n\nimport { getCurrentVersion, getNextVersion } from \"./process/version\";\nimport { updateChangelog } from \"./process/changelog\";\nimport { commitChanges } from \"./process/commit\";\nimport { tagChanges } from \"./process/tag\";\n\nasync function runFork() {\n\tconst startTime = Date.now();\n\n\tconst config = await getUserConfig();\n\n\tconst logger = new Logger(config);\n\tconst fileManager = new FileManager(config, logger);\n\tconst git = new Git(config);\n\n\tlogger.log(`Running fork-version - ${new Date().toUTCString()}`);\n\tlogger.warn(config.dryRun ? \"[Dry Run] No changes will be written to disk.\\n\" : \"\");\n\n\tconst current = await getCurrentVersion(config, logger, git, fileManager, config.files);\n\tconst next = await getNextVersion(config, logger, current.version);\n\n\tlogger.log(\"Updating files: \");\n\tfor (const outFile of current.files) {\n\t\tlogger.log(` - ${outFile.path}`);\n\n\t\tfileManager.write(outFile, next.version);\n\t}\n\n\tawait updateChangelog(config, logger, next.version);\n\tawait commitChanges(config, logger, git, current.files, next.version);\n\tawait tagChanges(config, logger, git, next.version);\n\n\t// Print git push command\n\tconst branchName = await git.getCurrentBranchName();\n\tlogger.log(\n\t\t`\\nRun \\`git push --follow-tags origin ${branchName}\\` to push the changes and the tag.`,\n\t);\n\n\t// Print npm publish command\n\tif (current.files.some((file) => file.name === \"package.json\" && file.isPrivate === false)) {\n\t\tconst npmTag = typeof config.preRelease === \"string\" ? config.preRelease : \"prerelease\";\n\t\tlogger.log(\n\t\t\t`${next.releaseType}`.startsWith(\"pre\")\n\t\t\t\t? `Run \\`npm publish --tag ${npmTag}\\` to publish the package.`\n\t\t\t\t: \"Run `npm publish` to publish the package.\",\n\t\t);\n\t}\n\n\tlogger.debug(`Completed in ${Date.now() - startTime} ms`);\n\n\tconst result = {\n\t\tconfig,\n\t\tcurrent,\n\t\tnext,\n\t};\n\n\tif (!config.dryRun && config.debug) {\n\t\twriteFileSync(\n\t\t\tjoin(config.path, `fork-version-${Date.now()}.debug-log.json`),\n\t\t\tJSON.stringify(result, null, 2),\n\t\t);\n\t}\n\n\treturn result;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nrunFork().catch((error: Error | any) => {\n\tif (error instanceof Error) {\n\t\t// If the error is a ZodError, print the keys that failed validation\n\t\tif (error.cause instanceof ZodError) {\n\t\t\tconsole.error(error.message);\n\t\t\tfor (const err of error.cause.errors) {\n\t\t\t\tconsole.log(`${err.path} => ${err.message}`);\n\t\t\t}\n\t\t\tprocess.exit(3);\n\t\t}\n\n\t\tif (error.stack) {\n\t\t\tconsole.error(error.stack);\n\t\t} else {\n\t\t\tconsole.error(error.message);\n\t\t}\n\t} else {\n\t\tconsole.error(error);\n\t}\n\tprocess.exit(1);\n});\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,48 +1,48 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkJAYAB33O_cjs = require('./chunk-JAYAB33O.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
Object.defineProperty(exports, "FileManager", {
|
|
8
8
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
9
|
+
get: function () { return chunkJAYAB33O_cjs.FileManager; }
|
|
10
10
|
});
|
|
11
11
|
Object.defineProperty(exports, "ForkConfigSchema", {
|
|
12
12
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
13
|
+
get: function () { return chunkJAYAB33O_cjs.ForkConfigSchema; }
|
|
14
14
|
});
|
|
15
15
|
Object.defineProperty(exports, "Logger", {
|
|
16
16
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
17
|
+
get: function () { return chunkJAYAB33O_cjs.Logger; }
|
|
18
18
|
});
|
|
19
19
|
Object.defineProperty(exports, "commitChanges", {
|
|
20
20
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
21
|
+
get: function () { return chunkJAYAB33O_cjs.commitChanges; }
|
|
22
22
|
});
|
|
23
23
|
Object.defineProperty(exports, "defineConfig", {
|
|
24
24
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
25
|
+
get: function () { return chunkJAYAB33O_cjs.defineConfig; }
|
|
26
26
|
});
|
|
27
27
|
Object.defineProperty(exports, "getCurrentVersion", {
|
|
28
28
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
29
|
+
get: function () { return chunkJAYAB33O_cjs.getCurrentVersion; }
|
|
30
30
|
});
|
|
31
31
|
Object.defineProperty(exports, "getNextVersion", {
|
|
32
32
|
enumerable: true,
|
|
33
|
-
get: function () { return
|
|
33
|
+
get: function () { return chunkJAYAB33O_cjs.getNextVersion; }
|
|
34
34
|
});
|
|
35
35
|
Object.defineProperty(exports, "getUserConfig", {
|
|
36
36
|
enumerable: true,
|
|
37
|
-
get: function () { return
|
|
37
|
+
get: function () { return chunkJAYAB33O_cjs.getUserConfig; }
|
|
38
38
|
});
|
|
39
39
|
Object.defineProperty(exports, "tagChanges", {
|
|
40
40
|
enumerable: true,
|
|
41
|
-
get: function () { return
|
|
41
|
+
get: function () { return chunkJAYAB33O_cjs.tagChanges; }
|
|
42
42
|
});
|
|
43
43
|
Object.defineProperty(exports, "updateChangelog", {
|
|
44
44
|
enumerable: true,
|
|
45
|
-
get: function () { return
|
|
45
|
+
get: function () { return chunkJAYAB33O_cjs.updateChangelog; }
|
|
46
46
|
});
|
|
47
47
|
//# sourceMappingURL=index.cjs.map
|
|
48
48
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.cts
CHANGED
|
@@ -384,11 +384,41 @@ declare class FileManager {
|
|
|
384
384
|
write(fileState: FileState, newVersion: string): void;
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
+
declare class Git {
|
|
388
|
+
private config;
|
|
389
|
+
constructor(config: Pick<ForkConfig, "path" | "dryRun">);
|
|
390
|
+
private execGit;
|
|
391
|
+
add(...args: (string | undefined)[]): Promise<string>;
|
|
392
|
+
commit(...args: (string | undefined)[]): Promise<string>;
|
|
393
|
+
tag(...args: (string | undefined)[]): Promise<string>;
|
|
394
|
+
isIgnored(file: string): Promise<boolean>;
|
|
395
|
+
getCurrentBranchName(): Promise<string>;
|
|
396
|
+
/**
|
|
397
|
+
* `getTags` returns valid semver version tags in order of the commit history.
|
|
398
|
+
*
|
|
399
|
+
* Using `git log` to get the commit history, we then parse the tags from the
|
|
400
|
+
* commit details which is expected to be in the following format:
|
|
401
|
+
* @example
|
|
402
|
+
* ```txt
|
|
403
|
+
* commit 3841b1d05750d42197fe958e3d8e06df378a842d (HEAD -> main, tag: 1.0.2)
|
|
404
|
+
* Author: Username <username@example.com>
|
|
405
|
+
* Date: Sat Nov 9 15:00:00 2024 +0000
|
|
406
|
+
*
|
|
407
|
+
* chore(release): 1.2.3
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* - [Functionality extracted from the conventional-changelog - git-semver-tags project](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/index.js)
|
|
411
|
+
* - [conventional-changelog git-semver-tags MIT Licence](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/LICENSE.md)
|
|
412
|
+
*/
|
|
413
|
+
getTags(tagPrefix: string | undefined): Promise<string[]>;
|
|
414
|
+
getLatestTag(tagPrefix: string | undefined): Promise<string>;
|
|
415
|
+
}
|
|
416
|
+
|
|
387
417
|
interface CurrentVersion {
|
|
388
418
|
version: string;
|
|
389
419
|
files: FileState[];
|
|
390
420
|
}
|
|
391
|
-
declare function getCurrentVersion(config: ForkConfig, logger: Logger, fileManager: FileManager, filesToUpdate: string[]): Promise<CurrentVersion>;
|
|
421
|
+
declare function getCurrentVersion(config: ForkConfig, logger: Logger, git: Git, fileManager: FileManager, filesToUpdate: string[]): Promise<CurrentVersion>;
|
|
392
422
|
interface NextVersion {
|
|
393
423
|
version: string;
|
|
394
424
|
level?: number;
|
|
@@ -400,18 +430,6 @@ declare function getNextVersion(config: ForkConfig, logger: Logger, currentVersi
|
|
|
400
430
|
|
|
401
431
|
declare function updateChangelog(config: ForkConfig, logger: Logger, nextVersion: string): Promise<void>;
|
|
402
432
|
|
|
403
|
-
declare class Git {
|
|
404
|
-
private config;
|
|
405
|
-
private logger;
|
|
406
|
-
constructor(config: ForkConfig, logger: Logger);
|
|
407
|
-
add(...args: (string | undefined)[]): Promise<string>;
|
|
408
|
-
commit(...args: (string | undefined)[]): Promise<string>;
|
|
409
|
-
tag(...args: (string | undefined)[]): Promise<string>;
|
|
410
|
-
shouldIgnore(file: string): Promise<boolean>;
|
|
411
|
-
currentBranch(): Promise<string>;
|
|
412
|
-
private execGit;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
433
|
declare function commitChanges(config: ForkConfig, logger: Logger, git: Git, files: FileState[], nextVersion: string): Promise<void>;
|
|
416
434
|
|
|
417
435
|
declare function tagChanges(config: ForkConfig, logger: Logger, git: Git, nextVersion: string): Promise<void>;
|
package/dist/index.d.ts
CHANGED
|
@@ -384,11 +384,41 @@ declare class FileManager {
|
|
|
384
384
|
write(fileState: FileState, newVersion: string): void;
|
|
385
385
|
}
|
|
386
386
|
|
|
387
|
+
declare class Git {
|
|
388
|
+
private config;
|
|
389
|
+
constructor(config: Pick<ForkConfig, "path" | "dryRun">);
|
|
390
|
+
private execGit;
|
|
391
|
+
add(...args: (string | undefined)[]): Promise<string>;
|
|
392
|
+
commit(...args: (string | undefined)[]): Promise<string>;
|
|
393
|
+
tag(...args: (string | undefined)[]): Promise<string>;
|
|
394
|
+
isIgnored(file: string): Promise<boolean>;
|
|
395
|
+
getCurrentBranchName(): Promise<string>;
|
|
396
|
+
/**
|
|
397
|
+
* `getTags` returns valid semver version tags in order of the commit history.
|
|
398
|
+
*
|
|
399
|
+
* Using `git log` to get the commit history, we then parse the tags from the
|
|
400
|
+
* commit details which is expected to be in the following format:
|
|
401
|
+
* @example
|
|
402
|
+
* ```txt
|
|
403
|
+
* commit 3841b1d05750d42197fe958e3d8e06df378a842d (HEAD -> main, tag: 1.0.2)
|
|
404
|
+
* Author: Username <username@example.com>
|
|
405
|
+
* Date: Sat Nov 9 15:00:00 2024 +0000
|
|
406
|
+
*
|
|
407
|
+
* chore(release): 1.2.3
|
|
408
|
+
* ```
|
|
409
|
+
*
|
|
410
|
+
* - [Functionality extracted from the conventional-changelog - git-semver-tags project](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/index.js)
|
|
411
|
+
* - [conventional-changelog git-semver-tags MIT Licence](https://github.com/conventional-changelog/conventional-changelog/blob/fac8045242099c016f5f3905e54e02b7d466bd7b/packages/git-semver-tags/LICENSE.md)
|
|
412
|
+
*/
|
|
413
|
+
getTags(tagPrefix: string | undefined): Promise<string[]>;
|
|
414
|
+
getLatestTag(tagPrefix: string | undefined): Promise<string>;
|
|
415
|
+
}
|
|
416
|
+
|
|
387
417
|
interface CurrentVersion {
|
|
388
418
|
version: string;
|
|
389
419
|
files: FileState[];
|
|
390
420
|
}
|
|
391
|
-
declare function getCurrentVersion(config: ForkConfig, logger: Logger, fileManager: FileManager, filesToUpdate: string[]): Promise<CurrentVersion>;
|
|
421
|
+
declare function getCurrentVersion(config: ForkConfig, logger: Logger, git: Git, fileManager: FileManager, filesToUpdate: string[]): Promise<CurrentVersion>;
|
|
392
422
|
interface NextVersion {
|
|
393
423
|
version: string;
|
|
394
424
|
level?: number;
|
|
@@ -400,18 +430,6 @@ declare function getNextVersion(config: ForkConfig, logger: Logger, currentVersi
|
|
|
400
430
|
|
|
401
431
|
declare function updateChangelog(config: ForkConfig, logger: Logger, nextVersion: string): Promise<void>;
|
|
402
432
|
|
|
403
|
-
declare class Git {
|
|
404
|
-
private config;
|
|
405
|
-
private logger;
|
|
406
|
-
constructor(config: ForkConfig, logger: Logger);
|
|
407
|
-
add(...args: (string | undefined)[]): Promise<string>;
|
|
408
|
-
commit(...args: (string | undefined)[]): Promise<string>;
|
|
409
|
-
tag(...args: (string | undefined)[]): Promise<string>;
|
|
410
|
-
shouldIgnore(file: string): Promise<boolean>;
|
|
411
|
-
currentBranch(): Promise<string>;
|
|
412
|
-
private execGit;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
433
|
declare function commitChanges(config: ForkConfig, logger: Logger, git: Git, files: FileState[], nextVersion: string): Promise<void>;
|
|
416
434
|
|
|
417
435
|
declare function tagChanges(config: ForkConfig, logger: Logger, git: Git, nextVersion: string): Promise<void>;
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { FileManager, ForkConfigSchema, Logger, commitChanges, defineConfig, getCurrentVersion, getNextVersion, getUserConfig, tagChanges, updateChangelog } from './chunk-
|
|
1
|
+
export { FileManager, ForkConfigSchema, Logger, commitChanges, defineConfig, getCurrentVersion, getNextVersion, getUserConfig, tagChanges, updateChangelog } from './chunk-4M7BP5DG.js';
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fork-version",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Fork-Version automates version control tasks such as determining, updating, and committing versions, files, and changelogs, simplifying the process when adhering to the conventional commit standard.",
|
|
6
6
|
"keywords": [
|
|
@@ -28,9 +28,10 @@
|
|
|
28
28
|
"name": "Eanna Glavin",
|
|
29
29
|
"url": "https://eglavin.com"
|
|
30
30
|
},
|
|
31
|
-
"packageManager": "pnpm@
|
|
31
|
+
"packageManager": "pnpm@9.12.3",
|
|
32
32
|
"engines": {
|
|
33
|
-
"node": ">=18.0.0"
|
|
33
|
+
"node": ">=18.0.0",
|
|
34
|
+
"pnpm": ">=9.0.0"
|
|
34
35
|
},
|
|
35
36
|
"private": false,
|
|
36
37
|
"type": "module",
|
|
@@ -92,7 +93,6 @@
|
|
|
92
93
|
"conventional-changelog-conventionalcommits": "7.0.2",
|
|
93
94
|
"conventional-recommended-bump": "9.0.0",
|
|
94
95
|
"esbuild": "0.24.0",
|
|
95
|
-
"git-semver-tags": "7.0.1",
|
|
96
96
|
"glob": "10.3.12",
|
|
97
97
|
"joycon": "3.1.1",
|
|
98
98
|
"jsonc-parser": "^3.3.1",
|
|
@@ -105,18 +105,18 @@
|
|
|
105
105
|
"@types/json-schema": "7.0.15",
|
|
106
106
|
"@types/node": "20.11.30",
|
|
107
107
|
"@types/semver": "7.5.8",
|
|
108
|
-
"@vitest/coverage-v8": "2.1.
|
|
109
|
-
"@vitest/ui": "2.1.
|
|
110
|
-
"eslint": "9.
|
|
108
|
+
"@vitest/coverage-v8": "2.1.4",
|
|
109
|
+
"@vitest/ui": "2.1.4",
|
|
110
|
+
"eslint": "9.14.0",
|
|
111
111
|
"eslint-config-prettier": "9.1.0",
|
|
112
112
|
"eslint-plugin-prettier": "5.2.1",
|
|
113
|
-
"globals": "15.
|
|
113
|
+
"globals": "15.11.0",
|
|
114
114
|
"prettier": "3.3.3",
|
|
115
115
|
"rimraf": "6.0.1",
|
|
116
|
-
"tsup": "8.3.
|
|
117
|
-
"typescript": "5.6.
|
|
118
|
-
"typescript-eslint": "8.
|
|
119
|
-
"vitest": "2.1.
|
|
120
|
-
"zod-to-json-schema": "3.23.
|
|
116
|
+
"tsup": "8.3.5",
|
|
117
|
+
"typescript": "5.6.3",
|
|
118
|
+
"typescript-eslint": "8.12.2",
|
|
119
|
+
"vitest": "2.1.4",
|
|
120
|
+
"zod-to-json-schema": "3.23.5"
|
|
121
121
|
}
|
|
122
122
|
}
|