@crombolo/schema 0.51.1 → 0.52.2
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/package.json +3 -3
- package/src/load.ts +28 -4
- package/src/rename.ts +3 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/schema",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.52.2",
|
|
4
4
|
"description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Schema-as-code for crombolo: TOML document, media and member type definitions.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Crombolo",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@crombolo/core": "0.
|
|
32
|
-
"@crombolo/data": "0.
|
|
31
|
+
"@crombolo/core": "0.52.2",
|
|
32
|
+
"@crombolo/data": "0.52.2"
|
|
33
33
|
}
|
|
34
34
|
}
|
package/src/load.ts
CHANGED
|
@@ -54,6 +54,19 @@ function tomlFiles(dir: string): string[] {
|
|
|
54
54
|
.map((name) => join(dir, name))
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
/** Forms and workflows may sit in folders (story 289), at any depth. */
|
|
58
|
+
function tomlFilesDeep(dir: string): string[] {
|
|
59
|
+
if (!existsSync(dir)) return []
|
|
60
|
+
return readdirSync(dir, { withFileTypes: true })
|
|
61
|
+
.filter((entry) => !entry.name.startsWith('.'))
|
|
62
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
63
|
+
.flatMap((entry) => {
|
|
64
|
+
const path = join(dir, entry.name)
|
|
65
|
+
if (entry.isDirectory()) return tomlFilesDeep(path)
|
|
66
|
+
return entry.name.endsWith('.toml') ? [path] : []
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
57
70
|
export interface LoadSchemaOptions {
|
|
58
71
|
/** The field and workflow types forms may use: the built-ins, and the wired bundles'. */
|
|
59
72
|
formTypes?: FormTypes
|
|
@@ -118,21 +131,32 @@ export function loadSchemaDirectory(
|
|
|
118
131
|
}
|
|
119
132
|
}
|
|
120
133
|
const forms: SchemaForm[] = []
|
|
121
|
-
|
|
134
|
+
/** Two files in different folders can claim one alias, which only their paths can show. */
|
|
135
|
+
const claim = (key: string, alias: string, file: string) => {
|
|
136
|
+
const other = files.get(key)
|
|
137
|
+
if (other)
|
|
138
|
+
problems.push({
|
|
139
|
+
file: rel(file),
|
|
140
|
+
path: '',
|
|
141
|
+
message: `"${alias}" is also the alias in ${rel(other)}`,
|
|
142
|
+
})
|
|
143
|
+
else files.set(key, file)
|
|
144
|
+
}
|
|
145
|
+
for (const file of tomlFilesDeep(join(schemaDir, 'forms'))) {
|
|
122
146
|
const parsed = parseForm(rel(file), readFileSync(file, 'utf8'), options.formTypes)
|
|
123
147
|
problems.push(...parsed.problems)
|
|
124
148
|
if (parsed.value) {
|
|
125
149
|
forms.push(parsed.value)
|
|
126
|
-
|
|
150
|
+
claim(`form:${parsed.value.alias}`, parsed.value.alias, file)
|
|
127
151
|
}
|
|
128
152
|
}
|
|
129
153
|
const workflows: SchemaWorkflow[] = []
|
|
130
|
-
for (const file of
|
|
154
|
+
for (const file of tomlFilesDeep(join(schemaDir, 'workflows'))) {
|
|
131
155
|
const parsed = parseWorkflow(rel(file), readFileSync(file, 'utf8'))
|
|
132
156
|
problems.push(...parsed.problems)
|
|
133
157
|
if (parsed.value) {
|
|
134
158
|
workflows.push(parsed.value)
|
|
135
|
-
|
|
159
|
+
claim(`workflow:${parsed.value.alias}`, parsed.value.alias, file)
|
|
136
160
|
}
|
|
137
161
|
}
|
|
138
162
|
const userGroups: SchemaUserGroup[] = []
|
package/src/rename.ts
CHANGED
|
@@ -225,8 +225,8 @@ export function renameProperty(
|
|
|
225
225
|
kind,
|
|
226
226
|
types.map((t) => (t === type ? renamed : t)),
|
|
227
227
|
)
|
|
228
|
-
// A block's label names an element type's properties: `{{heading}
|
|
229
|
-
const label = new RegExp(`\\{
|
|
228
|
+
// A block's label names an element type's properties: `{=heading}`, `{umbValue:heading}`.
|
|
229
|
+
const label = new RegExp(`\\{(=\\s*|umbValue:\\s*)${from}\\b`, 'g')
|
|
230
230
|
next = {
|
|
231
231
|
...next,
|
|
232
232
|
dataTypes: next.dataTypes.map((d) => {
|
|
@@ -236,7 +236,7 @@ export function renameProperty(
|
|
|
236
236
|
label.lastIndex = 0
|
|
237
237
|
named = true
|
|
238
238
|
references.push({ in: `data type "${d.alias}"`, how: 'block label' })
|
|
239
|
-
return { ...b, label: b.label.replace(label, `{
|
|
239
|
+
return { ...b, label: b.label.replace(label, `{$1${to}`) }
|
|
240
240
|
})
|
|
241
241
|
return named ? { ...d, ...(blocks ? { blocks } : {}) } : d
|
|
242
242
|
}),
|