-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.js
41 lines (29 loc) · 841 Bytes
/
convert.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
41
let la = require('./js/lexicalAnalyzer.js'),
pp = require('./js/phpParser.js'),
fs = require('fs');
let readFilePath = process.argv[2];
let contents = fs.readFileSync(readFilePath).toString();
let filePaths = readFilePath.split("/");
let fileName = filePaths.pop();
let dir = "dist/";
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
for(let i = 0;i < filePaths.length;i++) {
let path = filePaths[i];
if(!path)continue;
if(path === ".")continue;
if(path.match(/^[A-Z]:$/))continue;
dir += filePaths[i] + "/";
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir);
}
}
console.log(dir + fileName);
let tokens = la.run(contents);
let codes = pp.run(tokens);
let distCode = "";
for (let i = 0;i < codes.length;i++) {
distCode += codes[i].value;
}
fs.writeFileSync(dir + fileName, distCode);