-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
40 lines (32 loc) · 966 Bytes
/
main.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
31
32
33
34
35
36
37
38
39
40
var fs = require('fs')
var path = require('path')
const originalDir = path.join(__dirname, 'original')
const newDir = path.join(__dirname, 'new')
fs.readdir(originalDir, (err, files)=>{
if (err) {
return console.warn(err)
}
files.forEach(function (file){
// File Path of Original
let originalFilePath = path.join(originalDir, file)
filter(originalFilePath, file)
})
})
function filter(filePath) {
fs.readFile(filePath, 'utf-8', (err, data)=>{
if (err) {
console.log(err)
return
}
data = data.replace(/^[0-9]$/gm, "Verse $&");
data = data.replace("Refrain", "Chorus")
let file = path.join(newDir, data.split('\n')[0].slice(0, -1))
data = "Intro \n" + data
fs.writeFile(file + '.txt', data, (err)=>{
if (err) {
console.log(err)
}
console.log(file)
})
})
}