@omnixdp/typegen 0.2.1 → 0.3.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/README.md +1 -1
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +52 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +4 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,7 @@ npx omnixdp-typegen \
|
|
|
25
25
|
--out src/omnixdp.generated.ts
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
Space arguments can be a space id, slug, or exact name. Typegen exchanges client credentials for short-lived access tokens. Existing `--management-token`, `--business-objects-token`, and `--ratings-and-reviews-token` flags remain supported when you already have bearer tokens. Regenerate the output after changing content types, taxonomy types, data types, or global fields in the admin.
|
|
28
|
+
Space arguments can be a space id, slug, or exact name. Typegen loads `.env` and `.env.local` before evaluating config files, then exchanges client credentials for short-lived access tokens. Existing `--management-token`, `--business-objects-token`, and `--ratings-and-reviews-token` flags remain supported when you already have bearer tokens. Regenerate the output after changing content types, taxonomy types, data types, or global fields in the admin.
|
|
29
29
|
|
|
30
30
|
## Check in CI
|
|
31
31
|
|
package/dist/cli.d.ts
CHANGED
package/dist/cli.js
CHANGED
|
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
+
exports.loadEnvFiles = loadEnvFiles;
|
|
27
28
|
exports.loadConfig = loadConfig;
|
|
28
29
|
const promises_1 = require("node:fs/promises");
|
|
29
30
|
const node_module_1 = require("node:module");
|
|
@@ -38,6 +39,7 @@ async function main() {
|
|
|
38
39
|
printHelp();
|
|
39
40
|
return;
|
|
40
41
|
}
|
|
42
|
+
await loadEnvFiles();
|
|
41
43
|
const fileConfig = args.config ? await loadConfig(args.config) : await loadDefaultConfig();
|
|
42
44
|
const config = compactConfig({ ...fileConfig, ...args });
|
|
43
45
|
const out = config.out ?? "src/omnixdp.generated.ts";
|
|
@@ -59,6 +61,56 @@ async function main() {
|
|
|
59
61
|
await (0, promises_1.writeFile)(outPath, output, "utf8");
|
|
60
62
|
console.log(`Generated ${out}`);
|
|
61
63
|
}
|
|
64
|
+
async function loadEnvFiles(cwd = process.cwd()) {
|
|
65
|
+
const protectedKeys = new Set(Object.keys(process.env));
|
|
66
|
+
for (const file of [".env", ".env.local"]) {
|
|
67
|
+
const values = await readEnvFile((0, node_path_1.join)(cwd, file));
|
|
68
|
+
for (const [key, value] of Object.entries(values)) {
|
|
69
|
+
if (!protectedKeys.has(key)) {
|
|
70
|
+
process.env[key] = value;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
async function readEnvFile(path) {
|
|
76
|
+
const content = await (0, promises_1.readFile)(path, "utf8").catch((error) => {
|
|
77
|
+
if (error.code === "ENOENT")
|
|
78
|
+
return null;
|
|
79
|
+
throw error;
|
|
80
|
+
});
|
|
81
|
+
if (content === null)
|
|
82
|
+
return {};
|
|
83
|
+
const values = {};
|
|
84
|
+
for (const line of content.split(/\r?\n/)) {
|
|
85
|
+
const parsed = parseEnvLine(line);
|
|
86
|
+
if (parsed) {
|
|
87
|
+
values[parsed.key] = parsed.value;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return values;
|
|
91
|
+
}
|
|
92
|
+
function parseEnvLine(line) {
|
|
93
|
+
const trimmed = line.trim();
|
|
94
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
95
|
+
return null;
|
|
96
|
+
const normalized = trimmed.startsWith("export ") ? trimmed.slice("export ".length).trimStart() : trimmed;
|
|
97
|
+
const separatorIndex = normalized.indexOf("=");
|
|
98
|
+
if (separatorIndex <= 0)
|
|
99
|
+
return null;
|
|
100
|
+
const key = normalized.slice(0, separatorIndex).trim();
|
|
101
|
+
if (!/^[A-Za-z_][A-Za-z0-9_]*$/.test(key))
|
|
102
|
+
return null;
|
|
103
|
+
return { key, value: unquoteEnvValue(normalized.slice(separatorIndex + 1).trim()) };
|
|
104
|
+
}
|
|
105
|
+
function unquoteEnvValue(value) {
|
|
106
|
+
if (value.length >= 2 && value.startsWith("\"") && value.endsWith("\"")) {
|
|
107
|
+
return value.slice(1, -1).replace(/\\n/g, "\n").replace(/\\r/g, "\r").replace(/\\"/g, "\"").replace(/\\\\/g, "\\");
|
|
108
|
+
}
|
|
109
|
+
if (value.length >= 2 && value.startsWith("'") && value.endsWith("'")) {
|
|
110
|
+
return value.slice(1, -1);
|
|
111
|
+
}
|
|
112
|
+
return value.replace(/\s+#.*$/, "");
|
|
113
|
+
}
|
|
62
114
|
function parseArgs(argv) {
|
|
63
115
|
const out = {};
|
|
64
116
|
for (let i = 0; i < argv.length; i += 1) {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export { fetchTypegenSchema, normalizeApiUrl } from "./fetch-schema";
|
|
2
2
|
export { generateTypes } from "./generate";
|
|
3
|
+
export { loadConfig, loadEnvFiles } from "./cli";
|
|
3
4
|
export type { TypegenApplication, TypegenConfig, TypegenField, TypegenFieldKind, TypegenModel, TypegenSchema, TypegenSpace } from "./schema";
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateTypes = exports.normalizeApiUrl = exports.fetchTypegenSchema = void 0;
|
|
3
|
+
exports.loadEnvFiles = exports.loadConfig = exports.generateTypes = exports.normalizeApiUrl = exports.fetchTypegenSchema = void 0;
|
|
4
4
|
var fetch_schema_1 = require("./fetch-schema");
|
|
5
5
|
Object.defineProperty(exports, "fetchTypegenSchema", { enumerable: true, get: function () { return fetch_schema_1.fetchTypegenSchema; } });
|
|
6
6
|
Object.defineProperty(exports, "normalizeApiUrl", { enumerable: true, get: function () { return fetch_schema_1.normalizeApiUrl; } });
|
|
7
7
|
var generate_1 = require("./generate");
|
|
8
8
|
Object.defineProperty(exports, "generateTypes", { enumerable: true, get: function () { return generate_1.generateTypes; } });
|
|
9
|
+
var cli_1 = require("./cli");
|
|
10
|
+
Object.defineProperty(exports, "loadConfig", { enumerable: true, get: function () { return cli_1.loadConfig; } });
|
|
11
|
+
Object.defineProperty(exports, "loadEnvFiles", { enumerable: true, get: function () { return cli_1.loadEnvFiles; } });
|