@palantir/pack.sdkgen 0.4.0 → 0.6.0

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 (61) hide show
  1. package/build/esm/__tests__/generator.test.js +1 -5
  2. package/build/esm/__tests__/generator.test.js.map +1 -1
  3. package/build/esm/__tests__/templateLoader.test.js +5 -4
  4. package/build/esm/__tests__/templateLoader.test.js.map +1 -1
  5. package/build/esm/commands/create.js +28 -151
  6. package/build/esm/commands/create.js.map +1 -1
  7. package/build/esm/index.js +1 -7
  8. package/build/esm/index.js.map +1 -1
  9. package/build/types/commands/create.d.ts +1 -1
  10. package/build/types/commands/create.d.ts.map +1 -1
  11. package/build/types/index.d.ts +2 -8
  12. package/build/types/index.d.ts.map +1 -1
  13. package/package.json +3 -8
  14. package/build/esm/__tests__/schemaParser.test.js +0 -67
  15. package/build/esm/__tests__/schemaParser.test.js.map +0 -1
  16. package/build/esm/__tests__/templateUtils.test.js +0 -94
  17. package/build/esm/__tests__/templateUtils.test.js.map +0 -1
  18. package/build/esm/core/contextBuilder.js +0 -33
  19. package/build/esm/core/contextBuilder.js.map +0 -1
  20. package/build/esm/core/generator.js +0 -248
  21. package/build/esm/core/generator.js.map +0 -1
  22. package/build/esm/core/hookRunner.js +0 -68
  23. package/build/esm/core/hookRunner.js.map +0 -1
  24. package/build/esm/core/schemaParser.js +0 -50
  25. package/build/esm/core/schemaParser.js.map +0 -1
  26. package/build/esm/core/templateLoader.js +0 -109
  27. package/build/esm/core/templateLoader.js.map +0 -1
  28. package/build/esm/types/index.js +0 -2
  29. package/build/esm/types/index.js.map +0 -1
  30. package/build/esm/utils/fileSystem.js +0 -72
  31. package/build/esm/utils/fileSystem.js.map +0 -1
  32. package/build/esm/utils/logger.js +0 -44
  33. package/build/esm/utils/logger.js.map +0 -1
  34. package/build/esm/utils/prompts.js +0 -25
  35. package/build/esm/utils/prompts.js.map +0 -1
  36. package/build/esm/utils/templateUtils.js +0 -61
  37. package/build/esm/utils/templateUtils.js.map +0 -1
  38. package/build/types/__tests__/schemaParser.test.d.ts +0 -2
  39. package/build/types/__tests__/schemaParser.test.d.ts.map +0 -1
  40. package/build/types/__tests__/templateUtils.test.d.ts +0 -2
  41. package/build/types/__tests__/templateUtils.test.d.ts.map +0 -1
  42. package/build/types/core/contextBuilder.d.ts +0 -5
  43. package/build/types/core/contextBuilder.d.ts.map +0 -1
  44. package/build/types/core/generator.d.ts +0 -15
  45. package/build/types/core/generator.d.ts.map +0 -1
  46. package/build/types/core/hookRunner.d.ts +0 -3
  47. package/build/types/core/hookRunner.d.ts.map +0 -1
  48. package/build/types/core/schemaParser.d.ts +0 -7
  49. package/build/types/core/schemaParser.d.ts.map +0 -1
  50. package/build/types/core/templateLoader.d.ts +0 -13
  51. package/build/types/core/templateLoader.d.ts.map +0 -1
  52. package/build/types/types/index.d.ts +0 -68
  53. package/build/types/types/index.d.ts.map +0 -1
  54. package/build/types/utils/fileSystem.d.ts +0 -8
  55. package/build/types/utils/fileSystem.d.ts.map +0 -1
  56. package/build/types/utils/logger.d.ts +0 -11
  57. package/build/types/utils/logger.d.ts.map +0 -1
  58. package/build/types/utils/prompts.d.ts +0 -3
  59. package/build/types/utils/prompts.d.ts.map +0 -1
  60. package/build/types/utils/templateUtils.d.ts +0 -3
  61. package/build/types/utils/templateUtils.d.ts.map +0 -1
@@ -14,15 +14,11 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ import { ContextBuilder, Generator, Logger, SchemaParser, TemplateLoader } from "@palantir/pack.codegen.core";
17
18
  import fs from "fs-extra";
18
19
  import path from "path";
19
20
  import { fileURLToPath } from "url";
20
21
  import { beforeAll, describe, expect, it } from "vitest";
21
- import { ContextBuilder } from "../core/contextBuilder.js";
22
- import { Generator } from "../core/generator.js";
23
- import { SchemaParser } from "../core/schemaParser.js";
24
- import { TemplateLoader } from "../core/templateLoader.js";
25
- import { Logger } from "../utils/logger.js";
26
22
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
27
23
  const fixturesDir = path.join(__dirname, "fixtures");
28
24
  const testOutputDir = path.join(__dirname, "../../test-output", "generator");
@@ -1 +1 @@
1
- {"version":3,"file":"generator.test.js","names":["fs","path","fileURLToPath","beforeAll","describe","expect","it","ContextBuilder","Generator","SchemaParser","TemplateLoader","Logger","__dirname","dirname","import","meta","url","fixturesDir","join","testOutputDir","remove","ensureDir","projectName","outputPath","packageRoot","resolve","templatePath","schemaPath","logger","templateLoader","config","templateConfig","templateDir","loadTemplate","schemaParser","schema","loadSchema","transformedSchema","transformers","default","transformer","transformerPath","transformFn","answers","options","skipInstall","utils","contextBuilder","context","build","greeting","author","license","verbose","dryRun","generator","generate","pathExists","toBe","packageJson","readJSON","toMatchObject","name","helloWorldContent","readFile","toContain","description"],"sources":["generator.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from \"fs-extra\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { beforeAll, describe, expect, it } from \"vitest\";\nimport { ContextBuilder } from \"../core/contextBuilder.js\";\nimport { Generator } from \"../core/generator.js\";\nimport { SchemaParser } from \"../core/schemaParser.js\";\nimport { TemplateLoader } from \"../core/templateLoader.js\";\nimport { Logger } from \"../utils/logger.js\";\nimport type { PackageJson } from \"./types/testTypes.js\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\nconst fixturesDir = path.join(__dirname, \"fixtures\");\nconst testOutputDir = path.join(__dirname, \"../../test-output\", \"generator\");\n\ndescribe(\"Generator\", () => {\n beforeAll(async () => {\n // Clean up before all tests run\n await fs.remove(testOutputDir);\n await fs.ensureDir(testOutputDir);\n });\n\n it(\"should generate SDK with demo template\", async () => {\n const projectName = \"demo-template-sdk\";\n const outputPath = path.join(testOutputDir, projectName);\n // Find the template directory relative to the package root\n const packageRoot = path.resolve(__dirname, \"../..\");\n const templatePath = path.resolve(packageRoot, \"../sdkgen-demo-template\");\n const schemaPath = path.join(fixturesDir, \"test-schema.json\");\n\n // Load template\n const logger = new Logger(false);\n const templateLoader = new TemplateLoader(logger);\n const { config: templateConfig, templateDir } = await templateLoader.loadTemplate(templatePath);\n\n // Load schema\n const schemaParser = new SchemaParser(logger);\n const schema = await schemaParser.loadSchema(schemaPath);\n\n // Transform schema if transformer exists\n let transformedSchema = schema;\n if (templateConfig.transformers?.default) {\n const transformer = templateConfig.transformers.default;\n if (typeof transformer === \"string\") {\n const transformerPath = path.join(templateDir, transformer);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Dynamic import of transformer\n const { default: transformFn } = await import(transformerPath);\n\n transformedSchema = await transformFn(schema, {\n projectName,\n schema,\n answers: {},\n templateConfig,\n schemaPath,\n outputPath,\n options: { skipInstall: true },\n utils: {} as unknown,\n });\n }\n }\n\n // Build context with test answers\n const contextBuilder = new ContextBuilder();\n const context = contextBuilder.build(\n projectName,\n transformedSchema,\n {\n greeting: \"Hello, Test!\",\n author: \"Test Author\",\n license: \"MIT\",\n },\n templateConfig,\n outputPath,\n { skipInstall: true, verbose: false, dryRun: false },\n schemaPath,\n );\n\n // Generate SDK\n const generator = new Generator(context, templateDir, logger);\n await generator.generate();\n\n // Verify generated files\n expect(await fs.pathExists(outputPath)).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"package.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"src\", \"helloWorld.ts\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"src\", \"index.ts\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"README.md\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \".gitignore\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"tsconfig.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"jest.config.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \".eslintrc.json\"))).toBe(true);\n\n // Verify package.json content\n const packageJson = await fs.readJSON(path.join(outputPath, \"package.json\")) as PackageJson;\n expect(packageJson).toMatchObject({\n name: projectName,\n author: \"Test Author\",\n license: \"MIT\",\n });\n\n // Verify generated TypeScript content\n const helloWorldContent = await fs.readFile(\n path.join(outputPath, \"src\", \"helloWorld.ts\"),\n \"utf8\",\n );\n expect(helloWorldContent).toContain(\"private greeting: string = 'Hello, Test!'\");\n expect(helloWorldContent).toContain(\"Test Author\");\n expect(helloWorldContent).toContain(\"getSchemaInfo()\");\n });\n\n it(\"should handle dry-run mode\", async () => {\n const projectName = \"dry-run-mode-sdk\";\n const outputPath = path.join(testOutputDir, projectName);\n // Find the template directory relative to the package root\n const packageRoot = path.resolve(__dirname, \"../..\");\n const templatePath = path.resolve(packageRoot, \"../sdkgen-demo-template\");\n const schemaPath = path.join(fixturesDir, \"test-schema.json\");\n\n const logger = new Logger(false);\n const templateLoader = new TemplateLoader(logger);\n const { config: templateConfig, templateDir } = await templateLoader.loadTemplate(templatePath);\n\n const schemaParser = new SchemaParser(logger);\n const schema = await schemaParser.loadSchema(schemaPath);\n\n const contextBuilder = new ContextBuilder();\n const context = contextBuilder.build(\n projectName,\n schema,\n {\n greeting: \"Hello, Dry Run!\",\n author: \"Dry Run Author\",\n license: \"MIT\",\n },\n templateConfig,\n outputPath,\n { skipInstall: true, verbose: false, dryRun: true },\n schemaPath,\n );\n\n const generator = new Generator(context, templateDir, logger);\n await generator.generate();\n\n // In dry-run mode, no files should be created\n expect(await fs.pathExists(outputPath)).toBe(false);\n });\n\n it(\"should generate SDK with default template\", async () => {\n const projectName = \"default-template-sdk\";\n const outputPath = path.join(testOutputDir, projectName);\n const templatePath = path.resolve(__dirname, \"../../templates/default\");\n\n const logger = new Logger(false);\n const templateLoader = new TemplateLoader(logger);\n const { config: templateConfig, templateDir } = await templateLoader.loadTemplate(templatePath);\n\n const contextBuilder = new ContextBuilder();\n const context = contextBuilder.build(\n projectName,\n {},\n {\n description: \"Default template test SDK\",\n author: \"Default Author\",\n },\n templateConfig,\n outputPath,\n { skipInstall: true, verbose: false, dryRun: false },\n );\n\n const generator = new Generator(context, templateDir, logger);\n await generator.generate();\n\n // Verify generated files\n expect(await fs.pathExists(outputPath)).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"package.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"src\", \"index.ts\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"tsconfig.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \".gitignore\"))).toBe(true);\n\n // Verify package.json content\n const packageJson = await fs.readJSON(path.join(outputPath, \"package.json\")) as PackageJson;\n expect(packageJson).toMatchObject({\n name: projectName,\n description: \"Default template test SDK\",\n author: \"Default Author\",\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,UAAU;AACzB,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,aAAa,QAAQ,KAAK;AACnC,SAASC,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AACxD,SAASC,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,SAAS,QAAQ,sBAAsB;AAChD,SAASC,YAAY,QAAQ,yBAAyB;AACtD,SAASC,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,MAAM,QAAQ,oBAAoB;AAG3C,MAAMC,SAAS,GAAGX,IAAI,CAACY,OAAO,CAACX,aAAa,CAACY,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAC9D,MAAMC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ACxCf,MAAM,EAAE;IACV,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"generator.test.js","names":["ContextBuilder","Generator","Logger","SchemaParser","TemplateLoader","fs","path","fileURLToPath","beforeAll","describe","expect","it","__dirname","dirname","import","meta","url","fixturesDir","join","testOutputDir","remove","ensureDir","projectName","outputPath","packageRoot","resolve","templatePath","schemaPath","logger","templateLoader","config","templateConfig","templateDir","loadTemplate","schemaParser","schema","loadSchema","transformedSchema","transformers","default","transformer","transformerPath","transformFn","answers","options","skipInstall","utils","contextBuilder","context","build","greeting","author","license","verbose","dryRun","generator","generate","pathExists","toBe","packageJson","readJSON","toMatchObject","name","helloWorldContent","readFile","toContain","description"],"sources":["generator.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n ContextBuilder,\n Generator,\n Logger,\n SchemaParser,\n TemplateLoader,\n} from \"@palantir/pack.codegen.core\";\nimport fs from \"fs-extra\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { beforeAll, describe, expect, it } from \"vitest\";\nimport type { PackageJson } from \"./types/testTypes.js\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\nconst fixturesDir = path.join(__dirname, \"fixtures\");\nconst testOutputDir = path.join(__dirname, \"../../test-output\", \"generator\");\n\ndescribe(\"Generator\", () => {\n beforeAll(async () => {\n // Clean up before all tests run\n await fs.remove(testOutputDir);\n await fs.ensureDir(testOutputDir);\n });\n\n it(\"should generate SDK with demo template\", async () => {\n const projectName = \"demo-template-sdk\";\n const outputPath = path.join(testOutputDir, projectName);\n // Find the template directory relative to the package root\n const packageRoot = path.resolve(__dirname, \"../..\");\n const templatePath = path.resolve(packageRoot, \"../sdkgen-demo-template\");\n const schemaPath = path.join(fixturesDir, \"test-schema.json\");\n\n // Load template\n const logger = new Logger(false);\n const templateLoader = new TemplateLoader(logger);\n const { config: templateConfig, templateDir } = await templateLoader.loadTemplate(templatePath);\n\n // Load schema\n const schemaParser = new SchemaParser(logger);\n const schema = await schemaParser.loadSchema(schemaPath);\n\n // Transform schema if transformer exists\n let transformedSchema = schema;\n if (templateConfig.transformers?.default) {\n const transformer = templateConfig.transformers.default;\n if (typeof transformer === \"string\") {\n const transformerPath = path.join(templateDir, transformer);\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Dynamic import of transformer\n const { default: transformFn } = await import(transformerPath);\n\n transformedSchema = await transformFn(schema, {\n projectName,\n schema,\n answers: {},\n templateConfig,\n schemaPath,\n outputPath,\n options: { skipInstall: true },\n utils: {} as unknown,\n });\n }\n }\n\n // Build context with test answers\n const contextBuilder = new ContextBuilder();\n const context = contextBuilder.build(\n projectName,\n transformedSchema,\n {\n greeting: \"Hello, Test!\",\n author: \"Test Author\",\n license: \"MIT\",\n },\n templateConfig,\n outputPath,\n { skipInstall: true, verbose: false, dryRun: false },\n schemaPath,\n );\n\n // Generate SDK\n const generator = new Generator(context, templateDir, logger);\n await generator.generate();\n\n // Verify generated files\n expect(await fs.pathExists(outputPath)).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"package.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"src\", \"helloWorld.ts\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"src\", \"index.ts\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"README.md\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \".gitignore\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"tsconfig.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"jest.config.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \".eslintrc.json\"))).toBe(true);\n\n // Verify package.json content\n const packageJson = await fs.readJSON(path.join(outputPath, \"package.json\")) as PackageJson;\n expect(packageJson).toMatchObject({\n name: projectName,\n author: \"Test Author\",\n license: \"MIT\",\n });\n\n // Verify generated TypeScript content\n const helloWorldContent = await fs.readFile(\n path.join(outputPath, \"src\", \"helloWorld.ts\"),\n \"utf8\",\n );\n expect(helloWorldContent).toContain(\"private greeting: string = 'Hello, Test!'\");\n expect(helloWorldContent).toContain(\"Test Author\");\n expect(helloWorldContent).toContain(\"getSchemaInfo()\");\n });\n\n it(\"should handle dry-run mode\", async () => {\n const projectName = \"dry-run-mode-sdk\";\n const outputPath = path.join(testOutputDir, projectName);\n // Find the template directory relative to the package root\n const packageRoot = path.resolve(__dirname, \"../..\");\n const templatePath = path.resolve(packageRoot, \"../sdkgen-demo-template\");\n const schemaPath = path.join(fixturesDir, \"test-schema.json\");\n\n const logger = new Logger(false);\n const templateLoader = new TemplateLoader(logger);\n const { config: templateConfig, templateDir } = await templateLoader.loadTemplate(templatePath);\n\n const schemaParser = new SchemaParser(logger);\n const schema = await schemaParser.loadSchema(schemaPath);\n\n const contextBuilder = new ContextBuilder();\n const context = contextBuilder.build(\n projectName,\n schema,\n {\n greeting: \"Hello, Dry Run!\",\n author: \"Dry Run Author\",\n license: \"MIT\",\n },\n templateConfig,\n outputPath,\n { skipInstall: true, verbose: false, dryRun: true },\n schemaPath,\n );\n\n const generator = new Generator(context, templateDir, logger);\n await generator.generate();\n\n // In dry-run mode, no files should be created\n expect(await fs.pathExists(outputPath)).toBe(false);\n });\n\n it(\"should generate SDK with default template\", async () => {\n const projectName = \"default-template-sdk\";\n const outputPath = path.join(testOutputDir, projectName);\n const templatePath = path.resolve(__dirname, \"../../templates/default\");\n\n const logger = new Logger(false);\n const templateLoader = new TemplateLoader(logger);\n const { config: templateConfig, templateDir } = await templateLoader.loadTemplate(templatePath);\n\n const contextBuilder = new ContextBuilder();\n const context = contextBuilder.build(\n projectName,\n {},\n {\n description: \"Default template test SDK\",\n author: \"Default Author\",\n },\n templateConfig,\n outputPath,\n { skipInstall: true, verbose: false, dryRun: false },\n );\n\n const generator = new Generator(context, templateDir, logger);\n await generator.generate();\n\n // Verify generated files\n expect(await fs.pathExists(outputPath)).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"package.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"src\", \"index.ts\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"tsconfig.json\"))).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \".gitignore\"))).toBe(true);\n\n // Verify package.json content\n const packageJson = await fs.readJSON(path.join(outputPath, \"package.json\")) as PackageJson;\n expect(packageJson).toMatchObject({\n name: projectName,\n description: \"Default template test SDK\",\n author: \"Default Author\",\n });\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,cAAc,EACdC,SAAS,EACTC,MAAM,EACNC,YAAY,EACZC,cAAc,QACT,6BAA6B;AACpC,OAAOC,EAAE,MAAM,UAAU;AACzB,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,aAAa,QAAQ,KAAK;AACnC,SAASC,SAAS,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAGxD,MAAMC,SAAS,GAAGN,IAAI,CAACO,OAAO,CAACN,aAAa,CAACO,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAC9D,MAAMC,WAAW,GAAGX,IAAI,CAACY,IAAI,CAACN,SAAS,EAAE,UAAU,CAAC;AACpD,MAAMO,aAAa,GAAGb,IAAI,CAACY,IAAI,CAACN,SAAS,EAAE,mBAAmB,EAAE,WAAW,CAAC;AAE5EH,QAAQ,CAAC,WAAW,E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B,WAAW,EAAEJ,MAAM,CAAC;IAC7D,MAAM2B,SAAS,CAACC,QAAQ,CAAC,CAAC;;IAE1B;IACA9C,MAAM,CAAC,MAAML,EAAE,CAACoD,UAAU,CAAClC,UAAU,CAAC,CAAC,CAACmC,IAAI,CAAC,IAAI,CAAC;IAClDhD,MAAM,CAAC,MAAML,EAAE,CAACoD,UAAU,CAACnD,IAAI,CAACY,IAAI,CAACK,UAAU,EAAE,cAAc,CAAC,CAAC,CAAC,CAACmC,IAAI,CAAC,IAAI,CAAC;IAC7EhD,MAAM,CAAC,MAAML,EAAE,CAACoD,UAAU,CAACnD,IAAI,CAACY,IAAI,CAACK,UAAU,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAACmC,IAAI,CAAC,IAAI,CAAC;IAChFhD,MAAM,CAAC,MAAML,EAAE,CAACoD,UAAU,CAACnD,IAAI,CAACY,IAAI,CAACK,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,CAACmC,IAAI,CAAC,IAAI,CAAC;IAC9EhD,MAAM,CAAC,MAAML,EAAE,CAACoD,UAAU,CAACnD,IAAI,CAACY,IAAI,CAACK,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,CAACmC,IAAI,CAAC,IAAI,CAAC;;IAE3E;IACA,MAAMC,WAAW,GAAG,MAAMtD,EAAE,CAACuD,QAAQ,CAACtD,IAAI,CAACY,IAAI,CAACK,UAAU,EAAE,cAAc,CAAC,CAAgB;IAC3Fb,MAAM,CAACiD,WAAW,CAAC,CAACE,aAAa,CAAC;MAChCC,IAAI,EAAExC,WAAW;MACjB4C,WAAW,EAAE,2BAA2B;MACxCf,MAAM,EAAE;IACV,CAAC,CAAC;EACJ,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -14,11 +14,10 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ import { Logger, TemplateLoader } from "@palantir/pack.codegen.core";
17
18
  import path from "path";
18
19
  import { fileURLToPath } from "url";
19
20
  import { describe, expect, it } from "vitest";
20
- import { TemplateLoader } from "../core/templateLoader.js";
21
- import { Logger } from "../utils/logger.js";
22
21
  const __dirname = path.dirname(fileURLToPath(import.meta.url));
23
22
  describe("TemplateLoader", () => {
24
23
  const logger = new Logger(false);
@@ -40,11 +39,13 @@ describe("TemplateLoader", () => {
40
39
  expect(config.hooks).toBeDefined();
41
40
  expect(templateDir).toBe(templatePath);
42
41
  });
43
- it("should load default template", async () => {
42
+ it("should load the built-in default template from local path", async () => {
43
+ const packageRoot = path.resolve(__dirname, "../..");
44
+ const templatePath = path.resolve(packageRoot, "templates/default");
44
45
  const {
45
46
  config,
46
47
  templateDir
47
- } = await loader.loadTemplate("default");
48
+ } = await loader.loadTemplate(templatePath);
48
49
  expect(config).toBeDefined();
49
50
  expect(config.name).toBe("default-template");
50
51
  expect(templateDir).toContain("templates/default");
@@ -1 +1 @@
1
- {"version":3,"file":"templateLoader.test.js","names":["path","fileURLToPath","describe","expect","it","TemplateLoader","Logger","__dirname","dirname","import","meta","url","logger","loader","packageRoot","resolve","templatePath","config","templateDir","loadTemplate","toBeDefined","name","toBe","description","prompts","toHaveLength","templateFiles","toEqual","staticFiles","hooks","toContain","rejects","toThrow","tempDir","join","fs","ensureDir","remove"],"sources":["templateLoader.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { describe, expect, it } from \"vitest\";\nimport { TemplateLoader } from \"../core/templateLoader.js\";\nimport { Logger } from \"../utils/logger.js\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\ndescribe(\"TemplateLoader\", () => {\n const logger = new Logger(false);\n const loader = new TemplateLoader(logger);\n\n it(\"should load demo template from local path\", async () => {\n // Find the template directory relative to the package root\n const packageRoot = path.resolve(__dirname, \"../..\");\n const templatePath = path.resolve(packageRoot, \"../sdkgen-demo-template\");\n const { config, templateDir } = await loader.loadTemplate(templatePath);\n\n expect(config).toBeDefined();\n expect(config.name).toBe(\"hello-world-template\");\n expect(config.description).toBe(\"A simple Hello World SDK template\");\n expect(config.prompts).toHaveLength(3);\n expect(config.templateFiles).toEqual([\"**/*.ejs\"]);\n expect(config.staticFiles).toEqual([\"_gitignore\"]);\n expect(config.hooks).toBeDefined();\n expect(templateDir).toBe(templatePath);\n });\n\n it(\"should load default template\", async () => {\n const { config, templateDir } = await loader.loadTemplate(\"default\");\n\n expect(config).toBeDefined();\n expect(config.name).toBe(\"default-template\");\n expect(templateDir).toContain(\"templates/default\");\n });\n\n it(\"should throw error for non-existent template\", async () => {\n await expect(loader.loadTemplate(\"/non/existent/template\")).rejects.toThrow(\n \"Template directory does not exist\",\n );\n });\n\n it(\"should throw error for template without config\", async () => {\n // Create a temporary directory without template.config.js for this test\n const tempDir = path.join(__dirname, \"../../build/temp-template\");\n const fs = await import(\"fs-extra\");\n await fs.ensureDir(tempDir);\n\n try {\n await expect(loader.loadTemplate(tempDir)).rejects.toThrow(\n \"Template configuration not found\",\n );\n } finally {\n await fs.remove(tempDir);\n }\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,IAAI,MAAM,MAAM;AACvB,SAASC,aAAa,QAAQ,KAAK;AACnC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAC7C,SAASC,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,MAAM,QAAQ,oBAAoB;AAE3C,MAAMC,SAAS,GAAGP,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AAML,MAAM,CAACM,YAAY,CAAC,SAAS,CAAC;IAEpEhB,MAAM,CAACc,MAAM,CAAC,CAACG,WAAW,CAAC,CAAC;IAC5BjB,MAAM,CAACc,MAAM,CAACI,IAAI,CAAC,CAACC,IAAI,CAAC,kBAAkB,CAAC;IAC5CnB,MAAM,CAACe,WAAW,CAAC,CAACY,SAAS,CAAC,mBAAmB,CAAC;EACpD,CAAC,CAAC;EAEF1B,EAAE,CAAC,8CAA8C,EAAE,YAAY;IAC7D,MAAMD,MAAM,CAACU,MAAM,CAACM,YAAY,CAAC,wBAAwB,CAAC,CAAC,CAACY,OAAO,CAACC,OAAO,CACzE,mCACF,CAAC;EACH,CAAC,CAAC;EAEF5B,EAAE,CAAC,gDAAgD,EAAE,YAAY;IAC/D;IACA,MAAM6B,OAAO,GAAGjC,IAAI,CAACkC,IAAI,CAAC3B,SAAS,EAAE,2BAA2B,CAAC;IACjE,MAAM4B,EAAE,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC;IACnC,MAAMA,EAAE,CAACC,SAAS,CAACH,OAAO,CAAC;IAE3B,IAAI;MACF,MAAM9B,MAAM,CAACU,MAAM,CAACM,YAAY,CAACc,OAAO,CAAC,CAAC,CAACF,OAAO,CAACC,OAAO,CACxD,kCACF,CAAC;IACH,CAAC,SAAS;MACR,MAAMG,EAAE,CAACE,MAAM,CAACJ,OAAO,CAAC;IAC1B;EACF,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
1
+ {"version":3,"file":"templateLoader.test.js","names":["Logger","TemplateLoader","path","fileURLToPath","describe","expect","it","__dirname","dirname","import","meta","url","logger","loader","packageRoot","resolve","templatePath","config","templateDir","loadTemplate","toBeDefined","name","toBe","description","prompts","toHaveLength","templateFiles","toEqual","staticFiles","hooks","toContain","rejects","toThrow","tempDir","join","fs","ensureDir","remove"],"sources":["templateLoader.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Logger, TemplateLoader } from \"@palantir/pack.codegen.core\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { describe, expect, it } from \"vitest\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\ndescribe(\"TemplateLoader\", () => {\n const logger = new Logger(false);\n const loader = new TemplateLoader(logger);\n\n it(\"should load demo template from local path\", async () => {\n // Find the template directory relative to the package root\n const packageRoot = path.resolve(__dirname, \"../..\");\n const templatePath = path.resolve(packageRoot, \"../sdkgen-demo-template\");\n const { config, templateDir } = await loader.loadTemplate(templatePath);\n\n expect(config).toBeDefined();\n expect(config.name).toBe(\"hello-world-template\");\n expect(config.description).toBe(\"A simple Hello World SDK template\");\n expect(config.prompts).toHaveLength(3);\n expect(config.templateFiles).toEqual([\"**/*.ejs\"]);\n expect(config.staticFiles).toEqual([\"_gitignore\"]);\n expect(config.hooks).toBeDefined();\n expect(templateDir).toBe(templatePath);\n });\n\n it(\"should load the built-in default template from local path\", async () => {\n const packageRoot = path.resolve(__dirname, \"../..\");\n const templatePath = path.resolve(packageRoot, \"templates/default\");\n const { config, templateDir } = await loader.loadTemplate(templatePath);\n\n expect(config).toBeDefined();\n expect(config.name).toBe(\"default-template\");\n expect(templateDir).toContain(\"templates/default\");\n });\n\n it(\"should throw error for non-existent template\", async () => {\n await expect(loader.loadTemplate(\"/non/existent/template\")).rejects.toThrow(\n \"Template directory does not exist\",\n );\n });\n\n it(\"should throw error for template without config\", async () => {\n // Create a temporary directory without template.config.js for this test\n const tempDir = path.join(__dirname, \"../../build/temp-template\");\n const fs = await import(\"fs-extra\");\n await fs.ensureDir(tempDir);\n\n try {\n await expect(loader.loadTemplate(tempDir)).rejects.toThrow(\n \"Template configuration not found\",\n );\n } finally {\n await fs.remove(tempDir);\n }\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,MAAM,EAAEC,cAAc,QAAQ,6BAA6B;AACpE,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,aAAa,QAAQ,KAAK;AACnC,SAASC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,QAAQ,QAAQ;AAE7C,MAAMC,SAAS,GAAGL,IAAI,CAACM,OAAO,CAACL,aAAa,CAACM,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAE9DP,QAAQ,CAAC,gBAAgB,EAAE,MAAM;EAC/B,MAAMQ,MAAM,GAAG,IAAIZ,MAAM,CAAC,KAAK,CAAC;EAChC,MAAMa,MAAM,GAAG,IAAIZ,cAAc,CAACW,MAAM,CAAC;EAEzCN,EAAE,CAAC,2CAA2C,EAAE,YAAY;IAC1D;IACA,MAAMQ,WAAW,GAAGZ,IAAI,CAACa,OAAO,CAACR,SAAS,EAAE,OAAO,CAAC;IACpD,MAAMS,YAAY,GAAGd,IAAI,CAACa,OAAO,CAACD,WAAW,EAAE,yBAAyB,CAAC;IACzE,MAAM;MAAEG,MAAM;MAAEC;IAAY,CAAC,GAAG,MAAML,MAAM,CAACM,YAAY,CAACH,YAAY,CAAC;IAEvEX,MAAM,CAACY,MAAM,CAAC,CAACG,WAAW,CAAC,CAAC;IAC5Bf,MAAM,CAACY,MAAM,CAACI,IAAI,CAAC,CAACC,IAAI,CAAC,sBAAsB,CAAC;IAChDjB,MAAM,CAACY,MAAM,CAACM,WAAW,CAAC,CAACD,IAAI,CAAC,mCAAmC,CAAC;IACpEjB,MAAM,CAACY,MAAM,CAACO,OAAO,CAAC,CAACC,YAAY,CAAC,CAAC,CAAC;IACtCpB,MAAM,C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;MACF,MAAM5B,MAAM,CAACQ,MAAM,CAACM,YAAY,CAACc,OAAO,CAAC,CAAC,CAACF,OAAO,CAACC,OAAO,CACxD,kCACF,CAAC;IACH,CAAC,SAAS;MACR,MAAMG,EAAE,CAACE,MAAM,CAACJ,OAAO,CAAC;IAC1B;EACF,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -14,160 +14,37 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
- import fs from "fs-extra";
17
+ import { createProject } from "@palantir/pack.codegen.core";
18
+ import { findUp } from "find-up";
18
19
  import path from "path";
19
- import { ContextBuilder } from "../core/contextBuilder.js";
20
- import { Generator } from "../core/generator.js";
21
- import { SchemaParser } from "../core/schemaParser.js";
22
- import { TemplateLoader } from "../core/templateLoader.js";
23
- import { Logger } from "../utils/logger.js";
24
- import { promptUser } from "../utils/prompts.js";
25
- export async function createCommand(projectName, options) {
26
- const logger = new Logger(options.verbose);
27
- try {
28
- logger.info(`Creating SDK project: ${projectName}`);
29
-
30
- // Set output path
31
- const outputPath = path.resolve(projectName);
32
-
33
- // Check if directory already exists
34
- if (await fs.pathExists(outputPath)) {
35
- if (options.overwrite) {
36
- logger.info(`Directory ${projectName} exists, continuing with overwrite`);
37
- } else {
38
- throw new Error(`Directory ${projectName} already exists`);
39
- }
40
- }
41
-
42
- // Load template
43
- const templateLoader = new TemplateLoader(logger);
44
- const templateName = options.template || "default";
45
- logger.debug(`Loading template: ${templateName}`);
46
- const {
47
- config: templateConfig,
48
- templateDir
49
- } = await templateLoader.loadTemplate(templateName);
50
- logger.success(`Template loaded: ${templateConfig.name}`);
51
-
52
- // Load schema
53
- const schemaParser = new SchemaParser(logger);
54
- const schema = await schemaParser.loadSchema(options.schema);
55
- if (options.schema) {
56
- logger.success("Schema loaded successfully");
57
- }
58
-
59
- // Prompt user for additional configuration
60
- let answers = {};
61
-
62
- // Load config from file or object if provided
63
- if (options.config) {
64
- if (typeof options.config === "string") {
65
- // Load from file path
66
- try {
67
- const configPath = path.resolve(options.config);
68
- const configContent = await fs.readFile(configPath, "utf-8");
69
- answers = JSON.parse(configContent);
70
- logger.debug(`Using config from ${configPath}: ${JSON.stringify(answers)}`);
71
- } catch (error) {
72
- throw new Error(`Failed to load config file: ${error instanceof Error ? error.message : String(error)}`);
73
- }
74
- } else {
75
- // Use provided object directly
76
- answers = options.config;
77
- logger.debug(`Using config object: ${JSON.stringify(answers)}`);
78
- }
79
- }
80
-
81
- // Transform schema if transformer is defined
82
- let transformedSchema = schema;
83
- if (templateConfig.transformers?.default) {
84
- logger.debug("Applying schema transformer");
85
- const transformer = templateConfig.transformers.default;
86
- if (typeof transformer === "string") {
87
- // Load transformer from file
88
- const transformerPath = path.join(templateDir, transformer);
89
- const {
90
- default: transformFn
91
- } = await import(transformerPath);
92
- transformedSchema = await transformFn(schema, {
93
- projectName,
94
- schema,
95
- answers,
96
- templateConfig,
97
- schemaPath: options.schema,
98
- outputPath,
99
- options: {
100
- skipInstall: options.skipInstall,
101
- verbose: options.verbose,
102
- dryRun: options.dryRun
103
- },
104
- utils: {}
105
- });
106
- } else if (typeof transformer === "function") {
107
- transformedSchema = await transformer(schema, {
108
- projectName,
109
- schema,
110
- answers,
111
- templateConfig,
112
- schemaPath: options.schema,
113
- outputPath,
114
- options: {
115
- skipInstall: options.skipInstall,
116
- verbose: options.verbose,
117
- dryRun: options.dryRun
118
- },
119
- utils: {}
120
- });
121
- }
122
- }
123
- if (templateConfig.prompts && templateConfig.prompts.length > 0) {
124
- if (options.nonInteractive || process.env.CI) {
125
- // Use default values from prompts for missing answers
126
- for (const prompt of templateConfig.prompts) {
127
- if (!(prompt.name in answers) && prompt.default !== undefined) {
128
- answers[prompt.name] = prompt.default;
129
- }
130
- }
131
- logger.debug("Running in non-interactive mode with defaults");
132
- } else {
133
- // Filter out prompts that already have answers
134
- const unansweredPrompts = templateConfig.prompts.filter(prompt => !(prompt.name in answers));
135
- if (unansweredPrompts.length > 0) {
136
- logger.info("Please answer the following questions:");
137
- const newAnswers = await promptUser(unansweredPrompts);
138
- answers = {
139
- ...answers,
140
- ...newAnswers
141
- };
142
- }
143
- }
144
- }
145
-
146
- // Build generator context
147
- const contextBuilder = new ContextBuilder();
148
- const context = contextBuilder.build(projectName, transformedSchema, answers, templateConfig, outputPath, {
149
- skipInstall: options.skipInstall,
150
- verbose: options.verbose,
151
- dryRun: options.dryRun
152
- }, options.schema);
20
+ import { fileURLToPath } from "url";
21
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
153
22
 
154
- // Generate SDK
155
- const generator = new Generator(context, templateDir, logger);
156
- await generator.generate();
157
- if (!options.dryRun) {
158
- logger.success(`🎉 SDK project created successfully!`);
159
- logger.info(`Next steps:`);
160
- logger.info(` cd ${projectName}`);
161
- if (options.skipInstall) {
162
- logger.info(` npm install`);
163
- }
164
- logger.info(` npm run build`);
165
- } else {
166
- logger.success("✨ Dry run completed. No files were written.");
23
+ /**
24
+ * Resolves the template reference to an absolute path when it refers to this
25
+ * package's built-in `default` template, otherwise passes it through so the
26
+ * engine can resolve local paths or installed npm packages.
27
+ */
28
+ async function resolveTemplate(template) {
29
+ if (!template || template === "default") {
30
+ const packageJsonPath = await findUp("package.json", {
31
+ cwd: __dirname
32
+ });
33
+ if (!packageJsonPath) {
34
+ throw new Error("Could not find package.json");
167
35
  }
168
- } catch (error) {
169
- logger.error(`Failed to create SDK: ${error instanceof Error ? error.message : String(error)}`);
170
- process.exit(1);
36
+ return path.join(path.dirname(packageJsonPath), "templates/default");
171
37
  }
38
+ return template;
39
+ }
40
+ export async function createCommand(projectName, options) {
41
+ const template = await resolveTemplate(options.template);
42
+ await createProject(projectName, {
43
+ ...options,
44
+ template,
45
+ messaging: {
46
+ entity: "SDK project"
47
+ }
48
+ });
172
49
  }
173
50
  //# sourceMappingURL=create.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.js","names":["fs","path","ContextBuilder","Generator","SchemaParser","TemplateLoader","Logger","promptUser","createCommand","projectName","options","logger","verbose","info","outputPath","resolve","pathExists","overwrite","Error","templateLoader","templateName","template","debug","config","templateConfig","templateDir","loadTemplate","success","name","schemaParser","schema","loadSchema","answers","configPath","configContent","readFile","JSON","parse","stringify","error","message","String","transformedSchema","transformers","default","transformer","transformerPath","join","transformFn","schemaPath","skipInstall","dryRun","utils","prompts","length","nonInteractive","process","env","CI","prompt","undefined","unansweredPrompts","filter","newAnswers","contextBuilder","context","build","generator","generate","exit"],"sources":["create.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport fs from \"fs-extra\";\nimport path from \"path\";\nimport { ContextBuilder } from \"../core/contextBuilder.js\";\nimport { Generator } from \"../core/generator.js\";\nimport { SchemaParser } from \"../core/schemaParser.js\";\nimport { TemplateLoader } from \"../core/templateLoader.js\";\nimport type { CreateCommandOptions, TemplateUtils } from \"../types/index.js\";\nimport { Logger } from \"../utils/logger.js\";\nimport { promptUser } from \"../utils/prompts.js\";\n\nexport async function createCommand(\n projectName: string,\n options: CreateCommandOptions,\n): Promise<void> {\n const logger = new Logger(options.verbose);\n\n try {\n logger.info(`Creating SDK project: ${projectName}`);\n\n // Set output path\n const outputPath = path.resolve(projectName);\n\n // Check if directory already exists\n if (await fs.pathExists(outputPath)) {\n if (options.overwrite) {\n logger.info(`Directory ${projectName} exists, continuing with overwrite`);\n } else {\n throw new Error(`Directory ${projectName} already exists`);\n }\n }\n\n // Load template\n const templateLoader = new TemplateLoader(logger);\n const templateName = options.template || \"default\";\n logger.debug(`Loading template: ${templateName}`);\n\n const { config: templateConfig, templateDir } = await templateLoader.loadTemplate(templateName);\n logger.success(`Template loaded: ${templateConfig.name}`);\n\n // Load schema\n const schemaParser = new SchemaParser(logger);\n const schema = await schemaParser.loadSchema(options.schema);\n if (options.schema) {\n logger.success(\"Schema loaded successfully\");\n }\n\n // Prompt user for additional configuration\n let answers: Record<string, unknown> = {};\n\n // Load config from file or object if provided\n if (options.config) {\n if (typeof options.config === \"string\") {\n // Load from file path\n try {\n const configPath = path.resolve(options.config);\n const configContent = await fs.readFile(configPath, \"utf-8\");\n answers = JSON.parse(configContent) as Record<string, unknown>;\n logger.debug(`Using config from ${configPath}: ${JSON.stringify(answers)}`);\n } catch (error) {\n throw new Error(\n `Failed to load config file: ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n } else {\n // Use provided object directly\n answers = options.config;\n logger.debug(`Using config object: ${JSON.stringify(answers)}`);\n }\n }\n\n // Transform schema if transformer is defined\n let transformedSchema = schema;\n if (templateConfig.transformers?.default) {\n logger.debug(\"Applying schema transformer\");\n const transformer = templateConfig.transformers.default;\n\n if (typeof transformer === \"string\") {\n // Load transformer from file\n const transformerPath = path.join(templateDir, transformer);\n const { default: transformFn } = await import(transformerPath) as {\n default: (schema: unknown, context: unknown) => Promise<unknown>;\n };\n transformedSchema = await transformFn(schema, {\n projectName,\n schema,\n answers,\n templateConfig,\n schemaPath: options.schema,\n outputPath,\n options: {\n skipInstall: options.skipInstall,\n verbose: options.verbose,\n dryRun: options.dryRun,\n },\n utils: {} as TemplateUtils,\n });\n } else if (typeof transformer === \"function\") {\n transformedSchema = await transformer(schema, {\n projectName,\n schema,\n answers,\n templateConfig,\n schemaPath: options.schema,\n outputPath,\n options: {\n skipInstall: options.skipInstall,\n verbose: options.verbose,\n dryRun: options.dryRun,\n },\n utils: {} as TemplateUtils,\n });\n }\n }\n\n if (templateConfig.prompts && templateConfig.prompts.length > 0) {\n if (options.nonInteractive || process.env.CI) {\n // Use default values from prompts for missing answers\n for (const prompt of templateConfig.prompts) {\n if (!(prompt.name in answers) && prompt.default !== undefined) {\n answers[prompt.name] = prompt.default;\n }\n }\n logger.debug(\"Running in non-interactive mode with defaults\");\n } else {\n // Filter out prompts that already have answers\n const unansweredPrompts = templateConfig.prompts.filter(\n prompt => !(prompt.name in answers),\n );\n if (unansweredPrompts.length > 0) {\n logger.info(\"Please answer the following questions:\");\n const newAnswers = await promptUser(unansweredPrompts);\n answers = { ...answers, ...newAnswers };\n }\n }\n }\n\n // Build generator context\n const contextBuilder = new ContextBuilder();\n const context = contextBuilder.build(\n projectName,\n transformedSchema,\n answers,\n templateConfig,\n outputPath,\n {\n skipInstall: options.skipInstall,\n verbose: options.verbose,\n dryRun: options.dryRun,\n },\n options.schema,\n );\n\n // Generate SDK\n const generator = new Generator(context, templateDir, logger);\n await generator.generate();\n\n if (!options.dryRun) {\n logger.success(`🎉 SDK project created successfully!`);\n logger.info(`Next steps:`);\n logger.info(` cd ${projectName}`);\n if (options.skipInstall) {\n logger.info(` npm install`);\n }\n logger.info(` npm run build`);\n } else {\n logger.success(\"✨ Dry run completed. No files were written.\");\n }\n } catch (error) {\n logger.error(`Failed to create SDK: ${error instanceof Error ? error.message : String(error)}`);\n process.exit(1);\n }\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,EAAE,MAAM,UAAU;AACzB,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,cAAc,QAAQ,2BAA2B;AAC1D,SAASC,SAAS,QAAQ,sBAAsB;AAChD,SAASC,YAAY,QAAQ,yBAAyB;AACtD,SAASC,cAAc,QAAQ,2BAA2B;AAE1D,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAASC,UAAU,QAAQ,qBAAqB;AAEhD,OAAO,eAAeC,aAAaA,CACjCC,WAAmB,EACnBC,OAA6B,EACd;EACf,MAAMC,MAAM,GAAG,IAAIL,MAAM,CAACI,OAAO,CAACE,OAAO,CAAC;EAE1C,IAAI;IACFD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FiB,OAAO,CAACa,IAAI,CAAC,CAAC,CAAC;EACjB;AACF","ignoreList":[]}
1
+ {"version":3,"file":"create.js","names":["createProject","findUp","path","fileURLToPath","__dirname","dirname","import","meta","url","resolveTemplate","template","packageJsonPath","cwd","Error","join","createCommand","projectName","options","messaging","entity"],"sources":["create.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type CreateCommandOptions, createProject } from \"@palantir/pack.codegen.core\";\nimport { findUp } from \"find-up\";\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\n\n/**\n * Resolves the template reference to an absolute path when it refers to this\n * package's built-in `default` template, otherwise passes it through so the\n * engine can resolve local paths or installed npm packages.\n */\nasync function resolveTemplate(template?: string): Promise<string> {\n if (!template || template === \"default\") {\n const packageJsonPath = await findUp(\"package.json\", { cwd: __dirname });\n if (!packageJsonPath) {\n throw new Error(\"Could not find package.json\");\n }\n return path.join(path.dirname(packageJsonPath), \"templates/default\");\n }\n return template;\n}\n\nexport async function createCommand(\n projectName: string,\n options: CreateCommandOptions,\n): Promise<void> {\n const template = await resolveTemplate(options.template);\n await createProject(projectName, {\n ...options,\n template,\n messaging: { entity: \"SDK project\" },\n });\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAAoCA,aAAa,QAAQ,6BAA6B;AACtF,SAASC,MAAM,QAAQ,SAAS;AAChC,OAAOC,IAAI,MAAM,MAAM;AACvB,SAASC,aAAa,QAAQ,KAAK;AAEnC,MAAMC,SAAS,GAAGF,IAAI,CAACG,OAAO,CAACF,aAAa,CAACG,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;;AAE9D;AACA;AACA;AACA;AACA;AACA,eAAeC,eAAeA,CAACC,QAAiB,EAAmB;EACjE,IAAI,CAACA,QAAQ,IAAIA,QAAQ,KAAK,SAAS,EAAE;IACvC,MAAMC,eAAe,GAAG,MAAMV,MAAM,CAAC,cAAc,EAAE;MAAEW,GAAG,EAAER;IAAU,CAAC,CAAC;IACxE,IAAI,CAACO,eAAe,EAAE;MACpB,MAAM,IAAIE,KAAK,CAAC,6BAA6B,CAAC;IAChD;IACA,OAAOX,IAAI,CAACY,IAAI,CAACZ,IAAI,CAACG,OAAO,CAACM,eAAe,CAAC,EAAE,mBAAmB,CAAC;EACtE;EACA,OAAOD,QAAQ;AACjB;AAEA,OAAO,eAAeK,aAAaA,CACjCC,WAAmB,EACnBC,OAA6B,EACd;EACf,MAAMP,QAAQ,GAAG,MAAMD,eAAe,CAACQ,OAAO,CAACP,QAAQ,CAAC;EACxD,MAAMV,aAAa,CAACgB,WAAW,EAAE;IAC/B,GAAGC,OAAO;IACVP,QAAQ;IACRQ,SAAS,EAAE;MAAEC,MAAM,EAAE;IAAc;EACrC,CAAC,CAAC;AACJ","ignoreList":[]}
@@ -14,13 +14,7 @@
14
14
  * limitations under the License.
15
15
  */
16
16
 
17
+ export { ContextBuilder, createTemplateUtils, Generator, Logger, promptUser, SchemaParser, TemplateLoader } from "@palantir/pack.codegen.core";
17
18
  export { cli } from "./cli.js";
18
19
  export { createCommand } from "./commands/create.js";
19
- export { ContextBuilder } from "./core/contextBuilder.js";
20
- export { Generator } from "./core/generator.js";
21
- export { SchemaParser } from "./core/schemaParser.js";
22
- export { TemplateLoader } from "./core/templateLoader.js";
23
- export { Logger } from "./utils/logger.js";
24
- export { promptUser } from "./utils/prompts.js";
25
- export { createTemplateUtils } from "./utils/templateUtils.js";
26
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["cli","createCommand","ContextBuilder","Generator","SchemaParser","TemplateLoader","Logger","promptUser","createTemplateUtils"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport { cli } from \"./cli.js\";\nexport { createCommand } from \"./commands/create.js\";\nexport { ContextBuilder } from \"./core/contextBuilder.js\";\nexport { Generator } from \"./core/generator.js\";\nexport { SchemaParser } from \"./core/schemaParser.js\";\nexport { TemplateLoader } from \"./core/templateLoader.js\";\nexport type * from \"./types/index.js\";\nexport { Logger } from \"./utils/logger.js\";\nexport { promptUser } from \"./utils/prompts.js\";\nexport { createTemplateUtils } from \"./utils/templateUtils.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,GAAG,QAAQ,UAAU;AAC9B,SAASC,aAAa,QAAQ,sBAAsB;AACpD,SAASC,cAAc,QAAQ,0BAA0B;AACzD,SAASC,SAAS,QAAQ,qBAAqB;AAC/C,SAASC,YAAY,QAAQ,wBAAwB;AACrD,SAASC,cAAc,QAAQ,0BAA0B;AAEzD,SAASC,MAAM,QAAQ,mBAAmB;AAC1C,SAASC,UAAU,QAAQ,oBAAoB;AAC/C,SAASC,mBAAmB,QAAQ,0BAA0B","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["ContextBuilder","createTemplateUtils","Generator","Logger","promptUser","SchemaParser","TemplateLoader","cli","createCommand"],"sources":["index.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport {\n ContextBuilder,\n createTemplateUtils,\n Generator,\n Logger,\n promptUser,\n SchemaParser,\n TemplateLoader,\n} from \"@palantir/pack.codegen.core\";\nexport type * from \"@palantir/pack.codegen.core\";\nexport { cli } from \"./cli.js\";\nexport { createCommand } from \"./commands/create.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SACEA,cAAc,EACdC,mBAAmB,EACnBC,SAAS,EACTC,MAAM,EACNC,UAAU,EACVC,YAAY,EACZC,cAAc,QACT,6BAA6B;AAEpC,SAASC,GAAG,QAAQ,UAAU;AAC9B,SAASC,aAAa,QAAQ,sBAAsB","ignoreList":[]}
@@ -1,3 +1,3 @@
1
- import type { CreateCommandOptions } from "../types/index.js";
1
+ import { type CreateCommandOptions } from "@palantir/pack.codegen.core";
2
2
  export declare function createCommand(projectName: string, options: CreateCommandOptions): Promise<void>;
3
3
  //# sourceMappingURL=create.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/commands/create.ts"],"names":[],"mappings":"AAsBA,OAAO,KAAK,EAAE,oBAAoB,EAAiB,MAAM,mBAAmB,CAAC;AAI7E,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CA8Jf"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/commands/create.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,oBAAoB,EAAiB,MAAM,6BAA6B,CAAC;AAuBvF,wBAAsB,aAAa,CACjC,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,IAAI,CAAC,CAOf"}
@@ -1,11 +1,5 @@
1
+ export { ContextBuilder, createTemplateUtils, Generator, Logger, promptUser, SchemaParser, TemplateLoader, } from "@palantir/pack.codegen.core";
2
+ export type * from "@palantir/pack.codegen.core";
1
3
  export { cli } from "./cli.js";
2
4
  export { createCommand } from "./commands/create.js";
3
- export { ContextBuilder } from "./core/contextBuilder.js";
4
- export { Generator } from "./core/generator.js";
5
- export { SchemaParser } from "./core/schemaParser.js";
6
- export { TemplateLoader } from "./core/templateLoader.js";
7
- export type * from "./types/index.js";
8
- export { Logger } from "./utils/logger.js";
9
- export { promptUser } from "./utils/prompts.js";
10
- export { createTemplateUtils } from "./utils/templateUtils.js";
11
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,mBAAmB,kBAAkB,CAAC;AACtC,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,SAAS,EACT,MAAM,EACN,UAAU,EACV,YAAY,EACZ,cAAc,GACf,MAAM,6BAA6B,CAAC;AACrC,mBAAmB,6BAA6B,CAAC;AACjD,OAAO,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAC/B,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@palantir/pack.sdkgen",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "Generic Typescript SDK generator CLI",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -18,18 +18,13 @@
18
18
  },
19
19
  "dependencies": {
20
20
  "commander": "^14.0.0",
21
- "consola": "^3.4.2",
22
- "ejs": "^3.1.10",
23
21
  "find-up": "^8.0.0",
24
- "fs-extra": "^11.3.2",
25
- "glob": "^13.0.0",
26
- "inquirer": "^13.0.1"
22
+ "@palantir/pack.codegen.core": "0.2.0"
27
23
  },
28
24
  "devDependencies": {
29
- "@types/ejs": "^3.1.5",
30
25
  "@types/fs-extra": "^11.0.4",
31
- "@types/inquirer": "^9.0.9",
32
26
  "@types/node": "^20.19.17",
27
+ "fs-extra": "^11.3.2",
33
28
  "prettier": "^3.7.3",
34
29
  "rimraf": "^6.1.2",
35
30
  "tslib": "^2.8.1",
@@ -1,67 +0,0 @@
1
- /*
2
- * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
3
- *
4
- * Licensed under the Apache License, Version 2.0 (the "License");
5
- * you may not use this file except in compliance with the License.
6
- * You may obtain a copy of the License at
7
- *
8
- * http://www.apache.org/licenses/LICENSE-2.0
9
- *
10
- * Unless required by applicable law or agreed to in writing, software
11
- * distributed under the License is distributed on an "AS IS" BASIS,
12
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
- * See the License for the specific language governing permissions and
14
- * limitations under the License.
15
- */
16
-
17
- import path from "path";
18
- import { fileURLToPath } from "url";
19
- import { describe, expect, it } from "vitest";
20
- import { SchemaParser } from "../core/schemaParser.js";
21
- import { Logger } from "../utils/logger.js";
22
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
23
- const fixturesDir = path.join(__dirname, "fixtures");
24
- describe("SchemaParser", () => {
25
- const logger = new Logger(false);
26
- const parser = new SchemaParser(logger);
27
- it("should load JSON schema", async () => {
28
- const schemaPath = path.join(fixturesDir, "test-schema.json");
29
- const schema = await parser.loadSchema(schemaPath);
30
- expect(schema).toMatchObject({
31
- version: "1.0.0",
32
- description: "Test API Schema",
33
- types: {
34
- User: {
35
- id: "string",
36
- name: "string",
37
- email: "string",
38
- createdAt: "Date"
39
- },
40
- Post: {
41
- id: "string",
42
- title: "string",
43
- content: "string",
44
- authorId: "string"
45
- },
46
- Comment: {
47
- id: "string",
48
- postId: "string",
49
- userId: "string",
50
- content: "string",
51
- createdAt: "Date"
52
- }
53
- }
54
- });
55
- });
56
- it("should return null when no schema provided", async () => {
57
- const schema = await parser.loadSchema();
58
- expect(schema).toBeNull();
59
- });
60
- it("should throw error for non-existent file", async () => {
61
- await expect(parser.loadSchema("/non/existent/file.json")).rejects.toThrow("Schema path not found");
62
- });
63
- it("should throw error for unsupported file type", async () => {
64
- await expect(parser.loadSchema("test.txt")).rejects.toThrow("Schema path not found");
65
- });
66
- });
67
- //# sourceMappingURL=schemaParser.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"schemaParser.test.js","names":["path","fileURLToPath","describe","expect","it","SchemaParser","Logger","__dirname","dirname","import","meta","url","fixturesDir","join","logger","parser","schemaPath","schema","loadSchema","toMatchObject","version","description","types","User","id","name","email","createdAt","Post","title","content","authorId","Comment","postId","userId","toBeNull","rejects","toThrow"],"sources":["schemaParser.test.ts"],"sourcesContent":["/*\n * Copyright 2025 Palantir Technologies, Inc. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport path from \"path\";\nimport { fileURLToPath } from \"url\";\nimport { describe, expect, it } from \"vitest\";\nimport { SchemaParser } from \"../core/schemaParser.js\";\nimport { Logger } from \"../utils/logger.js\";\nimport type { TestSchema } from \"./types/testTypes.js\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\nconst fixturesDir = path.join(__dirname, \"fixtures\");\n\ndescribe(\"SchemaParser\", () => {\n const logger = new Logger(false);\n const parser = new SchemaParser(logger);\n\n it(\"should load JSON schema\", async () => {\n const schemaPath = path.join(fixturesDir, \"test-schema.json\");\n const schema = await parser.loadSchema(schemaPath) as TestSchema;\n\n expect(schema).toMatchObject({\n version: \"1.0.0\",\n description: \"Test API Schema\",\n types: {\n User: {\n id: \"string\",\n name: \"string\",\n email: \"string\",\n createdAt: \"Date\",\n },\n Post: {\n id: \"string\",\n title: \"string\",\n content: \"string\",\n authorId: \"string\",\n },\n Comment: {\n id: \"string\",\n postId: \"string\",\n userId: \"string\",\n content: \"string\",\n createdAt: \"Date\",\n },\n },\n });\n });\n\n it(\"should return null when no schema provided\", async () => {\n const schema = await parser.loadSchema();\n expect(schema).toBeNull();\n });\n\n it(\"should throw error for non-existent file\", async () => {\n await expect(parser.loadSchema(\"/non/existent/file.json\")).rejects.toThrow(\n \"Schema path not found\",\n );\n });\n\n it(\"should throw error for unsupported file type\", async () => {\n await expect(parser.loadSchema(\"test.txt\")).rejects.toThrow(\n \"Schema path not found\",\n );\n });\n});\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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