Skip to content

Commit

Permalink
feat: allow multiple file selection for analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyaliao committed Oct 4, 2024
1 parent e33cc05 commit 45355ec
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ async function main(): Promise<void> {
process.exit(1)
}

const selectFile = await prompt('請選擇分析的檔案:', {
type: 'select',
const selectedFiles = await prompt('請選擇分析的檔案(可多選):', {
type: 'multiselect',
options: filterFiles,
})

const filePath = new URL(`../data/${selectFile}`, import.meta.url)
let payload: Payload[] = []

const payload = JSON.parse(await fs.readFile(
new URL(filePath, import.meta.url),
'utf-8',
)) as Payload[]
for (const selectFile of selectedFiles) {
const filePath = new URL(`../data/${selectFile}`, import.meta.url)
const fileContent = JSON.parse(await fs.readFile(filePath, 'utf-8')) as Payload[]
payload = payload.concat(fileContent)
}
consola.info(`共有 ${payload.length} 筆資料,共花費 ${(cost() / 1000).toFixed(2)} 秒`)

const channels = [...new Set(payload.map(item => item.source.channel))]
Expand Down

0 comments on commit 45355ec

Please sign in to comment.