@codelitdev/platform-cli 0.1.0-alpha.0 → 0.2.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.
Files changed (51) hide show
  1. package/README.md +77 -0
  2. package/dist/bin.js +7 -9
  3. package/dist/create.js +11 -20
  4. package/dist/doctor.js +1 -1
  5. package/dist/git.js +2 -2
  6. package/dist/index.d.ts +1 -2
  7. package/dist/index.js +1 -2
  8. package/dist/manifest.d.ts +8 -4
  9. package/dist/manifest.js +27 -5
  10. package/dist/preset.d.ts +26 -0
  11. package/dist/preset.js +110 -0
  12. package/dist/preset.json +70 -0
  13. package/dist/sync.d.ts +20 -0
  14. package/dist/sync.js +87 -0
  15. package/dist/template.d.ts +15 -0
  16. package/dist/template.js +33 -1
  17. package/package.json +14 -7
  18. package/template/.github/dependabot.yml +15 -0
  19. package/template/.github/workflows/code-quality.yml +31 -0
  20. package/template/.github/workflows/platform-conformance.yml +4 -3
  21. package/template/README.md +3 -2
  22. package/template/apps/api/.env.example +2 -1
  23. package/template/apps/api/README.md +3 -0
  24. package/template/apps/api/package.json +20 -17
  25. package/template/apps/api/scripts/generate-auth-schema.mjs +2 -2
  26. package/template/apps/api/src/app.test.ts +83 -0
  27. package/template/apps/api/src/auth/authenticate.ts +2 -2
  28. package/template/apps/api/src/auth/options.ts +11 -4
  29. package/template/apps/api/src/billing.ts +1 -1
  30. package/template/apps/api/src/db/migrations/0000_auth.sql +0 -1
  31. package/template/apps/api/src/db/schema/auth.generated.ts +1 -2
  32. package/template/apps/api/src/dispatch.ts +8 -1
  33. package/template/apps/api/src/express-app.ts +29 -2
  34. package/template/apps/api/src/main.ts +3 -10
  35. package/template/apps/api/src/runtime.ts +2 -2
  36. package/template/apps/api/src/seed.ts +7 -5
  37. package/template/apps/web/app/globals.css +0 -10
  38. package/template/apps/web/app/layout.tsx +1 -1
  39. package/template/apps/web/app/login/page.tsx +6 -45
  40. package/template/apps/web/app/page.tsx +1 -1
  41. package/template/apps/web/next-env.d.ts +4 -0
  42. package/template/apps/web/package.json +8 -8
  43. package/template/apps/web/tsconfig.json +1 -1
  44. package/template/package.json +0 -1
  45. package/template/packages/api-contract/package.json +3 -3
  46. package/dist/codemod-readme-title.d.ts +0 -5
  47. package/dist/codemod-readme-title.js +0 -21
  48. package/dist/upgrade.d.ts +0 -13
  49. package/dist/upgrade.js +0 -97
  50. package/template/apps/api/src/logger.ts +0 -26
  51. package/template/tooling/platform/config.ts +0 -2
package/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # @codelitdev/platform-cli
2
+
3
+ Create a CodeLit Platform product, check its Platform configuration, and keep
4
+ its CLI-managed files current. The CLI runs locally in the product repository;
5
+ it does not deploy the product or run its conformance tests.
6
+
7
+ ## Commands
8
+
9
+ | Command | Where to run it | What it does |
10
+ | --- | --- | --- |
11
+ | `bunx @codelitdev/platform-cli create my-product` | From the parent directory | Creates a product in a new or empty `my-product` directory from the packaged template. |
12
+ | `bunx @codelitdev/platform-cli doctor` | From a product root | Checks its `.codelit-platform.json` manifest, managed-file hashes, and resolved package versions against the compatibility preset bundled with this CLI release. |
13
+ | `bunx @codelitdev/platform-cli sync --dry-run` | From a product root | Reports the managed files `sync` would write and any conflicts, without writing. |
14
+ | `bunx @codelitdev/platform-cli sync` | From a clean Git worktree | Rewrites the managed files from this CLI release's template and updates the manifest. |
15
+
16
+ Pin the CLI version in automated workflows and use a frozen product lockfile.
17
+ `create` copies the template and pins its CodeLit dependencies to the preset's
18
+ recommended versions; it does not install dependencies or create a lockfile.
19
+ After creation, install dependencies in the new product, review its
20
+ configuration, and commit the lockfile.
21
+
22
+ ## Managed and product-owned files
23
+
24
+ `create` records a `.codelit-platform.json` manifest with the product's name
25
+ and slug, the CLI version, declared capabilities, and exact hashes
26
+ of the CLI-managed files. Today that is one file,
27
+ `.github/workflows/platform-conformance.yml`.
28
+
29
+ Everything else, including `.github/workflows/code-quality.yml`, belongs to
30
+ the product after `create`. The CLI never changes product-owned files.
31
+
32
+ `doctor` is read-only. It prints a JSON report such as
33
+ `{"ok":true,"issues":[]}` and exits nonzero when issues exist. A successful
34
+ check says nothing about product behavior.
35
+
36
+ ## Sync
37
+
38
+ All `@codelitdev/*` packages release together under one version. To move a
39
+ product to a release, update its Platform dependencies, then run that
40
+ release's `sync`:
41
+
42
+ ```sh
43
+ bunx @codelitdev/platform-cli@0.2.0 sync --dry-run
44
+ bunx @codelitdev/platform-cli@0.2.0 sync
45
+ ```
46
+
47
+ `sync` renders each managed file from the template shipped with the CLI. It
48
+ replaces a file only when its hash still matches the manifest, and creates a
49
+ newly managed file only when it is absent or already identical. Any other
50
+ difference is a conflict: nothing is written, and you reconcile the file by
51
+ hand. Writes require a clean Git worktree; `--dry-run` works in a dirty one. If
52
+ writing fails, the CLI restores the files it changed.
53
+
54
+ When a release requires changes to product-owned files, its release notes say
55
+ so; apply them yourself. Manifests written by earlier CLI releases
56
+ (`schemaVersion: 1`) are migrated on the next `sync`.
57
+
58
+ ## CI
59
+
60
+ `create` writes two workflows:
61
+
62
+ - `platform-conformance.yml` (managed): runs `doctor` with the exact CLI
63
+ version that wrote the file, the API package's `check:drift`, and its
64
+ `test:conformance` script. The job fails if the API package has no
65
+ `test:conformance` script. Make it a required pull-request check, and gate
66
+ Platform update pull requests on it.
67
+ - `code-quality.yml` (product-owned): lint, typecheck, test, and build. Edit
68
+ it freely.
69
+
70
+ `create` also writes a product-owned `.github/dependabot.yml` that opens one
71
+ grouped pull request per Platform release.
72
+
73
+ `doctor` checks configuration and compatibility; conformance checks the
74
+ running product's behavior.
75
+
76
+ The package also exports `createProduct`, `doctor`, and `syncProduct` for
77
+ programmatic use. Their options and return types are declared in `dist`.
package/dist/bin.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import { createProduct } from "./create.js";
3
3
  import { doctor } from "./doctor.js";
4
- import { upgradeProduct } from "./upgrade.js";
4
+ import { syncProduct } from "./sync.js";
5
+ import { productNameFromTarget } from "./template.js";
5
6
  const [command, ...rest] = process.argv.slice(2);
6
7
  try {
7
8
  if (command === "create") {
@@ -10,7 +11,7 @@ try {
10
11
  throw new Error("usage: codelit-platform create <dir>");
11
12
  const result = createProduct({
12
13
  targetDir: name,
13
- productName: name,
14
+ productName: productNameFromTarget(name),
14
15
  });
15
16
  process.stdout.write(`created ${result.root}\n`);
16
17
  }
@@ -20,20 +21,17 @@ try {
20
21
  if (!report.ok)
21
22
  process.exitCode = 1;
22
23
  }
23
- else if (command === "upgrade") {
24
- const dryRun = rest.includes("--dry-run");
25
- const version = rest.find((arg) => !arg.startsWith("--"));
26
- const result = upgradeProduct({
24
+ else if (command === "sync") {
25
+ const result = syncProduct({
27
26
  root: process.cwd(),
28
- version,
29
- dryRun,
27
+ dryRun: rest.includes("--dry-run"),
30
28
  });
31
29
  process.stdout.write(`${JSON.stringify(result)}\n`);
32
30
  if (result.conflicts.length > 0)
33
31
  process.exitCode = 1;
34
32
  }
35
33
  else {
36
- process.stderr.write("usage: codelit-platform create|doctor|upgrade\n");
34
+ process.stderr.write("usage: codelit-platform create|doctor|sync\n");
37
35
  process.exitCode = 1;
38
36
  }
39
37
  }
package/dist/create.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { existsSync, mkdirSync, readFileSync, renameSync, writeFileSync, } from "node:fs";
2
2
  import path from "node:path";
3
- import { loadPresetManifest } from "@codelitdev/platform-preset";
4
3
  import { copyTemplate, isEmptyDir, listFiles, removeDir, replaceTokens } from "./fs.js";
5
4
  import { sha256File } from "./hash.js";
6
5
  import { writeManifest } from "./manifest.js";
7
- import { resolveTemplateDir, slugify } from "./template.js";
6
+ import { loadPresetManifest } from "./preset.js";
7
+ import { cliVersion, MANAGED_FILES, resolveTemplateDir, slugify, templateTokens, } from "./template.js";
8
8
  export function createProduct(input) {
9
9
  const target = path.resolve(input.targetDir);
10
10
  if (existsSync(target) && !isEmptyDir(target)) {
@@ -16,27 +16,17 @@ export function createProduct(input) {
16
16
  try {
17
17
  copyTemplate(resolveTemplateDir(), staging);
18
18
  renameSync(path.join(staging, "biome.template.json"), path.join(staging, "biome.json"));
19
- replaceTokens(staging, {
20
- __PRODUCT_NAME__: input.productName,
21
- __PRODUCT_SLUG__: slug,
22
- });
23
- pinCodelitVersions(staging, loadPresetManifest());
24
- const managedRel = path.join("tooling", "platform", "config.ts");
25
- const managedPath = path.join(staging, managedRel);
26
- const workflowRel = path.join(".github", "workflows", "platform-conformance.yml");
27
- const workflowPath = path.join(staging, workflowRel);
19
+ const product = { name: input.productName, slug };
20
+ replaceTokens(staging, templateTokens(product));
28
21
  const preset = loadPresetManifest();
22
+ pinCodelitVersions(staging, preset);
29
23
  writeManifest(staging, {
30
- schemaVersion: 1,
31
- templateVersion: "1.0.0",
32
- presetVersion: preset.presetVersion,
24
+ schemaVersion: 2,
25
+ product,
26
+ cliVersion: cliVersion(),
33
27
  capabilities: ["auth", "mcp", "observability", "billing"],
34
- managedFiles: {
35
- [managedRel.replaceAll("\\", "/")]: sha256File(managedPath),
36
- [workflowRel.replaceAll("\\", "/")]: sha256File(workflowPath),
37
- },
28
+ managedFiles: Object.fromEntries(MANAGED_FILES.map((rel) => [rel, sha256File(path.join(staging, rel))])),
38
29
  productOwnedGlobs: ["apps/**", "packages/api-contract/**"],
39
- appliedUpgrades: ["1.0.0"],
40
30
  });
41
31
  validateGeneratedMetadata(staging);
42
32
  mkdirSync(path.dirname(target), { recursive: true });
@@ -60,6 +50,7 @@ function validateGeneratedMetadata(root) {
60
50
  "packages/api-contract/package.json",
61
51
  "apps/api/README.md",
62
52
  ".github/workflows/platform-conformance.yml",
53
+ ".github/workflows/code-quality.yml",
63
54
  ];
64
55
  if (required.some((file) => !files.includes(file))) {
65
56
  throw new Error("create_metadata_invalid");
@@ -72,7 +63,7 @@ function validateGeneratedMetadata(root) {
72
63
  !file.endsWith(".yml"))
73
64
  continue;
74
65
  const content = readFileSync(path.join(root, file), "utf8");
75
- if (content.includes("__PRODUCT_"))
66
+ if (content.includes("__PRODUCT_") || content.includes("__PLATFORM_"))
76
67
  throw new Error("create_tokens_unresolved");
77
68
  }
78
69
  const packageJson = JSON.parse(readFileSync(path.join(root, "package.json"), "utf8"));
package/dist/doctor.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import { existsSync, readdirSync, readFileSync, statSync } from "node:fs";
2
2
  import path from "node:path";
3
- import { loadPresetManifest, validateResolvedVersions, } from "@codelitdev/platform-preset";
4
3
  import { sha256File } from "./hash.js";
5
4
  import { readManifest } from "./manifest.js";
5
+ import { loadPresetManifest, validateResolvedVersions } from "./preset.js";
6
6
  export function doctor(root) {
7
7
  const issues = [];
8
8
  try {
package/dist/git.js CHANGED
@@ -7,13 +7,13 @@ export function assertGitClean(cwd) {
7
7
  });
8
8
  }
9
9
  catch {
10
- throw new Error("upgrade_requires_git_repository");
10
+ throw new Error("sync_requires_git_repository");
11
11
  }
12
12
  const status = execFileSync("git", ["status", "--porcelain"], {
13
13
  cwd,
14
14
  encoding: "utf8",
15
15
  });
16
16
  if (status.trim().length > 0) {
17
- throw new Error("upgrade_requires_clean_worktree");
17
+ throw new Error("sync_requires_clean_worktree");
18
18
  }
19
19
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- export { README_TITLE_CODEMOD } from "./codemod-readme-title.js";
2
1
  export { createProduct } from "./create.js";
3
2
  export { type DoctorReport, doctor } from "./doctor.js";
4
- export { type UpgradeResult, upgradeProduct } from "./upgrade.js";
3
+ export { type SyncResult, syncProduct } from "./sync.js";
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- export { README_TITLE_CODEMOD } from "./codemod-readme-title.js";
2
1
  export { createProduct } from "./create.js";
3
2
  export { doctor } from "./doctor.js";
4
- export { upgradeProduct } from "./upgrade.js";
3
+ export { syncProduct } from "./sync.js";
@@ -1,11 +1,15 @@
1
1
  export type PlatformManifest = {
2
- schemaVersion: 1;
3
- templateVersion: string;
4
- presetVersion: string;
2
+ schemaVersion: 2;
3
+ /** Template tokens; `sync` re-renders managed files with them. */
4
+ product: {
5
+ name: string;
6
+ slug: string;
7
+ };
8
+ /** The CLI release that last wrote the managed files; its preset applies. */
9
+ cliVersion: string;
5
10
  capabilities: string[];
6
11
  managedFiles: Record<string, string>;
7
12
  productOwnedGlobs: string[];
8
- appliedUpgrades: string[];
9
13
  };
10
14
  export declare const MANIFEST_NAME = ".codelit-platform.json";
11
15
  export declare function readManifest(root: string): PlatformManifest;
package/dist/manifest.js CHANGED
@@ -5,13 +5,14 @@ export function readManifest(root) {
5
5
  const file = path.join(root, MANIFEST_NAME);
6
6
  if (!existsSync(file))
7
7
  throw new Error("platform_manifest_missing");
8
- const manifest = JSON.parse(readFileSync(file, "utf8"));
9
- if (manifest.schemaVersion !== 1 ||
10
- typeof manifest.templateVersion !== "string" ||
11
- typeof manifest.presetVersion !== "string" ||
8
+ const raw = JSON.parse(readFileSync(file, "utf8"));
9
+ const manifest = raw.schemaVersion === 1 ? migrateV1(root, raw) : raw;
10
+ if (manifest.schemaVersion !== 2 ||
11
+ typeof manifest.product?.name !== "string" ||
12
+ typeof manifest.product?.slug !== "string" ||
13
+ typeof manifest.cliVersion !== "string" ||
12
14
  !Array.isArray(manifest.capabilities) ||
13
15
  !Array.isArray(manifest.productOwnedGlobs) ||
14
- !Array.isArray(manifest.appliedUpgrades) ||
15
16
  !manifest.managedFiles ||
16
17
  typeof manifest.managedFiles !== "object") {
17
18
  throw new Error("platform_manifest_invalid");
@@ -26,6 +27,27 @@ export function readManifest(root) {
26
27
  }
27
28
  return manifest;
28
29
  }
30
+ /**
31
+ * v1 did not record template tokens. `create` names the root package after
32
+ * the product slug, so the slug doubles as the name, as it does when a
33
+ * product is created from a directory basename.
34
+ */
35
+ function migrateV1(root, manifest) {
36
+ const pkgPath = path.join(root, "package.json");
37
+ const slug = existsSync(pkgPath)
38
+ ? JSON.parse(readFileSync(pkgPath, "utf8")).name
39
+ : undefined;
40
+ if (typeof slug !== "string" || !slug)
41
+ throw new Error("platform_manifest_invalid");
42
+ return {
43
+ schemaVersion: 2,
44
+ product: { name: slug, slug },
45
+ cliVersion: "0.0.0",
46
+ capabilities: manifest.capabilities,
47
+ managedFiles: manifest.managedFiles,
48
+ productOwnedGlobs: manifest.productOwnedGlobs,
49
+ };
50
+ }
29
51
  export function writeManifest(root, manifest) {
30
52
  writeFileSync(path.join(root, MANIFEST_NAME), `${JSON.stringify(manifest, null, 4)}\n`);
31
53
  }
@@ -0,0 +1,26 @@
1
+ export type PackagePin = {
2
+ recommended: string;
3
+ supported: string;
4
+ minimumSecure: string;
5
+ };
6
+ /**
7
+ * Compatibility rules for products: recommended, supported, and minimum-secure
8
+ * versions of each @codelitdev package, plus exact pins for the external
9
+ * packages the template uses. `scripts/sync-preset.mjs` writes `recommended`
10
+ * and `external`; `supported` and `minimumSecure` are hand-maintained.
11
+ */
12
+ export type PresetManifest = {
13
+ schemaVersion: 1;
14
+ runtime: {
15
+ bun: string;
16
+ };
17
+ packages: Record<string, PackagePin>;
18
+ external: Record<string, string>;
19
+ };
20
+ export declare function loadPresetManifest(): PresetManifest;
21
+ export type PresetIssue = {
22
+ packageName: string;
23
+ reason: "below_minimum_secure" | "unsupported" | "external_mismatch" | "unknown_package";
24
+ resolved: string;
25
+ };
26
+ export declare function validateResolvedVersions(resolved: Record<string, string>, manifest?: PresetManifest): PresetIssue[];
package/dist/preset.js ADDED
@@ -0,0 +1,110 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ const manifestPath = join(dirname(fileURLToPath(import.meta.url)), "preset.json");
5
+ export function loadPresetManifest() {
6
+ return JSON.parse(readFileSync(manifestPath, "utf8"));
7
+ }
8
+ function parseVersion(value) {
9
+ const match = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z.-]+))?$/.exec(value);
10
+ if (!match)
11
+ return null;
12
+ return {
13
+ major: Number(match[1]),
14
+ minor: Number(match[2] ?? 0),
15
+ patch: Number(match[3] ?? 0),
16
+ prerelease: match[4]?.split(".") ?? [],
17
+ };
18
+ }
19
+ function cmp(a, b) {
20
+ const pa = parseVersion(a);
21
+ const pb = parseVersion(b);
22
+ if (!pa || !pb)
23
+ return a.localeCompare(b);
24
+ for (const key of ["major", "minor", "patch"]) {
25
+ if (pa[key] !== pb[key])
26
+ return pa[key] - pb[key];
27
+ }
28
+ if (pa.prerelease.length === 0 && pb.prerelease.length > 0)
29
+ return 1;
30
+ if (pa.prerelease.length > 0 && pb.prerelease.length === 0)
31
+ return -1;
32
+ for (let i = 0; i < Math.max(pa.prerelease.length, pb.prerelease.length); i += 1) {
33
+ const left = pa.prerelease[i];
34
+ const right = pb.prerelease[i];
35
+ if (left === undefined)
36
+ return -1;
37
+ if (right === undefined)
38
+ return 1;
39
+ if (left === right)
40
+ continue;
41
+ const leftNumber = /^\d+$/.test(left);
42
+ const rightNumber = /^\d+$/.test(right);
43
+ if (leftNumber && rightNumber)
44
+ return Number(left) - Number(right);
45
+ if (leftNumber)
46
+ return -1;
47
+ if (rightNumber)
48
+ return 1;
49
+ return left.localeCompare(right);
50
+ }
51
+ return 0;
52
+ }
53
+ function satisfies(version, range) {
54
+ const clauses = range.split(/\s+/).filter(Boolean);
55
+ return clauses.every((clause) => {
56
+ const match = /^(>=|<=|>|<|=)?(.+)$/.exec(clause);
57
+ if (!match)
58
+ return false;
59
+ const relation = match[1] ?? "=";
60
+ const result = cmp(version, match[2]);
61
+ if (relation === ">=")
62
+ return result >= 0;
63
+ if (relation === "<=")
64
+ return result <= 0;
65
+ if (relation === ">")
66
+ return result > 0;
67
+ if (relation === "<")
68
+ return result < 0;
69
+ return result === 0;
70
+ });
71
+ }
72
+ export function validateResolvedVersions(resolved, manifest = loadPresetManifest()) {
73
+ const issues = [];
74
+ for (const [name, version] of Object.entries(resolved)) {
75
+ const pin = manifest.packages[name];
76
+ if (!pin && name in manifest.external) {
77
+ if (cmp(version, manifest.external[name]) !== 0) {
78
+ issues.push({
79
+ packageName: name,
80
+ reason: "external_mismatch",
81
+ resolved: version,
82
+ });
83
+ }
84
+ continue;
85
+ }
86
+ if (!pin) {
87
+ issues.push({
88
+ packageName: name,
89
+ reason: "unknown_package",
90
+ resolved: version,
91
+ });
92
+ continue;
93
+ }
94
+ if (cmp(version, pin.minimumSecure) < 0) {
95
+ issues.push({
96
+ packageName: name,
97
+ reason: "below_minimum_secure",
98
+ resolved: version,
99
+ });
100
+ }
101
+ if (!satisfies(version, pin.supported)) {
102
+ issues.push({
103
+ packageName: name,
104
+ reason: "unsupported",
105
+ resolved: version,
106
+ });
107
+ }
108
+ }
109
+ return issues;
110
+ }
@@ -0,0 +1,70 @@
1
+ {
2
+ "schemaVersion": 1,
3
+ "runtime": {
4
+ "bun": "1.4.1"
5
+ },
6
+ "packages": {
7
+ "@codelitdev/platform": {
8
+ "recommended": "0.2.0",
9
+ "supported": ">=0.1.0-alpha.0 <2",
10
+ "minimumSecure": "0.1.0-alpha.0"
11
+ },
12
+ "@codelitdev/observability": {
13
+ "recommended": "0.2.0",
14
+ "supported": ">=0.1.0-alpha.0 <2",
15
+ "minimumSecure": "0.1.0-alpha.0"
16
+ },
17
+ "@codelitdev/mcp-server-kit": {
18
+ "recommended": "0.2.0",
19
+ "supported": ">=0.1.0-alpha.0 <2",
20
+ "minimumSecure": "0.1.0-alpha.0"
21
+ },
22
+ "@codelitdev/platform-conformance": {
23
+ "recommended": "0.2.0",
24
+ "supported": ">=0.1.0-alpha.0 <2",
25
+ "minimumSecure": "0.1.0-alpha.0"
26
+ },
27
+ "@codelitdev/platform-cli": {
28
+ "recommended": "0.2.0",
29
+ "supported": ">=0.1.0-alpha.0 <2",
30
+ "minimumSecure": "0.1.0-alpha.0"
31
+ },
32
+ "@codelitdev/billing": {
33
+ "recommended": "0.2.0",
34
+ "supported": ">=0.1.0-alpha.4 <1",
35
+ "minimumSecure": "0.1.0-alpha.4"
36
+ },
37
+ "@codelitdev/oauth-server-kit": {
38
+ "recommended": "0.2.0",
39
+ "supported": ">=0.1.0-alpha.2 <1",
40
+ "minimumSecure": "0.1.0-alpha.2"
41
+ },
42
+ "@codelitdev/design-system": {
43
+ "recommended": "0.2.0",
44
+ "supported": ">=0.1.0-alpha.7 <1",
45
+ "minimumSecure": "0.1.0-alpha.7"
46
+ }
47
+ },
48
+ "external": {
49
+ "typescript": "5.9.3",
50
+ "express": "4.21.2",
51
+ "@ts-rest/core": "3.52.1",
52
+ "@ts-rest/express": "3.52.1",
53
+ "@ts-rest/open-api": "3.52.1",
54
+ "pg": "8.23.0",
55
+ "@types/pg": "8.23.1",
56
+ "zod": "3.25.76",
57
+ "better-auth": "1.7.7",
58
+ "@better-auth/oauth-provider": "1.7.7",
59
+ "drizzle-orm": "0.45.2",
60
+ "drizzle-kit": "0.31.10",
61
+ "pino": "9.6.0",
62
+ "@types/bun": "1.4.1",
63
+ "@electric-sql/pglite": "0.5.8",
64
+ "@modelcontextprotocol/sdk": "1.30.0",
65
+ "dodopayments": "2.48.0",
66
+ "next": "16.3.6",
67
+ "react": "19.2.8",
68
+ "react-dom": "19.2.8"
69
+ }
70
+ }
package/dist/sync.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export type SyncResult = {
2
+ dryRun: boolean;
3
+ /** Managed files this sync writes or creates. */
4
+ changed: string[];
5
+ /** Managed files edited since the last Platform operation; nothing is written. */
6
+ conflicts: string[];
7
+ /** Files the CLI no longer manages; they stay in place as product-owned. */
8
+ released: string[];
9
+ };
10
+ /**
11
+ * Bring a product's managed files to the template shipped with this CLI.
12
+ * Product-owned files are never touched: changes to them are documented in the
13
+ * release notes and applied by the product.
14
+ */
15
+ export declare function syncProduct(input: {
16
+ root: string;
17
+ dryRun?: boolean;
18
+ allowDirty?: boolean;
19
+ failAfterWrite?: boolean;
20
+ }): SyncResult;
package/dist/sync.js ADDED
@@ -0,0 +1,87 @@
1
+ import { existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { assertGitClean } from "./git.js";
4
+ import { sha256File, sha256Text } from "./hash.js";
5
+ import { readManifest, writeManifest } from "./manifest.js";
6
+ import { cliVersion, MANAGED_FILES, renderTemplateFile } from "./template.js";
7
+ /**
8
+ * Bring a product's managed files to the template shipped with this CLI.
9
+ * Product-owned files are never touched: changes to them are documented in the
10
+ * release notes and applied by the product.
11
+ */
12
+ export function syncProduct(input) {
13
+ const root = path.resolve(input.root);
14
+ const dryRun = Boolean(input.dryRun);
15
+ if (!dryRun && !input.allowDirty)
16
+ assertGitClean(root);
17
+ const manifest = readManifest(root);
18
+ const changed = [];
19
+ const conflicts = [];
20
+ const plannedWrites = new Map();
21
+ const managedFiles = {};
22
+ // Compute and validate the complete plan before touching any file. A
23
+ // managed hash mismatch is a conflict, not a best-effort warning. A new
24
+ // managed file may be adopted only when it is absent or already identical.
25
+ for (const rel of MANAGED_FILES) {
26
+ const file = path.join(root, rel);
27
+ const desired = renderTemplateFile(rel, manifest.product);
28
+ const recorded = manifest.managedFiles[rel];
29
+ const current = existsSync(file) ? readFileSync(file, "utf8") : undefined;
30
+ const drifted = recorded === undefined
31
+ ? current !== undefined && current !== desired
32
+ : current === undefined || sha256File(file) !== recorded;
33
+ if (drifted) {
34
+ conflicts.push(rel);
35
+ continue;
36
+ }
37
+ managedFiles[rel] = sha256Text(desired);
38
+ if (current !== desired) {
39
+ plannedWrites.set(rel, desired);
40
+ changed.push(rel);
41
+ }
42
+ }
43
+ const released = Object.keys(manifest.managedFiles).filter((rel) => !MANAGED_FILES.includes(rel));
44
+ if (conflicts.length > 0)
45
+ return { dryRun, changed: [], conflicts, released: [] };
46
+ if (dryRun)
47
+ return { dryRun, changed, conflicts, released };
48
+ const manifestPath = path.join(root, ".codelit-platform.json");
49
+ const backups = new Map([
50
+ [".codelit-platform.json", readFileSync(manifestPath, "utf8")],
51
+ ]);
52
+ try {
53
+ for (const [rel, content] of plannedWrites) {
54
+ const file = path.join(root, rel);
55
+ backups.set(rel, existsSync(file) ? readFileSync(file, "utf8") : undefined);
56
+ mkdirSync(path.dirname(file), { recursive: true });
57
+ writeFileSync(file, content);
58
+ }
59
+ if (input.failAfterWrite)
60
+ throw new Error("sync_forced_failure");
61
+ // Listing fields drops ones earlier releases wrote, such as presetVersion.
62
+ writeManifest(root, {
63
+ schemaVersion: 2,
64
+ product: manifest.product,
65
+ cliVersion: cliVersion(),
66
+ capabilities: manifest.capabilities,
67
+ managedFiles,
68
+ productOwnedGlobs: manifest.productOwnedGlobs,
69
+ });
70
+ return { dryRun, changed, conflicts, released };
71
+ }
72
+ catch (error) {
73
+ const restored = [];
74
+ for (const [rel, content] of backups) {
75
+ const file = path.join(root, rel);
76
+ if (content === undefined)
77
+ rmSync(file, { force: true });
78
+ else
79
+ writeFileSync(file, content);
80
+ restored.push(rel);
81
+ }
82
+ const message = error instanceof Error ? error.message : String(error);
83
+ throw new Error(`${message}; sync_rolled_back:${restored.join(",")}`, {
84
+ cause: error,
85
+ });
86
+ }
87
+ }
@@ -1,2 +1,17 @@
1
1
  export declare function resolveTemplateDir(): string;
2
2
  export declare function slugify(name: string): string;
3
+ export declare function productNameFromTarget(targetDir: string): string;
4
+ /** The CLI release that renders managed files, pinned in the managed workflow. */
5
+ export declare function cliVersion(): string;
6
+ /**
7
+ * Files the CLI owns in every product. `sync` rewrites them from the current
8
+ * template; everything else in a product, including `code-quality.yml`, is
9
+ * product-owned after `create`.
10
+ */
11
+ export declare const MANAGED_FILES: readonly [".github/workflows/platform-conformance.yml"];
12
+ export type ProductTokens = {
13
+ name: string;
14
+ slug: string;
15
+ };
16
+ export declare function templateTokens(product: ProductTokens): Record<string, string>;
17
+ export declare function renderTemplateFile(rel: string, product: ProductTokens): string;