@liascript/devserver 1.1.2--0.12.3 → 1.1.2--0.12.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +19 -269
- package/dist/index.js.map +1 -1
- package/package.json +10 -4
- package/views/main.hbs +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,37 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var $9KXPr$path = require("path");
|
|
5
|
-
var $9KXPr$dotenv = require("dotenv");
|
|
6
|
-
var $9KXPr$express = require("express");
|
|
7
|
-
var $9KXPr$fs = require("fs");
|
|
8
|
-
var $9KXPr$cors = require("cors");
|
|
9
|
-
var $9KXPr$expresshandlebars = require("express-handlebars");
|
|
10
|
-
var $9KXPr$ip = require("ip");
|
|
11
|
-
var $9KXPr$open = require("open");
|
|
12
|
-
var $9KXPr$bodyparser = require("body-parser");
|
|
13
|
-
var $9KXPr$reloadshjs = require("reloadsh.js");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var $dbf4313da36ea993$var$$parcel$__dirname = $9KXPr$path.resolve(__dirname, "../src");
|
|
20
|
-
|
|
21
|
-
$9KXPr$dotenv.config();
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const $dbf4313da36ea993$var$app = $9KXPr$express();
|
|
28
|
-
$dbf4313da36ea993$var$app.use($9KXPr$bodyparser.json());
|
|
29
|
-
var $dbf4313da36ea993$var$dirname = "";
|
|
30
|
-
var $dbf4313da36ea993$var$node_modules;
|
|
31
|
-
var $dbf4313da36ea993$var$reloadPath = "";
|
|
32
|
-
var $dbf4313da36ea993$var$liascriptPath = "";
|
|
33
|
-
var $dbf4313da36ea993$var$clients = [];
|
|
34
|
-
const $dbf4313da36ea993$var$gotoScript = `<script>
|
|
3
|
+
var e,o=require("minimist"),t=require("path"),n=require("dotenv"),i=require("express"),r=require("fs"),s=require("cors"),l=require("express-handlebars"),a=require("ip"),c=require("open"),p=require("body-parser"),d=require("reloadsh.js"),h=t.resolve(__dirname,"../src");n.config();const _=i();_.use(p.json());var u="",m="",g="",f=[];const v=`<script>
|
|
35
4
|
if (!window.LIA) {
|
|
36
5
|
window.LIA = {}
|
|
37
6
|
}
|
|
@@ -63,242 +32,23 @@ events.onmessage = (event) => {
|
|
|
63
32
|
console.warn("gotoLine failed")
|
|
64
33
|
}
|
|
65
34
|
};
|
|
66
|
-
</script>`;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
path: input,
|
|
85
|
-
readme: undefined
|
|
86
|
-
};
|
|
87
|
-
if (input) {
|
|
88
|
-
const stats = $9KXPr$fs.lstatSync(input);
|
|
89
|
-
// Is it a directory?
|
|
90
|
-
if (stats.isDirectory()) project.path = input;
|
|
91
|
-
else if (stats.isFile()) {
|
|
92
|
-
project.path = $9KXPr$path.dirname(input);
|
|
93
|
-
project.readme = $9KXPr$path.basename(input);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
$dbf4313da36ea993$var$app.set("view engine", "hbs");
|
|
97
|
-
$dbf4313da36ea993$var$app.engine("hbs", $9KXPr$expresshandlebars({
|
|
98
|
-
layoutsDir: $9KXPr$path.resolve($9KXPr$path.join($dbf4313da36ea993$var$dirname, "views/layouts")),
|
|
99
|
-
defaultLayout: "main",
|
|
100
|
-
extname: "hbs"
|
|
101
|
-
}));
|
|
102
|
-
$dbf4313da36ea993$var$app.set("views", $9KXPr$path.resolve($9KXPr$path.join($dbf4313da36ea993$var$dirname, "views")));
|
|
103
|
-
$dbf4313da36ea993$var$app.get("/", function(req, res) {
|
|
104
|
-
res.redirect("/home");
|
|
105
|
-
});
|
|
106
|
-
$dbf4313da36ea993$var$app.get("/gotoLine", $dbf4313da36ea993$var$eventsHandler);
|
|
107
|
-
$dbf4313da36ea993$var$app.get("/home*", function(req, res) {
|
|
108
|
-
const currentPath = project.path + "/" + req.params[0];
|
|
109
|
-
const stats = $9KXPr$fs.lstatSync(currentPath);
|
|
110
|
-
// Is it a directory?
|
|
111
|
-
if (stats.isDirectory()) {
|
|
112
|
-
const files = $9KXPr$fs.readdirSync(currentPath).filter((e)=>{
|
|
113
|
-
return e[0] !== ".";
|
|
114
|
-
});
|
|
115
|
-
let basePath = "/home";
|
|
116
|
-
let pathNames = req.params[0].split("/").filter((e)=>{
|
|
117
|
-
return e !== "";
|
|
118
|
-
});
|
|
119
|
-
let paths = [];
|
|
120
|
-
for(let i = 0; i < pathNames.length; i++){
|
|
121
|
-
basePath += "/" + pathNames[i];
|
|
122
|
-
paths.push({
|
|
123
|
-
name: pathNames[i],
|
|
124
|
-
href: basePath
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
res.render("main", {
|
|
128
|
-
layout: "index",
|
|
129
|
-
path: paths,
|
|
130
|
-
file: files.map((file)=>{
|
|
131
|
-
return {
|
|
132
|
-
name: file,
|
|
133
|
-
href: `http://${hostname}:${port}/home${req.params[0]}/${file}`,
|
|
134
|
-
isDirectory: $9KXPr$fs.lstatSync(currentPath + "/" + file).isDirectory()
|
|
135
|
-
};
|
|
136
|
-
}).sort((a, b)=>{
|
|
137
|
-
if (a.isDirectory && !b.isDirectory) return -1;
|
|
138
|
-
else if (!a.isDirectory && b.isDirectory) return 1;
|
|
139
|
-
else {
|
|
140
|
-
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) return -1;
|
|
141
|
-
else return 1;
|
|
142
|
-
}
|
|
143
|
-
return 0;
|
|
144
|
-
})
|
|
145
|
-
});
|
|
146
|
-
} else if (stats.isFile()) {
|
|
147
|
-
if (req.params[0].toLocaleLowerCase().endsWith(".md")) {
|
|
148
|
-
if (testOnline) res.redirect(`https://LiaScript.github.io/course/?http://${hostname}:${port}/${req.params[0]}`);
|
|
149
|
-
else res.redirect(`/liascript/index.html?http://${hostname}:${port}/${req.params[0]}`);
|
|
150
|
-
} else res.sendFile(req.params[0], {
|
|
151
|
-
root: project.path
|
|
152
|
-
});
|
|
153
|
-
} else res.send("ups, something went wrong");
|
|
154
|
-
});
|
|
155
|
-
$dbf4313da36ea993$var$app.get("/liascript/", function(req, res) {
|
|
156
|
-
res.redirect("/liascript/index.html");
|
|
157
|
-
});
|
|
158
|
-
$dbf4313da36ea993$var$app.get("/liascript/index.html", function(req, res) {
|
|
159
|
-
// ------------------------------------
|
|
160
|
-
if (liveReload && responsiveVoice) $9KXPr$fs.readFile($dbf4313da36ea993$var$liascriptPath + "/index.html", "utf8", function(err, data) {
|
|
161
|
-
res.send(data.replace("</head>", `<script type='text/javascript' src='/reloader/reloader.js'></script>
|
|
162
|
-
<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>
|
|
163
|
-
${$dbf4313da36ea993$var$gotoScript}
|
|
164
|
-
</head>`));
|
|
165
|
-
});
|
|
166
|
-
else if (liveReload) $9KXPr$fs.readFile($dbf4313da36ea993$var$liascriptPath + "/index.html", "utf8", function(err, data) {
|
|
167
|
-
res.send(data.replace("</head>", `<script type='text/javascript' src='/reloader/reloader.js'></script>
|
|
168
|
-
${$dbf4313da36ea993$var$gotoScript}
|
|
169
|
-
</head>`));
|
|
170
|
-
});
|
|
171
|
-
else if (responsiveVoice) $9KXPr$fs.readFile($dbf4313da36ea993$var$liascriptPath + "/index.html", "utf8", function(err, data) {
|
|
172
|
-
res.send(data.replace("</head>", `<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>
|
|
173
|
-
${$dbf4313da36ea993$var$gotoScript}
|
|
174
|
-
</head>`));
|
|
175
|
-
});
|
|
176
|
-
else $9KXPr$fs.readFile($dbf4313da36ea993$var$liascriptPath + "/index.html", "utf8", function(err, data) {
|
|
177
|
-
res.send(data.replace("</head>", `${$dbf4313da36ea993$var$gotoScript}</head>`));
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
// load everything from the liascript folder
|
|
181
|
-
$dbf4313da36ea993$var$app.get("/liascript/*", function(req, res) {
|
|
182
|
-
res.sendFile(req.params[0], {
|
|
183
|
-
root: $dbf4313da36ea993$var$liascriptPath
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
// ignore this one
|
|
187
|
-
$dbf4313da36ea993$var$app.get("/sw.js", function(req, res) {});
|
|
188
|
-
$dbf4313da36ea993$var$app.get("/favicon.ico", function(req, res) {});
|
|
189
|
-
// pass the reloader, to be used for live updates
|
|
190
|
-
$dbf4313da36ea993$var$app.get("/reloader/reloader.js", function(req, res) {
|
|
191
|
-
res.sendFile($dbf4313da36ea993$var$reloadPath);
|
|
192
|
-
});
|
|
193
|
-
// react to click-events
|
|
194
|
-
$dbf4313da36ea993$var$app.post("/lineGoto", function(req, res) {
|
|
195
|
-
if (gotoCallback) try {
|
|
196
|
-
const linenumber = req.body.linenumber;
|
|
197
|
-
const filename = req.body.filename;
|
|
198
|
-
gotoCallback(linenumber, filename);
|
|
199
|
-
} catch (e) {
|
|
200
|
-
console.warn("lineGoto event with wrong datatype, you have to provide {'linenumber': int, 'filename': string}");
|
|
201
|
-
}
|
|
202
|
-
return res.json({});
|
|
203
|
-
});
|
|
204
|
-
// everything else comes from the current project folder
|
|
205
|
-
$dbf4313da36ea993$var$app.get("/*", $9KXPr$cors(), function(req, res) {
|
|
206
|
-
res.sendFile(req.originalUrl, {
|
|
207
|
-
root: project.path
|
|
208
|
-
});
|
|
209
|
-
});
|
|
210
|
-
let localURL = "http://" + hostname + ":" + port;
|
|
211
|
-
if (project.path && project.readme) localURL += "/liascript/index.html?http://" + hostname + ":" + port + "/" + project.readme;
|
|
212
|
-
if (testOnline && project.readme) localURL = "https://LiaScript.github.io/course/?http://" + hostname + ":" + port + "/" + project.readme;
|
|
213
|
-
const server = $9KXPr$reloadshjs($dbf4313da36ea993$var$app, liveReload ? [
|
|
214
|
-
$9KXPr$path.join(project.path, project.readme || "")
|
|
215
|
-
] : []);
|
|
216
|
-
if (liveReload) console.log(`✨ watching for changes on: "${$9KXPr$path.join(project.path || "", project.readme || "")}"`);
|
|
217
|
-
server.on("error", (e)=>{
|
|
218
|
-
throw e;
|
|
219
|
-
});
|
|
220
|
-
server.listen(port);
|
|
221
|
-
if (openInBrowser) $9KXPr$open(localURL);
|
|
222
|
-
console.log("\uD83D\uDCE1 starting server");
|
|
223
|
-
console.log(` - local: ${localURL}`);
|
|
224
|
-
console.log(` - on your network: ${localURL.replace(hostname, $9KXPr$ip.address())}`);
|
|
225
|
-
$dbf4313da36ea993$var$serverPointer = server;
|
|
226
|
-
}
|
|
227
|
-
function $dbf4313da36ea993$export$fa6813432f753b0d() {
|
|
228
|
-
if ($dbf4313da36ea993$var$serverPointer) $dbf4313da36ea993$var$serverPointer.close();
|
|
229
|
-
}
|
|
230
|
-
function $dbf4313da36ea993$export$5d5b784f9a618ec3(linenumber, filename) {
|
|
231
|
-
$dbf4313da36ea993$var$clients.forEach((client)=>client.response.write(`data: ${JSON.stringify({
|
|
232
|
-
linenumber: linenumber,
|
|
233
|
-
filename: filename
|
|
234
|
-
})}\n\n`));
|
|
235
|
-
}
|
|
236
|
-
function $dbf4313da36ea993$var$eventsHandler(request, response, next) {
|
|
237
|
-
const headers = {
|
|
238
|
-
"Content-Type": "text/event-stream",
|
|
239
|
-
Connection: "keep-alive",
|
|
240
|
-
"Cache-Control": "no-cache"
|
|
241
|
-
};
|
|
242
|
-
response.writeHead(200, headers);
|
|
243
|
-
const data = `data: \n\n`;
|
|
244
|
-
response.write(data);
|
|
245
|
-
const clientId = Date.now();
|
|
246
|
-
const newClient = {
|
|
247
|
-
id: clientId,
|
|
248
|
-
response: response
|
|
249
|
-
};
|
|
250
|
-
$dbf4313da36ea993$var$clients.push(newClient);
|
|
251
|
-
request.on("close", ()=>{
|
|
252
|
-
console.log(`${clientId} Connection closed`);
|
|
253
|
-
$dbf4313da36ea993$var$clients = $dbf4313da36ea993$var$clients.filter((client)=>client.id !== clientId);
|
|
254
|
-
});
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
const $aa3bf3164f10b283$var$argv = $9KXPr$minimist(process.argv.slice(2));
|
|
260
|
-
function $aa3bf3164f10b283$var$liascript() {
|
|
261
|
-
console.log(" _ _ ____ _ _");
|
|
262
|
-
console.log("| | (_) __ _/ ___| ___ _ __(_)_ __ | |_");
|
|
263
|
-
console.log("| | | |/ _` \\___ \\ / __| '__| | '_ \\| __|");
|
|
264
|
-
console.log("| |___| | (_| |___) | (__| | | | |_) | |_ ");
|
|
265
|
-
console.log("|_____|_|\\__,_|____/ \\___|_| |_| .__/ \\__|");
|
|
266
|
-
console.log(" |_|");
|
|
267
|
-
console.log();
|
|
268
|
-
}
|
|
269
|
-
if ($aa3bf3164f10b283$var$argv.v || $aa3bf3164f10b283$var$argv.version) {
|
|
270
|
-
console.log("DevServer: 1.1.2");
|
|
271
|
-
console.log("LiaScript: 0.12.3");
|
|
272
|
-
process.exit();
|
|
273
|
-
}
|
|
274
|
-
if ($aa3bf3164f10b283$var$argv.h || $aa3bf3164f10b283$var$argv.help) {
|
|
275
|
-
$aa3bf3164f10b283$var$liascript();
|
|
276
|
-
console.log("-h --help show this help");
|
|
277
|
-
console.log("-v --version show version information");
|
|
278
|
-
console.log("-i --input input README.md file or folder (default: .)");
|
|
279
|
-
console.log("-n --hostname hostname of your server (default: localhost)");
|
|
280
|
-
console.log("-p --port used port number (default: 3000)");
|
|
281
|
-
console.log("-l --live do live reload on file change");
|
|
282
|
-
console.log("-o --open open in default browser");
|
|
283
|
-
console.log("-t --test test online on https://LiaScript.github.io");
|
|
284
|
-
console.log();
|
|
285
|
-
console.log("-r --responsiveVoice add optional responsiveVoice support,");
|
|
286
|
-
console.log(" or pass your own responsiveVoice key.");
|
|
287
|
-
console.log(" Adding this feature might slow down");
|
|
288
|
-
console.log(" the reloading speed.");
|
|
289
|
-
console.log(" For more information visit:");
|
|
290
|
-
console.log(" https://responsivevoice.org");
|
|
291
|
-
process.exit();
|
|
292
|
-
}
|
|
293
|
-
$aa3bf3164f10b283$var$liascript();
|
|
294
|
-
$dbf4313da36ea993$export$2cd8252107eb640b($aa3bf3164f10b283$var$argv.node_modules);
|
|
295
|
-
try {
|
|
296
|
-
$dbf4313da36ea993$export$b3571188c770cc5a($aa3bf3164f10b283$var$argv.p || $aa3bf3164f10b283$var$argv.port, $aa3bf3164f10b283$var$argv.n || $aa3bf3164f10b283$var$argv.hostname, $aa3bf3164f10b283$var$argv.i || $aa3bf3164f10b283$var$argv.input, $aa3bf3164f10b283$var$argv.r || $aa3bf3164f10b283$var$argv.responsiveVoice || process.env.RESPONSIVE_VOICE_KEY, $aa3bf3164f10b283$var$argv.l || $aa3bf3164f10b283$var$argv.live, $aa3bf3164f10b283$var$argv.o || $aa3bf3164f10b283$var$argv.open, $aa3bf3164f10b283$var$argv.t || $aa3bf3164f10b283$var$argv.test);
|
|
297
|
-
} catch (e) {
|
|
298
|
-
console.error("Error: ", e.message);
|
|
299
|
-
process.exit();
|
|
300
|
-
}
|
|
301
|
-
console.log("✨ hit Ctrl-c to close the server");
|
|
302
|
-
|
|
35
|
+
</script>`;function y(o,n){u=o||t.join(h,".."),e=n||t.join(u,"node_modules"),m=t.resolve(t.join(e,"reloadsh.js/reloader.browser.js")),g=t.resolve(t.join(e,"@liascript/editor/dist"))}function w(e,o,t){o.writeHead(200,{"Content-Type":"text/event-stream",Connection:"keep-alive","Cache-Control":"no-cache"});let n=`data:
|
|
36
|
+
|
|
37
|
+
`;o.write(n);let i=Date.now();f.push({id:i,response:o}),e.on("close",()=>{console.log(`${i} Connection closed`),f=f.filter(e=>e.id!==i)})}y(h);const j=o(process.argv.slice(2));function b(){console.log(" _ _ ____ _ _"),console.log("| | (_) __ _/ ___| ___ _ __(_)_ __ | |_"),console.log("| | | |/ _` \\___ \\ / __| '__| | '_ \\| __|"),console.log("| |___| | (_| |___) | (__| | | | |_) | |_ "),console.log("|_____|_|\\__,_|____/ \\___|_| |_| .__/ \\__|"),console.log(" |_|"),console.log()}(j.v||j.version)&&(console.log("DevServer: 1.1.2"),console.log("LiaScript: 0.12.6"),process.exit()),(j.h||j.help)&&(b(),console.log("-h --help show this help"),console.log("-v --version show version information"),console.log("-i --input input README.md file or folder (default: .)"),console.log("-n --hostname hostname of your server (default: localhost)"),console.log("-p --port used port number (default: 3000)"),console.log("-l --live do live reload on file change"),console.log("-o --open open in default browser"),console.log("-t --test test online on https://LiaScript.github.io"),console.log(),console.log("-r --responsiveVoice add optional responsiveVoice support,"),console.log(" or pass your own responsiveVoice key."),console.log(" Adding this feature might slow down"),console.log(" the reloading speed."),console.log(" For more information visit:"),console.log(" https://responsivevoice.org"),process.exit()),b(),y(j.node_modules);try{!function(e,o,n,i,p,h,f,y){e=e||3e3,o=o||"localhost",h=h||!1,p=p||!1,f=f||!1;var j={path:n=n||".",readme:void 0};if(n){let e=r.lstatSync(n);// Is it a directory?
|
|
38
|
+
e.isDirectory()?j.path=n:e.isFile()&&(j.path=t.dirname(n),j.readme=t.basename(n))}_.set("view engine","hbs"),_.engine("hbs",l({layoutsDir:t.resolve(t.join(u,"views/layouts")),defaultLayout:"main",extname:"hbs"})),_.set("views",t.resolve(t.join(u,"views"))),_.get("/",function(e,o){o.redirect("/home")}),_.get("/gotoLine",w),_.get("/home*",function(t,n){let i=j.path+"/"+t.params[0],s=r.lstatSync(i);// Is it a directory?
|
|
39
|
+
if(s.isDirectory()){let s=r.readdirSync(i).filter(e=>"."!==e[0]),l="/home",a=t.params[0].split("/").filter(e=>""!==e),c=[];for(let e=0;e<a.length;e++)l+="/"+a[e],c.push({name:a[e],href:l});n.render("main",{layout:"index",path:c,file:s.map(n=>({name:n,href:`http://${o}:${e}/home${t.params[0]}/${n}`,isDirectory:r.lstatSync(i+"/"+n).isDirectory()})).sort((e,o)=>e.isDirectory&&!o.isDirectory?-1:!e.isDirectory&&o.isDirectory?1:e.name.toLocaleLowerCase()<o.name.toLocaleLowerCase()?-1:1)})}else s.isFile()?t.params[0].toLocaleLowerCase().endsWith(".md")?f?n.redirect(`https://LiaScript.github.io/course/?http://${o}:${e}/${t.params[0]}`):n.redirect(`/liascript/index.html?http://${o}:${e}/${t.params[0]}`):n.sendFile(t.params[0],{root:j.path}):n.send("ups, something went wrong")}),_.get("/liascript/",function(e,o){o.redirect("/liascript/index.html")}),_.get("/liascript/index.html",function(e,o){// ------------------------------------
|
|
40
|
+
p&&i?r.readFile(g+"/index.html","utf8",function(e,t){o.send(t.replace("</head>",`<script type='text/javascript' src='/reloader/reloader.js'></script>
|
|
41
|
+
<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${i}'></script>
|
|
42
|
+
${v}
|
|
43
|
+
</head>`))}):p?r.readFile(g+"/index.html","utf8",function(e,t){o.send(t.replace("</head>",`<script type='text/javascript' src='/reloader/reloader.js'></script>
|
|
44
|
+
${v}
|
|
45
|
+
</head>`))}):i?r.readFile(g+"/index.html","utf8",function(e,t){o.send(t.replace("</head>",`<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${i}'></script>
|
|
46
|
+
${v}
|
|
47
|
+
</head>`))}):r.readFile(g+"/index.html","utf8",function(e,t){o.send(t.replace("</head>",`${v}</head>`))})}),// load everything from the liascript folder
|
|
48
|
+
_.get("/liascript/*",function(e,o){o.sendFile(e.params[0],{root:g})}),// ignore this one
|
|
49
|
+
_.get("/sw.js",function(e,o){}),_.get("/favicon.ico",function(e,o){}),// pass the reloader, to be used for live updates
|
|
50
|
+
_.get("/reloader/reloader.js",function(e,o){o.sendFile(m)}),// react to click-events
|
|
51
|
+
_.post("/lineGoto",function(e,o){if(y)try{let o=e.body.linenumber,t=e.body.filename;y(o,t)}catch(e){console.warn("lineGoto event with wrong datatype, you have to provide {'linenumber': int, 'filename': string}")}return o.json({})}),// everything else comes from the current project folder
|
|
52
|
+
_.get("/*",s(),function(e,o){o.sendFile(e.originalUrl,{root:j.path})});let b="http://"+o+":"+e;j.path&&j.readme&&(b+="/liascript/index.html?http://"+o+":"+e+"/"+j.readme),f&&j.readme&&(b="https://LiaScript.github.io/course/?http://"+o+":"+e+"/"+j.readme);let x=d(_,p?[t.join(j.path,j.readme||"")]:[]);p&&console.log(`✨ watching for changes on: "${t.join(j.path||"",j.readme||"")}"`),x.on("error",e=>{throw e}),x.listen(e),h&&c(b),console.log("\uD83D\uDCE1 starting server"),console.log(` - local: ${b}`),console.log(` - on your network: ${b.replace(o,a.address())}`)}(j.p||j.port,j.n||j.hostname,j.i||j.input,j.r||j.responsiveVoice||process.env.RESPONSIVE_VOICE_KEY,j.l||j.live,j.o||j.open,j.t||j.test)}catch(e){console.error("Error: ",e.message),process.exit()}console.log("✨ hit Ctrl-c to close the server");//# sourceMappingURL=index.js.map
|
|
303
53
|
|
|
304
54
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;ACAA;;;;;;AAYA,MAAM,4BAA2B;AACjC,0BAAI,IAAI;AAER,IAAI,gCAAU;AACd,IAAI;AACJ,IAAI,mCAAa;AACjB,IAAI,sCAAgB;AAEpB,IAAI,gCAAU,EAAE;AAEhB,MAAM,mCAAa,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SAgCX,CAAC;AAEV,IAAI;AAEJ,0CAAK;AAEE,SAAS,0CAAK,UAAmB,EAAE,eAAwB;IAChE,gCAAU,cAAc,iBAAU,yCAAW;IAE7C,qCAAe,mBAAmB,iBAAU,+BAAS;IAErD,mCAAa,oBACX,iBAAU,oCAAc;IAG1B,sCAAgB,oBACd,iBAAU,oCAAc;AAE5B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C,EAAE,SAAS,kBAAkB,CAAC;QAC3C,gCAAU,8BAAQ,OAAO,CAAC,SAAW,OAAO,OAAO;IACrD;AACF;;;;AD3aA,MAAM,6BAAO,gBAAoB,QAAQ,KAAK,MAAM;AAIpD,SAAS;IACP,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ;AACV;AAEA,IAAI,2BAAK,KAAK,2BAAK,SAAS;IAC1B,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ;AACV;AAEA,IAAI,2BAAK,KAAK,2BAAK,MAAM;IACvB;IAEA,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ;IACR,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,QAAQ,IAAI;IAEZ,QAAQ;AACV;AAEA;AAEA,0CAAY,2BAAK;AAEjB,IAAI;IACF,0CACE,2BAAK,KAAK,2BAAK,MACf,2BAAK,KAAK,2BAAK,UACf,2BAAK,KAAK,2BAAK,OACf,2BAAK,KAAK,2BAAK,mBAAmB,QAAQ,IAAI,sBAC9C,2BAAK,KAAK,2BAAK,MACf,2BAAK,KAAK,2BAAK,MACf,2BAAK,KAAK,2BAAK;AAEnB,EAAE,OAAO,GAAG;IACV,QAAQ,MAAM,WAAW,EAAE;IAC3B,QAAQ;AACV;AAEA,QAAQ,IAAI","sources":["src/index.ts","src/lib.ts"],"sourcesContent":["const argv = require('minimist')(process.argv.slice(2))\n\nimport * as server from './lib'\n\nfunction liascript() {\n console.log(' _ _ ____ _ _')\n console.log('| | (_) __ _/ ___| ___ _ __(_)_ __ | |_')\n console.log(\"| | | |/ _` \\\\___ \\\\ / __| '__| | '_ \\\\| __|\")\n console.log('| |___| | (_| |___) | (__| | | | |_) | |_ ')\n console.log('|_____|_|\\\\__,_|____/ \\\\___|_| |_| .__/ \\\\__|')\n console.log(' |_|')\n console.log()\n}\n\nif (argv.v || argv.version) {\n console.log('DevServer: 1.1.2')\n console.log('LiaScript: 0.12.3')\n process.exit()\n}\n\nif (argv.h || argv.help) {\n liascript()\n\n console.log('-h --help show this help')\n console.log('-v --version show version information')\n console.log('-i --input input README.md file or folder (default: .)')\n console.log('-n --hostname hostname of your server (default: localhost)')\n console.log('-p --port used port number (default: 3000)')\n console.log('-l --live do live reload on file change')\n console.log('-o --open open in default browser')\n console.log('-t --test test online on https://LiaScript.github.io')\n console.log()\n console.log('-r --responsiveVoice add optional responsiveVoice support,')\n console.log(' or pass your own responsiveVoice key.')\n console.log(' Adding this feature might slow down')\n console.log(' the reloading speed.')\n console.log(' For more information visit:')\n console.log(' https://responsivevoice.org')\n\n process.exit()\n}\n\nliascript()\n\nserver.init(argv.node_modules)\n\ntry {\n server.start(\n argv.p || argv.port,\n argv.n || argv.hostname,\n argv.i || argv.input,\n argv.r || argv.responsiveVoice || process.env.RESPONSIVE_VOICE_KEY,\n argv.l || argv.live,\n argv.o || argv.open,\n argv.t || argv.test\n )\n} catch (e) {\n console.error('Error: ', e.message)\n process.exit()\n}\n\nconsole.log('✨ hit Ctrl-c to close the server')\n","require('dotenv').config()\nimport * as express from 'express'\n\nimport * as fs from 'fs'\nimport * as path from 'path'\n\nconst cors = require('cors')\nconst handlebars = require('express-handlebars')\nconst ip = require('ip')\nconst open = require('open')\nconst bodyParser = require('body-parser')\n\nconst app: express.Application = express()\napp.use(bodyParser.json())\n\nvar dirname = ''\nvar node_modules\nvar reloadPath = ''\nvar liascriptPath = ''\n\nvar clients = []\n\nconst gotoScript = `<script>\nif (!window.LIA) {\n window.LIA = {}\n}\n\nvar filename__ = document.location.search.replace(\"?\"+document.location.origin, \"\")\n\nwindow.LIA.lineGoto = function(linenumber) {\n fetch(\"/lineGoto\", {\n method: \"POST\",\n headers: {'Content-Type': 'application/json'}, \n body: JSON.stringify({\n \"linenumber\": linenumber,\n \"filename\": filename__\n })\n }).then(res => {\n console.log(\"Goto line\", linenumber);\n });\n}\n\nconst events = new EventSource('/gotoLine');\nevents.onmessage = (event) => {\n try {\n const data = JSON.parse(event.data);\n if (data.filename == filename__) {\n console.log(\"goto line:\", data.linenumber);\n window.LIA.gotoLine(data.linenumber)\n }\n } catch (e) {\n console.warn(\"gotoLine failed\")\n }\n};\n</script>`\n\nvar serverPointer: any\n\ninit(__dirname)\n\nexport function init(serverPath?: string, nodeModulesPath?: string) {\n dirname = serverPath || path.join(__dirname, '..')\n\n node_modules = nodeModulesPath || path.join(dirname, 'node_modules')\n\n reloadPath = path.resolve(\n path.join(node_modules, 'reloadsh.js/reloader.browser.js')\n )\n\n liascriptPath = path.resolve(\n path.join(node_modules, '@liascript/editor/dist')\n )\n}\n\nexport function start(\n port?: number,\n hostname?: string,\n input?: string,\n responsiveVoice?: string,\n liveReload?: boolean,\n openInBrowser?: boolean,\n testOnline?: boolean,\n gotoCallback?: (linenumber: number, filename: string) => void\n) {\n port = port || 3000\n hostname = hostname || 'localhost'\n openInBrowser = openInBrowser || false\n input = input || '.'\n liveReload = liveReload || false\n testOnline = testOnline || false\n\n var project: {\n path: string\n readme?: string\n } = {\n path: input,\n readme: undefined,\n }\n\n if (input) {\n const stats = fs.lstatSync(input)\n\n // Is it a directory?\n if (stats.isDirectory()) {\n project.path = input\n } else if (stats.isFile()) {\n project.path = path.dirname(input)\n project.readme = path.basename(input)\n }\n }\n\n app.set('view engine', 'hbs')\n app.engine(\n 'hbs',\n handlebars({\n layoutsDir: path.resolve(path.join(dirname, 'views/layouts')),\n defaultLayout: 'main',\n extname: 'hbs',\n })\n )\n app.set('views', path.resolve(path.join(dirname, 'views')))\n\n app.get('/', function (req: express.Request, res: express.Response) {\n res.redirect('/home')\n })\n\n app.get('/gotoLine', eventsHandler)\n\n app.get('/home*', function (req: express.Request, res: express.Response) {\n const currentPath = project.path + '/' + req.params[0]\n\n const stats = fs.lstatSync(currentPath)\n\n // Is it a directory?\n if (stats.isDirectory()) {\n const files = fs.readdirSync(currentPath).filter((e: string) => {\n return e[0] !== '.'\n })\n\n let basePath = '/home'\n let pathNames = req.params[0].split('/').filter((e: string) => {\n return e !== ''\n })\n\n let paths: { name: string; href: string }[] = []\n for (let i = 0; i < pathNames.length; i++) {\n basePath += '/' + pathNames[i]\n paths.push({ name: pathNames[i], href: basePath })\n }\n\n res.render('main', {\n layout: 'index',\n path: paths,\n file: files\n .map((file: string) => {\n return {\n name: file,\n href: `http://${hostname}:${port}/home${req.params[0]}/${file}`,\n isDirectory: fs.lstatSync(currentPath + '/' + file).isDirectory(),\n }\n })\n .sort(\n (\n a: {\n name: string\n href: string\n isDirectory: boolean\n },\n b: {\n name: string\n href: string\n isDirectory: boolean\n }\n ) => {\n if (a.isDirectory && !b.isDirectory) {\n return -1\n } else if (!a.isDirectory && b.isDirectory) {\n return 1\n } else {\n if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {\n return -1\n } else {\n return 1\n }\n }\n return 0\n }\n ),\n })\n } else if (stats.isFile()) {\n if (req.params[0].toLocaleLowerCase().endsWith('.md')) {\n if (testOnline) {\n res.redirect(\n `https://LiaScript.github.io/course/?http://${hostname}:${port}/${req.params[0]}`\n )\n } else {\n res.redirect(\n `/liascript/index.html?http://${hostname}:${port}/${req.params[0]}`\n )\n }\n } else {\n res.sendFile(req.params[0], { root: project.path })\n }\n } else {\n res.send('ups, something went wrong')\n }\n })\n\n app.get(\n '/liascript/',\n function (req: express.Request, res: express.Response) {\n res.redirect('/liascript/index.html')\n }\n )\n\n app.get(\n '/liascript/index.html',\n function (req: express.Request, res: express.Response) {\n // ------------------------------------\n if (liveReload && responsiveVoice) {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='/reloader/reloader.js'></script>\n <script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${gotoScript}\n </head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else if (liveReload) {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='/reloader/reloader.js'></script>\n ${gotoScript}\n </head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else if (responsiveVoice) {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${gotoScript}\n </head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(data.replace('</head>', `${gotoScript}</head>`))\n }\n )\n }\n }\n )\n\n // load everything from the liascript folder\n app.get(\n '/liascript/*',\n function (req: express.Request, res: express.Response) {\n res.sendFile(req.params[0], { root: liascriptPath })\n }\n )\n // ignore this one\n app.get('/sw.js', function (req: express.Request, res: express.Response) {})\n app.get(\n '/favicon.ico',\n function (req: express.Request, res: express.Response) {}\n )\n\n // pass the reloader, to be used for live updates\n app.get(\n '/reloader/reloader.js',\n function (req: express.Request, res: express.Response) {\n res.sendFile(reloadPath)\n }\n )\n\n // react to click-events\n app.post('/lineGoto', function (req: express.Request, res: express.Response) {\n if (gotoCallback) {\n try {\n const linenumber = req.body.linenumber\n const filename = req.body.filename\n gotoCallback(linenumber, filename)\n } catch (e) {\n console.warn(\n \"lineGoto event with wrong datatype, you have to provide {'linenumber': int, 'filename': string}\"\n )\n }\n }\n return res.json({})\n })\n\n // everything else comes from the current project folder\n app.get('/*', cors(), function (req: express.Request, res: express.Response) {\n res.sendFile(req.originalUrl, { root: project.path })\n })\n\n let localURL = 'http://' + hostname + ':' + port\n\n if (project.path && project.readme) {\n localURL +=\n '/liascript/index.html?http://' +\n hostname +\n ':' +\n port +\n '/' +\n project.readme\n }\n\n if (testOnline && project.readme) {\n localURL =\n 'https://LiaScript.github.io/course/?http://' +\n hostname +\n ':' +\n port +\n '/' +\n project.readme\n }\n\n const server = require('reloadsh.js')(\n app,\n liveReload ? [path.join(project.path, project.readme || '')] : []\n )\n\n if (liveReload) {\n console.log(\n `✨ watching for changes on: \"${path.join(\n project.path || '',\n project.readme || ''\n )}\"`\n )\n }\n\n server.on('error', (e: any) => {\n throw e\n })\n\n server.listen(port)\n\n if (openInBrowser) {\n open(localURL)\n }\n\n console.log('📡 starting server')\n console.log(` - local: ${localURL}`)\n console.log(\n ` - on your network: ${localURL.replace(hostname, ip.address())}`\n )\n\n serverPointer = server\n}\n\nexport function stop() {\n if (serverPointer) {\n serverPointer.close()\n }\n}\n\nexport function gotoLine(linenumber: number, filename: string) {\n clients.forEach((client) =>\n client.response.write(\n `data: ${JSON.stringify({\n linenumber: linenumber,\n filename: filename,\n })}\\n\\n`\n )\n )\n}\n\nfunction eventsHandler(\n request: express.Request,\n response: express.Response,\n next: any\n) {\n const headers = {\n 'Content-Type': 'text/event-stream',\n Connection: 'keep-alive',\n 'Cache-Control': 'no-cache',\n }\n response.writeHead(200, headers)\n\n const data = `data: \\n\\n`\n\n response.write(data)\n\n const clientId = Date.now()\n\n const newClient = {\n id: clientId,\n response,\n }\n\n clients.push(newClient)\n\n request.on('close', () => {\n console.log(`${clientId} Connection closed`)\n clients = clients.filter((client) => client.id !== clientId)\n })\n}\n"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
|
|
1
|
+
{"mappings":"A,IEgBI,E,E,Q,Y,E,Q,Q,E,Q,U,E,Q,W,E,Q,M,E,Q,Q,E,Q,sB,E,Q,M,E,Q,Q,E,Q,e,E,Q,e,E,E,O,C,U,UAhBJ,EAAA,MAAA,GAYA,MAAM,E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AAG,EAAE,EAG/D,GACF,QAAQ,GAAA,CACN,CAAC,4BAA4B,EAAE,EAAA,IAAA,CAC7B,EAAQ,IAAA,EAAQ,GAChB,EAAQ,MAAA,EAAU,IAClB,CAAC,CAAC,EAIR,EAAO,EAAA,CAAG,QAAS,AAAC,IAClB,MAAM,CACR,GAEA,EAAO,MAAA,CAAO,GAEV,GACF,EAAK,GAGP,QAAQ,GAAA,CAAI,gCACZ,QAAQ,GAAA,CAAI,CAAC,sBAAsB,EAAE,EAAS,CAAC,EAC/C,QAAQ,GAAA,CACN,CAAC,sBAAsB,EAAE,EAAS,OAAA,CAAQ,EAAU,EAAA,OAAA,IAAc,CAAC,CAIvE,ED3UI,EAAK,CAAA,EAAK,EAAK,IAAA,CACf,EAAK,CAAA,EAAK,EAAK,QAAA,CACf,EAAK,CAAA,EAAK,EAAK,KAAA,CACf,EAAK,CAAA,EAAK,EAAK,eAAA,EAAmB,QAAQ,GAAA,CAAI,oBAAA,CAC9C,EAAK,CAAA,EAAK,EAAK,IAAA,CACf,EAAK,CAAA,EAAK,EAAK,IAAA,CACf,EAAK,CAAA,EAAK,EAAK,IAPjB,CASF,CAAE,MAAO,EAAG,CACV,QAAQ,KAAA,CAAM,UAAW,EAAE,OAA3B,EACA,QAAQ,IAAR,EACF,CAEA,QAAQ,GAAA,CAAI,mC,kC","sources":["<anon>","src/index.ts","src/lib.ts"],"sourcesContent":["var $aRKkE$minimist = require(\"minimist\");\nvar $aRKkE$path = require(\"path\");\nvar $aRKkE$dotenv = require(\"dotenv\");\nvar $aRKkE$express = require(\"express\");\nvar $aRKkE$fs = require(\"fs\");\nvar $aRKkE$cors = require(\"cors\");\nvar $aRKkE$expresshandlebars = require(\"express-handlebars\");\nvar $aRKkE$ip = require(\"ip\");\nvar $aRKkE$open = require(\"open\");\nvar $aRKkE$bodyparser = require(\"body-parser\");\nvar $aRKkE$reloadshjs = require(\"reloadsh.js\");\n\n\n\n\n\nvar $f14dee9e17222834$var$$parcel$__dirname = $aRKkE$path.resolve(__dirname, \"../src\");\n\n$aRKkE$dotenv.config();\n\n\n\n\n\nconst $f14dee9e17222834$var$app = $aRKkE$express();\n$f14dee9e17222834$var$app.use($aRKkE$bodyparser.json());\nvar $f14dee9e17222834$var$dirname = \"\";\nvar $f14dee9e17222834$var$node_modules;\nvar $f14dee9e17222834$var$reloadPath = \"\";\nvar $f14dee9e17222834$var$liascriptPath = \"\";\nvar $f14dee9e17222834$var$clients = [];\nconst $f14dee9e17222834$var$gotoScript = `<script>\nif (!window.LIA) {\n window.LIA = {}\n}\n\nvar filename__ = document.location.search.replace(\"?\"+document.location.origin, \"\")\n\nwindow.LIA.lineGoto = function(linenumber) {\n fetch(\"/lineGoto\", {\n method: \"POST\",\n headers: {'Content-Type': 'application/json'}, \n body: JSON.stringify({\n \"linenumber\": linenumber,\n \"filename\": filename__\n })\n }).then(res => {\n console.log(\"Goto line\", linenumber);\n });\n}\n\nconst events = new EventSource('/gotoLine');\nevents.onmessage = (event) => {\n try {\n const data = JSON.parse(event.data);\n if (data.filename == filename__) {\n console.log(\"goto line:\", data.linenumber);\n window.LIA.gotoLine(data.linenumber)\n }\n } catch (e) {\n console.warn(\"gotoLine failed\")\n }\n};\n</script>`;\nvar $f14dee9e17222834$var$serverPointer;\n$f14dee9e17222834$export$2cd8252107eb640b($f14dee9e17222834$var$$parcel$__dirname);\nfunction $f14dee9e17222834$export$2cd8252107eb640b(serverPath, nodeModulesPath) {\n $f14dee9e17222834$var$dirname = serverPath || $aRKkE$path.join($f14dee9e17222834$var$$parcel$__dirname, \"..\");\n $f14dee9e17222834$var$node_modules = nodeModulesPath || $aRKkE$path.join($f14dee9e17222834$var$dirname, \"node_modules\");\n $f14dee9e17222834$var$reloadPath = $aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$node_modules, \"reloadsh.js/reloader.browser.js\"));\n $f14dee9e17222834$var$liascriptPath = $aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$node_modules, \"@liascript/editor/dist\"));\n}\n\nfunction $f14dee9e17222834$export$b3571188c770cc5a(port, hostname, input, responsiveVoice, liveReload, openInBrowser, testOnline, gotoCallback) {\n port = port || 3000;\n hostname = hostname || \"localhost\";\n openInBrowser = openInBrowser || false;\n input = input || \".\";\n liveReload = liveReload || false;\n testOnline = testOnline || false;\n var project = {\n path: input,\n readme: undefined\n };\n if (input) {\n const stats = $aRKkE$fs.lstatSync(input);\n // Is it a directory?\n if (stats.isDirectory()) project.path = input;\n else if (stats.isFile()) {\n project.path = $aRKkE$path.dirname(input);\n project.readme = $aRKkE$path.basename(input);\n }\n }\n $f14dee9e17222834$var$app.set(\"view engine\", \"hbs\");\n $f14dee9e17222834$var$app.engine(\"hbs\", $aRKkE$expresshandlebars({\n layoutsDir: $aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$dirname, \"views/layouts\")),\n defaultLayout: \"main\",\n extname: \"hbs\"\n }));\n $f14dee9e17222834$var$app.set(\"views\", $aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$dirname, \"views\")));\n $f14dee9e17222834$var$app.get(\"/\", function(req, res) {\n res.redirect(\"/home\");\n });\n $f14dee9e17222834$var$app.get(\"/gotoLine\", $f14dee9e17222834$var$eventsHandler);\n $f14dee9e17222834$var$app.get(\"/home*\", function(req, res) {\n const currentPath = project.path + \"/\" + req.params[0];\n const stats = $aRKkE$fs.lstatSync(currentPath);\n // Is it a directory?\n if (stats.isDirectory()) {\n const files = $aRKkE$fs.readdirSync(currentPath).filter((e)=>{\n return e[0] !== \".\";\n });\n let basePath = \"/home\";\n let pathNames = req.params[0].split(\"/\").filter((e)=>{\n return e !== \"\";\n });\n let paths = [];\n for(let i = 0; i < pathNames.length; i++){\n basePath += \"/\" + pathNames[i];\n paths.push({\n name: pathNames[i],\n href: basePath\n });\n }\n res.render(\"main\", {\n layout: \"index\",\n path: paths,\n file: files.map((file)=>{\n return {\n name: file,\n href: `http://${hostname}:${port}/home${req.params[0]}/${file}`,\n isDirectory: $aRKkE$fs.lstatSync(currentPath + \"/\" + file).isDirectory()\n };\n }).sort((a, b)=>{\n if (a.isDirectory && !b.isDirectory) return -1;\n else if (!a.isDirectory && b.isDirectory) return 1;\n else {\n if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) return -1;\n else return 1;\n }\n return 0;\n })\n });\n } else if (stats.isFile()) {\n if (req.params[0].toLocaleLowerCase().endsWith(\".md\")) {\n if (testOnline) res.redirect(`https://LiaScript.github.io/course/?http://${hostname}:${port}/${req.params[0]}`);\n else res.redirect(`/liascript/index.html?http://${hostname}:${port}/${req.params[0]}`);\n } else res.sendFile(req.params[0], {\n root: project.path\n });\n } else res.send(\"ups, something went wrong\");\n });\n $f14dee9e17222834$var$app.get(\"/liascript/\", function(req, res) {\n res.redirect(\"/liascript/index.html\");\n });\n $f14dee9e17222834$var$app.get(\"/liascript/index.html\", function(req, res) {\n // ------------------------------------\n if (liveReload && responsiveVoice) $aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath + \"/index.html\", \"utf8\", function(err, data) {\n res.send(data.replace(\"</head>\", `<script type='text/javascript' src='/reloader/reloader.js'></script>\n <script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${$f14dee9e17222834$var$gotoScript}\n </head>`));\n });\n else if (liveReload) $aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath + \"/index.html\", \"utf8\", function(err, data) {\n res.send(data.replace(\"</head>\", `<script type='text/javascript' src='/reloader/reloader.js'></script>\n ${$f14dee9e17222834$var$gotoScript}\n </head>`));\n });\n else if (responsiveVoice) $aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath + \"/index.html\", \"utf8\", function(err, data) {\n res.send(data.replace(\"</head>\", `<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${$f14dee9e17222834$var$gotoScript}\n </head>`));\n });\n else $aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath + \"/index.html\", \"utf8\", function(err, data) {\n res.send(data.replace(\"</head>\", `${$f14dee9e17222834$var$gotoScript}</head>`));\n });\n });\n // load everything from the liascript folder\n $f14dee9e17222834$var$app.get(\"/liascript/*\", function(req, res) {\n res.sendFile(req.params[0], {\n root: $f14dee9e17222834$var$liascriptPath\n });\n });\n // ignore this one\n $f14dee9e17222834$var$app.get(\"/sw.js\", function(req, res) {});\n $f14dee9e17222834$var$app.get(\"/favicon.ico\", function(req, res) {});\n // pass the reloader, to be used for live updates\n $f14dee9e17222834$var$app.get(\"/reloader/reloader.js\", function(req, res) {\n res.sendFile($f14dee9e17222834$var$reloadPath);\n });\n // react to click-events\n $f14dee9e17222834$var$app.post(\"/lineGoto\", function(req, res) {\n if (gotoCallback) try {\n const linenumber = req.body.linenumber;\n const filename = req.body.filename;\n gotoCallback(linenumber, filename);\n } catch (e) {\n console.warn(\"lineGoto event with wrong datatype, you have to provide {'linenumber': int, 'filename': string}\");\n }\n return res.json({});\n });\n // everything else comes from the current project folder\n $f14dee9e17222834$var$app.get(\"/*\", $aRKkE$cors(), function(req, res) {\n res.sendFile(req.originalUrl, {\n root: project.path\n });\n });\n let localURL = \"http://\" + hostname + \":\" + port;\n if (project.path && project.readme) localURL += \"/liascript/index.html?http://\" + hostname + \":\" + port + \"/\" + project.readme;\n if (testOnline && project.readme) localURL = \"https://LiaScript.github.io/course/?http://\" + hostname + \":\" + port + \"/\" + project.readme;\n const server = $aRKkE$reloadshjs($f14dee9e17222834$var$app, liveReload ? [\n $aRKkE$path.join(project.path, project.readme || \"\")\n ] : []);\n if (liveReload) console.log(`✨ watching for changes on: \"${$aRKkE$path.join(project.path || \"\", project.readme || \"\")}\"`);\n server.on(\"error\", (e)=>{\n throw e;\n });\n server.listen(port);\n if (openInBrowser) $aRKkE$open(localURL);\n console.log(\"\\uD83D\\uDCE1 starting server\");\n console.log(` - local: ${localURL}`);\n console.log(` - on your network: ${localURL.replace(hostname, $aRKkE$ip.address())}`);\n $f14dee9e17222834$var$serverPointer = server;\n}\nfunction $f14dee9e17222834$export$fa6813432f753b0d() {\n if ($f14dee9e17222834$var$serverPointer) $f14dee9e17222834$var$serverPointer.close();\n}\nfunction $f14dee9e17222834$export$5d5b784f9a618ec3(linenumber, filename) {\n $f14dee9e17222834$var$clients.forEach((client)=>client.response.write(`data: ${JSON.stringify({\n linenumber: linenumber,\n filename: filename\n })}\\n\\n`));\n}\nfunction $f14dee9e17222834$var$eventsHandler(request, response, next) {\n const headers = {\n \"Content-Type\": \"text/event-stream\",\n Connection: \"keep-alive\",\n \"Cache-Control\": \"no-cache\"\n };\n response.writeHead(200, headers);\n const data = `data: \\n\\n`;\n response.write(data);\n const clientId = Date.now();\n const newClient = {\n id: clientId,\n response: response\n };\n $f14dee9e17222834$var$clients.push(newClient);\n request.on(\"close\", ()=>{\n console.log(`${clientId} Connection closed`);\n $f14dee9e17222834$var$clients = $f14dee9e17222834$var$clients.filter((client)=>client.id !== clientId);\n });\n}\n\n\n\nconst $71fcc9ea54afc905$var$argv = $aRKkE$minimist(process.argv.slice(2));\nfunction $71fcc9ea54afc905$var$liascript() {\n console.log(\" _ _ ____ _ _\");\n console.log(\"| | (_) __ _/ ___| ___ _ __(_)_ __ | |_\");\n console.log(\"| | | |/ _` \\\\___ \\\\ / __| '__| | '_ \\\\| __|\");\n console.log(\"| |___| | (_| |___) | (__| | | | |_) | |_ \");\n console.log(\"|_____|_|\\\\__,_|____/ \\\\___|_| |_| .__/ \\\\__|\");\n console.log(\" |_|\");\n console.log();\n}\nif ($71fcc9ea54afc905$var$argv.v || $71fcc9ea54afc905$var$argv.version) {\n console.log(\"DevServer: 1.1.2\");\n console.log(\"LiaScript: 0.12.6\");\n process.exit();\n}\nif ($71fcc9ea54afc905$var$argv.h || $71fcc9ea54afc905$var$argv.help) {\n $71fcc9ea54afc905$var$liascript();\n console.log(\"-h --help show this help\");\n console.log(\"-v --version show version information\");\n console.log(\"-i --input input README.md file or folder (default: .)\");\n console.log(\"-n --hostname hostname of your server (default: localhost)\");\n console.log(\"-p --port used port number (default: 3000)\");\n console.log(\"-l --live do live reload on file change\");\n console.log(\"-o --open open in default browser\");\n console.log(\"-t --test test online on https://LiaScript.github.io\");\n console.log();\n console.log(\"-r --responsiveVoice add optional responsiveVoice support,\");\n console.log(\" or pass your own responsiveVoice key.\");\n console.log(\" Adding this feature might slow down\");\n console.log(\" the reloading speed.\");\n console.log(\" For more information visit:\");\n console.log(\" https://responsivevoice.org\");\n process.exit();\n}\n$71fcc9ea54afc905$var$liascript();\n$f14dee9e17222834$export$2cd8252107eb640b($71fcc9ea54afc905$var$argv.node_modules);\ntry {\n $f14dee9e17222834$export$b3571188c770cc5a($71fcc9ea54afc905$var$argv.p || $71fcc9ea54afc905$var$argv.port, $71fcc9ea54afc905$var$argv.n || $71fcc9ea54afc905$var$argv.hostname, $71fcc9ea54afc905$var$argv.i || $71fcc9ea54afc905$var$argv.input, $71fcc9ea54afc905$var$argv.r || $71fcc9ea54afc905$var$argv.responsiveVoice || process.env.RESPONSIVE_VOICE_KEY, $71fcc9ea54afc905$var$argv.l || $71fcc9ea54afc905$var$argv.live, $71fcc9ea54afc905$var$argv.o || $71fcc9ea54afc905$var$argv.open, $71fcc9ea54afc905$var$argv.t || $71fcc9ea54afc905$var$argv.test);\n} catch (e) {\n console.error(\"Error: \", e.message);\n process.exit();\n}\nconsole.log(\"✨ hit Ctrl-c to close the server\");\n\n\n//# sourceMappingURL=index.js.map\n","const argv = require('minimist')(process.argv.slice(2))\n\nimport * as server from './lib'\n\nfunction liascript() {\n console.log(' _ _ ____ _ _')\n console.log('| | (_) __ _/ ___| ___ _ __(_)_ __ | |_')\n console.log(\"| | | |/ _` \\\\___ \\\\ / __| '__| | '_ \\\\| __|\")\n console.log('| |___| | (_| |___) | (__| | | | |_) | |_ ')\n console.log('|_____|_|\\\\__,_|____/ \\\\___|_| |_| .__/ \\\\__|')\n console.log(' |_|')\n console.log()\n}\n\nif (argv.v || argv.version) {\n console.log('DevServer: 1.1.2')\n console.log('LiaScript: 0.12.6')\n process.exit()\n}\n\nif (argv.h || argv.help) {\n liascript()\n\n console.log('-h --help show this help')\n console.log('-v --version show version information')\n console.log('-i --input input README.md file or folder (default: .)')\n console.log('-n --hostname hostname of your server (default: localhost)')\n console.log('-p --port used port number (default: 3000)')\n console.log('-l --live do live reload on file change')\n console.log('-o --open open in default browser')\n console.log('-t --test test online on https://LiaScript.github.io')\n console.log()\n console.log('-r --responsiveVoice add optional responsiveVoice support,')\n console.log(' or pass your own responsiveVoice key.')\n console.log(' Adding this feature might slow down')\n console.log(' the reloading speed.')\n console.log(' For more information visit:')\n console.log(' https://responsivevoice.org')\n\n process.exit()\n}\n\nliascript()\n\nserver.init(argv.node_modules)\n\ntry {\n server.start(\n argv.p || argv.port,\n argv.n || argv.hostname,\n argv.i || argv.input,\n argv.r || argv.responsiveVoice || process.env.RESPONSIVE_VOICE_KEY,\n argv.l || argv.live,\n argv.o || argv.open,\n argv.t || argv.test\n )\n} catch (e) {\n console.error('Error: ', e.message)\n process.exit()\n}\n\nconsole.log('✨ hit Ctrl-c to close the server')\n","require('dotenv').config()\nimport * as express from 'express'\n\nimport * as fs from 'fs'\nimport * as path from 'path'\n\nconst cors = require('cors')\nconst handlebars = require('express-handlebars')\nconst ip = require('ip')\nconst open = require('open')\nconst bodyParser = require('body-parser')\n\nconst app: express.Application = express()\napp.use(bodyParser.json())\n\nvar dirname = ''\nvar node_modules\nvar reloadPath = ''\nvar liascriptPath = ''\n\nvar clients = []\n\nconst gotoScript = `<script>\nif (!window.LIA) {\n window.LIA = {}\n}\n\nvar filename__ = document.location.search.replace(\"?\"+document.location.origin, \"\")\n\nwindow.LIA.lineGoto = function(linenumber) {\n fetch(\"/lineGoto\", {\n method: \"POST\",\n headers: {'Content-Type': 'application/json'}, \n body: JSON.stringify({\n \"linenumber\": linenumber,\n \"filename\": filename__\n })\n }).then(res => {\n console.log(\"Goto line\", linenumber);\n });\n}\n\nconst events = new EventSource('/gotoLine');\nevents.onmessage = (event) => {\n try {\n const data = JSON.parse(event.data);\n if (data.filename == filename__) {\n console.log(\"goto line:\", data.linenumber);\n window.LIA.gotoLine(data.linenumber)\n }\n } catch (e) {\n console.warn(\"gotoLine failed\")\n }\n};\n</script>`\n\nvar serverPointer: any\n\ninit(__dirname)\n\nexport function init(serverPath?: string, nodeModulesPath?: string) {\n dirname = serverPath || path.join(__dirname, '..')\n\n node_modules = nodeModulesPath || path.join(dirname, 'node_modules')\n\n reloadPath = path.resolve(\n path.join(node_modules, 'reloadsh.js/reloader.browser.js')\n )\n\n liascriptPath = path.resolve(\n path.join(node_modules, '@liascript/editor/dist')\n )\n}\n\nexport function start(\n port?: number,\n hostname?: string,\n input?: string,\n responsiveVoice?: string,\n liveReload?: boolean,\n openInBrowser?: boolean,\n testOnline?: boolean,\n gotoCallback?: (linenumber: number, filename: string) => void\n) {\n port = port || 3000\n hostname = hostname || 'localhost'\n openInBrowser = openInBrowser || false\n input = input || '.'\n liveReload = liveReload || false\n testOnline = testOnline || false\n\n var project: {\n path: string\n readme?: string\n } = {\n path: input,\n readme: undefined,\n }\n\n if (input) {\n const stats = fs.lstatSync(input)\n\n // Is it a directory?\n if (stats.isDirectory()) {\n project.path = input\n } else if (stats.isFile()) {\n project.path = path.dirname(input)\n project.readme = path.basename(input)\n }\n }\n\n app.set('view engine', 'hbs')\n app.engine(\n 'hbs',\n handlebars({\n layoutsDir: path.resolve(path.join(dirname, 'views/layouts')),\n defaultLayout: 'main',\n extname: 'hbs',\n })\n )\n app.set('views', path.resolve(path.join(dirname, 'views')))\n\n app.get('/', function (req: express.Request, res: express.Response) {\n res.redirect('/home')\n })\n\n app.get('/gotoLine', eventsHandler)\n\n app.get('/home*', function (req: express.Request, res: express.Response) {\n const currentPath = project.path + '/' + req.params[0]\n\n const stats = fs.lstatSync(currentPath)\n\n // Is it a directory?\n if (stats.isDirectory()) {\n const files = fs.readdirSync(currentPath).filter((e: string) => {\n return e[0] !== '.'\n })\n\n let basePath = '/home'\n let pathNames = req.params[0].split('/').filter((e: string) => {\n return e !== ''\n })\n\n let paths: { name: string; href: string }[] = []\n for (let i = 0; i < pathNames.length; i++) {\n basePath += '/' + pathNames[i]\n paths.push({ name: pathNames[i], href: basePath })\n }\n\n res.render('main', {\n layout: 'index',\n path: paths,\n file: files\n .map((file: string) => {\n return {\n name: file,\n href: `http://${hostname}:${port}/home${req.params[0]}/${file}`,\n isDirectory: fs.lstatSync(currentPath + '/' + file).isDirectory(),\n }\n })\n .sort(\n (\n a: {\n name: string\n href: string\n isDirectory: boolean\n },\n b: {\n name: string\n href: string\n isDirectory: boolean\n }\n ) => {\n if (a.isDirectory && !b.isDirectory) {\n return -1\n } else if (!a.isDirectory && b.isDirectory) {\n return 1\n } else {\n if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {\n return -1\n } else {\n return 1\n }\n }\n return 0\n }\n ),\n })\n } else if (stats.isFile()) {\n if (req.params[0].toLocaleLowerCase().endsWith('.md')) {\n if (testOnline) {\n res.redirect(\n `https://LiaScript.github.io/course/?http://${hostname}:${port}/${req.params[0]}`\n )\n } else {\n res.redirect(\n `/liascript/index.html?http://${hostname}:${port}/${req.params[0]}`\n )\n }\n } else {\n res.sendFile(req.params[0], { root: project.path })\n }\n } else {\n res.send('ups, something went wrong')\n }\n })\n\n app.get(\n '/liascript/',\n function (req: express.Request, res: express.Response) {\n res.redirect('/liascript/index.html')\n }\n )\n\n app.get(\n '/liascript/index.html',\n function (req: express.Request, res: express.Response) {\n // ------------------------------------\n if (liveReload && responsiveVoice) {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='/reloader/reloader.js'></script>\n <script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${gotoScript}\n </head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else if (liveReload) {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='/reloader/reloader.js'></script>\n ${gotoScript}\n </head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else if (responsiveVoice) {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${gotoScript}\n </head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(data.replace('</head>', `${gotoScript}</head>`))\n }\n )\n }\n }\n )\n\n // load everything from the liascript folder\n app.get(\n '/liascript/*',\n function (req: express.Request, res: express.Response) {\n res.sendFile(req.params[0], { root: liascriptPath })\n }\n )\n // ignore this one\n app.get('/sw.js', function (req: express.Request, res: express.Response) {})\n app.get(\n '/favicon.ico',\n function (req: express.Request, res: express.Response) {}\n )\n\n // pass the reloader, to be used for live updates\n app.get(\n '/reloader/reloader.js',\n function (req: express.Request, res: express.Response) {\n res.sendFile(reloadPath)\n }\n )\n\n // react to click-events\n app.post('/lineGoto', function (req: express.Request, res: express.Response) {\n if (gotoCallback) {\n try {\n const linenumber = req.body.linenumber\n const filename = req.body.filename\n gotoCallback(linenumber, filename)\n } catch (e) {\n console.warn(\n \"lineGoto event with wrong datatype, you have to provide {'linenumber': int, 'filename': string}\"\n )\n }\n }\n return res.json({})\n })\n\n // everything else comes from the current project folder\n app.get('/*', cors(), function (req: express.Request, res: express.Response) {\n res.sendFile(req.originalUrl, { root: project.path })\n })\n\n let localURL = 'http://' + hostname + ':' + port\n\n if (project.path && project.readme) {\n localURL +=\n '/liascript/index.html?http://' +\n hostname +\n ':' +\n port +\n '/' +\n project.readme\n }\n\n if (testOnline && project.readme) {\n localURL =\n 'https://LiaScript.github.io/course/?http://' +\n hostname +\n ':' +\n port +\n '/' +\n project.readme\n }\n\n const server = require('reloadsh.js')(\n app,\n liveReload ? [path.join(project.path, project.readme || '')] : []\n )\n\n if (liveReload) {\n console.log(\n `✨ watching for changes on: \"${path.join(\n project.path || '',\n project.readme || ''\n )}\"`\n )\n }\n\n server.on('error', (e: any) => {\n throw e\n })\n\n server.listen(port)\n\n if (openInBrowser) {\n open(localURL)\n }\n\n console.log('📡 starting server')\n console.log(` - local: ${localURL}`)\n console.log(\n ` - on your network: ${localURL.replace(hostname, ip.address())}`\n )\n\n serverPointer = server\n}\n\nexport function stop() {\n if (serverPointer) {\n serverPointer.close()\n }\n}\n\nexport function gotoLine(linenumber: number, filename: string) {\n clients.forEach((client) =>\n client.response.write(\n `data: ${JSON.stringify({\n linenumber: linenumber,\n filename: filename,\n })}\\n\\n`\n )\n )\n}\n\nfunction eventsHandler(\n request: express.Request,\n response: express.Response,\n next: any\n) {\n const headers = {\n 'Content-Type': 'text/event-stream',\n Connection: 'keep-alive',\n 'Cache-Control': 'no-cache',\n }\n response.writeHead(200, headers)\n\n const data = `data: \\n\\n`\n\n response.write(data)\n\n const clientId = Date.now()\n\n const newClient = {\n id: clientId,\n response,\n }\n\n clients.push(newClient)\n\n request.on('close', () => {\n console.log(`${clientId} Connection closed`)\n clients = clients.filter((client) => client.id !== clientId)\n })\n}\n"],"names":["$f14dee9e17222834$var$node_modules","$aRKkE$minimist","require","$aRKkE$path","$aRKkE$dotenv","$aRKkE$express","$aRKkE$fs","$aRKkE$cors","$aRKkE$expresshandlebars","$aRKkE$ip","$aRKkE$open","$aRKkE$bodyparser","$aRKkE$reloadshjs","$f14dee9e17222834$var$$parcel$__dirname","resolve","__dirname","config","$f14dee9e17222834$var$app","use","json","$f14dee9e17222834$var$dirname","$f14dee9e17222834$var$reloadPath","$f14dee9e17222834$var$liascriptPath","$f14dee9e17222834$var$clients","$f14dee9e17222834$var$gotoScript","$f14dee9e17222834$export$2cd8252107eb640b","serverPath","nodeModulesPath","join","$f14dee9e17222834$var$eventsHandler","request","response","next","writeHead","Connection","data","write","clientId","Date","now","push","id","on","console","log","filter","client","$71fcc9ea54afc905$var$argv","process","argv","slice","$71fcc9ea54afc905$var$liascript","v","version","exit","h","help","node_modules","$f14dee9e17222834$export$b3571188c770cc5a","port","hostname","input","responsiveVoice","liveReload","openInBrowser","testOnline","gotoCallback","project","path","readme","undefined","stats","lstatSync","isDirectory","isFile","dirname","basename","set","engine","layoutsDir","defaultLayout","extname","get","req","res","redirect","currentPath","params","files","readdirSync","e","basePath","pathNames","split","paths","i","length","name","href","render","layout","file","map","sort","a","b","toLocaleLowerCase","endsWith","sendFile","root","send","readFile","err","replace","post","linenumber","body","filename","warn","originalUrl","localURL","server","listen","address","p","n","r","env","RESPONSIVE_VOICE_KEY","l","live","o","open","t","test","error","message"],"version":3,"file":"index.js.map","sourceRoot":"../"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liascript/devserver",
|
|
3
|
-
"version": "1.1.2--0.12.
|
|
3
|
+
"version": "1.1.2--0.12.6",
|
|
4
4
|
"description": "Run a development server for LiaScript locally",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"author": "André Dietrich",
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@liascript/editor": "^1.1.
|
|
35
|
+
"@liascript/editor": "^1.1.2--0.12.6",
|
|
36
36
|
"body-parser": "^1.20.0",
|
|
37
37
|
"cors": "^2.8.5",
|
|
38
38
|
"dotenv": "^5.0.1",
|
|
@@ -45,10 +45,16 @@
|
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
47
|
"@types/express": "^4.17.11",
|
|
48
|
-
"parcel": "^2.
|
|
48
|
+
"parcel": "^2.9.3",
|
|
49
49
|
"typescript": "^4.6.3"
|
|
50
50
|
},
|
|
51
51
|
"engines": {
|
|
52
|
-
"node": "
|
|
52
|
+
"node": ">= 12"
|
|
53
|
+
},
|
|
54
|
+
"targets": {
|
|
55
|
+
"main": {
|
|
56
|
+
"context": "node",
|
|
57
|
+
"optimize": true
|
|
58
|
+
}
|
|
53
59
|
}
|
|
54
60
|
}
|