@eserstack/codebase 0.0.0-bootstrap.0 → 5.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/README.md +302 -0
- package/dist/changelog-gen.d.ts +105 -0
- package/dist/changelog-gen.js +498 -0
- package/dist/changelog-text.d.ts +39 -0
- package/dist/changelog-text.js +82 -0
- package/dist/cli-support.d.ts +140 -0
- package/dist/cli-support.js +244 -0
- package/dist/cli-system/app-opts.d.ts +15 -0
- package/dist/cli-system/app-opts.js +13 -0
- package/dist/cli-system/app.d.ts +29 -0
- package/dist/cli-system/app.js +12 -0
- package/dist/cli-system/handlers/completions-setup.d.ts +14 -0
- package/dist/cli-system/handlers/completions-setup.js +139 -0
- package/dist/cli-system/handlers/completions.d.ts +3 -0
- package/dist/cli-system/handlers/completions.js +79 -0
- package/dist/cli-system/handlers/doctor.d.ts +8 -0
- package/dist/cli-system/handlers/doctor.js +146 -0
- package/dist/cli-system/handlers/info.d.ts +3 -0
- package/dist/cli-system/handlers/info.js +69 -0
- package/dist/cli-system/handlers/install.d.ts +8 -0
- package/dist/cli-system/handlers/install.js +137 -0
- package/dist/cli-system/handlers/mod.d.ts +12 -0
- package/dist/cli-system/handlers/mod.js +13 -0
- package/dist/cli-system/handlers/uninstall.d.ts +3 -0
- package/dist/cli-system/handlers/uninstall.js +60 -0
- package/dist/cli-system/handlers/update.d.ts +76 -0
- package/dist/cli-system/handlers/update.js +310 -0
- package/dist/cli-system/handlers/version-check.d.ts +16 -0
- package/dist/cli-system/handlers/version-check.js +176 -0
- package/dist/cli-system/handlers/version.d.ts +3 -0
- package/dist/cli-system/handlers/version.js +45 -0
- package/dist/cli-system/mod.d.ts +19 -0
- package/dist/cli-system/mod.js +52 -0
- package/dist/commitmsg.d.ts +28 -0
- package/dist/commitmsg.js +232 -0
- package/dist/directive-analysis.d.ts +75 -0
- package/dist/directive-analysis.js +223 -0
- package/dist/ffi-client.d.ts +11 -0
- package/dist/ffi-client.js +12 -0
- package/dist/file-tool.d.ts +96 -0
- package/dist/file-tool.js +274 -0
- package/dist/file-tools-shared.d.ts +81 -0
- package/dist/file-tools-shared.js +276 -0
- package/dist/gh-contributors.d.ts +89 -0
- package/dist/gh-contributors.js +205 -0
- package/dist/gh.d.ts +3 -0
- package/dist/gh.js +64 -0
- package/dist/git-listing.d.ts +27 -0
- package/dist/git-listing.js +69 -0
- package/dist/git.d.ts +172 -0
- package/dist/git.js +277 -0
- package/dist/install.d.ts +34 -0
- package/dist/install.js +421 -0
- package/dist/main.d.ts +22 -0
- package/dist/main.js +14 -0
- package/dist/mod.d.ts +25 -0
- package/dist/mod.js +8 -0
- package/dist/module.d.ts +10 -0
- package/dist/module.js +221 -0
- package/dist/native-functions.d.ts +1088 -0
- package/dist/native-functions.js +2 -0
- package/dist/npm-externals.d.ts +27 -0
- package/dist/npm-externals.js +34 -0
- package/dist/npm-workspace-specifiers.d.ts +6 -0
- package/dist/npm-workspace-specifiers.js +45 -0
- package/dist/package/loader.d.ts +34 -0
- package/dist/package/loader.js +203 -0
- package/dist/package/mod.d.ts +36 -0
- package/dist/package/mod.js +5 -0
- package/dist/package/types.d.ts +142 -0
- package/dist/package/types.js +32 -0
- package/dist/package/workspace.d.ts +33 -0
- package/dist/package/workspace.js +158 -0
- package/dist/package/writer.d.ts +52 -0
- package/dist/package/writer.js +278 -0
- package/dist/package.json +275 -0
- package/dist/release-notes.d.ts +90 -0
- package/dist/release-notes.js +236 -0
- package/dist/release-tag.d.ts +46 -0
- package/dist/release-tag.js +95 -0
- package/dist/release.d.ts +145 -0
- package/dist/release.js +584 -0
- package/dist/source-mask.d.ts +3 -0
- package/dist/source-mask.js +185 -0
- package/dist/validate-bom.d.ts +5 -0
- package/dist/validate-bom.js +43 -0
- package/dist/validate-case-conflict.d.ts +5 -0
- package/dist/validate-case-conflict.js +43 -0
- package/dist/validate-circular-deps.d.ts +11 -0
- package/dist/validate-circular-deps.js +53 -0
- package/dist/validate-code-conventions.d.ts +22 -0
- package/dist/validate-code-conventions.js +166 -0
- package/dist/validate-commit-msg.d.ts +50 -0
- package/dist/validate-commit-msg.js +182 -0
- package/dist/validate-docs.d.ts +20 -0
- package/dist/validate-docs.js +78 -0
- package/dist/validate-eof.d.ts +5 -0
- package/dist/validate-eof.js +61 -0
- package/dist/validate-error-coverage.d.ts +28 -0
- package/dist/validate-error-coverage.js +93 -0
- package/dist/validate-export-names.d.ts +17 -0
- package/dist/validate-export-names.js +56 -0
- package/dist/validate-filenames.d.ts +5 -0
- package/dist/validate-filenames.js +151 -0
- package/dist/validate-json.d.ts +5 -0
- package/dist/validate-json.js +71 -0
- package/dist/validate-large-files.d.ts +5 -0
- package/dist/validate-large-files.js +41 -0
- package/dist/validate-laroux-boundaries.d.ts +19 -0
- package/dist/validate-laroux-boundaries.js +59 -0
- package/dist/validate-licenses.d.ts +5 -0
- package/dist/validate-licenses.js +137 -0
- package/dist/validate-line-endings.d.ts +5 -0
- package/dist/validate-line-endings.js +47 -0
- package/dist/validate-merge-conflict.d.ts +5 -0
- package/dist/validate-merge-conflict.js +46 -0
- package/dist/validate-mod-exports.d.ts +16 -0
- package/dist/validate-mod-exports.js +56 -0
- package/dist/validate-naming-and-todos.d.ts +5 -0
- package/dist/validate-naming-and-todos.js +70 -0
- package/dist/validate-runtime-js-apis.d.ts +5 -0
- package/dist/validate-runtime-js-apis.js +78 -0
- package/dist/validate-secrets.d.ts +5 -0
- package/dist/validate-secrets.js +82 -0
- package/dist/validate-self-imports.d.ts +5 -0
- package/dist/validate-self-imports.js +78 -0
- package/dist/validate-server-loc.d.ts +32 -0
- package/dist/validate-server-loc.js +94 -0
- package/dist/validate-shebangs.d.ts +5 -0
- package/dist/validate-shebangs.js +33 -0
- package/dist/validate-stream.d.ts +25 -0
- package/dist/validate-stream.js +62 -0
- package/dist/validate-submodules.d.ts +5 -0
- package/dist/validate-submodules.js +43 -0
- package/dist/validate-symlinks.d.ts +5 -0
- package/dist/validate-symlinks.js +46 -0
- package/dist/validate-toml.d.ts +5 -0
- package/dist/validate-toml.js +40 -0
- package/dist/validate-trailing-whitespace.d.ts +5 -0
- package/dist/validate-trailing-whitespace.js +49 -0
- package/dist/validate-yaml.d.ts +5 -0
- package/dist/validate-yaml.js +40 -0
- package/dist/validation/config.d.ts +17 -0
- package/dist/validation/config.js +30 -0
- package/dist/validation/mod.d.ts +71 -0
- package/dist/validation/mod.js +479 -0
- package/dist/validation/registry.d.ts +57 -0
- package/dist/validation/registry.js +256 -0
- package/dist/validation/types.d.ts +101 -0
- package/dist/validation/types.js +2 -0
- package/dist/validation/validators/circular-deps.d.ts +7 -0
- package/dist/validation/validators/circular-deps.js +31 -0
- package/dist/validation/validators/docs.d.ts +7 -0
- package/dist/validation/validators/docs.js +38 -0
- package/dist/validation/validators/error-coverage.d.ts +2 -0
- package/dist/validation/validators/error-coverage.js +46 -0
- package/dist/validation/validators/export-names.d.ts +7 -0
- package/dist/validation/validators/export-names.js +31 -0
- package/dist/validation/validators/laroux-boundaries.d.ts +2 -0
- package/dist/validation/validators/laroux-boundaries.js +29 -0
- package/dist/validation/validators/mod-exports.d.ts +7 -0
- package/dist/validation/validators/mod-exports.js +32 -0
- package/dist/validation/validators/mod.d.ts +11 -0
- package/dist/validation/validators/mod.js +12 -0
- package/dist/validation/validators/server-loc.d.ts +2 -0
- package/dist/validation/validators/server-loc.js +48 -0
- package/dist/versions.d.ts +166 -0
- package/dist/versions.js +349 -0
- package/dist/violation-baseline.d.ts +58 -0
- package/dist/violation-baseline.js +144 -0
- package/dist/walk-stream.d.ts +24 -0
- package/dist/walk-stream.js +55 -0
- package/dist/workspace-discovery.d.ts +60 -0
- package/dist/workspace-discovery.js +130 -0
- package/package.json +225 -1
package/dist/install.js
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
/**
|
|
3
|
+
* Git hook installation — installs, uninstalls, and reports status of
|
|
4
|
+
* managed git hooks derived from `.eser/manifest.yml` workflow events.
|
|
5
|
+
*
|
|
6
|
+
* @module
|
|
7
|
+
*/
|
|
8
|
+
import * as shellFlags from "@eserstack/shell/args/flags";
|
|
9
|
+
import * as span from "@eserstack/streams/span";
|
|
10
|
+
import * as streams from "@eserstack/streams";
|
|
11
|
+
import * as primitives from "@eserstack/primitives";
|
|
12
|
+
import * as standards from "@eserstack/standards";
|
|
13
|
+
import * as configManifest from "@eserstack/config/manifest";
|
|
14
|
+
import * as cliSupport from "./cli-support.js";
|
|
15
|
+
// =============================================================================
|
|
16
|
+
// Constants
|
|
17
|
+
// =============================================================================
|
|
18
|
+
/** Maps manifest event names to git hook filenames and extra shell args. */
|
|
19
|
+
const EVENT_TO_HOOK = {
|
|
20
|
+
precommit: { hookName: "pre-commit", args: "" },
|
|
21
|
+
commitmsg: { hookName: "commit-msg", args: '-- "$1"' },
|
|
22
|
+
prepush: { hookName: "pre-push", args: "" },
|
|
23
|
+
};
|
|
24
|
+
/** Marker comment placed in managed hook scripts. */
|
|
25
|
+
const MARKER = "# @eser managed hook";
|
|
26
|
+
/**
|
|
27
|
+
* Unsets the variables git exports to a hook (GIT_DIR and GIT_INDEX_FILE in a
|
|
28
|
+
* linked worktree, among others). The workflows run from the working tree
|
|
29
|
+
* root, where git finds the repository by itself, and their tests create
|
|
30
|
+
* scratch repositories whose git calls would otherwise act on the repository
|
|
31
|
+
* being committed to. The Go `eser codebase install` writes the same line.
|
|
32
|
+
*/
|
|
33
|
+
const CLEAR_REPOSITORY_ENV = "unset $(git rev-parse --local-env-vars)";
|
|
34
|
+
// =============================================================================
|
|
35
|
+
// Helpers
|
|
36
|
+
// =============================================================================
|
|
37
|
+
/**
|
|
38
|
+
* Resolve the command a hook runs to reach the CLI.
|
|
39
|
+
*
|
|
40
|
+
* Uses `detectExecutionContext()` to determine how the CLI was invoked,
|
|
41
|
+
* honoring the user's chosen invocation method for the hook command.
|
|
42
|
+
*/
|
|
43
|
+
const resolveCliCommand = async () => {
|
|
44
|
+
const ctx = await standards.crossRuntime.detectExecutionContext({
|
|
45
|
+
command: "eser",
|
|
46
|
+
devCommand: "pnpm cli",
|
|
47
|
+
npmPackage: "eser",
|
|
48
|
+
});
|
|
49
|
+
return ctx.command;
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Generate the shell script content for a git hook.
|
|
53
|
+
*/
|
|
54
|
+
export const generateHookScript = (cliCmd, event, args) => {
|
|
55
|
+
const argsStr = args.length > 0 ? ` ${args}` : "";
|
|
56
|
+
const command = `${cliCmd} workflows run -e ${event}${argsStr}`;
|
|
57
|
+
return [
|
|
58
|
+
"#!/bin/sh",
|
|
59
|
+
`${MARKER} — generated by \`eser codebase install\``,
|
|
60
|
+
"# Do not edit. Re-run `eser codebase install` to update.",
|
|
61
|
+
"",
|
|
62
|
+
CLEAR_REPOSITORY_ENV,
|
|
63
|
+
command,
|
|
64
|
+
"",
|
|
65
|
+
].join("\n");
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Locate the `.git` directory for the current repository.
|
|
69
|
+
*/
|
|
70
|
+
const findGitDir = async () => {
|
|
71
|
+
try {
|
|
72
|
+
const output = await standards.crossRuntime.runtime.exec.exec("git", [
|
|
73
|
+
"rev-parse",
|
|
74
|
+
"--git-dir",
|
|
75
|
+
]);
|
|
76
|
+
const dir = output.trim();
|
|
77
|
+
if (dir.length > 0)
|
|
78
|
+
return dir;
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
// fall through
|
|
82
|
+
}
|
|
83
|
+
// Fallback: check cwd
|
|
84
|
+
const cwd = standards.crossRuntime.runtime.process.cwd();
|
|
85
|
+
const dotGit = standards.crossRuntime.runtime.path.join(cwd, ".git");
|
|
86
|
+
try {
|
|
87
|
+
const info = await standards.crossRuntime.runtime.fs.stat(dotGit);
|
|
88
|
+
if (info.isDirectory)
|
|
89
|
+
return dotGit;
|
|
90
|
+
}
|
|
91
|
+
catch {
|
|
92
|
+
// not found
|
|
93
|
+
}
|
|
94
|
+
return null;
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* Extract unique events from a manifest's workflows array.
|
|
98
|
+
*/
|
|
99
|
+
const extractEvents = (raw) => {
|
|
100
|
+
const workflows = raw["workflows"];
|
|
101
|
+
if (!Array.isArray(workflows))
|
|
102
|
+
return [];
|
|
103
|
+
const events = new Set();
|
|
104
|
+
for (const wf of workflows) {
|
|
105
|
+
if (Array.isArray(wf.on)) {
|
|
106
|
+
for (const ev of wf.on) {
|
|
107
|
+
if (typeof ev === "string")
|
|
108
|
+
events.add(ev);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return [...events];
|
|
113
|
+
};
|
|
114
|
+
// =============================================================================
|
|
115
|
+
// Renderer for string returns
|
|
116
|
+
// =============================================================================
|
|
117
|
+
const renderer = streams.renderers.ansi();
|
|
118
|
+
/** Parse the install arguments: `--force` (`-f`), `--dry-run` (`-n`), `--help` (`-h`). */
|
|
119
|
+
export const parseInstallArgs = (cliArgs) => {
|
|
120
|
+
const { values } = shellFlags.parseArgs(cliArgs ?? [], {
|
|
121
|
+
options: {
|
|
122
|
+
force: { type: "boolean", short: "f" },
|
|
123
|
+
"dry-run": { type: "boolean", short: "n" },
|
|
124
|
+
help: { type: "boolean", short: "h" },
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
return {
|
|
128
|
+
help: values["help"] === true,
|
|
129
|
+
force: values["force"] === true,
|
|
130
|
+
dryRun: values["dry-run"] === true,
|
|
131
|
+
};
|
|
132
|
+
};
|
|
133
|
+
/** Parse the arguments of `uninstall` and `status`, which only know `--help` (`-h`). */
|
|
134
|
+
export const parseHelpArgs = (cliArgs) => {
|
|
135
|
+
const { values } = shellFlags.parseArgs(cliArgs ?? [], {
|
|
136
|
+
options: { help: { type: "boolean", short: "h" } },
|
|
137
|
+
});
|
|
138
|
+
return { help: values["help"] === true };
|
|
139
|
+
};
|
|
140
|
+
/**
|
|
141
|
+
* Install managed git hooks based on `.eser/manifest.yml` workflow events.
|
|
142
|
+
*
|
|
143
|
+
* Flags:
|
|
144
|
+
* --force Overwrite non-managed hooks
|
|
145
|
+
* --dry-run Show what would happen without writing
|
|
146
|
+
* --help Show usage
|
|
147
|
+
*/
|
|
148
|
+
export const main = async (cliArgs) => {
|
|
149
|
+
const parsed = parseInstallArgs(cliArgs);
|
|
150
|
+
const out = streams.output({
|
|
151
|
+
renderer,
|
|
152
|
+
sink: streams.sinks.stdout(),
|
|
153
|
+
});
|
|
154
|
+
if (parsed.help) {
|
|
155
|
+
out.writeln("eser codebase install — Install git hooks from .eser/manifest.yml");
|
|
156
|
+
out.writeln();
|
|
157
|
+
out.writeln("Flags:");
|
|
158
|
+
out.writeln(" --force, -f Overwrite non-managed hooks");
|
|
159
|
+
out.writeln(" --dry-run, -n Show what would happen without writing");
|
|
160
|
+
out.writeln(" --help, -h Show this help");
|
|
161
|
+
await out.close();
|
|
162
|
+
return primitives.results.ok(undefined);
|
|
163
|
+
}
|
|
164
|
+
const { force, dryRun } = parsed;
|
|
165
|
+
// 1. Find .git directory
|
|
166
|
+
const gitDir = await findGitDir();
|
|
167
|
+
if (gitDir === null) {
|
|
168
|
+
out.writeln(span.red("Error: not inside a git repository"));
|
|
169
|
+
await out.close();
|
|
170
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
171
|
+
}
|
|
172
|
+
const hooksDir = standards.crossRuntime.runtime.path.join(gitDir, "hooks");
|
|
173
|
+
// 2. Load manifest
|
|
174
|
+
const cwd = standards.crossRuntime.runtime.process.cwd();
|
|
175
|
+
const raw = await configManifest.loadManifest(cwd);
|
|
176
|
+
if (raw === null) {
|
|
177
|
+
out.writeln(span.red("Error: no .eser/manifest.yml found in current directory"));
|
|
178
|
+
await out.close();
|
|
179
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
180
|
+
}
|
|
181
|
+
// 3. Extract events
|
|
182
|
+
const events = extractEvents(raw);
|
|
183
|
+
if (events.length === 0) {
|
|
184
|
+
out.writeln(span.yellow("No workflow events found — nothing to install."));
|
|
185
|
+
await out.close();
|
|
186
|
+
return primitives.results.ok(undefined);
|
|
187
|
+
}
|
|
188
|
+
// 4. Ensure hooks directory exists
|
|
189
|
+
if (!dryRun) {
|
|
190
|
+
await standards.crossRuntime.runtime.fs.ensureDir(hooksDir);
|
|
191
|
+
}
|
|
192
|
+
// 5. Install hooks
|
|
193
|
+
const cliCmd = await resolveCliCommand();
|
|
194
|
+
let installed = 0;
|
|
195
|
+
let skipped = 0;
|
|
196
|
+
let updated = 0;
|
|
197
|
+
for (const event of events) {
|
|
198
|
+
const mapping = EVENT_TO_HOOK[event];
|
|
199
|
+
if (mapping === undefined) {
|
|
200
|
+
out.writeln(span.dim(` skip ${event} (unknown event, no hook mapping)`));
|
|
201
|
+
continue;
|
|
202
|
+
}
|
|
203
|
+
const { hookName, args } = mapping;
|
|
204
|
+
const hookPath = standards.crossRuntime.runtime.path.join(hooksDir, hookName);
|
|
205
|
+
const script = generateHookScript(cliCmd, event, args);
|
|
206
|
+
let exists = false;
|
|
207
|
+
let isManaged = false;
|
|
208
|
+
try {
|
|
209
|
+
// Hooks are written one at a time, so a failed write stops before the
|
|
210
|
+
// next hook changes and the report follows the manifest order.
|
|
211
|
+
const existing =
|
|
212
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
213
|
+
await standards.crossRuntime.runtime.fs.readTextFile(hookPath);
|
|
214
|
+
exists = true;
|
|
215
|
+
isManaged = existing.includes(MARKER);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
// file does not exist
|
|
219
|
+
}
|
|
220
|
+
if (dryRun) {
|
|
221
|
+
if (!exists) {
|
|
222
|
+
out.writeln(span.blue(` would create ${hookName}`));
|
|
223
|
+
}
|
|
224
|
+
else if (isManaged) {
|
|
225
|
+
out.writeln(span.blue(` would update ${hookName} (managed)`));
|
|
226
|
+
}
|
|
227
|
+
else if (force) {
|
|
228
|
+
out.writeln(span.yellow(` would overwrite ${hookName} (--force)`));
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
out.writeln(span.yellow(` would skip ${hookName} (user hook; use --force to overwrite)`));
|
|
232
|
+
}
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
if (exists && !isManaged && !force) {
|
|
236
|
+
out.writeln(span.yellow(` skip ${hookName} — user hook exists (use --force to overwrite)`));
|
|
237
|
+
skipped++;
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
// One hook at a time, as above.
|
|
241
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
242
|
+
await standards.crossRuntime.runtime.fs.writeTextFile(hookPath, script);
|
|
243
|
+
// chmod +x (non-fatal on platforms without chmod support)
|
|
244
|
+
try {
|
|
245
|
+
// One hook at a time, as above.
|
|
246
|
+
// oxlint-disable-next-line no-await-in-loop
|
|
247
|
+
await standards.crossRuntime.runtime.fs.chmod(hookPath, 0o755);
|
|
248
|
+
}
|
|
249
|
+
catch {
|
|
250
|
+
// Windows doesn't support chmod — hook will still work via shebang
|
|
251
|
+
}
|
|
252
|
+
if (exists && isManaged) {
|
|
253
|
+
out.writeln(span.green(` updated ${hookName}`));
|
|
254
|
+
updated++;
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
out.writeln(span.green(` installed ${hookName}`));
|
|
258
|
+
installed++;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
// Summary
|
|
262
|
+
out.writeln();
|
|
263
|
+
const parts = [];
|
|
264
|
+
if (installed > 0)
|
|
265
|
+
parts.push(`${installed} installed`);
|
|
266
|
+
if (updated > 0)
|
|
267
|
+
parts.push(`${updated} updated`);
|
|
268
|
+
if (skipped > 0)
|
|
269
|
+
parts.push(`${skipped} skipped`);
|
|
270
|
+
if (dryRun) {
|
|
271
|
+
out.writeln(span.dim("(dry run — no changes made)"));
|
|
272
|
+
}
|
|
273
|
+
else if (parts.length > 0) {
|
|
274
|
+
out.writeln(span.green(`Done: ${parts.join(", ")}.`));
|
|
275
|
+
}
|
|
276
|
+
else {
|
|
277
|
+
out.writeln(span.dim("Nothing to do."));
|
|
278
|
+
}
|
|
279
|
+
await out.close();
|
|
280
|
+
return primitives.results.ok(undefined);
|
|
281
|
+
};
|
|
282
|
+
// =============================================================================
|
|
283
|
+
// Uninstall
|
|
284
|
+
// =============================================================================
|
|
285
|
+
/**
|
|
286
|
+
* Remove all managed git hooks (those containing the `@eser managed hook` marker).
|
|
287
|
+
*/
|
|
288
|
+
export const uninstallMain = async (cliArgs) => {
|
|
289
|
+
const parsed = parseHelpArgs(cliArgs);
|
|
290
|
+
const out = streams.output({
|
|
291
|
+
renderer,
|
|
292
|
+
sink: streams.sinks.stdout(),
|
|
293
|
+
});
|
|
294
|
+
if (parsed.help) {
|
|
295
|
+
out.writeln("eser codebase uninstall — Remove managed git hooks");
|
|
296
|
+
await out.close();
|
|
297
|
+
return primitives.results.ok(undefined);
|
|
298
|
+
}
|
|
299
|
+
const gitDir = await findGitDir();
|
|
300
|
+
if (gitDir === null) {
|
|
301
|
+
out.writeln(span.red("Error: not inside a git repository"));
|
|
302
|
+
await out.close();
|
|
303
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
304
|
+
}
|
|
305
|
+
const hooksDir = standards.crossRuntime.runtime.path.join(gitDir, "hooks");
|
|
306
|
+
// Each known hook file is independent, so they are checked and removed
|
|
307
|
+
// concurrently; the report below keeps the order of the list.
|
|
308
|
+
const knownHooks = Object.values(EVENT_TO_HOOK).map((m) => m.hookName);
|
|
309
|
+
const uniqueHooks = [...new Set(knownHooks)];
|
|
310
|
+
const removedHooks = await Promise.all(uniqueHooks.map(async (hookName) => {
|
|
311
|
+
const hookPath = standards.crossRuntime.runtime.path.join(hooksDir, hookName);
|
|
312
|
+
try {
|
|
313
|
+
const content = await standards.crossRuntime.runtime.fs.readTextFile(hookPath);
|
|
314
|
+
if (!content.includes(MARKER)) {
|
|
315
|
+
return false;
|
|
316
|
+
}
|
|
317
|
+
await standards.crossRuntime.runtime.fs.remove(hookPath);
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
catch {
|
|
321
|
+
// file doesn't exist — skip
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
}));
|
|
325
|
+
let removed = 0;
|
|
326
|
+
for (const [index, hookName] of uniqueHooks.entries()) {
|
|
327
|
+
if (removedHooks[index] === true) {
|
|
328
|
+
out.writeln(span.green(` removed ${hookName}`));
|
|
329
|
+
removed++;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
out.writeln();
|
|
333
|
+
if (removed > 0) {
|
|
334
|
+
out.writeln(span.green(`Done: ${removed} hook(s) removed.`));
|
|
335
|
+
}
|
|
336
|
+
else {
|
|
337
|
+
out.writeln(span.dim("No managed hooks found."));
|
|
338
|
+
}
|
|
339
|
+
await out.close();
|
|
340
|
+
return primitives.results.ok(undefined);
|
|
341
|
+
};
|
|
342
|
+
// =============================================================================
|
|
343
|
+
// Status
|
|
344
|
+
// =============================================================================
|
|
345
|
+
/**
|
|
346
|
+
* Show the installation status of git hooks expected by the manifest.
|
|
347
|
+
*/
|
|
348
|
+
export const statusMain = async (cliArgs) => {
|
|
349
|
+
const parsed = parseHelpArgs(cliArgs);
|
|
350
|
+
const out = streams.output({
|
|
351
|
+
renderer,
|
|
352
|
+
sink: streams.sinks.stdout(),
|
|
353
|
+
});
|
|
354
|
+
if (parsed.help) {
|
|
355
|
+
out.writeln("eser codebase status — Show git hook installation status");
|
|
356
|
+
await out.close();
|
|
357
|
+
return primitives.results.ok(undefined);
|
|
358
|
+
}
|
|
359
|
+
const gitDir = await findGitDir();
|
|
360
|
+
if (gitDir === null) {
|
|
361
|
+
out.writeln(span.red("Error: not inside a git repository"));
|
|
362
|
+
await out.close();
|
|
363
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
364
|
+
}
|
|
365
|
+
const hooksDir = standards.crossRuntime.runtime.path.join(gitDir, "hooks");
|
|
366
|
+
// Load manifest
|
|
367
|
+
const cwd = standards.crossRuntime.runtime.process.cwd();
|
|
368
|
+
const raw = await configManifest.loadManifest(cwd);
|
|
369
|
+
if (raw === null) {
|
|
370
|
+
out.writeln(span.red("Error: no .eser/manifest.yml found in current directory"));
|
|
371
|
+
await out.close();
|
|
372
|
+
return primitives.results.fail({ exitCode: 1 });
|
|
373
|
+
}
|
|
374
|
+
const events = extractEvents(raw);
|
|
375
|
+
if (events.length === 0) {
|
|
376
|
+
out.writeln(span.dim("No workflow events found in manifest."));
|
|
377
|
+
await out.close();
|
|
378
|
+
return primitives.results.ok(undefined);
|
|
379
|
+
}
|
|
380
|
+
// The hook files are only read, so they are read concurrently; the report
|
|
381
|
+
// below keeps the manifest order.
|
|
382
|
+
const statuses = await Promise.all(events.map(async (event) => {
|
|
383
|
+
const mapping = EVENT_TO_HOOK[event];
|
|
384
|
+
if (mapping === undefined) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
const hookPath = standards.crossRuntime.runtime.path.join(hooksDir, mapping.hookName);
|
|
388
|
+
try {
|
|
389
|
+
const content = await standards.crossRuntime.runtime.fs.readTextFile(hookPath);
|
|
390
|
+
return content.includes(MARKER)
|
|
391
|
+
? span.green("managed (@eser)")
|
|
392
|
+
: span.yellow("user hook");
|
|
393
|
+
}
|
|
394
|
+
catch {
|
|
395
|
+
return span.dim("not installed");
|
|
396
|
+
}
|
|
397
|
+
}));
|
|
398
|
+
out.writeln(span.bold("Git hook status:"));
|
|
399
|
+
out.writeln();
|
|
400
|
+
for (const [index, event] of events.entries()) {
|
|
401
|
+
const mapping = EVENT_TO_HOOK[event];
|
|
402
|
+
const statusSpan = statuses[index] ?? null;
|
|
403
|
+
if (mapping === undefined || statusSpan === null) {
|
|
404
|
+
out.writeln(span.text(" "), span.dim(event.padEnd(14)), span.text(" "), span.dim("(no hook mapping)"));
|
|
405
|
+
continue;
|
|
406
|
+
}
|
|
407
|
+
out.writeln(span.text(` ${mapping.hookName.padEnd(14)} `), statusSpan);
|
|
408
|
+
}
|
|
409
|
+
out.writeln();
|
|
410
|
+
await out.close();
|
|
411
|
+
return primitives.results.ok(undefined);
|
|
412
|
+
};
|
|
413
|
+
// =============================================================================
|
|
414
|
+
// Direct execution
|
|
415
|
+
// =============================================================================
|
|
416
|
+
if (import.meta.main) {
|
|
417
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
418
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
419
|
+
const result = await main(standards.crossRuntime.runtime.process.args);
|
|
420
|
+
cliSupport.runCliMain(result);
|
|
421
|
+
}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The standalone CLI of @eserstack/codebase. The package's `.` export runs this
|
|
3
|
+
* CLI, and the library is published at `/mod`:
|
|
4
|
+
*
|
|
5
|
+
* ```typescript
|
|
6
|
+
* import * as codebase from "@eserstack/codebase/mod";
|
|
7
|
+
*
|
|
8
|
+
* const packages = await codebase.discoverPackages(".");
|
|
9
|
+
* ```
|
|
10
|
+
*
|
|
11
|
+
* Usage:
|
|
12
|
+
* npx eser codebase versions
|
|
13
|
+
* node ./main.ts release
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
16
|
+
*/
|
|
17
|
+
import type * as results from "@eserstack/primitives/results";
|
|
18
|
+
/** Parse the process arguments and run the matching codebase command. */
|
|
19
|
+
export declare const main: () => Promise<results.Result<void, {
|
|
20
|
+
message?: string;
|
|
21
|
+
exitCode: number;
|
|
22
|
+
}>>;
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
import * as module from "./module.js";
|
|
3
|
+
import * as cliSupport from "./cli-support.js";
|
|
4
|
+
import config from "./package.json" with { type: "json" };
|
|
5
|
+
const app = module.moduleDef.toCommand("codebase", config.version);
|
|
6
|
+
/** Parse the process arguments and run the matching codebase command. */
|
|
7
|
+
export const main = async () => {
|
|
8
|
+
return await app.parse();
|
|
9
|
+
};
|
|
10
|
+
if (import.meta.main) {
|
|
11
|
+
// Entry point: the await only runs when this file is executed directly.
|
|
12
|
+
// oxlint-disable-next-line node/no-top-level-await
|
|
13
|
+
await cliSupport.exitCli(await main());
|
|
14
|
+
}
|
package/dist/mod.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codebase management utilities for workspace discovery, git operations,
|
|
3
|
+
* and package configuration validation.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```typescript
|
|
7
|
+
* import * as codebase from "@eserstack/codebase/mod";
|
|
8
|
+
*
|
|
9
|
+
* // Git operations
|
|
10
|
+
* const commits = await codebase.getCommitsBetween("HEAD~5", "HEAD");
|
|
11
|
+
*
|
|
12
|
+
* // Workspace discovery
|
|
13
|
+
* const packages = await codebase.discoverPackages(".");
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
17
|
+
*/
|
|
18
|
+
export type { Commit, CommitUser } from "./git.ts";
|
|
19
|
+
export { checkout, checkoutPrevious, commit, createAndCheckoutBranch, createTag, getCommitsBetween, getCommitsSinceDate, getCurrentBranch, getLatestTag, push, pushTag, stageAll, } from "./git.ts";
|
|
20
|
+
export type { ConfigFileType, FieldMapping, FieldOrigin, LoadOptions, PackageConfig, PackageFieldName, RawConfigFile, TrackedField, UpdateOptions, UpdateResult, WorkspaceModule, } from "./package/mod.ts";
|
|
21
|
+
export { baseDirProp, CONFIG_FILE_PRIORITY, ConfigFileTypes, DEFAULT_FIELD_MAPPINGS, getBaseDir, getFilesWithField, getModule, getUpdateTargets, getWorkspaceModules, load, loadPackageConfig, PackageLoadError, PackageUpdateError, syncField, tryLoad, updateField, updateFields, updateVersion, } from "./package/mod.ts";
|
|
22
|
+
export type { DiscoveredPackage } from "./workspace-discovery.ts";
|
|
23
|
+
export { discoverPackages, extractEntrypoints, getPackageFiles, getWorkspace, resolveModulePath, } from "./workspace-discovery.ts";
|
|
24
|
+
export type { DirectiveAnalysisOptions, DirectiveMatch, DirectiveName, } from "./directive-analysis.ts";
|
|
25
|
+
export { analyzeClientComponents, analyzeDirectives, analyzeServerActions, containsDirective, DIRECTIVES, extractExports, hasDirective, } from "./directive-analysis.ts";
|
package/dist/mod.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright 2023-present Eser Ozvataf and other contributors. All rights reserved. Apache-2.0 license.
|
|
2
|
+
export { checkout, checkoutPrevious, commit, createAndCheckoutBranch, createTag, getCommitsBetween, getCommitsSinceDate, getCurrentBranch, getLatestTag, push, pushTag, stageAll, } from "./git.js";
|
|
3
|
+
export { baseDirProp, CONFIG_FILE_PRIORITY, ConfigFileTypes, DEFAULT_FIELD_MAPPINGS, getBaseDir, getFilesWithField, getModule, getUpdateTargets, getWorkspaceModules, load, loadPackageConfig, PackageLoadError, PackageUpdateError, syncField, tryLoad, updateField, updateFields, updateVersion, } from "./package/mod.js";
|
|
4
|
+
export { discoverPackages, extractEntrypoints, getPackageFiles, getWorkspace, resolveModulePath, } from "./workspace-discovery.js";
|
|
5
|
+
export { analyzeClientComponents, analyzeDirectives, analyzeServerActions, containsDirective, DIRECTIVES, extractExports, hasDirective, } from "./directive-analysis.js";
|
|
6
|
+
// CLI scripts are accessed via their own entry points in package.json exports,
|
|
7
|
+
// not through this barrel. Each exports a `main` function which would collide.
|
|
8
|
+
// Import directly: @eserstack/codebase/validate-circular-deps, @eserstack/codebase/versions, etc.
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codebase module definition for @eserstack/shell integration.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import * as module from "@eserstack/shell/module";
|
|
7
|
+
/** The command module type, `Module` from `@eserstack/shell/module`. */
|
|
8
|
+
export type Module = module.Module;
|
|
9
|
+
/** The `codebase` command group: git hooks, GitHub, release, validators. */
|
|
10
|
+
export declare const moduleDef: Module;
|