@openpolicy/cli 0.0.9 → 0.0.10

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.
Files changed (3) hide show
  1. package/README.md +66 -2
  2. package/dist/cli.js +30 -18
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -1,3 +1,67 @@
1
- # OpenPolicy CLI
1
+ # `@openpolicy/cli`
2
2
 
3
- This is the CLI package for the OpenPolicy project.
3
+ > CLI for generating and validating [OpenPolicy](https://openpolicy.sh) policy documents.
4
+
5
+ Compile privacy policies and terms of service to Markdown or HTML from the command line — no Vite or Astro required.
6
+
7
+ ## Install
8
+
9
+ ```sh
10
+ bun add -D @openpolicy/cli
11
+ bun add @openpolicy/sdk
12
+ # or: npm install --save-dev @openpolicy/cli @openpolicy/sdk
13
+ ```
14
+
15
+ Or run without installing:
16
+
17
+ ```sh
18
+ bunx @openpolicy/cli --help
19
+ ```
20
+
21
+ ## Commands
22
+
23
+ ### `init` — interactive setup wizard
24
+
25
+ Creates a starter config file with placeholder content:
26
+
27
+ ```sh
28
+ openpolicy init # privacy policy (default)
29
+ openpolicy init --type terms # terms of service
30
+ ```
31
+
32
+ ### `generate` — compile a policy
33
+
34
+ ```sh
35
+ openpolicy generate ./privacy.config.ts --format markdown,html --out ./public/policies
36
+ openpolicy generate ./terms.config.ts --format markdown --out ./public/policies
37
+ ```
38
+
39
+ | Flag | Default | Description |
40
+ |---|---|---|
41
+ | `--format` | `markdown` | Comma-separated output formats: `markdown`, `html` |
42
+ | `--out` | `./public/policies` | Output directory |
43
+ | `--type` | auto-detected | Override policy type: `privacy` or `terms` |
44
+
45
+ Policy type is auto-detected from the filename — files containing `"terms"` compile as terms of service.
46
+
47
+ ### `validate` — check a policy config
48
+
49
+ ```sh
50
+ openpolicy validate ./privacy.config.ts
51
+ openpolicy validate ./privacy.config.ts --jurisdiction gdpr
52
+ ```
53
+
54
+ | Flag | Default | Description |
55
+ |---|---|---|
56
+ | `--jurisdiction` | `all` | Validate against: `gdpr`, `ccpa`, or `all` |
57
+ | `--type` | auto-detected | Override policy type: `privacy` or `terms` |
58
+
59
+ ## Documentation
60
+
61
+ [openpolicy.sh/docs/getting-started/cli](https://openpolicy.sh/docs/getting-started/cli)
62
+
63
+ ## Links
64
+
65
+ - [GitHub](https://github.com/jamiedavenport/openpolicy)
66
+ - [openpolicy.sh](https://openpolicy.sh)
67
+ - [npm](https://www.npmjs.com/package/@openpolicy/cli)
package/dist/cli.js CHANGED
@@ -2,6 +2,7 @@
2
2
  import { defineCommand, runMain } from "citty";
3
3
  import { join, resolve } from "node:path";
4
4
  import consola from "consola";
5
+ import { access, mkdir, writeFile } from "node:fs/promises";
5
6
  import { compilePolicy, validatePrivacyPolicy, validateTermsOfService } from "@openpolicy/core";
6
7
  import { existsSync } from "node:fs";
7
8
  //#region \0rolldown/runtime.js
@@ -309,8 +310,8 @@ var init_generate = __esmMin((() => {
309
310
  args: {
310
311
  config: {
311
312
  type: "positional",
312
- description: "Path to policy config file",
313
- default: "./policy.config.ts"
313
+ description: "Path(s) to policy config file(s), comma-separated",
314
+ default: "./policy.config.ts,./terms.config.ts"
314
315
  },
315
316
  format: {
316
317
  type: "string",
@@ -331,22 +332,33 @@ var init_generate = __esmMin((() => {
331
332
  async run({ args }) {
332
333
  const formats = (args.format ?? "markdown").split(",").map((f) => f.trim()).filter(Boolean);
333
334
  const outDir = args.out ?? "./output";
334
- const configPath = args.config ?? "./policy.config.ts";
335
- const policyType = detectType(args.type || void 0, configPath);
336
- consola.start(`Generating ${policyType} policy from ${configPath} formats: ${formats.join(", ")}`);
337
- const config = await loadConfig(configPath);
338
- const outputFilename = policyType === "terms" ? "terms-of-service" : "privacy-policy";
339
- const results = compilePolicy(policyType === "terms" ? {
340
- type: "terms",
341
- ...config
342
- } : {
343
- type: "privacy",
344
- ...config
345
- }, { formats });
346
- for (const result of results) {
347
- const outPath = join(outDir, `${outputFilename}.${result.format === "markdown" ? "md" : result.format}`);
348
- await Bun.write(outPath, result.content);
349
- consola.success(`Written: ${outPath}`);
335
+ const configPaths = (args.config ?? "./policy.config.ts,./terms.config.ts").split(",").map((p) => p.trim()).filter(Boolean);
336
+ const isMulti = configPaths.length > 1;
337
+ for (const configPath of configPaths) {
338
+ if (!await access(configPath).then(() => true).catch(() => false)) {
339
+ if (isMulti) {
340
+ consola.warn(`Config not found, skipping: ${configPath}`);
341
+ continue;
342
+ }
343
+ throw new Error(`Config not found: ${configPath}`);
344
+ }
345
+ const policyType = detectType(args.type || void 0, configPath);
346
+ consola.start(`Generating ${policyType} policy from ${configPath} formats: ${formats.join(", ")}`);
347
+ const config = await loadConfig(configPath);
348
+ const outputFilename = policyType === "terms" ? "terms-of-service" : "privacy-policy";
349
+ const results = compilePolicy(policyType === "terms" ? {
350
+ type: "terms",
351
+ ...config
352
+ } : {
353
+ type: "privacy",
354
+ ...config
355
+ }, { formats });
356
+ await mkdir(outDir, { recursive: true });
357
+ for (const result of results) {
358
+ const outPath = join(outDir, `${outputFilename}.${result.format === "markdown" ? "md" : result.format}`);
359
+ await writeFile(outPath, result.content, "utf-8");
360
+ consola.success(`Written: ${outPath}`);
361
+ }
350
362
  }
351
363
  consola.success(`Policy generation complete → ${outDir}`);
352
364
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openpolicy/cli",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "type": "module",
5
5
  "description": "CLI for generating and validating OpenPolicy privacy policy documents",
6
6
  "license": "MIT",