@kosdev-code/kos-codegen-core 0.1.0-next.792 → 0.1.0-next.797

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.
Files changed (35) hide show
  1. package/index.d.ts +2 -2
  2. package/index.d.ts.map +1 -1
  3. package/index.js +397 -0
  4. package/index.js.map +1 -1
  5. package/index.mjs +397 -0
  6. package/index.mjs.map +1 -1
  7. package/lib/generators/ci-sync.d.ts +26 -0
  8. package/lib/generators/ci-sync.d.ts.map +1 -0
  9. package/lib/generators/generate-polyglot-workspace.d.ts +38 -0
  10. package/lib/generators/generate-polyglot-workspace.d.ts.map +1 -0
  11. package/lib/generators/index.d.ts +5 -0
  12. package/lib/generators/index.d.ts.map +1 -1
  13. package/lib/generators/java-workspace.d.ts +33 -0
  14. package/lib/generators/java-workspace.d.ts.map +1 -0
  15. package/lib/generators/kab-targets.d.ts +40 -0
  16. package/lib/generators/kab-targets.d.ts.map +1 -0
  17. package/lib/generators/release-version-script.d.ts +10 -0
  18. package/lib/generators/release-version-script.d.ts.map +1 -0
  19. package/package.json +2 -2
  20. package/templates/polyglot-workspace/build/build-java.sh.template +18 -0
  21. package/templates/polyglot-workspace/build/build-release.sh.template +11 -0
  22. package/templates/polyglot-workspace/build/build-ui.sh.template +23 -0
  23. package/templates/polyglot-workspace/build/docker-build.sh.template +55 -0
  24. package/templates/polyglot-workspace/build/jdkw.sh.template +93 -0
  25. package/templates/polyglot-workspace/build/nodew.sh.template +73 -0
  26. package/templates/polyglot-workspace/build/release_version_prebuild.sh.template +34 -0
  27. package/templates/polyglot-workspace/github/build-java.json.template +6 -0
  28. package/templates/polyglot-workspace/github/build-release.json.template +14 -0
  29. package/templates/polyglot-workspace/github/build-ui.json.template +13 -0
  30. package/templates/polyglot-workspace/github/workflows/develop-java.yml.template +35 -0
  31. package/templates/polyglot-workspace/github/workflows/develop-ui.yml.template +38 -0
  32. package/templates/polyglot-workspace/github/workflows/release.yml.template +37 -0
  33. package/templates/polyglot-workspace/java/README.md.template +36 -0
  34. package/templates/polyglot-workspace/root/.gitignore.template +5 -0
  35. package/templates/polyglot-workspace/root/README.md.template +71 -0
package/index.mjs CHANGED
@@ -515,6 +515,296 @@ 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 hasUi = (options.type ?? "polyglot") !== "java";
527
+ const normalized = normalizeAllValues({ name: options.name });
528
+ const vars = {
529
+ ...normalized,
530
+ hasUi,
531
+ keyset: options.keyset || "prod.kos",
532
+ appUiName: `${normalized.nameDashCase}-ui`,
533
+ nodeVersion: options.nodeVersion || process.version.replace(/^v/, ""),
534
+ jdkMajor: options.jdkMajor || "17",
535
+ mavenVersion: options.mavenVersion || "3.9.9"
536
+ };
537
+ generateFilesFromTemplates(
538
+ codegenFs,
539
+ path.join(templateDir, "root"),
540
+ ".",
541
+ vars
542
+ );
543
+ generateFilesFromTemplates(
544
+ codegenFs,
545
+ path.join(templateDir, "build"),
546
+ "build",
547
+ vars
548
+ );
549
+ generateFilesFromTemplates(
550
+ codegenFs,
551
+ path.join(templateDir, "github"),
552
+ ".github",
553
+ vars
554
+ );
555
+ generateFilesFromTemplates(
556
+ codegenFs,
557
+ path.join(templateDir, "java"),
558
+ "java",
559
+ vars
560
+ );
561
+ return { executablePaths: [...BUILD_SCRIPTS] };
562
+ }
563
+ const UI_PROJECT_DIRS = [
564
+ "apps",
565
+ "libs",
566
+ "plugins",
567
+ "splash",
568
+ "themes",
569
+ "content",
570
+ "translations"
571
+ ];
572
+ function joinArtifactPath(outputPath, fileName) {
573
+ return `${outputPath.replace(/\/+$/, "")}/${fileName}`;
574
+ }
575
+ function discoverUiArtifacts(codegenFs) {
576
+ const artifacts = [];
577
+ for (const dir of UI_PROJECT_DIRS) {
578
+ for (const file of codegenFs.listFiles(`ui/${dir}`)) {
579
+ if (!file.endsWith("project.json")) continue;
580
+ const raw = codegenFs.read(file);
581
+ if (raw === null) continue;
582
+ let project;
583
+ try {
584
+ project = JSON.parse(raw);
585
+ } catch {
586
+ continue;
587
+ }
588
+ const name = project.name;
589
+ if (!name) continue;
590
+ const kabOptions = project.targets?.kab?.options;
591
+ if (kabOptions?.outputPath && kabOptions?.kabName) {
592
+ artifacts.push({
593
+ id: name,
594
+ filename: `ui/${joinArtifactPath(kabOptions.outputPath, kabOptions.kabName)}`
595
+ });
596
+ } else if (project.targets?.splash) {
597
+ artifacts.push({
598
+ id: name,
599
+ filename: `ui/dist/archives/packages/${name}/${name}.kab`,
600
+ layer: 1
601
+ });
602
+ }
603
+ }
604
+ }
605
+ for (const file of codegenFs.listFiles("ui/external")) {
606
+ if (!file.endsWith(".kab")) continue;
607
+ const base = file.slice(file.lastIndexOf("/") + 1, -".kab".length);
608
+ artifacts.push({ id: base, filename: file });
609
+ }
610
+ return artifacts;
611
+ }
612
+ function discoverJavaArtifacts(codegenFs) {
613
+ const aggregator = codegenFs.read("java/pom.xml");
614
+ if (aggregator === null) return [];
615
+ const artifacts = [];
616
+ for (const match of aggregator.matchAll(/<module>([^<]+)<\/module>/g)) {
617
+ const moduleDir = match[1];
618
+ const pom = codegenFs.read(`java/${moduleDir}/pom.xml`);
619
+ if (pom === null || !pom.includes("kos-kab-maven-plugin")) continue;
620
+ const withoutParent = pom.replace(/<parent>[\s\S]*?<\/parent>/, "");
621
+ const artifactId = withoutParent.match(
622
+ /<artifactId>([^<]+)<\/artifactId>/
623
+ )?.[1];
624
+ if (!artifactId) continue;
625
+ artifacts.push({
626
+ id: moduleDir,
627
+ // eslint-disable-next-line no-template-curly-in-string
628
+ filename: `java/${moduleDir}/target/${artifactId}-\${KOS_STD_VERSION_REGEX}.kab`
629
+ });
630
+ }
631
+ return artifacts;
632
+ }
633
+ function syncManifest(codegenFs, manifestPath, discovered, prune) {
634
+ const raw = codegenFs.read(manifestPath);
635
+ if (raw === null) return null;
636
+ const manifest = JSON.parse(raw);
637
+ const existing = manifest.artifacts ?? [];
638
+ const byFilename = new Map(discovered.map((d) => [d.filename, d]));
639
+ const kept = [];
640
+ const stale = [];
641
+ const pruned = [];
642
+ for (const entry of existing) {
643
+ if (byFilename.has(entry.filename)) {
644
+ kept.push(entry);
645
+ byFilename.delete(entry.filename);
646
+ } else if (prune) {
647
+ pruned.push(entry.id ?? entry.filename);
648
+ } else {
649
+ kept.push(entry);
650
+ stale.push(entry.id ?? entry.filename);
651
+ }
652
+ }
653
+ const added = [];
654
+ for (const artifact of byFilename.values()) {
655
+ kept.push({
656
+ id: artifact.id,
657
+ filename: artifact.filename,
658
+ artifactstore: "kos-cdn",
659
+ marketplace: 1,
660
+ ...artifact.layer !== void 0 ? { layer: artifact.layer } : {}
661
+ });
662
+ added.push(artifact.id);
663
+ }
664
+ if (added.length > 0 || pruned.length > 0) {
665
+ manifest.artifacts = kept;
666
+ codegenFs.write(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
667
+ }
668
+ return { added, stale, pruned };
669
+ }
670
+ function syncCiManifests(codegenFs, options = {}) {
671
+ const prune = options.prune ?? false;
672
+ const ui = discoverUiArtifacts(codegenFs);
673
+ const java = discoverJavaArtifacts(codegenFs);
674
+ const manifests = {};
675
+ const plan = [
676
+ [".github/build-ui.json", ui],
677
+ [".github/build-java.json", java],
678
+ [".github/build-release.json", [...ui, ...java]]
679
+ ];
680
+ for (const [manifestPath, discovered] of plan) {
681
+ const result = syncManifest(codegenFs, manifestPath, discovered, prune);
682
+ if (result) {
683
+ manifests[manifestPath] = result;
684
+ }
685
+ }
686
+ return { manifests, discovered: { ui, java } };
687
+ }
688
+ function ensureJavaAggregatorPom(codegenFs, options) {
689
+ const pomPath = "java/pom.xml";
690
+ const existing = codegenFs.read(pomPath);
691
+ if (existing === null) {
692
+ codegenFs.write(
693
+ pomPath,
694
+ `<?xml version="1.0" encoding="UTF-8"?>
695
+ <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">
696
+ <modelVersion>4.0.0</modelVersion>
697
+ <groupId>${options.groupId}</groupId>
698
+ <artifactId>${options.artifactId}</artifactId>
699
+ <version>0.0.0-SNAPSHOT</version>
700
+ <packaging>pom</packaging>
701
+ <modules>
702
+ <module>${options.moduleName}</module>
703
+ </modules>
704
+ </project>
705
+ `
706
+ );
707
+ return;
708
+ }
709
+ if (existing.includes(`<module>${options.moduleName}</module>`)) {
710
+ return;
711
+ }
712
+ codegenFs.write(
713
+ pomPath,
714
+ existing.replace(
715
+ "</modules>",
716
+ ` <module>${options.moduleName}</module>
717
+ </modules>`
718
+ )
719
+ );
720
+ }
721
+ function finalizeArchetypeModule(codegenFs, options) {
722
+ const { moduleName, kosVersion, kabPluginVersion, apiInfoVersion } = options;
723
+ const notes = [];
724
+ const pomPath = `java/${moduleName}/pom.xml`;
725
+ let pom = codegenFs.read(pomPath);
726
+ if (pom === null) {
727
+ throw new Error(`Generated module pom not found: ${pomPath}`);
728
+ }
729
+ if (pom.includes("<kos.version>0.0.0-SNAPSHOT</kos.version>")) {
730
+ if (kosVersion) {
731
+ pom = pom.replace(
732
+ "<kos.version>0.0.0-SNAPSHOT</kos.version>",
733
+ `<kos.version>${kosVersion}</kos.version>`
734
+ );
735
+ } else {
736
+ notes.push(
737
+ "kos.version is 0.0.0-SNAPSHOT — set it to a released kos-bom version before building"
738
+ );
739
+ }
740
+ }
741
+ if (pom.includes("${kos-kab-maven-plugin.version}") && !pom.includes("<kos-kab-maven-plugin.version>")) {
742
+ if (kabPluginVersion) {
743
+ pom = pom.replace(
744
+ /(<kos\.version>[^<]*<\/kos\.version>)/,
745
+ `$1
746
+ <kos-kab-maven-plugin.version>${kabPluginVersion}</kos-kab-maven-plugin.version>`
747
+ );
748
+ } else {
749
+ notes.push(
750
+ "the ${kos-kab-maven-plugin.version} property is referenced but undefined — add it before building"
751
+ );
752
+ }
753
+ }
754
+ const unversionedApiInfo = /<artifactId>api-info<\/artifactId>(\s*)<\/dependency>/;
755
+ if (unversionedApiInfo.test(pom)) {
756
+ if (apiInfoVersion) {
757
+ pom = pom.replace(
758
+ unversionedApiInfo,
759
+ `<artifactId>api-info</artifactId>$1 <version>${apiInfoVersion}</version>$1</dependency>`
760
+ );
761
+ } else {
762
+ notes.push(
763
+ "api-info has no version and is not managed by the kos-bom — add one before building"
764
+ );
765
+ }
766
+ }
767
+ codegenFs.write(pomPath, pom);
768
+ const githubDir = `java/${moduleName}/github`;
769
+ if (codegenFs.exists(githubDir)) {
770
+ for (const file of codegenFs.listFiles(githubDir)) {
771
+ codegenFs.delete(file);
772
+ }
773
+ }
774
+ const gitignore = codegenFs.read(`java/${moduleName}/gitignore`);
775
+ if (gitignore !== null) {
776
+ codegenFs.write(`java/${moduleName}/.gitignore`, gitignore);
777
+ codegenFs.delete(`java/${moduleName}/gitignore`);
778
+ }
779
+ return notes;
780
+ }
781
+ function addJavaArtifactToManifests(codegenFs, options) {
782
+ const { moduleName } = options;
783
+ for (const manifestPath of [
784
+ ".github/build-java.json",
785
+ ".github/build-release.json"
786
+ ]) {
787
+ const raw = codegenFs.read(manifestPath);
788
+ if (raw === null) {
789
+ continue;
790
+ }
791
+ const manifest = JSON.parse(raw);
792
+ manifest.artifacts = manifest.artifacts ?? [];
793
+ if (manifest.artifacts.some(
794
+ (artifact) => artifact.id === moduleName
795
+ )) {
796
+ continue;
797
+ }
798
+ manifest.artifacts.push({
799
+ id: moduleName,
800
+ // eslint-disable-next-line no-template-curly-in-string
801
+ filename: `java/${moduleName}/target/${moduleName}-\${KOS_STD_VERSION_REGEX}.kab`,
802
+ artifactstore: "kos-cdn",
803
+ marketplace: 1
804
+ });
805
+ codegenFs.write(manifestPath, JSON.stringify(manifest, null, 2) + "\n");
806
+ }
807
+ }
518
808
  function normalizeOptions(codegenFs, options, projects) {
519
809
  const toNormalize = {
520
810
  name: options.name
@@ -560,6 +850,103 @@ function normalizeOptions(codegenFs, options, projects) {
560
850
  template: ""
561
851
  };
562
852
  }
853
+ const UPDATE_RELEASE_VERSION_SCRIPT_PATH = "tools/scripts/update-release-version.mjs";
854
+ function buildKabTargets(options) {
855
+ const {
856
+ name,
857
+ archiveDir = "packages",
858
+ descriptorDir,
859
+ buildTarget = "build"
860
+ } = options;
861
+ const outputPath = `dist/archives/${archiveDir}/${name}/`;
862
+ const targets = {
863
+ kab: {
864
+ command: `node tools/scripts/kabtool.mjs build ${name} && node tools/scripts/kabtool.mjs list ${name} `,
865
+ options: {
866
+ outputPath,
867
+ zipName: "ui.zip",
868
+ kabName: `${name}.kab`
869
+ },
870
+ dependsOn: ["zip"]
871
+ },
872
+ zip: {
873
+ command: `node tools/scripts/archiver.js ${name}`,
874
+ options: {
875
+ outputPath,
876
+ zipName: "ui.zip"
877
+ },
878
+ dependsOn: descriptorDir ? [buildTarget, "descriptor"] : [buildTarget]
879
+ }
880
+ };
881
+ if (descriptorDir) {
882
+ targets.descriptor = {
883
+ command: `node tools/scripts/descriptor.mjs ${name}`,
884
+ options: {
885
+ outputPath: `dist/${descriptorDir}`,
886
+ fileName: "descriptor.json"
887
+ },
888
+ dependsOn: ["build"]
889
+ };
890
+ }
891
+ targets.version = {
892
+ command: `node ${UPDATE_RELEASE_VERSION_SCRIPT_PATH} ${name} {args.ver}`,
893
+ options: {},
894
+ dependsOn: []
895
+ };
896
+ return targets;
897
+ }
898
+ const UPDATE_RELEASE_VERSION_SCRIPT = `import devkit from "@nx/devkit";
899
+ import { resolve } from "path";
900
+ import { readFileSync, writeFileSync } from "fs";
901
+ import prettier from "prettier";
902
+
903
+ // KOS artifact versioning: stamps the project's .kos.json "version" field
904
+ // (which kabtool bakes into the KAB). Never touches package.json.
905
+ // Driven by tag-based releases:
906
+ // nx run-many --target=version --args=--ver=$KOSBUILD_VERSION
907
+
908
+ const { readCachedProjectGraph } = devkit;
909
+ const [, , name, versionArg] = process.argv;
910
+
911
+ // "{args.ver}" arrives literally when the target runs without --args=--ver=<v>;
912
+ // treat that (or a missing arg) as "report current version, change nothing".
913
+ const version =
914
+ versionArg && !versionArg.startsWith("{args") ? versionArg : undefined;
915
+
916
+ if (!name) {
917
+ console.error("usage: update-release-version.mjs <project> <version>");
918
+ process.exit(1);
919
+ }
920
+
921
+ const graph = readCachedProjectGraph();
922
+ const project = graph.nodes[name];
923
+ if (!project) {
924
+ console.error("Unknown project: " + name);
925
+ process.exit(1);
926
+ }
927
+
928
+ const kosJsonPath = resolve(process.cwd(), project.data.root, ".kos.json");
929
+ let kosJson;
930
+ try {
931
+ kosJson = JSON.parse(readFileSync(kosJsonPath, "utf8"));
932
+ } catch {
933
+ console.error("Missing or invalid .kos.json: " + kosJsonPath);
934
+ process.exit(1);
935
+ }
936
+
937
+ if (!version) {
938
+ console.log(name + ": " + kosJson.version + " (no --ver given; unchanged)");
939
+ process.exit(0);
940
+ }
941
+
942
+ const prettierOptions = await prettier.resolveConfig(kosJsonPath);
943
+ const output = await prettier.format(
944
+ JSON.stringify({ ...kosJson, version }, null, 2),
945
+ { ...prettierOptions, parser: "json" }
946
+ );
947
+ writeFileSync(kosJsonPath, output);
948
+ console.log(name + ": version -> " + version);
949
+ `;
563
950
  function appendBarrelExport(codegenFs, indexPath, exportPath) {
564
951
  const exportLine = `export * from '${exportPath}'`;
565
952
  const content = codegenFs.read(indexPath) ?? "";
@@ -2985,6 +3372,8 @@ export {
2985
3372
  PLUGIN_TYPES,
2986
3373
  PluginHandlerFactory,
2987
3374
  TrackingFileSystem,
3375
+ UPDATE_RELEASE_VERSION_SCRIPT,
3376
+ UPDATE_RELEASE_VERSION_SCRIPT_PATH,
2988
3377
  ValidationError,
2989
3378
  addChildToModel,
2990
3379
  addComputedToModel,
@@ -2992,17 +3381,23 @@ export {
2992
3381
  addContainerSupportToModel,
2993
3382
  addDependencyToModel,
2994
3383
  addFutureToModel,
3384
+ addJavaArtifactToManifests,
2995
3385
  addKosModelConfiguration,
2996
3386
  addModelEffectToModel,
2997
3387
  addPropertyToModel,
2998
3388
  addServiceRequestToModel,
2999
3389
  addTopicHandlerToModel,
3000
3390
  appendBarrelExport,
3391
+ buildKabTargets,
3001
3392
  camelCase,
3002
3393
  constantCase,
3003
3394
  dashCase,
3004
3395
  describeModel,
3396
+ discoverJavaArtifacts,
3005
3397
  discoverProjects,
3398
+ discoverUiArtifacts,
3399
+ ensureJavaAggregatorPom,
3400
+ finalizeArchetypeModule,
3006
3401
  findProjectByName,
3007
3402
  findProjectForPath,
3008
3403
  formatFiles,
@@ -3014,6 +3409,7 @@ export {
3014
3409
  generateHook,
3015
3410
  generateInit,
3016
3411
  generateModel,
3412
+ generatePolyglotWorkspace,
3017
3413
  generateSplashProject,
3018
3414
  getCodegenLogger,
3019
3415
  getCurrentDirectoryName,
@@ -3031,6 +3427,7 @@ export {
3031
3427
  readNxJson,
3032
3428
  resolveModelFilePath,
3033
3429
  setCodegenLogger,
3430
+ syncCiManifests,
3034
3431
  updateJson,
3035
3432
  updateModelIndex,
3036
3433
  validateModel,