@ostack.tech/ui-kform-scaffolder 0.3.2 → 0.3.4

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.
@@ -1,10 +1,11 @@
1
1
  import { jsxs, jsx, Fragment } from "react/jsx-runtime";
2
- import { useConfig, UseTableValuesSerializerConfig as UseTableValuesSerializerConfig$1, addEjsTemplateFile, addTemplateFile, joinPaths, tsFile, code, anySchematicKind as anySchematicKind$1, bigDecimalSchematicKind as bigDecimalSchematicKind$1, bigIntegerSchematicKind as bigIntegerSchematicKind$1, booleanSchematicKind as booleanSchematicKind$1, byteSchematicKind as byteSchematicKind$1, classSchematicKind as classSchematicKind$1, doubleSchematicKind as doubleSchematicKind$1, enumSchematicKind as enumSchematicKind$1, fileSchematicKind as fileSchematicKind$1, floatSchematicKind as floatSchematicKind$1, intSchematicKind as intSchematicKind$1, ListableBuilderWithoutKindSelect, createSchematic, listSchematicKind, localDateSchematicKind as localDateSchematicKind$1, longSchematicKind as longSchematicKind$1, shortSchematicKind as shortSchematicKind$1, stringSchematicKind as stringSchematicKind$1, tableSchematicKind as tableSchematicKind$1, annotate, SchematicBuilder as SchematicBuilder$1, configScaffolder, scaffoldSchemas, scaffoldModels, scaffoldValidator } from "@ostack.tech/kform-scaffolder";
2
+ import { useConfig, UseTableValuesSerializerConfig as UseTableValuesSerializerConfig$1, addEjsTemplateFile, joinPaths, tsFile, code, anySchematicKind as anySchematicKind$1, bigDecimalSchematicKind as bigDecimalSchematicKind$1, bigIntegerSchematicKind as bigIntegerSchematicKind$1, booleanSchematicKind as booleanSchematicKind$1, byteSchematicKind as byteSchematicKind$1, classSchematicKind as classSchematicKind$1, doubleSchematicKind as doubleSchematicKind$1, enumSchematicKind as enumSchematicKind$1, fileSchematicKind as fileSchematicKind$1, floatSchematicKind as floatSchematicKind$1, intSchematicKind as intSchematicKind$1, ListableBuilderWithoutKindSelect, createSchematic, listSchematicKind, localDateSchematicKind as localDateSchematicKind$1, longSchematicKind as longSchematicKind$1, shortSchematicKind as shortSchematicKind$1, stringSchematicKind as stringSchematicKind$1, tableSchematicKind as tableSchematicKind$1, annotate, addTemplateFile, SchematicBuilder as SchematicBuilder$1, configScaffolder, scaffoldSchemas, scaffoldModels, scaffoldValidator } from "@ostack.tech/kform-scaffolder";
3
3
  import { useRef } from "react";
4
4
  import { capitalCase, camelCase, kebabCase, constantCase, sentenceCase, pascalCase } from "change-case";
5
+ const DEFAULT_LOCALE = "en-US";
5
6
  const LOCALES = JSON.parse('["en-GB","en-US","fr","pt"]');
6
7
  function DefaultLocaleConfig({
7
- defaultValue = "en-US",
8
+ defaultValue = DEFAULT_LOCALE,
8
9
  disabled
9
10
  }) {
10
11
  const [config, setConfig] = useConfig("defaultLocale", defaultValue);
@@ -23,8 +24,9 @@ function DefaultLocaleConfig({
23
24
  )
24
25
  ] });
25
26
  }
27
+ const DEFAULT_SERIALIZATION_FORMAT = "json";
26
28
  function SerializationFormatConfig({
27
- defaultValue = "json",
29
+ defaultValue = DEFAULT_SERIALIZATION_FORMAT,
28
30
  disabled
29
31
  }) {
30
32
  const [useTableValuesSerializerConfig, setUseTableValuesSerializerConfig] = useConfig("useTableValuesSerializer", false);
@@ -61,7 +63,10 @@ function SerializationFormatConfig({
61
63
  function UseTableValuesSerializerConfig({
62
64
  disabled
63
65
  }) {
64
- const [serializationFormatConfig] = useConfig("serializationFormat", "json");
66
+ const [serializationFormatConfig] = useConfig(
67
+ "serializationFormat",
68
+ DEFAULT_SERIALIZATION_FORMAT
69
+ );
65
70
  return /* @__PURE__ */ jsx(
66
71
  UseTableValuesSerializerConfig$1,
67
72
  {
@@ -88,17 +93,25 @@ function scaffoldActions(schematic, data) {
88
93
  addEjsTemplateFile(data, "actions/Submit.tsx", submitTsxEjs, ejsData);
89
94
  addEjsTemplateFile(data, "actions/Validate.tsx", validateTsxEjs, ejsData);
90
95
  }
91
- const reportErrorTs = 'export const REPORT_ERROR_ENDPOINT = "/api/report-error";\n';
92
- const submitTsEjs = 'import { LocatedValidationWarning } from "@ostack.tech/kform";\nimport {\n decode<%= formClass %>SubmitResponseFromString,\n encode<%= formClass %>ToString,\n <%= formClass %>,\n} from "<%= kmpModuleName %>";\n\nexport const SUBMIT_ENDPOINT = "/api/submit";\n\nexport async function submit(\n <%= formVar %>: <%= formClass %>,\n acceptedWarnings?: LocatedValidationWarning[],\n) {\n const params = new URLSearchParams();\n if (acceptedWarnings?.length) {\n const acceptedWarningCodes = new Set(acceptedWarnings.map((w) => w.code));\n params.set("acceptedWarnings", Array.from(acceptedWarningCodes).join());\n }\n\n const res = await fetch(`${SUBMIT_ENDPOINT}?${params}`, {\n method: "POST",\n headers: { "Content-Type": "<%= serializationMimeType %>" },\n body: encode<%= formClass %>ToString(<%= formVar %>, import.meta.env.DEV),\n });\n return decode<%= formClass %>SubmitResponseFromString(await res.text());\n}\n';
96
+ const apiFetchTsEjs = 'const API_BASE_URL = new URL("<%= apiBasePath %>", window.location.origin);\n\n/**\n * Wrapper around `fetch` for accessing the API.\n *\n * Configuration common to all API requests should be set here.\n */\nexport function apiFetch(url: string | URL, init?: RequestInit) {\n return fetch(new URL(url, API_BASE_URL), init);\n}\n';
97
+ const reportErrorTsEjs = 'import type { ErrorReport } from "@ostack.tech/ui";\nimport { apiFetch } from "./apiFetch.ts";\n\nconst REPORT_ERROR_API_ENDPOINT = "<%= reportErrorApiEndpoint %>";\n\nexport async function reportError(error: ErrorReport) {\n await apiFetch(REPORT_ERROR_API_ENDPOINT, {\n method: "POST",\n headers: { "Content-Type": "application/json" },\n body: JSON.stringify(error, null, import.meta.env.DEV ? 2 : 0),\n });\n}\n';
98
+ const submitTsEjs = 'import { LocatedValidationWarning } from "@ostack.tech/kform";\nimport {\n decode<%= formClass %>SubmitResponseFromString,\n encode<%= formClass %>ToString,\n <%= formClass %>,\n} from "<%= kmpModuleName %>";\nimport { apiFetch } from "./apiFetch.ts";\n\nconst SUBMIT_API_ENDPOINT = "<%= submitApiEndpoint %>";\n\nexport async function submit(\n <%= formVar %>: <%= formClass %>,\n acceptedWarnings?: LocatedValidationWarning[],\n) {\n const params = new URLSearchParams();\n if (acceptedWarnings?.length) {\n const acceptedWarningCodes = new Set(acceptedWarnings.map((w) => w.code));\n params.set("acceptedWarnings", Array.from(acceptedWarningCodes).join());\n }\n\n const response = await apiFetch(`${SUBMIT_API_ENDPOINT}?${params}`, {\n method: "POST",\n headers: { "Content-Type": "<%= serializationMimeType %>" },\n body: encode<%= formClass %>ToString(<%= formVar %>, import.meta.env.DEV),\n });\n return decode<%= formClass %>SubmitResponseFromString(await response.text());\n}\n';
99
+ const DEFAULT_API_BASE_PATH = "/api/";
100
+ const DEFAULT_REPORT_ERROR_API_ENDPOINT = "report-error";
101
+ const DEFAULT_SUBMIT_API_ENDPOINT = "submit";
93
102
  function scaffoldApi(schematic, data) {
94
103
  const ejsData = {
95
104
  kmpModuleName: data.kmpModuleName ?? `${kebabCase(schematic.name)}-shared`,
96
- serializationFormat: data.serializationFormat ?? "json",
105
+ serializationFormat: data.serializationFormat ?? DEFAULT_SERIALIZATION_FORMAT,
97
106
  serializationMimeType: `application/${data.serializationFormat}`,
98
107
  formVar: camelCase(schematic.name),
99
- formClass: schematic.name
108
+ formClass: schematic.name,
109
+ apiBasePath: data.apiBasePath ?? DEFAULT_API_BASE_PATH,
110
+ reportErrorApiEndpoint: data.reportErrorApiEndpoint ?? DEFAULT_REPORT_ERROR_API_ENDPOINT,
111
+ submitApiEndpoint: data.submitApiEndpoint ?? DEFAULT_SUBMIT_API_ENDPOINT
100
112
  };
101
- addTemplateFile(data, "api/reportError.ts", reportErrorTs);
113
+ addEjsTemplateFile(data, "api/apiFetch.ts", apiFetchTsEjs, ejsData);
114
+ addEjsTemplateFile(data, "api/reportError.ts", reportErrorTsEjs, ejsData);
102
115
  addEjsTemplateFile(data, "api/submit.ts", submitTsEjs, ejsData);
103
116
  }
104
117
  function scaffoldIssueMessages(schematic, data) {
@@ -754,7 +767,7 @@ function scaffoldAppComponent(schematic, data) {
754
767
  scaffoldIssueMessages(schematic, data);
755
768
  }
756
769
  function scaffoldAppComponentFile(schematic, data) {
757
- const localeVar = (data.defaultLocale ?? "en-US").replaceAll("-", "");
770
+ const localeVar = (data.defaultLocale ?? DEFAULT_LOCALE).replaceAll("-", "");
758
771
  data.currentFile.imports.push(
759
772
  { moduleName: "@ostack.tech/kform", name: "ktMapToObject" },
760
773
  { moduleName: "@ostack.tech/ui-kform", name: "FormApp" },
@@ -763,7 +776,7 @@ function scaffoldAppComponentFile(schematic, data) {
763
776
  { moduleName: data.kmpModuleName, name: schematic.name },
764
777
  { moduleName: data.kmpModuleName, name: `${schematic.name}FormMode` },
765
778
  { moduleName: data.kmpModuleName, name: `${schematic.name}Schema` },
766
- { moduleName: `./api/reportError.ts`, name: "REPORT_ERROR_ENDPOINT" },
779
+ { moduleName: `./api/reportError.ts`, name: "reportError" },
767
780
  {
768
781
  moduleName: `./${schematic.name}Context.ts`,
769
782
  name: `use${schematic.name}Context`
@@ -796,7 +809,7 @@ function scaffoldAppComponentFile(schematic, data) {
796
809
  }
797
810
  issueMessages={${constantCase(schematic.name)}_ISSUE_MESSAGES}
798
811
  defaultLocale={${localeVar}}
799
- errorReportingUrl={REPORT_ERROR_ENDPOINT}
812
+ reportError={reportError}
800
813
  >
801
814
  <${schematic.name}Layout />
802
815
  </FormApp>
@@ -963,22 +976,26 @@ function scaffoldExternalContexts(schematic, data) {
963
976
  );
964
977
  }
965
978
  const buildGradleKts = "allprojects {\n repositories { mavenCentral() }\n}\n";
966
- const gradlePropertiesEjs = "group=<%= group %>\nversion=0.0.1\n\norg.gradle.caching=true\norg.gradle.configuration-cache=true\n";
967
- const libsVersionsTomlEjs = '[versions]\n# Plugins\nkotlin = "2.2.20"\nnodeGradle = "7.1.0"\n# Libraries\nkotlinxCoroutines = "1.10.2"\nkform = "<%= kFormVersion %>"\n<%_ if (usesKotlinxDatetime) { -%>\nkotlinxDatetime = "0.7.1"\n<%_ } -%>\n<%_ if (serializationFormat === "json") { -%>\nkotlinxSerialization = "1.9.0"\n<%_ } -%>\n<%_ if (usesKtMath) { -%>\nktMath = "0.10.2"\n<%_ } -%>\nslf4j = "2.0.17"\n<%_ if (serializationFormat === "xml") { -%>\nxmlutil = "0.91.1"\n<%_ } -%>\n# Runtimes\njvmToolchain = "17"\nnodejs = "22.20.0"\n\n[libraries]\nkform = { module = "tech.ostack:kform", version.ref = "kform" }\nkform-jsBindings = { module = "tech.ostack:kform-js-bindings", version.ref = "kform" }\nkotlinxCoroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" }\n<%_ if (usesKotlinxDatetime) { -%>\nkotlinxDatetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }\n<%_ } -%>\n<%_ if (serializationFormat === "json") { -%>\nkotlinxSerialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" }\n<%_ } -%>\n<%_ if (usesKtMath) { -%>\nktMath = { module = "io.github.gciatto:kt-math", version.ref = "ktMath" }\n<%_ } -%>\nslf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }\n<%_ if (serializationFormat === "xml") { -%>\nxmlutil-serialization = { module = "io.github.pdvrieze.xmlutil:serialization", version.ref = "xmlutil" }\n<%_ } -%>\n\n[plugins]\nkotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }\nkotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }\nnodeGradle = { id = "com.github.node-gradle.node", version.ref = "nodeGradle" }\n';
979
+ const gradlePropertiesEjs = "group=<%= gradlePropertiesGroup %>\nversion=0.0.1\n\norg.gradle.caching=true\norg.gradle.configuration-cache=true\n";
980
+ const libsVersionsTomlEjs = '[versions]\n# Plugins\nkotlin = "2.2.21"\nnodeGradle = "7.1.0"\n# Libraries\nkotlinxCoroutines = "1.10.2"\nkform = "<%= kFormVersion %>"\n<%_ if (includeKotlinxDatetime) { -%>\nkotlinxDatetime = "0.7.1"\n<%_ } -%>\n<%_ if (serializationFormat === "json") { -%>\nkotlinxSerialization = "1.9.0"\n<%_ } -%>\n<%_ if (includeKtMath) { -%>\nktMath = "0.10.2"\n<%_ } -%>\nslf4j = "2.0.17"\n<%_ if (serializationFormat === "xml") { -%>\nxmlutil = "0.91.1"\n<%_ } -%>\n# Runtimes\njvmToolchain = "<%= jvmToolchainVersion %>"\nnodejs = "<%= nodejsVersion %>"\n\n[libraries]\nkform = { module = "tech.ostack:kform", version.ref = "kform" }\nkform-jsBindings = { module = "tech.ostack:kform-js-bindings", version.ref = "kform" }\nkotlinxCoroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinxCoroutines" }\n<%_ if (includeKotlinxDatetime) { -%>\nkotlinxDatetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "kotlinxDatetime" }\n<%_ } -%>\n<%_ if (serializationFormat === "json") { -%>\nkotlinxSerialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerialization" }\n<%_ } -%>\n<%_ if (includeKtMath) { -%>\nktMath = { module = "io.github.gciatto:kt-math", version.ref = "ktMath" }\n<%_ } -%>\nslf4j-simple = { module = "org.slf4j:slf4j-simple", version.ref = "slf4j" }\n<%_ if (serializationFormat === "xml") { -%>\nxmlutil-serialization = { module = "io.github.pdvrieze.xmlutil:serialization", version.ref = "xmlutil" }\n<%_ } -%>\n\n[plugins]\nkotlin-multiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" }\nkotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }\nnodeGradle = { id = "com.github.node-gradle.node", version.ref = "nodeGradle" }\n';
968
981
  const reactAppBuildGradleKtsEjs = 'import com.github.gradle.node.npm.task.NpmTask\n\nplugins {\n alias(libs.plugins.nodeGradle)\n base\n}\n\nval isCI = System.getenv("CI") !in arrayOf(null, "0", "false")\nnode {\n download = true\n version = libs.versions.nodejs.get()\n npmInstallCommand = if (isCI) "ci" else "install"\n}\n\nval sharedPackage = project(":shared").file("build/<%= formId %>-shared-$version.tgz")\n\nval npmInstallShared by tasks.registering(NpmTask::class) {\n group = "build"\n dependsOn(":shared:packJsPackage")\n npmCommand = listOf("install", "<%= formId %>-shared@file:$sharedPackage")\n\n inputs.file(sharedPackage)\n outputs.dir("node_modules/<%= formId %>-shared")\n}\n\ntasks.npmInstall {\n dependsOn(npmInstallShared)\n}\n\nval npmRunDev by tasks.registering(NpmTask::class) {\n group = "development"\n dependsOn(tasks.npmInstall)\n npmCommand = listOf("run", "dev")\n}\n\nprivate fun NpmTask.npmRunBuild(buildReason: String) {\n group = "build"\n dependsOn(tasks.npmInstall)\n npmCommand = listOf("run", "build")\n environment = mapOf("VITE_BUILD_REASON" to buildReason)\n\n inputs.dir("src")\n inputs.file(sharedPackage)\n inputs.file("index.html")\n inputs.file("package.json")\n inputs.file("tsconfig.json")\n inputs.file("tsconfig.app.json")\n inputs.file("tsconfig.node.json")\n inputs.file("vite.config.ts")\n outputs.dir("build/dist")\n}\n\nval npmRunBuild by tasks.registering(NpmTask::class) {\n npmRunBuild("production")\n}\n\nval npmRunBuildPreview by tasks.registering(NpmTask::class) {\n npmRunBuild("preview")\n}\n\nval npmRunPreview by tasks.registering(NpmTask::class) {\n group = "development"\n dependsOn(npmRunBuildPreview)\n npmCommand = listOf("run", "preview")\n}\n\nval npmRunLint by tasks.registering(NpmTask::class) {\n group = "verification"\n dependsOn(tasks.npmInstall)\n npmCommand = listOf("run", "lint")\n\n inputs.dir("src")\n inputs.file("eslint.config.js")\n inputs.file("package.json")\n inputs.file("tsconfig.json")\n inputs.file("tsconfig.app.json")\n inputs.file("tsconfig.node.json")\n outputs.upToDateWhen { true }\n}\n\ntasks.assemble {\n dependsOn(npmRunBuild)\n}\n';
969
982
  const settingsGradleKtsEjs = 'plugins {\n id("org.gradle.toolchains.foojay-resolver-convention") version "1.0.0"\n}\n\nrootProject.name = "<%= formId %>"\n\ninclude("shared", "react-app")\n';
970
- const sharedBuildGradleKtsEjs = 'import com.github.gradle.node.npm.task.NpmTask\n\nplugins {\n alias(libs.plugins.kotlin.multiplatform)\n alias(libs.plugins.kotlin.serialization)\n alias(libs.plugins.nodeGradle)\n}\n\nkotlin {\n jvmToolchain(libs.versions.jvmToolchain.get().toInt())\n jvm {\n testRuns["test"].executionTask.configure { useJUnitPlatform() }\n }\n js {\n compilerOptions {\n target = "es2015"\n freeCompilerArgs.add("-Xes-long-as-bigint")\n freeCompilerArgs.add("-Xwarning-level=NON_EXPORTABLE_TYPE:disabled")\n }\n binaries.library()\n browser { testTask { useMocha() } }\n generateTypeScriptDefinitions()\n }\n\n sourceSets {\n all {\n // Opt in to the experimental `JsExport` annotation\n languageSettings.optIn("kotlin.js.ExperimentalJsExport")\n }\n\n commonMain.dependencies {\n api(libs.kform)\n <%_ if (usesKotlinxDatetime) { -%>\n api(libs.kotlinxDatetime)\n <%_ } -%>\n <%_ if (serializationFormat === "json") { -%>\n api(libs.kotlinxSerialization.json)\n <%_ } -%>\n <%_ if (usesKtMath) { -%>\n api(libs.ktMath)\n <%_ } -%>\n <%_ if (serializationFormat === "xml") { -%>\n api(libs.xmlutil.serialization)\n <%_ } -%>\n }\n commonTest.dependencies {\n implementation(kotlin("test"))\n implementation(libs.kotlinxCoroutines.test)\n }\n jvmTest.dependencies {\n implementation(libs.slf4j.simple)\n }\n jsMain.dependencies {\n implementation(libs.kform.jsBindings)\n <%_ if (usesKotlinxDatetime) { -%>\n implementation(npm("@js-joda/timezone", "2.3.0"))\n <%_ } -%>\n }\n }\n}\n\nval isCI = System.getenv("CI") !in arrayOf(null, "0", "false")\nnode {\n download = true\n version = libs.versions.nodejs.get()\n npmInstallCommand = if (isCI) "ci" else "install"\n}\n\n// Packs the result of the JS compilation, for consumption by the React app\nval packJsPackage by tasks.registering(NpmTask::class) {\n group = "build"\n dependsOn("jsBrowserProductionLibraryDistribution")\n\n val libraryDir = "build/dist/js/productionLibrary"\n npmCommand = listOf("pack", libraryDir, "--pack-destination", "build")\n\n inputs.dir(libraryDir)\n outputs.file("build/<%= formId %>-shared-${version}.tgz")\n}\n';
983
+ const sharedBuildGradleKtsEjs = 'import com.github.gradle.node.npm.task.NpmTask\n\nplugins {\n alias(libs.plugins.kotlin.multiplatform)\n alias(libs.plugins.kotlin.serialization)\n alias(libs.plugins.nodeGradle)\n}\n\nkotlin {\n jvmToolchain(libs.versions.jvmToolchain.get().toInt())\n jvm {\n testRuns["test"].executionTask.configure { useJUnitPlatform() }\n }\n js {\n compilerOptions {\n target = "es2015"\n freeCompilerArgs.add("-Xes-long-as-bigint")\n freeCompilerArgs.add("-Xwarning-level=NON_EXPORTABLE_TYPE:disabled")\n }\n binaries.library()\n browser { testTask { useMocha() } }\n generateTypeScriptDefinitions()\n }\n\n sourceSets {\n all {\n // Opt in to the experimental `JsExport` annotation\n languageSettings.optIn("kotlin.js.ExperimentalJsExport")\n }\n\n commonMain.dependencies {\n api(libs.kform)\n <%_ if (includeKotlinxDatetime) { -%>\n api(libs.kotlinxDatetime)\n <%_ } -%>\n <%_ if (serializationFormat === "json") { -%>\n api(libs.kotlinxSerialization.json)\n <%_ } -%>\n <%_ if (includeKtMath) { -%>\n api(libs.ktMath)\n <%_ } -%>\n <%_ if (serializationFormat === "xml") { -%>\n api(libs.xmlutil.serialization)\n <%_ } -%>\n }\n commonTest.dependencies {\n implementation(kotlin("test"))\n implementation(libs.kotlinxCoroutines.test)\n }\n jvmTest.dependencies {\n implementation(libs.slf4j.simple)\n }\n jsMain.dependencies {\n implementation(libs.kform.jsBindings)\n <%_ if (includeKotlinxDatetime) { -%>\n implementation(npm("@js-joda/timezone", "2.3.0"))\n <%_ } -%>\n }\n }\n}\n\nval isCI = System.getenv("CI") !in arrayOf(null, "0", "false")\nnode {\n download = true\n version = libs.versions.nodejs.get()\n npmInstallCommand = if (isCI) "ci" else "install"\n}\n\n// Packs the result of the JS compilation, for consumption by the React app\nval packJsPackage by tasks.registering(NpmTask::class) {\n group = "build"\n dependsOn("jsBrowserProductionLibraryDistribution")\n\n val libraryDir = "build/dist/js/productionLibrary"\n npmCommand = listOf("pack", libraryDir, "--pack-destination", "build")\n\n inputs.dir(libraryDir)\n outputs.file("build/<%= formId %>-shared-${version}.tgz")\n}\n';
971
984
  const jsJodaTimeZoneKtEjs = 'package <%= filePackage %>\n\n// See: https://github.com/Kotlin/kotlinx-datetime?tab=readme-ov-file#note-about-time-zones-in-js\n@JsModule("@js-joda/timezone")\n@JsNonModule\nexternal object JsJodaTimeZoneModule\n\n@JsExport\nval jsJodaTz = JsJodaTimeZoneModule\n';
985
+ const DEFAULT_JVM_TOOLCHAIN_VERSION = "17";
986
+ const DEFAULT_NODEJS_VERSION = "22.20.0";
972
987
  function scaffoldGradleProject(schematic, data) {
973
988
  const ejsData = {
974
- group: data.currentPackage,
989
+ gradlePropertiesGroup: data.gradlePropertiesGroup ?? data.currentPackage,
975
990
  filePackage: data.currentPackage,
976
991
  formId: kebabCase(schematic.name),
977
992
  formTitle: capitalCase(schematic.name),
978
- kFormVersion: "0.31.4",
993
+ kFormVersion: "0.31.5",
979
994
  serializationFormat: data.serializationFormat ?? "json",
980
- usesKotlinxDatetime: usesKotlinxDatetime(schematic, data),
981
- usesKtMath: usesKtMath(schematic)
995
+ includeKotlinxDatetime: data.includeKotlinxDatetime ?? usesKotlinxDatetime(schematic, data),
996
+ includeKtMath: data.includeKtMath ?? usesKtMath(schematic),
997
+ jvmToolchainVersion: data.jvmToolchainVersion ?? DEFAULT_JVM_TOOLCHAIN_VERSION,
998
+ nodejsVersion: data.nodejsVersion ?? DEFAULT_NODEJS_VERSION
982
999
  };
983
1000
  addEjsTemplateFile(data, "gradle.properties", gradlePropertiesEjs, ejsData);
984
1001
  addEjsTemplateFile(
@@ -1000,7 +1017,7 @@ function scaffoldGradleProject(schematic, data) {
1000
1017
  sharedBuildGradleKtsEjs,
1001
1018
  ejsData
1002
1019
  );
1003
- if (ejsData.usesKotlinxDatetime) {
1020
+ if (ejsData.includeKotlinxDatetime) {
1004
1021
  addEjsTemplateFile(
1005
1022
  data,
1006
1023
  "shared/src/jsMain/kotlin/JsJodaTimeZone.kt",
@@ -1513,23 +1530,28 @@ const indexScss = '@use "@ostack.tech/ui/scss" as ostack-ui;\n@use "@ostack.tech
1513
1530
  function scaffoldStyles(_schematic, data) {
1514
1531
  addTemplateFile(data, "index.scss", indexScss);
1515
1532
  }
1516
- const eslintConfigJs = 'import js from "@eslint/js";\nimport { defineConfig, globalIgnores } from "eslint/config";\nimport reactHooks from "eslint-plugin-react-hooks";\nimport reactRefresh from "eslint-plugin-react-refresh";\nimport globals from "globals";\nimport tseslint from "typescript-eslint";\n\nexport default defineConfig([\n globalIgnores([".gradle", "build"]),\n {\n files: ["**/*.{ts,tsx}"],\n extends: [\n js.configs.recommended,\n tseslint.configs.recommended,\n reactHooks.configs["recommended-latest"],\n reactRefresh.configs.vite,\n ],\n languageOptions: {\n ecmaVersion: 2020,\n globals: globals.browser,\n },\n },\n]);\n';
1533
+ const eslintConfigJs = 'import js from "@eslint/js";\nimport { defineConfig, globalIgnores } from "eslint/config";\nimport reactHooks from "eslint-plugin-react-hooks";\nimport reactRefresh from "eslint-plugin-react-refresh";\nimport globals from "globals";\nimport tseslint from "typescript-eslint";\n\nexport default defineConfig([\n globalIgnores([".gradle", "build"]),\n {\n files: ["**/*.{ts,tsx}"],\n extends: [\n js.configs.recommended,\n tseslint.configs.recommended,\n reactHooks.configs.flat.recommended,\n reactRefresh.configs.vite,\n ],\n languageOptions: {\n ecmaVersion: 2020,\n globals: globals.browser,\n },\n },\n]);\n';
1517
1534
  const indexHtmlEjs = '<!doctype html>\n<html lang="en">\n <head>\n <meta charset="UTF-8" />\n <link rel="icon" type="image/svg+xml" href="/vite.svg" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <title><%= formTitle %></title>\n </head>\n <body>\n <div\n id="<%= formId %>-app-root"\n data-external-contexts="<%= externalContextsData %>"\n ></div>\n <script type="module" src="/src/main.tsx"><\/script>\n <script type="module">\n render<%= formClass %>App();\n <\/script>\n </body>\n</html>\n';
1518
1535
  const packageJsonEjs = '{\n "name": "<%= formId %>-react-app",\n "private": true,\n "version": "0.0.0",\n "type": "module",\n "scripts": {\n "dev": "vite",\n "build": "tsc -b && vite build",\n "lint": "eslint .",\n "preview": "vite preview"\n },\n "dependencies": {\n "@fortawesome/fontawesome-svg-core": "<%= dependencyVersions["@fortawesome/fontawesome-svg-core"] %>",\n "@fortawesome/free-regular-svg-icons": "<%= dependencyVersions["@fortawesome/free-regular-svg-icons"] %>",\n "@fortawesome/free-solid-svg-icons": "<%= dependencyVersions["@fortawesome/free-solid-svg-icons"] %>",\n "@ostack.tech/kform-react": "~<%= kFormVersion %>",\n "@ostack.tech/ui": "~<%= ostackUiVersion %>",\n "@ostack.tech/ui-kform": "~<%= ostackUiVersion %>",\n "date-fns": "<%= dependencyVersions["date-fns"] %>",\n "<%= formId %>-shared": "file:../shared/build/<%= formId %>-shared-0.0.1.tgz",\n "react": "<%= dependencyVersions.react %>",\n "react-dom": "<%= dependencyVersions["react-dom"] %>",\n "react-router": "<%= dependencyVersions["react-router"] %>",\n "react-router-dom": "<%= dependencyVersions["react-router-dom"] %>"\n },\n "devDependencies": {\n "@eslint/js": "<%= dependencyVersions["@eslint/js"] %>",\n "@types/node": "<%= dependencyVersions["@types/node"] %>",\n "@types/ostack.tech__kform": "npm:@ostack.tech/kform@~<%= kFormVersion %>",\n "@types/react": "<%= dependencyVersions["@types/react"] %>",\n "@types/react-dom": "<%= dependencyVersions["@types/react-dom"] %>",\n "@vitejs/plugin-react-swc": "<%= dependencyVersions["@vitejs/plugin-react-swc"] %>",\n "eslint": "<%= dependencyVersions.eslint %>",\n "eslint-plugin-react-hooks": "<%= dependencyVersions["eslint-plugin-react-hooks"] %>",\n "eslint-plugin-react-refresh": "<%= dependencyVersions["eslint-plugin-react-refresh"] %>",\n "globals": "<%= dependencyVersions.globals %>",\n "sass-embedded": "<%= dependencyVersions["sass-embedded"] %>",\n "typescript": "<%= dependencyVersions.typescript %>",\n "typescript-eslint": "<%= dependencyVersions["typescript-eslint"] %>",\n "vite": "<%= dependencyVersions.vite %>"\n }\n}\n';
1519
1536
  const viteSvg = '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>\n';
1520
1537
  const tsConfigAppJson = '{\n "compilerOptions": {\n "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",\n "target": "ES2022",\n "useDefineForClassFields": true,\n "lib": ["ES2022", "DOM", "DOM.Iterable"],\n "module": "ESNext",\n "types": ["vite/client"],\n "skipLibCheck": true,\n\n /* Bundler mode */\n "moduleResolution": "bundler",\n "allowImportingTsExtensions": true,\n "verbatimModuleSyntax": true,\n "moduleDetection": "force",\n "noEmit": true,\n "jsx": "react-jsx",\n\n /* Linting */\n "strict": true,\n "noUnusedLocals": true,\n "noUnusedParameters": true,\n "erasableSyntaxOnly": true,\n "noFallthroughCasesInSwitch": true,\n "noUncheckedSideEffectImports": true\n },\n "include": ["src"]\n}\n';
1521
1538
  const tsConfigJson = '{\n "files": [],\n "references": [\n { "path": "./tsconfig.app.json" },\n { "path": "./tsconfig.node.json" }\n ]\n}\n';
1522
1539
  const tsConfigNodeJson = '{\n "compilerOptions": {\n "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",\n "target": "ES2023",\n "lib": ["ES2023"],\n "module": "ESNext",\n "types": ["node"],\n "skipLibCheck": true,\n\n /* Bundler mode */\n "moduleResolution": "bundler",\n "allowImportingTsExtensions": true,\n "verbatimModuleSyntax": true,\n "moduleDetection": "force",\n "noEmit": true,\n\n /* Linting */\n "strict": true,\n "noUnusedLocals": true,\n "noUnusedParameters": true,\n "erasableSyntaxOnly": true,\n "noFallthroughCasesInSwitch": true,\n "noUncheckedSideEffectImports": true\n },\n "include": ["vite.config.ts"]\n}\n';
1523
- const viteConfigTsEjs = 'import { resolve } from "node:path";\n\nimport react from "@vitejs/plugin-react-swc";\nimport { defineConfig } from "vite";\n\n// https://vite.dev/config/\nexport default defineConfig({\n plugins: [react()],\n build: {\n outDir: "build/dist",\n rollupOptions: {\n input: {\n "<%= formId %>-app":\n process.env.VITE_BUILD_REASON === "preview"\n ? "index.html"\n : "src/main.tsx",\n },\n output: {\n // Output files without hashes, making it easier to serve them in the\n // server. However, the server is expected to somehow "version" them for\n // cache busting purposes.\n entryFileNames: "assets/[name].js",\n chunkFileNames: "assets/[name].js",\n assetFileNames: "assets/[name].[ext]",\n },\n },\n },\n resolve: {\n alias: [\n // Due to how Kotlin "bundles" dependencies, we need to use the\n // `@ostack.tech/kform` produced by the shared module.\n {\n find: "@ostack.tech/kform",\n replacement: resolve(\n import.meta.dirname,\n "node_modules/<%= formId %>-shared/ostack-kform.mjs",\n ),\n },\n ],\n },\n server: {\n proxy: { "/api": "http://127.0.0.1:8080" },\n },\n});\n';
1540
+ const viteConfigTsEjs = 'import { resolve } from "node:path";\n\nimport react from "@vitejs/plugin-react-swc";\nimport { defineConfig } from "vite";\n\n// https://vite.dev/config/\nexport default defineConfig({\n plugins: [react()],\n build: {\n outDir: "<%= viteConfigOutDir %>",\n rollupOptions: {\n input: {\n "<%= formId %>-app":\n process.env.VITE_BUILD_REASON === "preview"\n ? "index.html"\n : "src/main.tsx",\n },\n output: {\n // Output files without hashes, making it easier to serve them in the\n // server. However, the server is expected to somehow "version" them for\n // cache busting purposes.\n entryFileNames: "assets/[name].js",\n chunkFileNames: "assets/[name].js",\n assetFileNames: "assets/[name].[ext]",\n },\n },\n },\n resolve: {\n alias: [\n // Due to how Kotlin "bundles" dependencies, we need to use the\n // `@ostack.tech/kform` produced by the shared module.\n {\n find: "@ostack.tech/kform",\n replacement: resolve(\n import.meta.dirname,\n "node_modules/<%= formId %>-shared/ostack-kform.mjs",\n ),\n },\n ],\n },\n server: {\n proxy: { "<%= apiBasePath %>": "<%= viteConfigProxyTarget %>" },\n },\n});\n';
1541
+ const DEFAULT_VITE_CONFIG_OUT_DIR = "build/dist/";
1542
+ const DEFAULT_VITE_CONFIG_PROXY_TARGET = "http://127.0.0.1:8080/";
1524
1543
  function scaffoldViteProject(schematic, data) {
1525
1544
  const ejsData = {
1526
1545
  formId: kebabCase(schematic.name),
1527
1546
  formClass: schematic.name,
1528
1547
  formTitle: capitalCase(schematic.name),
1529
- ostackUiVersion: "0.3.2",
1530
- kFormVersion: "0.31.4",
1531
- dependencyVersions: JSON.parse('{"@eslint/js":"^9.38.0","@fortawesome/fontawesome-svg-core":"^7.1.0","@fortawesome/free-brands-svg-icons":"^7.1.0","@fortawesome/free-regular-svg-icons":"^7.1.0","@fortawesome/free-solid-svg-icons":"^7.1.0","@ostack.tech/kform":"~0.31.4","@ostack.tech/kform-react":"~0.31.4","@ostack.tech/kform-scaffolder":"~0.31.4","@storybook/addon-docs":"^9.1.13","@storybook/addon-links":"^9.1.13","@storybook/react-vite":"^9.1.13","@types/node":"^22.18.12","@types/react":"^19.2.2","@types/react-dom":"^19.2.2","@vitejs/plugin-react-swc":"^4.1.0","change-case":"^5.4.4","cpy-cli":"^6.0.0","date-fns":"^4.1.0","eslint":"^9.38.0","eslint-config-prettier":"^10.1.8","eslint-plugin-prettier":"^5.5.4","eslint-plugin-react-hooks":"^6.1.1","eslint-plugin-react-refresh":"^0.4.24","eslint-plugin-simple-import-sort":"^12.1.1","eslint-plugin-storybook":"^9.1.13","globals":"^16.4.0","happy-dom":"^20.0.8","lint-staged":"^16.2.6","prettier":"^3.6.2","prettier-plugin-jsdoc":"^1.3.3","react":"^19.2.0","react-dom":"^19.2.0","react-router":"^7.9.4","react-router-dom":"^7.9.4","rimraf":"^6.0.1","sass-embedded":"^1.93.2","simple-git-hooks":"^2.13.1","storybook":"^9.1.13","terser":"^5.44.0","tslib":"^2.8.1","typescript":"~5.9.3","typescript-eslint":"^8.46.2","vite":"^7.1.12","vite-plugin-dts":"^4.5.4","vitest":"^4.0.1","zustand":"^5.0.8"}'),
1532
- externalContextsData: data.serializationFormat === "json" ? "{}" : `<${schematic.name}ExternalContexts />`
1548
+ ostackUiVersion: "0.3.4",
1549
+ kFormVersion: "0.31.5",
1550
+ dependencyVersions: JSON.parse('{"@eslint/js":"^9.38.0","@fortawesome/fontawesome-svg-core":"^7.1.0","@fortawesome/free-brands-svg-icons":"^7.1.0","@fortawesome/free-regular-svg-icons":"^7.1.0","@fortawesome/free-solid-svg-icons":"^7.1.0","@ostack.tech/kform":"~0.31.5","@ostack.tech/kform-react":"~0.31.5","@ostack.tech/kform-scaffolder":"~0.31.5","@storybook/addon-docs":"^9.1.16","@storybook/addon-links":"^9.1.16","@storybook/react-vite":"^9.1.16","@types/node":"^22.18.13","@types/react":"^19.2.2","@types/react-dom":"^19.2.2","@vitejs/plugin-react-swc":"^4.2.0","change-case":"^5.4.4","cpy-cli":"^6.0.0","date-fns":"^4.1.0","eslint":"^9.38.0","eslint-config-prettier":"^10.1.8","eslint-plugin-prettier":"^5.5.4","eslint-plugin-react-hooks":"^7.0.1","eslint-plugin-react-refresh":"^0.4.24","eslint-plugin-simple-import-sort":"^12.1.1","eslint-plugin-storybook":"^9.1.16","globals":"^16.4.0","happy-dom":"^20.0.10","lint-staged":"^16.2.6","prettier":"^3.6.2","prettier-plugin-jsdoc":"^1.5.0","react":"^19.2.0","react-dom":"^19.2.0","react-router":"^7.9.5","react-router-dom":"^7.9.5","rimraf":"^6.0.1","sass-embedded":"^1.93.2","simple-git-hooks":"^2.13.1","storybook":"^9.1.16","terser":"^5.44.0","tslib":"^2.8.1","typescript":"~5.9.3","typescript-eslint":"^8.46.2","vite":"^7.1.12","vite-plugin-dts":"^4.5.4","vitest":"^4.0.5","zustand":"^5.0.8"}'),
1551
+ externalContextsData: data.serializationFormat === "json" ? "{}" : `<${schematic.name}ExternalContexts />`,
1552
+ apiBasePath: data.apiBasePath ?? DEFAULT_API_BASE_PATH,
1553
+ viteConfigOutDir: data.viteConfigOutDir ?? DEFAULT_VITE_CONFIG_OUT_DIR,
1554
+ viteConfigProxyTarget: data.viteConfigProxyTarget ?? DEFAULT_VITE_CONFIG_PROXY_TARGET
1533
1555
  };
1534
1556
  addEjsTemplateFile(data, "react-app/package.json", packageJsonEjs, ejsData);
1535
1557
  addEjsTemplateFile(
@@ -1600,6 +1622,15 @@ function SchematicBuilder({
1600
1622
  );
1601
1623
  }
1602
1624
  export {
1625
+ DEFAULT_API_BASE_PATH,
1626
+ DEFAULT_JVM_TOOLCHAIN_VERSION,
1627
+ DEFAULT_LOCALE,
1628
+ DEFAULT_NODEJS_VERSION,
1629
+ DEFAULT_REPORT_ERROR_API_ENDPOINT,
1630
+ DEFAULT_SERIALIZATION_FORMAT,
1631
+ DEFAULT_SUBMIT_API_ENDPOINT,
1632
+ DEFAULT_VITE_CONFIG_OUT_DIR,
1633
+ DEFAULT_VITE_CONFIG_PROXY_TARGET,
1603
1634
  DefaultLocaleConfig,
1604
1635
  LOCALES,
1605
1636
  SchematicBuilder,