11import {
2+ dirname ,
23 ensureDir ,
34 join ,
45 NAME ,
@@ -16,7 +17,7 @@ import {
1617import { livereloadServer } from "./livereload_server.ts" ;
1718import { byteSize , checkUniqueEntrypoints , mux } from "./util.ts" ;
1819import { logger , setLogLevel } from "./logger_util.ts" ;
19- import { setImportMap } from "./bundle_util.ts" ;
20+ import { setImportMap , setTsconfig } from "./bundle_util.ts" ;
2021
2122function usage ( ) {
2223 logger . log ( `
@@ -48,6 +49,7 @@ Options:
4849 --static-dist-prefix <prefix> The prefix for static files in the destination.
4950 --public-url <prefix> The path prefix for urls. Default is ".".
5051 -i, --import-map <file> The path to an import map file.
52+ -c, --config <file> The path to a tsconfig file.
5153 -o, --open Automatically opens in specified browser.
5254 TODO --https Serves files over HTTPS.
5355 TODO --cert <path> The path to certificate to use with HTTPS.
@@ -69,6 +71,7 @@ Options:
6971 --static-dist-prefix <prefix> The prefix for static files in the destination.
7072 --public-url <prefix> The path prefix for urls. Default is ".".
7173 -i, --import-map <file> The path to an import map file.
74+ -c, --config <file> The path to a tsconfig file.
7275 -L, --log-level <level> Set the log level (choices: "none", "error", "warn", "info", "verbose")
7376 -h, --help Display help for command
7477` . trim ( ) ) ;
@@ -87,6 +90,7 @@ type CliArgs = {
8790 "static-dir" : string ;
8891 "static-dist-prefix" : string ;
8992 "import-map" : string ;
93+ "config" : string ;
9094} ;
9195
9296/**
@@ -106,6 +110,7 @@ export async function main(cliArgs: string[] = Deno.args): Promise<number> {
106110 "public-url" : publicUrl = "." ,
107111 "livereload-port" : livereloadPort = 35729 ,
108112 "import-map" : importMap ,
113+ "config" : config ,
109114 } = parseFlags ( cliArgs , {
110115 string : [
111116 "log-level" ,
@@ -114,6 +119,7 @@ export async function main(cliArgs: string[] = Deno.args): Promise<number> {
114119 "static-dir" ,
115120 "public-url" ,
116121 "import-map" ,
122+ "config" ,
117123 ] ,
118124 boolean : [ "help" , "version" , "open" ] ,
119125 alias : {
@@ -124,6 +130,7 @@ export async function main(cliArgs: string[] = Deno.args): Promise<number> {
124130 L : "log-level" ,
125131 p : "port" ,
126132 i : "import-map" ,
133+ c : "config" ,
127134 } ,
128135 } ) as CliArgs ;
129136
@@ -191,6 +198,7 @@ export async function main(cliArgs: string[] = Deno.args): Promise<number> {
191198 publicUrl,
192199 staticDistPrefix,
193200 importMap,
201+ config,
194202 } ) ;
195203 return 0 ;
196204 }
@@ -218,6 +226,7 @@ export async function main(cliArgs: string[] = Deno.args): Promise<number> {
218226 publicUrl,
219227 staticDistPrefix,
220228 importMap,
229+ config,
221230 } ) ;
222231 return 0 ;
223232}
@@ -227,6 +236,7 @@ type BuildAndServeCommonOptions = {
227236 staticDistPrefix : string ;
228237 publicUrl : string ;
229238 importMap : string ;
239+ config : string ;
230240} ;
231241
232242type BuildOptions = {
@@ -244,10 +254,12 @@ async function build(
244254 publicUrl,
245255 staticDistPrefix,
246256 importMap,
257+ config,
247258 } : BuildOptions & BuildAndServeCommonOptions ,
248259) {
249260 checkUniqueEntrypoints ( paths ) ;
250261 setImportMap ( importMap ) ;
262+ setTsconfig ( config ) ;
251263
252264 logger . log ( `Writing the assets to ${ distDir } ` ) ;
253265 await ensureDir ( distDir ) ;
@@ -267,6 +279,7 @@ async function build(
267279 const bytes = new Uint8Array ( await asset . arrayBuffer ( ) ) ;
268280 // TODO(kt3k): Print more structured report
269281 logger . log ( "Writing" , filename , byteSize ( bytes . byteLength ) ) ;
282+ await ensureDir ( dirname ( filename ) ) ;
270283 await Deno . writeFile ( filename , bytes ) ;
271284 }
272285}
@@ -290,10 +303,12 @@ async function serve(
290303 publicUrl,
291304 staticDistPrefix,
292305 importMap,
306+ config,
293307 } : ServeOptions & BuildAndServeCommonOptions ,
294308) {
295309 checkUniqueEntrypoints ( paths ) ;
296310 setImportMap ( importMap ) ;
311+ setTsconfig ( config ) ;
297312
298313 // This is used for propagating onBuild event to livereload server.
299314 const buildEventHub = new EventTarget ( ) ;
0 commit comments