@olenbetong/appframe-vite 6.1.2 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +115 -5
- package/lib/cli-resources-add.d.ts +1 -0
- package/lib/cli-resources-add.js +184 -0
- package/lib/cli-resources-edit.d.ts +1 -0
- package/lib/cli-resources-edit.js +177 -0
- package/lib/cli-resources-generate.d.ts +1 -0
- package/lib/cli-resources-generate.js +44 -0
- package/lib/cli.js +40 -16
- package/lib/index.js +27 -0
- package/lib/resourceGenerate.d.ts +63 -0
- package/lib/resourceGenerate.js +567 -0
- package/lib/resourcesConfig.d.ts +55 -0
- package/lib/resourcesConfig.js +111 -0
- package/package.json +12 -3
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import { readFile, writeFile } from "node:fs/promises";
|
|
3
|
+
import { resolve } from "node:path";
|
|
4
|
+
import { parse as parseYaml, stringify as stringifyYaml } from "yaml";
|
|
5
|
+
// ---------------------------------------------------------------------------
|
|
6
|
+
// Config file path
|
|
7
|
+
// ---------------------------------------------------------------------------
|
|
8
|
+
export const RESOURCES_CONFIG_FILE = "resources.yaml";
|
|
9
|
+
export function getResourcesConfigPath(filePath) {
|
|
10
|
+
return resolve(process.cwd(), filePath ?? RESOURCES_CONFIG_FILE);
|
|
11
|
+
}
|
|
12
|
+
// ---------------------------------------------------------------------------
|
|
13
|
+
// Read / write
|
|
14
|
+
// ---------------------------------------------------------------------------
|
|
15
|
+
export async function readResourcesConfig(filePath) {
|
|
16
|
+
let configPath = getResourcesConfigPath(filePath);
|
|
17
|
+
if (!existsSync(configPath)) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
let raw = await readFile(configPath, "utf-8");
|
|
21
|
+
return parseYaml(raw) ?? {};
|
|
22
|
+
}
|
|
23
|
+
export async function writeResourcesConfig(config, filePath) {
|
|
24
|
+
let configPath = getResourcesConfigPath(filePath);
|
|
25
|
+
let content = stringifyYaml(config, { lineWidth: 120 });
|
|
26
|
+
await writeFile(configPath, content, "utf-8");
|
|
27
|
+
}
|
|
28
|
+
// ---------------------------------------------------------------------------
|
|
29
|
+
// Convert ResourceEntry ↔ CLIOptions
|
|
30
|
+
// ---------------------------------------------------------------------------
|
|
31
|
+
function arrayOrStringToString(value) {
|
|
32
|
+
if (value === undefined)
|
|
33
|
+
return undefined;
|
|
34
|
+
if (Array.isArray(value))
|
|
35
|
+
return value.join(",");
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
/** Convert a `ResourceEntry` into a `CLIOptions`-compatible object for code generation. */
|
|
39
|
+
export function entryToCLIOptions(entry, hostname) {
|
|
40
|
+
return {
|
|
41
|
+
server: hostname,
|
|
42
|
+
id: entry.id,
|
|
43
|
+
global: entry.global ?? false,
|
|
44
|
+
dynamic: entry.dynamic ?? false,
|
|
45
|
+
types: entry.types,
|
|
46
|
+
maxRecords: entry.maxRecords !== undefined ? String(entry.maxRecords) : "50",
|
|
47
|
+
sortOrder: arrayOrStringToString(entry.sortOrder),
|
|
48
|
+
permissions: entry.permissions,
|
|
49
|
+
master: entry.master,
|
|
50
|
+
linkFields: arrayOrStringToString(entry.linkFields),
|
|
51
|
+
expose: entry.expose,
|
|
52
|
+
unique: entry.unique,
|
|
53
|
+
overrides: arrayOrStringToString(entry.overrides),
|
|
54
|
+
distinct: entry.distinct,
|
|
55
|
+
aggregates: arrayOrStringToString(entry.aggregates),
|
|
56
|
+
groupBy: arrayOrStringToString(entry.groupBy),
|
|
57
|
+
where: entry.where,
|
|
58
|
+
fields: arrayOrStringToString(entry.fields) ?? false,
|
|
59
|
+
output: resolve(process.cwd(), entry.output),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/** Convert a `CLIOptions` back to a `ResourceEntry` for saving to YAML. */
|
|
63
|
+
export function cliOptionsToEntry(resource, options) {
|
|
64
|
+
function maybeArray(value) {
|
|
65
|
+
if (!value)
|
|
66
|
+
return undefined;
|
|
67
|
+
let arr = value.split(",").filter(Boolean);
|
|
68
|
+
return arr.length > 1 ? arr : undefined;
|
|
69
|
+
}
|
|
70
|
+
let entry = {
|
|
71
|
+
id: options.id,
|
|
72
|
+
resource,
|
|
73
|
+
output: options.output ?? `src/data/${options.id}.ts`,
|
|
74
|
+
};
|
|
75
|
+
if (options.global)
|
|
76
|
+
entry.global = true;
|
|
77
|
+
if (options.types)
|
|
78
|
+
entry.types = true;
|
|
79
|
+
if (options.permissions)
|
|
80
|
+
entry.permissions = options.permissions;
|
|
81
|
+
if (options.maxRecords && options.maxRecords !== "50") {
|
|
82
|
+
entry.maxRecords = Number(options.maxRecords);
|
|
83
|
+
}
|
|
84
|
+
if (options.sortOrder)
|
|
85
|
+
entry.sortOrder = maybeArray(options.sortOrder) ?? options.sortOrder;
|
|
86
|
+
if (options.master)
|
|
87
|
+
entry.master = options.master;
|
|
88
|
+
if (options.linkFields)
|
|
89
|
+
entry.linkFields = maybeArray(options.linkFields) ?? options.linkFields;
|
|
90
|
+
if (options.expose !== undefined)
|
|
91
|
+
entry.expose = options.expose;
|
|
92
|
+
if (options.dynamic)
|
|
93
|
+
entry.dynamic = true;
|
|
94
|
+
if (options.unique)
|
|
95
|
+
entry.unique = options.unique;
|
|
96
|
+
if (options.overrides)
|
|
97
|
+
entry.overrides = maybeArray(options.overrides) ?? options.overrides;
|
|
98
|
+
if (options.distinct)
|
|
99
|
+
entry.distinct = true;
|
|
100
|
+
if (options.aggregates)
|
|
101
|
+
entry.aggregates = maybeArray(options.aggregates) ?? options.aggregates;
|
|
102
|
+
if (options.groupBy)
|
|
103
|
+
entry.groupBy = maybeArray(options.groupBy) ?? options.groupBy;
|
|
104
|
+
if (options.where)
|
|
105
|
+
entry.where = options.where;
|
|
106
|
+
if (options.fields && typeof options.fields === "string") {
|
|
107
|
+
let fields = options.fields.split(",").filter(Boolean);
|
|
108
|
+
entry.fields = fields.length > 1 ? fields : options.fields;
|
|
109
|
+
}
|
|
110
|
+
return entry;
|
|
111
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olenbetong/appframe-vite",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"description": "Tools to use and deploy Vite applications to Appframe",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -13,6 +13,10 @@
|
|
|
13
13
|
"./proxy": {
|
|
14
14
|
"import": "./lib/proxy.js",
|
|
15
15
|
"types": "./lib/proxy.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./resources": {
|
|
18
|
+
"import": "./lib/resourceGenerate.js",
|
|
19
|
+
"types": "./lib/resourceGenerate.d.ts"
|
|
16
20
|
}
|
|
17
21
|
},
|
|
18
22
|
"files": [
|
|
@@ -28,16 +32,21 @@
|
|
|
28
32
|
"body-parser": "^2.2.2",
|
|
29
33
|
"chalk": "^5.4.1",
|
|
30
34
|
"chokidar": "^5.0.0",
|
|
35
|
+
"commander": "^14.0.1",
|
|
31
36
|
"dotenv": "^17.2.3",
|
|
32
|
-
"
|
|
37
|
+
"fuzzy": "^0.1.3",
|
|
38
|
+
"inquirer": "^12.9.6",
|
|
39
|
+
"inquirer-autocomplete-standalone": "^0.8.1",
|
|
40
|
+
"jsdom": "29.1.1",
|
|
33
41
|
"rollup-plugin-visualizer": "^6.0.5",
|
|
42
|
+
"yaml": "^2.8.4",
|
|
34
43
|
"@olenbetong/appframe-data": "1.5.0"
|
|
35
44
|
},
|
|
36
45
|
"devDependencies": {
|
|
37
46
|
"@types/jsdom": "^27.0.0",
|
|
38
47
|
"@types/node": "25.6.0",
|
|
39
48
|
"typescript": "6.0.3",
|
|
40
|
-
"vite": "8.0.
|
|
49
|
+
"vite": "8.0.10"
|
|
41
50
|
},
|
|
42
51
|
"peerDependencies": {
|
|
43
52
|
"vite": ">=5.0.0"
|