-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen.ts
41 lines (34 loc) · 1.01 KB
/
gen.ts
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
import 'zx/globals'
const run = async () => {
const files = 1500
// 20w
const lines = 20 * 10000
const oneFileLines = parseInt((lines / files).toString(), 10)
const tasks: Promise<void>[] = []
if (fs.existsSync(path.join(__dirname, './src'))) {
fs.removeSync(path.join(__dirname, './src'))
}
fs.mkdirSync(path.join(__dirname, './src'))
Array(files)
.fill(0)
.forEach((_, i) => {
const p = path.join(__dirname, './src', `file-${i}.ts`)
let content = Array(oneFileLines)
.fill(0)
.map((_, j) => {
const line = `const a${i}_${j} = 1`
return line
})
.join('\n')
const importFileNumber = i === files - 1 ? 0 : i + 1
const importLine = `import './file-${importFileNumber}'`
content = `${importLine}\n${content}`
const task = async () => {
console.log(`Writing ${path.basename(p)}`)
await fs.writeFile(p, content, 'utf-8')
}
tasks.push(task())
})
await Promise.all(tasks)
}
run()