swallowkit 1.0.0-beta.32 → 1.0.0-beta.36

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 (33) hide show
  1. package/dist/cli/commands/init.js +4 -6
  2. package/dist/cli/commands/init.js.map +1 -1
  3. package/dist/cli/commands/scaffold.d.ts.map +1 -1
  4. package/dist/cli/commands/scaffold.js +4 -1
  5. package/dist/cli/commands/scaffold.js.map +1 -1
  6. package/dist/cli/index.js +1 -1
  7. package/dist/cli/index.js.map +1 -1
  8. package/dist/core/project/manifest.js +1 -1
  9. package/dist/core/project/manifest.js.map +1 -1
  10. package/dist/core/scaffold/functions-generator.js +1 -1
  11. package/dist/core/scaffold/functions-generator.js.map +1 -1
  12. package/dist/core/scaffold/native-schema-generator.d.ts.map +1 -1
  13. package/dist/core/scaffold/native-schema-generator.js +22 -3
  14. package/dist/core/scaffold/native-schema-generator.js.map +1 -1
  15. package/dist/machine/index.js +1 -1
  16. package/dist/machine/index.js.map +1 -1
  17. package/package.json +2 -3
  18. package/src/__tests__/__snapshots__/functions-generator.test.ts.snap +3 -3
  19. package/src/__tests__/dev.test.ts +1 -1
  20. package/src/__tests__/functions-generator.test.ts +1 -1
  21. package/src/__tests__/init.test.ts +1 -1
  22. package/src/__tests__/jest-globals.d.ts +8 -0
  23. package/src/__tests__/machine.test.ts +105 -0
  24. package/src/__tests__/mcp.test.ts +14 -16
  25. package/src/__tests__/scaffold.test.ts +94 -0
  26. package/src/__tests__/tsconfig.json +15 -0
  27. package/src/cli/commands/init.ts +4 -7
  28. package/src/cli/commands/scaffold.ts +5 -1
  29. package/src/cli/index.ts +1 -1
  30. package/src/core/project/manifest.ts +1 -1
  31. package/src/core/scaffold/functions-generator.ts +1 -1
  32. package/src/core/scaffold/native-schema-generator.ts +27 -3
  33. package/src/machine/index.ts +1 -1
@@ -601,6 +601,31 @@ function buildGeneratedPythonModelsInitSource(models: ModelInfo[]): string {
601
601
  return models.map((model) => `from .${toSnakeCase(model.name)} import ${model.name}`).join("\n") + "\n";
602
602
  }
603
603
 
604
+ function mergePythonInitSource(existingSource: string | undefined, generatedSource: string): string {
605
+ if (!existingSource) {
606
+ return generatedSource;
607
+ }
608
+
609
+ const existingLines = existingSource.split(/\r?\n/);
610
+ const lineSet = new Set(existingLines);
611
+ const missingLines = generatedSource
612
+ .trim()
613
+ .split(/\r?\n/)
614
+ .filter((line) => line.length > 0 && !lineSet.has(line));
615
+
616
+ if (missingLines.length === 0) {
617
+ return existingSource.endsWith("\n") ? existingSource : `${existingSource}\n`;
618
+ }
619
+
620
+ const normalizedExisting = existingSource.endsWith("\n") ? existingSource : `${existingSource}\n`;
621
+ return `${normalizedExisting}${missingLines.join("\n")}\n`;
622
+ }
623
+
624
+ function writeMergedPythonInitFile(filePath: string, generatedSource: string): void {
625
+ const existingSource = fs.existsSync(filePath) ? fs.readFileSync(filePath, "utf-8") : undefined;
626
+ fs.writeFileSync(filePath, mergePythonInitSource(existingSource, generatedSource), "utf-8");
627
+ }
628
+
604
629
  function ensureCSharpCodegenProjectFiles(functionsRoot: string): void {
605
630
  const toolManifestPath = path.join(functionsRoot, ".config", "dotnet-tools.json");
606
631
  fs.mkdirSync(path.dirname(toolManifestPath), { recursive: true });
@@ -752,8 +777,8 @@ async function generatePythonSchemaArtifacts(
752
777
  const packageRoot = path.join(outputDir, "backend_models");
753
778
  const modelsRoot = path.join(packageRoot, "models");
754
779
  fs.mkdirSync(modelsRoot, { recursive: true });
755
- fs.writeFileSync(path.join(packageRoot, "__init__.py"), buildGeneratedPythonPackageInitSource(models), "utf-8");
756
- fs.writeFileSync(path.join(modelsRoot, "__init__.py"), buildGeneratedPythonModelsInitSource(models), "utf-8");
780
+ writeMergedPythonInitFile(path.join(packageRoot, "__init__.py"), buildGeneratedPythonPackageInitSource(models));
781
+ writeMergedPythonInitFile(path.join(modelsRoot, "__init__.py"), buildGeneratedPythonModelsInitSource(models));
757
782
 
758
783
  for (const model of models) {
759
784
  const modelPath = getPythonSchemaModelPath(outputDir, model.name);
@@ -785,7 +810,6 @@ export async function generateLanguageSchemaArtifacts(
785
810
  backendLanguage === "csharp" ? "csharp-models" : "python-models"
786
811
  );
787
812
 
788
- fs.rmSync(outputDir, { recursive: true, force: true });
789
813
  fs.mkdirSync(outputDir, { recursive: true });
790
814
 
791
815
  if (backendLanguage === "csharp") {
@@ -134,7 +134,7 @@ function createMachineProgram(): Command {
134
134
  .argument("<model>", "Model file or model name")
135
135
  .option("--functions-dir <dir>", "Functions directory", "functions")
136
136
  .option("--api-dir <dir>", "API routes directory", "app/api")
137
- .option("--api-only", "Generate only API artifacts", false)
137
+ .option("--api-only", "Skip UI components; still update Functions, BFF routes, OpenAPI, and native schema assets", false)
138
138
  .action(async (model: string, options: { functionsDir?: string; apiDir?: string; apiOnly?: boolean }) => {
139
139
  await handleMachineAction("generate-scaffold", async () => runMachineScaffoldOperation({
140
140
  model,