@@ -12,29 +12,52 @@ try {
1212 jsBuildTime = 0 ;
1313}
1414
15- // check if any of our repo files have a later time
16- let build = args . length > 0 && args . includes ( "--force" ) ;
17- try {
18- const command = new Deno . Command ( "git" , { args : [ "ls-files" ] } ) ;
19- const cmdOutput = await command . output ( ) ;
20- if ( cmdOutput . success ) {
21- const output = new TextDecoder ( ) . decode ( cmdOutput . stdout ) ;
22- const files = output . split ( "\n" ) . filter ( ( line ) => line . length > 0 ) ;
23- build = files . some ( ( file ) =>
24- Deno . statSync ( file ) . mtime ! . valueOf ( ) > jsBuildTime
25- ) ;
26- } else {
27- // not in a git repo, rebuild
28- build = true ;
29- }
30- } catch {
31- // git not installed, rebuild
32- build = true ;
33- }
15+ const buildFromArgs = ( ) => {
16+ return args . includes ( "--force" ) ;
17+ } ;
3418
35- if ( build ) {
36- const buildCommand = new Deno . Command ( Deno . execPath ( ) , {
37- args : [ "task" , "build" ] ,
19+ const run = async ( args : string [ ] , quiet = true ) => {
20+ const command = new Deno . Command ( Deno . execPath ( ) , {
21+ args,
3822 } ) ;
39- await buildCommand . spawn ( ) . status ;
23+ const output = await command . output ( ) ;
24+ if ( output . success || quiet ) {
25+ return output ;
26+ }
27+ console . error ( "Command failed" ) ;
28+ console . log ( new TextDecoder ( ) . decode ( output . stderr ) ) ;
29+ Deno . exit ( output . code ) ;
30+ } ;
31+
32+ const buildFromGit = async ( ) => {
33+ let output : Deno . CommandOutput ;
34+ try {
35+ const command = new Deno . Command ( "git" , { args : [ "ls-files" ] } ) ;
36+ output = await command . output ( ) ;
37+ } catch {
38+ // git not installed, rebuild
39+ return true ;
40+ }
41+ if ( ! output . success ) {
42+ return true ;
43+ }
44+ const stdout = new TextDecoder ( ) . decode ( output . stdout ) ;
45+ const files = stdout . split ( "\n" ) . filter ( ( line ) => line . length > 0 ) ;
46+ return files . some ( ( file ) =>
47+ Deno . statSync ( file ) . mtime ! . valueOf ( ) > jsBuildTime
48+ ) ;
49+ } ;
50+
51+ // check if any of our repo files have a later time
52+ const build = buildFromArgs ( ) || await buildFromGit ( ) ;
53+
54+ if ( ! build ) {
55+ console . log ( "No changes to quarto-preview.js, skipping build" ) ;
56+ Deno . exit ( 0 ) ;
4057}
58+
59+ console . log ( "Building quarto-preview.js" ) ;
60+ console . log ( "Installing..." ) ;
61+ await run ( [ "install" , "--allow-scripts" ] , false ) ;
62+ console . log ( "Building..." ) ;
63+ await run ( [ "task" , "build" ] , false ) ;
0 commit comments