-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
45 lines (36 loc) · 953 Bytes
/
script.js
File metadata and controls
45 lines (36 loc) · 953 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//@ts-check
import { extractProjectJson } from './src/extract.js'
import { optimize } from './src/optimizer/index.js'
const fileInput = /** @type {HTMLInputElement} */(
document.getElementById('file_upload')
)
/**
* @param {number} progress
*/
function onProgress(progress) {
console.log('추출 %d%%', progress * 100)
}
/**
* @param {string} message
* @param {string[]} stack
*/
function log(message, stack) {
console.log('%s\n%s', message, stack.join('\n'))
}
/**
* 파일이 로딩 중일 때 다른 파일을 선택하면 abort됨.
* @type {AbortController | undefined}
*/
let controller
fileInput.addEventListener('change', async () => {
controller?.abort()
const { signal } = controller = new AbortController
const pack = fileInput.files?.[0]
if (!pack) return
const project = await extractProjectJson(pack, {
onProgress,
signal,
})
const optimized = optimize(project, log)
console.log(optimized)
})