@@ -4,18 +4,31 @@ const path = require("path")
44const { finished } = require ( "stream/promises" )
55const { Readable } = require ( "stream" )
66
7- const getAllFiles = function ( dirPath , arrayOfFiles ) {
7+ async function downloadFile ( url , outputPath ) {
8+ const response = await fetch ( url )
9+
10+ if ( ! response . ok ) {
11+ throw new Error ( `Failed to download, status: ${ response . status } ` )
12+ }
13+
14+ const directory = path . dirname ( outputPath )
15+
16+ fs . mkdirSync ( directory , { recursive : true } )
17+ fs . writeFileSync ( outputPath , Buffer . from ( await response . arrayBuffer ( ) ) )
18+ }
19+
20+ function getAllFiles ( dirPath , arrayOfFiles ) {
821 files = fs . readdirSync ( dirPath )
922
1023 arrayOfFiles = arrayOfFiles || [ ]
1124
12- files . forEach ( function ( file ) {
25+ for ( const file of files ) {
1326 if ( fs . statSync ( dirPath + "/" + file ) . isDirectory ( ) ) {
1427 arrayOfFiles = getAllFiles ( dirPath + "/" + file , arrayOfFiles )
1528 } else {
1629 arrayOfFiles . push ( path . join ( __dirname , dirPath , "/" , file ) )
1730 }
18- } )
31+ }
1932
2033 return arrayOfFiles
2134}
@@ -35,16 +48,26 @@ for (let path of getAllFiles("../test/tests/nattlua/analyzer/")) {
3548}
3649
3750fs . writeFileSync ( "src/random.json" , JSON . stringify ( tests ) )
38- ; ( async ( ) => {
39- const res = await fetch ( "https://unpkg.com/[email protected] /dist/glue.wasm" ) 40- fs . unlink ( "public/glue.wasm" , ( err ) => {
41- if ( err ) {
42- console . error ( err )
43- }
44- } )
45- const fileStream = fs . createWriteStream ( "public/glue.wasm" , { flags : "wx" } )
46- await finished ( Readable . fromWeb ( res . body ) . pipe ( fileStream ) )
47- } ) ( )
51+
52+ async function downloadLua ( ) {
53+ let baseUrl = "https://raw.githubusercontent.com/thenumbernine/js-util/7865018a985074f558b4337226d07e18fe5f9452/"
54+
55+ await downloadFile ( baseUrl + "lua-5.4.7-with-ffi.wasm" , "public/js/lua-5.4.7-with-ffi.wasm" )
56+ await downloadFile ( baseUrl + "lua-interop.js" , "public/js/lua-interop.js" )
57+ await downloadFile ( baseUrl + "lua-5.4.7-with-ffi.js" , "public/js/lua-5.4.7-with-ffi.js" )
58+ ; ( async ( ) => {
59+ const res = await fetch ( "https://unpkg.com/[email protected] /dist/glue.wasm" ) 60+ fs . unlink ( "public/glue.wasm" , ( err ) => {
61+ if ( err ) {
62+ console . error ( err )
63+ }
64+ } )
65+ const fileStream = fs . createWriteStream ( "public/glue.wasm" , { flags : "wx" } )
66+ await finished ( Readable . fromWeb ( res . body ) . pipe ( fileStream ) )
67+ } ) ( )
68+ }
69+
70+ downloadLua ( )
4871
4972execSync ( "cd ../ && luajit nattlua.lua build fast" )
5073
0 commit comments