-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathrun.js
153 lines (102 loc) · 2.26 KB
/
run.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
"use strict";
let child_process = require("child_process");
let fs = require("fs");
function GetPath(location)
{
if (location.length < 1)
{
return "";
}
let pos = location.lastIndexOf("/");
if (pos < 1)
{
return "";
}
return location.substring(0, pos);
}
function GetFileName(location)
{
if (location.length < 1)
{
return "";
}
let pos = (location.lastIndexOf("/") + 1);
if (pos >= location.length)
{
return "";
}
return location.substring(pos, location.length);
}
let args = process.argv;
let argCount = args.length;
if (argCount < 3)
{
console.log("Too few args. " + argCount);
console.log(args);
return;
}
let location = args[2].replace(/\\/g, "/");
if (location.length < 1)
{
console.log("Invalid Location");
return;
}
let currentPath = process.cwd().replace(/\\/g, "/");
let path = GetPath(location);
let fileName = GetFileName(location);
// console.log("path $" + path + "$");
// console.log("fileName $" + fileName + "$");
let match = path.match(/^[A-Z]:/);
if (!match)
{
// At this point we have no drive letter in the beginning.
if (path != "")
{
path = (currentPath + "/" + path);
}
else
{
path = currentPath;
}
}
// console.log("path $" + path + "$");
// console.log("fileName $" + fileName + "$");
if
(
(fileName.length < 3) ||
(fileName.substring((fileName.length - 3), fileName.length) != ".js")
)
{
fileName = fileName + ".js";
}
let prepFileName = "prep_" + fileName;
let newLocation = (path + "/" + fileName );
let newPrepLocation = (path + "/" + prepFileName);
console.log("path $" + path + "$");
console.log("fileName $" + fileName + "$");
console.log("prepFileName $" + prepFileName + "$");
console.log("newLocation $" + newLocation + "$");
console.log("newPrepLocation $" + newPrepLocation + "$");
let core = fs.readFileSync("core.js", "utf8");
let file = fs.readFileSync(newLocation, "utf8");
fs.writeFileSync(newPrepLocation, (core + file));
let newArgs =
[
newPrepLocation,
];
for (let index = 3; index < argCount; index++)
{
let arg = args[index];
newArgs.push(arg);
}
console.log(newArgs.length);
console.log(newArgs);
child_process.execFileSync
(
"node.exe",
newArgs,
{
stdio: "inherit",
encoding: "utf8"
}
);