Skip to content

Commit 258b768

Browse files
authored
fix(appkit): generate types (#35)
1 parent 6c0e705 commit 258b768

File tree

5 files changed

+26
-65
lines changed

5 files changed

+26
-65
lines changed

.github/workflows/publish-fix.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#!/usr/bin/env tsx
1+
#!/usr/bin/env node
22
import path from "node:path";
33

4-
import { generateFromEntryPoint } from "../src/type-generator";
4+
import { generateFromEntryPoint } from "../dist/type-generator/index.js";
55

66
// Parse arguments
77
const args = process.argv.slice(2);

packages/appkit/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"./package.json": "./package.json"
2828
},
2929
"bin": {
30-
"appkit-generate-types": "./bin/generate-types.ts"
30+
"appkit-generate-types": "./bin/generate-types.js"
3131
},
3232
"scripts": {
3333
"build:package": "tsdown --config tsdown.config.ts",

packages/appkit/src/type-generator/vite-plugin.ts

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { execSync } from "node:child_process";
21
import path from "node:path";
32
import type { Plugin } from "vite";
3+
import { generateFromEntryPoint } from "./index";
44

55
/**
66
* Options for the AppKit types plugin.
@@ -14,22 +14,31 @@ interface AppKitTypesPluginOptions {
1414

1515
/**
1616
* Vite plugin to generate types for AppKit queries.
17-
* Calls `npx appkit-generate-types` under the hood.
17+
* Calls generateFromEntryPoint under the hood.
1818
* @param options - Options to override default values.
1919
* @returns Vite plugin to generate types for AppKit queries.
2020
*/
2121
export function appKitTypesPlugin(options?: AppKitTypesPluginOptions): Plugin {
2222
let root: string;
23-
let appRoot: string;
2423
let outFile: string;
2524
let watchFolders: string[];
2625

27-
function generate() {
26+
async function generate() {
2827
try {
29-
const args = [appRoot, outFile].join(" ");
30-
execSync(`npx appkit-generate-types ${args}`, {
31-
cwd: appRoot,
32-
stdio: "inherit",
28+
const warehouseId = process.env.DATABRICKS_WAREHOUSE_ID || "";
29+
30+
if (!warehouseId) {
31+
console.warn(
32+
"[AppKit] Warehouse ID not found. Skipping type generation.",
33+
);
34+
return;
35+
}
36+
37+
await generateFromEntryPoint({
38+
outFile,
39+
queryFolder: watchFolders[0],
40+
warehouseId,
41+
noCache: false,
3342
});
3443
} catch (error) {
3544
// throw in production to fail the build
@@ -42,16 +51,15 @@ export function appKitTypesPlugin(options?: AppKitTypesPluginOptions): Plugin {
4251

4352
return {
4453
name: "appkit-types",
54+
4555
configResolved(config) {
4656
root = config.root;
47-
appRoot = path.resolve(root, "..");
48-
4957
outFile = path.resolve(root, options?.outFile ?? "src/appKitTypes.d.ts");
50-
5158
watchFolders = (options?.watchFolders ?? ["../config/queries"]).map(
5259
(folder) => path.resolve(root, folder),
5360
);
5461
},
62+
5563
buildStart() {
5664
generate();
5765
},

tools/dist.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ fs.writeFileSync("tmp/package.json", JSON.stringify(pkg, null, 2));
3838

3939
fs.cpSync("dist", "tmp/dist", { recursive: true });
4040

41+
if (fs.existsSync("bin")) {
42+
fs.cpSync("bin", "tmp/bin", { recursive: true });
43+
}
44+
4145
// Copy bin and scripts from shared package
4246
if (isAppKitPackage) {
4347
if (fs.existsSync(sharedBin)) {

0 commit comments

Comments
 (0)