@palantir/pack.sdkgen 0.0.1-beta.1

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 (80) hide show
  1. package/LICENSE.txt +13 -0
  2. package/README.md +589 -0
  3. package/bin/cli.ts +7 -0
  4. package/build/esm/__tests__/createCommand.test.js +157 -0
  5. package/build/esm/__tests__/createCommand.test.js.map +1 -0
  6. package/build/esm/__tests__/generator.test.js +190 -0
  7. package/build/esm/__tests__/generator.test.js.map +1 -0
  8. package/build/esm/__tests__/schemaParser.test.js +67 -0
  9. package/build/esm/__tests__/schemaParser.test.js.map +1 -0
  10. package/build/esm/__tests__/templateLoader.test.js +67 -0
  11. package/build/esm/__tests__/templateLoader.test.js.map +1 -0
  12. package/build/esm/__tests__/templateUtils.test.js +94 -0
  13. package/build/esm/__tests__/templateUtils.test.js.map +1 -0
  14. package/build/esm/__tests__/types/testTypes.js +2 -0
  15. package/build/esm/__tests__/types/testTypes.js.map +1 -0
  16. package/build/esm/cli.js +25 -0
  17. package/build/esm/cli.js.map +1 -0
  18. package/build/esm/commands/create.js +173 -0
  19. package/build/esm/commands/create.js.map +1 -0
  20. package/build/esm/core/contextBuilder.js +33 -0
  21. package/build/esm/core/contextBuilder.js.map +1 -0
  22. package/build/esm/core/generator.js +248 -0
  23. package/build/esm/core/generator.js.map +1 -0
  24. package/build/esm/core/hookRunner.js +68 -0
  25. package/build/esm/core/hookRunner.js.map +1 -0
  26. package/build/esm/core/schemaParser.js +50 -0
  27. package/build/esm/core/schemaParser.js.map +1 -0
  28. package/build/esm/core/templateLoader.js +99 -0
  29. package/build/esm/core/templateLoader.js.map +1 -0
  30. package/build/esm/index.js +26 -0
  31. package/build/esm/index.js.map +1 -0
  32. package/build/esm/types/index.js +2 -0
  33. package/build/esm/types/index.js.map +1 -0
  34. package/build/esm/utils/fileSystem.js +72 -0
  35. package/build/esm/utils/fileSystem.js.map +1 -0
  36. package/build/esm/utils/logger.js +44 -0
  37. package/build/esm/utils/logger.js.map +1 -0
  38. package/build/esm/utils/prompts.js +25 -0
  39. package/build/esm/utils/prompts.js.map +1 -0
  40. package/build/esm/utils/templateUtils.js +61 -0
  41. package/build/esm/utils/templateUtils.js.map +1 -0
  42. package/build/types/__tests__/createCommand.test.d.ts +2 -0
  43. package/build/types/__tests__/createCommand.test.d.ts.map +1 -0
  44. package/build/types/__tests__/generator.test.d.ts +2 -0
  45. package/build/types/__tests__/generator.test.d.ts.map +1 -0
  46. package/build/types/__tests__/schemaParser.test.d.ts +2 -0
  47. package/build/types/__tests__/schemaParser.test.d.ts.map +1 -0
  48. package/build/types/__tests__/templateLoader.test.d.ts +2 -0
  49. package/build/types/__tests__/templateLoader.test.d.ts.map +1 -0
  50. package/build/types/__tests__/templateUtils.test.d.ts +2 -0
  51. package/build/types/__tests__/templateUtils.test.d.ts.map +1 -0
  52. package/build/types/__tests__/types/testTypes.d.ts +38 -0
  53. package/build/types/__tests__/types/testTypes.d.ts.map +1 -0
  54. package/build/types/cli.d.ts +2 -0
  55. package/build/types/cli.d.ts.map +1 -0
  56. package/build/types/commands/create.d.ts +3 -0
  57. package/build/types/commands/create.d.ts.map +1 -0
  58. package/build/types/core/contextBuilder.d.ts +5 -0
  59. package/build/types/core/contextBuilder.d.ts.map +1 -0
  60. package/build/types/core/generator.d.ts +15 -0
  61. package/build/types/core/generator.d.ts.map +1 -0
  62. package/build/types/core/hookRunner.d.ts +3 -0
  63. package/build/types/core/hookRunner.d.ts.map +1 -0
  64. package/build/types/core/schemaParser.d.ts +7 -0
  65. package/build/types/core/schemaParser.d.ts.map +1 -0
  66. package/build/types/core/templateLoader.d.ts +12 -0
  67. package/build/types/core/templateLoader.d.ts.map +1 -0
  68. package/build/types/index.d.ts +11 -0
  69. package/build/types/index.d.ts.map +1 -0
  70. package/build/types/types/index.d.ts +68 -0
  71. package/build/types/types/index.d.ts.map +1 -0
  72. package/build/types/utils/fileSystem.d.ts +8 -0
  73. package/build/types/utils/fileSystem.d.ts.map +1 -0
  74. package/build/types/utils/logger.d.ts +11 -0
  75. package/build/types/utils/logger.d.ts.map +1 -0
  76. package/build/types/utils/prompts.d.ts +3 -0
  77. package/build/types/utils/prompts.d.ts.map +1 -0
  78. package/build/types/utils/templateUtils.d.ts +3 -0
  79. package/build/types/utils/templateUtils.d.ts.map +1 -0
  80. package/package.json +61 -0
@@ -0,0 +1,157 @@
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 fs from "fs-extra";
18
+ import path from "path";
19
+ import { fileURLToPath } from "url";
20
+ import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
21
+ import { createCommand } from "../commands/create.js";
22
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
23
+ const testOutputDir = path.join(__dirname, "../../test-output", "create-command");
24
+ describe("createCommand", () => {
25
+ beforeAll(async () => {
26
+ // Clean up before all tests run
27
+ await fs.remove(testOutputDir);
28
+ await fs.ensureDir(testOutputDir);
29
+ });
30
+ beforeEach(() => {
31
+ // Mock console methods to avoid cluttering test output
32
+ vi.spyOn(console, "log").mockImplementation(() => {});
33
+ vi.spyOn(console, "error").mockImplementation(() => {});
34
+ // Mock process.exit to prevent tests from exiting
35
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- Process.exit mock needs any type
36
+ vi.spyOn(process, "exit").mockImplementation(() => {});
37
+ });
38
+ afterEach(() => {
39
+ vi.restoreAllMocks();
40
+ });
41
+ it("should create SDK with demo template and schema", async () => {
42
+ const projectName = "demo-template-with-schema";
43
+ const outputPath = path.join(testOutputDir, projectName);
44
+ // Find the template directory relative to the package root
45
+ const packageRoot = path.resolve(__dirname, "../..");
46
+ const templatePath = path.resolve(packageRoot, "../sdkgen-demo-template");
47
+ const schemaPath = path.join(__dirname, "fixtures", "test-schema.json");
48
+
49
+ // Change to test directory to create project there
50
+ const originalCwd = process.cwd();
51
+ process.chdir(testOutputDir);
52
+ try {
53
+ await createCommand(projectName, {
54
+ template: templatePath,
55
+ schema: schemaPath,
56
+ skipInstall: true,
57
+ verbose: false,
58
+ dryRun: false,
59
+ config: {
60
+ greeting: "Hello from test!",
61
+ author: "Test Suite",
62
+ license: "MIT"
63
+ }
64
+ });
65
+
66
+ // Verify the SDK was created
67
+ expect(await fs.pathExists(outputPath)).toBe(true);
68
+ expect(await fs.pathExists(path.join(outputPath, "package.json"))).toBe(true);
69
+ expect(await fs.pathExists(path.join(outputPath, "src", "helloWorld.ts"))).toBe(true);
70
+
71
+ // Verify content
72
+ const packageJson = await fs.readJSON(path.join(outputPath, "package.json"));
73
+ expect(packageJson).toMatchObject({
74
+ name: projectName,
75
+ author: "Test Suite"
76
+ });
77
+ const helloWorldContent = await fs.readFile(path.join(outputPath, "src", "helloWorld.ts"), "utf8");
78
+ expect(helloWorldContent).toContain("'Hello from test!'");
79
+ } finally {
80
+ process.chdir(originalCwd);
81
+ }
82
+ });
83
+ it("should create SDK without schema", async () => {
84
+ const projectName = "default-template-no-schema";
85
+ const outputPath = path.join(testOutputDir, projectName);
86
+ const templatePath = path.resolve(__dirname, "../../templates/default");
87
+ const originalCwd = process.cwd();
88
+ process.chdir(testOutputDir);
89
+ try {
90
+ await createCommand(projectName, {
91
+ template: templatePath,
92
+ skipInstall: true,
93
+ verbose: false,
94
+ dryRun: false,
95
+ config: {
96
+ description: "SDK without schema",
97
+ author: "No Schema Author"
98
+ }
99
+ });
100
+ expect(await fs.pathExists(outputPath)).toBe(true);
101
+ expect(await fs.pathExists(path.join(outputPath, "package.json"))).toBe(true);
102
+ const packageJson = await fs.readJSON(path.join(outputPath, "package.json"));
103
+ expect(packageJson).toMatchObject({
104
+ description: "SDK without schema"
105
+ });
106
+ } finally {
107
+ process.chdir(originalCwd);
108
+ }
109
+ });
110
+ it("should handle dry-run mode", async () => {
111
+ const projectName = "dry-run-command-test";
112
+ const outputPath = path.join(testOutputDir, projectName);
113
+ const templatePath = path.resolve(__dirname, "../../templates/default");
114
+ const originalCwd = process.cwd();
115
+ process.chdir(testOutputDir);
116
+ try {
117
+ await createCommand(projectName, {
118
+ template: templatePath,
119
+ skipInstall: true,
120
+ verbose: false,
121
+ dryRun: true,
122
+ config: {
123
+ description: "Dry run SDK",
124
+ author: "Dry Run Author"
125
+ }
126
+ });
127
+
128
+ // In dry-run mode, directory should not be created
129
+ expect(await fs.pathExists(outputPath)).toBe(false);
130
+ } finally {
131
+ process.chdir(originalCwd);
132
+ }
133
+ });
134
+ it("should fail if directory already exists", async () => {
135
+ const projectName = "existing-directory-test";
136
+ const outputPath = path.join(testOutputDir, projectName);
137
+
138
+ // Create the directory first
139
+ await fs.ensureDir(outputPath);
140
+ const originalCwd = process.cwd();
141
+ process.chdir(testOutputDir);
142
+ try {
143
+ await createCommand(projectName, {
144
+ template: "default",
145
+ skipInstall: true
146
+ });
147
+ } catch (_error) {
148
+ // Error may or may not be thrown
149
+ } finally {
150
+ process.chdir(originalCwd);
151
+ }
152
+
153
+ // eslint-disable-next-line @typescript-eslint/unbound-method -- vi.mocked returns safe mock
154
+ expect(vi.mocked(process.exit)).toHaveBeenCalledWith(1);
155
+ });
156
+ });
157
+ //# sourceMappingURL=createCommand.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createCommand.test.js","names":["fs","path","fileURLToPath","afterEach","beforeAll","beforeEach","describe","expect","it","vi","createCommand","__dirname","dirname","import","meta","url","testOutputDir","join","remove","ensureDir","spyOn","console","mockImplementation","process","restoreAllMocks","projectName","outputPath","packageRoot","resolve","templatePath","schemaPath","originalCwd","cwd","chdir","template","schema","skipInstall","verbose","dryRun","config","greeting","author","license","pathExists","toBe","packageJson","readJSON","toMatchObject","name","helloWorldContent","readFile","toContain","description","_error","mocked","exit","toHaveBeenCalledWith"],"sources":["createCommand.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 { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from \"vitest\";\nimport { createCommand } from \"../commands/create.js\";\nimport type { PackageJson } from \"./types/testTypes.js\";\n\nconst __dirname = path.dirname(fileURLToPath(import.meta.url));\nconst testOutputDir = path.join(__dirname, \"../../test-output\", \"create-command\");\n\ndescribe(\"createCommand\", () => {\n beforeAll(async () => {\n // Clean up before all tests run\n await fs.remove(testOutputDir);\n await fs.ensureDir(testOutputDir);\n });\n\n beforeEach(() => {\n // Mock console methods to avoid cluttering test output\n vi.spyOn(console, \"log\").mockImplementation(() => {});\n vi.spyOn(console, \"error\").mockImplementation(() => {});\n // Mock process.exit to prevent tests from exiting\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument -- Process.exit mock needs any type\n vi.spyOn(process, \"exit\").mockImplementation((() => {}) as any);\n });\n\n afterEach(() => {\n vi.restoreAllMocks();\n });\n\n it(\"should create SDK with demo template and schema\", async () => {\n const projectName = \"demo-template-with-schema\";\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(__dirname, \"fixtures\", \"test-schema.json\");\n\n // Change to test directory to create project there\n const originalCwd = process.cwd();\n process.chdir(testOutputDir);\n\n try {\n await createCommand(projectName, {\n template: templatePath,\n schema: schemaPath,\n skipInstall: true,\n verbose: false,\n dryRun: false,\n config: {\n greeting: \"Hello from test!\",\n author: \"Test Suite\",\n license: \"MIT\",\n },\n });\n\n // Verify the SDK was created\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\n // Verify content\n const packageJson = await fs.readJSON(path.join(outputPath, \"package.json\")) as PackageJson;\n expect(packageJson).toMatchObject({\n name: projectName,\n author: \"Test Suite\",\n });\n\n const helloWorldContent = await fs.readFile(\n path.join(outputPath, \"src\", \"helloWorld.ts\"),\n \"utf8\",\n );\n expect(helloWorldContent).toContain(\"'Hello from test!'\");\n } finally {\n process.chdir(originalCwd);\n }\n });\n\n it(\"should create SDK without schema\", async () => {\n const projectName = \"default-template-no-schema\";\n const outputPath = path.join(testOutputDir, projectName);\n const templatePath = path.resolve(__dirname, \"../../templates/default\");\n\n const originalCwd = process.cwd();\n process.chdir(testOutputDir);\n\n try {\n await createCommand(projectName, {\n template: templatePath,\n skipInstall: true,\n verbose: false,\n dryRun: false,\n config: {\n description: \"SDK without schema\",\n author: \"No Schema Author\",\n },\n });\n\n expect(await fs.pathExists(outputPath)).toBe(true);\n expect(await fs.pathExists(path.join(outputPath, \"package.json\"))).toBe(true);\n\n const packageJson = await fs.readJSON(path.join(outputPath, \"package.json\")) as PackageJson;\n expect(packageJson).toMatchObject({\n description: \"SDK without schema\",\n });\n } finally {\n process.chdir(originalCwd);\n }\n });\n\n it(\"should handle dry-run mode\", async () => {\n const projectName = \"dry-run-command-test\";\n const outputPath = path.join(testOutputDir, projectName);\n const templatePath = path.resolve(__dirname, \"../../templates/default\");\n\n const originalCwd = process.cwd();\n process.chdir(testOutputDir);\n\n try {\n await createCommand(projectName, {\n template: templatePath,\n skipInstall: true,\n verbose: false,\n dryRun: true,\n config: {\n description: \"Dry run SDK\",\n author: \"Dry Run Author\",\n },\n });\n\n // In dry-run mode, directory should not be created\n expect(await fs.pathExists(outputPath)).toBe(false);\n } finally {\n process.chdir(originalCwd);\n }\n });\n\n it(\"should fail if directory already exists\", async () => {\n const projectName = \"existing-directory-test\";\n const outputPath = path.join(testOutputDir, projectName);\n\n // Create the directory first\n await fs.ensureDir(outputPath);\n\n const originalCwd = process.cwd();\n process.chdir(testOutputDir);\n\n try {\n await createCommand(projectName, {\n template: \"default\",\n skipInstall: true,\n });\n } catch (_error) {\n // Error may or may not be thrown\n } finally {\n process.chdir(originalCwd);\n }\n\n // eslint-disable-next-line @typescript-eslint/unbound-method -- vi.mocked returns safe mock\n expect(vi.mocked(process.exit)).toHaveBeenCalledWith(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,aAAa,QAAQ,KAAK;AACnC,SAASC,SAAS,EAAEC,SAAS,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,EAAE,EAAEC,EAAE,QAAQ,QAAQ;AACnF,SAASC,aAAa,QAAQ,uBAAuB;AAGrD,MAAMC,SAAS,GAAGV,IAAI,CAACW,OAAO,CAACV,aAAa,CAACW,MAAM,CAACC,IAAI,CAACC,GAAG,CAAC,CAAC;AAC9D,MAAMC,aAAa,GAAGf,IAAI,CAACgB,IAAI,CAACN,SAAS,EAAE,mBAAmB,EAAE,gBAAgB,CAAC;AAEjFL,QAAQ,CAAC,eAAe,EAAE,MAAM;EAC9BF,SAAS,CAAC,YAAY;IACpB;IACA,MAAMJ,EAAE,CAACkB,MAAM,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
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 fs from "fs-extra";
18
+ import path from "path";
19
+ import { fileURLToPath } from "url";
20
+ 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
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
27
+ const fixturesDir = path.join(__dirname, "fixtures");
28
+ const testOutputDir = path.join(__dirname, "../../test-output", "generator");
29
+ describe("Generator", () => {
30
+ beforeAll(async () => {
31
+ // Clean up before all tests run
32
+ await fs.remove(testOutputDir);
33
+ await fs.ensureDir(testOutputDir);
34
+ });
35
+ it("should generate SDK with demo template", async () => {
36
+ const projectName = "demo-template-sdk";
37
+ const outputPath = path.join(testOutputDir, projectName);
38
+ // Find the template directory relative to the package root
39
+ const packageRoot = path.resolve(__dirname, "../..");
40
+ const templatePath = path.resolve(packageRoot, "../sdkgen-demo-template");
41
+ const schemaPath = path.join(fixturesDir, "test-schema.json");
42
+
43
+ // Load template
44
+ const logger = new Logger(false);
45
+ const templateLoader = new TemplateLoader(logger);
46
+ const {
47
+ config: templateConfig,
48
+ templateDir
49
+ } = await templateLoader.loadTemplate(templatePath);
50
+
51
+ // Load schema
52
+ const schemaParser = new SchemaParser(logger);
53
+ const schema = await schemaParser.loadSchema(schemaPath);
54
+
55
+ // Transform schema if transformer exists
56
+ let transformedSchema = schema;
57
+ if (templateConfig.transformers?.default) {
58
+ const transformer = templateConfig.transformers.default;
59
+ if (typeof transformer === "string") {
60
+ const transformerPath = path.join(templateDir, transformer);
61
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- Dynamic import of transformer
62
+ const {
63
+ default: transformFn
64
+ } = await import(transformerPath);
65
+ transformedSchema = await transformFn(schema, {
66
+ projectName,
67
+ schema,
68
+ answers: {},
69
+ templateConfig,
70
+ schemaPath,
71
+ outputPath,
72
+ options: {
73
+ skipInstall: true
74
+ },
75
+ utils: {}
76
+ });
77
+ }
78
+ }
79
+
80
+ // Build context with test answers
81
+ const contextBuilder = new ContextBuilder();
82
+ const context = contextBuilder.build(projectName, transformedSchema, {
83
+ greeting: "Hello, Test!",
84
+ author: "Test Author",
85
+ license: "MIT"
86
+ }, templateConfig, outputPath, {
87
+ skipInstall: true,
88
+ verbose: false,
89
+ dryRun: false
90
+ }, schemaPath);
91
+
92
+ // Generate SDK
93
+ const generator = new Generator(context, templateDir, logger);
94
+ await generator.generate();
95
+
96
+ // Verify generated files
97
+ expect(await fs.pathExists(outputPath)).toBe(true);
98
+ expect(await fs.pathExists(path.join(outputPath, "package.json"))).toBe(true);
99
+ expect(await fs.pathExists(path.join(outputPath, "src", "helloWorld.ts"))).toBe(true);
100
+ expect(await fs.pathExists(path.join(outputPath, "src", "index.ts"))).toBe(true);
101
+ expect(await fs.pathExists(path.join(outputPath, "README.md"))).toBe(true);
102
+ expect(await fs.pathExists(path.join(outputPath, ".gitignore"))).toBe(true);
103
+ expect(await fs.pathExists(path.join(outputPath, "tsconfig.json"))).toBe(true);
104
+ expect(await fs.pathExists(path.join(outputPath, "jest.config.json"))).toBe(true);
105
+ expect(await fs.pathExists(path.join(outputPath, ".eslintrc.json"))).toBe(true);
106
+
107
+ // Verify package.json content
108
+ const packageJson = await fs.readJSON(path.join(outputPath, "package.json"));
109
+ expect(packageJson).toMatchObject({
110
+ name: projectName,
111
+ author: "Test Author",
112
+ license: "MIT"
113
+ });
114
+
115
+ // Verify generated TypeScript content
116
+ const helloWorldContent = await fs.readFile(path.join(outputPath, "src", "helloWorld.ts"), "utf8");
117
+ expect(helloWorldContent).toContain("private greeting: string = 'Hello, Test!'");
118
+ expect(helloWorldContent).toContain("Test Author");
119
+ expect(helloWorldContent).toContain("getSchemaInfo()");
120
+ });
121
+ it("should handle dry-run mode", async () => {
122
+ const projectName = "dry-run-mode-sdk";
123
+ const outputPath = path.join(testOutputDir, projectName);
124
+ // Find the template directory relative to the package root
125
+ const packageRoot = path.resolve(__dirname, "../..");
126
+ const templatePath = path.resolve(packageRoot, "../sdkgen-demo-template");
127
+ const schemaPath = path.join(fixturesDir, "test-schema.json");
128
+ const logger = new Logger(false);
129
+ const templateLoader = new TemplateLoader(logger);
130
+ const {
131
+ config: templateConfig,
132
+ templateDir
133
+ } = await templateLoader.loadTemplate(templatePath);
134
+ const schemaParser = new SchemaParser(logger);
135
+ const schema = await schemaParser.loadSchema(schemaPath);
136
+ const contextBuilder = new ContextBuilder();
137
+ const context = contextBuilder.build(projectName, schema, {
138
+ greeting: "Hello, Dry Run!",
139
+ author: "Dry Run Author",
140
+ license: "MIT"
141
+ }, templateConfig, outputPath, {
142
+ skipInstall: true,
143
+ verbose: false,
144
+ dryRun: true
145
+ }, schemaPath);
146
+ const generator = new Generator(context, templateDir, logger);
147
+ await generator.generate();
148
+
149
+ // In dry-run mode, no files should be created
150
+ expect(await fs.pathExists(outputPath)).toBe(false);
151
+ });
152
+ it("should generate SDK with default template", async () => {
153
+ const projectName = "default-template-sdk";
154
+ const outputPath = path.join(testOutputDir, projectName);
155
+ const templatePath = path.resolve(__dirname, "../../templates/default");
156
+ const logger = new Logger(false);
157
+ const templateLoader = new TemplateLoader(logger);
158
+ const {
159
+ config: templateConfig,
160
+ templateDir
161
+ } = await templateLoader.loadTemplate(templatePath);
162
+ const contextBuilder = new ContextBuilder();
163
+ const context = contextBuilder.build(projectName, {}, {
164
+ description: "Default template test SDK",
165
+ author: "Default Author"
166
+ }, templateConfig, outputPath, {
167
+ skipInstall: true,
168
+ verbose: false,
169
+ dryRun: false
170
+ });
171
+ const generator = new Generator(context, templateDir, logger);
172
+ await generator.generate();
173
+
174
+ // Verify generated files
175
+ expect(await fs.pathExists(outputPath)).toBe(true);
176
+ expect(await fs.pathExists(path.join(outputPath, "package.json"))).toBe(true);
177
+ expect(await fs.pathExists(path.join(outputPath, "src", "index.ts"))).toBe(true);
178
+ expect(await fs.pathExists(path.join(outputPath, "tsconfig.json"))).toBe(true);
179
+ expect(await fs.pathExists(path.join(outputPath, ".gitignore"))).toBe(true);
180
+
181
+ // Verify package.json content
182
+ const packageJson = await fs.readJSON(path.join(outputPath, "package.json"));
183
+ expect(packageJson).toMatchObject({
184
+ name: projectName,
185
+ description: "Default template test SDK",
186
+ author: "Default Author"
187
+ });
188
+ });
189
+ });
190
+ //# sourceMappingURL=generator.test.js.map
@@ -0,0 +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":"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C;IAChFrD,MAAM,CAAC,MAAML,EAAE,CAACyD,UAAU,CAACxD,IAAI,CAACiB,IAAI,CAACK,UAAU,EAAE,eAAe,CAAC,CAAC,CAAC,CAACmC,IAAI,CAAC,IAAI,CAAC;IAC9ErD,MAAM,CAAC,MAAML,EAAE,CAACyD,UAAU,CAACxD,IAAI,CAACiB,IAAI,CAACK,UAAU,EAAE,YAAY,CAAC,CAAC,CAAC,CAACmC,IAAI,CAAC,IAAI,CAAC;;IAE3E;IACA,MAAMC,WAAW,GAAG,MAAM3D,EAAE,CAAC4D,QAAQ,CAAC3D,IAAI,CAACiB,IAAI,CAACK,UAAU,EAAE,cAAc,CAAC,CAAgB;IAC3FlB,MAAM,CAACsD,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":[]}
@@ -0,0 +1,67 @@
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
@@ -0,0 +1 @@
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;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,YAAY,QAAQ,yBAAyB;AACtD,SAASC,MAAM,QAAQ,oBAAoB;AAG3C,MAAMC,SAAS,GAAGP,IAAI,CA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AC;EAEF/B,EAAE,CAAC,0CAA0C,EAAE,YAAY;IACzD,MAAMD,MAAM,CAACY,MAAM,CAACG,UAAU,CAAC,yBAAyB,CAAC,CAAC,CAACkB,OAAO,CAACC,OAAO,CACxE,uBACF,CAAC;EACH,CAAC,CAAC;EAEFjC,EAAE,CAAC,8CAA8C,EAAE,YAAY;IAC7D,MAAMD,MAAM,CAACY,MAAM,CAACG,UAAU,CAAC,UAAU,CAAC,CAAC,CAACkB,OAAO,CAACC,OAAO,CACzD,uBACF,CAAC;EACH,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,67 @@
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 { TemplateLoader } from "../core/templateLoader.js";
21
+ import { Logger } from "../utils/logger.js";
22
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
23
+ describe("TemplateLoader", () => {
24
+ const logger = new Logger(false);
25
+ const loader = new TemplateLoader(logger);
26
+ it("should load demo template from local path", async () => {
27
+ // Find the template directory relative to the package root
28
+ const packageRoot = path.resolve(__dirname, "../..");
29
+ const templatePath = path.resolve(packageRoot, "../sdkgen-demo-template");
30
+ const {
31
+ config,
32
+ templateDir
33
+ } = await loader.loadTemplate(templatePath);
34
+ expect(config).toBeDefined();
35
+ expect(config.name).toBe("hello-world-template");
36
+ expect(config.description).toBe("A simple Hello World SDK template");
37
+ expect(config.prompts).toHaveLength(3);
38
+ expect(config.templateFiles).toEqual(["**/*.ejs"]);
39
+ expect(config.staticFiles).toEqual(["_gitignore"]);
40
+ expect(config.hooks).toBeDefined();
41
+ expect(templateDir).toBe(templatePath);
42
+ });
43
+ it("should load default template", async () => {
44
+ const {
45
+ config,
46
+ templateDir
47
+ } = await loader.loadTemplate("default");
48
+ expect(config).toBeDefined();
49
+ expect(config.name).toBe("default-template");
50
+ expect(templateDir).toContain("templates/default");
51
+ });
52
+ it("should throw error for non-existent template", async () => {
53
+ await expect(loader.loadTemplate("/non/existent/template")).rejects.toThrow("Template directory does not exist");
54
+ });
55
+ it("should throw error for template without config", async () => {
56
+ // Create a temporary directory without template.config.js for this test
57
+ const tempDir = path.join(__dirname, "../../build/temp-template");
58
+ const fs = await import("fs-extra");
59
+ await fs.ensureDir(tempDir);
60
+ try {
61
+ await expect(loader.loadTemplate(tempDir)).rejects.toThrow("Template configuration not found");
62
+ } finally {
63
+ await fs.remove(tempDir);
64
+ }
65
+ });
66
+ });
67
+ //# sourceMappingURL=templateLoader.test.js.map
@@ -0,0 +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,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