@kosdev-code/kos-codegen-core 0.1.0-next.790 → 0.1.0-next.796
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/index.d.ts +2 -2
- package/index.d.ts.map +1 -1
- package/index.js +814 -488
- package/index.js.map +1 -1
- package/index.mjs +813 -487
- package/index.mjs.map +1 -1
- package/lib/generators/add-future-to-model/model-transformer.d.ts +3 -4
- package/lib/generators/add-future-to-model/model-transformer.d.ts.map +1 -1
- package/lib/generators/add-future-to-model/normalize-options.d.ts.map +1 -1
- package/lib/generators/add-future-to-model/registration-transformer.d.ts.map +1 -1
- package/lib/generators/augment/resolve-model-file.d.ts.map +1 -1
- package/lib/generators/ci-sync.d.ts +26 -0
- package/lib/generators/ci-sync.d.ts.map +1 -0
- package/lib/generators/generate-polyglot-workspace.d.ts +29 -0
- package/lib/generators/generate-polyglot-workspace.d.ts.map +1 -0
- package/lib/generators/index.d.ts +6 -0
- package/lib/generators/index.d.ts.map +1 -1
- package/lib/generators/java-workspace.d.ts +33 -0
- package/lib/generators/java-workspace.d.ts.map +1 -0
- package/lib/generators/kab-targets.d.ts +40 -0
- package/lib/generators/kab-targets.d.ts.map +1 -0
- package/lib/generators/release-version-script.d.ts +10 -0
- package/lib/generators/release-version-script.d.ts.map +1 -0
- package/package.json +2 -2
- package/templates/polyglot-workspace/build/build-java.sh.template +18 -0
- package/templates/polyglot-workspace/build/build-release.sh.template +11 -0
- package/templates/polyglot-workspace/build/build-ui.sh.template +16 -0
- package/templates/polyglot-workspace/build/docker-build.sh.template +49 -0
- package/templates/polyglot-workspace/build/jdkw.sh.template +93 -0
- package/templates/polyglot-workspace/build/nodew.sh.template +73 -0
- package/templates/polyglot-workspace/build/release_version_prebuild.sh.template +31 -0
- package/templates/polyglot-workspace/github/build-java.json.template +6 -0
- package/templates/polyglot-workspace/github/build-release.json.template +14 -0
- package/templates/polyglot-workspace/github/build-ui.json.template +13 -0
- package/templates/polyglot-workspace/github/workflows/develop-java.yml.template +35 -0
- package/templates/polyglot-workspace/github/workflows/develop-ui.yml.template +38 -0
- package/templates/polyglot-workspace/github/workflows/release.yml.template +37 -0
- package/templates/polyglot-workspace/java/README.md.template +36 -0
- package/templates/polyglot-workspace/root/.gitignore.template +5 -0
- package/templates/polyglot-workspace/root/README.md.template +69 -0
package/index.mjs
CHANGED
|
@@ -515,6 +515,294 @@ function generateInit(codegenFs, options) {
|
|
|
515
515
|
};
|
|
516
516
|
writeJson(codegenFs, "nx.json", nxConfig);
|
|
517
517
|
}
|
|
518
|
+
const BUILD_SCRIPTS = [
|
|
519
|
+
"build/build-ui.sh",
|
|
520
|
+
"build/build-java.sh",
|
|
521
|
+
"build/build-release.sh",
|
|
522
|
+
"build/release_version_prebuild.sh",
|
|
523
|
+
"build/docker-build.sh"
|
|
524
|
+
];
|
|
525
|
+
function generatePolyglotWorkspace(codegenFs, templateDir, options) {
|
|
526
|
+
const normalized = normalizeAllValues({ name: options.name });
|
|
527
|
+
const vars = {
|
|
528
|
+
...normalized,
|
|
529
|
+
keyset: options.keyset || "prod.kos",
|
|
530
|
+
appUiName: `${normalized.nameDashCase}-ui`,
|
|
531
|
+
nodeVersion: options.nodeVersion || process.version.replace(/^v/, ""),
|
|
532
|
+
jdkMajor: options.jdkMajor || "17",
|
|
533
|
+
mavenVersion: options.mavenVersion || "3.9.9"
|
|
534
|
+
};
|
|
535
|
+
generateFilesFromTemplates(
|
|
536
|
+
codegenFs,
|
|
537
|
+
path.join(templateDir, "root"),
|
|
538
|
+
".",
|
|
539
|
+
vars
|
|
540
|
+
);
|
|
541
|
+
generateFilesFromTemplates(
|
|
542
|
+
codegenFs,
|
|
543
|
+
path.join(templateDir, "build"),
|
|
544
|
+
"build",
|
|
545
|
+
vars
|
|
546
|
+
);
|
|
547
|
+
generateFilesFromTemplates(
|
|
548
|
+
codegenFs,
|
|
549
|
+
path.join(templateDir, "github"),
|
|
550
|
+
".github",
|
|
551
|
+
vars
|
|
552
|
+
);
|
|
553
|
+
generateFilesFromTemplates(
|
|
554
|
+
codegenFs,
|
|
555
|
+
path.join(templateDir, "java"),
|
|
556
|
+
"java",
|
|
557
|
+
vars
|
|
558
|
+
);
|
|
559
|
+
return { executablePaths: [...BUILD_SCRIPTS] };
|
|
560
|
+
}
|
|
561
|
+
const UI_PROJECT_DIRS = [
|
|
562
|
+
"apps",
|
|
563
|
+
"libs",
|
|
564
|
+
"plugins",
|
|
565
|
+
"splash",
|
|
566
|
+
"themes",
|
|
567
|
+
"content",
|
|
568
|
+
"translations"
|
|
569
|
+
];
|
|
570
|
+
function joinArtifactPath(outputPath, fileName) {
|
|
571
|
+
return `${outputPath.replace(/\/+$/, "")}/${fileName}`;
|
|
572
|
+
}
|
|
573
|
+
function discoverUiArtifacts(codegenFs) {
|
|
574
|
+
const artifacts = [];
|
|
575
|
+
for (const dir of UI_PROJECT_DIRS) {
|
|
576
|
+
for (const file of codegenFs.listFiles(`ui/${dir}`)) {
|
|
577
|
+
if (!file.endsWith("project.json")) continue;
|
|
578
|
+
const raw = codegenFs.read(file);
|
|
579
|
+
if (raw === null) continue;
|
|
580
|
+
let project;
|
|
581
|
+
try {
|
|
582
|
+
project = JSON.parse(raw);
|
|
583
|
+
} catch {
|
|
584
|
+
continue;
|
|
585
|
+
}
|
|
586
|
+
const name = project.name;
|
|
587
|
+
if (!name) continue;
|
|
588
|
+
const kabOptions = project.targets?.kab?.options;
|
|
589
|
+
if (kabOptions?.outputPath && kabOptions?.kabName) {
|
|
590
|
+
artifacts.push({
|
|
591
|
+
id: name,
|
|
592
|
+
filename: `ui/${joinArtifactPath(kabOptions.outputPath, kabOptions.kabName)}`
|
|
593
|
+
});
|
|
594
|
+
} else if (project.targets?.splash) {
|
|
595
|
+
artifacts.push({
|
|
596
|
+
id: name,
|
|
597
|
+
filename: `ui/dist/archives/packages/${name}/${name}.kab`,
|
|
598
|
+
layer: 1
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
for (const file of codegenFs.listFiles("ui/external")) {
|
|
604
|
+
if (!file.endsWith(".kab")) continue;
|
|
605
|
+
const base = file.slice(file.lastIndexOf("/") + 1, -".kab".length);
|
|
606
|
+
artifacts.push({ id: base, filename: file });
|
|
607
|
+
}
|
|
608
|
+
return artifacts;
|
|
609
|
+
}
|
|
610
|
+
function discoverJavaArtifacts(codegenFs) {
|
|
611
|
+
const aggregator = codegenFs.read("java/pom.xml");
|
|
612
|
+
if (aggregator === null) return [];
|
|
613
|
+
const artifacts = [];
|
|
614
|
+
for (const match of aggregator.matchAll(/<module>([^<]+)<\/module>/g)) {
|
|
615
|
+
const moduleDir = match[1];
|
|
616
|
+
const pom = codegenFs.read(`java/${moduleDir}/pom.xml`);
|
|
617
|
+
if (pom === null || !pom.includes("kos-kab-maven-plugin")) continue;
|
|
618
|
+
const withoutParent = pom.replace(/<parent>[\s\S]*?<\/parent>/, "");
|
|
619
|
+
const artifactId = withoutParent.match(
|
|
620
|
+
/<artifactId>([^<]+)<\/artifactId>/
|
|
621
|
+
)?.[1];
|
|
622
|
+
if (!artifactId) continue;
|
|
623
|
+
artifacts.push({
|
|
624
|
+
id: moduleDir,
|
|
625
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
626
|
+
filename: `java/${moduleDir}/target/${artifactId}-\${KOS_STD_VERSION_REGEX}.kab`
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
return artifacts;
|
|
630
|
+
}
|
|
631
|
+
function syncManifest(codegenFs, manifestPath, discovered, prune) {
|
|
632
|
+
const raw = codegenFs.read(manifestPath);
|
|
633
|
+
if (raw === null) return null;
|
|
634
|
+
const manifest = JSON.parse(raw);
|
|
635
|
+
const existing = manifest.artifacts ?? [];
|
|
636
|
+
const byFilename = new Map(discovered.map((d) => [d.filename, d]));
|
|
637
|
+
const kept = [];
|
|
638
|
+
const stale = [];
|
|
639
|
+
const pruned = [];
|
|
640
|
+
for (const entry of existing) {
|
|
641
|
+
if (byFilename.has(entry.filename)) {
|
|
642
|
+
kept.push(entry);
|
|
643
|
+
byFilename.delete(entry.filename);
|
|
644
|
+
} else if (prune) {
|
|
645
|
+
pruned.push(entry.id ?? entry.filename);
|
|
646
|
+
} else {
|
|
647
|
+
kept.push(entry);
|
|
648
|
+
stale.push(entry.id ?? entry.filename);
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
const added = [];
|
|
652
|
+
for (const artifact of byFilename.values()) {
|
|
653
|
+
kept.push({
|
|
654
|
+
id: artifact.id,
|
|
655
|
+
filename: artifact.filename,
|
|
656
|
+
artifactstore: "kos-cdn",
|
|
657
|
+
marketplace: 1,
|
|
658
|
+
...artifact.layer !== void 0 ? { layer: artifact.layer } : {}
|
|
659
|
+
});
|
|
660
|
+
added.push(artifact.id);
|
|
661
|
+
}
|
|
662
|
+
if (added.length > 0 || pruned.length > 0) {
|
|
663
|
+
manifest.artifacts = kept;
|
|
664
|
+
codegenFs.write(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
|
|
665
|
+
}
|
|
666
|
+
return { added, stale, pruned };
|
|
667
|
+
}
|
|
668
|
+
function syncCiManifests(codegenFs, options = {}) {
|
|
669
|
+
const prune = options.prune ?? false;
|
|
670
|
+
const ui = discoverUiArtifacts(codegenFs);
|
|
671
|
+
const java = discoverJavaArtifacts(codegenFs);
|
|
672
|
+
const manifests = {};
|
|
673
|
+
const plan = [
|
|
674
|
+
[".github/build-ui.json", ui],
|
|
675
|
+
[".github/build-java.json", java],
|
|
676
|
+
[".github/build-release.json", [...ui, ...java]]
|
|
677
|
+
];
|
|
678
|
+
for (const [manifestPath, discovered] of plan) {
|
|
679
|
+
const result = syncManifest(codegenFs, manifestPath, discovered, prune);
|
|
680
|
+
if (result) {
|
|
681
|
+
manifests[manifestPath] = result;
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return { manifests, discovered: { ui, java } };
|
|
685
|
+
}
|
|
686
|
+
function ensureJavaAggregatorPom(codegenFs, options) {
|
|
687
|
+
const pomPath = "java/pom.xml";
|
|
688
|
+
const existing = codegenFs.read(pomPath);
|
|
689
|
+
if (existing === null) {
|
|
690
|
+
codegenFs.write(
|
|
691
|
+
pomPath,
|
|
692
|
+
`<?xml version="1.0" encoding="UTF-8"?>
|
|
693
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
694
|
+
<modelVersion>4.0.0</modelVersion>
|
|
695
|
+
<groupId>${options.groupId}</groupId>
|
|
696
|
+
<artifactId>${options.artifactId}</artifactId>
|
|
697
|
+
<version>0.0.0-SNAPSHOT</version>
|
|
698
|
+
<packaging>pom</packaging>
|
|
699
|
+
<modules>
|
|
700
|
+
<module>${options.moduleName}</module>
|
|
701
|
+
</modules>
|
|
702
|
+
</project>
|
|
703
|
+
`
|
|
704
|
+
);
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
if (existing.includes(`<module>${options.moduleName}</module>`)) {
|
|
708
|
+
return;
|
|
709
|
+
}
|
|
710
|
+
codegenFs.write(
|
|
711
|
+
pomPath,
|
|
712
|
+
existing.replace(
|
|
713
|
+
"</modules>",
|
|
714
|
+
` <module>${options.moduleName}</module>
|
|
715
|
+
</modules>`
|
|
716
|
+
)
|
|
717
|
+
);
|
|
718
|
+
}
|
|
719
|
+
function finalizeArchetypeModule(codegenFs, options) {
|
|
720
|
+
const { moduleName, kosVersion, kabPluginVersion, apiInfoVersion } = options;
|
|
721
|
+
const notes = [];
|
|
722
|
+
const pomPath = `java/${moduleName}/pom.xml`;
|
|
723
|
+
let pom = codegenFs.read(pomPath);
|
|
724
|
+
if (pom === null) {
|
|
725
|
+
throw new Error(`Generated module pom not found: ${pomPath}`);
|
|
726
|
+
}
|
|
727
|
+
if (pom.includes("<kos.version>0.0.0-SNAPSHOT</kos.version>")) {
|
|
728
|
+
if (kosVersion) {
|
|
729
|
+
pom = pom.replace(
|
|
730
|
+
"<kos.version>0.0.0-SNAPSHOT</kos.version>",
|
|
731
|
+
`<kos.version>${kosVersion}</kos.version>`
|
|
732
|
+
);
|
|
733
|
+
} else {
|
|
734
|
+
notes.push(
|
|
735
|
+
"kos.version is 0.0.0-SNAPSHOT — set it to a released kos-bom version before building"
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
if (pom.includes("${kos-kab-maven-plugin.version}") && !pom.includes("<kos-kab-maven-plugin.version>")) {
|
|
740
|
+
if (kabPluginVersion) {
|
|
741
|
+
pom = pom.replace(
|
|
742
|
+
/(<kos\.version>[^<]*<\/kos\.version>)/,
|
|
743
|
+
`$1
|
|
744
|
+
<kos-kab-maven-plugin.version>${kabPluginVersion}</kos-kab-maven-plugin.version>`
|
|
745
|
+
);
|
|
746
|
+
} else {
|
|
747
|
+
notes.push(
|
|
748
|
+
"the ${kos-kab-maven-plugin.version} property is referenced but undefined — add it before building"
|
|
749
|
+
);
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
const unversionedApiInfo = /<artifactId>api-info<\/artifactId>(\s*)<\/dependency>/;
|
|
753
|
+
if (unversionedApiInfo.test(pom)) {
|
|
754
|
+
if (apiInfoVersion) {
|
|
755
|
+
pom = pom.replace(
|
|
756
|
+
unversionedApiInfo,
|
|
757
|
+
`<artifactId>api-info</artifactId>$1 <version>${apiInfoVersion}</version>$1</dependency>`
|
|
758
|
+
);
|
|
759
|
+
} else {
|
|
760
|
+
notes.push(
|
|
761
|
+
"api-info has no version and is not managed by the kos-bom — add one before building"
|
|
762
|
+
);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
codegenFs.write(pomPath, pom);
|
|
766
|
+
const githubDir = `java/${moduleName}/github`;
|
|
767
|
+
if (codegenFs.exists(githubDir)) {
|
|
768
|
+
for (const file of codegenFs.listFiles(githubDir)) {
|
|
769
|
+
codegenFs.delete(file);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
const gitignore = codegenFs.read(`java/${moduleName}/gitignore`);
|
|
773
|
+
if (gitignore !== null) {
|
|
774
|
+
codegenFs.write(`java/${moduleName}/.gitignore`, gitignore);
|
|
775
|
+
codegenFs.delete(`java/${moduleName}/gitignore`);
|
|
776
|
+
}
|
|
777
|
+
return notes;
|
|
778
|
+
}
|
|
779
|
+
function addJavaArtifactToManifests(codegenFs, options) {
|
|
780
|
+
const { moduleName } = options;
|
|
781
|
+
for (const manifestPath of [
|
|
782
|
+
".github/build-java.json",
|
|
783
|
+
".github/build-release.json"
|
|
784
|
+
]) {
|
|
785
|
+
const raw = codegenFs.read(manifestPath);
|
|
786
|
+
if (raw === null) {
|
|
787
|
+
continue;
|
|
788
|
+
}
|
|
789
|
+
const manifest = JSON.parse(raw);
|
|
790
|
+
manifest.artifacts = manifest.artifacts ?? [];
|
|
791
|
+
if (manifest.artifacts.some(
|
|
792
|
+
(artifact) => artifact.id === moduleName
|
|
793
|
+
)) {
|
|
794
|
+
continue;
|
|
795
|
+
}
|
|
796
|
+
manifest.artifacts.push({
|
|
797
|
+
id: moduleName,
|
|
798
|
+
// eslint-disable-next-line no-template-curly-in-string
|
|
799
|
+
filename: `java/${moduleName}/target/${moduleName}-\${KOS_STD_VERSION_REGEX}.kab`,
|
|
800
|
+
artifactstore: "kos-cdn",
|
|
801
|
+
marketplace: 1
|
|
802
|
+
});
|
|
803
|
+
codegenFs.write(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
|
|
804
|
+
}
|
|
805
|
+
}
|
|
518
806
|
function normalizeOptions(codegenFs, options, projects) {
|
|
519
807
|
const toNormalize = {
|
|
520
808
|
name: options.name
|
|
@@ -560,6 +848,103 @@ function normalizeOptions(codegenFs, options, projects) {
|
|
|
560
848
|
template: ""
|
|
561
849
|
};
|
|
562
850
|
}
|
|
851
|
+
const UPDATE_RELEASE_VERSION_SCRIPT_PATH = "tools/scripts/update-release-version.mjs";
|
|
852
|
+
function buildKabTargets(options) {
|
|
853
|
+
const {
|
|
854
|
+
name,
|
|
855
|
+
archiveDir = "packages",
|
|
856
|
+
descriptorDir,
|
|
857
|
+
buildTarget = "build"
|
|
858
|
+
} = options;
|
|
859
|
+
const outputPath = `dist/archives/${archiveDir}/${name}/`;
|
|
860
|
+
const targets = {
|
|
861
|
+
kab: {
|
|
862
|
+
command: `node tools/scripts/kabtool.mjs build ${name} && node tools/scripts/kabtool.mjs list ${name} `,
|
|
863
|
+
options: {
|
|
864
|
+
outputPath,
|
|
865
|
+
zipName: "ui.zip",
|
|
866
|
+
kabName: `${name}.kab`
|
|
867
|
+
},
|
|
868
|
+
dependsOn: ["zip"]
|
|
869
|
+
},
|
|
870
|
+
zip: {
|
|
871
|
+
command: `node tools/scripts/archiver.js ${name}`,
|
|
872
|
+
options: {
|
|
873
|
+
outputPath,
|
|
874
|
+
zipName: "ui.zip"
|
|
875
|
+
},
|
|
876
|
+
dependsOn: descriptorDir ? [buildTarget, "descriptor"] : [buildTarget]
|
|
877
|
+
}
|
|
878
|
+
};
|
|
879
|
+
if (descriptorDir) {
|
|
880
|
+
targets.descriptor = {
|
|
881
|
+
command: `node tools/scripts/descriptor.mjs ${name}`,
|
|
882
|
+
options: {
|
|
883
|
+
outputPath: `dist/${descriptorDir}`,
|
|
884
|
+
fileName: "descriptor.json"
|
|
885
|
+
},
|
|
886
|
+
dependsOn: ["build"]
|
|
887
|
+
};
|
|
888
|
+
}
|
|
889
|
+
targets.version = {
|
|
890
|
+
command: `node ${UPDATE_RELEASE_VERSION_SCRIPT_PATH} ${name} {args.ver}`,
|
|
891
|
+
options: {},
|
|
892
|
+
dependsOn: []
|
|
893
|
+
};
|
|
894
|
+
return targets;
|
|
895
|
+
}
|
|
896
|
+
const UPDATE_RELEASE_VERSION_SCRIPT = `import devkit from "@nx/devkit";
|
|
897
|
+
import { resolve } from "path";
|
|
898
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
899
|
+
import prettier from "prettier";
|
|
900
|
+
|
|
901
|
+
// KOS artifact versioning: stamps the project's .kos.json "version" field
|
|
902
|
+
// (which kabtool bakes into the KAB). Never touches package.json.
|
|
903
|
+
// Driven by tag-based releases:
|
|
904
|
+
// nx run-many --target=version --args=--ver=$KOSBUILD_VERSION
|
|
905
|
+
|
|
906
|
+
const { readCachedProjectGraph } = devkit;
|
|
907
|
+
const [, , name, versionArg] = process.argv;
|
|
908
|
+
|
|
909
|
+
// "{args.ver}" arrives literally when the target runs without --args=--ver=<v>;
|
|
910
|
+
// treat that (or a missing arg) as "report current version, change nothing".
|
|
911
|
+
const version =
|
|
912
|
+
versionArg && !versionArg.startsWith("{args") ? versionArg : undefined;
|
|
913
|
+
|
|
914
|
+
if (!name) {
|
|
915
|
+
console.error("usage: update-release-version.mjs <project> <version>");
|
|
916
|
+
process.exit(1);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
const graph = readCachedProjectGraph();
|
|
920
|
+
const project = graph.nodes[name];
|
|
921
|
+
if (!project) {
|
|
922
|
+
console.error("Unknown project: " + name);
|
|
923
|
+
process.exit(1);
|
|
924
|
+
}
|
|
925
|
+
|
|
926
|
+
const kosJsonPath = resolve(process.cwd(), project.data.root, ".kos.json");
|
|
927
|
+
let kosJson;
|
|
928
|
+
try {
|
|
929
|
+
kosJson = JSON.parse(readFileSync(kosJsonPath, "utf8"));
|
|
930
|
+
} catch {
|
|
931
|
+
console.error("Missing or invalid .kos.json: " + kosJsonPath);
|
|
932
|
+
process.exit(1);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
if (!version) {
|
|
936
|
+
console.log(name + ": " + kosJson.version + " (no --ver given; unchanged)");
|
|
937
|
+
process.exit(0);
|
|
938
|
+
}
|
|
939
|
+
|
|
940
|
+
const prettierOptions = await prettier.resolveConfig(kosJsonPath);
|
|
941
|
+
const output = await prettier.format(
|
|
942
|
+
JSON.stringify({ ...kosJson, version }, null, 2),
|
|
943
|
+
{ ...prettierOptions, parser: "json" }
|
|
944
|
+
);
|
|
945
|
+
writeFileSync(kosJsonPath, output);
|
|
946
|
+
console.log(name + ": version -> " + version);
|
|
947
|
+
`;
|
|
563
948
|
function appendBarrelExport(codegenFs, indexPath, exportPath) {
|
|
564
949
|
const exportLine = `export * from '${exportPath}'`;
|
|
565
950
|
const content = codegenFs.read(indexPath) ?? "";
|
|
@@ -955,6 +1340,63 @@ function generateModel(params) {
|
|
|
955
1340
|
);
|
|
956
1341
|
}
|
|
957
1342
|
}
|
|
1343
|
+
function resolveModelFilePath(codegenFs, query, projects) {
|
|
1344
|
+
const kosConfig = getKosProjectConfiguration(
|
|
1345
|
+
codegenFs,
|
|
1346
|
+
query.modelProject,
|
|
1347
|
+
projects
|
|
1348
|
+
);
|
|
1349
|
+
const internal = !!kosConfig?.generator?.internal;
|
|
1350
|
+
const project = findProjectByName(
|
|
1351
|
+
codegenFs.root,
|
|
1352
|
+
query.modelProject,
|
|
1353
|
+
projects
|
|
1354
|
+
);
|
|
1355
|
+
const sourceRoot = project ? project.sourceRoot || path.join(project.root, "src") : void 0;
|
|
1356
|
+
if (query.modelPath) {
|
|
1357
|
+
return { modelFilePath: query.modelPath, internal, sourceRoot };
|
|
1358
|
+
}
|
|
1359
|
+
if (!project) {
|
|
1360
|
+
throw new Error(
|
|
1361
|
+
`Project not found: ${query.modelProject}. Ensure a project.json exists.`
|
|
1362
|
+
);
|
|
1363
|
+
}
|
|
1364
|
+
const { modelNameDashCase } = normalizeAllValues({
|
|
1365
|
+
modelName: query.modelName
|
|
1366
|
+
});
|
|
1367
|
+
const modelLocation = kosConfig?.generator?.defaults?.model?.folder || "";
|
|
1368
|
+
const modelFilePath = path.join(
|
|
1369
|
+
sourceRoot,
|
|
1370
|
+
modelLocation,
|
|
1371
|
+
modelNameDashCase,
|
|
1372
|
+
`${modelNameDashCase}-model.ts`
|
|
1373
|
+
);
|
|
1374
|
+
if (codegenFs.exists(modelFilePath)) {
|
|
1375
|
+
return { modelFilePath, internal, sourceRoot };
|
|
1376
|
+
}
|
|
1377
|
+
const discovered = findModelFileByName(
|
|
1378
|
+
codegenFs,
|
|
1379
|
+
path.join(sourceRoot, modelLocation),
|
|
1380
|
+
modelNameDashCase
|
|
1381
|
+
);
|
|
1382
|
+
if (discovered) {
|
|
1383
|
+
return { modelFilePath: discovered, internal, sourceRoot };
|
|
1384
|
+
}
|
|
1385
|
+
return { modelFilePath, internal, sourceRoot };
|
|
1386
|
+
}
|
|
1387
|
+
function findModelFileByName(codegenFs, searchRoot, modelNameDashCase) {
|
|
1388
|
+
const fileName = `${modelNameDashCase}-model.ts`;
|
|
1389
|
+
const candidates = codegenFs.listFiles(searchRoot).filter((f) => path.basename(f) === fileName).sort();
|
|
1390
|
+
if (candidates.length === 0) return null;
|
|
1391
|
+
if (candidates.length > 1) {
|
|
1392
|
+
throw new Error(
|
|
1393
|
+
`Model name '${modelNameDashCase}' is ambiguous — multiple files match ${fileName}:
|
|
1394
|
+
` + candidates.map((c) => ` - ${c}`).join("\n") + `
|
|
1395
|
+
Pass modelPath to pick one.`
|
|
1396
|
+
);
|
|
1397
|
+
}
|
|
1398
|
+
return candidates[0];
|
|
1399
|
+
}
|
|
958
1400
|
function normalizeAddFutureOptions(codegenFs, options, projects) {
|
|
959
1401
|
const projectConfiguration = findProjectByName(
|
|
960
1402
|
codegenFs.root,
|
|
@@ -983,9 +1425,12 @@ function normalizeAddFutureOptions(codegenFs, options, projects) {
|
|
|
983
1425
|
const nameLowerCase = normalizedValues.modelNameLowerCase;
|
|
984
1426
|
const projectRoot = projectConfiguration.root;
|
|
985
1427
|
const sourceRoot = projectConfiguration.sourceRoot || path.join(projectRoot, "src");
|
|
986
|
-
const
|
|
987
|
-
|
|
988
|
-
|
|
1428
|
+
const { modelFilePath } = resolveModelFilePath(
|
|
1429
|
+
codegenFs,
|
|
1430
|
+
{ modelName: options.modelName, modelProject: options.modelProject },
|
|
1431
|
+
projects
|
|
1432
|
+
);
|
|
1433
|
+
const modelDirectory = path.dirname(modelFilePath);
|
|
989
1434
|
const servicesDirectory = path.join(modelDirectory, "services");
|
|
990
1435
|
const servicesFilePath = codegenFs.exists(servicesDirectory) ? path.join(servicesDirectory, `${nameDashCase}-services.ts`) : void 0;
|
|
991
1436
|
const registrationFilePath = path.join(
|
|
@@ -1008,309 +1453,357 @@ function normalizeAddFutureOptions(codegenFs, options, projects) {
|
|
|
1008
1453
|
internal
|
|
1009
1454
|
};
|
|
1010
1455
|
}
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
}
|
|
1016
|
-
codegenFs;
|
|
1017
|
-
options;
|
|
1018
|
-
transform() {
|
|
1019
|
-
const { modelFilePath } = this.options;
|
|
1020
|
-
if (!this.codegenFs.exists(modelFilePath)) {
|
|
1021
|
-
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1022
|
-
}
|
|
1023
|
-
let content = this.codegenFs.read(modelFilePath);
|
|
1024
|
-
content = this.addESLintDisable(content);
|
|
1025
|
-
content = this.addImports(content);
|
|
1026
|
-
content = this.addServiceImport(content);
|
|
1027
|
-
content = this.addInterfaceMerging(content);
|
|
1028
|
-
content = this.addDecorator(content);
|
|
1029
|
-
content = this.updatePublicType(content);
|
|
1030
|
-
content = this.removeLegacySetup(content);
|
|
1031
|
-
content = this.addFutureMethod(content);
|
|
1032
|
-
if (this.options.futureType === "complete") {
|
|
1033
|
-
content = this.addOnFutureUpdateMethod(content);
|
|
1034
|
-
}
|
|
1035
|
-
this.codegenFs.write(modelFilePath, content);
|
|
1036
|
-
}
|
|
1037
|
-
addESLintDisable(content) {
|
|
1038
|
-
if (content.includes("@typescript-eslint/no-unsafe-declaration-merging")) {
|
|
1039
|
-
return content;
|
|
1040
|
-
}
|
|
1041
|
-
const eslintDisable = "/* eslint-disable @typescript-eslint/no-unsafe-declaration-merging */\n";
|
|
1042
|
-
return eslintDisable + content;
|
|
1043
|
-
}
|
|
1044
|
-
addImports(content) {
|
|
1045
|
-
const { internal, futureType } = this.options;
|
|
1046
|
-
const isComplete = futureType === "complete";
|
|
1047
|
-
const kosModelImportRegex = internal ? /import\s*{\s*([^}]*kosModel[^}]*)\s*}\s*from\s*"\.\.\/\.\.\/\.\.\/core\/core\/decorators"/ : /import\s*{\s*([^}]*kosModel[^}]*)\s*}\s*from\s*"@kosdev-code\/kos-ui-sdk"/;
|
|
1048
|
-
const kosModelMatch = content.match(kosModelImportRegex);
|
|
1049
|
-
if (kosModelMatch) {
|
|
1050
|
-
const existingImportsStr = kosModelMatch[1] || "";
|
|
1051
|
-
const newImports = [
|
|
1052
|
-
"kosFuture",
|
|
1053
|
-
"kosFutureAware",
|
|
1054
|
-
isComplete ? "KosFutureAwareFull" : "KosFutureAwareMinimal"
|
|
1055
|
-
];
|
|
1056
|
-
const existingImports = existingImportsStr.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1057
|
-
const importsToRemove = [
|
|
1058
|
-
"setupCompleteFutureSupport",
|
|
1059
|
-
"setupMinimalFutureSupport"
|
|
1060
|
-
];
|
|
1061
|
-
const cleanedImports = existingImports.filter(
|
|
1062
|
-
(imp) => !importsToRemove.includes(imp)
|
|
1063
|
-
);
|
|
1064
|
-
const importsToAdd = newImports.filter(
|
|
1065
|
-
(imp) => !cleanedImports.includes(imp)
|
|
1066
|
-
);
|
|
1067
|
-
const allImports = [...cleanedImports, ...importsToAdd];
|
|
1068
|
-
const newImportLine = internal ? `import { ${allImports.join(
|
|
1069
|
-
", "
|
|
1070
|
-
)} } from "../../../core/core/decorators"` : `import { ${allImports.join(", ")} } from "@kosdev-code/kos-ui-sdk"`;
|
|
1071
|
-
content = content.replace(kosModelImportRegex, newImportLine);
|
|
1072
|
-
}
|
|
1073
|
-
const typeImportsBase = internal ? "../../../models/types/future-interfaces" : "@kosdev-code/kos-ui-sdk";
|
|
1074
|
-
const futureTypeImports = ["ExternalFutureInterface", "IFutureModel"];
|
|
1075
|
-
const typeImportRegex = internal ? /import type {([^}]*)} from "\.\.\/\.\.\/\.\.\/models\/types\/future-interfaces"/ : /import type {([^}]*)} from "@kosdev-code\/kos-ui-sdk"/;
|
|
1076
|
-
const typeImportMatch = content.match(typeImportRegex);
|
|
1077
|
-
if (typeImportMatch) {
|
|
1078
|
-
const existingTypes = typeImportMatch[1] || "";
|
|
1079
|
-
const existingTypesList = existingTypes.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1080
|
-
const typesToRemove = [
|
|
1081
|
-
"FutureAwareContainer",
|
|
1082
|
-
"FutureHandlerContainer",
|
|
1083
|
-
"FutureStateAccessor",
|
|
1084
|
-
"FutureUpdateHandler"
|
|
1085
|
-
];
|
|
1086
|
-
const cleanedTypes = existingTypesList.filter(
|
|
1087
|
-
(type) => !typesToRemove.includes(type)
|
|
1088
|
-
);
|
|
1089
|
-
const typesToAdd = futureTypeImports.filter(
|
|
1090
|
-
(type) => !cleanedTypes.includes(type)
|
|
1091
|
-
);
|
|
1092
|
-
const allTypes = [...cleanedTypes, ...typesToAdd].join(", ");
|
|
1093
|
-
const newTypeImport = `import type { ${allTypes} } from "${typeImportsBase}"`;
|
|
1094
|
-
content = content.replace(typeImportRegex, newTypeImport);
|
|
1095
|
-
} else {
|
|
1096
|
-
const importLines = content.split("\n");
|
|
1097
|
-
const lastImportIndex = importLines.findLastIndex(
|
|
1098
|
-
(line) => line.trim().startsWith("import")
|
|
1099
|
-
);
|
|
1100
|
-
if (lastImportIndex >= 0) {
|
|
1101
|
-
const newTypeImport = `import type { ${futureTypeImports.join(
|
|
1102
|
-
", "
|
|
1103
|
-
)} } from "${typeImportsBase}";`;
|
|
1104
|
-
importLines.splice(lastImportIndex + 1, 0, newTypeImport);
|
|
1105
|
-
content = importLines.join("\n");
|
|
1106
|
-
}
|
|
1107
|
-
}
|
|
1108
|
-
return content;
|
|
1109
|
-
}
|
|
1110
|
-
addServiceImport(content) {
|
|
1111
|
-
const { nameProperCase, updateServices } = this.options;
|
|
1112
|
-
if (!updateServices) {
|
|
1113
|
-
return content;
|
|
1114
|
-
}
|
|
1115
|
-
if (content.includes(`${nameProperCase}OperationProgress`)) {
|
|
1116
|
-
return content;
|
|
1117
|
-
}
|
|
1118
|
-
const servicesImportRegex = /import\s*{([^}]*)}\s*from\s*["']\.\/services["'];?/s;
|
|
1119
|
-
const servicesMatch = content.match(servicesImportRegex);
|
|
1120
|
-
if (servicesMatch) {
|
|
1121
|
-
const existingImports = servicesMatch[1];
|
|
1122
|
-
const cleanedImports = existingImports.split(",").map((s) => s.trim()).filter(Boolean);
|
|
1123
|
-
cleanedImports.push(`${nameProperCase}OperationProgress`);
|
|
1124
|
-
const newImport = `import { ${cleanedImports.join(
|
|
1125
|
-
", "
|
|
1126
|
-
)} } from "./services";`;
|
|
1127
|
-
content = content.replace(servicesImportRegex, newImport);
|
|
1128
|
-
} else {
|
|
1129
|
-
const typesImportRegex = /import\s+type\s+{[^}]*}\s+from\s+["']\.\/types["'];?/;
|
|
1130
|
-
const typesMatch = content.match(typesImportRegex);
|
|
1131
|
-
if (typesMatch) {
|
|
1132
|
-
const newImport = `
|
|
1133
|
-
import type { ${nameProperCase}OperationProgress } from "./services";`;
|
|
1134
|
-
content = content.replace(typesMatch[0], typesMatch[0] + newImport);
|
|
1135
|
-
}
|
|
1136
|
-
}
|
|
1137
|
-
return content;
|
|
1138
|
-
}
|
|
1139
|
-
addInterfaceMerging(content) {
|
|
1140
|
-
const { nameProperCase, futureType } = this.options;
|
|
1141
|
-
const isComplete = futureType === "complete";
|
|
1142
|
-
const interfaceType = isComplete ? "KosFutureAwareFull" : "KosFutureAwareMinimal";
|
|
1143
|
-
const progressType = this.options.updateServices ? `${nameProperCase}OperationProgress` : "Record<string, unknown>";
|
|
1144
|
-
const classRegex = new RegExp(
|
|
1145
|
-
`(@kosModel[^\\n]*\\n)([^\\n]*export\\s+class\\s+${nameProperCase}ModelImpl)`,
|
|
1146
|
-
"m"
|
|
1147
|
-
);
|
|
1148
|
-
const classMatch = content.match(classRegex);
|
|
1149
|
-
if (classMatch) {
|
|
1150
|
-
const interfaceRegex = new RegExp(
|
|
1151
|
-
`interface\\s+${nameProperCase}ModelImpl\\s+extends`
|
|
1152
|
-
);
|
|
1153
|
-
if (!content.match(interfaceRegex)) {
|
|
1154
|
-
const interfaceMerging = `
|
|
1155
|
-
// Interface merging for Future Container type safety
|
|
1156
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
|
1157
|
-
export interface ${nameProperCase}ModelImpl extends ${interfaceType}<${progressType}> {}
|
|
1158
|
-
|
|
1159
|
-
`;
|
|
1160
|
-
content = content.replace(
|
|
1161
|
-
classMatch[0],
|
|
1162
|
-
interfaceMerging + classMatch[0]
|
|
1163
|
-
);
|
|
1164
|
-
}
|
|
1165
|
-
}
|
|
1166
|
-
return content;
|
|
1167
|
-
}
|
|
1168
|
-
addDecorator(content) {
|
|
1169
|
-
const { nameProperCase, futureType } = this.options;
|
|
1170
|
-
const isComplete = futureType === "complete";
|
|
1171
|
-
const classRegex = new RegExp(
|
|
1172
|
-
`(@kosModel[^\\n]*\\n)((?:@[^\\n]*\\n)*)([^\\n]*export\\s+class\\s+${nameProperCase}ModelImpl)`,
|
|
1173
|
-
"m"
|
|
1174
|
-
);
|
|
1175
|
-
const classMatch = content.match(classRegex);
|
|
1176
|
-
if (classMatch) {
|
|
1177
|
-
if (!classMatch[2].includes("@kosFutureAware")) {
|
|
1178
|
-
const decoratorOptions = isComplete ? "" : "{ mode: 'minimal' }";
|
|
1179
|
-
const futureDecorator = `@kosFutureAware(${decoratorOptions})
|
|
1180
|
-
`;
|
|
1181
|
-
content = content.replace(
|
|
1182
|
-
classMatch[0],
|
|
1183
|
-
classMatch[1] + classMatch[2] + futureDecorator + classMatch[3]
|
|
1184
|
-
);
|
|
1185
|
-
}
|
|
1186
|
-
}
|
|
1187
|
-
return content;
|
|
1188
|
-
}
|
|
1189
|
-
updatePublicType(content) {
|
|
1190
|
-
const { nameProperCase, updateServices } = this.options;
|
|
1191
|
-
const progressType = updateServices ? `${nameProperCase}OperationProgress` : "Record<string, unknown>";
|
|
1192
|
-
const typeRegex = new RegExp(
|
|
1193
|
-
`export\\s+type\\s+${nameProperCase}Model\\s*=\\s*PublicModelInterface<${nameProperCase}ModelImpl>([^;]*);`,
|
|
1194
|
-
"s"
|
|
1195
|
-
);
|
|
1196
|
-
const typeMatch = content.match(typeRegex);
|
|
1197
|
-
if (typeMatch) {
|
|
1198
|
-
if (!typeMatch[1].includes("ExternalFutureInterface")) {
|
|
1199
|
-
const newType = `export type ${nameProperCase}Model = PublicModelInterface<${nameProperCase}ModelImpl> & ExternalFutureInterface<${progressType}>;`;
|
|
1200
|
-
content = content.replace(typeMatch[0], newType);
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
return content;
|
|
1204
|
-
}
|
|
1205
|
-
removeLegacySetup(content) {
|
|
1206
|
-
const setupRegex = /\s*setup(Complete|Minimal)FutureSupport\(this\);?\s*/g;
|
|
1207
|
-
content = content.replace(setupRegex, "");
|
|
1208
|
-
const propertyRegex = /\s*(public|private|protected)?\s*(declare\s+)?futureHandler[!?]?:\s*FutureAwareContainer[^;]*;\s*/g;
|
|
1209
|
-
content = content.replace(propertyRegex, "");
|
|
1210
|
-
const futurePropertyRegex = /\s*(public|private|protected)?\s*(declare\s+)?future\??:\s*IFutureModel[^;]*;\s*/g;
|
|
1211
|
-
content = content.replace(futurePropertyRegex, "");
|
|
1212
|
-
const implementsRegex = new RegExp(
|
|
1213
|
-
`(implements\\s+[^{]*?)\\s*,?\\s*(FutureUpdateHandler|FutureHandlerContainer|FutureStateAccessor)`,
|
|
1214
|
-
"g"
|
|
1215
|
-
);
|
|
1216
|
-
content = content.replace(implementsRegex, "$1");
|
|
1217
|
-
content = content.replace(/,\s*,/g, ",");
|
|
1218
|
-
content = content.replace(/implements\s*,/g, "implements");
|
|
1219
|
-
return content;
|
|
1456
|
+
function transformSourceFile(codegenFs, filePath, mutate) {
|
|
1457
|
+
const content = codegenFs.read(filePath);
|
|
1458
|
+
if (content === null) {
|
|
1459
|
+
throw new Error(`File not found: ${filePath}`);
|
|
1220
1460
|
}
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1461
|
+
const project = new Project({
|
|
1462
|
+
useInMemoryFileSystem: true,
|
|
1463
|
+
manipulationSettings: {
|
|
1464
|
+
indentationText: IndentationText.TwoSpaces,
|
|
1465
|
+
quoteKind: QuoteKind.Double
|
|
1225
1466
|
}
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
async performLongRunningOperation(): Promise<void> {
|
|
1239
|
-
// TODO: Implement your long-running operation here
|
|
1240
|
-
// This method should use a service that returns a Future for progress tracking
|
|
1241
|
-
|
|
1242
|
-
this.logger.debug(\`Starting long-running operation for \${this.id}\`);
|
|
1243
|
-
|
|
1244
|
-
// Example implementation pattern using services:
|
|
1245
|
-
// import { perform${nameProperCase}Operation } from './services';
|
|
1246
|
-
//
|
|
1247
|
-
// const future = await perform${nameProperCase}Operation();
|
|
1248
|
-
// return this.futureHandler.setFuture(future);
|
|
1249
|
-
|
|
1250
|
-
// Placeholder that doesn't actually do anything
|
|
1251
|
-
await new Promise(resolve => setTimeout(resolve, 1000));
|
|
1252
|
-
|
|
1253
|
-
this.logger.debug(\`Completed long-running operation for \${this.id}\`);
|
|
1467
|
+
});
|
|
1468
|
+
const sourceFile = project.createSourceFile(filePath, content, {
|
|
1469
|
+
overwrite: true
|
|
1470
|
+
});
|
|
1471
|
+
mutate(sourceFile);
|
|
1472
|
+
codegenFs.write(filePath, sourceFile.getFullText());
|
|
1473
|
+
}
|
|
1474
|
+
function ensureNamedImport(sourceFile, moduleSpecifier, names) {
|
|
1475
|
+
const decls = sourceFile.getImportDeclarations().filter((d) => d.getModuleSpecifierValue() === moduleSpecifier);
|
|
1476
|
+
const existing = /* @__PURE__ */ new Set();
|
|
1477
|
+
for (const d of decls) {
|
|
1478
|
+
for (const n of d.getNamedImports()) existing.add(n.getName());
|
|
1254
1479
|
}
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
if (lastBraceIndex >= 0) {
|
|
1259
|
-
const updatedContent = classContent.slice(0, lastBraceIndex) + methodCode + classContent.slice(lastBraceIndex);
|
|
1260
|
-
content = content.replace(
|
|
1261
|
-
classMatch[0],
|
|
1262
|
-
`class ${nameProperCase}ModelImpl${classMatch[0].match(/[^{]*/)?.[0]}{${updatedContent}}`
|
|
1263
|
-
);
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
return content;
|
|
1480
|
+
let target = decls.find((d) => !d.isTypeOnly());
|
|
1481
|
+
if (!target) {
|
|
1482
|
+
target = sourceFile.addImportDeclaration({ moduleSpecifier });
|
|
1267
1483
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
return content;
|
|
1273
|
-
}
|
|
1274
|
-
const futureMethodRegex = /@kosFuture\(\)[^}]*}/s;
|
|
1275
|
-
const futureMethodMatch = content.match(futureMethodRegex);
|
|
1276
|
-
if (futureMethodMatch) {
|
|
1277
|
-
const methodCode = `
|
|
1278
|
-
|
|
1279
|
-
/**
|
|
1280
|
-
* Optional: Custom Future update handling
|
|
1281
|
-
* Called whenever the Future state changes (progress, status, completion, etc.)
|
|
1282
|
-
*/
|
|
1283
|
-
onFutureUpdate?(update: IFutureModel<${progressType}>): void {
|
|
1284
|
-
// Add custom Future update logic here
|
|
1285
|
-
// Examples:
|
|
1286
|
-
// - Log progress milestones
|
|
1287
|
-
// - Update derived state based on progress
|
|
1288
|
-
// - Handle specific error conditions
|
|
1289
|
-
// - Trigger notifications at certain thresholds
|
|
1290
|
-
|
|
1291
|
-
this.logger.debug(\`Future update for \${this.id}:\`, {
|
|
1292
|
-
progress: update.progress,
|
|
1293
|
-
status: update.status,
|
|
1294
|
-
endState: update.endState,
|
|
1295
|
-
clientData: update.clientData
|
|
1296
|
-
});
|
|
1297
|
-
}`;
|
|
1298
|
-
content = content.replace(
|
|
1299
|
-
futureMethodMatch[0],
|
|
1300
|
-
futureMethodMatch[0] + methodCode
|
|
1301
|
-
);
|
|
1302
|
-
}
|
|
1303
|
-
return content;
|
|
1484
|
+
for (const { name, isTypeOnly } of names) {
|
|
1485
|
+
if (existing.has(name)) continue;
|
|
1486
|
+
target.addNamedImport({ name, isTypeOnly: !!isTypeOnly });
|
|
1487
|
+
existing.add(name);
|
|
1304
1488
|
}
|
|
1305
1489
|
}
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1490
|
+
function resolveSdkModuleSpecifier(sourceFile) {
|
|
1491
|
+
const decl = sourceFile.getImportDeclarations().find((d) => d.getNamedImports().some((n) => n.getName() === "kosModel"));
|
|
1492
|
+
return decl?.getModuleSpecifierValue() ?? "@kosdev-code/kos-ui-sdk";
|
|
1493
|
+
}
|
|
1494
|
+
function getModelClass(sourceFile, preferName) {
|
|
1495
|
+
const classes = sourceFile.getClasses();
|
|
1496
|
+
const byName = preferName ? classes.find((c) => c.getName() === preferName) : void 0;
|
|
1497
|
+
if (byName) return byName;
|
|
1498
|
+
const impl = classes.find((c) => /ModelImpl$/.test(c.getName() ?? ""));
|
|
1499
|
+
if (impl) return impl;
|
|
1500
|
+
const exported = classes.find((c) => c.isExported());
|
|
1501
|
+
if (exported) return exported;
|
|
1502
|
+
if (classes.length > 0) return classes[0];
|
|
1503
|
+
throw new Error("No class declaration found in model file.");
|
|
1504
|
+
}
|
|
1505
|
+
function addClassDecorator(cls, name, opts) {
|
|
1506
|
+
if (cls.getDecorator(name)) return;
|
|
1507
|
+
const typeArgs = opts?.typeArgs?.length ? `<${opts.typeArgs.join(", ")}>` : "";
|
|
1508
|
+
const args = opts?.argsText ?? "";
|
|
1509
|
+
const decorators = cls.getDecorators();
|
|
1510
|
+
const kosModelIdx = decorators.findIndex((d) => d.getName() === "kosModel");
|
|
1511
|
+
const insertIdx = kosModelIdx >= 0 ? kosModelIdx + 1 : decorators.length;
|
|
1512
|
+
cls.insertDecorator(insertIdx, {
|
|
1513
|
+
name: `${name}${typeArgs}`,
|
|
1514
|
+
arguments: args ? [args] : []
|
|
1515
|
+
});
|
|
1516
|
+
}
|
|
1517
|
+
function ensureDeclarationMerge(sourceFile, interfaceName, extendsExpr, typeParameters = []) {
|
|
1518
|
+
const baseType = extendsExpr.split("<")[0].trim();
|
|
1519
|
+
let iface = sourceFile.getInterface(interfaceName);
|
|
1520
|
+
if (iface) {
|
|
1521
|
+
const already = iface.getExtends().some((e) => e.getText().split("<")[0].trim() === baseType);
|
|
1522
|
+
if (!already) iface.addExtends(extendsExpr);
|
|
1523
|
+
return;
|
|
1524
|
+
}
|
|
1525
|
+
iface = sourceFile.addInterface({
|
|
1526
|
+
name: interfaceName,
|
|
1527
|
+
isExported: true,
|
|
1528
|
+
typeParameters,
|
|
1529
|
+
extends: [extendsExpr]
|
|
1530
|
+
});
|
|
1531
|
+
sourceFile.insertText(
|
|
1532
|
+
iface.getStart(),
|
|
1533
|
+
"// eslint-disable-next-line @typescript-eslint/no-empty-interface\n"
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
function ensureFileEslintDisable(sourceFile, rule) {
|
|
1537
|
+
if (sourceFile.getFullText().includes(rule)) return;
|
|
1538
|
+
sourceFile.insertText(0, `/* eslint-disable ${rule} */
|
|
1539
|
+
`);
|
|
1540
|
+
}
|
|
1541
|
+
function addDecoratedMethod(cls, spec) {
|
|
1542
|
+
if (cls.getMethod(spec.name)) return false;
|
|
1543
|
+
cls.addMethod({
|
|
1544
|
+
name: spec.name,
|
|
1545
|
+
isAsync: spec.isAsync,
|
|
1546
|
+
returnType: spec.returnType,
|
|
1547
|
+
parameters: spec.parameters?.map((p) => {
|
|
1548
|
+
return { name: p.name, type: p.type };
|
|
1549
|
+
}),
|
|
1550
|
+
statements: spec.statements,
|
|
1551
|
+
decorators: [
|
|
1552
|
+
{
|
|
1553
|
+
name: spec.decoratorName,
|
|
1554
|
+
arguments: spec.decoratorArgsText ? [spec.decoratorArgsText] : []
|
|
1555
|
+
}
|
|
1556
|
+
]
|
|
1557
|
+
});
|
|
1558
|
+
return true;
|
|
1559
|
+
}
|
|
1560
|
+
function propertyInsertIndex(cls) {
|
|
1561
|
+
const props = cls.getProperties();
|
|
1562
|
+
if (props.length === 0) return 0;
|
|
1563
|
+
return props[props.length - 1].getChildIndex() + 1;
|
|
1564
|
+
}
|
|
1565
|
+
function addPlainProperty(cls, spec) {
|
|
1566
|
+
if (cls.getProperty(spec.name)) return false;
|
|
1567
|
+
cls.insertProperty(propertyInsertIndex(cls), {
|
|
1568
|
+
name: spec.name,
|
|
1569
|
+
type: spec.type,
|
|
1570
|
+
initializer: spec.initializer,
|
|
1571
|
+
isReadonly: !!spec.readonly,
|
|
1572
|
+
scope: spec.scope ? SCOPE_MAP[spec.scope] : void 0,
|
|
1573
|
+
hasExclamationToken: spec.initializer ? false : !!spec.hasExclamation
|
|
1574
|
+
});
|
|
1575
|
+
return true;
|
|
1576
|
+
}
|
|
1577
|
+
const SCOPE_MAP = {
|
|
1578
|
+
private: Scope.Private,
|
|
1579
|
+
protected: Scope.Protected,
|
|
1580
|
+
public: Scope.Public
|
|
1581
|
+
};
|
|
1582
|
+
function addDecoratedProperty(cls, spec) {
|
|
1583
|
+
if (cls.getProperty(spec.name)) return false;
|
|
1584
|
+
cls.insertProperty(propertyInsertIndex(cls), {
|
|
1585
|
+
name: spec.name,
|
|
1586
|
+
type: spec.type,
|
|
1587
|
+
initializer: spec.initializer,
|
|
1588
|
+
scope: spec.scope ? SCOPE_MAP[spec.scope] : void 0,
|
|
1589
|
+
hasExclamationToken: spec.initializer ? false : !!spec.hasExclamation,
|
|
1590
|
+
decorators: [
|
|
1591
|
+
spec.bare && !spec.decoratorArgsText ? { name: spec.decoratorName } : {
|
|
1592
|
+
name: spec.decoratorName,
|
|
1593
|
+
arguments: spec.decoratorArgsText ? [spec.decoratorArgsText] : []
|
|
1594
|
+
}
|
|
1595
|
+
]
|
|
1596
|
+
});
|
|
1597
|
+
return true;
|
|
1598
|
+
}
|
|
1599
|
+
function addGetter(cls, spec) {
|
|
1600
|
+
if (cls.getGetAccessor(spec.name)) return false;
|
|
1601
|
+
const ctor = cls.getConstructors()[0];
|
|
1602
|
+
const index = ctor ? ctor.getChildIndex() + 1 : propertyInsertIndex(cls);
|
|
1603
|
+
cls.insertGetAccessor(index, {
|
|
1604
|
+
name: spec.name,
|
|
1605
|
+
returnType: spec.returnType,
|
|
1606
|
+
statements: spec.statements ?? "// TODO: derive and return the computed value"
|
|
1607
|
+
});
|
|
1608
|
+
return true;
|
|
1609
|
+
}
|
|
1610
|
+
const LEGACY_IMPORTS = /* @__PURE__ */ new Set([
|
|
1611
|
+
"setupCompleteFutureSupport",
|
|
1612
|
+
"setupMinimalFutureSupport",
|
|
1613
|
+
"FutureAwareContainer",
|
|
1614
|
+
"FutureHandlerContainer",
|
|
1615
|
+
"FutureStateAccessor",
|
|
1616
|
+
"FutureUpdateHandler"
|
|
1617
|
+
]);
|
|
1618
|
+
const LEGACY_IMPLEMENTS = /* @__PURE__ */ new Set([
|
|
1619
|
+
"FutureUpdateHandler",
|
|
1620
|
+
"FutureHandlerContainer",
|
|
1621
|
+
"FutureStateAccessor"
|
|
1622
|
+
]);
|
|
1623
|
+
class ModelFileTransformer {
|
|
1624
|
+
constructor(codegenFs, options) {
|
|
1625
|
+
this.codegenFs = codegenFs;
|
|
1626
|
+
this.options = options;
|
|
1627
|
+
}
|
|
1628
|
+
codegenFs;
|
|
1629
|
+
options;
|
|
1630
|
+
get progressType() {
|
|
1631
|
+
const { nameProperCase, updateServices } = this.options;
|
|
1632
|
+
return updateServices ? `${nameProperCase}OperationProgress` : "Record<string, unknown>";
|
|
1633
|
+
}
|
|
1634
|
+
transform() {
|
|
1635
|
+
const { modelFilePath } = this.options;
|
|
1636
|
+
if (!this.codegenFs.exists(modelFilePath)) {
|
|
1637
|
+
throw new Error(`Model file not found: ${modelFilePath}`);
|
|
1638
|
+
}
|
|
1639
|
+
transformSourceFile(this.codegenFs, modelFilePath, (sf) => {
|
|
1640
|
+
this.removeLegacyImports(sf);
|
|
1641
|
+
this.addImports(sf);
|
|
1642
|
+
const cls = getModelClass(sf, `${this.options.nameProperCase}ModelImpl`);
|
|
1643
|
+
this.removeLegacyClassMembers(cls);
|
|
1644
|
+
this.addDecorator(cls);
|
|
1645
|
+
this.addFutureMethod(cls);
|
|
1646
|
+
if (this.options.futureType === "complete") {
|
|
1647
|
+
this.addOnFutureUpdateMethod(cls);
|
|
1648
|
+
}
|
|
1649
|
+
this.updatePublicType(sf);
|
|
1650
|
+
ensureDeclarationMerge(
|
|
1651
|
+
sf,
|
|
1652
|
+
`${this.options.nameProperCase}ModelImpl`,
|
|
1653
|
+
`${this.options.futureType === "complete" ? "KosFutureAwareFull" : "KosFutureAwareMinimal"}<${this.progressType}>`
|
|
1654
|
+
);
|
|
1655
|
+
ensureFileEslintDisable(
|
|
1656
|
+
sf,
|
|
1657
|
+
"@typescript-eslint/no-unsafe-declaration-merging"
|
|
1658
|
+
);
|
|
1659
|
+
});
|
|
1660
|
+
}
|
|
1661
|
+
removeLegacyImports(sf) {
|
|
1662
|
+
for (const decl of sf.getImportDeclarations()) {
|
|
1663
|
+
for (const named of decl.getNamedImports()) {
|
|
1664
|
+
if (LEGACY_IMPORTS.has(named.getName())) named.remove();
|
|
1665
|
+
}
|
|
1666
|
+
if (decl.getNamedImports().length === 0 && !decl.getDefaultImport() && !decl.getNamespaceImport()) {
|
|
1667
|
+
decl.remove();
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
}
|
|
1671
|
+
addImports(sf) {
|
|
1672
|
+
const { internal, futureType, updateServices, nameProperCase } = this.options;
|
|
1673
|
+
const isComplete = futureType === "complete";
|
|
1674
|
+
const sdkSpec = resolveSdkModuleSpecifier(sf);
|
|
1675
|
+
ensureNamedImport(sf, sdkSpec, [
|
|
1676
|
+
{ name: "kosFuture" },
|
|
1677
|
+
{ name: "kosFutureAware" },
|
|
1678
|
+
{
|
|
1679
|
+
name: isComplete ? "KosFutureAwareFull" : "KosFutureAwareMinimal",
|
|
1680
|
+
isTypeOnly: true
|
|
1681
|
+
}
|
|
1682
|
+
]);
|
|
1683
|
+
const typeSpec = internal ? "../../../models/types/future-interfaces" : sdkSpec;
|
|
1684
|
+
ensureNamedImport(sf, typeSpec, [
|
|
1685
|
+
{ name: "ExternalFutureInterface", isTypeOnly: true },
|
|
1686
|
+
...isComplete ? [{ name: "IFutureModel", isTypeOnly: true }] : []
|
|
1687
|
+
]);
|
|
1688
|
+
if (updateServices) {
|
|
1689
|
+
ensureNamedImport(sf, "./services", [
|
|
1690
|
+
{ name: `${nameProperCase}OperationProgress`, isTypeOnly: true }
|
|
1691
|
+
]);
|
|
1692
|
+
}
|
|
1693
|
+
}
|
|
1694
|
+
removeLegacyClassMembers(cls) {
|
|
1695
|
+
for (const ctor of cls.getConstructors()) {
|
|
1696
|
+
for (const stmt of ctor.getStatements()) {
|
|
1697
|
+
if (/setup(Complete|Minimal)FutureSupport\s*\(\s*this\s*\)/.test(
|
|
1698
|
+
stmt.getText()
|
|
1699
|
+
)) {
|
|
1700
|
+
stmt.remove();
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
const futureHandler = cls.getProperty("futureHandler");
|
|
1705
|
+
if (futureHandler?.getTypeNode()?.getText().includes("FutureAwareContainer")) {
|
|
1706
|
+
futureHandler.remove();
|
|
1707
|
+
}
|
|
1708
|
+
const future = cls.getProperty("future");
|
|
1709
|
+
if (future?.getTypeNode()?.getText().includes("IFutureModel")) {
|
|
1710
|
+
future.remove();
|
|
1711
|
+
}
|
|
1712
|
+
const impls = cls.getImplements();
|
|
1713
|
+
for (let i = impls.length - 1; i >= 0; i--) {
|
|
1714
|
+
const base = impls[i].getText().split("<")[0].trim();
|
|
1715
|
+
if (LEGACY_IMPLEMENTS.has(base)) cls.removeImplements(i);
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1718
|
+
addDecorator(cls) {
|
|
1719
|
+
const argsText = this.options.futureType === "complete" ? "" : `{ mode: "minimal" }`;
|
|
1720
|
+
addClassDecorator(cls, "kosFutureAware", { argsText });
|
|
1721
|
+
}
|
|
1722
|
+
updatePublicType(sf) {
|
|
1723
|
+
const { nameProperCase } = this.options;
|
|
1724
|
+
const alias = sf.getTypeAlias(`${nameProperCase}Model`);
|
|
1725
|
+
if (!alias) return;
|
|
1726
|
+
const text = alias.getTypeNode()?.getText() ?? "";
|
|
1727
|
+
if (!text.includes(`PublicModelInterface<${nameProperCase}ModelImpl>`) || text.includes("ExternalFutureInterface")) {
|
|
1728
|
+
return;
|
|
1729
|
+
}
|
|
1730
|
+
alias.setType(
|
|
1731
|
+
`PublicModelInterface<${nameProperCase}ModelImpl> & ExternalFutureInterface<${this.progressType}>`
|
|
1732
|
+
);
|
|
1733
|
+
}
|
|
1734
|
+
addFutureMethod(cls) {
|
|
1735
|
+
const { nameProperCase } = this.options;
|
|
1736
|
+
const hasFutureMethod = cls.getMethods().some((m) => m.getDecorator("kosFuture"));
|
|
1737
|
+
if (hasFutureMethod || cls.getMethod("performLongRunningOperation")) return;
|
|
1738
|
+
cls.addMethod({
|
|
1739
|
+
name: "performLongRunningOperation",
|
|
1740
|
+
isAsync: true,
|
|
1741
|
+
returnType: "Promise<void>",
|
|
1742
|
+
decorators: [{ name: "kosFuture", arguments: [] }],
|
|
1743
|
+
docs: [
|
|
1744
|
+
{
|
|
1745
|
+
description: "Placeholder method for Future operations\nReplace this with your actual long-running operation"
|
|
1746
|
+
}
|
|
1747
|
+
],
|
|
1748
|
+
statements: [
|
|
1749
|
+
"// TODO: Implement your long-running operation here",
|
|
1750
|
+
"// This method should use a service that returns a Future for progress tracking",
|
|
1751
|
+
"",
|
|
1752
|
+
"this.logger.debug(`Starting long-running operation for ${this.id}`);",
|
|
1753
|
+
"",
|
|
1754
|
+
"// Example implementation pattern using services:",
|
|
1755
|
+
`// import { perform${nameProperCase}Operation } from './services';`,
|
|
1756
|
+
"//",
|
|
1757
|
+
`// const future = await perform${nameProperCase}Operation();`,
|
|
1758
|
+
"// return this.futureHandler.setFuture(future);",
|
|
1759
|
+
"",
|
|
1760
|
+
"// Placeholder that doesn't actually do anything",
|
|
1761
|
+
"await new Promise((resolve) => setTimeout(resolve, 1000));",
|
|
1762
|
+
"",
|
|
1763
|
+
"this.logger.debug(`Completed long-running operation for ${this.id}`);"
|
|
1764
|
+
]
|
|
1765
|
+
});
|
|
1766
|
+
}
|
|
1767
|
+
addOnFutureUpdateMethod(cls) {
|
|
1768
|
+
if (cls.getMethod("onFutureUpdate")) return;
|
|
1769
|
+
cls.addMethod({
|
|
1770
|
+
name: "onFutureUpdate",
|
|
1771
|
+
hasQuestionToken: true,
|
|
1772
|
+
returnType: "void",
|
|
1773
|
+
parameters: [
|
|
1774
|
+
{ name: "update", type: `IFutureModel<${this.progressType}>` }
|
|
1775
|
+
],
|
|
1776
|
+
docs: [
|
|
1777
|
+
{
|
|
1778
|
+
description: "Optional: Custom Future update handling\nCalled whenever the Future state changes (progress, status, completion, etc.)"
|
|
1779
|
+
}
|
|
1780
|
+
],
|
|
1781
|
+
statements: [
|
|
1782
|
+
"// Add custom Future update logic here",
|
|
1783
|
+
"// Examples:",
|
|
1784
|
+
"// - Log progress milestones",
|
|
1785
|
+
"// - Update derived state based on progress",
|
|
1786
|
+
"// - Handle specific error conditions",
|
|
1787
|
+
"// - Trigger notifications at certain thresholds",
|
|
1788
|
+
"",
|
|
1789
|
+
"this.logger.debug(`Future update for ${this.id}:`, {",
|
|
1790
|
+
" progress: update.progress,",
|
|
1791
|
+
" status: update.status,",
|
|
1792
|
+
" endState: update.endState,",
|
|
1793
|
+
" clientData: update.clientData,",
|
|
1794
|
+
"});"
|
|
1795
|
+
]
|
|
1796
|
+
});
|
|
1797
|
+
}
|
|
1798
|
+
}
|
|
1799
|
+
class ServiceFileTransformer {
|
|
1800
|
+
constructor(codegenFs, options) {
|
|
1801
|
+
this.codegenFs = codegenFs;
|
|
1802
|
+
this.options = options;
|
|
1803
|
+
}
|
|
1804
|
+
codegenFs;
|
|
1805
|
+
options;
|
|
1806
|
+
transform() {
|
|
1314
1807
|
const { servicesFilePath } = this.options;
|
|
1315
1808
|
if (!servicesFilePath || !this.codegenFs.exists(servicesFilePath)) {
|
|
1316
1809
|
this.createServicesFile();
|
|
@@ -1483,9 +1976,16 @@ class RegistrationFileTransformer {
|
|
|
1483
1976
|
logger.warn("Registration file not found, skipping registration updates");
|
|
1484
1977
|
return;
|
|
1485
1978
|
}
|
|
1486
|
-
|
|
1979
|
+
const original = this.codegenFs.read(registrationFilePath);
|
|
1980
|
+
let content = original;
|
|
1487
1981
|
content = this.addTypeCast(content);
|
|
1488
1982
|
content = this.updateDocumentation(content);
|
|
1983
|
+
if (content === original) {
|
|
1984
|
+
logger.info(
|
|
1985
|
+
"Registration file has no legacy future patterns — leaving it untouched"
|
|
1986
|
+
);
|
|
1987
|
+
return;
|
|
1988
|
+
}
|
|
1489
1989
|
this.codegenFs.write(registrationFilePath, content);
|
|
1490
1990
|
}
|
|
1491
1991
|
addTypeCast(content) {
|
|
@@ -1553,7 +2053,7 @@ function addFutureToModel(codegenFs, options, projects) {
|
|
|
1553
2053
|
}
|
|
1554
2054
|
if (normalized.registrationFilePath) {
|
|
1555
2055
|
logger.info(
|
|
1556
|
-
`Would
|
|
2056
|
+
`Would update registration file (only if legacy patterns are present): ${normalized.registrationFilePath}`
|
|
1557
2057
|
);
|
|
1558
2058
|
}
|
|
1559
2059
|
return;
|
|
@@ -1604,191 +2104,6 @@ function addFutureToModel(codegenFs, options, projects) {
|
|
|
1604
2104
|
throw error;
|
|
1605
2105
|
}
|
|
1606
2106
|
}
|
|
1607
|
-
function resolveModelFilePath(codegenFs, query, projects) {
|
|
1608
|
-
const kosConfig = getKosProjectConfiguration(
|
|
1609
|
-
codegenFs,
|
|
1610
|
-
query.modelProject,
|
|
1611
|
-
projects
|
|
1612
|
-
);
|
|
1613
|
-
const internal = !!kosConfig?.generator?.internal;
|
|
1614
|
-
const project = findProjectByName(
|
|
1615
|
-
codegenFs.root,
|
|
1616
|
-
query.modelProject,
|
|
1617
|
-
projects
|
|
1618
|
-
);
|
|
1619
|
-
const sourceRoot = project ? project.sourceRoot || path.join(project.root, "src") : void 0;
|
|
1620
|
-
if (query.modelPath) {
|
|
1621
|
-
return { modelFilePath: query.modelPath, internal, sourceRoot };
|
|
1622
|
-
}
|
|
1623
|
-
if (!project) {
|
|
1624
|
-
throw new Error(
|
|
1625
|
-
`Project not found: ${query.modelProject}. Ensure a project.json exists.`
|
|
1626
|
-
);
|
|
1627
|
-
}
|
|
1628
|
-
const { modelNameDashCase } = normalizeAllValues({
|
|
1629
|
-
modelName: query.modelName
|
|
1630
|
-
});
|
|
1631
|
-
const modelLocation = kosConfig?.generator?.defaults?.model?.folder || "";
|
|
1632
|
-
const modelFilePath = path.join(
|
|
1633
|
-
sourceRoot,
|
|
1634
|
-
modelLocation,
|
|
1635
|
-
modelNameDashCase,
|
|
1636
|
-
`${modelNameDashCase}-model.ts`
|
|
1637
|
-
);
|
|
1638
|
-
return { modelFilePath, internal, sourceRoot };
|
|
1639
|
-
}
|
|
1640
|
-
function transformSourceFile(codegenFs, filePath, mutate) {
|
|
1641
|
-
const content = codegenFs.read(filePath);
|
|
1642
|
-
if (content === null) {
|
|
1643
|
-
throw new Error(`File not found: ${filePath}`);
|
|
1644
|
-
}
|
|
1645
|
-
const project = new Project({
|
|
1646
|
-
useInMemoryFileSystem: true,
|
|
1647
|
-
manipulationSettings: {
|
|
1648
|
-
indentationText: IndentationText.TwoSpaces,
|
|
1649
|
-
quoteKind: QuoteKind.Double
|
|
1650
|
-
}
|
|
1651
|
-
});
|
|
1652
|
-
const sourceFile = project.createSourceFile(filePath, content, {
|
|
1653
|
-
overwrite: true
|
|
1654
|
-
});
|
|
1655
|
-
mutate(sourceFile);
|
|
1656
|
-
codegenFs.write(filePath, sourceFile.getFullText());
|
|
1657
|
-
}
|
|
1658
|
-
function ensureNamedImport(sourceFile, moduleSpecifier, names) {
|
|
1659
|
-
const decls = sourceFile.getImportDeclarations().filter((d) => d.getModuleSpecifierValue() === moduleSpecifier);
|
|
1660
|
-
const existing = /* @__PURE__ */ new Set();
|
|
1661
|
-
for (const d of decls) {
|
|
1662
|
-
for (const n of d.getNamedImports()) existing.add(n.getName());
|
|
1663
|
-
}
|
|
1664
|
-
let target = decls.find((d) => !d.isTypeOnly());
|
|
1665
|
-
if (!target) {
|
|
1666
|
-
target = sourceFile.addImportDeclaration({ moduleSpecifier });
|
|
1667
|
-
}
|
|
1668
|
-
for (const { name, isTypeOnly } of names) {
|
|
1669
|
-
if (existing.has(name)) continue;
|
|
1670
|
-
target.addNamedImport({ name, isTypeOnly: !!isTypeOnly });
|
|
1671
|
-
existing.add(name);
|
|
1672
|
-
}
|
|
1673
|
-
}
|
|
1674
|
-
function resolveSdkModuleSpecifier(sourceFile) {
|
|
1675
|
-
const decl = sourceFile.getImportDeclarations().find((d) => d.getNamedImports().some((n) => n.getName() === "kosModel"));
|
|
1676
|
-
return decl?.getModuleSpecifierValue() ?? "@kosdev-code/kos-ui-sdk";
|
|
1677
|
-
}
|
|
1678
|
-
function getModelClass(sourceFile, preferName) {
|
|
1679
|
-
const classes = sourceFile.getClasses();
|
|
1680
|
-
const impl = classes.find((c) => /ModelImpl$/.test(c.getName() ?? ""));
|
|
1681
|
-
if (impl) return impl;
|
|
1682
|
-
const exported = classes.find((c) => c.isExported());
|
|
1683
|
-
if (exported) return exported;
|
|
1684
|
-
if (classes.length > 0) return classes[0];
|
|
1685
|
-
throw new Error("No class declaration found in model file.");
|
|
1686
|
-
}
|
|
1687
|
-
function addClassDecorator(cls, name, opts) {
|
|
1688
|
-
if (cls.getDecorator(name)) return;
|
|
1689
|
-
const typeArgs = opts?.typeArgs?.length ? `<${opts.typeArgs.join(", ")}>` : "";
|
|
1690
|
-
const args = opts?.argsText ?? "";
|
|
1691
|
-
const decorators = cls.getDecorators();
|
|
1692
|
-
const kosModelIdx = decorators.findIndex((d) => d.getName() === "kosModel");
|
|
1693
|
-
const insertIdx = kosModelIdx >= 0 ? kosModelIdx + 1 : decorators.length;
|
|
1694
|
-
cls.insertDecorator(insertIdx, {
|
|
1695
|
-
name: `${name}${typeArgs}`,
|
|
1696
|
-
arguments: args ? [args] : []
|
|
1697
|
-
});
|
|
1698
|
-
}
|
|
1699
|
-
function ensureDeclarationMerge(sourceFile, interfaceName, extendsExpr, typeParameters = []) {
|
|
1700
|
-
const baseType = extendsExpr.split("<")[0].trim();
|
|
1701
|
-
let iface = sourceFile.getInterface(interfaceName);
|
|
1702
|
-
if (iface) {
|
|
1703
|
-
const already = iface.getExtends().some((e) => e.getText().split("<")[0].trim() === baseType);
|
|
1704
|
-
if (!already) iface.addExtends(extendsExpr);
|
|
1705
|
-
return;
|
|
1706
|
-
}
|
|
1707
|
-
iface = sourceFile.addInterface({
|
|
1708
|
-
name: interfaceName,
|
|
1709
|
-
isExported: true,
|
|
1710
|
-
typeParameters,
|
|
1711
|
-
extends: [extendsExpr]
|
|
1712
|
-
});
|
|
1713
|
-
sourceFile.insertText(
|
|
1714
|
-
iface.getStart(),
|
|
1715
|
-
"// eslint-disable-next-line @typescript-eslint/no-empty-interface\n"
|
|
1716
|
-
);
|
|
1717
|
-
}
|
|
1718
|
-
function ensureFileEslintDisable(sourceFile, rule) {
|
|
1719
|
-
if (sourceFile.getFullText().includes(rule)) return;
|
|
1720
|
-
sourceFile.insertText(0, `/* eslint-disable ${rule} */
|
|
1721
|
-
`);
|
|
1722
|
-
}
|
|
1723
|
-
function addDecoratedMethod(cls, spec) {
|
|
1724
|
-
if (cls.getMethod(spec.name)) return false;
|
|
1725
|
-
cls.addMethod({
|
|
1726
|
-
name: spec.name,
|
|
1727
|
-
isAsync: spec.isAsync,
|
|
1728
|
-
returnType: spec.returnType,
|
|
1729
|
-
parameters: spec.parameters?.map((p) => {
|
|
1730
|
-
return { name: p.name, type: p.type };
|
|
1731
|
-
}),
|
|
1732
|
-
statements: spec.statements,
|
|
1733
|
-
decorators: [
|
|
1734
|
-
{
|
|
1735
|
-
name: spec.decoratorName,
|
|
1736
|
-
arguments: spec.decoratorArgsText ? [spec.decoratorArgsText] : []
|
|
1737
|
-
}
|
|
1738
|
-
]
|
|
1739
|
-
});
|
|
1740
|
-
return true;
|
|
1741
|
-
}
|
|
1742
|
-
function propertyInsertIndex(cls) {
|
|
1743
|
-
const props = cls.getProperties();
|
|
1744
|
-
if (props.length === 0) return 0;
|
|
1745
|
-
return props[props.length - 1].getChildIndex() + 1;
|
|
1746
|
-
}
|
|
1747
|
-
function addPlainProperty(cls, spec) {
|
|
1748
|
-
if (cls.getProperty(spec.name)) return false;
|
|
1749
|
-
cls.insertProperty(propertyInsertIndex(cls), {
|
|
1750
|
-
name: spec.name,
|
|
1751
|
-
type: spec.type,
|
|
1752
|
-
initializer: spec.initializer,
|
|
1753
|
-
isReadonly: !!spec.readonly,
|
|
1754
|
-
scope: spec.scope ? SCOPE_MAP[spec.scope] : void 0,
|
|
1755
|
-
hasExclamationToken: spec.initializer ? false : !!spec.hasExclamation
|
|
1756
|
-
});
|
|
1757
|
-
return true;
|
|
1758
|
-
}
|
|
1759
|
-
const SCOPE_MAP = {
|
|
1760
|
-
private: Scope.Private,
|
|
1761
|
-
protected: Scope.Protected,
|
|
1762
|
-
public: Scope.Public
|
|
1763
|
-
};
|
|
1764
|
-
function addDecoratedProperty(cls, spec) {
|
|
1765
|
-
if (cls.getProperty(spec.name)) return false;
|
|
1766
|
-
cls.insertProperty(propertyInsertIndex(cls), {
|
|
1767
|
-
name: spec.name,
|
|
1768
|
-
type: spec.type,
|
|
1769
|
-
initializer: spec.initializer,
|
|
1770
|
-
scope: spec.scope ? SCOPE_MAP[spec.scope] : void 0,
|
|
1771
|
-
hasExclamationToken: spec.initializer ? false : !!spec.hasExclamation,
|
|
1772
|
-
decorators: [
|
|
1773
|
-
spec.bare && !spec.decoratorArgsText ? { name: spec.decoratorName } : {
|
|
1774
|
-
name: spec.decoratorName,
|
|
1775
|
-
arguments: spec.decoratorArgsText ? [spec.decoratorArgsText] : []
|
|
1776
|
-
}
|
|
1777
|
-
]
|
|
1778
|
-
});
|
|
1779
|
-
return true;
|
|
1780
|
-
}
|
|
1781
|
-
function addGetter(cls, spec) {
|
|
1782
|
-
if (cls.getGetAccessor(spec.name)) return false;
|
|
1783
|
-
const ctor = cls.getConstructors()[0];
|
|
1784
|
-
const index = ctor ? ctor.getChildIndex() + 1 : propertyInsertIndex(cls);
|
|
1785
|
-
cls.insertGetAccessor(index, {
|
|
1786
|
-
name: spec.name,
|
|
1787
|
-
returnType: spec.returnType,
|
|
1788
|
-
statements: spec.statements ?? "// TODO: derive and return the computed value"
|
|
1789
|
-
});
|
|
1790
|
-
return true;
|
|
1791
|
-
}
|
|
1792
2107
|
function buildDecoratorArgs(options) {
|
|
1793
2108
|
const top = [];
|
|
1794
2109
|
if (options.containerProperty) {
|
|
@@ -3055,6 +3370,8 @@ export {
|
|
|
3055
3370
|
PLUGIN_TYPES,
|
|
3056
3371
|
PluginHandlerFactory,
|
|
3057
3372
|
TrackingFileSystem,
|
|
3373
|
+
UPDATE_RELEASE_VERSION_SCRIPT,
|
|
3374
|
+
UPDATE_RELEASE_VERSION_SCRIPT_PATH,
|
|
3058
3375
|
ValidationError,
|
|
3059
3376
|
addChildToModel,
|
|
3060
3377
|
addComputedToModel,
|
|
@@ -3062,17 +3379,23 @@ export {
|
|
|
3062
3379
|
addContainerSupportToModel,
|
|
3063
3380
|
addDependencyToModel,
|
|
3064
3381
|
addFutureToModel,
|
|
3382
|
+
addJavaArtifactToManifests,
|
|
3065
3383
|
addKosModelConfiguration,
|
|
3066
3384
|
addModelEffectToModel,
|
|
3067
3385
|
addPropertyToModel,
|
|
3068
3386
|
addServiceRequestToModel,
|
|
3069
3387
|
addTopicHandlerToModel,
|
|
3070
3388
|
appendBarrelExport,
|
|
3389
|
+
buildKabTargets,
|
|
3071
3390
|
camelCase,
|
|
3072
3391
|
constantCase,
|
|
3073
3392
|
dashCase,
|
|
3074
3393
|
describeModel,
|
|
3394
|
+
discoverJavaArtifacts,
|
|
3075
3395
|
discoverProjects,
|
|
3396
|
+
discoverUiArtifacts,
|
|
3397
|
+
ensureJavaAggregatorPom,
|
|
3398
|
+
finalizeArchetypeModule,
|
|
3076
3399
|
findProjectByName,
|
|
3077
3400
|
findProjectForPath,
|
|
3078
3401
|
formatFiles,
|
|
@@ -3084,6 +3407,7 @@ export {
|
|
|
3084
3407
|
generateHook,
|
|
3085
3408
|
generateInit,
|
|
3086
3409
|
generateModel,
|
|
3410
|
+
generatePolyglotWorkspace,
|
|
3087
3411
|
generateSplashProject,
|
|
3088
3412
|
getCodegenLogger,
|
|
3089
3413
|
getCurrentDirectoryName,
|
|
@@ -3099,7 +3423,9 @@ export {
|
|
|
3099
3423
|
properCase,
|
|
3100
3424
|
readJson,
|
|
3101
3425
|
readNxJson,
|
|
3426
|
+
resolveModelFilePath,
|
|
3102
3427
|
setCodegenLogger,
|
|
3428
|
+
syncCiManifests,
|
|
3103
3429
|
updateJson,
|
|
3104
3430
|
updateModelIndex,
|
|
3105
3431
|
validateModel,
|