vite-plugin-windmill 1.683.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.
- package/LICENSE +21 -0
- package/README.md +220 -0
- package/bin/vite-plugin-windmill +3 -0
- package/dist/cli.d.mts +4 -0
- package/dist/cli.mjs +475 -0
- package/dist/index.d.mts +128 -0
- package/dist/index.mjs +1044 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +70 -0
package/dist/cli.mjs
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { parseArgs } from "node:util";
|
|
3
|
+
import { access, readFile, readdir } from "node:fs/promises";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { ApiError, AppService, setClient } from "windmill-client";
|
|
6
|
+
import { createHash } from "node:crypto";
|
|
7
|
+
import { parse } from "yaml";
|
|
8
|
+
//#region src/project.ts
|
|
9
|
+
const RAW_APP_FOLDER_SUFFIXES = [".raw_app", "__raw_app"];
|
|
10
|
+
const RAW_APP_FILE_NAME = "raw_app.yaml";
|
|
11
|
+
const WMILL_CONFIG_FILE_NAME = "wmill.yaml";
|
|
12
|
+
const DEPLOY_IGNORED_FILE_NAMES = new Set([
|
|
13
|
+
"AGENTS.md",
|
|
14
|
+
"DATATABLES.md",
|
|
15
|
+
"package-lock.json",
|
|
16
|
+
"raw_app.yaml",
|
|
17
|
+
"wmill.d.ts"
|
|
18
|
+
]);
|
|
19
|
+
const DEPLOY_IGNORED_DIRECTORIES = new Set([
|
|
20
|
+
".claude",
|
|
21
|
+
"backend",
|
|
22
|
+
"dist",
|
|
23
|
+
"node_modules",
|
|
24
|
+
"sql_to_apply"
|
|
25
|
+
]);
|
|
26
|
+
const LANGUAGE_BY_EXTENSION = {
|
|
27
|
+
"bq.sql": "bigquery",
|
|
28
|
+
"bun.ts": "bun",
|
|
29
|
+
cs: "csharp",
|
|
30
|
+
"deno.ts": "deno",
|
|
31
|
+
"duckdb.sql": "duckdb",
|
|
32
|
+
"frontend.js": "frontend",
|
|
33
|
+
go: "go",
|
|
34
|
+
gql: "graphql",
|
|
35
|
+
java: "java",
|
|
36
|
+
"ms.sql": "mssql",
|
|
37
|
+
"my.sql": "mysql",
|
|
38
|
+
"native.ts": "nativets",
|
|
39
|
+
nu: "nu",
|
|
40
|
+
"odb.sql": "oracledb",
|
|
41
|
+
"pg.sql": "postgresql",
|
|
42
|
+
php: "php",
|
|
43
|
+
"playbook.yml": "ansible",
|
|
44
|
+
ps1: "powershell",
|
|
45
|
+
py: "python3",
|
|
46
|
+
rb: "ruby",
|
|
47
|
+
rs: "rust",
|
|
48
|
+
"sf.sql": "snowflake",
|
|
49
|
+
sh: "bash",
|
|
50
|
+
ts: "bun"
|
|
51
|
+
};
|
|
52
|
+
const isNodeError = (value) => value instanceof Error && "code" in value;
|
|
53
|
+
const pathExists = async (filePath) => {
|
|
54
|
+
try {
|
|
55
|
+
await access(filePath);
|
|
56
|
+
return true;
|
|
57
|
+
} catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const normalizeToPosix = (value) => value.split(path.sep).join("/");
|
|
62
|
+
const dirnameIfPossible = (value) => {
|
|
63
|
+
const parent = path.dirname(value);
|
|
64
|
+
return parent === value ? void 0 : parent;
|
|
65
|
+
};
|
|
66
|
+
const findUp = async (startDir, fileName) => {
|
|
67
|
+
let currentDir = path.resolve(startDir);
|
|
68
|
+
while (true) {
|
|
69
|
+
const candidate = path.join(currentDir, fileName);
|
|
70
|
+
if (await pathExists(candidate)) return candidate;
|
|
71
|
+
const parentDir = dirnameIfPossible(currentDir);
|
|
72
|
+
if (!parentDir) return void 0;
|
|
73
|
+
currentDir = parentDir;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
const parseYamlFile = async (filePath) => {
|
|
77
|
+
return parse(await readFile(filePath, "utf8"));
|
|
78
|
+
};
|
|
79
|
+
const resolveRoot = async (explicitRoot, dir) => {
|
|
80
|
+
if (explicitRoot) {
|
|
81
|
+
const root = path.resolve(explicitRoot);
|
|
82
|
+
return {
|
|
83
|
+
path: await pathExists(path.join(root, WMILL_CONFIG_FILE_NAME)) ? path.join(root, WMILL_CONFIG_FILE_NAME) : void 0,
|
|
84
|
+
root
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
const configPath = await findUp(dir, WMILL_CONFIG_FILE_NAME);
|
|
88
|
+
return {
|
|
89
|
+
path: configPath,
|
|
90
|
+
root: configPath ? path.dirname(configPath) : dir
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
const resolveDir = async (explicitDir) => {
|
|
94
|
+
const candidate = path.resolve(explicitDir ?? process.cwd());
|
|
95
|
+
const rawAppPath = await findUp(candidate, RAW_APP_FILE_NAME);
|
|
96
|
+
if (!rawAppPath) throw new Error(`Could not find ${RAW_APP_FILE_NAME} from ${candidate}`);
|
|
97
|
+
return path.dirname(rawAppPath);
|
|
98
|
+
};
|
|
99
|
+
const stripRawAppSuffix = (folderName) => {
|
|
100
|
+
for (const suffix of RAW_APP_FOLDER_SUFFIXES) if (folderName.endsWith(suffix)) return folderName.slice(0, -suffix.length);
|
|
101
|
+
};
|
|
102
|
+
const inferPath = (dir, root) => {
|
|
103
|
+
const segments = normalizeToPosix(path.relative(root, dir)).split("/").filter(Boolean);
|
|
104
|
+
if (segments.length === 0) throw new Error(`Could not infer a Windmill app path from ${dir}`);
|
|
105
|
+
const lastSegment = segments.at(-1);
|
|
106
|
+
if (!lastSegment) throw new Error(`Could not infer a Windmill app path from ${dir}`);
|
|
107
|
+
const strippedSegment = stripRawAppSuffix(lastSegment);
|
|
108
|
+
if (!strippedSegment) throw new Error(`Expected ${dir} to end in .raw_app or __raw_app so the app path can be inferred`);
|
|
109
|
+
return [...segments.slice(0, -1), strippedSegment].join("/");
|
|
110
|
+
};
|
|
111
|
+
const inferBase = (pathValue) => `/apps_raw/get/${pathValue}/`;
|
|
112
|
+
const resolveEntry = async (dir, value) => {
|
|
113
|
+
if (value) {
|
|
114
|
+
const entry = path.resolve(dir, value);
|
|
115
|
+
if (!await pathExists(entry)) throw new Error(`Entry file does not exist: ${entry}`);
|
|
116
|
+
return entry;
|
|
117
|
+
}
|
|
118
|
+
const tsEntry = path.join(dir, "index.ts");
|
|
119
|
+
if (await pathExists(tsEntry)) return tsEntry;
|
|
120
|
+
const tsxEntry = path.join(dir, "index.tsx");
|
|
121
|
+
if (await pathExists(tsxEntry)) return tsxEntry;
|
|
122
|
+
throw new Error(`Could not find index.ts or index.tsx inside ${dir}`);
|
|
123
|
+
};
|
|
124
|
+
const resolveEnv = (options) => ({
|
|
125
|
+
url: options.url ?? process.env.BASE_INTERNAL_URL ?? process.env.BASE_URL,
|
|
126
|
+
token: options.token ?? process.env.WM_TOKEN,
|
|
127
|
+
workspace: options.workspace ?? process.env.WM_WORKSPACE
|
|
128
|
+
});
|
|
129
|
+
const resolveProject = async (options = {}) => {
|
|
130
|
+
const dir = await resolveDir(options.dir);
|
|
131
|
+
const { path: config, root } = await resolveRoot(options.root, dir);
|
|
132
|
+
const wmillConfig = config ? await parseYamlFile(config) : {};
|
|
133
|
+
const pathValue = options.path ?? inferPath(dir, root);
|
|
134
|
+
const entry = await resolveEntry(dir, options.entry);
|
|
135
|
+
const { url, token, workspace } = resolveEnv(options);
|
|
136
|
+
return {
|
|
137
|
+
base: options.base ?? inferBase(pathValue),
|
|
138
|
+
config,
|
|
139
|
+
dir,
|
|
140
|
+
entry,
|
|
141
|
+
nonDotted: options.nonDotted ?? wmillConfig.nonDottedPaths ?? false,
|
|
142
|
+
path: pathValue,
|
|
143
|
+
root,
|
|
144
|
+
syncExcludes: wmillConfig.excludes ?? [],
|
|
145
|
+
ts: options.ts ?? wmillConfig.defaultTs ?? "bun",
|
|
146
|
+
workspace,
|
|
147
|
+
token,
|
|
148
|
+
url,
|
|
149
|
+
yaml: path.join(dir, RAW_APP_FILE_NAME)
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
const collectStaticFields = (fields) => Object.fromEntries(Object.entries(fields ?? {}).filter(([, field]) => field.type === "static").map(([name, field]) => [name, field.value]));
|
|
153
|
+
const createRawscriptHash = (content) => createHash("sha256").update(content ?? "").digest("hex");
|
|
154
|
+
const resolveTriggerableEntry = async (runnableId, runnable) => {
|
|
155
|
+
const staticInputs = collectStaticFields(runnable.fields);
|
|
156
|
+
const allowUserResources = Object.entries(runnable.fields ?? {}).filter(([, field]) => field.allowUserResources).map(([name]) => name);
|
|
157
|
+
if (runnable.inlineScript) return [`${runnableId}:rawscript/${createRawscriptHash(runnable.inlineScript.content)}`, {
|
|
158
|
+
allow_user_resources: allowUserResources,
|
|
159
|
+
one_of_inputs: {},
|
|
160
|
+
static_inputs: staticInputs
|
|
161
|
+
}];
|
|
162
|
+
if (runnable.path && runnable.runType) return [`${runnableId}:${runnable.runType === "hubscript" ? "script" : runnable.runType}/${runnable.path}`, {
|
|
163
|
+
allow_user_resources: allowUserResources,
|
|
164
|
+
one_of_inputs: {},
|
|
165
|
+
static_inputs: staticInputs
|
|
166
|
+
}];
|
|
167
|
+
};
|
|
168
|
+
const generateRawAppPolicy = async (runnables, policy, isPublic) => {
|
|
169
|
+
const resolvedTriggerableEntries = (await Promise.all(Object.entries(runnables).map(async ([runnableId, runnable]) => resolveTriggerableEntry(runnableId, runnable)))).filter((entry) => entry !== void 0);
|
|
170
|
+
return {
|
|
171
|
+
...policy,
|
|
172
|
+
execution_mode: isPublic ? "anonymous" : "publisher",
|
|
173
|
+
triggerables_v2: Object.fromEntries(resolvedTriggerableEntries)
|
|
174
|
+
};
|
|
175
|
+
};
|
|
176
|
+
const resolveRunnableLanguage = (extension, ts) => {
|
|
177
|
+
const language = LANGUAGE_BY_EXTENSION[extension];
|
|
178
|
+
if (!language) return void 0;
|
|
179
|
+
return extension === "ts" ? ts : language;
|
|
180
|
+
};
|
|
181
|
+
const findRunnableContentFile = async (backendDir, runnableId, allFileNames) => {
|
|
182
|
+
for (const fileName of allFileNames) {
|
|
183
|
+
if (fileName.endsWith(".yaml") || fileName.endsWith(".lock")) continue;
|
|
184
|
+
if (!fileName.startsWith(`${runnableId}.`)) continue;
|
|
185
|
+
const extension = fileName.slice(runnableId.length + 1);
|
|
186
|
+
if (!resolveRunnableLanguage(extension, "bun")) continue;
|
|
187
|
+
return {
|
|
188
|
+
content: await readFile(path.join(backendDir, fileName), "utf8"),
|
|
189
|
+
extension
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
};
|
|
193
|
+
const getRunnableIdFromCodeFile = (fileName) => {
|
|
194
|
+
if (fileName.endsWith(".yaml") || fileName.endsWith(".lock")) return void 0;
|
|
195
|
+
for (const extension of Object.keys(LANGUAGE_BY_EXTENSION)) if (fileName.endsWith(`.${extension}`)) return fileName.slice(0, -(extension.length + 1));
|
|
196
|
+
};
|
|
197
|
+
const inlinePathPrefix = "!inline ";
|
|
198
|
+
const dereferenceInlineValue = async (value, localPath) => {
|
|
199
|
+
if (typeof value !== "string" || !value.startsWith(inlinePathPrefix)) return value;
|
|
200
|
+
const relativePath = value.slice(8);
|
|
201
|
+
return readFile(path.join(localPath, relativePath), "utf8");
|
|
202
|
+
};
|
|
203
|
+
const cloneRunnable = async (value, localPath) => {
|
|
204
|
+
if (Array.isArray(value)) return Promise.all(value.map(async (item) => cloneRunnable(item, localPath)));
|
|
205
|
+
if (typeof value !== "object" || value === null) return dereferenceInlineValue(value, localPath);
|
|
206
|
+
const entries = await Promise.all(Object.entries(value).map(async ([key, entryValue]) => [key, await cloneRunnable(entryValue, localPath)]));
|
|
207
|
+
return Object.fromEntries(entries);
|
|
208
|
+
};
|
|
209
|
+
const loadRunnablesFromBackend = async (backendDir, ts = "bun") => {
|
|
210
|
+
const runnables = {};
|
|
211
|
+
try {
|
|
212
|
+
const allFileNames = (await readdir(backendDir, { withFileTypes: true })).filter((entry) => entry.isFile()).map((entry) => entry.name);
|
|
213
|
+
const processedIds = /* @__PURE__ */ new Set();
|
|
214
|
+
for (const fileName of allFileNames) {
|
|
215
|
+
if (!fileName.endsWith(".yaml")) continue;
|
|
216
|
+
const runnableId = fileName.slice(0, -5);
|
|
217
|
+
processedIds.add(runnableId);
|
|
218
|
+
const runnable = await parseYamlFile(path.join(backendDir, fileName));
|
|
219
|
+
if (runnable.type === "inline") {
|
|
220
|
+
const contentFile = await findRunnableContentFile(backendDir, runnableId, allFileNames);
|
|
221
|
+
if (contentFile) {
|
|
222
|
+
const lockPath = path.join(backendDir, `${runnableId}.lock`);
|
|
223
|
+
let lock;
|
|
224
|
+
try {
|
|
225
|
+
lock = await readFile(lockPath, "utf8");
|
|
226
|
+
} catch (error) {
|
|
227
|
+
if (!isNodeError(error) || error.code !== "ENOENT") throw error;
|
|
228
|
+
}
|
|
229
|
+
runnable.inlineScript = {
|
|
230
|
+
...runnable.inlineScript,
|
|
231
|
+
content: contentFile.content,
|
|
232
|
+
language: resolveRunnableLanguage(contentFile.extension, ts),
|
|
233
|
+
...lock ? { lock } : {}
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
} else if (runnable.type === "flow" || runnable.type === "hubscript" || runnable.type === "script") {
|
|
237
|
+
const { type, schema: _schema, ...rest } = runnable;
|
|
238
|
+
runnables[runnableId] = {
|
|
239
|
+
...rest,
|
|
240
|
+
runType: type,
|
|
241
|
+
type: "path"
|
|
242
|
+
};
|
|
243
|
+
continue;
|
|
244
|
+
}
|
|
245
|
+
runnables[runnableId] = runnable;
|
|
246
|
+
}
|
|
247
|
+
for (const fileName of allFileNames) {
|
|
248
|
+
const runnableId = getRunnableIdFromCodeFile(fileName);
|
|
249
|
+
if (!runnableId || processedIds.has(runnableId)) continue;
|
|
250
|
+
processedIds.add(runnableId);
|
|
251
|
+
const contentFile = await findRunnableContentFile(backendDir, runnableId, allFileNames);
|
|
252
|
+
if (!contentFile) continue;
|
|
253
|
+
const lockPath = path.join(backendDir, `${runnableId}.lock`);
|
|
254
|
+
let lock;
|
|
255
|
+
try {
|
|
256
|
+
lock = await readFile(lockPath, "utf8");
|
|
257
|
+
} catch (error) {
|
|
258
|
+
if (!isNodeError(error) || error.code !== "ENOENT") throw error;
|
|
259
|
+
}
|
|
260
|
+
runnables[runnableId] = {
|
|
261
|
+
inlineScript: {
|
|
262
|
+
content: contentFile.content,
|
|
263
|
+
language: resolveRunnableLanguage(contentFile.extension, ts),
|
|
264
|
+
...lock ? { lock } : {}
|
|
265
|
+
},
|
|
266
|
+
type: "inline"
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
} catch (error) {
|
|
270
|
+
if (!isNodeError(error) || error.code !== "ENOENT") throw error;
|
|
271
|
+
}
|
|
272
|
+
return runnables;
|
|
273
|
+
};
|
|
274
|
+
const matchesSyncExclude = (relativePath, excludes) => excludes.some((pattern) => path.posix.matchesGlob(relativePath, pattern));
|
|
275
|
+
const collectAppFiles = async (dir, options = {}) => {
|
|
276
|
+
const files = {};
|
|
277
|
+
const root = options.root ? path.resolve(options.root) : dir;
|
|
278
|
+
const excludes = options.excludes ?? [];
|
|
279
|
+
const walk = async (currentDir, relativeDir = "/") => {
|
|
280
|
+
const entries = await readdir(currentDir, { withFileTypes: true });
|
|
281
|
+
for (const entry of entries) {
|
|
282
|
+
const fullPath = path.join(currentDir, entry.name);
|
|
283
|
+
const relativePath = `${relativeDir}${entry.name}`;
|
|
284
|
+
const relativeToRoot = normalizeToPosix(path.relative(root, fullPath));
|
|
285
|
+
if (entry.isDirectory()) {
|
|
286
|
+
if (DEPLOY_IGNORED_DIRECTORIES.has(entry.name)) continue;
|
|
287
|
+
await walk(fullPath, `${relativePath}/`);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
290
|
+
if (DEPLOY_IGNORED_FILE_NAMES.has(entry.name)) continue;
|
|
291
|
+
if (matchesSyncExclude(relativeToRoot, excludes)) continue;
|
|
292
|
+
files[relativePath] = await readFile(fullPath, "utf8");
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
await walk(dir);
|
|
296
|
+
return files;
|
|
297
|
+
};
|
|
298
|
+
const loadRawAppProject = async (project) => {
|
|
299
|
+
const config = await parseYamlFile(project.yaml);
|
|
300
|
+
const backendDir = path.join(project.dir, "backend");
|
|
301
|
+
const backendRunnables = await loadRunnablesFromBackend(backendDir, project.ts);
|
|
302
|
+
const runnables = await cloneRunnable(Object.keys(backendRunnables).length > 0 ? backendRunnables : config.runnables ?? {}, backendDir);
|
|
303
|
+
const files = await collectAppFiles(project.dir, {
|
|
304
|
+
excludes: project.syncExcludes,
|
|
305
|
+
root: project.root
|
|
306
|
+
});
|
|
307
|
+
return {
|
|
308
|
+
config,
|
|
309
|
+
files,
|
|
310
|
+
policy: await generateRawAppPolicy(runnables, config.policy, Boolean(config.public)),
|
|
311
|
+
runnables,
|
|
312
|
+
value: {
|
|
313
|
+
...config.data !== void 0 ? { data: config.data } : {},
|
|
314
|
+
files,
|
|
315
|
+
runnables
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
};
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/deploy.ts
|
|
321
|
+
const defaultDeploymentMessage = () => {
|
|
322
|
+
const sha = process.env.GITHUB_SHA;
|
|
323
|
+
return sha ? `vite-plugin-windmill deploy ${sha}` : "vite-plugin-windmill deploy";
|
|
324
|
+
};
|
|
325
|
+
const requireProjectConnection = (project) => {
|
|
326
|
+
if (!project.workspace) throw new Error("Missing Windmill workspace. Set `workspace` or `WM_WORKSPACE`.");
|
|
327
|
+
if (!project.token) throw new Error("Missing Windmill token. Set `token` or `WM_TOKEN`.");
|
|
328
|
+
if (!project.url) throw new Error("Missing Windmill URL. Set `url`, `BASE_INTERNAL_URL`, or `BASE_URL`.");
|
|
329
|
+
return {
|
|
330
|
+
url: project.url,
|
|
331
|
+
token: project.token,
|
|
332
|
+
workspace: project.workspace
|
|
333
|
+
};
|
|
334
|
+
};
|
|
335
|
+
const readBundleFile = async (filePath, fallback = "") => {
|
|
336
|
+
try {
|
|
337
|
+
return await readFile(filePath, "utf8");
|
|
338
|
+
} catch (error) {
|
|
339
|
+
if (error instanceof Error && "code" in error && error.code === "ENOENT") return fallback;
|
|
340
|
+
throw error;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
const readBundleContents = async (dir, js = path.join(dir, "dist/windmill/bundle.js"), css = path.join(dir, "dist/windmill/bundle.css")) => ({
|
|
344
|
+
css: await readBundleFile(css, ""),
|
|
345
|
+
js: await readBundleFile(js)
|
|
346
|
+
});
|
|
347
|
+
const findExistingRawApp = async (workspace, pathValue) => {
|
|
348
|
+
try {
|
|
349
|
+
return await AppService.getAppByPath({
|
|
350
|
+
workspace,
|
|
351
|
+
path: pathValue
|
|
352
|
+
});
|
|
353
|
+
} catch (error) {
|
|
354
|
+
if (error instanceof ApiError && error.status === 404) return void 0;
|
|
355
|
+
throw error;
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
/**
|
|
359
|
+
* Deploys a raw app to Windmill using `windmill-client` instead of shelling out to the CLI.
|
|
360
|
+
*/
|
|
361
|
+
const deploy = async (options) => {
|
|
362
|
+
const dir = options.dir ?? process.cwd();
|
|
363
|
+
const project = await resolveProject({
|
|
364
|
+
...options,
|
|
365
|
+
dir
|
|
366
|
+
});
|
|
367
|
+
const rawAppProject = await loadRawAppProject(project);
|
|
368
|
+
const connection = requireProjectConnection(project);
|
|
369
|
+
const bundles = options.bundles ?? await readBundleContents(dir, options.js, options.css);
|
|
370
|
+
if (!bundles.js) throw new Error("Cannot deploy a Windmill raw app without a JavaScript bundle");
|
|
371
|
+
if (options.dry) return {
|
|
372
|
+
action: "dry-run",
|
|
373
|
+
base: project.base,
|
|
374
|
+
path: project.path,
|
|
375
|
+
workspace: connection.workspace
|
|
376
|
+
};
|
|
377
|
+
setClient(connection.token, connection.url);
|
|
378
|
+
const existingApp = await findExistingRawApp(connection.workspace, project.path);
|
|
379
|
+
if (existingApp && !existingApp.raw_app) throw new Error(`${project.path} exists remotely but is not a raw app`);
|
|
380
|
+
const message = options.message ?? defaultDeploymentMessage();
|
|
381
|
+
const appPayload = {
|
|
382
|
+
...rawAppProject.config.custom_path ? { custom_path: rawAppProject.config.custom_path } : {},
|
|
383
|
+
deployment_message: message,
|
|
384
|
+
path: project.path,
|
|
385
|
+
policy: rawAppProject.policy,
|
|
386
|
+
summary: rawAppProject.config.summary,
|
|
387
|
+
value: rawAppProject.value
|
|
388
|
+
};
|
|
389
|
+
if (existingApp) {
|
|
390
|
+
await AppService.updateAppRaw({
|
|
391
|
+
workspace: connection.workspace,
|
|
392
|
+
path: project.path,
|
|
393
|
+
formData: {
|
|
394
|
+
app: appPayload,
|
|
395
|
+
css: bundles.css,
|
|
396
|
+
js: bundles.js
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
return {
|
|
400
|
+
action: "update",
|
|
401
|
+
base: project.base,
|
|
402
|
+
path: project.path,
|
|
403
|
+
workspace: connection.workspace
|
|
404
|
+
};
|
|
405
|
+
}
|
|
406
|
+
await AppService.createAppRaw({
|
|
407
|
+
workspace: connection.workspace,
|
|
408
|
+
formData: {
|
|
409
|
+
app: appPayload,
|
|
410
|
+
css: bundles.css,
|
|
411
|
+
js: bundles.js
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
return {
|
|
415
|
+
action: "create",
|
|
416
|
+
base: project.base,
|
|
417
|
+
path: project.path,
|
|
418
|
+
workspace: connection.workspace
|
|
419
|
+
};
|
|
420
|
+
};
|
|
421
|
+
//#endregion
|
|
422
|
+
//#region src/cli.ts
|
|
423
|
+
const main = async () => {
|
|
424
|
+
const { values } = parseArgs({ options: {
|
|
425
|
+
base: { type: "string" },
|
|
426
|
+
css: { type: "string" },
|
|
427
|
+
dir: { type: "string" },
|
|
428
|
+
dry: { type: "boolean" },
|
|
429
|
+
entry: { type: "string" },
|
|
430
|
+
js: { type: "string" },
|
|
431
|
+
message: { type: "string" },
|
|
432
|
+
path: { type: "string" },
|
|
433
|
+
root: { type: "string" },
|
|
434
|
+
token: { type: "string" },
|
|
435
|
+
url: { type: "string" },
|
|
436
|
+
workspace: { type: "string" },
|
|
437
|
+
help: {
|
|
438
|
+
type: "boolean",
|
|
439
|
+
short: "h"
|
|
440
|
+
}
|
|
441
|
+
} });
|
|
442
|
+
if (values.help) return console.log(`
|
|
443
|
+
Usage: vite-plugin-windmill [options]
|
|
444
|
+
|
|
445
|
+
Deploy a built Windmill raw app bundle.
|
|
446
|
+
|
|
447
|
+
Options:
|
|
448
|
+
-h, --help Show this help message
|
|
449
|
+
--base <path> Override the raw-app base path
|
|
450
|
+
--css <path> Path to the CSS file to include in the deployment
|
|
451
|
+
--dir <path> Raw-app directory to resolve and deploy from
|
|
452
|
+
--dry Perform a dry run without making any changes
|
|
453
|
+
--entry <path> Override the raw-app entry file
|
|
454
|
+
--js <path> Path to the JavaScript file to include in the deployment
|
|
455
|
+
--message <text> Deployment message or description
|
|
456
|
+
--path <path> Override the inferred Windmill raw-app path
|
|
457
|
+
--root <path> Override the workspace root used to infer the app path
|
|
458
|
+
--token <token> Windmill API token for authentication
|
|
459
|
+
--url <url> Windmill instance URL
|
|
460
|
+
--workspace <name> Windmill workspace name
|
|
461
|
+
|
|
462
|
+
Connection resolution order:
|
|
463
|
+
workspace: --workspace, WM_WORKSPACE
|
|
464
|
+
token: --token, WM_TOKEN
|
|
465
|
+
url: --url, BASE_INTERNAL_URL, BASE_URL
|
|
466
|
+
`.trim());
|
|
467
|
+
const result = await deploy(values);
|
|
468
|
+
console.log(JSON.stringify(result, null, 2));
|
|
469
|
+
};
|
|
470
|
+
main().catch((error) => {
|
|
471
|
+
console.error(error instanceof Error ? error.message : String(error));
|
|
472
|
+
process.exitCode = 1;
|
|
473
|
+
});
|
|
474
|
+
//#endregion
|
|
475
|
+
export { main };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { Policy } from "windmill-client";
|
|
2
|
+
import { Plugin, ProxyOptions } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/types.d.ts
|
|
5
|
+
interface WindmillApiProxyOptions extends ProxyOptions {
|
|
6
|
+
context?: string;
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
target?: string;
|
|
9
|
+
token?: string;
|
|
10
|
+
}
|
|
11
|
+
interface PluginDeployOptions {
|
|
12
|
+
deploy?: boolean;
|
|
13
|
+
dry?: boolean;
|
|
14
|
+
message?: string;
|
|
15
|
+
}
|
|
16
|
+
interface PluginOptions {
|
|
17
|
+
base?: string;
|
|
18
|
+
deploy?: boolean | PluginDeployOptions;
|
|
19
|
+
dir?: string;
|
|
20
|
+
entry?: string;
|
|
21
|
+
message?: string;
|
|
22
|
+
nonDotted?: boolean;
|
|
23
|
+
path?: string;
|
|
24
|
+
proxy?: boolean | WindmillApiProxyOptions;
|
|
25
|
+
root?: string;
|
|
26
|
+
token?: string;
|
|
27
|
+
ts?: string;
|
|
28
|
+
url?: string;
|
|
29
|
+
workspace?: string;
|
|
30
|
+
}
|
|
31
|
+
interface Project {
|
|
32
|
+
base: string;
|
|
33
|
+
config?: string;
|
|
34
|
+
dir: string;
|
|
35
|
+
entry: string;
|
|
36
|
+
nonDotted: boolean;
|
|
37
|
+
path: string;
|
|
38
|
+
root: string;
|
|
39
|
+
syncExcludes: string[];
|
|
40
|
+
ts: string;
|
|
41
|
+
workspace?: string;
|
|
42
|
+
token?: string;
|
|
43
|
+
url?: string;
|
|
44
|
+
yaml: string;
|
|
45
|
+
}
|
|
46
|
+
interface RawAppFileConfig {
|
|
47
|
+
summary: string;
|
|
48
|
+
custom_path?: string;
|
|
49
|
+
public?: boolean;
|
|
50
|
+
data?: unknown;
|
|
51
|
+
policy?: Policy;
|
|
52
|
+
runnables?: Record<string, RawAppRunnable>;
|
|
53
|
+
}
|
|
54
|
+
interface RawAppField {
|
|
55
|
+
allowUserResources?: boolean;
|
|
56
|
+
ctx?: string;
|
|
57
|
+
type?: string;
|
|
58
|
+
value?: unknown;
|
|
59
|
+
[key: string]: unknown;
|
|
60
|
+
}
|
|
61
|
+
interface RawInlineScript {
|
|
62
|
+
cache_ttl?: number;
|
|
63
|
+
content?: string;
|
|
64
|
+
id?: number;
|
|
65
|
+
language?: string;
|
|
66
|
+
lock?: string;
|
|
67
|
+
schema?: unknown;
|
|
68
|
+
}
|
|
69
|
+
interface RawAppRunnable {
|
|
70
|
+
fields?: Record<string, RawAppField>;
|
|
71
|
+
inlineScript?: RawInlineScript;
|
|
72
|
+
path?: string;
|
|
73
|
+
runType?: "flow" | "hubscript" | "script";
|
|
74
|
+
schema?: unknown;
|
|
75
|
+
type?: string;
|
|
76
|
+
[key: string]: unknown;
|
|
77
|
+
}
|
|
78
|
+
interface RawAppProject {
|
|
79
|
+
config: RawAppFileConfig;
|
|
80
|
+
files: Record<string, string>;
|
|
81
|
+
policy: Policy;
|
|
82
|
+
runnables: Record<string, RawAppRunnable>;
|
|
83
|
+
value: {
|
|
84
|
+
data?: unknown;
|
|
85
|
+
files: Record<string, string>;
|
|
86
|
+
runnables: Record<string, RawAppRunnable>;
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
interface BundleContents {
|
|
90
|
+
css: string;
|
|
91
|
+
js: string;
|
|
92
|
+
}
|
|
93
|
+
interface DeployOptions {
|
|
94
|
+
base?: string;
|
|
95
|
+
bundles?: BundleContents;
|
|
96
|
+
css?: string;
|
|
97
|
+
dir?: string;
|
|
98
|
+
dry?: boolean;
|
|
99
|
+
entry?: string;
|
|
100
|
+
js?: string;
|
|
101
|
+
message?: string;
|
|
102
|
+
path?: string;
|
|
103
|
+
root?: string;
|
|
104
|
+
token?: string;
|
|
105
|
+
url?: string;
|
|
106
|
+
workspace?: string;
|
|
107
|
+
}
|
|
108
|
+
interface DeployRawAppResult {
|
|
109
|
+
action: "create" | "dry-run" | "update";
|
|
110
|
+
base: string;
|
|
111
|
+
path: string;
|
|
112
|
+
workspace: string;
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/deploy.d.ts
|
|
116
|
+
/**
|
|
117
|
+
* Deploys a raw app to Windmill using `windmill-client` instead of shelling out to the CLI.
|
|
118
|
+
*/
|
|
119
|
+
declare const deploy: (options: DeployOptions) => Promise<DeployRawAppResult>;
|
|
120
|
+
//#endregion
|
|
121
|
+
//#region src/plugin.d.ts
|
|
122
|
+
/**
|
|
123
|
+
* Creates a Vite plugin that aligns a SPA with Windmill raw-app build and deploy behavior.
|
|
124
|
+
*/
|
|
125
|
+
declare const windmill: (options?: PluginOptions) => Plugin;
|
|
126
|
+
//#endregion
|
|
127
|
+
export { type BundleContents, type DeployOptions, type DeployRawAppResult, type PluginDeployOptions, type PluginOptions, type Project, type RawAppField, type RawAppFileConfig, type RawAppProject, type RawAppRunnable, type WindmillApiProxyOptions, windmill as default, windmill, deploy };
|
|
128
|
+
//# sourceMappingURL=index.d.mts.map
|