fork-version 1.4.90 → 1.4.95
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 +40 -0
- package/dist/{chunk-OAJOJDJP.cjs → chunk-6SI2AHBP.cjs} +241 -249
- package/dist/chunk-6SI2AHBP.cjs.map +1 -0
- package/dist/{chunk-ODYTFXKR.js → chunk-7ZOLJADN.js} +242 -248
- package/dist/chunk-7ZOLJADN.js.map +1 -0
- package/dist/cli.cjs +26 -10
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +22 -6
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +12 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/package.json +26 -24
- package/dist/chunk-OAJOJDJP.cjs.map +0 -1
- package/dist/chunk-ODYTFXKR.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,45 @@
|
|
|
1
1
|
# Fork Version
|
|
2
2
|
|
|
3
|
+
## 1.4.95 (2024-10-06)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Chore
|
|
7
|
+
|
|
8
|
+
* bump dependencies ([#71](https://github.com/eglavin/fork-version/issues/71)) ([d2d046c](https://github.com/eglavin/fork-version/commit/d2d046ca22bf7f0a078e3f1d02a10d8b6e98b9b5))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## 1.4.94 (2024-10-04)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Test
|
|
15
|
+
|
|
16
|
+
* improve versioning tests ([#68](https://github.com/eglavin/fork-version/issues/68)) ([635329c](https://github.com/eglavin/fork-version/commit/635329c6b9beb1929f5e03da6ecd76c340b7c406))
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
## 1.4.93 (2024-07-28)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Refactor
|
|
23
|
+
|
|
24
|
+
* extract types from schema + use js file to define schema ([#69](https://github.com/eglavin/fork-version/issues/69)) ([01fccbe](https://github.com/eglavin/fork-version/commit/01fccbe020a70d2c5f8c3c3b6c33da6cb9260ebd))
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## 1.4.92 (2024-06-21)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### Refactor
|
|
31
|
+
|
|
32
|
+
* add should ignore option to git class + remove dotgitignore ([#67](https://github.com/eglavin/fork-version/issues/67)) ([527b8a4](https://github.com/eglavin/fork-version/commit/527b8a4766e59a509794a0de5ad978f92e3226bf))
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
## 1.4.91 (2024-06-17)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
### Bug Fixes
|
|
39
|
+
|
|
40
|
+
* dont throw an error when no remote is defined ([#66](https://github.com/eglavin/fork-version/issues/66)) ([7e9c687](https://github.com/eglavin/fork-version/commit/7e9c68743571b061d7165e63b3c7eeeca7dbaaef))
|
|
41
|
+
|
|
42
|
+
|
|
3
43
|
## 1.4.90 (2024-06-13)
|
|
4
44
|
|
|
5
45
|
|
|
@@ -6,17 +6,16 @@ var path = require('path');
|
|
|
6
6
|
var JoyCon = require('joycon');
|
|
7
7
|
var bundleRequire = require('bundle-require');
|
|
8
8
|
var glob = require('glob');
|
|
9
|
-
var dotgitignore = require('dotgitignore');
|
|
10
9
|
var meow = require('meow');
|
|
11
10
|
var conventionalChangelogConfigSpec = require('conventional-changelog-config-spec');
|
|
12
11
|
var child_process = require('child_process');
|
|
12
|
+
var detectIndent = require('detect-indent');
|
|
13
|
+
var detectNewline = require('detect-newline');
|
|
14
|
+
var cheerio = require('cheerio/slim');
|
|
13
15
|
var semver3 = require('semver');
|
|
14
16
|
var conventionalRecommendedBump = require('conventional-recommended-bump');
|
|
15
17
|
var gitSemverTags = require('git-semver-tags');
|
|
16
18
|
var conventionalChangelog = require('conventional-changelog');
|
|
17
|
-
var detectIndent = require('detect-indent');
|
|
18
|
-
var detectNewline = require('detect-newline');
|
|
19
|
-
var cheerio = require('cheerio/lib/slim');
|
|
20
19
|
|
|
21
20
|
var _documentCurrentScript = typeof document !== 'undefined' ? document.currentScript : null;
|
|
22
21
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -40,17 +39,16 @@ function _interopNamespace(e) {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
var JoyCon__default = /*#__PURE__*/_interopDefault(JoyCon);
|
|
43
|
-
var dotgitignore__default = /*#__PURE__*/_interopDefault(dotgitignore);
|
|
44
42
|
var meow__default = /*#__PURE__*/_interopDefault(meow);
|
|
45
43
|
var conventionalChangelogConfigSpec__default = /*#__PURE__*/_interopDefault(conventionalChangelogConfigSpec);
|
|
44
|
+
var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
|
|
45
|
+
var cheerio__namespace = /*#__PURE__*/_interopNamespace(cheerio);
|
|
46
46
|
var semver3__default = /*#__PURE__*/_interopDefault(semver3);
|
|
47
47
|
var conventionalRecommendedBump__default = /*#__PURE__*/_interopDefault(conventionalRecommendedBump);
|
|
48
48
|
var gitSemverTags__default = /*#__PURE__*/_interopDefault(gitSemverTags);
|
|
49
49
|
var conventionalChangelog__default = /*#__PURE__*/_interopDefault(conventionalChangelog);
|
|
50
|
-
var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
|
|
51
|
-
var cheerio__namespace = /*#__PURE__*/_interopNamespace(cheerio);
|
|
52
50
|
|
|
53
|
-
// src/config/schema.
|
|
51
|
+
// src/config/schema.js
|
|
54
52
|
var ChangelogPresetConfigTypeSchema = zod.z.object({
|
|
55
53
|
/**
|
|
56
54
|
* The type of commit message.
|
|
@@ -295,9 +293,6 @@ var ForkConfigSchema = zod.z.object({
|
|
|
295
293
|
*/
|
|
296
294
|
releaseMessageSuffix: zod.z.string().optional().describe("Add a suffix to the release commit message.")
|
|
297
295
|
});
|
|
298
|
-
function defineConfig(config) {
|
|
299
|
-
return config;
|
|
300
|
-
}
|
|
301
296
|
|
|
302
297
|
// src/config/defaults.ts
|
|
303
298
|
var DEFAULT_CONFIG = {
|
|
@@ -399,7 +394,7 @@ Examples:
|
|
|
399
394
|
Run fork-version and update all "package.json" files in subdirectories.`;
|
|
400
395
|
function getCliArguments() {
|
|
401
396
|
return meow__default.default(helperText, {
|
|
402
|
-
importMeta: ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.src || new URL('
|
|
397
|
+
importMeta: ({ url: (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('chunk-6SI2AHBP.cjs', document.baseURI).href)) }),
|
|
403
398
|
booleanDefault: void 0,
|
|
404
399
|
helpIndent: 0,
|
|
405
400
|
flags: {
|
|
@@ -503,12 +498,9 @@ function getChangelogPresetConfig(mergedConfig, cliArgumentsFlags, detectedGitHo
|
|
|
503
498
|
return ChangelogPresetConfigSchema.passthrough().parse(preset);
|
|
504
499
|
}
|
|
505
500
|
async function detectGitHost(cwd) {
|
|
506
|
-
const remoteUrl = await new Promise((onResolve
|
|
507
|
-
child_process.execFile("git", ["config", "--get", "remote.origin.url"], { cwd }, (
|
|
508
|
-
|
|
509
|
-
onReject(error);
|
|
510
|
-
}
|
|
511
|
-
onResolve(stdout ? stdout.trim() : stderr);
|
|
501
|
+
const remoteUrl = await new Promise((onResolve) => {
|
|
502
|
+
child_process.execFile("git", ["config", "--get", "remote.origin.url"], { cwd }, (_error, stdout) => {
|
|
503
|
+
onResolve(stdout ? stdout.trim() : "");
|
|
512
504
|
});
|
|
513
505
|
});
|
|
514
506
|
if (remoteUrl.startsWith("https://") && remoteUrl.includes("@dev.azure.com/")) {
|
|
@@ -576,10 +568,7 @@ async function getUserConfig() {
|
|
|
576
568
|
const detectedGitHost = await detectGitHost(cwd);
|
|
577
569
|
return {
|
|
578
570
|
...mergedConfig,
|
|
579
|
-
files:
|
|
580
|
-
cwd,
|
|
581
|
-
getFilesList(configFile?.files, cliArguments.flags?.files, globResults)
|
|
582
|
-
),
|
|
571
|
+
files: getFilesList(configFile?.files, cliArguments.flags?.files, globResults),
|
|
583
572
|
path: cwd,
|
|
584
573
|
preRelease: (
|
|
585
574
|
// Meow doesn't support multiple flags with the same name, so we need to check both.
|
|
@@ -635,10 +624,232 @@ function getFilesList(configFiles, cliFiles, globResults) {
|
|
|
635
624
|
}
|
|
636
625
|
return DEFAULT_CONFIG.files;
|
|
637
626
|
}
|
|
638
|
-
function
|
|
639
|
-
|
|
640
|
-
|
|
627
|
+
function defineConfig(config) {
|
|
628
|
+
return config;
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
// src/utils/logger.ts
|
|
632
|
+
var Logger = class {
|
|
633
|
+
constructor(config) {
|
|
634
|
+
this.config = config;
|
|
635
|
+
this.log = this.log.bind(this);
|
|
636
|
+
this.warn = this.warn.bind(this);
|
|
637
|
+
this.error = this.error.bind(this);
|
|
638
|
+
this.debug = this.debug.bind(this);
|
|
639
|
+
this.disableLogs = this.config.silent || this.config.inspectVersion;
|
|
640
|
+
}
|
|
641
|
+
disableLogs = false;
|
|
642
|
+
log(...messages) {
|
|
643
|
+
if (!this.disableLogs) {
|
|
644
|
+
console.log(...messages);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
warn(...messages) {
|
|
648
|
+
if (!this.disableLogs) {
|
|
649
|
+
console.warn(...messages);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
error(...messages) {
|
|
653
|
+
if (!this.disableLogs) {
|
|
654
|
+
console.error(...messages);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
debug(...messages) {
|
|
658
|
+
if (this.config.debug && !this.disableLogs) {
|
|
659
|
+
console.debug(...messages);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
|
|
664
|
+
// src/libs/stringify-package.ts
|
|
665
|
+
var DEFAULT_INDENT = 2;
|
|
666
|
+
var CRLF = "\r\n";
|
|
667
|
+
var LF = "\n";
|
|
668
|
+
function stringifyPackage(data, indent, newline) {
|
|
669
|
+
const stringified = JSON.stringify(data, null, indent ?? DEFAULT_INDENT);
|
|
670
|
+
if (newline === CRLF) {
|
|
671
|
+
return stringified.replace(new RegExp(LF, "g"), CRLF);
|
|
672
|
+
}
|
|
673
|
+
return stringified;
|
|
674
|
+
}
|
|
675
|
+
function fileExists(filePath) {
|
|
676
|
+
try {
|
|
677
|
+
return fs.lstatSync(filePath).isFile();
|
|
678
|
+
} catch (_error) {
|
|
679
|
+
return false;
|
|
680
|
+
}
|
|
641
681
|
}
|
|
682
|
+
|
|
683
|
+
// src/strategies/json-package.ts
|
|
684
|
+
var JSONPackage = class {
|
|
685
|
+
constructor(config, logger) {
|
|
686
|
+
this.config = config;
|
|
687
|
+
this.logger = logger;
|
|
688
|
+
}
|
|
689
|
+
read(fileName) {
|
|
690
|
+
const filePath = path.resolve(this.config.path, fileName);
|
|
691
|
+
if (fileExists(filePath)) {
|
|
692
|
+
const fileContents = fs.readFileSync(filePath, "utf8");
|
|
693
|
+
const parsedJson = JSON.parse(fileContents);
|
|
694
|
+
if (parsedJson.version) {
|
|
695
|
+
return {
|
|
696
|
+
name: fileName,
|
|
697
|
+
path: filePath,
|
|
698
|
+
version: parsedJson.version,
|
|
699
|
+
isPrivate: typeof parsedJson?.private === "boolean" ? parsedJson.private : true
|
|
700
|
+
};
|
|
701
|
+
}
|
|
702
|
+
this.logger.warn(`[File Manager] Unable to determine json package: ${fileName}`);
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
write(fileState, newVersion) {
|
|
706
|
+
const fileContents = fs.readFileSync(fileState.path, "utf8");
|
|
707
|
+
const parsedJson = JSON.parse(fileContents);
|
|
708
|
+
parsedJson.version = newVersion;
|
|
709
|
+
if (parsedJson.packages?.[""]) {
|
|
710
|
+
parsedJson.packages[""].version = newVersion;
|
|
711
|
+
}
|
|
712
|
+
fs.writeFileSync(
|
|
713
|
+
fileState.path,
|
|
714
|
+
stringifyPackage(parsedJson, detectIndent__default.default(fileContents).indent, detectNewline.detectNewline(fileContents)),
|
|
715
|
+
"utf8"
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
isSupportedFile(fileName) {
|
|
719
|
+
return fileName.endsWith(".json");
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
var PlainText = class {
|
|
723
|
+
constructor(config, logger) {
|
|
724
|
+
this.config = config;
|
|
725
|
+
this.logger = logger;
|
|
726
|
+
}
|
|
727
|
+
read(fileName) {
|
|
728
|
+
const filePath = path.resolve(this.config.path, fileName);
|
|
729
|
+
if (fileExists(filePath)) {
|
|
730
|
+
const fileContents = fs.readFileSync(filePath, "utf8");
|
|
731
|
+
return {
|
|
732
|
+
name: fileName,
|
|
733
|
+
path: filePath,
|
|
734
|
+
version: fileContents || ""
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
this.logger.warn(`[File Manager] Unable to determine plain text: ${fileName}`);
|
|
738
|
+
}
|
|
739
|
+
write(fileState, newVersion) {
|
|
740
|
+
fs.writeFileSync(fileState.path, newVersion, "utf8");
|
|
741
|
+
}
|
|
742
|
+
isSupportedFile(fileName) {
|
|
743
|
+
return fileName.endsWith("version.txt");
|
|
744
|
+
}
|
|
745
|
+
};
|
|
746
|
+
var MSBuildProject = class {
|
|
747
|
+
constructor(config, logger) {
|
|
748
|
+
this.config = config;
|
|
749
|
+
this.logger = logger;
|
|
750
|
+
}
|
|
751
|
+
read(fileName) {
|
|
752
|
+
const filePath = path.resolve(this.config.path, fileName);
|
|
753
|
+
if (fileExists(filePath)) {
|
|
754
|
+
const fileContents = fs.readFileSync(filePath, "utf8");
|
|
755
|
+
const $ = cheerio__namespace.load(fileContents, {
|
|
756
|
+
xmlMode: true,
|
|
757
|
+
xml: { decodeEntities: false }
|
|
758
|
+
});
|
|
759
|
+
const version = $("Project > PropertyGroup > Version").text();
|
|
760
|
+
if (version) {
|
|
761
|
+
return {
|
|
762
|
+
name: fileName,
|
|
763
|
+
path: filePath,
|
|
764
|
+
version
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
this.logger.warn(`[File Manager] Unable to determine ms-build package: ${fileName}`);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
write(fileState, newVersion) {
|
|
771
|
+
const fileContents = fs.readFileSync(fileState.path, "utf8");
|
|
772
|
+
const $ = cheerio__namespace.load(fileContents, {
|
|
773
|
+
xmlMode: true,
|
|
774
|
+
xml: { decodeEntities: false }
|
|
775
|
+
});
|
|
776
|
+
$("Project > PropertyGroup > Version").text(newVersion);
|
|
777
|
+
const updatedContent = $.xml().replaceAll('"/>', '" />');
|
|
778
|
+
fs.writeFileSync(fileState.path, updatedContent, "utf8");
|
|
779
|
+
}
|
|
780
|
+
isSupportedFile(fileName) {
|
|
781
|
+
return [".csproj", ".dbproj", ".esproj", ".fsproj", ".props", ".vbproj", ".vcxproj"].findIndex(
|
|
782
|
+
(ext) => fileName.endsWith(ext)
|
|
783
|
+
) !== -1;
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
|
|
787
|
+
// src/strategies/file-manager.ts
|
|
788
|
+
var FileManager = class {
|
|
789
|
+
constructor(config, logger) {
|
|
790
|
+
this.config = config;
|
|
791
|
+
this.logger = logger;
|
|
792
|
+
this.JSONPackage = new JSONPackage(config, logger);
|
|
793
|
+
this.PlainText = new PlainText(config, logger);
|
|
794
|
+
this.MSBuildProject = new MSBuildProject(config, logger);
|
|
795
|
+
}
|
|
796
|
+
JSONPackage;
|
|
797
|
+
PlainText;
|
|
798
|
+
MSBuildProject;
|
|
799
|
+
/**
|
|
800
|
+
* Get the state from the given file name.
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* ```ts
|
|
804
|
+
* fileManager.read("package.json");
|
|
805
|
+
* ```
|
|
806
|
+
*
|
|
807
|
+
* @returns
|
|
808
|
+
* ```json
|
|
809
|
+
* { "name": "package.json", "path": "/path/to/package.json", "version": "1.2.3", "isPrivate": true }
|
|
810
|
+
* ```
|
|
811
|
+
*/
|
|
812
|
+
read(fileName) {
|
|
813
|
+
const _fileName = fileName.toLowerCase();
|
|
814
|
+
if (this.JSONPackage.isSupportedFile(_fileName)) {
|
|
815
|
+
return this.JSONPackage.read(fileName);
|
|
816
|
+
}
|
|
817
|
+
if (this.PlainText.isSupportedFile(_fileName)) {
|
|
818
|
+
return this.PlainText.read(fileName);
|
|
819
|
+
}
|
|
820
|
+
if (this.MSBuildProject.isSupportedFile(_fileName)) {
|
|
821
|
+
return this.MSBuildProject.read(fileName);
|
|
822
|
+
}
|
|
823
|
+
this.logger.error(`[File Manager] Unsupported file: ${fileName}`);
|
|
824
|
+
}
|
|
825
|
+
/**
|
|
826
|
+
* Write the new version to the given file.
|
|
827
|
+
*
|
|
828
|
+
* @example
|
|
829
|
+
* ```ts
|
|
830
|
+
* fileManager.write(
|
|
831
|
+
* { name: "package.json", path: "/path/to/package.json", version: "1.2.2" },
|
|
832
|
+
* "1.2.3"
|
|
833
|
+
* );
|
|
834
|
+
* ```
|
|
835
|
+
*/
|
|
836
|
+
write(fileState, newVersion) {
|
|
837
|
+
if (this.config.dryRun) {
|
|
838
|
+
return;
|
|
839
|
+
}
|
|
840
|
+
const _fileName = fileState.name.toLowerCase();
|
|
841
|
+
if (this.JSONPackage.isSupportedFile(_fileName)) {
|
|
842
|
+
return this.JSONPackage.write(fileState, newVersion);
|
|
843
|
+
}
|
|
844
|
+
if (this.PlainText.isSupportedFile(_fileName)) {
|
|
845
|
+
return this.PlainText.write(fileState, newVersion);
|
|
846
|
+
}
|
|
847
|
+
if (this.MSBuildProject.isSupportedFile(_fileName)) {
|
|
848
|
+
return this.MSBuildProject.write(fileState, newVersion);
|
|
849
|
+
}
|
|
850
|
+
this.logger.error(`[File Manager] Unsupported file: ${fileState.path}`);
|
|
851
|
+
}
|
|
852
|
+
};
|
|
642
853
|
async function getLatestGitTagVersion(tagPrefix) {
|
|
643
854
|
const gitTags = await gitSemverTags__default.default({ tagPrefix });
|
|
644
855
|
if (!gitTags.length) {
|
|
@@ -682,10 +893,10 @@ function getReleaseType(releaseType, currentVersion, preReleaseTag) {
|
|
|
682
893
|
}
|
|
683
894
|
|
|
684
895
|
// src/process/version.ts
|
|
685
|
-
async function getCurrentVersion(config, logger, fileManager) {
|
|
896
|
+
async function getCurrentVersion(config, logger, fileManager, filesToUpdate) {
|
|
686
897
|
const files = [];
|
|
687
898
|
const versions = /* @__PURE__ */ new Set();
|
|
688
|
-
for (const file of
|
|
899
|
+
for (const file of filesToUpdate) {
|
|
689
900
|
const fileState = fileManager.read(file);
|
|
690
901
|
if (fileState) {
|
|
691
902
|
files.push(fileState);
|
|
@@ -751,7 +962,7 @@ async function getNextVersion(config, logger, currentVersion) {
|
|
|
751
962
|
tagPrefix: config.tagPrefix,
|
|
752
963
|
cwd: config.path
|
|
753
964
|
});
|
|
754
|
-
} catch (
|
|
965
|
+
} catch (_error) {
|
|
755
966
|
throw new Error(`[conventional-recommended-bump] Unable to determine next version`);
|
|
756
967
|
}
|
|
757
968
|
if (recommendedBump.releaseType) {
|
|
@@ -775,15 +986,6 @@ async function getNextVersion(config, logger, currentVersion) {
|
|
|
775
986
|
}
|
|
776
987
|
throw new Error("Unable to find next version");
|
|
777
988
|
}
|
|
778
|
-
function fileExists(filePath) {
|
|
779
|
-
try {
|
|
780
|
-
return fs.lstatSync(filePath).isFile();
|
|
781
|
-
} catch (e) {
|
|
782
|
-
return false;
|
|
783
|
-
}
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
// src/process/changelog.ts
|
|
787
989
|
var RELEASE_PATTERN = /(^#+ \[?[0-9]+\.[0-9]+\.[0-9]+|<a name=)/m;
|
|
788
990
|
function getOldReleaseContent(filePath, exists) {
|
|
789
991
|
if (exists) {
|
|
@@ -909,216 +1111,6 @@ async function tagChanges(config, logger, git, nextVersion) {
|
|
|
909
1111
|
);
|
|
910
1112
|
}
|
|
911
1113
|
|
|
912
|
-
// src/libs/stringify-package.ts
|
|
913
|
-
var DEFAULT_INDENT = 2;
|
|
914
|
-
var CRLF = "\r\n";
|
|
915
|
-
var LF = "\n";
|
|
916
|
-
function stringifyPackage(data, indent, newline) {
|
|
917
|
-
const stringified = JSON.stringify(data, null, indent ?? DEFAULT_INDENT);
|
|
918
|
-
if (newline === CRLF) {
|
|
919
|
-
return stringified.replace(new RegExp(LF, "g"), CRLF);
|
|
920
|
-
}
|
|
921
|
-
return stringified;
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
// src/strategies/json-package.ts
|
|
925
|
-
var JSONPackage = class {
|
|
926
|
-
constructor(config, logger) {
|
|
927
|
-
this.config = config;
|
|
928
|
-
this.logger = logger;
|
|
929
|
-
}
|
|
930
|
-
read(fileName) {
|
|
931
|
-
const filePath = path.resolve(this.config.path, fileName);
|
|
932
|
-
if (fileExists(filePath)) {
|
|
933
|
-
const fileContents = fs.readFileSync(filePath, "utf8");
|
|
934
|
-
const parsedJson = JSON.parse(fileContents);
|
|
935
|
-
if (parsedJson.version) {
|
|
936
|
-
return {
|
|
937
|
-
name: fileName,
|
|
938
|
-
path: filePath,
|
|
939
|
-
version: parsedJson.version,
|
|
940
|
-
isPrivate: typeof parsedJson?.private === "boolean" ? parsedJson.private : true
|
|
941
|
-
};
|
|
942
|
-
}
|
|
943
|
-
this.logger.warn(`[File Manager] Unable to determine json package: ${fileName}`);
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
write(fileState, newVersion) {
|
|
947
|
-
const fileContents = fs.readFileSync(fileState.path, "utf8");
|
|
948
|
-
const parsedJson = JSON.parse(fileContents);
|
|
949
|
-
parsedJson.version = newVersion;
|
|
950
|
-
if (parsedJson.packages?.[""]) {
|
|
951
|
-
parsedJson.packages[""].version = newVersion;
|
|
952
|
-
}
|
|
953
|
-
fs.writeFileSync(
|
|
954
|
-
fileState.path,
|
|
955
|
-
stringifyPackage(parsedJson, detectIndent__default.default(fileContents).indent, detectNewline.detectNewline(fileContents)),
|
|
956
|
-
"utf8"
|
|
957
|
-
);
|
|
958
|
-
}
|
|
959
|
-
isSupportedFile(fileName) {
|
|
960
|
-
return fileName.endsWith(".json");
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
var PlainText = class {
|
|
964
|
-
constructor(config, logger) {
|
|
965
|
-
this.config = config;
|
|
966
|
-
this.logger = logger;
|
|
967
|
-
}
|
|
968
|
-
read(fileName) {
|
|
969
|
-
const filePath = path.resolve(this.config.path, fileName);
|
|
970
|
-
if (fileExists(filePath)) {
|
|
971
|
-
const fileContents = fs.readFileSync(filePath, "utf8");
|
|
972
|
-
return {
|
|
973
|
-
name: fileName,
|
|
974
|
-
path: filePath,
|
|
975
|
-
version: fileContents || ""
|
|
976
|
-
};
|
|
977
|
-
}
|
|
978
|
-
this.logger.warn(`[File Manager] Unable to determine plain text: ${fileName}`);
|
|
979
|
-
}
|
|
980
|
-
write(fileState, newVersion) {
|
|
981
|
-
fs.writeFileSync(fileState.path, newVersion, "utf8");
|
|
982
|
-
}
|
|
983
|
-
isSupportedFile(fileName) {
|
|
984
|
-
return fileName.endsWith("version.txt");
|
|
985
|
-
}
|
|
986
|
-
};
|
|
987
|
-
var MSBuildProject = class {
|
|
988
|
-
constructor(config, logger) {
|
|
989
|
-
this.config = config;
|
|
990
|
-
this.logger = logger;
|
|
991
|
-
}
|
|
992
|
-
read(fileName) {
|
|
993
|
-
const filePath = path.resolve(this.config.path, fileName);
|
|
994
|
-
if (fileExists(filePath)) {
|
|
995
|
-
const fileContents = fs.readFileSync(filePath, "utf8");
|
|
996
|
-
const $ = cheerio__namespace.load(fileContents, { xmlMode: true, decodeEntities: false });
|
|
997
|
-
const version = $("Project > PropertyGroup > Version").text();
|
|
998
|
-
if (version) {
|
|
999
|
-
return {
|
|
1000
|
-
name: fileName,
|
|
1001
|
-
path: filePath,
|
|
1002
|
-
version
|
|
1003
|
-
};
|
|
1004
|
-
}
|
|
1005
|
-
this.logger.warn(`[File Manager] Unable to determine ms-build package: ${fileName}`);
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
write(fileState, newVersion) {
|
|
1009
|
-
const fileContents = fs.readFileSync(fileState.path, "utf8");
|
|
1010
|
-
const $ = cheerio__namespace.load(fileContents, { xmlMode: true, decodeEntities: false });
|
|
1011
|
-
$("Project > PropertyGroup > Version").text(newVersion);
|
|
1012
|
-
const updatedContent = $.xml().replaceAll('"/>', '" />');
|
|
1013
|
-
fs.writeFileSync(fileState.path, updatedContent, "utf8");
|
|
1014
|
-
}
|
|
1015
|
-
isSupportedFile(fileName) {
|
|
1016
|
-
return [".csproj", ".dbproj", ".esproj", ".fsproj", ".props", ".vbproj", ".vcxproj"].findIndex(
|
|
1017
|
-
(ext) => fileName.endsWith(ext)
|
|
1018
|
-
) !== -1;
|
|
1019
|
-
}
|
|
1020
|
-
};
|
|
1021
|
-
|
|
1022
|
-
// src/strategies/file-manager.ts
|
|
1023
|
-
var FileManager = class {
|
|
1024
|
-
constructor(config, logger) {
|
|
1025
|
-
this.config = config;
|
|
1026
|
-
this.logger = logger;
|
|
1027
|
-
this.JSONPackage = new JSONPackage(config, logger);
|
|
1028
|
-
this.PlainText = new PlainText(config, logger);
|
|
1029
|
-
this.MSBuildProject = new MSBuildProject(config, logger);
|
|
1030
|
-
}
|
|
1031
|
-
JSONPackage;
|
|
1032
|
-
PlainText;
|
|
1033
|
-
MSBuildProject;
|
|
1034
|
-
/**
|
|
1035
|
-
* Get the state from the given file name.
|
|
1036
|
-
*
|
|
1037
|
-
* @example
|
|
1038
|
-
* ```ts
|
|
1039
|
-
* fileManager.read("package.json");
|
|
1040
|
-
* ```
|
|
1041
|
-
*
|
|
1042
|
-
* @returns
|
|
1043
|
-
* ```json
|
|
1044
|
-
* { "name": "package.json", "path": "/path/to/package.json", "version": "1.2.3", "isPrivate": true }
|
|
1045
|
-
* ```
|
|
1046
|
-
*/
|
|
1047
|
-
read(fileName) {
|
|
1048
|
-
const _fileName = fileName.toLowerCase();
|
|
1049
|
-
if (this.JSONPackage.isSupportedFile(_fileName)) {
|
|
1050
|
-
return this.JSONPackage.read(fileName);
|
|
1051
|
-
}
|
|
1052
|
-
if (this.PlainText.isSupportedFile(_fileName)) {
|
|
1053
|
-
return this.PlainText.read(fileName);
|
|
1054
|
-
}
|
|
1055
|
-
if (this.MSBuildProject.isSupportedFile(_fileName)) {
|
|
1056
|
-
return this.MSBuildProject.read(fileName);
|
|
1057
|
-
}
|
|
1058
|
-
this.logger.error(`[File Manager] Unsupported file: ${fileName}`);
|
|
1059
|
-
}
|
|
1060
|
-
/**
|
|
1061
|
-
* Write the new version to the given file.
|
|
1062
|
-
*
|
|
1063
|
-
* @example
|
|
1064
|
-
* ```ts
|
|
1065
|
-
* fileManager.write(
|
|
1066
|
-
* { name: "package.json", path: "/path/to/package.json", version: "1.2.2" },
|
|
1067
|
-
* "1.2.3"
|
|
1068
|
-
* );
|
|
1069
|
-
* ```
|
|
1070
|
-
*/
|
|
1071
|
-
write(fileState, newVersion) {
|
|
1072
|
-
if (this.config.dryRun) {
|
|
1073
|
-
return;
|
|
1074
|
-
}
|
|
1075
|
-
const _fileName = fileState.name.toLowerCase();
|
|
1076
|
-
if (this.JSONPackage.isSupportedFile(_fileName)) {
|
|
1077
|
-
return this.JSONPackage.write(fileState, newVersion);
|
|
1078
|
-
}
|
|
1079
|
-
if (this.PlainText.isSupportedFile(_fileName)) {
|
|
1080
|
-
return this.PlainText.write(fileState, newVersion);
|
|
1081
|
-
}
|
|
1082
|
-
if (this.MSBuildProject.isSupportedFile(_fileName)) {
|
|
1083
|
-
return this.MSBuildProject.write(fileState, newVersion);
|
|
1084
|
-
}
|
|
1085
|
-
this.logger.error(`[File Manager] Unsupported file: ${fileState.path}`);
|
|
1086
|
-
}
|
|
1087
|
-
};
|
|
1088
|
-
|
|
1089
|
-
// src/utils/logger.ts
|
|
1090
|
-
var Logger = class {
|
|
1091
|
-
constructor(config) {
|
|
1092
|
-
this.config = config;
|
|
1093
|
-
this.log = this.log.bind(this);
|
|
1094
|
-
this.warn = this.warn.bind(this);
|
|
1095
|
-
this.error = this.error.bind(this);
|
|
1096
|
-
this.debug = this.debug.bind(this);
|
|
1097
|
-
this.disableLogs = this.config.silent || this.config.inspectVersion;
|
|
1098
|
-
}
|
|
1099
|
-
disableLogs = false;
|
|
1100
|
-
log(...messages) {
|
|
1101
|
-
if (!this.disableLogs) {
|
|
1102
|
-
console.log(...messages);
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
warn(...messages) {
|
|
1106
|
-
if (!this.disableLogs) {
|
|
1107
|
-
console.warn(...messages);
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
error(...messages) {
|
|
1111
|
-
if (!this.disableLogs) {
|
|
1112
|
-
console.error(...messages);
|
|
1113
|
-
}
|
|
1114
|
-
}
|
|
1115
|
-
debug(...messages) {
|
|
1116
|
-
if (this.config.debug && !this.disableLogs) {
|
|
1117
|
-
console.debug(...messages);
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
};
|
|
1121
|
-
|
|
1122
1114
|
exports.FileManager = FileManager;
|
|
1123
1115
|
exports.ForkConfigSchema = ForkConfigSchema;
|
|
1124
1116
|
exports.Logger = Logger;
|
|
@@ -1129,5 +1121,5 @@ exports.getNextVersion = getNextVersion;
|
|
|
1129
1121
|
exports.getUserConfig = getUserConfig;
|
|
1130
1122
|
exports.tagChanges = tagChanges;
|
|
1131
1123
|
exports.updateChangelog = updateChangelog;
|
|
1132
|
-
//# sourceMappingURL=
|
|
1133
|
-
//# sourceMappingURL=chunk-
|
|
1124
|
+
//# sourceMappingURL=chunk-6SI2AHBP.cjs.map
|
|
1125
|
+
//# sourceMappingURL=chunk-6SI2AHBP.cjs.map
|