-
Notifications
You must be signed in to change notification settings - Fork 0
/
compile.js
30 lines (26 loc) · 1.27 KB
/
compile.js
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
const fs = require('fs')
const path = require('path')
let errors = 0, libsImported = 0, filesDone = 0
fs.readdirSync('src').forEach(filePath => {
if (fs.existsSync(path.join('bin', filePath))) fs.unlinkSync(path.join('bin', filePath))
fs.readFileSync(path.join('src', filePath), 'utf-8').split('\n').forEach(line => {
line = line.trim()
const matches = /(?<=(#include ))(.{1,})$/.exec(line)
if (matches) {
const libPath = matches[0]
if (!fs.existsSync(path.join('libs', libPath))) {
console.error(`Library "${libPath}" does not exist in the libs directory`)
fs.appendFileSync(path.join('bin', filePath), line.replace(`#include ${libPath}`, `Library "${libPath}" not found\n`))
errors++
return
}
console.log('Importing library', libPath, 'into', filePath, )
fs.appendFileSync(path.join('bin', filePath), fs.readFileSync(path.join('libs', libPath), 'utf8') + '\n')
libsImported++
} else {
fs.appendFileSync(path.join('bin', filePath), line + '\n')
}
})
filesDone++
})
console.log('Imported', libsImported, 'libraries total between', filesDone, 'files, with', errors, 'errors')