@git.zone/cli 8.10.1 → 9.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_deno_binary_installer → asset_binary_installer}/install.sh +2 -2
- package/assets/templates/{asset_deno_binary_postinstall → asset_binary_postinstall}/bin/wrapper.js +2 -2
- package/assets/templates/{asset_deno_binary_postinstall → asset_binary_postinstall}/scripts/install-binary.js +2 -2
- package/assets/templates/asset_binary_release_gitea/.gitea/workflows/release.yml +180 -0
- package/assets/templates/asset_tspack_release_gitea/.gitea/workflows/release.yml +7 -4
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.d.mts +9 -3
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-gitea-tag.mjs +50 -6
- package/assets/templates/asset_tspack_release_gitea/scripts/gitzone-release-api.mjs +7 -6
- package/dist_ts/00_commitinfo_data.js +2 -2
- package/dist_ts/helpers.managedassets.d.ts +44 -0
- package/dist_ts/helpers.managedassets.js +166 -0
- package/dist_ts/helpers.ownerscopes.d.ts +4 -16
- package/dist_ts/helpers.ownerscopes.js +5 -16
- package/dist_ts/helpers.packagefiles.d.ts +2 -1
- package/dist_ts/helpers.packagefiles.js +7 -4
- package/dist_ts/helpers.sealedrelease.js +3 -3
- package/dist_ts/helpers.tssea.d.ts +11 -0
- package/dist_ts/helpers.tssea.js +81 -0
- package/dist_ts/helpers.workflow.d.ts +2 -3
- package/dist_ts/helpers.workflow.js +9 -19
- package/dist_ts/index.d.ts +1 -1
- package/dist_ts/index.js +2 -2
- package/dist_ts/mod_commit/mod.helpers.d.ts +8 -21
- package/dist_ts/mod_commit/mod.helpers.js +32 -83
- package/dist_ts/mod_commit/mod.ui.js +1 -5
- package/dist_ts/mod_config/index.js +41 -33
- package/dist_ts/mod_format/formatters/assets.formatter.js +42 -92
- package/dist_ts/mod_format/formatters/packagejson.formatter.js +3 -3
- package/dist_ts/mod_format/index.js +30 -11
- package/dist_ts/mod_format/interfaces.format.js +1 -2
- package/dist_ts/mod_release/classes.releasejournal.d.ts +63 -2
- package/dist_ts/mod_release/classes.releasejournal.js +247 -48
- package/dist_ts/mod_release/helpers.giteaassets.js +18 -9
- package/dist_ts/mod_release/helpers.releasepreparation.d.ts +6 -14
- package/dist_ts/mod_release/helpers.releasepreparation.js +27 -53
- package/dist_ts/mod_release/index.js +108 -13
- package/dist_ts/mod_services/classes.serviceconfiguration.d.ts +2 -2
- package/dist_ts/mod_services/classes.serviceoptions.d.ts +2 -2
- package/dist_ts/plugins.d.ts +3 -1
- package/dist_ts/plugins.js +4 -2
- package/package.json +3 -2
- package/readme.md +153 -74
- package/ts/00_commitinfo_data.ts +1 -1
- package/ts/helpers.managedassets.ts +215 -0
- package/ts/helpers.ownerscopes.ts +4 -15
- package/ts/helpers.packagefiles.ts +6 -3
- package/ts/helpers.sealedrelease.ts +2 -2
- package/ts/helpers.tssea.ts +102 -0
- package/ts/helpers.workflow.ts +12 -28
- package/ts/index.ts +1 -1
- package/ts/mod_commit/mod.helpers.ts +33 -94
- package/ts/mod_commit/mod.ui.ts +0 -4
- package/ts/mod_config/index.ts +47 -35
- package/ts/mod_format/formatters/assets.formatter.ts +47 -108
- package/ts/mod_format/formatters/packagejson.formatter.ts +2 -2
- package/ts/mod_format/index.ts +36 -10
- package/ts/mod_format/interfaces.format.ts +0 -1
- package/ts/mod_release/classes.releasejournal.ts +323 -52
- package/ts/mod_release/helpers.giteaassets.ts +19 -10
- package/ts/mod_release/helpers.releasepreparation.ts +36 -69
- package/ts/mod_release/index.ts +138 -18
- package/ts/mod_services/classes.serviceconfiguration.ts +2 -2
- package/ts/mod_services/classes.serviceoptions.ts +2 -2
- package/ts/plugins.ts +4 -0
- package/assets/templates/asset_deno_binary_release_gitea/.gitea/workflows/release.yml +0 -154
- package/assets/templates/multienv/deno.json +0 -8
- package/dist_ts/mod_format/formatters/deno.formatter.d.ts +0 -18
- package/dist_ts/mod_format/formatters/deno.formatter.js +0 -175
- package/ts/mod_format/formatters/deno.formatter.ts +0 -219
|
@@ -3,7 +3,6 @@ import * as paths from '../paths.js';
|
|
|
3
3
|
import { logger } from '../gitzone.logging.js';
|
|
4
4
|
import * as ui from './mod.ui.js';
|
|
5
5
|
|
|
6
|
-
export type ProjectType = 'npm' | 'deno' | 'both' | 'none';
|
|
7
6
|
export type VersionType = 'patch' | 'minor' | 'major';
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -33,39 +32,6 @@ export async function detectCurrentBranch(): Promise<string> {
|
|
|
33
32
|
}
|
|
34
33
|
}
|
|
35
34
|
|
|
36
|
-
/**
|
|
37
|
-
* Detects the project type based on presence of package.json and/or deno.json
|
|
38
|
-
* @returns The project type
|
|
39
|
-
*/
|
|
40
|
-
export async function detectProjectType(cwdArg = paths.cwd): Promise<ProjectType> {
|
|
41
|
-
const packageJsonPath = plugins.path.join(cwdArg, 'package.json');
|
|
42
|
-
const denoJsonPath = plugins.path.join(cwdArg, 'deno.json');
|
|
43
|
-
|
|
44
|
-
const hasPackageJson = await plugins.smartfs.file(packageJsonPath).exists();
|
|
45
|
-
const hasDenoJson = await plugins.smartfs.file(denoJsonPath).exists();
|
|
46
|
-
|
|
47
|
-
if (hasPackageJson && hasDenoJson) {
|
|
48
|
-
logger.log('info', 'Detected dual project (npm + deno)');
|
|
49
|
-
return 'both';
|
|
50
|
-
} else if (hasPackageJson) {
|
|
51
|
-
logger.log('info', 'Detected npm project');
|
|
52
|
-
return 'npm';
|
|
53
|
-
} else if (hasDenoJson) {
|
|
54
|
-
logger.log('info', 'Detected deno project');
|
|
55
|
-
return 'deno';
|
|
56
|
-
} else {
|
|
57
|
-
throw new Error('No package.json or deno.json found in current directory');
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* A pnpm lockfile, `pnpm install` and `pnpm pack` belong to a project's
|
|
63
|
-
* package.json, so every npm-shaped decision asks this one question.
|
|
64
|
-
*/
|
|
65
|
-
export const projectTypeHasPackageJson = (
|
|
66
|
-
projectTypeArg: ProjectType,
|
|
67
|
-
): boolean => projectTypeArg === 'npm' || projectTypeArg === 'both';
|
|
68
|
-
|
|
69
35
|
/**
|
|
70
36
|
* Parses a semantic version string and bumps it according to the version type
|
|
71
37
|
* @param currentVersion Current version string (e.g., "1.2.3")
|
|
@@ -100,43 +66,37 @@ export function calculateNewVersion(currentVersion: string, versionType: Version
|
|
|
100
66
|
}
|
|
101
67
|
|
|
102
68
|
/**
|
|
103
|
-
*
|
|
104
|
-
|
|
69
|
+
* The project's package.json, which carries the version gitzone commit and release own.
|
|
70
|
+
*/
|
|
71
|
+
const packageJsonPathIn = async (cwdArg: string): Promise<string> => {
|
|
72
|
+
const packageJsonPath = plugins.path.join(cwdArg, 'package.json');
|
|
73
|
+
if (!(await plugins.smartfs.file(packageJsonPath).exists())) {
|
|
74
|
+
throw new Error(
|
|
75
|
+
`No package.json found in ${cwdArg}: gitzone commit and release version the package.json.`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return packageJsonPath;
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Reads the current version from package.json
|
|
105
83
|
* @returns The current version string
|
|
106
84
|
*/
|
|
107
|
-
export async function readCurrentVersion(
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
)
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
.read()) as string;
|
|
117
|
-
const packageJson = JSON.parse(content) as { version?: string };
|
|
118
|
-
|
|
119
|
-
if (!packageJson.version) {
|
|
120
|
-
throw new Error('package.json does not contain a version field');
|
|
121
|
-
}
|
|
122
|
-
return packageJson.version;
|
|
123
|
-
} else {
|
|
124
|
-
const denoJsonPath = plugins.path.join(cwdArg, 'deno.json');
|
|
125
|
-
const content = (await plugins.smartfs
|
|
126
|
-
.file(denoJsonPath)
|
|
127
|
-
.encoding('utf8')
|
|
128
|
-
.read()) as string;
|
|
129
|
-
const denoConfig = JSON.parse(content) as { version?: string };
|
|
130
|
-
|
|
131
|
-
if (!denoConfig.version) {
|
|
132
|
-
throw new Error('deno.json does not contain a version field');
|
|
133
|
-
}
|
|
134
|
-
return denoConfig.version;
|
|
85
|
+
export async function readCurrentVersion(cwdArg = paths.cwd): Promise<string> {
|
|
86
|
+
const content = (await plugins.smartfs
|
|
87
|
+
.file(await packageJsonPathIn(cwdArg))
|
|
88
|
+
.encoding('utf8')
|
|
89
|
+
.read()) as string;
|
|
90
|
+
const packageJson = JSON.parse(content) as { version?: string };
|
|
91
|
+
|
|
92
|
+
if (!packageJson.version) {
|
|
93
|
+
throw new Error('package.json does not contain a version field');
|
|
135
94
|
}
|
|
95
|
+
return packageJson.version;
|
|
136
96
|
}
|
|
137
97
|
|
|
138
98
|
/**
|
|
139
|
-
* Updates the version field in a JSON file
|
|
99
|
+
* Updates the version field in a JSON file
|
|
140
100
|
* @param filePath Path to the JSON file
|
|
141
101
|
* @param newVersion The new version to write
|
|
142
102
|
*/
|
|
@@ -154,51 +114,30 @@ export async function updateVersionFile(filePath: string, newVersion: string): P
|
|
|
154
114
|
}
|
|
155
115
|
|
|
156
116
|
/**
|
|
157
|
-
* Updates
|
|
117
|
+
* Updates the package.json version without creating commits or tags.
|
|
118
|
+
* @returns The updated files, relative to `cwdArg`
|
|
158
119
|
*/
|
|
159
120
|
export async function updateProjectVersionFiles(
|
|
160
|
-
projectType: ProjectType,
|
|
161
121
|
newVersion: string,
|
|
162
122
|
cwdArg = paths.cwd,
|
|
163
123
|
): Promise<string[]> {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const denoJsonPath = plugins.path.join(cwdArg, 'deno.json');
|
|
167
|
-
|
|
168
|
-
if (projectType === 'npm' || projectType === 'both') {
|
|
169
|
-
await updateVersionFile(packageJsonPath, newVersion);
|
|
170
|
-
filesToUpdate.push('package.json');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
if (projectType === 'deno' || projectType === 'both') {
|
|
174
|
-
await updateVersionFile(denoJsonPath, newVersion);
|
|
175
|
-
filesToUpdate.push('deno.json');
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
return filesToUpdate;
|
|
124
|
+
await updateVersionFile(await packageJsonPathIn(cwdArg), newVersion);
|
|
125
|
+
return ['package.json'];
|
|
179
126
|
}
|
|
180
127
|
|
|
181
128
|
/**
|
|
182
|
-
* Bumps the
|
|
183
|
-
* Handles npm-only, deno-only, and dual projects with unified logic
|
|
184
|
-
* @param projectType The detected project type
|
|
129
|
+
* Bumps the package.json version, then commits and tags it
|
|
185
130
|
* @param versionType The type of version bump
|
|
186
131
|
* @param currentStep The current step number for progress display
|
|
187
132
|
* @param totalSteps The total number of steps for progress display
|
|
188
133
|
* @returns The new version string
|
|
189
134
|
*/
|
|
190
135
|
export async function bumpProjectVersion(
|
|
191
|
-
projectType: ProjectType,
|
|
192
136
|
versionType: VersionType,
|
|
193
137
|
currentStep?: number,
|
|
194
138
|
totalSteps?: number
|
|
195
139
|
): Promise<string> {
|
|
196
|
-
|
|
197
|
-
throw new Error('Cannot bump version: no package.json or deno.json found');
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const projectEmoji = projectType === 'npm' ? '📦' : projectType === 'deno' ? '🦕' : '🔀';
|
|
201
|
-
const description = `🏷️ Bumping version (${projectEmoji} ${projectType})`;
|
|
140
|
+
const description = '🏷️ Bumping version (📦 package.json)';
|
|
202
141
|
|
|
203
142
|
if (currentStep && totalSteps) {
|
|
204
143
|
ui.printStep(currentStep, totalSteps, description, 'in-progress');
|
|
@@ -211,7 +150,7 @@ export async function bumpProjectVersion(
|
|
|
211
150
|
|
|
212
151
|
try {
|
|
213
152
|
// 1. Read current version
|
|
214
|
-
const currentVersion = await readCurrentVersion(
|
|
153
|
+
const currentVersion = await readCurrentVersion();
|
|
215
154
|
|
|
216
155
|
// 2. Calculate new version (reuse existing function!)
|
|
217
156
|
const newVersion = calculateNewVersion(currentVersion, versionType);
|
|
@@ -219,7 +158,7 @@ export async function bumpProjectVersion(
|
|
|
219
158
|
logger.log('info', `Bumping version: ${currentVersion} → ${newVersion}`);
|
|
220
159
|
|
|
221
160
|
// 3. Determine which files to update
|
|
222
|
-
const filesToUpdate = await updateProjectVersionFiles(
|
|
161
|
+
const filesToUpdate = await updateProjectVersionFiles(newVersion);
|
|
223
162
|
|
|
224
163
|
// 4. Stage all updated files
|
|
225
164
|
await smartshellInstance.exec(`git add ${filesToUpdate.join(' ')}`);
|
package/ts/mod_commit/mod.ui.ts
CHANGED
|
@@ -163,10 +163,6 @@ function getProjectTypeEmoji(projectType: string): string {
|
|
|
163
163
|
switch (projectType) {
|
|
164
164
|
case 'npm':
|
|
165
165
|
return '📦 npm';
|
|
166
|
-
case 'deno':
|
|
167
|
-
return '🦕 Deno';
|
|
168
|
-
case 'both':
|
|
169
|
-
return '🔀 npm + Deno';
|
|
170
166
|
default:
|
|
171
167
|
return '❓ Unknown';
|
|
172
168
|
}
|
package/ts/mod_config/index.ts
CHANGED
|
@@ -44,6 +44,11 @@ import {
|
|
|
44
44
|
type IReleasePrerelease,
|
|
45
45
|
} from "../mod_release/helpers.releaseversion.js";
|
|
46
46
|
import { getSealedReleaseConfigError } from "../helpers.sealedrelease.js";
|
|
47
|
+
import {
|
|
48
|
+
getManagedAssetsMigrationErrors,
|
|
49
|
+
managedAssetKinds,
|
|
50
|
+
readBinaryBuild,
|
|
51
|
+
} from "../helpers.managedassets.js";
|
|
47
52
|
import {
|
|
48
53
|
getReleaseDockerAliasPolicy,
|
|
49
54
|
latestDistTag,
|
|
@@ -1257,6 +1262,22 @@ async function validatePackageFilesConfig(
|
|
|
1257
1262
|
});
|
|
1258
1263
|
return;
|
|
1259
1264
|
}
|
|
1265
|
+
// The binary set derives from the managed assets, whose removed keys the
|
|
1266
|
+
// managed assets findings already name once each.
|
|
1267
|
+
const assets = isPlainObject(cliConfig.assets) ? cliConfig.assets : undefined;
|
|
1268
|
+
if (
|
|
1269
|
+
assets &&
|
|
1270
|
+
assets.enabled !== false &&
|
|
1271
|
+
getManagedAssetsMigrationErrors(assets).length > 0
|
|
1272
|
+
) {
|
|
1273
|
+
findings.push({
|
|
1274
|
+
level: "warn",
|
|
1275
|
+
message:
|
|
1276
|
+
"package.json files is not checked while @git.zone/cli.assets uses removed keys",
|
|
1277
|
+
fix: "Migrate @git.zone/cli.assets first; the managed assets findings name each removed key.",
|
|
1278
|
+
});
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1260
1281
|
let packageJson: Record<string, any>;
|
|
1261
1282
|
try {
|
|
1262
1283
|
packageJson = await readPackageJson();
|
|
@@ -2200,6 +2221,17 @@ async function validateAssetsConfig(
|
|
|
2200
2221
|
findings.push({ level: "ok", message: "Managed assets are disabled" });
|
|
2201
2222
|
return;
|
|
2202
2223
|
}
|
|
2224
|
+
const migrationErrors = getManagedAssetsMigrationErrors(rawAssetsConfig);
|
|
2225
|
+
if (migrationErrors.length > 0) {
|
|
2226
|
+
for (const message of migrationErrors) {
|
|
2227
|
+
findings.push({
|
|
2228
|
+
level: "error",
|
|
2229
|
+
message,
|
|
2230
|
+
fix: "Migrate @git.zone/cli.assets as the message says.",
|
|
2231
|
+
});
|
|
2232
|
+
}
|
|
2233
|
+
return;
|
|
2234
|
+
}
|
|
2203
2235
|
if (rawAssetsConfig.kind === "tspackRelease") {
|
|
2204
2236
|
const error = getSealedReleaseConfigError(rawAssetsConfig.sealedRelease);
|
|
2205
2237
|
findings.push(
|
|
@@ -2217,11 +2249,11 @@ async function validateAssetsConfig(
|
|
|
2217
2249
|
);
|
|
2218
2250
|
return;
|
|
2219
2251
|
}
|
|
2220
|
-
if (rawAssetsConfig.kind !== "
|
|
2252
|
+
if (rawAssetsConfig.kind !== "binaryCli") {
|
|
2221
2253
|
findings.push({
|
|
2222
2254
|
level: "error",
|
|
2223
2255
|
message: `Unsupported managed asset kind: ${formatValue(rawAssetsConfig.kind)}`,
|
|
2224
|
-
fix:
|
|
2256
|
+
fix: `Use kind ${managedAssetKinds.join(" or ")}, or disable managed assets.`,
|
|
2225
2257
|
});
|
|
2226
2258
|
return;
|
|
2227
2259
|
}
|
|
@@ -2230,35 +2262,27 @@ async function validateAssetsConfig(
|
|
|
2230
2262
|
if (typeof cliName !== "string" || !cliName.trim()) {
|
|
2231
2263
|
findings.push({
|
|
2232
2264
|
level: "error",
|
|
2233
|
-
message: "
|
|
2265
|
+
message: "binaryCli assets require cliName",
|
|
2234
2266
|
fix: "Set @git.zone/cli.assets.cliName.",
|
|
2235
2267
|
});
|
|
2236
2268
|
} else {
|
|
2237
2269
|
findings.push({
|
|
2238
2270
|
level: "ok",
|
|
2239
|
-
message: `Managed
|
|
2271
|
+
message: `Managed binaryCli assets target ${cliName}`,
|
|
2240
2272
|
});
|
|
2241
2273
|
}
|
|
2242
2274
|
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
isPlainObject(rawAssetsConfig.binary) &&
|
|
2246
|
-
Array.isArray(rawAssetsConfig.binary.targets)
|
|
2247
|
-
? rawAssetsConfig.binary.targets
|
|
2248
|
-
: isPlainObject(tsdenoConfig) &&
|
|
2249
|
-
Array.isArray(tsdenoConfig.compileTargets)
|
|
2250
|
-
? tsdenoConfig.compileTargets
|
|
2251
|
-
: [];
|
|
2252
|
-
if (binaryTargets.length === 0) {
|
|
2275
|
+
try {
|
|
2276
|
+
const binaryBuild = await readBinaryBuild(process.cwd(), smartconfigData);
|
|
2253
2277
|
findings.push({
|
|
2254
|
-
level: "
|
|
2255
|
-
message:
|
|
2256
|
-
fix: "Add @git.zone/tsdeno.compileTargets or @git.zone/cli.assets.binary.targets.",
|
|
2278
|
+
level: "ok",
|
|
2279
|
+
message: `Managed assets release ${binaryBuild.targets.length} @git.zone/tssea executable(s) from ${binaryBuild.outDir}`,
|
|
2257
2280
|
});
|
|
2258
|
-
}
|
|
2281
|
+
} catch (error) {
|
|
2259
2282
|
findings.push({
|
|
2260
|
-
level: "
|
|
2261
|
-
message:
|
|
2283
|
+
level: "error",
|
|
2284
|
+
message: error instanceof Error ? error.message : String(error),
|
|
2285
|
+
fix: "Configure and install @git.zone/tssea as the message says.",
|
|
2262
2286
|
});
|
|
2263
2287
|
}
|
|
2264
2288
|
|
|
@@ -2825,35 +2849,23 @@ async function validateDetectedProjectType(
|
|
|
2825
2849
|
findings: IDoctorFinding[],
|
|
2826
2850
|
): Promise<void> {
|
|
2827
2851
|
const packageJsonPath = plugins.path.join(process.cwd(), "package.json");
|
|
2828
|
-
const denoJsonPath = plugins.path.join(process.cwd(), "deno.json");
|
|
2829
2852
|
const hasPackageJson = await plugins.smartfs.file(packageJsonPath).exists();
|
|
2830
|
-
const hasDenoJson = await plugins.smartfs.file(denoJsonPath).exists();
|
|
2831
2853
|
|
|
2832
|
-
if (!hasPackageJson
|
|
2854
|
+
if (!hasPackageJson) {
|
|
2833
2855
|
findings.push({
|
|
2834
2856
|
level: "warn",
|
|
2835
|
-
message: "Could not detect package.json
|
|
2857
|
+
message: "Could not detect package.json",
|
|
2836
2858
|
fix: "Run this command from a project root.",
|
|
2837
2859
|
});
|
|
2838
2860
|
return;
|
|
2839
2861
|
}
|
|
2840
2862
|
|
|
2841
|
-
if (
|
|
2863
|
+
if (validProjectTypes.includes(cliConfig.projectType)) {
|
|
2842
2864
|
findings.push({
|
|
2843
2865
|
level: "ok",
|
|
2844
2866
|
message:
|
|
2845
2867
|
"Detected project files match configured npm-compatible project type",
|
|
2846
2868
|
});
|
|
2847
|
-
return;
|
|
2848
|
-
}
|
|
2849
|
-
|
|
2850
|
-
if (hasDenoJson && !hasPackageJson) {
|
|
2851
|
-
findings.push({
|
|
2852
|
-
level: "warn",
|
|
2853
|
-
message:
|
|
2854
|
-
"Detected a Deno-only project, but guided config supports npm-compatible project types",
|
|
2855
|
-
fix: "Use `gitzone config set projectType npm|service|wcc|website` only for npm-compatible projects.",
|
|
2856
|
-
});
|
|
2857
2869
|
}
|
|
2858
2870
|
}
|
|
2859
2871
|
|
|
@@ -6,6 +6,12 @@ import { ScafTemplate } from '../../mod_template/classes.scaftemplate.js';
|
|
|
6
6
|
import { logger, logVerbose } from '../../gitzone.logging.js';
|
|
7
7
|
import { getCliConfigValue, readSmartconfigFile } from '../../helpers.smartconfig.js';
|
|
8
8
|
import { getSealedReleaseConfigError } from '../../helpers.sealedrelease.js';
|
|
9
|
+
import {
|
|
10
|
+
assertManagedAssetsCurrent,
|
|
11
|
+
managedAssetKinds,
|
|
12
|
+
readBinaryBuild,
|
|
13
|
+
type IBinaryBuild,
|
|
14
|
+
} from '../../helpers.managedassets.js';
|
|
9
15
|
|
|
10
16
|
interface IAssetFileMapping {
|
|
11
17
|
from: string;
|
|
@@ -20,16 +26,6 @@ interface IAssetTemplateEntry {
|
|
|
20
26
|
variables?: Record<string, any>;
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
interface IBinaryTargetRenderData {
|
|
24
|
-
name: string;
|
|
25
|
-
assetName: string;
|
|
26
|
-
os: string;
|
|
27
|
-
arch: string;
|
|
28
|
-
denoTarget: string;
|
|
29
|
-
nodeKey: string;
|
|
30
|
-
label: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
29
|
const isPlainObject = (value: unknown): value is Record<string, any> => {
|
|
34
30
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
35
31
|
};
|
|
@@ -62,7 +58,7 @@ const normalizeRepository = (assetsConfig: Record<string, any>, moduleConfig: Re
|
|
|
62
58
|
const repository = isPlainObject(assetsConfig.repository) ? assetsConfig.repository : {};
|
|
63
59
|
const host = repository.host || moduleConfig.githost || 'code.foss.global';
|
|
64
60
|
const path = repository.path || [moduleConfig.gitscope, moduleConfig.gitrepo].filter(Boolean).join('/');
|
|
65
|
-
const branch = repository.branch ||
|
|
61
|
+
const branch = repository.branch || 'main';
|
|
66
62
|
const baseUrl = `https://${host}/${path}`;
|
|
67
63
|
return {
|
|
68
64
|
host,
|
|
@@ -74,64 +70,6 @@ const normalizeRepository = (assetsConfig: Record<string, any>, moduleConfig: Re
|
|
|
74
70
|
};
|
|
75
71
|
};
|
|
76
72
|
|
|
77
|
-
const normalizeOs = (target: Record<string, any>): string => {
|
|
78
|
-
const rawValue = `${target.os || ''} ${target.target || ''} ${target.name || ''}`.toLowerCase();
|
|
79
|
-
if (rawValue.includes('apple') || rawValue.includes('darwin') || rawValue.includes('macos')) return 'macos';
|
|
80
|
-
if (rawValue.includes('windows') || rawValue.includes('pc-windows') || rawValue.includes('-win')) return 'windows';
|
|
81
|
-
return 'linux';
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const normalizeArch = (target: Record<string, any>): string => {
|
|
85
|
-
const rawValue = `${target.arch || ''} ${target.target || ''} ${target.name || ''}`.toLowerCase();
|
|
86
|
-
if (rawValue.includes('aarch64') || rawValue.includes('arm64')) return 'arm64';
|
|
87
|
-
return 'x64';
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const getNodePlatform = (os: string): string => {
|
|
91
|
-
if (os === 'macos') return 'darwin';
|
|
92
|
-
if (os === 'windows') return 'win32';
|
|
93
|
-
return 'linux';
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const getPlatformLabel = (target: IBinaryTargetRenderData): string => {
|
|
97
|
-
const osLabel = target.os === 'macos' ? 'macOS' : target.os === 'windows' ? 'Windows' : 'Linux';
|
|
98
|
-
const archLabel = target.arch === 'arm64' ? 'ARM64' : 'x64';
|
|
99
|
-
return `${osLabel} ${archLabel}`;
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
const normalizeBinaryTargets = (
|
|
103
|
-
assetsConfig: Record<string, any>,
|
|
104
|
-
smartconfigData: Record<string, any>,
|
|
105
|
-
): IBinaryTargetRenderData[] => {
|
|
106
|
-
const binaryConfig = isPlainObject(assetsConfig.binary) ? assetsConfig.binary : {};
|
|
107
|
-
const tsdenoConfig = smartconfigData['@git.zone/tsdeno'];
|
|
108
|
-
const targets = Array.isArray(binaryConfig.targets)
|
|
109
|
-
? binaryConfig.targets
|
|
110
|
-
: isPlainObject(tsdenoConfig) && Array.isArray(tsdenoConfig.compileTargets)
|
|
111
|
-
? tsdenoConfig.compileTargets
|
|
112
|
-
: [];
|
|
113
|
-
|
|
114
|
-
return targets
|
|
115
|
-
.filter((target) => isPlainObject(target) && typeof target.name === 'string')
|
|
116
|
-
.map((target) => {
|
|
117
|
-
const os = normalizeOs(target);
|
|
118
|
-
const arch = normalizeArch(target);
|
|
119
|
-
const isWindows = os === 'windows';
|
|
120
|
-
const assetName = isWindows && !target.name.endsWith('.exe') ? `${target.name}.exe` : target.name;
|
|
121
|
-
const result: IBinaryTargetRenderData = {
|
|
122
|
-
name: target.name,
|
|
123
|
-
assetName,
|
|
124
|
-
os,
|
|
125
|
-
arch,
|
|
126
|
-
denoTarget: target.target || target.denoTarget || '',
|
|
127
|
-
nodeKey: `${getNodePlatform(os)}:${arch}`,
|
|
128
|
-
label: '',
|
|
129
|
-
};
|
|
130
|
-
result.label = getPlatformLabel(result);
|
|
131
|
-
return result;
|
|
132
|
-
});
|
|
133
|
-
};
|
|
134
|
-
|
|
135
73
|
const buildDefaultEntries = (assetsConfig: Record<string, any>, cliName: string): IAssetTemplateEntry[] => {
|
|
136
74
|
if (assetsConfig.kind === 'tspackRelease') {
|
|
137
75
|
return [{
|
|
@@ -144,29 +82,25 @@ const buildDefaultEntries = (assetsConfig: Record<string, any>, cliName: string)
|
|
|
144
82
|
],
|
|
145
83
|
}];
|
|
146
84
|
}
|
|
147
|
-
if (assetsConfig.kind !== '
|
|
85
|
+
if (assetsConfig.kind !== 'binaryCli') {
|
|
148
86
|
return [];
|
|
149
87
|
}
|
|
150
88
|
|
|
151
89
|
const entries: IAssetTemplateEntry[] = [];
|
|
152
90
|
const installerConfig = isPlainObject(assetsConfig.installer) ? assetsConfig.installer : {};
|
|
153
91
|
const npmWrapperConfig = isPlainObject(assetsConfig.npmWrapper) ? assetsConfig.npmWrapper : {};
|
|
154
|
-
const releaseWorkflowConfig = isPlainObject(assetsConfig.releaseWorkflow)
|
|
155
|
-
? assetsConfig.releaseWorkflow
|
|
156
|
-
: isPlainObject(assetsConfig.releaseAssets)
|
|
157
|
-
? assetsConfig.releaseAssets
|
|
158
|
-
: {};
|
|
92
|
+
const releaseWorkflowConfig = isPlainObject(assetsConfig.releaseWorkflow) ? assetsConfig.releaseWorkflow : {};
|
|
159
93
|
|
|
160
94
|
if (installerConfig.enabled !== false) {
|
|
161
95
|
entries.push({
|
|
162
|
-
template: '
|
|
96
|
+
template: 'asset_binary_installer',
|
|
163
97
|
files: [{ from: 'install.sh', to: installerConfig.file || 'install.sh', mode: '0755' }],
|
|
164
98
|
});
|
|
165
99
|
}
|
|
166
100
|
|
|
167
101
|
if (npmWrapperConfig.enabled === true) {
|
|
168
102
|
entries.push({
|
|
169
|
-
template: '
|
|
103
|
+
template: 'asset_binary_postinstall',
|
|
170
104
|
files: [
|
|
171
105
|
{
|
|
172
106
|
from: 'scripts/install-binary.js',
|
|
@@ -184,7 +118,7 @@ const buildDefaultEntries = (assetsConfig: Record<string, any>, cliName: string)
|
|
|
184
118
|
|
|
185
119
|
if (releaseWorkflowConfig.enabled !== false) {
|
|
186
120
|
entries.push({
|
|
187
|
-
template: '
|
|
121
|
+
template: 'asset_binary_release_gitea',
|
|
188
122
|
files: [{ from: '.gitea/workflows/release.yml', to: releaseWorkflowConfig.file || '.gitea/workflows/release.yml' }],
|
|
189
123
|
});
|
|
190
124
|
}
|
|
@@ -203,9 +137,9 @@ export class AssetsFormatter extends BaseFormatter {
|
|
|
203
137
|
logVerbose('No @git.zone/cli.assets config found, skipping');
|
|
204
138
|
return [];
|
|
205
139
|
}
|
|
140
|
+
assertManagedAssetsCurrent(assetsConfig);
|
|
206
141
|
|
|
207
|
-
const
|
|
208
|
-
const renderData = await this.buildRenderData(assetsConfig, smartconfigData);
|
|
142
|
+
const renderData = await this.buildRenderData(assetsConfig);
|
|
209
143
|
const entries = this.getTemplateEntries(assetsConfig, renderData.cliName);
|
|
210
144
|
const changes: IPlannedChange[] = [];
|
|
211
145
|
|
|
@@ -258,8 +192,14 @@ export class AssetsFormatter extends BaseFormatter {
|
|
|
258
192
|
const error = getSealedReleaseConfigError(assetsConfig.sealedRelease);
|
|
259
193
|
return error ? [{ level: 'error', module: this.name, message: error }] : [];
|
|
260
194
|
}
|
|
261
|
-
if (assetsConfig.kind && assetsConfig.kind
|
|
262
|
-
return [
|
|
195
|
+
if (assetsConfig.kind !== undefined && !(managedAssetKinds as readonly unknown[]).includes(assetsConfig.kind)) {
|
|
196
|
+
return [
|
|
197
|
+
{
|
|
198
|
+
level: 'error',
|
|
199
|
+
module: this.name,
|
|
200
|
+
message: `Unsupported managed asset kind: ${assetsConfig.kind}. Use ${managedAssetKinds.join(' or ')}.`,
|
|
201
|
+
},
|
|
202
|
+
];
|
|
263
203
|
}
|
|
264
204
|
const installer = isPlainObject(assetsConfig.installer) ? assetsConfig.installer : {};
|
|
265
205
|
if (installer.distribution && !['rawBranch', 'releaseAsset'].includes(installer.distribution)) {
|
|
@@ -323,38 +263,37 @@ export class AssetsFormatter extends BaseFormatter {
|
|
|
323
263
|
return fileMap;
|
|
324
264
|
}
|
|
325
265
|
|
|
326
|
-
private async buildRenderData(
|
|
327
|
-
assetsConfig: Record<string, any>,
|
|
328
|
-
smartconfigData: Record<string, any>,
|
|
329
|
-
): Promise<Record<string, any>> {
|
|
266
|
+
private async buildRenderData(assetsConfig: Record<string, any>): Promise<Record<string, any>> {
|
|
330
267
|
const packageJson = await readJsonFile(plugins.path.join(paths.cwd, 'package.json'));
|
|
331
|
-
const denoJson = await readJsonFile(plugins.path.join(paths.cwd, 'deno.json'));
|
|
332
268
|
const moduleConfig = this.project.gitzoneConfig?.data?.module || {};
|
|
333
269
|
const cliName = assetsConfig.cliName || packageJson.name?.split('/').pop() || moduleConfig.gitrepo || 'app';
|
|
334
270
|
const displayName = assetsConfig.displayName || cliName.toUpperCase();
|
|
335
271
|
const repository = normalizeRepository(assetsConfig, moduleConfig);
|
|
336
272
|
const npmPackageName = (moduleConfig as any).npmPackagename || moduleConfig.npmPackageName;
|
|
337
|
-
const
|
|
273
|
+
const binaryBuild =
|
|
274
|
+
assetsConfig.kind === 'binaryCli'
|
|
275
|
+
? await readBinaryBuild(paths.cwd, await readSmartconfigFile(paths.cwd))
|
|
276
|
+
: { outDir: '', targets: [] };
|
|
277
|
+
const binaryTargets = binaryBuild.targets;
|
|
338
278
|
const binaryConfig = isPlainObject(assetsConfig.binary) ? assetsConfig.binary : {};
|
|
339
279
|
const installerConfig = this.normalizeInstallerConfig(assetsConfig, cliName, repository);
|
|
340
280
|
const npmWrapperConfig = this.normalizeNpmWrapperConfig(assetsConfig, cliName);
|
|
341
|
-
const releaseWorkflowConfig = this.normalizeReleaseWorkflowConfig(assetsConfig,
|
|
281
|
+
const releaseWorkflowConfig = this.normalizeReleaseWorkflowConfig(assetsConfig, binaryBuild, installerConfig);
|
|
342
282
|
|
|
343
283
|
return {
|
|
344
284
|
module: moduleConfig,
|
|
345
285
|
projectType: this.project.gitzoneConfig?.data?.projectType,
|
|
346
286
|
packageJson,
|
|
347
|
-
denoJson,
|
|
348
287
|
assets: assetsConfig,
|
|
349
288
|
cliName,
|
|
350
289
|
cliNameUpper: cliName.toUpperCase(),
|
|
351
290
|
displayName,
|
|
352
291
|
packageName: assetsConfig.packageName || packageJson.name || npmPackageName || cliName,
|
|
353
|
-
versionFallback: packageJson.version ||
|
|
292
|
+
versionFallback: packageJson.version || '0.0.0',
|
|
354
293
|
repository,
|
|
355
294
|
binary: {
|
|
356
295
|
...binaryConfig,
|
|
357
|
-
outDir:
|
|
296
|
+
outDir: binaryBuild.outDir,
|
|
358
297
|
installFileName: binaryConfig.installFileName || cliName,
|
|
359
298
|
targets: binaryTargets,
|
|
360
299
|
supportedPlatformText: binaryTargets.map((target) => target.label).join(', '),
|
|
@@ -373,14 +312,14 @@ export class AssetsFormatter extends BaseFormatter {
|
|
|
373
312
|
): Record<string, any> {
|
|
374
313
|
const installer = isPlainObject(assetsConfig.installer) ? assetsConfig.installer : {};
|
|
375
314
|
const modes = isPlainObject(installer.modes) ? installer.modes : {};
|
|
376
|
-
const source = isPlainObject(modes.source) ? modes.source :
|
|
315
|
+
const source = isPlainObject(modes.source) ? modes.source : {};
|
|
377
316
|
const service = isPlainObject(installer.service) ? installer.service : {};
|
|
378
317
|
const file = installer.file || 'install.sh';
|
|
379
318
|
const releaseAssetName = plugins.path.basename(file);
|
|
380
|
-
const distribution = installer.distribution ||
|
|
319
|
+
const distribution = installer.distribution || 'rawBranch';
|
|
381
320
|
const versionSelection = uniqueStringArray(installer.versionSelection, ['latest', 'version']);
|
|
382
321
|
const detectNames = uniqueStringArray(service.detectNames, service.name ? [service.name] : [cliName]);
|
|
383
|
-
const removeLegacyUnits = uniqueStringArray(service.removeLegacyUnits ||
|
|
322
|
+
const removeLegacyUnits = uniqueStringArray(service.removeLegacyUnits || []);
|
|
384
323
|
const ensureDirs = uniqueStringArray(installer.ensureDirs);
|
|
385
324
|
const preservePaths = uniqueStringArray(installer.preservePaths);
|
|
386
325
|
const successHints = uniqueStringArray(installer.successHints, [`${cliName} --version`, `${cliName} --help`]);
|
|
@@ -398,7 +337,7 @@ export class AssetsFormatter extends BaseFormatter {
|
|
|
398
337
|
releaseNotesInstallUrl: distribution === 'releaseAsset' ? releaseNotesInstallUrl : rawBranchInstallUrl,
|
|
399
338
|
installDir: installer.installDir || `/opt/${cliName}`,
|
|
400
339
|
binDir: installer.binDir || '/usr/local/bin',
|
|
401
|
-
defaultMode: modes.default ||
|
|
340
|
+
defaultMode: modes.default || 'binary',
|
|
402
341
|
versionSelection,
|
|
403
342
|
supportsMajor: versionSelection.includes('major'),
|
|
404
343
|
source: {
|
|
@@ -407,7 +346,7 @@ export class AssetsFormatter extends BaseFormatter {
|
|
|
407
346
|
commands: uniqueStringArray(source.commands),
|
|
408
347
|
executable: source.executable || 'cli.js',
|
|
409
348
|
executableFiles: uniqueStringArray(source.executableFiles, source.executable ? [source.executable] : ['cli.js']),
|
|
410
|
-
validateCommand: source.validate ||
|
|
349
|
+
validateCommand: source.validate || `node ${source.executable || 'cli.js'} --version`,
|
|
411
350
|
},
|
|
412
351
|
service: {
|
|
413
352
|
...service,
|
|
@@ -438,31 +377,31 @@ export class AssetsFormatter extends BaseFormatter {
|
|
|
438
377
|
|
|
439
378
|
private normalizeReleaseWorkflowConfig(
|
|
440
379
|
assetsConfig: Record<string, any>,
|
|
441
|
-
|
|
380
|
+
binaryBuild: IBinaryBuild,
|
|
442
381
|
installerConfig: Record<string, any>,
|
|
443
382
|
): Record<string, any> {
|
|
444
|
-
const releaseWorkflow = isPlainObject(assetsConfig.releaseWorkflow)
|
|
445
|
-
? assetsConfig.releaseWorkflow
|
|
446
|
-
: isPlainObject(assetsConfig.releaseAssets)
|
|
447
|
-
? assetsConfig.releaseAssets
|
|
448
|
-
: {};
|
|
449
|
-
const binaryOutDir = binaryConfig.outDir || 'dist/binaries';
|
|
450
|
-
const assetGlobs = uniqueStringArray(releaseWorkflow.assetGlobs || releaseWorkflow.include, [`${binaryOutDir}/*`]);
|
|
383
|
+
const releaseWorkflow = isPlainObject(assetsConfig.releaseWorkflow) ? assetsConfig.releaseWorkflow : {};
|
|
451
384
|
const includeInstallerAsset =
|
|
452
385
|
typeof releaseWorkflow.includeInstallerAsset === 'boolean'
|
|
453
386
|
? releaseWorkflow.includeInstallerAsset
|
|
454
387
|
: installerConfig.enabled !== false && installerConfig.distribution === 'releaseAsset';
|
|
388
|
+
// Exactly the files this release built: the output directory can still hold
|
|
389
|
+
// executables of removed targets or an interrupted build's work directory.
|
|
390
|
+
const releaseFileNames = binaryBuild.targets.flatMap((target) => [target.name, ...target.noticeFiles]);
|
|
391
|
+
if (includeInstallerAsset) {
|
|
392
|
+
releaseFileNames.push(installerConfig.releaseAssetName);
|
|
393
|
+
}
|
|
455
394
|
return {
|
|
456
395
|
...releaseWorkflow,
|
|
457
396
|
enabled: releaseWorkflow.enabled !== false,
|
|
458
397
|
file: releaseWorkflow.file || '.gitea/workflows/release.yml',
|
|
459
398
|
installCommand: releaseWorkflow.installCommand || 'pnpm install --ignore-scripts',
|
|
460
|
-
compileCommand: releaseWorkflow.compileCommand || 'pnpm exec
|
|
399
|
+
compileCommand: releaseWorkflow.compileCommand || 'pnpm exec tsbundle && pnpm exec tssea build',
|
|
461
400
|
packNpmArtifact: releaseWorkflow.packNpmArtifact === true,
|
|
462
401
|
includeInstallerAsset,
|
|
463
|
-
|
|
402
|
+
releaseFileNames,
|
|
464
403
|
keepReleases: releaseWorkflow.keepReleases ?? 0,
|
|
465
|
-
binaryOutDir,
|
|
404
|
+
binaryOutDir: binaryBuild.outDir,
|
|
466
405
|
};
|
|
467
406
|
}
|
|
468
407
|
}
|
|
@@ -73,13 +73,13 @@ export class PackageJsonFormatter extends BaseFormatter {
|
|
|
73
73
|
|
|
74
74
|
const rawAssetsConfig = gitzoneData.assets;
|
|
75
75
|
const assetsConfig = rawAssetsConfig?.enabled === false ? undefined : rawAssetsConfig;
|
|
76
|
-
const managedAssetConfig = rawAssetsConfig?.kind === '
|
|
76
|
+
const managedAssetConfig = rawAssetsConfig?.kind === 'binaryCli' ? rawAssetsConfig : undefined;
|
|
77
77
|
const managedCliName = managedAssetConfig?.cliName || packageJson.name?.split('/').pop();
|
|
78
78
|
const managedBinFile = managedAssetConfig?.npmWrapper?.binFile || `bin/${managedCliName}-wrapper.js`;
|
|
79
79
|
const managedPostinstallFile = managedAssetConfig?.npmWrapper?.postinstallFile || 'scripts/install-binary.js';
|
|
80
80
|
const managedPostinstallCommand = `node ${managedPostinstallFile}`;
|
|
81
81
|
|
|
82
|
-
if (assetsConfig?.kind === '
|
|
82
|
+
if (assetsConfig?.kind === 'binaryCli' && assetsConfig.npmWrapper?.enabled) {
|
|
83
83
|
if (managedCliName) {
|
|
84
84
|
packageJson.bin = typeof packageJson.bin === 'object' && !Array.isArray(packageJson.bin)
|
|
85
85
|
? packageJson.bin
|