77 open ,
88 windmillUtils ,
99 yamlParseFile ,
10+ SEP ,
1011} from "../../../deps.ts" ;
1112import { GlobalOptions } from "../../types.ts" ;
1213import * as http from "node:http" ;
@@ -16,15 +17,23 @@ import process from "node:process";
1617import { Buffer } from "node:buffer" ;
1718import { writeFileSync } from "node:fs" ;
1819import { WebSocketServer , WebSocket } from "npm:ws" ;
19- import { getDevBuildOptions , ensureNodeModules , createFrameworkPlugins , detectFrameworks } from "./bundle.ts" ;
20+ import {
21+ getDevBuildOptions ,
22+ ensureNodeModules ,
23+ createFrameworkPlugins ,
24+ detectFrameworks ,
25+ } from "./bundle.ts" ;
2026import { wmillTsDev as wmillTs } from "./wmillTsDev.ts" ;
2127import * as wmill from "../../../gen/services.gen.ts" ;
2228import { resolveWorkspace } from "../../core/context.ts" ;
2329import { requireLogin } from "../../core/auth.ts" ;
2430import { GLOBAL_CONFIG_OPT } from "../../core/conf.ts" ;
2531import { replaceInlineScripts } from "./apps.ts" ;
2632import { Runnable } from "./metadata.ts" ;
27- import { inferRunnableSchemaFromFile } from "./app_metadata.ts" ;
33+ import {
34+ APP_BACKEND_FOLDER ,
35+ inferRunnableSchemaFromFile ,
36+ } from "./app_metadata.ts" ;
2837
2938const DEFAULT_PORT = 4000 ;
3039const DEFAULT_HOST = "localhost" ;
@@ -92,8 +101,8 @@ async function dev(opts: DevOptions) {
92101 log . error (
93102 colors . red (
94103 `Error: The dev command must be run inside a .raw_app folder.\n` +
95- `Current directory: ${ currentDirName } \n` +
96- `Please navigate to a folder ending with '.raw_app' before running this command.`
104+ `Current directory: ${ currentDirName } \n` +
105+ `Please navigate to a folder ending with '.raw_app' before running this command.`
97106 )
98107 ) ;
99108 Deno . exit ( 1 ) ;
@@ -105,7 +114,7 @@ async function dev(opts: DevOptions) {
105114 log . error (
106115 colors . red (
107116 `Error: raw_app.yaml not found in current directory.\n` +
108- `The dev command must be run in a .raw_app folder containing a raw_app.yaml file.`
117+ `The dev command must be run in a .raw_app folder containing a raw_app.yaml file.`
109118 )
110119 ) ;
111120 Deno . exit ( 1 ) ;
@@ -133,7 +142,8 @@ async function dev(opts: DevOptions) {
133142
134143 // Detect frameworks to determine default entry point
135144 const frameworks = detectFrameworks ( process . cwd ( ) ) ;
136- const defaultEntry = ( frameworks . svelte || frameworks . vue ) ? "index.ts" : "index.tsx" ;
145+ const defaultEntry =
146+ frameworks . svelte || frameworks . vue ? "index.ts" : "index.tsx" ;
137147 const entryPoint = opts . entry ?? defaultEntry ;
138148
139149 // Verify entry point exists
@@ -206,7 +216,6 @@ async function dev(opts: DevOptions) {
206216 } ,
207217 } ;
208218
209-
210219 // Create esbuild context
211220 const ctx = await esbuild . context ( {
212221 ...buildOptions ,
@@ -242,7 +251,7 @@ async function dev(opts: DevOptions) {
242251 await ctx . rebuild ( ) ;
243252
244253 // Watch runnables folder for changes
245- const runnablesPath = path . join ( process . cwd ( ) , "runnables" ) ;
254+ const runnablesPath = path . join ( process . cwd ( ) , APP_BACKEND_FOLDER ) ;
246255 let runnablesWatcher : Deno . FsWatcher | undefined ;
247256
248257 if ( fs . existsSync ( runnablesPath ) ) {
@@ -262,7 +271,10 @@ async function dev(opts: DevOptions) {
262271 // Process each changed path with individual debouncing
263272 for ( const changedPath of event . paths ) {
264273 const relativePath = path . relative ( process . cwd ( ) , changedPath ) ;
265- const relativeToRunnables = path . relative ( runnablesPath , changedPath ) ;
274+ const relativeToRunnables = path . relative (
275+ runnablesPath ,
276+ changedPath
277+ ) ;
266278
267279 // Skip non-modify events for schema inference
268280 if ( event . kind !== "modify" && event . kind !== "create" ) {
@@ -276,7 +288,9 @@ async function dev(opts: DevOptions) {
276288
277289 // Log the change event
278290 log . info (
279- colors . cyan ( `📝 Runnable changed [${ event . kind } ]: ${ relativePath } ` )
291+ colors . cyan (
292+ `📝 Runnable changed [${ event . kind } ]: ${ relativePath } `
293+ )
280294 ) ;
281295
282296 // Debounce schema inference per file (wait for typing to finish)
@@ -288,7 +302,9 @@ async function dev(opts: DevOptions) {
288302 delete schemaInferenceTimeouts [ changedPath ] ;
289303
290304 try {
291- log . info ( colors . cyan ( `📝 Inferring schema for: ${ relativeToRunnables } ` ) ) ;
305+ log . info (
306+ colors . cyan ( `📝 Inferring schema for: ${ relativeToRunnables } ` )
307+ ) ;
292308 // Infer schema for this runnable (returns schema in memory, doesn't write to file)
293309 const result = await inferRunnableSchemaFromFile (
294310 process . cwd ( ) ,
@@ -299,7 +315,15 @@ async function dev(opts: DevOptions) {
299315 // log.info(colors.green(` Runnable ID: ${result.runnableId}`));
300316 // Store inferred schema in memory
301317 inferredSchemas [ result . runnableId ] = result . schema ;
302- log . info ( colors . green ( ` Inferred Schemas: ${ JSON . stringify ( inferredSchemas , null , 2 ) } ` ) ) ;
318+ log . info (
319+ colors . green (
320+ ` Inferred Schemas: ${ JSON . stringify (
321+ inferredSchemas ,
322+ null ,
323+ 2
324+ ) } `
325+ )
326+ ) ;
303327 // Regenerate wmill.d.ts with updated schema from memory
304328 await genRunnablesTs ( inferredSchemas ) ;
305329 }
@@ -468,7 +492,9 @@ async function dev(opts: DevOptions) {
468492 case "backendAsync" : {
469493 // Run a runnable asynchronously and return job ID immediately
470494 log . info (
471- colors . blue ( `[backendAsync] Running runnable async: ${ runnable_id } ` )
495+ colors . blue (
496+ `[backendAsync] Running runnable async: ${ runnable_id } `
497+ )
472498 ) ;
473499 try {
474500 const runnables = await loadRunnables ( ) ;
@@ -628,7 +654,10 @@ const command = new Command()
628654 . option ( "--host <host:string>" , "Host to bind the dev server to" , {
629655 default : DEFAULT_HOST ,
630656 } )
631- . option ( "--entry <entry:string>" , "Entry point file (default: index.ts for Svelte/Vue, index.tsx otherwise)" )
657+ . option (
658+ "--entry <entry:string>" ,
659+ "Entry point file (default: index.ts for Svelte/Vue, index.tsx otherwise)"
660+ )
632661 . option ( "--no-open" , "Don't automatically open the browser" )
633662 . action ( dev as any ) ;
634663
@@ -671,7 +700,11 @@ async function loadRunnables(): Promise<Record<string, Runnable>> {
671700 const rawApp = ( await yamlParseFile (
672701 path . join ( localPath , "raw_app.yaml" )
673702 ) ) as any ;
674- replaceInlineScripts ( rawApp . runnables , path . join ( localPath , "runnables/" ) ) ;
703+ replaceInlineScripts (
704+ rawApp . runnables ,
705+ path . join ( localPath , APP_BACKEND_FOLDER ) + SEP ,
706+ true
707+ ) ;
675708
676709 return rawApp ?. runnables ?? { } ;
677710 } catch ( error : any ) {
@@ -707,7 +740,10 @@ async function executeRunnable(
707740 }
708741 }
709742
710- if ( ( runnable . type === "inline" || runnable . type === "runnableByName" ) && runnable . inlineScript ) {
743+ if (
744+ ( runnable . type === "inline" || runnable . type === "runnableByName" ) &&
745+ runnable . inlineScript
746+ ) {
711747 const inlineScript = runnable . inlineScript ;
712748 if ( inlineScript . id !== undefined ) {
713749 requestBody . id = inlineScript . id ;
@@ -719,7 +755,10 @@ async function executeRunnable(
719755 lock : inlineScript . id === undefined ? inlineScript . lock : undefined ,
720756 cache_ttl : inlineScript . cache_ttl ,
721757 } ;
722- } else if ( ( runnable . type === "path" || runnable . type === "runnableByPath" ) && runnable . path ) {
758+ } else if (
759+ ( runnable . type === "path" || runnable . type === "runnableByPath" ) &&
760+ runnable . path
761+ ) {
723762 const runType = runnable . runType ?? "script" ;
724763 requestBody . path =
725764 runType !== "hubscript"
0 commit comments