@magmonium/cli 0.7.12 → 0.7.13
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/bin/commands/assets.js +62 -1
- package/bin/commands/configure-wc.js +2 -2
- package/package.json +1 -1
- package/schemas/nav.schema.json +30 -8
- package/src/compilers/docs-compiler.d.ts +20 -0
- package/src/compilers/docs-compiler.d.ts.map +1 -0
- package/src/compilers/docs-compiler.js +55 -0
- package/src/compilers/docs-compiler.js.map +1 -0
- package/src/compilers/field-compiler.d.ts +20 -0
- package/src/compilers/field-compiler.d.ts.map +1 -1
- package/src/compilers/field-compiler.js +93 -5
- package/src/compilers/field-compiler.js.map +1 -1
- package/src/compilers/patterns-compiler.d.ts +46 -0
- package/src/compilers/patterns-compiler.d.ts.map +1 -0
- package/src/compilers/patterns-compiler.js +149 -0
- package/src/compilers/patterns-compiler.js.map +1 -0
- package/src/compilers/web-component/lib/ng-build.d.ts.map +1 -1
- package/src/compilers/web-component/lib/ng-build.js +16 -1
- package/src/compilers/web-component/lib/ng-build.js.map +1 -1
- package/src/compilers/web-component/lib/web-component-wrapper.d.ts.map +1 -1
- package/src/compilers/web-component/lib/web-component-wrapper.js +8 -6
- package/src/compilers/web-component/lib/web-component-wrapper.js.map +1 -1
- package/src/compilers/web-component/model/type.d.ts +1 -0
- package/src/compilers/web-component/model/type.d.ts.map +1 -1
- package/src/core/config.d.ts +60 -0
- package/src/core/config.d.ts.map +1 -1
- package/src/core/config.js +44 -0
- package/src/core/config.js.map +1 -1
- package/src/index.d.ts +2 -0
- package/src/index.d.ts.map +1 -1
- package/src/index.js +2 -0
- package/src/index.js.map +1 -1
- package/src/utils/i18n-fixer.d.ts.map +1 -1
- package/src/utils/i18n-fixer.js +2 -3
- package/src/utils/i18n-fixer.js.map +1 -1
- package/src/utils/web-translation-providers.d.ts +1 -9
- package/src/utils/web-translation-providers.d.ts.map +1 -1
- package/src/utils/web-translation-providers.js +26 -79
- package/src/utils/web-translation-providers.js.map +1 -1
package/bin/commands/assets.js
CHANGED
|
@@ -6,6 +6,7 @@ const {
|
|
|
6
6
|
ButtonGroupCompiler,
|
|
7
7
|
FieldCompiler,
|
|
8
8
|
OptionsCompiler,
|
|
9
|
+
PatternsCompiler,
|
|
9
10
|
CopyCompiler,
|
|
10
11
|
WorkerCompiler,
|
|
11
12
|
TabsCompiler,
|
|
@@ -13,6 +14,7 @@ const {
|
|
|
13
14
|
generateIsolatedPaths,
|
|
14
15
|
DEFAULT_PATHS_CONFIG,
|
|
15
16
|
WebComponentBuilder,
|
|
17
|
+
collectDocs,
|
|
16
18
|
} = require('../../src/index.js');
|
|
17
19
|
|
|
18
20
|
const fs = require('fs').promises;
|
|
@@ -44,7 +46,7 @@ function createYamlCompiler(
|
|
|
44
46
|
// resolve by SHARED_ICONS and messages by the translation merge, both without a
|
|
45
47
|
// folder listing, and both are an order of magnitude larger than all the config
|
|
46
48
|
// folders put together.
|
|
47
|
-
const MANIFEST_EXCLUDED_FOLDERS = ['icons', 'i18n'];
|
|
49
|
+
const MANIFEST_EXCLUDED_FOLDERS = ['icons', 'i18n', 'docs'];
|
|
48
50
|
|
|
49
51
|
/**
|
|
50
52
|
* Writes `index.json` — every compiled config in the tree, by folder and name.
|
|
@@ -81,6 +83,12 @@ async function writeAssetManifest(outputDir) {
|
|
|
81
83
|
if (Object.keys(folder).length) manifest[entry.name] = folder;
|
|
82
84
|
}
|
|
83
85
|
|
|
86
|
+
// Documents are markdown, not compiled JSON, so the folder walk above finds
|
|
87
|
+
// nothing in `docs/` — they are listed by name and language instead, which is
|
|
88
|
+
// the whole of what the editor's picker needs to offer one.
|
|
89
|
+
const docs = await collectDocs(root);
|
|
90
|
+
if (Object.keys(docs).length) manifest.docs = docs;
|
|
91
|
+
|
|
84
92
|
const manifestPath = path.join(root, 'index.json');
|
|
85
93
|
await fs.writeFile(manifestPath, JSON.stringify(manifest));
|
|
86
94
|
console.log(
|
|
@@ -446,6 +454,11 @@ function assetsCommand(program) {
|
|
|
446
454
|
outputPaths: PATHS.options.output,
|
|
447
455
|
...config.options,
|
|
448
456
|
},
|
|
457
|
+
patterns: {
|
|
458
|
+
inputPaths: PATHS.patterns.input,
|
|
459
|
+
outputPaths: PATHS.patterns.output,
|
|
460
|
+
...config.patterns,
|
|
461
|
+
},
|
|
449
462
|
nav: {
|
|
450
463
|
inputPaths: PATHS.navs.input,
|
|
451
464
|
outputPaths: [
|
|
@@ -580,6 +593,16 @@ function assetsCommand(program) {
|
|
|
580
593
|
outputPaths: PATHS.accordion_groups.output,
|
|
581
594
|
...config.accordion_groups,
|
|
582
595
|
},
|
|
596
|
+
lists: {
|
|
597
|
+
inputPaths: PATHS.lists.input,
|
|
598
|
+
outputPaths: PATHS.lists.output,
|
|
599
|
+
...config.lists,
|
|
600
|
+
},
|
|
601
|
+
section_tables: {
|
|
602
|
+
inputPaths: PATHS.section_tables.input,
|
|
603
|
+
outputPaths: PATHS.section_tables.output,
|
|
604
|
+
...config.section_tables,
|
|
605
|
+
},
|
|
583
606
|
graphs: {
|
|
584
607
|
inputPaths: PATHS.graphs.input,
|
|
585
608
|
outputPaths: PATHS.graphs.output,
|
|
@@ -610,6 +633,13 @@ function assetsCommand(program) {
|
|
|
610
633
|
compilers.push(new OptionsCompiler(buildConfig.options));
|
|
611
634
|
}
|
|
612
635
|
|
|
636
|
+
// Before fields, always: FieldCompiler reads compiled patterns out of
|
|
637
|
+
// the output directory and inlines them, so a pattern compiled after
|
|
638
|
+
// a field is a pattern that field never saw (libs/one ADR 0017).
|
|
639
|
+
if (buildConfig.patterns) {
|
|
640
|
+
compilers.push(new PatternsCompiler(buildConfig.patterns));
|
|
641
|
+
}
|
|
642
|
+
|
|
613
643
|
if (buildConfig.fields) {
|
|
614
644
|
compilers.push(new FieldCompiler(buildConfig.fields));
|
|
615
645
|
}
|
|
@@ -802,6 +832,16 @@ function assetsCommand(program) {
|
|
|
802
832
|
);
|
|
803
833
|
}
|
|
804
834
|
|
|
835
|
+
if (buildConfig.lists) {
|
|
836
|
+
compilers.push(createYamlCompiler('List', buildConfig.lists));
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
if (buildConfig.section_tables) {
|
|
840
|
+
compilers.push(
|
|
841
|
+
createYamlCompiler('SectionTable', buildConfig.section_tables)
|
|
842
|
+
);
|
|
843
|
+
}
|
|
844
|
+
|
|
805
845
|
if (buildConfig.graphs) {
|
|
806
846
|
compilers.push(
|
|
807
847
|
createYamlCompiler(
|
|
@@ -827,6 +867,27 @@ function assetsCommand(program) {
|
|
|
827
867
|
// Always add copy compiler for remaining files
|
|
828
868
|
compilers.push(new CopyCompiler(buildConfig.copy));
|
|
829
869
|
|
|
870
|
+
// Under --watch, a pattern edit has to reach the fields that inlined
|
|
871
|
+
// it. FieldCompiler watches `fields/` alone, so it would otherwise keep
|
|
872
|
+
// serving the expression it read at startup — the same hole options
|
|
873
|
+
// have had, closed here for both by re-running the field pass on the
|
|
874
|
+
// event PatternsCompiler emits.
|
|
875
|
+
const fieldCompiler = compilers.find(
|
|
876
|
+
(compiler) => compiler instanceof FieldCompiler
|
|
877
|
+
);
|
|
878
|
+
const patternsCompiler = compilers.find(
|
|
879
|
+
(compiler) => compiler instanceof PatternsCompiler
|
|
880
|
+
);
|
|
881
|
+
if (options.watch && fieldCompiler && patternsCompiler) {
|
|
882
|
+
patternsCompiler.on('patternsChanged', async () => {
|
|
883
|
+
try {
|
|
884
|
+
await fieldCompiler.compile();
|
|
885
|
+
} catch (error) {
|
|
886
|
+
console.error(`Field recompile after pattern change: ${error}`);
|
|
887
|
+
}
|
|
888
|
+
});
|
|
889
|
+
}
|
|
890
|
+
|
|
830
891
|
// Run all compilers for this source-output pair
|
|
831
892
|
for (const compiler of compilers) {
|
|
832
893
|
if (options.watch) {
|
|
@@ -41,7 +41,7 @@ function configureWcCommand(program) {
|
|
|
41
41
|
console.log(` npm run assets:compile`);
|
|
42
42
|
console.log(` 4. Add GitHub Secrets:`);
|
|
43
43
|
console.log(` MAG_APP_ID_${appNameUpper}`);
|
|
44
|
-
console.log(`
|
|
44
|
+
console.log(` MAG_DEPLOY_TOKEN (your per-user token, shared by every app)`);
|
|
45
45
|
console.log(
|
|
46
46
|
` MAG_ENDPOINT (default: https://api.magmonium.com)`
|
|
47
47
|
);
|
|
@@ -139,7 +139,7 @@ jobs:
|
|
|
139
139
|
run: |
|
|
140
140
|
mag-cli deploy \\
|
|
141
141
|
--app-id \${{ secrets.MAG_APP_ID_${appNameUpper} }} \\
|
|
142
|
-
--token \${{ secrets.
|
|
142
|
+
--token \${{ secrets.MAG_DEPLOY_TOKEN }} \\
|
|
143
143
|
--endpoint \${{ secrets.MAG_ENDPOINT || 'https://api.magmonium.com' }} \\
|
|
144
144
|
--dist-path ${wcDistPath}
|
|
145
145
|
`;
|
package/package.json
CHANGED
package/schemas/nav.schema.json
CHANGED
|
@@ -3,25 +3,47 @@
|
|
|
3
3
|
"title": "Nav Asset",
|
|
4
4
|
"description": "Schema for nav YAML files in mag_assets/navs/",
|
|
5
5
|
"type": "object",
|
|
6
|
-
"required": ["
|
|
6
|
+
"required": ["navId", "kind", "presentation"],
|
|
7
7
|
"additionalProperties": false,
|
|
8
8
|
"properties": {
|
|
9
|
+
"navId": {
|
|
10
|
+
"type": "string",
|
|
11
|
+
"description": "Full-path NavId (e.g., root, root_settings, root_settings_user). Always rooted and _-joined."
|
|
12
|
+
},
|
|
9
13
|
"title": {
|
|
10
14
|
"type": "string",
|
|
11
|
-
"description": "Display name for this nav entry"
|
|
15
|
+
"description": "Display name for this nav entry. Optional - if missing, the navId segment is used as title and this nav is treated as the default child with no nav label shown."
|
|
12
16
|
},
|
|
13
17
|
"icon": {
|
|
14
18
|
"type": "string",
|
|
15
|
-
"description": "Icon name (optional
|
|
19
|
+
"description": "Icon name (optional). No icon is shown for label-less/default navs."
|
|
20
|
+
},
|
|
21
|
+
"logo": {
|
|
22
|
+
"type": "string",
|
|
23
|
+
"description": "Logo source path. Typically only on root nav (e.g., assets/logo/icon.svg)."
|
|
24
|
+
},
|
|
25
|
+
"kind": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"enum": ["url", "murl"],
|
|
28
|
+
"description": "How this nav is reached: 'url' for a real Angular route, 'murl' for a nav panel."
|
|
16
29
|
},
|
|
17
|
-
"
|
|
18
|
-
"type": "
|
|
19
|
-
"
|
|
30
|
+
"presentation": {
|
|
31
|
+
"type": "string",
|
|
32
|
+
"enum": ["static", "component", "dynamic"],
|
|
33
|
+
"description": "How the panel is filled: 'static' for menu rows, 'component' for a registered widget, 'dynamic' for runtime resolution."
|
|
34
|
+
},
|
|
35
|
+
"path": {
|
|
36
|
+
"type": "string",
|
|
37
|
+
"description": "Route path override for Url navs. Absent means the ancestry path. Empty string means this is the default route (path: '')."
|
|
38
|
+
},
|
|
39
|
+
"param": {
|
|
40
|
+
"type": "string",
|
|
41
|
+
"description": "Route parameter name for dynamic Navs, defaulting to 'id'."
|
|
20
42
|
},
|
|
21
|
-
"
|
|
43
|
+
"children": {
|
|
22
44
|
"type": "array",
|
|
23
45
|
"items": { "type": "string" },
|
|
24
|
-
"description": "Child nav IDs
|
|
46
|
+
"description": "Child nav IDs (full paths). Ordered. Each must have a matching .yml file in the same navs/ folder."
|
|
25
47
|
}
|
|
26
48
|
}
|
|
27
49
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/** The one folder a DocAsset lives in, under `mag_assets/` and under `assets/`. */
|
|
2
|
+
export declare const DOCS_FOLDER = "docs";
|
|
3
|
+
/** One document as the manifest lists it: the languages it was authored in. */
|
|
4
|
+
export interface DocManifestEntry {
|
|
5
|
+
languages: string[];
|
|
6
|
+
}
|
|
7
|
+
export type DocManifest = Record<string, DocManifestEntry>;
|
|
8
|
+
/**
|
|
9
|
+
* Lists the documents in a compiled asset tree — `<root>/docs/<lang>/<name>.md`.
|
|
10
|
+
*
|
|
11
|
+
* A document is copied rather than compiled (CopyCompiler already carries it
|
|
12
|
+
* through untouched), so nothing else in the tree records that it exists. The
|
|
13
|
+
* m-one-ui editor lists its OneAssets off `index.json` (m-one-ui ADR 0016) and
|
|
14
|
+
* would otherwise have no way to offer a shipped doc by name.
|
|
15
|
+
*
|
|
16
|
+
* The `<lang>/` folder is mandatory: one resolution shape, so a doc dropped
|
|
17
|
+
* straight into `docs/` is not a document in any language and is ignored.
|
|
18
|
+
*/
|
|
19
|
+
export declare function collectDocs(root: string): Promise<DocManifest>;
|
|
20
|
+
//# sourceMappingURL=docs-compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs-compiler.d.ts","sourceRoot":"","sources":["../../../../../libs/cli/src/compilers/docs-compiler.ts"],"names":[],"mappings":"AAGA,mFAAmF;AACnF,eAAO,MAAM,WAAW,SAAS,CAAC;AAIlC,+EAA+E;AAC/E,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,EAAE,CAAC;CACrB;AAED,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAkCpE"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DOCS_FOLDER = void 0;
|
|
4
|
+
exports.collectDocs = collectDocs;
|
|
5
|
+
const tslib_1 = require("tslib");
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = tslib_1.__importDefault(require("path"));
|
|
8
|
+
/** The one folder a DocAsset lives in, under `mag_assets/` and under `assets/`. */
|
|
9
|
+
exports.DOCS_FOLDER = 'docs';
|
|
10
|
+
const MARKDOWN_EXTENSION = '.md';
|
|
11
|
+
/**
|
|
12
|
+
* Lists the documents in a compiled asset tree — `<root>/docs/<lang>/<name>.md`.
|
|
13
|
+
*
|
|
14
|
+
* A document is copied rather than compiled (CopyCompiler already carries it
|
|
15
|
+
* through untouched), so nothing else in the tree records that it exists. The
|
|
16
|
+
* m-one-ui editor lists its OneAssets off `index.json` (m-one-ui ADR 0016) and
|
|
17
|
+
* would otherwise have no way to offer a shipped doc by name.
|
|
18
|
+
*
|
|
19
|
+
* The `<lang>/` folder is mandatory: one resolution shape, so a doc dropped
|
|
20
|
+
* straight into `docs/` is not a document in any language and is ignored.
|
|
21
|
+
*/
|
|
22
|
+
async function collectDocs(root) {
|
|
23
|
+
const docsRoot = path_1.default.join(root, exports.DOCS_FOLDER);
|
|
24
|
+
let languages;
|
|
25
|
+
try {
|
|
26
|
+
const entries = await fs_1.promises.readdir(docsRoot, { withFileTypes: true });
|
|
27
|
+
languages = entries
|
|
28
|
+
.filter((entry) => entry.isDirectory())
|
|
29
|
+
.map((entry) => entry.name)
|
|
30
|
+
.sort();
|
|
31
|
+
}
|
|
32
|
+
catch {
|
|
33
|
+
// No docs folder is no documents, never a broken manifest.
|
|
34
|
+
return {};
|
|
35
|
+
}
|
|
36
|
+
const manifest = {};
|
|
37
|
+
for (const language of languages) {
|
|
38
|
+
let files;
|
|
39
|
+
try {
|
|
40
|
+
files = await fs_1.promises.readdir(path_1.default.join(docsRoot, language));
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
for (const file of files) {
|
|
46
|
+
if (!file.endsWith(MARKDOWN_EXTENSION))
|
|
47
|
+
continue;
|
|
48
|
+
const name = file.slice(0, -MARKDOWN_EXTENSION.length);
|
|
49
|
+
const entry = (manifest[name] ?? (manifest[name] = { languages: [] }));
|
|
50
|
+
entry.languages.push(language);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return manifest;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=docs-compiler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"docs-compiler.js","sourceRoot":"","sources":["../../../../../libs/cli/src/compilers/docs-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AAC,CAAC;YACvD,MAAM,KAAK,GAAG,CAAC,QAAQ,CAAC,IAAI,MAAb,QAAQ,CAAC,IAAI,IAAM,EAAE,SAAS,EAAE,EAAE,EAAE,EAAC,CAAC;YACrD,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACjC,CAAC;IACH,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC"}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { BaseCompiler } from '../core/base-compiler';
|
|
2
2
|
import { FieldCompilerConfig } from '../core/config';
|
|
3
|
+
/**
|
|
4
|
+
* Every directory a pattern name may be answered from, best answer first:
|
|
5
|
+
* the app's own compiled patterns, then the installed package, then a copy of
|
|
6
|
+
* the package's assets that a previous build already landed in the output.
|
|
7
|
+
*
|
|
8
|
+
* Authored ahead of shipped on purpose — the same precedence the editor's
|
|
9
|
+
* `resolveFieldPatternRules` uses, so a name resolves to the same rule in the
|
|
10
|
+
* Canvas and in the built app.
|
|
11
|
+
*/
|
|
12
|
+
export declare function patternLookupDirs(baseDirs: string[], packageRoot?: string): string[];
|
|
3
13
|
export declare class FieldCompiler extends BaseCompiler {
|
|
4
14
|
private watcher;
|
|
5
15
|
private readonly lookupDirs;
|
|
@@ -8,6 +18,16 @@ export declare class FieldCompiler extends BaseCompiler {
|
|
|
8
18
|
watch(): Promise<void>;
|
|
9
19
|
private findYAMLFiles;
|
|
10
20
|
private loadOptions;
|
|
21
|
+
/**
|
|
22
|
+
* Reads compiled `patterns/*.json` out of every tier `patternLookupDirs`
|
|
23
|
+
* names. First tier to answer a name wins, so an app's own pattern shadows a
|
|
24
|
+
* shipped one of the same name and never the other way round.
|
|
25
|
+
*
|
|
26
|
+
* A shipped name has to resolve here or nowhere: a Field inlines its rules at
|
|
27
|
+
* compile time, so a name this pass drops leaves the built Field declaring no
|
|
28
|
+
* shape at all, and the form validates nothing with no runtime symptom.
|
|
29
|
+
*/
|
|
30
|
+
private loadPatterns;
|
|
11
31
|
private processYAMLFiles;
|
|
12
32
|
private processField;
|
|
13
33
|
private isYAMLFile;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-compiler.d.ts","sourceRoot":"","sources":["../../../../../libs/cli/src/compilers/field-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"field-compiler.d.ts","sourceRoot":"","sources":["../../../../../libs/cli/src/compilers/field-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AA2CrD;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAAE,EAClB,WAAW,GAAE,MAAsB,GAClC,MAAM,EAAE,CAOV;AAED,qBAAa,aAAc,SAAQ,YAAY;IAC7C,OAAO,CAAC,OAAO,CAA4B;IAC3C,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAW;gBAE1B,MAAM,EAAE,mBAAmB;IAOjC,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAyCxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YA6Bd,aAAa;YAeb,WAAW;IAoCzB;;;;;;;;OAQG;YACW,YAAY;YAmCZ,gBAAgB;IAkC9B,OAAO,CAAC,YAAY;IA8DpB,OAAO,CAAC,UAAU;CAInB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.FieldCompiler = void 0;
|
|
4
|
+
exports.patternLookupDirs = patternLookupDirs;
|
|
4
5
|
const tslib_1 = require("tslib");
|
|
5
6
|
const base_compiler_1 = require("../core/base-compiler");
|
|
6
7
|
const file_utils_1 = require("../utils/file-utils");
|
|
@@ -8,6 +9,31 @@ const file_watcher_1 = require("../core/file-watcher");
|
|
|
8
9
|
const path_1 = tslib_1.__importDefault(require("path"));
|
|
9
10
|
const yaml_1 = tslib_1.__importDefault(require("yaml"));
|
|
10
11
|
const fs_1 = require("fs");
|
|
12
|
+
/**
|
|
13
|
+
* Where a shipped PatternAsset sits once `@magmonium/one` is installed. The
|
|
14
|
+
* scaffold never authors a copy of one (ADR 0032), so this is the only tier
|
|
15
|
+
* that can answer a shipped name there — and unlike `<output>/one/patterns` it
|
|
16
|
+
* is never cleaned by the assets command, which wipes the output directory
|
|
17
|
+
* before compiling and only restores `one/` afterwards.
|
|
18
|
+
*/
|
|
19
|
+
const ONE_PACKAGE_PATTERNS = path_1.default.join('node_modules', '@magmonium', 'one', 'assets', 'patterns');
|
|
20
|
+
/**
|
|
21
|
+
* Every directory a pattern name may be answered from, best answer first:
|
|
22
|
+
* the app's own compiled patterns, then the installed package, then a copy of
|
|
23
|
+
* the package's assets that a previous build already landed in the output.
|
|
24
|
+
*
|
|
25
|
+
* Authored ahead of shipped on purpose — the same precedence the editor's
|
|
26
|
+
* `resolveFieldPatternRules` uses, so a name resolves to the same rule in the
|
|
27
|
+
* Canvas and in the built app.
|
|
28
|
+
*/
|
|
29
|
+
function patternLookupDirs(baseDirs, packageRoot = process.cwd()) {
|
|
30
|
+
const unique = [...new Set(baseDirs)];
|
|
31
|
+
return [
|
|
32
|
+
...unique.map((baseDir) => path_1.default.join(baseDir, 'patterns')),
|
|
33
|
+
path_1.default.join(packageRoot, ONE_PACKAGE_PATTERNS),
|
|
34
|
+
...unique.map((baseDir) => path_1.default.join(baseDir, 'one', 'patterns')),
|
|
35
|
+
].filter((dir, index, dirs) => dirs.indexOf(dir) === index);
|
|
36
|
+
}
|
|
11
37
|
class FieldCompiler extends base_compiler_1.BaseCompiler {
|
|
12
38
|
constructor(config) {
|
|
13
39
|
super(config);
|
|
@@ -26,7 +52,11 @@ class FieldCompiler extends base_compiler_1.BaseCompiler {
|
|
|
26
52
|
}
|
|
27
53
|
// Load options data
|
|
28
54
|
const optionsData = await this.loadOptions();
|
|
29
|
-
|
|
55
|
+
// And the shapes a Field's value may take. Both are read from compiled
|
|
56
|
+
// JSON in the output directory, so both compilers must have run first —
|
|
57
|
+
// see the ordering in bin/commands/assets.js.
|
|
58
|
+
const patternsData = await this.loadPatterns();
|
|
59
|
+
const fieldData = await this.processYAMLFiles(yamlFiles, optionsData, patternsData);
|
|
30
60
|
// Write individual field JSON files only
|
|
31
61
|
for (const [fieldName, fieldConfig] of Object.entries(fieldData)) {
|
|
32
62
|
await this.writeFile(`${fieldName}.json`, this.formatOutput(fieldConfig));
|
|
@@ -104,7 +134,43 @@ class FieldCompiler extends base_compiler_1.BaseCompiler {
|
|
|
104
134
|
}
|
|
105
135
|
return optionsData;
|
|
106
136
|
}
|
|
107
|
-
|
|
137
|
+
/**
|
|
138
|
+
* Reads compiled `patterns/*.json` out of every tier `patternLookupDirs`
|
|
139
|
+
* names. First tier to answer a name wins, so an app's own pattern shadows a
|
|
140
|
+
* shipped one of the same name and never the other way round.
|
|
141
|
+
*
|
|
142
|
+
* A shipped name has to resolve here or nowhere: a Field inlines its rules at
|
|
143
|
+
* compile time, so a name this pass drops leaves the built Field declaring no
|
|
144
|
+
* shape at all, and the form validates nothing with no runtime symptom.
|
|
145
|
+
*/
|
|
146
|
+
async loadPatterns() {
|
|
147
|
+
const patternsData = {};
|
|
148
|
+
for (const patternsDir of patternLookupDirs(this.lookupDirs)) {
|
|
149
|
+
try {
|
|
150
|
+
const patternFiles = await fs_1.promises.readdir(patternsDir);
|
|
151
|
+
for (const file of patternFiles) {
|
|
152
|
+
if (!file.endsWith('.json'))
|
|
153
|
+
continue;
|
|
154
|
+
const patternName = file.replace('.json', '');
|
|
155
|
+
if (patternsData[patternName])
|
|
156
|
+
continue;
|
|
157
|
+
try {
|
|
158
|
+
const content = await fs_1.promises.readFile(path_1.default.join(patternsDir, file), 'utf8');
|
|
159
|
+
patternsData[patternName] = JSON.parse(content);
|
|
160
|
+
this.logger.debug(`Loaded pattern data for: ${patternName} from ${patternsDir}`);
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
this.logger.warn(`Could not read pattern data for ${patternName}: ${error}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
// Silently skip missing patterns directories
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return patternsData;
|
|
172
|
+
}
|
|
173
|
+
async processYAMLFiles(files, optionsData, patternsData = {}) {
|
|
108
174
|
const fieldData = {};
|
|
109
175
|
for (const file of files) {
|
|
110
176
|
try {
|
|
@@ -113,7 +179,7 @@ class FieldCompiler extends base_compiler_1.BaseCompiler {
|
|
|
113
179
|
// Parse YAML content
|
|
114
180
|
const fieldConfig = yaml_1.default.parse(content);
|
|
115
181
|
// Process field - resolve options if they're string references
|
|
116
|
-
const processedField = this.processField(fieldConfig, optionsData);
|
|
182
|
+
const processedField = this.processField(fieldConfig, optionsData, patternsData);
|
|
117
183
|
fieldData[fieldName] = processedField;
|
|
118
184
|
this.logger.debug(`✓ Compiled ${path_1.default.basename(file)} → ${fieldName}.json`);
|
|
119
185
|
}
|
|
@@ -123,10 +189,32 @@ class FieldCompiler extends base_compiler_1.BaseCompiler {
|
|
|
123
189
|
}
|
|
124
190
|
return fieldData;
|
|
125
191
|
}
|
|
126
|
-
processField(field, options) {
|
|
192
|
+
processField(field, options, patterns = {}) {
|
|
127
193
|
// Create base processed field without options
|
|
128
|
-
const { options: fieldOptions, ...fieldWithoutOptions } = field;
|
|
194
|
+
const { options: fieldOptions, patterns: fieldPatterns, ...fieldWithoutOptions } = field;
|
|
129
195
|
const processedField = { ...fieldWithoutOptions };
|
|
196
|
+
if (Array.isArray(fieldPatterns) && fieldPatterns.length) {
|
|
197
|
+
const resolved = fieldPatterns
|
|
198
|
+
.map((name) => {
|
|
199
|
+
const rule = patterns[name];
|
|
200
|
+
if (!rule) {
|
|
201
|
+
this.logger.warn(`Pattern "${name}" referenced in field "${field.model}" not found in patterns directory`);
|
|
202
|
+
}
|
|
203
|
+
return rule;
|
|
204
|
+
})
|
|
205
|
+
.filter((rule) => Boolean(rule));
|
|
206
|
+
// Only when something resolved: an empty array would read as "declares
|
|
207
|
+
// shapes, accepts none", and a Field nothing can satisfy is worse than
|
|
208
|
+
// one that checks nothing.
|
|
209
|
+
if (resolved.length) {
|
|
210
|
+
processedField.patterns = resolved;
|
|
211
|
+
}
|
|
212
|
+
if (resolved.length > 1 && !field['patternMessage']) {
|
|
213
|
+
// The editor refuses this at the gesture; a hand-written asset can
|
|
214
|
+
// still reach here, and the fallback message names no shape at all.
|
|
215
|
+
this.logger.warn(`Field "${field.model}" declares ${resolved.length} patterns but no \`patternMessage\``);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
130
218
|
if (fieldOptions && typeof fieldOptions === 'string') {
|
|
131
219
|
// If options is a string, look it up in the options directory
|
|
132
220
|
if (options[fieldOptions]) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"field-compiler.js","sourceRoot":"","sources":["../../../../../libs/cli/src/compilers/field-compiler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"field-compiler.js","sourceRoot":"","sources":["../../../../../libs/cli/src/compilers/field-compiler.ts"],"names":[],"mappings":";;;AAqDA,8CAUC;;AA/DD,yDAAqD;AAErD,oDAAgD;AAChD,uDAAmD;AAEnD,wDAAwB;AACxB,wDAAwB;AACxB,2BAAoC;AAsBpC;;;;;;GAMG;AACH,MAAM,oBAAoB,GAAG,cAAI,CAAC,IAAI,CACpC,cAAc,EACd,YAAY,EACZ,KAAK,EACL,QAAQ,EACR,UAAU,CACX,CAAC;AAEF;;;;;;;;GAQG;AACH,SAAgB,iBAAiB,CAC/B,QAAkB,EAClB,cAAsB,OAAO,CAAC,GAAG,EAAE;IAEnC,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,GAA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AAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACvC,gDAAgD;YAChD,cAAc,CAAC,OAAO,GAAG,YAAY,CAAC;QACxC,CAAC;QAED,OAAO,cAAc,CAAC;IACxB,CAAC;IAEO,UAAU,CAAC,QAAgB;QACjC,MAAM,GAAG,GAAG,sBAAS,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;QACjD,OAAO,GAAG,KAAK,MAAM,IAAI,GAAG,KAAK,OAAO,CAAC;IAC3C,CAAC;CACF;AApRD,sCAoRC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { BaseCompiler } from '../core/base-compiler';
|
|
2
|
+
import { CompilerConfig } from '../core/config';
|
|
3
|
+
/** One `mag_assets/patterns/<name>.yml` as authored. */
|
|
4
|
+
export interface PatternSource {
|
|
5
|
+
/** Stored unanchored — this compiler is what adds `^(?:…)$`. */
|
|
6
|
+
pattern: string;
|
|
7
|
+
/** i18n key shown when this rule is the only one a Field declares. */
|
|
8
|
+
message: string;
|
|
9
|
+
/** A value the expression accepts. Checked here, never emitted. */
|
|
10
|
+
example?: string;
|
|
11
|
+
/** Narrowed to `i`; see `sanitizeFlags`. */
|
|
12
|
+
flags?: string;
|
|
13
|
+
}
|
|
14
|
+
/** What a Field's compiled config carries once `FieldCompiler` inlines it. */
|
|
15
|
+
export interface CompiledPattern {
|
|
16
|
+
name: string;
|
|
17
|
+
expression: string;
|
|
18
|
+
flags?: string;
|
|
19
|
+
message: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* `g` makes a RegExp carry `lastIndex` between `.test()` calls, so one value
|
|
23
|
+
* alternates valid and invalid on repeated keystrokes; `m` reverses what the
|
|
24
|
+
* anchors below establish. Neither is a preference (libs/one ADR 0017).
|
|
25
|
+
*/
|
|
26
|
+
export declare function sanitizeFlags(flags: string | undefined): string | undefined;
|
|
27
|
+
/**
|
|
28
|
+
* `.test()` matches anywhere in a value, so an unanchored `[0-9]{4}` passes
|
|
29
|
+
* `abc1234xyz`. The non-capturing group is what keeps a pattern's own
|
|
30
|
+
* alternation inside its own bounds — without it `a|b` would anchor only `a`.
|
|
31
|
+
*
|
|
32
|
+
* Anchors an author wrote anyway are stripped first, so the result stays one
|
|
33
|
+
* pair rather than nesting. A trailing `\$` is an escaped dollar and is left
|
|
34
|
+
* alone; a trailing `\\$` is a literal backslash followed by the anchor.
|
|
35
|
+
*/
|
|
36
|
+
export declare function anchorExpression(source: string): string;
|
|
37
|
+
export declare class PatternsCompiler extends BaseCompiler {
|
|
38
|
+
private watcher;
|
|
39
|
+
constructor(config: CompilerConfig);
|
|
40
|
+
compile(): Promise<void>;
|
|
41
|
+
watch(): Promise<void>;
|
|
42
|
+
private processFile;
|
|
43
|
+
private findYAMLFiles;
|
|
44
|
+
private isYAMLFile;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=patterns-compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"patterns-compiler.d.ts","sourceRoot":"","sources":["../../../../../libs/cli/src/compilers/patterns-compiler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAOhD,wDAAwD;AACxD,MAAM,WAAW,aAAa;IAC5B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC;IAChB,sEAAsE;IACtE,OAAO,EAAE,MAAM,CAAC;IAChB,mEAAmE;IACnE,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,8EAA8E;AAC9E,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB;AAID;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAM3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAQvD;AAED,qBAAa,gBAAiB,SAAQ,YAAY;IAChD,OAAO,CAAC,OAAO,CAA4B;gBAE/B,MAAM,EAAE,cAAc;IAI5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BxB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAsBd,WAAW;YA4CX,aAAa;IAe3B,OAAO,CAAC,UAAU;CAGnB"}
|