@cejel/cejel 0.1.1 → 0.1.3

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/dist/index.js CHANGED
@@ -5,10 +5,10 @@ import {
5
5
  renderWitanBadgeSvg,
6
6
  renderWitanHtmlReport,
7
7
  runCejelScan
8
- } from "./chunk-H5T65GGS.js";
8
+ } from "./chunk-QQVCIG4N.js";
9
9
 
10
10
  // src/index.ts
11
- import { mkdirSync, realpathSync, writeFileSync } from "fs";
11
+ import { mkdirSync, readFileSync, realpathSync, writeFileSync } from "fs";
12
12
  import { join, resolve } from "path";
13
13
  import { pathToFileURL } from "url";
14
14
 
@@ -73,12 +73,88 @@ function formatScore(score) {
73
73
 
74
74
  // src/index.ts
75
75
  var DEFAULT_OUT_DIR = ".cejel";
76
+ var CLI_FLAG_SPECS = [
77
+ {
78
+ tokens: ["--out", "--out-dir"],
79
+ value: "<dir>",
80
+ description: "write the certificate here (default: .cejel; --out-dir is a compatibility alias)",
81
+ kind: "out"
82
+ },
83
+ {
84
+ tokens: ["--min-score"],
85
+ value: "<0-4>",
86
+ description: "exit nonzero below this overall score",
87
+ kind: "minScore"
88
+ },
89
+ {
90
+ tokens: ["--ingest"],
91
+ value: "<file>",
92
+ description: "fold in a SARIF/JSON scanner report (repeatable)",
93
+ kind: "ingest"
94
+ },
95
+ {
96
+ tokens: ["--quiet"],
97
+ description: "suppress the terminal summary",
98
+ kind: "quiet"
99
+ },
100
+ {
101
+ tokens: ["-h", "--help"],
102
+ description: "show this help",
103
+ kind: "help"
104
+ },
105
+ {
106
+ tokens: ["-v", "--version"],
107
+ description: "print the version",
108
+ kind: "version"
109
+ }
110
+ ];
111
+ var CLI_FLAG_TOKENS = CLI_FLAG_SPECS.flatMap(
112
+ (spec) => spec.tokens
113
+ );
114
+ var CLI_FLAG_KIND_BY_TOKEN = new Map(
115
+ CLI_FLAG_SPECS.flatMap((spec) => spec.tokens.map((token) => [token, spec.kind]))
116
+ );
117
+ function cliVersion() {
118
+ const manifest = JSON.parse(
119
+ readFileSync(new URL("../package.json", import.meta.url), "utf8")
120
+ );
121
+ if (typeof manifest.version !== "string" || manifest.version.length === 0) {
122
+ throw new Error("Cejel package manifest has no version.");
123
+ }
124
+ return manifest.version;
125
+ }
126
+ var usageOptionLabels = CLI_FLAG_SPECS.map(
127
+ (spec) => `${spec.tokens.join(", ")}${"value" in spec && spec.value ? ` ${spec.value}` : ""}`
128
+ );
129
+ var usageOptionLabelWidth = Math.max(...usageOptionLabels.map((label) => label.length));
130
+ var usageOptions = CLI_FLAG_SPECS.map(
131
+ (spec, index) => ` ${usageOptionLabels[index]?.padEnd(usageOptionLabelWidth)} ${spec.description}`
132
+ ).join("\n");
133
+ var USAGE = `cejel \u2014 a trust certificate for your codebase
134
+
135
+ Usage: npx @cejel/cejel [path] [options]
136
+
137
+ Options:
138
+ ${usageOptions}
139
+
140
+ Runs entirely offline. No code leaves your machine.
141
+ Docs: https://cejel.dev
142
+ `;
76
143
  async function main() {
77
144
  const exitCode = await runWitanFreeCli(process.argv.slice(2));
78
145
  process.exitCode = exitCode;
79
146
  }
80
147
  async function runWitanFreeCli(args) {
81
148
  const options = parseArgs(args);
149
+ if (options.showVersion) {
150
+ process.stdout.write(`${cliVersion()}
151
+ `);
152
+ return 0;
153
+ }
154
+ if (options.showHelp) {
155
+ process.stdout.write(USAGE);
156
+ return 0;
157
+ }
82
158
  const { report, summary } = runCejelScan({
83
159
  repoPath: options.repoPath,
84
160
  ingestPatterns: options.ingestPatterns,
@@ -120,42 +196,55 @@ function parseArgs(args) {
120
196
  let outDir = DEFAULT_OUT_DIR;
121
197
  let minScore;
122
198
  let quiet = false;
199
+ let showHelp = false;
200
+ let showVersion = false;
123
201
  const ingestPatterns = [];
124
202
  for (let index = 0; index < args.length; index += 1) {
125
203
  const arg = args[index];
126
204
  if (arg === "--" || arg === void 0) continue;
127
- if (arg === "--quiet") {
128
- quiet = true;
129
- continue;
130
- }
131
- if (arg === "--out-dir") {
132
- const value = args[index + 1];
133
- if (!value) throw new Error("Missing value for --out-dir");
134
- outDir = value;
135
- index += 1;
136
- continue;
205
+ const flagKind = CLI_FLAG_KIND_BY_TOKEN.get(arg);
206
+ if (!flagKind && arg.startsWith("-")) {
207
+ throw new Error(`Unknown Cejel CLI flag: ${arg}`);
137
208
  }
138
- if (arg === "--min-score") {
139
- const value = args[index + 1];
140
- if (!value) throw new Error("Missing value for --min-score");
141
- const parsed = Number(value);
142
- if (!Number.isFinite(parsed) || parsed < 0 || parsed > 4) {
143
- throw new Error(`--min-score must be between 0 and 4, got: ${value}`);
209
+ if (flagKind) {
210
+ switch (flagKind) {
211
+ case "help":
212
+ showHelp = true;
213
+ break;
214
+ case "version":
215
+ showVersion = true;
216
+ break;
217
+ case "quiet":
218
+ quiet = true;
219
+ break;
220
+ case "out": {
221
+ const value = args[index + 1];
222
+ if (!value) throw new Error(`Missing value for ${arg}`);
223
+ outDir = value;
224
+ index += 1;
225
+ break;
226
+ }
227
+ case "minScore": {
228
+ const value = args[index + 1];
229
+ if (!value) throw new Error("Missing value for --min-score");
230
+ const parsed = Number(value);
231
+ if (!Number.isFinite(parsed) || parsed < 0 || parsed > 4) {
232
+ throw new Error(`--min-score must be between 0 and 4, got: ${value}`);
233
+ }
234
+ minScore = parsed;
235
+ index += 1;
236
+ break;
237
+ }
238
+ case "ingest": {
239
+ const value = args[index + 1];
240
+ if (!value) throw new Error("Missing value for --ingest");
241
+ ingestPatterns.push(value);
242
+ index += 1;
243
+ break;
244
+ }
144
245
  }
145
- minScore = parsed;
146
- index += 1;
147
246
  continue;
148
247
  }
149
- if (arg === "--ingest") {
150
- const value = args[index + 1];
151
- if (!value) throw new Error("Missing value for --ingest");
152
- ingestPatterns.push(value);
153
- index += 1;
154
- continue;
155
- }
156
- if (arg.startsWith("--")) {
157
- throw new Error(`Unknown Cejel CLI flag: ${arg}`);
158
- }
159
248
  if (repoPath === void 0) repoPath = arg;
160
249
  }
161
250
  return {
@@ -163,6 +252,8 @@ function parseArgs(args) {
163
252
  outDir,
164
253
  ...minScore != null ? { minScore } : {},
165
254
  quiet,
255
+ showHelp,
256
+ showVersion,
166
257
  ingestPatterns
167
258
  };
168
259
  }
@@ -186,6 +277,9 @@ if (isEntryPoint()) {
186
277
  });
187
278
  }
188
279
  export {
280
+ CLI_FLAG_SPECS,
281
+ CLI_FLAG_TOKENS,
282
+ USAGE,
189
283
  parseArgs,
190
284
  runWitanFreeCli
191
285
  };