@metaobjectsdev/cli 0.5.0-rc.1

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 (67) hide show
  1. package/LICENSE +189 -0
  2. package/README.md +184 -0
  3. package/dist/bin/meta.d.ts +3 -0
  4. package/dist/bin/meta.d.ts.map +1 -0
  5. package/dist/bin/meta.js +7 -0
  6. package/dist/bin/meta.js.map +1 -0
  7. package/dist/src/commands/export.d.ts +2 -0
  8. package/dist/src/commands/export.d.ts.map +1 -0
  9. package/dist/src/commands/export.js +45 -0
  10. package/dist/src/commands/export.js.map +1 -0
  11. package/dist/src/commands/gen.d.ts +2 -0
  12. package/dist/src/commands/gen.d.ts.map +1 -0
  13. package/dist/src/commands/gen.js +86 -0
  14. package/dist/src/commands/gen.js.map +1 -0
  15. package/dist/src/commands/init.d.ts +16 -0
  16. package/dist/src/commands/init.d.ts.map +1 -0
  17. package/dist/src/commands/init.js +222 -0
  18. package/dist/src/commands/init.js.map +1 -0
  19. package/dist/src/commands/migrate.d.ts +2 -0
  20. package/dist/src/commands/migrate.d.ts.map +1 -0
  21. package/dist/src/commands/migrate.js +361 -0
  22. package/dist/src/commands/migrate.js.map +1 -0
  23. package/dist/src/index.d.ts +4 -0
  24. package/dist/src/index.d.ts.map +1 -0
  25. package/dist/src/index.js +105 -0
  26. package/dist/src/index.js.map +1 -0
  27. package/dist/src/lib/args.d.ts +34 -0
  28. package/dist/src/lib/args.d.ts.map +1 -0
  29. package/dist/src/lib/args.js +103 -0
  30. package/dist/src/lib/args.js.map +1 -0
  31. package/dist/src/lib/config.d.ts +17 -0
  32. package/dist/src/lib/config.d.ts.map +1 -0
  33. package/dist/src/lib/config.js +48 -0
  34. package/dist/src/lib/config.js.map +1 -0
  35. package/dist/src/lib/kysely.d.ts +28 -0
  36. package/dist/src/lib/kysely.d.ts.map +1 -0
  37. package/dist/src/lib/kysely.js +100 -0
  38. package/dist/src/lib/kysely.js.map +1 -0
  39. package/dist/src/lib/load-metaobjects-config.d.ts +3 -0
  40. package/dist/src/lib/load-metaobjects-config.d.ts.map +1 -0
  41. package/dist/src/lib/load-metaobjects-config.js +83 -0
  42. package/dist/src/lib/load-metaobjects-config.js.map +1 -0
  43. package/dist/src/lib/log.d.ts +6 -0
  44. package/dist/src/lib/log.d.ts.map +1 -0
  45. package/dist/src/lib/log.js +6 -0
  46. package/dist/src/lib/log.js.map +1 -0
  47. package/dist/src/lib/output.d.ts +38 -0
  48. package/dist/src/lib/output.d.ts.map +1 -0
  49. package/dist/src/lib/output.js +96 -0
  50. package/dist/src/lib/output.js.map +1 -0
  51. package/dist/src/lib/projection-migrations.d.ts +34 -0
  52. package/dist/src/lib/projection-migrations.d.ts.map +1 -0
  53. package/dist/src/lib/projection-migrations.js +112 -0
  54. package/dist/src/lib/projection-migrations.js.map +1 -0
  55. package/package.json +71 -0
  56. package/src/commands/export.ts +50 -0
  57. package/src/commands/gen.ts +88 -0
  58. package/src/commands/init.ts +272 -0
  59. package/src/commands/migrate.ts +390 -0
  60. package/src/index.ts +109 -0
  61. package/src/lib/args.ts +157 -0
  62. package/src/lib/config.ts +78 -0
  63. package/src/lib/kysely.ts +114 -0
  64. package/src/lib/load-metaobjects-config.ts +89 -0
  65. package/src/lib/log.ts +5 -0
  66. package/src/lib/output.ts +156 -0
  67. package/src/lib/projection-migrations.ts +159 -0
package/LICENSE ADDED
@@ -0,0 +1,189 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship made available under
36
+ the License, as indicated by a copyright notice that is included in
37
+ or attached to the work (an example is provided in the Appendix below).
38
+
39
+ "Derivative Works" shall mean any work, whether in Source or Object
40
+ form, that is based on (or derived from) the Work and for which the
41
+ editorial revisions, annotations, elaborations, or other transformations
42
+ represent, as a whole, an original work of authorship. For the purposes
43
+ of this License, Derivative Works shall not include works that remain
44
+ separable from, or merely link (or bind by name) to the interfaces of,
45
+ the Work and Derivative Works thereof.
46
+
47
+ "Contribution" shall mean, as submitted to the Licensor for inclusion
48
+ in the Work by the copyright owner or by an individual or Legal Entity
49
+ authorized to submit on behalf of the copyright owner. For the purposes
50
+ of this definition, "submitted" means any form of electronic, verbal,
51
+ or written communication sent to the Licensor or its representatives,
52
+ including but not limited to communication on electronic mailing lists,
53
+ source code control systems, and issue tracking systems that are managed
54
+ by, or on behalf of, the Licensor for the purpose of recording and
55
+ discussing modifications to the Work, but excluding communication that
56
+ is conspicuously marked or designated in writing by the copyright owner
57
+ as "Not a Contribution."
58
+
59
+ "Contributor" shall mean Licensor and any Legal Entity on behalf of
60
+ whom a Contribution has been received by the Licensor and included
61
+ within the Work.
62
+
63
+ 2. Grant of Copyright License. Subject to the terms and conditions of
64
+ this License, each Contributor hereby grants to You a perpetual,
65
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
66
+ copyright license to reproduce, prepare Derivative Works of,
67
+ publicly display, publicly perform, sublicense, and distribute the
68
+ Work and such Derivative Works in Source or Object form.
69
+
70
+ 3. Grant of Patent License. Subject to the terms and conditions of
71
+ this License, each Contributor hereby grants to You a perpetual,
72
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
73
+ (except as stated in this section) patent license to make, have made,
74
+ use, offer to sell, sell, import, and otherwise transfer the Work,
75
+ where such license applies only to those patent claims licensable
76
+ by such Contributor that are necessarily infringed by their
77
+ Contribution(s) alone or by the combination of their Contribution(s)
78
+ with the Work to which such Contribution(s) was submitted. If You
79
+ institute patent litigation against any entity (including a cross-claim
80
+ or counterclaim in a lawsuit) alleging that the Work or any
81
+ Contribution embodied within the Work constitutes direct or contributory
82
+ patent infringement, then any patent licenses granted to You under
83
+ this License for that Work shall terminate as of the date such
84
+ litigation is filed.
85
+
86
+ 4. Redistribution. You may reproduce and distribute copies of the
87
+ Work or Derivative Works thereof in any medium, with or without
88
+ modifications, and in Source or Object form, provided that You
89
+ meet the following conditions:
90
+
91
+ (a) You must give any other recipients of the Work or Derivative
92
+ Works a copy of this License; and
93
+
94
+ (b) You must cause any modified files to carry prominent notices
95
+ stating that You changed the files; and
96
+
97
+ (c) You must retain, in the Source form of any Derivative Works
98
+ that You distribute, all copyright, patent, trademark, and
99
+ attribution notices from the Source form of the Work,
100
+ excluding those notices that do not pertain to any part of
101
+ the Derivative Works; and
102
+
103
+ (d) If the Work includes a "NOTICE" text file as part of its
104
+ distribution, You must include a readable copy of the
105
+ attribution notices contained within such NOTICE file, in
106
+ at least one of the following places: within a NOTICE text
107
+ file distributed as part of the Derivative Works; within
108
+ the Source form or documentation, if provided along with the
109
+ Derivative Works; or, within a display generated by the
110
+ Derivative Works, if and wherever such third-party notices
111
+ normally appear. The contents of the NOTICE file are for
112
+ informational purposes only and do not modify the License.
113
+ You may add Your own attribution notices within Derivative
114
+ Works that You distribute, alongside or in addition to the
115
+ NOTICE text from the Work, provided that such additional
116
+ attribution notices cannot be construed as modifying the License.
117
+
118
+ You may add Your own license statement for Your modifications and
119
+ may provide additional grant of rights to use, reproduce, modify,
120
+ prepare derivative works of, distribute, and sublicense such modifications,
121
+ as an additional requirement of this License.
122
+
123
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
124
+ any Contribution intentionally submitted for inclusion in the Work
125
+ by You to the Licensor shall be under the terms and conditions of
126
+ this License, without any additional terms or conditions.
127
+ Notwithstanding the above, nothing herein shall supersede or modify
128
+ the terms of any separate license agreement you may have executed
129
+ with Licensor regarding such Contributions.
130
+
131
+ 6. Trademarks. This License does not grant permission to use the trade
132
+ names, trademarks, service marks, or product names of the Licensor,
133
+ except as required for reasonable and customary use in describing the
134
+ origin of the Work and reproducing the content of the NOTICE file.
135
+
136
+ 7. Disclaimer of Warranty. Unless required by applicable law or
137
+ agreed to in writing, Licensor provides the Work (and each
138
+ Contributor provides its Contributions) on an "AS IS" BASIS,
139
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
140
+ implied, including, without limitation, any conditions of TITLE,
141
+ NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR
142
+ PURPOSE. You are solely responsible for determining the
143
+ appropriateness of using or reproducing the Work and assume any
144
+ risks associated with Your exercise of permissions under this License.
145
+
146
+ 8. Limitation of Liability. In no event and under no legal theory,
147
+ whether in tort (including negligence), contract, or otherwise,
148
+ unless required by applicable law (such as deliberate and grossly
149
+ negligent acts) or agreed to in writing, shall any Contributor be
150
+ liable to You for damages, including any direct, indirect, special,
151
+ incidental, or exemplary damages of any character arising as a
152
+ result of this License or out of the use or inability to use the
153
+ Work (including but not limited to damages for loss of goodwill,
154
+ work stoppage, computer failure or malfunction, or all other
155
+ commercial damages or losses), even if such Contributor has been
156
+ advised of the possibility of such damages.
157
+
158
+ 9. Accepting Warranty or Additional Liability. While redistributing
159
+ the Work or Derivative Works thereof, You may choose to offer,
160
+ and charge a fee for, acceptance of support, warranty, indemnity,
161
+ or other liability obligations and/or rights consistent with this
162
+ License. However, in accepting such obligations, You may offer
163
+ only obligations consistent to this License provided that the
164
+ obligations are consistent with this License.
165
+
166
+ END OF TERMS AND CONDITIONS
167
+
168
+ APPENDIX: How to apply the Apache License to your work.
169
+
170
+ To apply the Apache License to your work, attach the following
171
+ boilerplate notice, with the fields enclosed by brackets "[]"
172
+ replaced with your own identifying information. (Don't include
173
+ the brackets!) The text should be enclosed in the appropriate
174
+ comment syntax for the file format in question. Also add information
175
+ on how to contact you electronically and/or by mail.
176
+
177
+ Copyright 2026 MetaObjects Contributors
178
+
179
+ Licensed under the Apache License, Version 2.0 (the "License");
180
+ you may not use this file except in compliance with the License.
181
+ You may obtain a copy of the License at
182
+
183
+ http://www.apache.org/licenses/LICENSE-2.0
184
+
185
+ Unless required by applicable law or agreed to in writing, software
186
+ distributed under the License is distributed on an "AS IS" BASIS,
187
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
188
+ See the License for the specific language governing permissions and
189
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,184 @@
1
+ # @metaobjectsdev/cli
2
+
3
+ The MetaObjects CLI — scaffolds `metaobjects/` + `.metaobjects/`, runs codegen and migrations against MetaObjects metadata.
4
+
5
+ **Status:** v0.3. TS reference implementation with Projects D–G shipped end-to-end.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ bun add -D @metaobjectsdev/cli
11
+ ```
12
+
13
+ Optional driver peers (install the one matching your DB):
14
+ - SQLite/Turso: `bun add -D @libsql/kysely-libsql`
15
+ - Postgres: `bun add -D pg`
16
+
17
+ ## Quick start
18
+
19
+ ```bash
20
+ # 1. Scaffold metaobjects/ + .metaobjects/ + metaobjects.config.ts
21
+ meta init
22
+
23
+ # 2. Author entity metadata
24
+ $EDITOR metaobjects/meta.myapp.json # see .metaobjects/AGENTS.md for format
25
+
26
+ # 3. Generate TS code (config-driven via metaobjects.config.ts)
27
+ meta gen
28
+
29
+ # 4. Diff metadata against your DB and emit migration SQL
30
+ meta migrate --db file:./local.db --slug initial
31
+ ```
32
+
33
+ ## Commands
34
+
35
+ ### `meta init`
36
+
37
+ Scaffolds `metaobjects/` (visible entity declarations, with a placeholder `meta.common.json`), `.metaobjects/` (hidden tool state: `config.json`, `package.meta.json`, `AGENTS.md`, `CLAUDE.md`, `.gitignore`, `.gen-state/`), and `metaobjects.config.ts` at the repo root.
38
+
39
+ Flags:
40
+ - `--force` — overwrite scaffold files (memory records preserved)
41
+ - `--quiet` — suppress next-steps output
42
+ - `--print-only` — show what would be created without writing
43
+ - `--refresh-docs` — refresh AGENTS.md + CLAUDE.md after a CLI upgrade
44
+
45
+ ### `meta gen [<entity>...]`
46
+
47
+ Generates TS code (Drizzle schema, Zod validators, query helpers, TanStack Query hooks, etc.) from `metaobjects/` entity metadata. Generator wiring lives in `metaobjects.config.ts`; `meta gen` errors out if that file is missing.
48
+
49
+ Flags:
50
+ - `--dry-run` — informational; files still written (true no-write planned)
51
+
52
+ Positional args filter entities by name. All other knobs (`outDir`, `targets`, `dialect`, `dbImport`, `extStyle`, `apiPrefix`, generator list) live in `metaobjects.config.ts`.
53
+
54
+ ### `meta migrate`
55
+
56
+ Diffs `metaobjects/` metadata against a live DB and emits paired migration SQL files (per-migration subdirectories with `up.sql` and `down.sql`).
57
+
58
+ Flags:
59
+ - `--db <url>` (required or via `$DATABASE_URL` or `.metaobjects/config.json`)
60
+ - Supported schemes: `file:`, `libsql:`, `postgres:`, `postgresql:`
61
+ - `--dialect sqlite|postgres` — auto-detected from URL scheme
62
+ - `--out-dir <path>` (default `./.metaobjects/migrations`)
63
+ - `--slug <name>` — required when changes are pending (e.g., `add-user-shipping`)
64
+ - `--allow <csv>` — destructive-change permissions: `drop-column,drop-table,type-change,drop-index,drop-fk,nullable-to-not-null`
65
+ - `--on-ambiguous abort|rename|drop-add` (default `abort`) — non-interactive
66
+ - `--dry-run` — print SQL pair to stdout, write nothing
67
+
68
+ ## Configuration
69
+
70
+ Two config files, by design:
71
+
72
+ **`metaobjects.config.ts`** (at repo root) — generator wiring and codegen knobs, type-checked TS:
73
+
74
+ ```ts
75
+ import { defineConfig } from "@metaobjectsdev/cli";
76
+ import { entityFile, queriesFile, routesFile, barrel } from "@metaobjectsdev/codegen-ts/generators";
77
+
78
+ export default defineConfig({
79
+ outDir: "packages/database/src/generated",
80
+ extStyle: "none",
81
+ dbImport: "../index",
82
+ dialect: "sqlite",
83
+ apiPrefix: "/api",
84
+ generators: [entityFile(), queriesFile(), routesFile(), barrel()],
85
+ });
86
+ ```
87
+
88
+ ### Multiple output targets
89
+
90
+ By default every generator writes to `outDir`. To route each generator's output
91
+ to a different directory/package — so generated code lands with its runtime
92
+ concern — declare named **targets** and point generators at them with `target`:
93
+
94
+ ```ts
95
+ import { defineConfig } from "@metaobjectsdev/cli";
96
+ import { entityFile, queriesFile, routesFile, barrel } from "@metaobjectsdev/codegen-ts/generators";
97
+ import { formFile } from "@metaobjectsdev/codegen-ts-react";
98
+ import { tanstackQuery, tanstackGrid } from "@metaobjectsdev/codegen-ts-tanstack";
99
+
100
+ export default defineConfig({
101
+ // The top-level outDir is the implicit "default" target — it holds the entity
102
+ // modules (Drizzle + Zod), so it needs an importBase that other targets use to
103
+ // import them.
104
+ outDir: "packages/database/src/generated",
105
+ importBase: "@acme/database/generated",
106
+ dbImport: "../index",
107
+ dialect: "sqlite",
108
+ outputLayout: "package",
109
+ apiPrefix: "/api",
110
+
111
+ targets: {
112
+ // routes run on the server; import db from the database package
113
+ api: { outDir: "apps/api/src/generated", dbImport: "@acme/database" },
114
+ // hooks/forms/grids run in the browser
115
+ web: { outDir: "apps/web/src/generated" },
116
+ },
117
+
118
+ generators: [
119
+ entityFile(), queriesFile(), barrel(), // → default (entity-module) target
120
+ routesFile({ target: "api" }),
121
+ formFile({ target: "web" }),
122
+ tanstackQuery({ target: "web" }),
123
+ tanstackGrid({ target: "web" }),
124
+ ],
125
+ });
126
+ ```
127
+
128
+ A **target** is `{ outDir, importBase?, outputLayout?, dbImport? }`. `outputLayout`
129
+ and `dbImport` fall back to the top-level values; `importBase` does not inherit (it
130
+ is each target's own identity). Generators with no `target` use the implicit
131
+ `default` target (the top-level `outDir`).
132
+
133
+ **How cross-target imports resolve.** Every generated artifact imports the entity
134
+ module (queries, routes, hooks, columns, forms). When a generator's target differs
135
+ from the entity-module target (the one holding `entityFile()` output), that import
136
+ is emitted as an **extension-less package path** built from the entity-module
137
+ target's `importBase` — e.g. `@acme/database/generated/acme/commerce/Program` —
138
+ instead of a relative `./Program`. Same-target imports stay relative and honor
139
+ `extStyle`. The entity-module target therefore **must** set `importBase` whenever
140
+ any generator routes elsewhere (the runner errors with a fix-it message otherwise),
141
+ and the package it lives in must expose those modules via its `exports` map (e.g.
142
+ `"./generated/*": "./src/generated/*.ts"`).
143
+
144
+ With no `targets` and no per-generator `target`, output is byte-identical to a
145
+ single-`outDir` project.
146
+
147
+ **`.metaobjects/config.json`** — static project state parseable by non-TS tooling:
148
+
149
+ ```json
150
+ {
151
+ "schema_version": 1,
152
+ "pending_in_git": true,
153
+ "confidence_thresholds": { "pending_promote": 0.8, "drift_warn": 0.7 },
154
+ "sources": [],
155
+ "extract": {},
156
+ "migrate": {
157
+ "outDir": "./.metaobjects/migrations",
158
+ "databaseUrl": "file:./local.db",
159
+ "onAmbiguous": "abort",
160
+ "allow": []
161
+ }
162
+ }
163
+ ```
164
+
165
+ Precedence for `meta migrate`: CLI flag > env var (`DATABASE_URL` only) > `.metaobjects/config.json` > built-in default.
166
+
167
+ ## Metadata format
168
+
169
+ See `.metaobjects/AGENTS.md` (scaffolded by `meta init`) for the metaobjects metamodel rules, attribute conventions, and worked examples. Deeper references:
170
+
171
+ - `@metaobjectsdev/metadata` [METAMODEL.md](../metadata/METAMODEL.md) — full metaobjects metamodel reference
172
+ - `@metaobjectsdev/sdk` [FORGE-METADATA.md](../sdk/FORGE-METADATA.md) — MetaObjects metadata additions
173
+
174
+ ## Not yet shipped
175
+
176
+ - `meta migrate --apply` — emit only, no DB writes from CLI
177
+ - `meta gen --watch` (dropped) — re-run on demand
178
+ - True 3-way merge in `meta gen` — codegen-ts has overwrite/skip-existing only
179
+ - Module-reference DB connections — URL-only
180
+ - Reified SDK APIs for adding/promoting descriptive records — hand-edit JSON for now
181
+
182
+ ## License
183
+
184
+ Apache-2.0.
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=meta.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.d.ts","sourceRoot":"","sources":["../../bin/meta.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ // Note: this .ts source file is executed by Bun in the workspace (not Node).
3
+ // The shebang stays as `node` so tsc copies it unchanged to dist/bin/meta.js,
4
+ // keeping the published CLI runnable by Node for npm consumers.
5
+ import { run } from "../src/index.js";
6
+ run(process.argv.slice(2)).then((code) => process.exit(code));
7
+ //# sourceMappingURL=meta.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"meta.js","sourceRoot":"","sources":["../../bin/meta.ts"],"names":[],"mappings":";AACA,6EAA6E;AAC7E,8EAA8E;AAC9E,gEAAgE;AAChE,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function exportCommand(args: string[], cwd: string): Promise<number>;
2
+ //# sourceMappingURL=export.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.d.ts","sourceRoot":"","sources":["../../../src/commands/export.ts"],"names":[],"mappings":"AAQA,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAyChF"}
@@ -0,0 +1,45 @@
1
+ import { resolve, join } from "node:path";
2
+ import { writeFile } from "node:fs/promises";
3
+ import { parseExportArgs } from "../lib/args.js";
4
+ import { log } from "../lib/log.js";
5
+ import { loadAndExportJson } from "@metaobjectsdev/metadata/core";
6
+ import { TypeRegistry, registerCoreTypes } from "@metaobjectsdev/metadata";
7
+ import { DEFAULT_METADATA_DIR, registerForgeTypes } from "@metaobjectsdev/sdk";
8
+ export async function exportCommand(args, cwd) {
9
+ let flags;
10
+ try {
11
+ flags = parseExportArgs(args);
12
+ }
13
+ catch (err) {
14
+ log.error(err.message);
15
+ return 2;
16
+ }
17
+ const projectRoot = cwd;
18
+ const metadataDir = join(projectRoot, DEFAULT_METADATA_DIR);
19
+ // Build a registry with core + forge types so metadata that includes
20
+ // descriptive types (decision, principle, etc.) loads without errors.
21
+ const registry = new TypeRegistry();
22
+ registerCoreTypes(registry);
23
+ registerForgeTypes(registry);
24
+ const result = await loadAndExportJson(metadataDir, { registry });
25
+ for (const w of result.warnings) {
26
+ log.warn(w);
27
+ }
28
+ if (result.errors.length > 0) {
29
+ for (const err of result.errors) {
30
+ log.error(err.message);
31
+ }
32
+ return 1;
33
+ }
34
+ if (flags.out !== undefined) {
35
+ const outPath = resolve(projectRoot, flags.out);
36
+ await writeFile(outPath, result.json, "utf8");
37
+ const byteCount = Buffer.byteLength(result.json, "utf8");
38
+ log.info(`meta export — wrote ${outPath} (${byteCount} bytes)`);
39
+ }
40
+ else {
41
+ process.stdout.write(result.json);
42
+ }
43
+ return 0;
44
+ }
45
+ //# sourceMappingURL=export.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"export.js","sourceRoot":"","sources":["../../../src/commands/export.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,e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AE,CAAC;QAC5B,MAAM,OAAO,GAAG,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC;QAChD,MAAM,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QAC9C,MAAM,SAAS,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;QACzD,GAAG,CAAC,IAAI,CAAC,uBAAuB,OAAO,KAAK,SAAS,SAAS,CAAC,CAAC;IAClE,CAAC;SAAM,CAAC;QACN,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAED,OAAO,CAAC,CAAC;AACX,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare function genCommand(args: string[], cwd: string): Promise<number>;
2
+ //# sourceMappingURL=gen.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gen.d.ts","sourceRoot":"","sources":["../../../src/commands/gen.ts"],"names":[],"mappings":"AAmBA,wBAAsB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAoE7E"}
@@ -0,0 +1,86 @@
1
+ import { relative } from "node:path";
2
+ import { parseGenArgs } from "../lib/args.js";
3
+ import { resolveGenConfig } from "../lib/config.js";
4
+ import { loadMetaobjectsConfig } from "../lib/load-metaobjects-config.js";
5
+ import { formatGenResult } from "../lib/output.js";
6
+ import { log } from "../lib/log.js";
7
+ import { loadMemory } from "@metaobjectsdev/sdk";
8
+ import { runGen } from "@metaobjectsdev/codegen-ts";
9
+ function mapStatus(s) {
10
+ switch (s) {
11
+ case "new":
12
+ case "overwrite": return "new";
13
+ case "skipped": return "unchanged";
14
+ case "refused": return "refused";
15
+ }
16
+ }
17
+ export async function genCommand(args, cwd) {
18
+ let flags;
19
+ try {
20
+ flags = parseGenArgs(args);
21
+ }
22
+ catch (err) {
23
+ log.error(err.message);
24
+ return 2;
25
+ }
26
+ const projectRoot = cwd;
27
+ const cliConfig = resolveGenConfig(flags);
28
+ let forgeConfig;
29
+ try {
30
+ forgeConfig = await loadMetaobjectsConfig(projectRoot);
31
+ }
32
+ catch (err) {
33
+ log.error(err.message);
34
+ return 2;
35
+ }
36
+ let metadata;
37
+ try {
38
+ metadata = await loadMemory(projectRoot);
39
+ }
40
+ catch (err) {
41
+ const msg = err.message;
42
+ if (msg.includes("ENOENT") || msg.includes("no such") || msg.includes("cannot read")) {
43
+ log.error(`no metaobjects/ found in ${projectRoot}; run 'meta init' to scaffold`);
44
+ }
45
+ else {
46
+ log.error(`failed to load metadata: ${msg}`);
47
+ }
48
+ return 2;
49
+ }
50
+ let result;
51
+ try {
52
+ result = await runGen({
53
+ config: forgeConfig,
54
+ metadata,
55
+ ...(cliConfig.entities.length > 0 ? { entityFilter: cliConfig.entities } : {}),
56
+ });
57
+ }
58
+ catch (err) {
59
+ log.error(`gen failed: ${err.message}`);
60
+ return 1;
61
+ }
62
+ for (const w of result.warnings) {
63
+ log.warn(w);
64
+ }
65
+ // result.files[].path is the absolute full path from decideAndWrite. With
66
+ // per-target output, show each path relative to the project root so files in
67
+ // different targets are distinguishable.
68
+ const files = result.files.map((f) => ({
69
+ path: relative(projectRoot, f.path),
70
+ status: mapStatus(f.status),
71
+ info: "",
72
+ }));
73
+ const targetDirs = Array.from(new Set((forgeConfig.targets ? Object.values(forgeConfig.targets).map((t) => t.outDir) : [])
74
+ .concat([forgeConfig.outDir])));
75
+ const output = formatGenResult({
76
+ files,
77
+ outDir: targetDirs.length > 1 ? targetDirs.join(", ") : forgeConfig.outDir,
78
+ dialect: forgeConfig.dialect,
79
+ dryRun: cliConfig.dryRun,
80
+ warnings: [],
81
+ }, { isTTY: !!process.stdout.isTTY });
82
+ log.info(output);
83
+ const hasFailure = files.some((f) => f.status === "conflict" || f.status === "refused");
84
+ return hasFailure ? 1 : 0;
85
+ }
86
+ //# s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ACxF,OAAO,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC5B,CAAC"}
@@ -0,0 +1,16 @@
1
+ export interface InitOptions {
2
+ cwd: string;
3
+ force?: boolean;
4
+ quiet?: boolean;
5
+ printOnly?: boolean;
6
+ refreshDocs?: boolean;
7
+ }
8
+ export interface InitResult {
9
+ created: string[];
10
+ preserved: string[];
11
+ warnings: string[];
12
+ }
13
+ export declare function init(opts: InitOptions): Promise<InitResult>;
14
+ export declare function nextStepsBlock(): string;
15
+ export declare function initCommand(args: string[], cwd: string): Promise<number>;
16
+ //# sourceMappingURL=init.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../../src/commands/init.ts"],"names":[],"mappings":"AA0DA,MAAM,WAAW,WAAW;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB;AAED,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,QAAQ,EAAE,MAAM,EAAE,CAAC;CACpB;AA4BD,wBAAsB,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC,CAqHjE;AAED,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAoBD,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAgC9E"}