@orizm/cli 0.1.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/LICENSE +202 -0
- package/README.md +9 -0
- package/bin/index.js +3 -0
- package/dist/cli.js +1042 -0
- package/package.json +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
package/README.md
ADDED
package/bin/index.js
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,1042 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __copyProps = (to, from, except, desc) => {
|
|
8
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
9
|
+
for (let key of __getOwnPropNames(from))
|
|
10
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
11
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
12
|
+
}
|
|
13
|
+
return to;
|
|
14
|
+
};
|
|
15
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
16
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
17
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
18
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
19
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
|
|
24
|
+
// src/cli.ts
|
|
25
|
+
var import_commander6 = require("commander");
|
|
26
|
+
|
|
27
|
+
// src/cms/generate/command.ts
|
|
28
|
+
var import_commander = require("commander");
|
|
29
|
+
|
|
30
|
+
// src/lib/load-config.ts
|
|
31
|
+
var import_esbuild = __toESM(require("esbuild"));
|
|
32
|
+
var import_config_validator = require("@orizm/common/config-validator");
|
|
33
|
+
var v = __toESM(require("valibot"));
|
|
34
|
+
async function loadConfig(configFile) {
|
|
35
|
+
const buildResult = await import_esbuild.default.build({
|
|
36
|
+
entryPoints: [configFile],
|
|
37
|
+
bundle: true,
|
|
38
|
+
write: false,
|
|
39
|
+
format: "cjs",
|
|
40
|
+
target: "node16"
|
|
41
|
+
});
|
|
42
|
+
return v.parse(import_config_validator.OrizmConfigDef, eval(buildResult.outputFiles[0].text).default);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/lib/cli-spinner.ts
|
|
46
|
+
var import_readline = __toESM(require("readline"));
|
|
47
|
+
|
|
48
|
+
// src/lib/cli-symbol.ts
|
|
49
|
+
var import_cli_color = require("cli-color");
|
|
50
|
+
var success = (0, import_cli_color.green)("\u2713");
|
|
51
|
+
var error = (0, import_cli_color.red)("\u2717");
|
|
52
|
+
|
|
53
|
+
// src/lib/cli-cursor.ts
|
|
54
|
+
function hide() {
|
|
55
|
+
process.stdout.write("\x1B[?25l");
|
|
56
|
+
}
|
|
57
|
+
function show() {
|
|
58
|
+
process.stdout.write("\x1B[?25h");
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// src/lib/cli-spinner.ts
|
|
62
|
+
var FRAMES = ["\u280B", "\u2819", "\u2839", "\u2838", "\u283C", "\u2834", "\u2826", "\u2827", "\u2807", "\u280F"];
|
|
63
|
+
var FRAME_INTERVAL = 80;
|
|
64
|
+
var Spinner = class {
|
|
65
|
+
text = "";
|
|
66
|
+
currentFrame = 0;
|
|
67
|
+
timer = null;
|
|
68
|
+
isSpinning = false;
|
|
69
|
+
start(text) {
|
|
70
|
+
if (text) {
|
|
71
|
+
this.text = text;
|
|
72
|
+
}
|
|
73
|
+
if (this.isSpinning) {
|
|
74
|
+
return this;
|
|
75
|
+
}
|
|
76
|
+
this.isSpinning = true;
|
|
77
|
+
this.currentFrame = 0;
|
|
78
|
+
hide();
|
|
79
|
+
this.render();
|
|
80
|
+
this.timer = setInterval(() => {
|
|
81
|
+
this.render();
|
|
82
|
+
}, FRAME_INTERVAL);
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
stop() {
|
|
86
|
+
if (!this.isSpinning) {
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
this.isSpinning = false;
|
|
90
|
+
if (this.timer) {
|
|
91
|
+
clearInterval(this.timer);
|
|
92
|
+
this.timer = null;
|
|
93
|
+
}
|
|
94
|
+
import_readline.default.clearLine(process.stdout, 0);
|
|
95
|
+
import_readline.default.cursorTo(process.stdout, 0);
|
|
96
|
+
show();
|
|
97
|
+
return this;
|
|
98
|
+
}
|
|
99
|
+
succeed(text) {
|
|
100
|
+
this.stop();
|
|
101
|
+
const finalText = text || this.text;
|
|
102
|
+
console.log(`${success} ${finalText}`);
|
|
103
|
+
}
|
|
104
|
+
render() {
|
|
105
|
+
const frame = FRAMES[this.currentFrame];
|
|
106
|
+
this.currentFrame = (this.currentFrame + 1) % FRAMES.length;
|
|
107
|
+
import_readline.default.clearLine(process.stdout, 0);
|
|
108
|
+
import_readline.default.cursorTo(process.stdout, 0);
|
|
109
|
+
process.stdout.write(`${frame} ${this.text}`);
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
function createSpinner() {
|
|
113
|
+
return new Spinner();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// src/lib/handle-error.ts
|
|
117
|
+
var v2 = __toESM(require("valibot"));
|
|
118
|
+
var cliColor = __toESM(require("cli-color"));
|
|
119
|
+
function handleError(error2) {
|
|
120
|
+
show();
|
|
121
|
+
if (v2.isValiError(error2)) {
|
|
122
|
+
console.error();
|
|
123
|
+
console.error(`Error: ${error2.issues.length} problem(s) found.`);
|
|
124
|
+
console.error(buildValiErrorMessage(error2));
|
|
125
|
+
console.error();
|
|
126
|
+
process.exit(1);
|
|
127
|
+
}
|
|
128
|
+
console.error();
|
|
129
|
+
console.error(
|
|
130
|
+
cliColor.red(
|
|
131
|
+
"Something went wrong. Please check the error below for more details."
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
console.error();
|
|
135
|
+
console.error(error2);
|
|
136
|
+
console.error();
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
function buildValiErrorMessage(e) {
|
|
140
|
+
return e.issues.map((issue) => {
|
|
141
|
+
return ` ${cliColor.red(issue.message)} (at ${cliColor.yellow(v2.getDotPath(issue))})`;
|
|
142
|
+
}).join("\n");
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/cms/generate/generator.ts
|
|
146
|
+
var import_promises = require("fs/promises");
|
|
147
|
+
var import_path = __toESM(require("path"));
|
|
148
|
+
var import_handlebars = __toESM(require("handlebars"));
|
|
149
|
+
|
|
150
|
+
// src/cms/templates/types.ts.hbr
|
|
151
|
+
var types_ts_default = '// This file was automatically generated and should not be edited.\n\nimport { FormValidationRules, StorageItemType } from "@orizm/common";\n\n// Utilities\ntype _ModuleRef<T> = T & _ModuleDescriptor;\ntype _ModuleDescriptor = {\n isModule: true;\n};\ntype _ArrayModuleRef<T> = T & _ArrayModuleDescriptor;\ntype _ArrayModuleDescriptor = {\n isModuleArray: true;\n};\n\n// Tables\n{{#each tables}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n createdAt: string;\n updatedAt: string;\n {{#unless this.isSubmissions}}\n group?: string;\n publishedAt?: string;\n _draft?: boolean;\n _published?: boolean;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n {{else}}\n _formId: string;\n _content: unknown;\n _formSchema: unknown;\n _attachments: StorageItemType[];\n {{/unless}}\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n\nexport type {{toCodeTypeName this.name}}CreateInput = {\n {{#unless this.isSubmissions}}\n group?: string;\n publishedAt?: string;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n createdAt?: string;\n {{/unless}}\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n\nexport type {{toCodeTypeName this.name}}UpdateInput = {\n {{#each this.columns}}\n {{#unless this.readOnly}}{{this.name}}?: {{typeName this}}{{#unless this.required}} | null{{/unless}};{{/unless}}\n {{/each}}\n {{#unless this.isSubmissions}}\n publishedAt?: string;\n scheduledPublishAt?: string | null;\n scheduledUnpublishAt?: string | null;\n createdAt?: string;\n {{/unless}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n};\n{{/each}}\n\n// Module types\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}} = {\n id?: string;\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n};\n{{/each}}\n\n\n// Descriptor types\n{{#each tables}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n create: {{toCodeTypeName this.name}}CreateInput;\n update: {{toCodeTypeName this.name}}UpdateInput;\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n {{#if (filterUniqueIndexes this.indexes)}}\n unique: [\n {{#each (filterUniqueIndexes this.indexes)}}\n { {{#each (getIndexColumns ../this this)}}{{this.name}}:{{typeName this}},{{/each}} },\n {{/each}}\n ]\n {{/if}}\n {{#unless (filterUniqueIndexes this.indexes)}}\n unique: [];\n {{/unless}}\n {{#if this.enableDrafts}}\n enableDrafts: true;\n {{/if}}\n {{#if this.enableForm}}\n submissionDescriptor: {{toCodeTypeName this.name}}_Submission__Descriptor;\n {{else}}\n submissionDescriptor: never;\n {{/if}}\n};\n{{/each}}\n\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n unique:[]\n};\n{{/each}}\n\n\n// Webhook types\nexport type WebhookEvent = "content.create" | "content.update" | "content.delete";\nexport type WebhookPayload = {\n event: WebhookEvent;\n timestamp: string;\n project: string;\n} & (\n {{#each tables}}\n | {\n table: "{{this.name}}";\n content: {{toCodeTypeName this.name}};\n old?: {{toCodeTypeName this.name}};\n }\n {{/each}}\n)\n';
|
|
152
|
+
|
|
153
|
+
// src/cms/templates/client.ts.hbr
|
|
154
|
+
var client_ts_default = '// This file was automatically generated and should not be edited.\n\nimport { OrizmCMSClient } from "@orizm/cms-sdk";\n\nimport * as Models from "./types";\n\nexport class CMSClient {\n constructor(protected client: OrizmCMSClient) {\n this.tables = {\n {{#each tables}}\n {{toEndpointName this.name}}: this.client.getTableClient<Models.{{toCodeTypeName this.name}}__Descriptor>("{{toEndpointName this.name}}"),\n {{/each}}\n };\n\n this.buckets = {\n {{#each buckets}}\n {{toEndpointName this.name}}: this.client.getBucketClient("{{toEndpointName this.name}}"),\n {{/each}}\n };\n\n this.userManagement = this.client.userManagement;\n \n this.userinfo = this.client.userinfo;\n \n this.auth = this.client.auth;\n }\n\n readonly tables;\n readonly buckets;\n readonly userManagement;\n readonly userinfo;\n readonly auth;\n}\n';
|
|
155
|
+
|
|
156
|
+
// src/cms/generate/generator.ts
|
|
157
|
+
import_handlebars.default.registerHelper("toEndpointName", (str) => {
|
|
158
|
+
return str;
|
|
159
|
+
});
|
|
160
|
+
function toCodeTypeName(str) {
|
|
161
|
+
str = str.charAt(0).toUpperCase() + str.slice(1);
|
|
162
|
+
return str.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
|
163
|
+
}
|
|
164
|
+
import_handlebars.default.registerHelper("toCodeTypeName", toCodeTypeName);
|
|
165
|
+
import_handlebars.default.registerHelper(
|
|
166
|
+
"typeName",
|
|
167
|
+
(column) => {
|
|
168
|
+
if (column.type === "reference") {
|
|
169
|
+
return "string";
|
|
170
|
+
} else if (column.type === "module") {
|
|
171
|
+
return toCodeTypeName(column.moduleName);
|
|
172
|
+
} else if (column.type === "module-array") {
|
|
173
|
+
return toCodeTypeName(column.moduleName) + "[]";
|
|
174
|
+
} else if (column.type == "json") {
|
|
175
|
+
return "unknown";
|
|
176
|
+
} else if (column.type === "storage") {
|
|
177
|
+
return "StorageItemType";
|
|
178
|
+
} else {
|
|
179
|
+
return column.type;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
);
|
|
183
|
+
import_handlebars.default.registerHelper(
|
|
184
|
+
"filterRefColumn",
|
|
185
|
+
(columns) => {
|
|
186
|
+
return (columns || []).filter(
|
|
187
|
+
(c) => c.type === "reference" && c.tableName && c.includeName || c.type === "module" && c.moduleName || c.type === "module-array" && c.moduleName
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
import_handlebars.default.registerHelper(
|
|
192
|
+
"includeName",
|
|
193
|
+
(column) => {
|
|
194
|
+
return column.type === "reference" ? column.includeName : column.name;
|
|
195
|
+
}
|
|
196
|
+
);
|
|
197
|
+
import_handlebars.default.registerHelper(
|
|
198
|
+
"includeType",
|
|
199
|
+
(column) => {
|
|
200
|
+
if (column.type === "reference")
|
|
201
|
+
return toCodeTypeName(column.tableName) + "__Descriptor";
|
|
202
|
+
if (column.type === "module")
|
|
203
|
+
return `_ModuleRef<${toCodeTypeName(column.moduleName)}__Descriptor>`;
|
|
204
|
+
if (column.type === "module-array")
|
|
205
|
+
return `_ArrayModuleRef<${toCodeTypeName(
|
|
206
|
+
column.moduleName
|
|
207
|
+
)}__Descriptor>`;
|
|
208
|
+
}
|
|
209
|
+
);
|
|
210
|
+
import_handlebars.default.registerHelper(
|
|
211
|
+
"filterUniqueIndexes",
|
|
212
|
+
(indexes) => {
|
|
213
|
+
return (indexes || []).filter((i) => i.unique);
|
|
214
|
+
}
|
|
215
|
+
);
|
|
216
|
+
import_handlebars.default.registerHelper(
|
|
217
|
+
"getIndexColumns",
|
|
218
|
+
(table, index) => {
|
|
219
|
+
return index.columns.map((i) => {
|
|
220
|
+
const column = table.columns.find((c) => c.name === i);
|
|
221
|
+
if (!column) {
|
|
222
|
+
throw new Error(`column ${i} not found`);
|
|
223
|
+
}
|
|
224
|
+
return column;
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
);
|
|
228
|
+
async function generate(options) {
|
|
229
|
+
const config = options.projectDef;
|
|
230
|
+
await (0, import_promises.mkdir)(options.output, { recursive: true });
|
|
231
|
+
await renderTypes(config, options.output);
|
|
232
|
+
await renderClient(config, options.output);
|
|
233
|
+
}
|
|
234
|
+
async function renderTypes(config, output) {
|
|
235
|
+
const submissionTables = config.tables.filter((t) => t.enableForm).map((t) => ({
|
|
236
|
+
name: t.name + "__submission",
|
|
237
|
+
columns: t.formOptions?.submissionColumns || [],
|
|
238
|
+
isSubmissions: true
|
|
239
|
+
}));
|
|
240
|
+
const renderParams = {
|
|
241
|
+
...config,
|
|
242
|
+
tables: [...config.tables, ...submissionTables]
|
|
243
|
+
};
|
|
244
|
+
const rendered = import_handlebars.default.compile(types_ts_default)(renderParams);
|
|
245
|
+
const targetPath = import_path.default.join(output, "types.ts");
|
|
246
|
+
await (0, import_promises.writeFile)(targetPath, rendered, "utf-8");
|
|
247
|
+
}
|
|
248
|
+
async function renderClient(config, output) {
|
|
249
|
+
const rendered = import_handlebars.default.compile(client_ts_default)(config);
|
|
250
|
+
const targetPath = import_path.default.join(output, "client.ts");
|
|
251
|
+
await (0, import_promises.writeFile)(targetPath, rendered, "utf-8");
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// src/cms/generate/command.ts
|
|
255
|
+
var spinner = createSpinner();
|
|
256
|
+
var cmsGenerateCommand = new import_commander.Command("generate").description("generate orizm client and types.").option("-c, --config <path>", "orizm config file path.", "orizm.config.ts").option("-o, --output <path>", "output directory.", "./src/orizm").action(async (options) => {
|
|
257
|
+
try {
|
|
258
|
+
spinner.start("Loading project schema...");
|
|
259
|
+
const projectDef = await loadConfig(options.config);
|
|
260
|
+
spinner.succeed("Loaded project schema.");
|
|
261
|
+
spinner.start("Generating code...");
|
|
262
|
+
await generate({
|
|
263
|
+
projectDef,
|
|
264
|
+
output: options.output
|
|
265
|
+
});
|
|
266
|
+
spinner.succeed(`Generated code to '${options.output}'`);
|
|
267
|
+
} catch (error2) {
|
|
268
|
+
handleError(error2);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
|
|
272
|
+
// src/cms/pull/command.ts
|
|
273
|
+
var import_commander2 = require("commander");
|
|
274
|
+
var cliColor2 = __toESM(require("cli-color"));
|
|
275
|
+
|
|
276
|
+
// src/api/developer-api-client.ts
|
|
277
|
+
var import_openapi_fetch = __toESM(require("openapi-fetch"));
|
|
278
|
+
function createDeveloperAPIClient(baseUrl, apiKey) {
|
|
279
|
+
const url = new URL(baseUrl);
|
|
280
|
+
url.pathname = `/api/dev/v1`;
|
|
281
|
+
return (0, import_openapi_fetch.default)({
|
|
282
|
+
baseUrl: url.toString(),
|
|
283
|
+
headers: {
|
|
284
|
+
"x-api-key": apiKey
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// src/cms/pull/fetch-definition-reference.ts
|
|
290
|
+
async function fetchDefinitionReference(options) {
|
|
291
|
+
const client = createDeveloperAPIClient(options.baseUrl, options.apiKey);
|
|
292
|
+
const response = await client.GET(
|
|
293
|
+
"/projects/{projectName}/definitions/current/reference",
|
|
294
|
+
{
|
|
295
|
+
params: { path: { projectName: options.projectName } }
|
|
296
|
+
}
|
|
297
|
+
);
|
|
298
|
+
if (response.data) {
|
|
299
|
+
return response.data.content;
|
|
300
|
+
}
|
|
301
|
+
if (response.response.status === 404) {
|
|
302
|
+
throw new Error(`Project ${options.projectName} not found.`);
|
|
303
|
+
}
|
|
304
|
+
if (response.response.status === 401) {
|
|
305
|
+
throw new Error(`API Key is invalid.`);
|
|
306
|
+
}
|
|
307
|
+
throw new Error(
|
|
308
|
+
`Unknown error occurred when fetching definitions for project ${options.projectName}.`
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
// src/cms/pull/load-env.ts
|
|
313
|
+
var import_promises2 = __toESM(require("fs/promises"));
|
|
314
|
+
var v3 = __toESM(require("valibot"));
|
|
315
|
+
var import_dotenv = __toESM(require("dotenv"));
|
|
316
|
+
var EnvSchema = v3.object({
|
|
317
|
+
ORIZM_PROJECT: v3.pipe(
|
|
318
|
+
v3.string(),
|
|
319
|
+
v3.minLength(1, "ORIZM_PROJECT is required"),
|
|
320
|
+
v3.brand("ORIZM_PROJECT")
|
|
321
|
+
),
|
|
322
|
+
ORIZM_BASE_URL: v3.pipe(
|
|
323
|
+
v3.optional(v3.string(), "https://app.orizm.com"),
|
|
324
|
+
// if null, use default value
|
|
325
|
+
v3.transform((v4) => v4.replace(/\/$/, "")),
|
|
326
|
+
// remove trailing slash
|
|
327
|
+
v3.brand("ORIZM_BASE_URL")
|
|
328
|
+
),
|
|
329
|
+
ORIZM_API_KEY: v3.pipe(
|
|
330
|
+
v3.string(),
|
|
331
|
+
v3.minLength(1, "ORIZM_API_KEY is required"),
|
|
332
|
+
v3.brand("ORIZM_API_KEY")
|
|
333
|
+
)
|
|
334
|
+
});
|
|
335
|
+
async function loadEnv(envPath) {
|
|
336
|
+
const envFileContent = await import_promises2.default.readFile(envPath, "utf-8");
|
|
337
|
+
const dotenvParsed = import_dotenv.default.parse(envFileContent);
|
|
338
|
+
const envParseResult = v3.safeParse(EnvSchema, dotenvParsed);
|
|
339
|
+
if (!envParseResult.success) {
|
|
340
|
+
throw new Error(
|
|
341
|
+
`Environment variables are not valid. ${envParseResult.issues.map((issue) => `${issue.message}(at ${issue.path})`).join("\n")}`
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
const env = envParseResult.output;
|
|
345
|
+
return env;
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// src/cms/pull/action.ts
|
|
349
|
+
var spinner2 = createSpinner();
|
|
350
|
+
async function pullAction(options) {
|
|
351
|
+
const env = await loadEnv(options.envPath);
|
|
352
|
+
spinner2.start("Loading project schema...");
|
|
353
|
+
const definitionReference = await fetchDefinitionReference({
|
|
354
|
+
baseUrl: env.ORIZM_BASE_URL,
|
|
355
|
+
apiKey: env.ORIZM_API_KEY,
|
|
356
|
+
projectName: env.ORIZM_PROJECT
|
|
357
|
+
});
|
|
358
|
+
spinner2.succeed("Loaded project schema.");
|
|
359
|
+
spinner2.start("Generating code...");
|
|
360
|
+
await generate({
|
|
361
|
+
output: options.destination,
|
|
362
|
+
projectDef: definitionReference
|
|
363
|
+
});
|
|
364
|
+
spinner2.succeed(`Generated code to '${options.destination}'`);
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// src/cms/pull/command.ts
|
|
368
|
+
var cmsPullCommand = new import_commander2.Command("pull").description("pull orizm schema and generate client and types.").option("-e, --env <path>", "env file path.", ".env.x.local").option("-o, --output <path>", "output directory.", "./src/orizm").action(async (options) => {
|
|
369
|
+
try {
|
|
370
|
+
await pullAction({
|
|
371
|
+
destination: options.output,
|
|
372
|
+
envPath: options.env
|
|
373
|
+
});
|
|
374
|
+
} catch (error2) {
|
|
375
|
+
if (error2 instanceof Error) {
|
|
376
|
+
console.error(cliColor2.red("Error:", error2.message));
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
console.error("An unexpected error occurred:", error2);
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
// src/consumer/generate/command.ts
|
|
384
|
+
var import_commander3 = require("commander");
|
|
385
|
+
|
|
386
|
+
// src/consumer/generate/action.ts
|
|
387
|
+
var import_cli_color3 = __toESM(require("cli-color"));
|
|
388
|
+
|
|
389
|
+
// src/consumer/pull/generate.ts
|
|
390
|
+
var import_promises3 = require("fs/promises");
|
|
391
|
+
var import_path2 = __toESM(require("path"));
|
|
392
|
+
var import_handlebars2 = __toESM(require("handlebars"));
|
|
393
|
+
var import_cli_color2 = __toESM(require("cli-color"));
|
|
394
|
+
|
|
395
|
+
// src/consumer/templates/client.ts.hbr
|
|
396
|
+
var client_ts_default2 = '// This file was automatically generated and should not be edited.\n\nimport { ConsumerClientOptions, OrizmConsumerClientBase } from "@orizm/consumer-sdk";\nimport * as Models from "./types";\n\nexport class OrizmClient extends OrizmConsumerClientBase {\n constructor(options: ConsumerClientOptions) {\n super(options);\n }\n\n readonly tables = {\n {{#each tables}}\n {{toEndpointName this.name}}: this.getTableClient<Models.{{toCodeTypeName this.name}}__Descriptor>("{{toEndpointName this.name}}"),\n {{/each}}\n };\n}\n';
|
|
397
|
+
|
|
398
|
+
// src/consumer/templates/types.ts.hbr
|
|
399
|
+
var types_ts_default2 = '// This file was automatically generated and should not be edited.\n\nimport { FormValidationRules, StorageItemType } from "@orizm/common";\n\n// Utilities\ntype _ModuleRef<T> = T & _ModuleDescriptor;\ntype _ModuleDescriptor = {\n isModule: true;\n};\ntype _ArrayModuleRef<T> = T & _ArrayModuleDescriptor;\ntype _ArrayModuleDescriptor = {\n isModuleArray: true;\n};\n\n\n// Tables\n{{#each tables}}\nexport type {{toCodeTypeName this.name}} = {\n id: string;\n createdAt: string;\n updatedAt: string;\n group?: string;\n publishedAt?: string;\n _draft?: boolean;\n _published?: boolean;\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n {{#if this.enableForm}}\n formSchema: FormValidationRules;\n {{/if}}\n}\n\n{{/each}}\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}} = {\n {{#each this.columns}}\n {{this.name}}{{#unless this.required}}?{{/unless}}: {{typeName this}};\n {{/each}}\n};\n{{/each}}\n\n// Descriptor types\n{{#each tables}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n {{#if (filterUniqueIndexes this.indexes)}}\n unique: [\n {{#each (filterUniqueIndexes this.indexes)}}\n { {{#each (getIndexColumns ../this this)}}{{this.name}}:{{typeName this}},{{/each}} },\n {{/each}}\n ]\n {{/if}}\n {{#unless (filterUniqueIndexes this.indexes)}}\n unique: [];\n {{/unless}}\n {{#if this.enableDrafts}}\n enableDrafts: true;\n {{/if}}\n};\n{{/each}}\n\n\n{{#each tableModules}}\nexport type {{toCodeTypeName this.name}}__Descriptor = {\n row: {{toCodeTypeName this.name}};\n {{#if (filterRefColumn this.columns)}}\n refs: {\n {{#each (filterRefColumn this.columns)}}\n {{includeName this}}: {{{includeType this}}};\n {{/each}}\n }\n {{/if}}\n {{#unless (filterRefColumn this.columns)}}\n refs: object;\n {{/unless}}\n unique:[]\n};\n{{/each}}\n\n\n// Webhook types\nexport type WebhookEvent = "content.create" | "content.update" | "content.delete";\nexport type WebhookPayload = {\n event: WebhookEvent;\n timestamp: string;\n project: string;\n} & (\n {{#each tables}}\n | {\n table: "{{this.name}}";\n content: {{toCodeTypeName this.name}};\n old?: {{toCodeTypeName this.name}};\n }\n {{/each}}\n)\n';
|
|
400
|
+
|
|
401
|
+
// src/consumer/pull/generate.ts
|
|
402
|
+
async function generate2(options) {
|
|
403
|
+
console.log("generating ....");
|
|
404
|
+
await (0, import_promises3.mkdir)(options.output, { recursive: true });
|
|
405
|
+
await renderTypes2(options.definition, options.output);
|
|
406
|
+
await renderClient2(options.definition, options.output);
|
|
407
|
+
console.log("output to: ", options.output, " :", import_cli_color2.default.green("OK"));
|
|
408
|
+
}
|
|
409
|
+
import_handlebars2.default.registerHelper("toEndpointName", (str) => {
|
|
410
|
+
return str;
|
|
411
|
+
});
|
|
412
|
+
function toCodeTypeName2(str) {
|
|
413
|
+
str = str.charAt(0).toUpperCase() + str.slice(1);
|
|
414
|
+
return str.replace(/_([a-z])/g, (g) => g[1].toUpperCase());
|
|
415
|
+
}
|
|
416
|
+
import_handlebars2.default.registerHelper("toCodeTypeName", toCodeTypeName2);
|
|
417
|
+
import_handlebars2.default.registerHelper("typeName", (column) => {
|
|
418
|
+
if (column.type === "reference") {
|
|
419
|
+
return "string";
|
|
420
|
+
} else if (column.type == "json") {
|
|
421
|
+
return "unknown";
|
|
422
|
+
} else if (column.type === "module") {
|
|
423
|
+
if (!column.moduleName) {
|
|
424
|
+
console.warn("moduleName is not defined", column.name);
|
|
425
|
+
}
|
|
426
|
+
return toCodeTypeName2(column.moduleName || "unknown");
|
|
427
|
+
} else if (column.type === "module-array") {
|
|
428
|
+
if (!column.moduleName) {
|
|
429
|
+
console.warn("moduleName is not defined", column.name);
|
|
430
|
+
}
|
|
431
|
+
return toCodeTypeName2(column.moduleName || "unknown") + "[]";
|
|
432
|
+
} else if (column.type === "storage") {
|
|
433
|
+
return "StorageItemType";
|
|
434
|
+
} else {
|
|
435
|
+
return column.type;
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
import_handlebars2.default.registerHelper("filterRefColumn", (columns) => {
|
|
439
|
+
return (columns || []).filter(
|
|
440
|
+
(c) => c.type === "reference" && c.tableName && c.includeName || c.type === "module" && c.moduleName || c.type === "module-array" && c.moduleName
|
|
441
|
+
);
|
|
442
|
+
});
|
|
443
|
+
import_handlebars2.default.registerHelper("includeName", (column) => {
|
|
444
|
+
return column.type === "reference" ? column.includeName : column.name;
|
|
445
|
+
});
|
|
446
|
+
import_handlebars2.default.registerHelper("includeType", (column) => {
|
|
447
|
+
if (column.type === "reference" && column.tableName)
|
|
448
|
+
return toCodeTypeName2(column.tableName) + "__Descriptor";
|
|
449
|
+
if (column.type === "module" && column.moduleName)
|
|
450
|
+
return `_ModuleRef<${toCodeTypeName2(column.moduleName)}__Descriptor>`;
|
|
451
|
+
if (column.type === "module-array" && column.moduleName)
|
|
452
|
+
return `_ArrayModuleRef<${toCodeTypeName2(column.moduleName)}__Descriptor>`;
|
|
453
|
+
});
|
|
454
|
+
import_handlebars2.default.registerHelper("filterUniqueIndexes", (indexes) => {
|
|
455
|
+
return (indexes || []).filter((i) => i.unique);
|
|
456
|
+
});
|
|
457
|
+
import_handlebars2.default.registerHelper(
|
|
458
|
+
"getIndexColumns",
|
|
459
|
+
(table, index) => {
|
|
460
|
+
return index.columns.map((i) => {
|
|
461
|
+
const column = table.columns.find((c) => c.name === i);
|
|
462
|
+
if (!column) {
|
|
463
|
+
throw new Error(`column ${i} not found`);
|
|
464
|
+
}
|
|
465
|
+
return column;
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
);
|
|
469
|
+
async function renderTypes2(config, output) {
|
|
470
|
+
const rendered = import_handlebars2.default.compile(types_ts_default2)(config);
|
|
471
|
+
const targetPath = import_path2.default.join(output, "types.ts");
|
|
472
|
+
await (0, import_promises3.writeFile)(targetPath, rendered, "utf-8");
|
|
473
|
+
}
|
|
474
|
+
async function renderClient2(config, output) {
|
|
475
|
+
const rendered = import_handlebars2.default.compile(client_ts_default2)(config);
|
|
476
|
+
const targetPath = import_path2.default.join(output, "client.ts");
|
|
477
|
+
await (0, import_promises3.writeFile)(targetPath, rendered, "utf-8");
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// src/consumer/generate/action.ts
|
|
481
|
+
async function generateAction(orizmConfigTs, destination) {
|
|
482
|
+
try {
|
|
483
|
+
const definition = await loadConfig(orizmConfigTs);
|
|
484
|
+
console.log(`definition: ${orizmConfigTs}`);
|
|
485
|
+
await generate2({
|
|
486
|
+
definition,
|
|
487
|
+
output: destination
|
|
488
|
+
});
|
|
489
|
+
} catch (e) {
|
|
490
|
+
console.error(import_cli_color3.default.red(e));
|
|
491
|
+
process.exit(1);
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
// src/consumer/generate/command.ts
|
|
496
|
+
var consumerGenerateCommand = new import_commander3.Command("generate").description("generate orizm client and types.").option("-c, --config <path>", "orizm config file path.", "orizm.config.ts").option("-o, --output <path>", "output directory.", "./src/orizm").action(async (options) => {
|
|
497
|
+
await generateAction(options.config, options.output);
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
// src/consumer/pull/command.ts
|
|
501
|
+
var import_commander4 = require("commander");
|
|
502
|
+
|
|
503
|
+
// src/consumer/pull/action.ts
|
|
504
|
+
var import_cli_color5 = __toESM(require("cli-color"));
|
|
505
|
+
|
|
506
|
+
// src/consumer/pull/pull.ts
|
|
507
|
+
var import_cli_color4 = __toESM(require("cli-color"));
|
|
508
|
+
async function pullDefinition(config) {
|
|
509
|
+
console.log("pull definition ....");
|
|
510
|
+
const abortController = new AbortController();
|
|
511
|
+
const abortTimer = setTimeout(() => {
|
|
512
|
+
abortController.abort();
|
|
513
|
+
}, 1e4);
|
|
514
|
+
try {
|
|
515
|
+
const url = new URL(config.baseUrl);
|
|
516
|
+
url.pathname = `/api/consumer/v1/${config.projectName}/definitions/current`;
|
|
517
|
+
const response = await fetch(url, {
|
|
518
|
+
headers: {
|
|
519
|
+
"x-consumer-key": config.consumerKey,
|
|
520
|
+
"User-Agent": "orizm-consumer-cli"
|
|
521
|
+
},
|
|
522
|
+
signal: abortController.signal
|
|
523
|
+
});
|
|
524
|
+
if (response.ok) {
|
|
525
|
+
const definition = await response.json().then((data) => data.content);
|
|
526
|
+
console.log(
|
|
527
|
+
`definitionVersion: ${definition.definitionVersion}`,
|
|
528
|
+
import_cli_color4.default.green("OK")
|
|
529
|
+
);
|
|
530
|
+
return definition;
|
|
531
|
+
} else {
|
|
532
|
+
throw new Error(
|
|
533
|
+
`Failed to pull definition : status code ${response.status}
|
|
534
|
+
${response.statusText}`
|
|
535
|
+
);
|
|
536
|
+
}
|
|
537
|
+
} catch (e) {
|
|
538
|
+
if (e instanceof TypeError || e instanceof DOMException && e.name === "AbortError") {
|
|
539
|
+
throw new Error("Failed to pull definition: " + String(e));
|
|
540
|
+
}
|
|
541
|
+
throw e;
|
|
542
|
+
} finally {
|
|
543
|
+
clearTimeout(abortTimer);
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
// src/consumer/pull/config.ts
|
|
548
|
+
var import_fs = require("fs");
|
|
549
|
+
var import_dotenv2 = require("dotenv");
|
|
550
|
+
async function loadConfig2(configPath) {
|
|
551
|
+
const config = (() => {
|
|
552
|
+
if ((0, import_fs.existsSync)(configPath)) {
|
|
553
|
+
const env = (0, import_fs.readFileSync)(configPath);
|
|
554
|
+
return (0, import_dotenv2.parse)(env);
|
|
555
|
+
} else {
|
|
556
|
+
return {};
|
|
557
|
+
}
|
|
558
|
+
})();
|
|
559
|
+
const projectName = config.ORIZM_PROJECT_NAME || process.env.ORIZM_PROJECT_NAME;
|
|
560
|
+
const consumerKey = config.ORIZM_CONSUMER_KEY || process.env.ORIZM_CONSUMER_KEY;
|
|
561
|
+
const baseUrl = config.ORIZM_BASE_URL || process.env.ORIZM_BASE_URL || "https://app.orizm.com";
|
|
562
|
+
console.log(`ORIZM_BASE_URL : ${baseUrl}`);
|
|
563
|
+
console.log(`ORIZM_PROJECT_NAME: ${projectName}`);
|
|
564
|
+
console.log(`ORIZM_CONSUMER_KEY: ${consumerKey ? "****" : void 0}`);
|
|
565
|
+
if (!projectName || !consumerKey) {
|
|
566
|
+
const errors = [];
|
|
567
|
+
if (!projectName) {
|
|
568
|
+
errors.push(
|
|
569
|
+
"ORIZM_CONSUMER_KEY is not set. Please set ORIZM_CONSUMER_KEY in .env.x-consumer-cli.local or environment variable."
|
|
570
|
+
);
|
|
571
|
+
}
|
|
572
|
+
if (!consumerKey) {
|
|
573
|
+
errors.push(
|
|
574
|
+
"ORIZM_PROJECT_NAME is not set. Please set ORIZM_PROJECT_NAME in .env.x-consumer-cli.local or environment variable."
|
|
575
|
+
);
|
|
576
|
+
}
|
|
577
|
+
throw new Error(errors.join("\n"));
|
|
578
|
+
}
|
|
579
|
+
return {
|
|
580
|
+
projectName,
|
|
581
|
+
consumerKey,
|
|
582
|
+
baseUrl
|
|
583
|
+
};
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
// src/consumer/pull/action.ts
|
|
587
|
+
async function pullAction2(options) {
|
|
588
|
+
try {
|
|
589
|
+
const config = await loadConfig2(options.envPath);
|
|
590
|
+
const definition = await pullDefinition(config);
|
|
591
|
+
await generate2({
|
|
592
|
+
definition,
|
|
593
|
+
output: options.destination
|
|
594
|
+
});
|
|
595
|
+
} catch (e) {
|
|
596
|
+
console.error(import_cli_color5.default.red(e));
|
|
597
|
+
process.exit(1);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
// src/consumer/pull/command.ts
|
|
602
|
+
var consumerPullCommand = new import_commander4.Command("pull").description("pull orizm schema and generate client and types.").option("-e, --env <path>", "env file path.", ".env.x-consumer-cli.local").option("-o, --output <path>", "output directory.", "./src/orizm").action(async (options) => {
|
|
603
|
+
await pullAction2({
|
|
604
|
+
destination: options.output,
|
|
605
|
+
envPath: options.env
|
|
606
|
+
});
|
|
607
|
+
});
|
|
608
|
+
|
|
609
|
+
// src/push/command.ts
|
|
610
|
+
var import_commander5 = require("commander");
|
|
611
|
+
var import_cli_color7 = require("cli-color");
|
|
612
|
+
|
|
613
|
+
// src/lib/env-manager.ts
|
|
614
|
+
var import_fs2 = __toESM(require("fs"));
|
|
615
|
+
var import_dotenv3 = __toESM(require("dotenv"));
|
|
616
|
+
var import_valibot = require("valibot");
|
|
617
|
+
var defaultEnvFilePath = ".env.x.local";
|
|
618
|
+
var schema = (0, import_valibot.object)({
|
|
619
|
+
ORIZM_PROJECT: (0, import_valibot.pipe)(
|
|
620
|
+
(0, import_valibot.string)(),
|
|
621
|
+
(0, import_valibot.minLength)(1, "ORIZM_PROJECT is required"),
|
|
622
|
+
(0, import_valibot.brand)("ORIZM_PROJECT")
|
|
623
|
+
),
|
|
624
|
+
ORIZM_BASE_URL: (0, import_valibot.pipe)(
|
|
625
|
+
(0, import_valibot.nullish)((0, import_valibot.string)(), "https://app.orizm.com"),
|
|
626
|
+
// if null, use default value
|
|
627
|
+
(0, import_valibot.transform)((v4) => v4.replace(/\/$/, "")),
|
|
628
|
+
// remove trailing slash
|
|
629
|
+
(0, import_valibot.brand)("ORIZM_BASE_URL")
|
|
630
|
+
),
|
|
631
|
+
ORIZM_API_KEY: (0, import_valibot.pipe)(
|
|
632
|
+
(0, import_valibot.string)(),
|
|
633
|
+
(0, import_valibot.minLength)(1, "ORIZM_API_KEY is required"),
|
|
634
|
+
(0, import_valibot.brand)("ORIZM_API_KEY")
|
|
635
|
+
)
|
|
636
|
+
});
|
|
637
|
+
var EnvManager = class {
|
|
638
|
+
parsed;
|
|
639
|
+
constructor(envFilePath) {
|
|
640
|
+
if (envFilePath && import_fs2.default.existsSync(envFilePath)) {
|
|
641
|
+
import_dotenv3.default.config({ path: envFilePath });
|
|
642
|
+
} else if (envFilePath !== defaultEnvFilePath) {
|
|
643
|
+
throw new Error(
|
|
644
|
+
`environment variables file: '${envFilePath}' is not found.`
|
|
645
|
+
);
|
|
646
|
+
} else {
|
|
647
|
+
import_dotenv3.default.config();
|
|
648
|
+
}
|
|
649
|
+
const result = (0, import_valibot.parse)(schema, process.env);
|
|
650
|
+
this.parsed = result;
|
|
651
|
+
}
|
|
652
|
+
get projectName() {
|
|
653
|
+
return this.parsed.ORIZM_PROJECT;
|
|
654
|
+
}
|
|
655
|
+
get baseUrl() {
|
|
656
|
+
return this.parsed.ORIZM_BASE_URL;
|
|
657
|
+
}
|
|
658
|
+
get apiKey() {
|
|
659
|
+
return this.parsed.ORIZM_API_KEY;
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
// src/lib/developer-api.ts
|
|
664
|
+
async function request(props) {
|
|
665
|
+
return await fetch(`${props.env.baseUrl}/api/dev/v1${props.path}`, {
|
|
666
|
+
method: props.method,
|
|
667
|
+
headers: {
|
|
668
|
+
"content-type": "application/json",
|
|
669
|
+
"x-api-key": props.env.apiKey
|
|
670
|
+
},
|
|
671
|
+
body: JSON.stringify(props.body)
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
async function applyDefinition(env, projectDef) {
|
|
675
|
+
const response = await request({
|
|
676
|
+
env,
|
|
677
|
+
method: "POST",
|
|
678
|
+
path: `/projects/${env.projectName}/definitions`,
|
|
679
|
+
body: { apply: true, project: projectDef }
|
|
680
|
+
});
|
|
681
|
+
if (!response.ok) {
|
|
682
|
+
const status = response.status;
|
|
683
|
+
if (status === 401) {
|
|
684
|
+
throw new Error(
|
|
685
|
+
"401 Unauthorized. Please check your Developer API key and try again."
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
throw new Error(
|
|
689
|
+
`${status} ${response.statusText}: Occurred unexpected error.`
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
var getChangeEvents = async (env, projectDef) => {
|
|
694
|
+
const response = await request({
|
|
695
|
+
env,
|
|
696
|
+
method: "POST",
|
|
697
|
+
path: `/projects/${env.projectName}/definitions/dry-run`,
|
|
698
|
+
body: { project: projectDef }
|
|
699
|
+
});
|
|
700
|
+
if (!response.ok) {
|
|
701
|
+
const status = response.status;
|
|
702
|
+
if (status === 400) {
|
|
703
|
+
const body = await response.json();
|
|
704
|
+
throw new Error(`400 Bad Request:
|
|
705
|
+
${JSON.stringify(body, null, 2)}`);
|
|
706
|
+
}
|
|
707
|
+
if (status === 401) {
|
|
708
|
+
throw new Error(
|
|
709
|
+
"401 Unauthorized: Please check your Developer API key and try again."
|
|
710
|
+
);
|
|
711
|
+
}
|
|
712
|
+
throw new Error(
|
|
713
|
+
`${status} ${response.statusText}: Occurred unexpected error.`
|
|
714
|
+
);
|
|
715
|
+
}
|
|
716
|
+
return await response.json();
|
|
717
|
+
};
|
|
718
|
+
|
|
719
|
+
// src/lib/display-change-events.ts
|
|
720
|
+
var import_cli_color6 = require("cli-color");
|
|
721
|
+
|
|
722
|
+
// src/lib/cli-table.ts
|
|
723
|
+
var COLORS = {
|
|
724
|
+
reset: "\x1B[0m",
|
|
725
|
+
green: "\x1B[32m",
|
|
726
|
+
red: "\x1B[31m"
|
|
727
|
+
};
|
|
728
|
+
var CliTable = class {
|
|
729
|
+
headers = [];
|
|
730
|
+
rows = [];
|
|
731
|
+
columnWidths = [];
|
|
732
|
+
rowColors = [];
|
|
733
|
+
// 各行の色を保持する配列
|
|
734
|
+
constructor(headers) {
|
|
735
|
+
this.headers = headers;
|
|
736
|
+
this.updateColumnWidths(headers);
|
|
737
|
+
}
|
|
738
|
+
// データ行を追加
|
|
739
|
+
addRow(row, options) {
|
|
740
|
+
if (row.length !== this.headers.length) {
|
|
741
|
+
throw new Error(
|
|
742
|
+
`The length of the row (${row.length}) does not match the length of the header (${this.headers.length})`
|
|
743
|
+
);
|
|
744
|
+
}
|
|
745
|
+
this.rows.push(row);
|
|
746
|
+
if (options?.color) {
|
|
747
|
+
this.rowColors.push(COLORS[options.color]);
|
|
748
|
+
} else {
|
|
749
|
+
this.rowColors.push(null);
|
|
750
|
+
}
|
|
751
|
+
this.updateColumnWidths(row);
|
|
752
|
+
}
|
|
753
|
+
// 列幅を更新
|
|
754
|
+
updateColumnWidths(row) {
|
|
755
|
+
for (let i = 0; i < row.length; i++) {
|
|
756
|
+
const cellLength = row[i].length;
|
|
757
|
+
if (!this.columnWidths[i] || cellLength > this.columnWidths[i]) {
|
|
758
|
+
this.columnWidths[i] = cellLength;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
// 水平線を生成
|
|
763
|
+
createHorizontalLine(position) {
|
|
764
|
+
let line = "";
|
|
765
|
+
if (position === "top") line += "\u250C";
|
|
766
|
+
else if (position === "middle") line += "\u251C";
|
|
767
|
+
else if (position === "bottom") line += "\u2514";
|
|
768
|
+
for (let i = 0; i < this.columnWidths.length; i++) {
|
|
769
|
+
line += "\u2500".repeat(this.columnWidths[i] + 2);
|
|
770
|
+
if (i < this.columnWidths.length - 1) {
|
|
771
|
+
if (position === "top") line += "\u252C";
|
|
772
|
+
else if (position === "middle") line += "\u253C";
|
|
773
|
+
else if (position === "bottom") line += "\u2534";
|
|
774
|
+
} else {
|
|
775
|
+
if (position === "top") line += "\u2510";
|
|
776
|
+
else if (position === "middle") line += "\u2524";
|
|
777
|
+
else if (position === "bottom") line += "\u2518";
|
|
778
|
+
}
|
|
779
|
+
}
|
|
780
|
+
return line;
|
|
781
|
+
}
|
|
782
|
+
// 行を整形
|
|
783
|
+
formatRow(row, color) {
|
|
784
|
+
let formattedRow = "\u2502";
|
|
785
|
+
for (let i = 0; i < row.length; i++) {
|
|
786
|
+
const cell = row[i];
|
|
787
|
+
const padding = " ".repeat(this.columnWidths[i] - cell.length);
|
|
788
|
+
if (color) {
|
|
789
|
+
formattedRow += ` ${color}${cell}${COLORS.reset}${padding} \u2502`;
|
|
790
|
+
} else {
|
|
791
|
+
formattedRow += ` ${cell}${padding} \u2502`;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return formattedRow;
|
|
795
|
+
}
|
|
796
|
+
// テーブルを文字列として取得
|
|
797
|
+
toString() {
|
|
798
|
+
if (this.headers.length === 0) {
|
|
799
|
+
return "";
|
|
800
|
+
}
|
|
801
|
+
const topLine = this.createHorizontalLine("top");
|
|
802
|
+
const middleLine = this.createHorizontalLine("middle");
|
|
803
|
+
const bottomLine = this.createHorizontalLine("bottom");
|
|
804
|
+
let table = topLine + "\n";
|
|
805
|
+
table += this.formatRow(this.headers, null) + "\n";
|
|
806
|
+
table += middleLine + "\n";
|
|
807
|
+
for (let i = 0; i < this.rows.length; i++) {
|
|
808
|
+
const color = this.rowColors[i] || null;
|
|
809
|
+
table += this.formatRow(this.rows[i], color) + "\n";
|
|
810
|
+
}
|
|
811
|
+
table += bottomLine;
|
|
812
|
+
return table;
|
|
813
|
+
}
|
|
814
|
+
// テーブルを出力
|
|
815
|
+
print() {
|
|
816
|
+
console.log(this.toString());
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
// src/lib/display-change-events.ts
|
|
821
|
+
async function displayChangeEvents(changeEvents) {
|
|
822
|
+
const tableChangeEvents = changeEvents.tableChangeEvents ?? [];
|
|
823
|
+
if (tableChangeEvents.length === 0) {
|
|
824
|
+
console.log();
|
|
825
|
+
console.log((0, import_cli_color6.green)("No changes."));
|
|
826
|
+
return;
|
|
827
|
+
}
|
|
828
|
+
const eventsByTable = /* @__PURE__ */ new Map();
|
|
829
|
+
for (const event of tableChangeEvents) {
|
|
830
|
+
const tableName = event.tableDef.name;
|
|
831
|
+
const tableEvents = eventsByTable.get(tableName) ?? [];
|
|
832
|
+
tableEvents.push(event);
|
|
833
|
+
eventsByTable.set(tableName, tableEvents);
|
|
834
|
+
}
|
|
835
|
+
for (const [tableName, events] of eventsByTable.entries()) {
|
|
836
|
+
console.log();
|
|
837
|
+
console.log(`\u26AB\uFE0ETable: ${tableName}`);
|
|
838
|
+
const table = new CliTable(["Type", "Name", "Event", "Detail"]);
|
|
839
|
+
for (const event of events) {
|
|
840
|
+
const eventName = event.event;
|
|
841
|
+
switch (eventName) {
|
|
842
|
+
case "table:create":
|
|
843
|
+
case "table:update": {
|
|
844
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
845
|
+
color: "green"
|
|
846
|
+
});
|
|
847
|
+
break;
|
|
848
|
+
}
|
|
849
|
+
case "table:delete": {
|
|
850
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
851
|
+
color: "red"
|
|
852
|
+
});
|
|
853
|
+
break;
|
|
854
|
+
}
|
|
855
|
+
case "column:create":
|
|
856
|
+
case "column:update": {
|
|
857
|
+
table.addRow(
|
|
858
|
+
[
|
|
859
|
+
"column",
|
|
860
|
+
event.columnDef.name,
|
|
861
|
+
eventName,
|
|
862
|
+
JSON.stringify(event.columnDef)
|
|
863
|
+
],
|
|
864
|
+
{ color: "green" }
|
|
865
|
+
);
|
|
866
|
+
break;
|
|
867
|
+
}
|
|
868
|
+
case "column:delete": {
|
|
869
|
+
table.addRow(
|
|
870
|
+
[
|
|
871
|
+
"column",
|
|
872
|
+
event.columnDef.name,
|
|
873
|
+
eventName,
|
|
874
|
+
JSON.stringify(event.columnDef)
|
|
875
|
+
],
|
|
876
|
+
{
|
|
877
|
+
color: "red"
|
|
878
|
+
}
|
|
879
|
+
);
|
|
880
|
+
break;
|
|
881
|
+
}
|
|
882
|
+
case "index:create":
|
|
883
|
+
case "index:update": {
|
|
884
|
+
table.addRow(
|
|
885
|
+
[
|
|
886
|
+
"index",
|
|
887
|
+
event.indexDef.columns.join(", "),
|
|
888
|
+
eventName,
|
|
889
|
+
JSON.stringify(event.indexDef)
|
|
890
|
+
],
|
|
891
|
+
{ color: "green" }
|
|
892
|
+
);
|
|
893
|
+
break;
|
|
894
|
+
}
|
|
895
|
+
case "index:delete": {
|
|
896
|
+
table.addRow(
|
|
897
|
+
[
|
|
898
|
+
"index",
|
|
899
|
+
event.indexDef.columns.join(", "),
|
|
900
|
+
eventName,
|
|
901
|
+
JSON.stringify(event.indexDef)
|
|
902
|
+
],
|
|
903
|
+
{ color: "red" }
|
|
904
|
+
);
|
|
905
|
+
break;
|
|
906
|
+
}
|
|
907
|
+
case "module:create":
|
|
908
|
+
case "module:update": {
|
|
909
|
+
table.addRow(
|
|
910
|
+
[
|
|
911
|
+
"module",
|
|
912
|
+
event.columnDef.name,
|
|
913
|
+
eventName,
|
|
914
|
+
JSON.stringify(event.columnDef)
|
|
915
|
+
],
|
|
916
|
+
{
|
|
917
|
+
color: "green"
|
|
918
|
+
}
|
|
919
|
+
);
|
|
920
|
+
break;
|
|
921
|
+
}
|
|
922
|
+
case "module:delete": {
|
|
923
|
+
table.addRow(
|
|
924
|
+
[
|
|
925
|
+
"module",
|
|
926
|
+
event.columnDef.name,
|
|
927
|
+
eventName,
|
|
928
|
+
JSON.stringify(event.columnDef)
|
|
929
|
+
],
|
|
930
|
+
{
|
|
931
|
+
color: "red"
|
|
932
|
+
}
|
|
933
|
+
);
|
|
934
|
+
break;
|
|
935
|
+
}
|
|
936
|
+
case "search:enable":
|
|
937
|
+
case "search:update": {
|
|
938
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
939
|
+
color: "green"
|
|
940
|
+
});
|
|
941
|
+
break;
|
|
942
|
+
}
|
|
943
|
+
case "search:disable": {
|
|
944
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
945
|
+
color: "red"
|
|
946
|
+
});
|
|
947
|
+
break;
|
|
948
|
+
}
|
|
949
|
+
case "history:enable": {
|
|
950
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
951
|
+
color: "green"
|
|
952
|
+
});
|
|
953
|
+
break;
|
|
954
|
+
}
|
|
955
|
+
case "history:disable": {
|
|
956
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
957
|
+
color: "red"
|
|
958
|
+
});
|
|
959
|
+
break;
|
|
960
|
+
}
|
|
961
|
+
case "formSubmissions:create":
|
|
962
|
+
case "formSubmissions:update": {
|
|
963
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
964
|
+
color: "green"
|
|
965
|
+
});
|
|
966
|
+
break;
|
|
967
|
+
}
|
|
968
|
+
case "formSubmissions:delete": {
|
|
969
|
+
table.addRow(["table", event.tableDef.name, eventName, ""], {
|
|
970
|
+
color: "red"
|
|
971
|
+
});
|
|
972
|
+
break;
|
|
973
|
+
}
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
table.print();
|
|
977
|
+
console.log();
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
// src/lib/cli-input.ts
|
|
982
|
+
var import_promises4 = require("readline/promises");
|
|
983
|
+
async function input(prompt) {
|
|
984
|
+
const rl = (0, import_promises4.createInterface)({
|
|
985
|
+
input: process.stdin,
|
|
986
|
+
output: process.stdout
|
|
987
|
+
});
|
|
988
|
+
const input2 = await rl.question(prompt).finally(() => {
|
|
989
|
+
rl.close();
|
|
990
|
+
});
|
|
991
|
+
return input2.trim();
|
|
992
|
+
}
|
|
993
|
+
|
|
994
|
+
// src/push/command.ts
|
|
995
|
+
var spinner3 = createSpinner();
|
|
996
|
+
var pushCommand = new import_commander5.Command("push").description("apply schema to project.").option("-e, --env <path>", "env file path.", ".env.x.local").option("-c, --config <path>", "orizm config file path.", "orizm.config.ts").option("--dry-run", "display change-events without applying schema.", false).option("-y, --yes", "apply schema without confirmation.", false).action(async (options) => {
|
|
997
|
+
try {
|
|
998
|
+
spinner3.start("Loading environment variables...");
|
|
999
|
+
const env = new EnvManager(options.env);
|
|
1000
|
+
spinner3.succeed("Loaded environment variables.");
|
|
1001
|
+
spinner3.start("Loading project schema...");
|
|
1002
|
+
const projectDef = await loadConfig(options.config);
|
|
1003
|
+
spinner3.succeed("Loaded project schema.");
|
|
1004
|
+
spinner3.start("Fetch schema change events...");
|
|
1005
|
+
const changeEvents = await getChangeEvents(env, projectDef);
|
|
1006
|
+
spinner3.succeed("Fetch schema change events.");
|
|
1007
|
+
await displayChangeEvents(changeEvents);
|
|
1008
|
+
if (changeEvents.tableChangeEvents.length === 0) {
|
|
1009
|
+
return;
|
|
1010
|
+
}
|
|
1011
|
+
if (options.dryRun) {
|
|
1012
|
+
return;
|
|
1013
|
+
}
|
|
1014
|
+
if (!options.yes) {
|
|
1015
|
+
const confirm = await input("Do you want to apply schema? (y/N): ");
|
|
1016
|
+
if (confirm !== "y") {
|
|
1017
|
+
console.log((0, import_cli_color7.red)("Canceled."));
|
|
1018
|
+
return;
|
|
1019
|
+
}
|
|
1020
|
+
}
|
|
1021
|
+
spinner3.start("Applying schema...");
|
|
1022
|
+
await applyDefinition(env, projectDef);
|
|
1023
|
+
spinner3.succeed("Schema applied.");
|
|
1024
|
+
} catch (error2) {
|
|
1025
|
+
handleError(error2);
|
|
1026
|
+
}
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
// src/cli.ts
|
|
1030
|
+
import_commander6.program.name("orizm CLI");
|
|
1031
|
+
import_commander6.program.addCommand(pushCommand);
|
|
1032
|
+
var cmsCommands = new import_commander6.Command("cms").description("cms commands.");
|
|
1033
|
+
cmsCommands.addCommand(cmsGenerateCommand);
|
|
1034
|
+
cmsCommands.addCommand(cmsPullCommand);
|
|
1035
|
+
import_commander6.program.addCommand(cmsCommands);
|
|
1036
|
+
var consumerCommands = new import_commander6.Command("consumer").description(
|
|
1037
|
+
"consumer commands."
|
|
1038
|
+
);
|
|
1039
|
+
consumerCommands.addCommand(consumerGenerateCommand);
|
|
1040
|
+
consumerCommands.addCommand(consumerPullCommand);
|
|
1041
|
+
import_commander6.program.addCommand(consumerCommands);
|
|
1042
|
+
import_commander6.program.parse();
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@orizm/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Orizm CLI",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/chot-Inc/superx.git",
|
|
8
|
+
"directory": "packages/orizm-cli"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"bin",
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"cli-color": "^2.0.3",
|
|
16
|
+
"commander": "^10.0.0",
|
|
17
|
+
"dotenv": "^16.3.1",
|
|
18
|
+
"esbuild": "^0.17.19",
|
|
19
|
+
"handlebars": "^4.7.7",
|
|
20
|
+
"openapi-fetch": "^0.12.2",
|
|
21
|
+
"valibot": "^1.0.0",
|
|
22
|
+
"@orizm/common": "1.11.0"
|
|
23
|
+
},
|
|
24
|
+
"bin": {
|
|
25
|
+
"orizm": "bin/index.js"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"@types/cli-color": "^2.0.2",
|
|
29
|
+
"openapi-typescript": "^7.6.1",
|
|
30
|
+
"@orizm/package-configs": "0.0.0"
|
|
31
|
+
},
|
|
32
|
+
"license": "Apache-2.0",
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsup",
|
|
35
|
+
"typecheck": "tsc --noEmit",
|
|
36
|
+
"generate": "openapi-typescript ../../apps/server/openapi/developerAPI.yaml --output src/api/developer-api.d.ts"
|
|
37
|
+
}
|
|
38
|
+
}
|