| 61 | } |
| 62 | |
| 63 | async function fetchAndUnzipTfjsDebuggerBundle(version) { |
| 64 | let resp; |
| 65 | try { |
| 66 | resp = await new Promise(resolve => { |
| 67 | const fileUrl = |
| 68 | `${TFJS_DEBUGGER_BUNDLE_URL_BASE}/tfjs-debugger_${version}.zip`; |
| 69 | fetch(fileUrl).then(response => { |
| 70 | if (!response.ok) { |
| 71 | throw new Error(`Failed to load bundle: ${fileUrl}`); |
| 72 | } |
| 73 | resolve(response); |
| 74 | }) |
| 75 | }); |
| 76 | } catch (e) { |
| 77 | console.error(e.message); |
| 78 | } |
| 79 | const buffer = await resp.buffer(); |
| 80 | |
| 81 | // Read zip objects. |
| 82 | const zipObjects = await new Promise(resolve => { |
| 83 | const zipObjects = []; |
| 84 | JSZip.loadAsync(buffer).then((zip) => { |
| 85 | zip.folder('dist').forEach((relativePath, zipObject) => { |
| 86 | zipObjects.push(zipObject); |
| 87 | }); |
| 88 | resolve(zipObjects); |
| 89 | }) |
| 90 | }); |
| 91 | |
| 92 | // Read and index files content. |
| 93 | for (const zipObject of zipObjects) { |
| 94 | await new Promise(resolve => { |
| 95 | const name = zipObject.name; |
| 96 | zipObject |
| 97 | .async( |
| 98 | EXTS_WITH_ARRAY_BUFFER_CONTENT.some(ext => name.endsWith(ext)) ? |
| 99 | 'nodebuffer' : |
| 100 | 'text') |
| 101 | .then(content => { |
| 102 | const fileName = name.replace('dist/', ''); |
| 103 | debuggerStaticFile[fileName] = content; |
| 104 | resolve(); |
| 105 | }); |
| 106 | }); |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | const parser = new ArgumentParser({ |
| 111 | description: 'Run tfjs-debugger locally that supports loading local packages', |