@palantir/pack.sdkgen 0.0.1 → 0.0.2
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.
- package/bin/cli-node.js +6 -0
- package/build/esm/core/templateLoader.js +14 -2
- package/build/esm/core/templateLoader.js.map +1 -1
- package/build/types/core/templateLoader.d.ts +1 -0
- package/build/types/core/templateLoader.d.ts.map +1 -1
- package/package.json +6 -4
- package/templates/default/template/_gitignore +4 -0
- package/templates/default/template/package.json.ejs +17 -0
- package/templates/default/template/src/index.ts.ejs +16 -0
- package/templates/default/template/tsconfig.json.ejs +15 -0
- package/templates/default/template.config.js +22 -0
package/bin/cli-node.js
ADDED
|
@@ -30,8 +30,11 @@ export class TemplateLoader {
|
|
|
30
30
|
resolvedPath = path.resolve(templatePath);
|
|
31
31
|
this.logger.debug(`Loading local template from: ${resolvedPath}`);
|
|
32
32
|
} else if (templatePath === "default") {
|
|
33
|
-
// Use built-in default template
|
|
34
|
-
|
|
33
|
+
// Use built-in default template
|
|
34
|
+
// Find package root by looking for package.json
|
|
35
|
+
const currentFile = import.meta.url.replace("file://", "");
|
|
36
|
+
const packageRoot = await this.findPackageRoot(path.dirname(currentFile));
|
|
37
|
+
resolvedPath = path.join(packageRoot, "templates/default");
|
|
35
38
|
this.logger.debug(`Loading built-in default template`);
|
|
36
39
|
} else {
|
|
37
40
|
// Try to resolve as an npm package
|
|
@@ -63,6 +66,15 @@ export class TemplateLoader {
|
|
|
63
66
|
templateDir: resolvedPath
|
|
64
67
|
};
|
|
65
68
|
}
|
|
69
|
+
async findPackageRoot(startDir) {
|
|
70
|
+
const packageJsonPath = await findUp("package.json", {
|
|
71
|
+
cwd: startDir
|
|
72
|
+
});
|
|
73
|
+
if (!packageJsonPath) {
|
|
74
|
+
throw new Error("Could not find package.json");
|
|
75
|
+
}
|
|
76
|
+
return path.dirname(packageJsonPath);
|
|
77
|
+
}
|
|
66
78
|
async resolveNodeModule(moduleName) {
|
|
67
79
|
try {
|
|
68
80
|
const require = (await import("module")).createRequire(import.meta.url);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateLoader.js","names":["findUp","fs","path","pathToFileURL","TemplateLoader","constructor","logger","loadTemplate","templatePath","resolvedPath","startsWith","resolve","debug","
|
|
1
|
+
{"version":3,"file":"templateLoader.js","names":["findUp","fs","path","pathToFileURL","TemplateLoader","constructor","logger","loadTemplate","templatePath","resolvedPath","startsWith","resolve","debug","currentFile","import","meta","url","replace","packageRoot","findPackageRoot","dirname","join","packagePath","resolveNodeModule","Error","pathExists","configPath","configUrl","href","default","config","templateDir","startDir","packageJsonPath","cwd","moduleName","require","createRequire","modulePath","directory","pkgPath","pkg","readJson","name","undefined","error","message","String","process"],"sources":["templateLoader.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 { findUp } from \"find-up\";\nimport fs from \"fs-extra\";\nimport path from \"path\";\nimport { pathToFileURL } from \"url\";\nimport type { TemplateConfig } from \"../types/index.js\";\nimport type { Logger } from \"../utils/logger.js\";\n\nexport class TemplateLoader {\n constructor(private readonly logger: Logger) {}\n\n async loadTemplate(templatePath: string): Promise<{\n config: TemplateConfig;\n templateDir: string;\n }> {\n let resolvedPath: string;\n\n // Check if it's a local path\n if (templatePath.startsWith(\".\") || templatePath.startsWith(\"/\")) {\n resolvedPath = path.resolve(templatePath);\n this.logger.debug(`Loading local template from: ${resolvedPath}`);\n } else if (templatePath === \"default\") {\n // Use built-in default template\n // Find package root by looking for package.json\n const currentFile = import.meta.url.replace(\"file://\", \"\");\n const packageRoot = await this.findPackageRoot(path.dirname(currentFile));\n resolvedPath = path.join(packageRoot, \"templates/default\");\n this.logger.debug(`Loading built-in default template`);\n } else {\n // Try to resolve as an npm package\n try {\n const packagePath = await this.resolveNodeModule(templatePath);\n resolvedPath = packagePath;\n this.logger.debug(`Loading npm template: ${templatePath}`);\n } catch {\n throw new Error(`Template not found: ${templatePath}`);\n }\n }\n\n // Check if template directory exists\n if (!await fs.pathExists(resolvedPath)) {\n throw new Error(`Template directory does not exist: ${resolvedPath}`);\n }\n\n // Load template configuration\n const configPath = path.join(resolvedPath, \"template.config.js\");\n if (!await fs.pathExists(configPath)) {\n throw new Error(`Template configuration not found: ${configPath}`);\n }\n\n const configUrl = pathToFileURL(configPath).href;\n const { default: config } = await import(configUrl) as { default: TemplateConfig };\n\n return {\n config,\n templateDir: resolvedPath,\n };\n }\n\n private async findPackageRoot(startDir: string): Promise<string> {\n const packageJsonPath = await findUp(\n \"package.json\",\n { cwd: startDir },\n );\n\n if (!packageJsonPath) {\n throw new Error(\"Could not find package.json\");\n }\n\n return path.dirname(packageJsonPath);\n }\n\n private async resolveNodeModule(moduleName: string): Promise<string> {\n try {\n const require = (await import(\"module\")).createRequire(import.meta.url);\n const modulePath = require.resolve(moduleName);\n const startDir = path.dirname(modulePath);\n\n const packageJsonPath = await findUp(\n async directory => {\n const pkgPath = path.join(directory, \"package.json\");\n try {\n const pkg = await fs.readJson(pkgPath) as { name?: string };\n if (pkg.name === moduleName) {\n return pkgPath;\n }\n } catch {\n return undefined;\n }\n return undefined;\n },\n { cwd: startDir },\n );\n\n if (packageJsonPath) {\n return path.dirname(packageJsonPath);\n }\n\n throw new Error(`Package root not found for: ${moduleName}`);\n } catch (error) {\n this.logger.debug(\n `Failed to resolve via require.resolve: ${\n error instanceof Error ? error.message : String(error)\n }`,\n );\n\n const modulePath = path.join(process.cwd(), \"node_modules\", moduleName);\n if (await fs.pathExists(modulePath)) {\n return modulePath;\n }\n }\n\n throw new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,CAACkB,UAAU,CAAC;MAEzC,MAAML,eAAe,GAAG,MAAMjC,MAAM,CAClC,MAAMuC,SAAS,IAAI;QACjB,MAAMC,OAAO,GAAGtC,IAAI,CAACmB,IAAI,CAACkB,SAAS,EAAE,cAAc,CAAC;QACpD,IAAI;UACF,MAAME,GAAG,GAAG,MAAMxC,EAAE,CAACyC,QAAQ,CAACF,OAAO,CAAsB;UAC3D,IAAIC,GAAG,CAACE,IAAI,KAAKR,UAAU,EAAE;YAC3B,OAAOK,OAAO;UAChB;QACF,CAAC,CAAC,MAAM;UACN,OAAOI,SAAS;QAClB;QACA,OAAOA,SAAS;MAClB,CAAC,EACD;QAAEV,GAAG,EAAEF;MAAS,CAClB,CAAC;MAED,IAAIC,eAAe,EAAE;QACnB,OAAO/B,IAAI,CAACkB,OAAO,CAACa,eAAe,CAAC;MACtC;MAEA,MAAM,IAAIT,KAAK,CAAC,+BAA+BW,UAAU,EAAE,CAAC;IAC9D,CAAC,CAAC,OAAOU,KAAK,EAAE;MACd,IAAI,CAACvC,MAAM,CAACM,KAAK,CACf,0CACEiC,KAAK,YAAYrB,KAAK,GAAGqB,KAAK,CAACC,OAAO,GAAGC,MAAM,CAACF,KAAK,CAAC,EAE1D,CAAC;MAED,MAAMP,UAAU,GAAGpC,IAAI,CAACmB,IAAI,CAAC2B,OAAO,CAACd,GAAG,CAAC,CAAC,EAAE,cAAc,EAAEC,UAAU,CAAC;MACvE,IAAI,MAAMlC,EAAE,CAACwB,UAAU,CAACa,UAAU,CAAC,EAAE;QACnC,OAAOA,UAAU;MACnB;IACF;IAEA,MAAM,IAAId,KAAK,CAAC,0BAA0BW,UAAU,EAAE,CAAC;EACzD;AACF","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateLoader.d.ts","sourceRoot":"","sources":["../../../src/core/templateLoader.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAErC,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;QAChD,MAAM,EAAE,cAAc,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;YA6CY,iBAAiB;CA0ChC"}
|
|
1
|
+
{"version":3,"file":"templateLoader.d.ts","sourceRoot":"","sources":["../../../src/core/templateLoader.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAEjD,qBAAa,cAAc;IACb,OAAO,CAAC,QAAQ,CAAC,MAAM;gBAAN,MAAM,EAAE,MAAM;IAErC,YAAY,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;QAChD,MAAM,EAAE,cAAc,CAAC;QACvB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;YA6CY,eAAe;YAaf,iBAAiB;CA0ChC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@palantir/pack.sdkgen",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.2",
|
|
4
4
|
"description": "Generic Typescript SDK generator CLI",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"url": "https://github.com/palantir/pack.git"
|
|
9
9
|
},
|
|
10
10
|
"bin": {
|
|
11
|
-
"sdkgen": "./bin/cli.ts"
|
|
11
|
+
"sdkgen-bun": "./bin/cli.ts",
|
|
12
|
+
"sdkgen": "./bin/cli-node.js"
|
|
12
13
|
},
|
|
13
14
|
"exports": {
|
|
14
15
|
".": {
|
|
@@ -35,14 +36,15 @@
|
|
|
35
36
|
"rimraf": "^6.0.1",
|
|
36
37
|
"tslib": "^2.8.1",
|
|
37
38
|
"typescript": "^5.9.2",
|
|
38
|
-
"@palantir/pack.monorepo.tsconfig": "~0.4.
|
|
39
|
+
"@palantir/pack.monorepo.tsconfig": "~0.4.2"
|
|
39
40
|
},
|
|
40
41
|
"publishConfig": {
|
|
41
42
|
"access": "public"
|
|
42
43
|
},
|
|
43
44
|
"files": [
|
|
44
45
|
"bin",
|
|
45
|
-
"build"
|
|
46
|
+
"build",
|
|
47
|
+
"templates"
|
|
46
48
|
],
|
|
47
49
|
"main": "./build/esm/index.js",
|
|
48
50
|
"types": "./build/types/index.d.ts",
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "<%= projectName %>",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "<%= answers.description %>",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"author": "<%= answers.author %>",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"test": "echo \"No tests yet\""
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "^5.0.0",
|
|
15
|
+
"@types/node": "^20.0.0"
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* <%= utils.capitalize(projectName) %> SDK
|
|
3
|
+
* <%= answers.description %>
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
export class SDK {
|
|
7
|
+
constructor(private config?: any) {}
|
|
8
|
+
|
|
9
|
+
// Add your SDK methods here
|
|
10
|
+
|
|
11
|
+
getVersion(): string {
|
|
12
|
+
return '1.0.0';
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default SDK;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
"rootDir": "./src",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"esModuleInterop": true,
|
|
10
|
+
"skipLibCheck": true,
|
|
11
|
+
"forceConsistentCasingInFileNames": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src/**/*"],
|
|
14
|
+
"exclude": ["node_modules", "dist"]
|
|
15
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
name: "default-template",
|
|
3
|
+
description: "Default SDK template",
|
|
4
|
+
|
|
5
|
+
prompts: [
|
|
6
|
+
{
|
|
7
|
+
type: "input",
|
|
8
|
+
name: "description",
|
|
9
|
+
message: "Project description?",
|
|
10
|
+
default: "SDK generated with sdkgen",
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
type: "input",
|
|
14
|
+
name: "author",
|
|
15
|
+
message: "Author name?",
|
|
16
|
+
default: "",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
|
|
20
|
+
templateFiles: ["**/*.ejs"],
|
|
21
|
+
staticFiles: ["_gitignore"],
|
|
22
|
+
};
|