@git.zone/cli 9.2.1 → 10.0.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/assets/templates/asset_binary_installer/install.sh +109 -34
- package/assets/templates/asset_binary_release_gitea/.gitea/workflows/release.yml +20 -6
- package/assets/templates/ci_rust/.gitea/workflows/rust_nottags.yaml +29 -0
- package/assets/templates/ci_rust/.gitea/workflows/rust_tags.yaml +32 -0
- package/assets/templates/gitignore/_gitignore +1 -1
- package/assets/templates/gitignore_rust/_gitignore +31 -0
- package/assets/templates/license_mit/license +4 -1
- package/assets/templates/rust/.smartscaf.yml +16 -0
- package/assets/templates/rust/_Cargo.toml +12 -0
- package/assets/templates/rust/_crate_Cargo.toml +10 -0
- package/assets/templates/rust/_crate_lib.rs +19 -0
- package/assets/templates/rust/_smartconfig.json +27 -0
- package/assets/templates/rust/readme.md +23 -0
- package/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/classes.gitzoneconfig.d.ts +3 -1
- package/dist_ts/classes.gitzoneconfig.js +9 -1
- package/dist_ts/helpers.managedassets.d.ts +1 -1
- package/dist_ts/helpers.managedassets.js +58 -14
- package/dist_ts/helpers.releasetargets.d.ts +6 -0
- package/dist_ts/helpers.releasetargets.js +13 -0
- package/dist_ts/helpers.smartconfigmigrations.js +42 -1
- package/dist_ts/helpers.toolconfig.d.ts +50 -0
- package/dist_ts/helpers.toolconfig.js +212 -0
- package/dist_ts/helpers.tssea.d.ts +9 -2
- package/dist_ts/helpers.tssea.js +47 -17
- package/dist_ts/helpers.tstest.d.ts +27 -8
- package/dist_ts/helpers.tstest.js +64 -26
- package/dist_ts/helpers.versionsource.d.ts +37 -0
- package/dist_ts/helpers.versionsource.js +112 -0
- package/dist_ts/helpers.workflow.d.ts +45 -1
- package/dist_ts/helpers.workflow.js +120 -5
- package/dist_ts/mod_commit/mod.helpers.d.ts +0 -24
- package/dist_ts/mod_commit/mod.helpers.js +1 -94
- package/dist_ts/mod_config/index.js +131 -18
- package/dist_ts/mod_format/formatters/assets.formatter.js +29 -27
- package/dist_ts/mod_format/formatters/gitignore.formatter.d.ts +4 -2
- package/dist_ts/mod_format/formatters/gitignore.formatter.js +10 -7
- package/dist_ts/mod_format/formatters/license.formatter.d.ts +8 -0
- package/dist_ts/mod_format/formatters/license.formatter.js +25 -2
- package/dist_ts/mod_format/formatters/packagejson.formatter.js +14 -3
- package/dist_ts/mod_format/formatters/rustfmt.formatter.d.ts +19 -0
- package/dist_ts/mod_format/formatters/rustfmt.formatter.js +97 -0
- package/dist_ts/mod_format/formatters/smartconfig.formatter.js +5 -2
- package/dist_ts/mod_format/index.js +3 -1
- package/dist_ts/mod_format/interfaces.format.js +2 -1
- package/dist_ts/mod_release/classes.releasejournal.d.ts +38 -2
- package/dist_ts/mod_release/classes.releasejournal.js +238 -66
- package/dist_ts/mod_release/helpers.cargorelease.d.ts +52 -0
- package/dist_ts/mod_release/helpers.cargorelease.js +195 -0
- package/dist_ts/mod_release/helpers.npmpackages.d.ts +18 -0
- package/dist_ts/mod_release/helpers.npmpackages.js +40 -2
- package/dist_ts/mod_release/helpers.releasecheck.d.ts +73 -0
- package/dist_ts/mod_release/helpers.releasecheck.js +269 -0
- package/dist_ts/mod_release/helpers.releasepreparation.d.ts +22 -8
- package/dist_ts/mod_release/helpers.releasepreparation.js +74 -26
- package/dist_ts/mod_release/helpers.releasepublication.d.ts +21 -1
- package/dist_ts/mod_release/helpers.releasepublication.js +249 -4
- package/dist_ts/mod_release/helpers.releaseversionsource.d.ts +10 -0
- package/dist_ts/mod_release/helpers.releaseversionsource.js +18 -0
- package/dist_ts/mod_release/helpers.rsrepoengine.d.ts +192 -0
- package/dist_ts/mod_release/helpers.rsrepoengine.js +457 -0
- package/dist_ts/mod_release/index.d.ts +3 -0
- package/dist_ts/mod_release/index.js +177 -65
- package/dist_ts/mod_template/index.js +6 -2
- package/package.json +1 -1
- package/readme.md +237 -21
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/classes.gitzoneconfig.ts +10 -1
- package/ts/helpers.managedassets.ts +64 -14
- package/ts/helpers.releasetargets.ts +13 -0
- package/ts/helpers.smartconfigmigrations.ts +48 -0
- package/ts/helpers.toolconfig.ts +280 -0
- package/ts/helpers.tssea.ts +59 -16
- package/ts/helpers.tstest.ts +105 -35
- package/ts/helpers.versionsource.ts +169 -0
- package/ts/helpers.workflow.ts +197 -5
- package/ts/mod_commit/mod.helpers.ts +0 -119
- package/ts/mod_config/index.ts +169 -19
- package/ts/mod_format/formatters/assets.formatter.ts +28 -27
- package/ts/mod_format/formatters/gitignore.formatter.ts +10 -6
- package/ts/mod_format/formatters/license.formatter.ts +26 -1
- package/ts/mod_format/formatters/packagejson.formatter.ts +14 -2
- package/ts/mod_format/formatters/rustfmt.formatter.ts +107 -0
- package/ts/mod_format/formatters/smartconfig.formatter.ts +8 -1
- package/ts/mod_format/index.ts +2 -0
- package/ts/mod_format/interfaces.format.ts +1 -0
- package/ts/mod_release/classes.releasejournal.ts +312 -39
- package/ts/mod_release/helpers.cargorelease.ts +289 -0
- package/ts/mod_release/helpers.npmpackages.ts +76 -1
- package/ts/mod_release/helpers.releasecheck.ts +409 -0
- package/ts/mod_release/helpers.releasepreparation.ts +116 -36
- package/ts/mod_release/helpers.releasepublication.ts +462 -1
- package/ts/mod_release/helpers.releaseversionsource.ts +29 -0
- package/ts/mod_release/helpers.rsrepoengine.ts +790 -0
- package/ts/mod_release/index.ts +277 -84
- package/ts/mod_template/index.ts +5 -1
package/ts/helpers.tstest.ts
CHANGED
|
@@ -1,51 +1,115 @@
|
|
|
1
1
|
import * as plugins from "./plugins.js";
|
|
2
|
+
import { readTsrepoToolSection } from "./helpers.toolconfig.js";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
* Resolve the project's own tstest binary. The CLI deliberately does not
|
|
5
|
-
* depend on tstest at runtime: a project that tests already has it, and a
|
|
6
|
-
* project that does not should simply skip the cleanup.
|
|
7
|
-
*/
|
|
8
|
-
export const getProjectTstestBinPath = (
|
|
4
|
+
const getProjectBinPath = (
|
|
9
5
|
projectRootArg: string,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
nameArg: string,
|
|
7
|
+
platformArg: NodeJS.Platform,
|
|
8
|
+
): string =>
|
|
9
|
+
plugins.path.join(
|
|
13
10
|
projectRootArg,
|
|
14
11
|
"node_modules",
|
|
15
12
|
".bin",
|
|
16
|
-
platformArg === "win32" ?
|
|
13
|
+
platformArg === "win32" ? `${nameArg}.CMD` : nameArg,
|
|
17
14
|
);
|
|
18
|
-
};
|
|
19
15
|
|
|
20
|
-
|
|
21
|
-
projectRootArg: string,
|
|
22
|
-
platformArg: NodeJS.Platform = process.platform,
|
|
23
|
-
): Promise<boolean> => {
|
|
16
|
+
const isAccessible = async (pathArg: string): Promise<boolean> => {
|
|
24
17
|
try {
|
|
25
|
-
await plugins.fs.access(
|
|
18
|
+
await plugins.fs.access(pathArg);
|
|
26
19
|
return true;
|
|
27
20
|
} catch {
|
|
28
21
|
return false;
|
|
29
22
|
}
|
|
30
23
|
};
|
|
31
24
|
|
|
25
|
+
/**
|
|
26
|
+
* Resolve the project's own tstest binary. The CLI deliberately does not
|
|
27
|
+
* depend on tstest at runtime: a project that tests already has it, and a
|
|
28
|
+
* project that does not should simply skip the cleanup.
|
|
29
|
+
*/
|
|
30
|
+
export const getProjectTstestBinPath = (
|
|
31
|
+
projectRootArg: string,
|
|
32
|
+
platformArg: NodeJS.Platform = process.platform,
|
|
33
|
+
): string => getProjectBinPath(projectRootArg, "tstest", platformArg);
|
|
34
|
+
|
|
35
|
+
/** The project's own `@git.zone/tsrepo` binary, which carries tstest as `tsrepo test`. */
|
|
36
|
+
export const getProjectTsrepoBinPath = (
|
|
37
|
+
projectRootArg: string,
|
|
38
|
+
platformArg: NodeJS.Platform = process.platform,
|
|
39
|
+
): string => getProjectBinPath(projectRootArg, "tsrepo", platformArg);
|
|
40
|
+
|
|
41
|
+
export const hasInstalledProjectTstestBinary = async (
|
|
42
|
+
projectRootArg: string,
|
|
43
|
+
platformArg: NodeJS.Platform = process.platform,
|
|
44
|
+
): Promise<boolean> =>
|
|
45
|
+
isAccessible(getProjectTstestBinPath(projectRootArg, platformArg));
|
|
46
|
+
|
|
47
|
+
export const hasInstalledProjectTsrepoBinary = async (
|
|
48
|
+
projectRootArg: string,
|
|
49
|
+
platformArg: NodeJS.Platform = process.platform,
|
|
50
|
+
): Promise<boolean> =>
|
|
51
|
+
isAccessible(getProjectTsrepoBinPath(projectRootArg, platformArg));
|
|
52
|
+
|
|
53
|
+
/** The command that removes the project's test artifacts. */
|
|
54
|
+
export interface ITestCleanupCommand {
|
|
55
|
+
tool: "tsrepo" | "tstest";
|
|
56
|
+
binPath: string;
|
|
57
|
+
args: string[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* `tsrepo test clean` when the project installs `@git.zone/tsrepo`, which
|
|
62
|
+
* carries tstest, otherwise its own `tstest clean`. Both are legitimate
|
|
63
|
+
* installs; tsrepo wins when a project has both.
|
|
64
|
+
*/
|
|
65
|
+
export const getProjectTestCleanupCommand = async (
|
|
66
|
+
projectRootArg: string,
|
|
67
|
+
platformArg: NodeJS.Platform = process.platform,
|
|
68
|
+
): Promise<ITestCleanupCommand> =>
|
|
69
|
+
(await hasInstalledProjectTsrepoBinary(projectRootArg, platformArg))
|
|
70
|
+
? {
|
|
71
|
+
tool: "tsrepo",
|
|
72
|
+
binPath: getProjectTsrepoBinPath(projectRootArg, platformArg),
|
|
73
|
+
args: ["test", "clean"],
|
|
74
|
+
}
|
|
75
|
+
: {
|
|
76
|
+
tool: "tstest",
|
|
77
|
+
binPath: getProjectTstestBinPath(projectRootArg, platformArg),
|
|
78
|
+
args: ["clean"],
|
|
79
|
+
};
|
|
80
|
+
|
|
32
81
|
/**
|
|
33
82
|
* Whether the project wants its test artifacts removed as part of a release.
|
|
34
83
|
* Defaults to true; a project opts out with
|
|
35
|
-
* `{"@git.zone/
|
|
84
|
+
* `{"@git.zone/tsrepo": {"test": {"cleanup": {"onRelease": false}}}}`, or the
|
|
85
|
+
* legacy `{"@git.zone/tstest": {"cleanup": {"onRelease": false}}}`. Like
|
|
86
|
+
* tsrepo itself, this refuses a project that carries both sections.
|
|
36
87
|
*/
|
|
37
88
|
export const readTstestCleanupOnRelease = (projectRootArg: string): boolean => {
|
|
89
|
+
let smartconfigData: unknown;
|
|
38
90
|
try {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
);
|
|
42
|
-
const tstestConfig = smartconfigInstance.dataFor<{
|
|
43
|
-
cleanup?: { onRelease?: boolean };
|
|
44
|
-
}>("@git.zone/tstest", {});
|
|
45
|
-
return tstestConfig?.cleanup?.onRelease !== false;
|
|
91
|
+
smartconfigData = new plugins.smartconfig.Smartconfig(projectRootArg)
|
|
92
|
+
.smartconfigJsonData;
|
|
46
93
|
} catch {
|
|
47
94
|
return true;
|
|
48
95
|
}
|
|
96
|
+
if (
|
|
97
|
+
typeof smartconfigData !== "object" ||
|
|
98
|
+
smartconfigData === null ||
|
|
99
|
+
Array.isArray(smartconfigData)
|
|
100
|
+
) {
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
const testConfig = readTsrepoToolSection(
|
|
104
|
+
smartconfigData as Record<string, unknown>,
|
|
105
|
+
"test",
|
|
106
|
+
);
|
|
107
|
+
const cleanup = testConfig?.cleanup;
|
|
108
|
+
return !(
|
|
109
|
+
typeof cleanup === "object" &&
|
|
110
|
+
cleanup !== null &&
|
|
111
|
+
(cleanup as { onRelease?: unknown }).onRelease === false
|
|
112
|
+
);
|
|
49
113
|
};
|
|
50
114
|
|
|
51
115
|
/** First tstest version that understands the `clean` subcommand. */
|
|
@@ -91,10 +155,11 @@ export const readProjectTstestVersion = async (
|
|
|
91
155
|
};
|
|
92
156
|
|
|
93
157
|
/**
|
|
94
|
-
* True when a release should
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
158
|
+
* True when a release should clean the project's test artifacts: the project
|
|
159
|
+
* has not opted out, and it installs tsrepo (every tsrepo has `tsrepo test
|
|
160
|
+
* clean`) or a tstest at a version that understands `tstest clean`. An older
|
|
161
|
+
* tstest would treat `clean` as a test path, so it is deliberately skipped
|
|
162
|
+
* rather than invoked.
|
|
98
163
|
*/
|
|
99
164
|
export const shouldCleanTestArtifactsOnRelease = async (
|
|
100
165
|
projectRootArg: string,
|
|
@@ -102,6 +167,9 @@ export const shouldCleanTestArtifactsOnRelease = async (
|
|
|
102
167
|
if (!readTstestCleanupOnRelease(projectRootArg)) {
|
|
103
168
|
return false;
|
|
104
169
|
}
|
|
170
|
+
if (await hasInstalledProjectTsrepoBinary(projectRootArg)) {
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
105
173
|
if (!(await hasInstalledProjectTstestBinary(projectRootArg))) {
|
|
106
174
|
return false;
|
|
107
175
|
}
|
|
@@ -114,26 +182,28 @@ export const shellQuote = (valueArg: string): string =>
|
|
|
114
182
|
`'${valueArg.replaceAll("'", `'\\''`)}'`;
|
|
115
183
|
|
|
116
184
|
/**
|
|
117
|
-
* Run the project's `
|
|
118
|
-
* reported and swallowed rather than failing an
|
|
185
|
+
* Run the project's `tsrepo test clean`, or its `tstest clean`. Cleanup is
|
|
186
|
+
* housekeeping, so a failure is reported and swallowed rather than failing an
|
|
187
|
+
* otherwise complete release.
|
|
119
188
|
*/
|
|
120
|
-
export const
|
|
189
|
+
export const runTestArtifactCleanup = async (
|
|
121
190
|
smartshellArg: plugins.smartshell.Smartshell,
|
|
122
191
|
projectRootArg: string,
|
|
123
192
|
): Promise<void> => {
|
|
124
|
-
const
|
|
193
|
+
const command = await getProjectTestCleanupCommand(projectRootArg);
|
|
194
|
+
const label = `${command.tool} ${command.args.join(" ")}`;
|
|
125
195
|
console.log("cleaning test artifacts");
|
|
126
196
|
try {
|
|
127
197
|
// Quoted: a project path may contain spaces or shell metacharacters.
|
|
128
198
|
const execResult = await smartshellArg.exec(
|
|
129
|
-
`cd ${shellQuote(projectRootArg)} && ${shellQuote(
|
|
199
|
+
`cd ${shellQuote(projectRootArg)} && ${[command.binPath, ...command.args].map(shellQuote).join(" ")}`,
|
|
130
200
|
);
|
|
131
201
|
if (execResult.exitCode !== 0) {
|
|
132
202
|
console.error(
|
|
133
|
-
|
|
203
|
+
`${label} exited with ${execResult.exitCode}; leaving test artifacts in place`,
|
|
134
204
|
);
|
|
135
205
|
}
|
|
136
206
|
} catch (error) {
|
|
137
|
-
console.error(
|
|
207
|
+
console.error(`${label} failed: ${error}`);
|
|
138
208
|
}
|
|
139
209
|
};
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import * as plugins from "./plugins.js";
|
|
2
|
+
import type { IRsrepoEngineClient } from "./mod_release/helpers.rsrepoengine.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where a project keeps the version gitzone releases:
|
|
6
|
+
* - `npm`: package.json.
|
|
7
|
+
* - `npm+internal-rust`: package.json; the crates of its `rust/` or `ts_rust/`
|
|
8
|
+
* workspace keep their own versions.
|
|
9
|
+
* - `cargo`: the Cargo workspace (`projectType: "rust"`), read and written
|
|
10
|
+
* only through the rsrepo engine (`plan` and `set-version`).
|
|
11
|
+
*/
|
|
12
|
+
export type TVersionSourceKind = "npm" | "npm+internal-rust" | "cargo";
|
|
13
|
+
|
|
14
|
+
export interface IVersionSource {
|
|
15
|
+
kind: TVersionSourceKind;
|
|
16
|
+
/** The project directory the source reads and writes. */
|
|
17
|
+
cwd: string;
|
|
18
|
+
/** What carries the version, for messages. */
|
|
19
|
+
description: string;
|
|
20
|
+
/** `00_commitinfo_data.ts` is baked only into TypeScript projects. */
|
|
21
|
+
bakesCommitInfo: boolean;
|
|
22
|
+
readCurrentVersion: () => Promise<string>;
|
|
23
|
+
/** Writes the version and returns the changed files, relative to the workspace root. */
|
|
24
|
+
writeVersion: (versionArg: string) => Promise<string[]>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const fileExists = async (pathArg: string): Promise<boolean> => {
|
|
28
|
+
try {
|
|
29
|
+
return (await plugins.fs.stat(pathArg)).isFile();
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return false;
|
|
32
|
+
throw error;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/** Internal Rust workspaces of a TypeScript package, as tsrust lays them out. */
|
|
37
|
+
export const internalRustWorkspaceDirectories = ["rust", "ts_rust"] as const;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The version source of a project: Cargo for `projectType: "rust"`, otherwise
|
|
41
|
+
* package.json, which a TypeScript project with an internal Rust workspace
|
|
42
|
+
* shares with nothing.
|
|
43
|
+
*/
|
|
44
|
+
export const detectVersionSourceKind = async (
|
|
45
|
+
cwdArg: string,
|
|
46
|
+
projectTypeArg: unknown,
|
|
47
|
+
): Promise<TVersionSourceKind> => {
|
|
48
|
+
if (projectTypeArg === "rust") return "cargo";
|
|
49
|
+
if (!(await fileExists(plugins.path.join(cwdArg, "package.json")))) {
|
|
50
|
+
if (await fileExists(plugins.path.join(cwdArg, "Cargo.toml"))) {
|
|
51
|
+
throw new Error(
|
|
52
|
+
`${cwdArg} has a Cargo.toml and no package.json: set @git.zone/cli.projectType to "rust" so gitzone versions the Cargo workspace.`,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
throw new Error(
|
|
56
|
+
`No package.json found in ${cwdArg}: gitzone commit and release version the package.json, or the Cargo workspace of projectType "rust".`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
for (const directory of internalRustWorkspaceDirectories) {
|
|
60
|
+
if (await fileExists(plugins.path.join(cwdArg, directory, "Cargo.toml"))) {
|
|
61
|
+
return "npm+internal-rust";
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return "npm";
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/** The project's projectType, read from the `.smartconfig.json` in `cwdArg`. */
|
|
68
|
+
export const readProjectType = (cwdArg: string): unknown => {
|
|
69
|
+
const smartconfigInstance = new plugins.smartconfig.Smartconfig(cwdArg);
|
|
70
|
+
const cliConfig = smartconfigInstance.dataFor<{ projectType?: unknown }>(
|
|
71
|
+
"@git.zone/cli",
|
|
72
|
+
{},
|
|
73
|
+
);
|
|
74
|
+
return cliConfig?.projectType;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const packageJsonVersionSource = (
|
|
78
|
+
kindArg: "npm" | "npm+internal-rust",
|
|
79
|
+
cwdArg: string,
|
|
80
|
+
): IVersionSource => {
|
|
81
|
+
const packageJsonPath = plugins.path.join(cwdArg, "package.json");
|
|
82
|
+
const readPackageJson = async (): Promise<Record<string, unknown>> => {
|
|
83
|
+
let content: string;
|
|
84
|
+
try {
|
|
85
|
+
content = await plugins.fs.readFile(packageJsonPath, "utf8");
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") {
|
|
88
|
+
throw new Error(
|
|
89
|
+
`No package.json found in ${cwdArg}: gitzone commit and release version the package.json.`,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
throw error;
|
|
93
|
+
}
|
|
94
|
+
const parsed: unknown = JSON.parse(content);
|
|
95
|
+
if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
|
|
96
|
+
throw new Error(`${packageJsonPath} must contain a JSON object.`);
|
|
97
|
+
}
|
|
98
|
+
return parsed as Record<string, unknown>;
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
kind: kindArg,
|
|
102
|
+
cwd: cwdArg,
|
|
103
|
+
description:
|
|
104
|
+
kindArg === "npm"
|
|
105
|
+
? "package.json"
|
|
106
|
+
: "package.json (internal crates keep their own versions)",
|
|
107
|
+
bakesCommitInfo: true,
|
|
108
|
+
readCurrentVersion: async () => {
|
|
109
|
+
const version = (await readPackageJson()).version;
|
|
110
|
+
if (typeof version !== "string" || !version) {
|
|
111
|
+
throw new Error("package.json does not contain a version field");
|
|
112
|
+
}
|
|
113
|
+
return version;
|
|
114
|
+
},
|
|
115
|
+
writeVersion: async (versionArg) => {
|
|
116
|
+
const packageJson = await readPackageJson();
|
|
117
|
+
packageJson.version = versionArg;
|
|
118
|
+
await plugins.fs.writeFile(
|
|
119
|
+
packageJsonPath,
|
|
120
|
+
`${JSON.stringify(packageJson, null, 2)}\n`,
|
|
121
|
+
"utf8",
|
|
122
|
+
);
|
|
123
|
+
return ["package.json"];
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const cargoVersionSource = (
|
|
129
|
+
cwdArg: string,
|
|
130
|
+
engineArg: IRsrepoEngineClient,
|
|
131
|
+
): IVersionSource => ({
|
|
132
|
+
kind: "cargo",
|
|
133
|
+
cwd: cwdArg,
|
|
134
|
+
description: "the Cargo workspace version",
|
|
135
|
+
bakesCommitInfo: false,
|
|
136
|
+
readCurrentVersion: async () => {
|
|
137
|
+
const plan = await engineArg.plan({ cwd: cwdArg, registries: [] });
|
|
138
|
+
if (plan.layout !== "root") {
|
|
139
|
+
throw new Error(
|
|
140
|
+
`projectType "rust" versions a Cargo workspace at the repository root; rsrepo found the ${plan.layout}/ layout.`,
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (plan.version === null) {
|
|
144
|
+
throw new Error(
|
|
145
|
+
"The Cargo workspace versions its crates independently. gitzone releases one shared version: move the members to [workspace.package] version and `version.workspace = true`.",
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
return plan.version;
|
|
149
|
+
},
|
|
150
|
+
writeVersion: async (versionArg) =>
|
|
151
|
+
(await engineArg.setVersion({ cwd: cwdArg, version: versionArg }))
|
|
152
|
+
.changedFiles,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Opens the version source of `kindArg`. A Cargo source needs the project's
|
|
157
|
+
* rsrepo engine; a package.json source never runs it.
|
|
158
|
+
*/
|
|
159
|
+
export const openVersionSource = (
|
|
160
|
+
kindArg: TVersionSourceKind,
|
|
161
|
+
cwdArg: string,
|
|
162
|
+
engineArg?: IRsrepoEngineClient,
|
|
163
|
+
): IVersionSource => {
|
|
164
|
+
if (kindArg !== "cargo") return packageJsonVersionSource(kindArg, cwdArg);
|
|
165
|
+
if (!engineArg) {
|
|
166
|
+
throw new Error("The Cargo version source requires the rsrepo engine.");
|
|
167
|
+
}
|
|
168
|
+
return cargoVersionSource(cwdArg, engineArg);
|
|
169
|
+
};
|