@liascript/devserver 1.1.52--1.0.0 β 1.2.0--1.0.2
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 +2 -2
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/lib.d.ts +1 -1
- package/dist/lib.js +296 -215
- package/package.json +12 -13
- package/views/main.hbs +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
var $f14dee9e17222834$var$node_modules,$f14dee9e17222834$var$serverPointer,$aRKkE$minimist=require("minimist"),$aRKkE$path=require("path"),$aRKkE$
|
|
3
|
+
var $f14dee9e17222834$var$node_modules,$f14dee9e17222834$var$serverPointer,$aRKkE$minimist=require("minimist"),$aRKkE$path=require("path"),$aRKkE$express=require("express"),$aRKkE$fs=require("fs"),$aRKkE$cors=require("cors"),$aRKkE$expresshandlebars=require("express-handlebars"),$aRKkE$ip=require("ip"),$aRKkE$open=require("open"),$aRKkE$bodyparser=require("body-parser"),$aRKkE$reload=require("reload"),$aRKkE$chokidar=require("chokidar"),$f14dee9e17222834$var$$parcel$__dirname=$aRKkE$path.resolve(__dirname,"../src");const $f14dee9e17222834$var$app=$aRKkE$express();$f14dee9e17222834$var$app.use($aRKkE$bodyparser.json());var $f14dee9e17222834$var$dirname="",$f14dee9e17222834$var$liascriptPath="",$f14dee9e17222834$var$reloadInstance=null,$f14dee9e17222834$var$watcher=null,$f14dee9e17222834$var$clients=[];const $f14dee9e17222834$var$gotoScript=`<script>
|
|
4
4
|
if (!window.LIA) {
|
|
5
5
|
window.LIA = {}
|
|
6
6
|
}
|
|
@@ -32,16 +32,16 @@ events.onmessage = (event) => {
|
|
|
32
32
|
console.warn("gotoLine failed")
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
|
-
</script>`;function $f14dee9e17222834$export$2cd8252107eb640b(e,a){$f14dee9e17222834$var$dirname=e||$aRKkE$path.join($f14dee9e17222834$var$$parcel$__dirname,".."),$f14dee9e17222834$var$node_modules=a||$aRKkE$path.join($f14dee9e17222834$var$dirname,"node_modules"),$f14dee9e17222834$var$
|
|
35
|
+
</script>`;function $f14dee9e17222834$export$2cd8252107eb640b(e,a){$f14dee9e17222834$var$dirname=e||$aRKkE$path.join($f14dee9e17222834$var$$parcel$__dirname,".."),$f14dee9e17222834$var$node_modules=a||$aRKkE$path.join($f14dee9e17222834$var$dirname,"node_modules"),$f14dee9e17222834$var$liascriptPath=$aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$node_modules,"@liascript/editor/dist"))}async function $f14dee9e17222834$export$b3571188c770cc5a(e,a,r,o,t,$,n,i){e=e||3e3,a=a||"localhost",$=$||!1,t=t||!1,n=n||!1;var s={path:r=r||".",readme:void 0};if(r){let e=$aRKkE$fs.lstatSync(r);e.isDirectory()?s.path=r:e.isFile()&&(s.path=$aRKkE$path.dirname(r),s.readme=$aRKkE$path.basename(r))}if($f14dee9e17222834$var$app.set("view engine","hbs"),$f14dee9e17222834$var$app.engine("hbs",$aRKkE$expresshandlebars({layoutsDir:$aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$dirname,"views/layouts")),defaultLayout:"main",extname:"hbs"})),$f14dee9e17222834$var$app.set("views",$aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$dirname,"views"))),t){let e=$aRKkE$path.join(s.path,s.readme||"");console.log(`\u{2728} watching for changes on: "${e}"`);try{$f14dee9e17222834$var$reloadInstance=await $aRKkE$reload($f14dee9e17222834$var$app),($f14dee9e17222834$var$watcher=$aRKkE$chokidar.watch(e,{ignoreInitial:!0,awaitWriteFinish:{stabilityThreshold:100,pollInterval:50}})).on("change",e=>{console.log("π file changed, reloading..."),$f14dee9e17222834$var$reloadInstance.reload()}),$f14dee9e17222834$var$watcher.on("error",e=>{console.error("Watcher error:",e)})}catch(e){console.error("Reload could not start:",e)}}$f14dee9e17222834$var$app.get("/",function(e,a){a.redirect("/home")}),$f14dee9e17222834$var$app.get("/gotoLine",$f14dee9e17222834$var$eventsHandler),$f14dee9e17222834$var$app.get("/home*",function(r,o){let t=s.path+"/"+r.params[0],$=$aRKkE$fs.lstatSync(t);if($.isDirectory()){let $=$aRKkE$fs.readdirSync(t).filter(e=>"."!==e[0]),n="/home",i=r.params[0].split("/").filter(e=>""!==e),s=[];for(let e=0;e<i.length;e++)n+="/"+i[e],s.push({name:i[e],href:n});o.render("main",{layout:"index",path:s,file:$.map(o=>({name:o,href:`http://${a}:${e}/home${r.params[0]}/${o}`,isDirectory:$aRKkE$fs.lstatSync(t+"/"+o).isDirectory()})).sort((e,a)=>e.isDirectory&&!a.isDirectory?-1:!e.isDirectory&&a.isDirectory?1:e.name.toLocaleLowerCase()<a.name.toLocaleLowerCase()?-1:1)})}else $.isFile()?r.params[0].toLocaleLowerCase().endsWith(".md")?n?o.redirect(`https://LiaScript.github.io/course/?http://${a}:${e}/${r.params[0]}`):o.redirect(`/liascript/index.html?http://${a}:${e}/${r.params[0]}`):o.sendFile(r.params[0],{root:s.path}):o.send("ups, something went wrong")}),$f14dee9e17222834$var$app.get("/liascript/",function(e,a){a.redirect("/liascript/index.html")}),$f14dee9e17222834$var$app.get("/liascript/index.html",function(e,a){t&&o?$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){e||!r?a.status(500).send("index.html not found or could not be read"):a.send(r.replace("</head>",`<script type='text/javascript' src='/reload/reload.js'></script>
|
|
36
36
|
<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${o}'></script>
|
|
37
37
|
${$f14dee9e17222834$var$gotoScript}
|
|
38
|
-
</head>`))}):t?$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){
|
|
38
|
+
</head>`))}):t?$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){e||!r?a.status(500).send("index.html not found or could not be read"):a.send(r.replace("</head>",`<script type='text/javascript' src='/reload/reload.js'></script>
|
|
39
39
|
${$f14dee9e17222834$var$gotoScript}
|
|
40
|
-
</head>`))}):o?$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){
|
|
40
|
+
</head>`))}):o?$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){e||!r?a.status(500).send("index.html not found or could not be read"):a.send(r.replace("</head>",`<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${o}'></script>
|
|
41
41
|
${$f14dee9e17222834$var$gotoScript}
|
|
42
|
-
</head>`))}):$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){
|
|
42
|
+
</head>`))}):$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){e||!r?a.status(500).send("index.html not found or could not be read"):a.send(r.replace("</head>",`${$f14dee9e17222834$var$gotoScript}</head>`))})}),$f14dee9e17222834$var$app.get("/liascript/*",function(e,a){a.sendFile(e.params[0],{root:$f14dee9e17222834$var$liascriptPath},r=>{if(r){let r=e.params[0];console.log(`File not found in liascriptPath, trying project.path: ${r}`,s.path),a.sendFile(r,{root:s.path})}})}),$f14dee9e17222834$var$app.get("/sw.js",function(e,a){}),$f14dee9e17222834$var$app.get("/favicon.ico",function(e,a){}),$f14dee9e17222834$var$app.post("/lineGoto",function(e,a){if(i)try{let a=e.body.linenumber,r=e.body.filename;i(a,r)}catch(e){console.warn("lineGoto event with wrong datatype, you have to provide {'linenumber': int, 'filename': string}")}return a.json({})}),$f14dee9e17222834$var$app.use("/*",$aRKkE$cors(),function(e,a,r){if(e.originalUrl.startsWith("/reload/")||e.originalUrl.startsWith("/socket.io"))return r();a.sendFile(e.originalUrl,{root:s.path})});let c="http://"+a+":"+e;s.path&&s.readme&&(c+="/liascript/index.html?http://"+a+":"+e+"/"+s.readme),n&&s.readme&&(c="https://LiaScript.github.io/course/?http://"+a+":"+e+"/"+s.readme);let l=$f14dee9e17222834$var$app.listen(e);l.on("error",e=>{throw e}),$&&$aRKkE$open(c),console.log("π‘ starting server"),console.log(` - local: ${c}`),console.log(` - on your network: ${c.replace(a,$aRKkE$ip.address())}`),$f14dee9e17222834$var$serverPointer=l}function $f14dee9e17222834$export$fa6813432f753b0d(){$f14dee9e17222834$var$serverPointer&&$f14dee9e17222834$var$serverPointer.close(),$f14dee9e17222834$var$watcher&&($f14dee9e17222834$var$watcher.close(),$f14dee9e17222834$var$watcher=null),$f14dee9e17222834$var$reloadInstance&&($f14dee9e17222834$var$reloadInstance=null)}function $f14dee9e17222834$export$5d5b784f9a618ec3(e,a){$f14dee9e17222834$var$clients.forEach(r=>r.response.write(`data: ${JSON.stringify({linenumber:e,filename:a})}
|
|
43
43
|
|
|
44
44
|
`))}function $f14dee9e17222834$var$eventsHandler(e,a,r){a.writeHead(200,{"Content-Type":"text/event-stream",Connection:"keep-alive","Cache-Control":"no-cache"});let o=`data:
|
|
45
45
|
|
|
46
|
-
`;a.write(o);let t=Date.now();$f14dee9e17222834$var$clients.push({id:t,response:a}),e.on("close",()=>{
|
|
46
|
+
`;a.write(o);let t=Date.now();$f14dee9e17222834$var$clients.push({id:t,response:a}),e.on("close",()=>{$f14dee9e17222834$var$clients=$f14dee9e17222834$var$clients.filter(e=>e.id!==t)})}$f14dee9e17222834$export$2cd8252107eb640b($f14dee9e17222834$var$$parcel$__dirname);const $71fcc9ea54afc905$var$argv=$aRKkE$minimist(process.argv.slice(2));function $71fcc9ea54afc905$var$liascript(){console.log(" _ _ ____ _ _"),console.log("| | (_) __ _/ ___| ___ _ __(_)_ __ | |_"),console.log("| | | |/ _` \\___ \\ / __| '__| | '_ \\| __|"),console.log("| |___| | (_| |___) | (__| | | | |_) | |_ "),console.log("|_____|_|\\__,_|____/ \\___|_| |_| .__/ \\__|"),console.log(" |_|"),console.log()}($71fcc9ea54afc905$var$argv.v||$71fcc9ea54afc905$var$argv.version)&&(console.log("DevServer: 1.2.0"),console.log("LiaScript: 1.0.2"),process.exit()),($71fcc9ea54afc905$var$argv.h||$71fcc9ea54afc905$var$argv.help)&&($71fcc9ea54afc905$var$liascript(),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()),$71fcc9ea54afc905$var$liascript(),$f14dee9e17222834$export$2cd8252107eb640b($71fcc9ea54afc905$var$argv.node_modules),$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).catch(e=>{console.error("Error: ",e.message),process.exit()}),console.log("β¨ hit Ctrl-c to close the server");
|
|
47
47
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":"A,IEgBI,mCAwCA,oC,gB,Q,Y,Y,Q,Q,c,Q,U,e,Q,W,U,Q,M,Y,Q,Q,yB,Q,sB,U,Q,M,Y,Q,Q,kB,Q,e,kB,Q,e,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QAAQ,IAAI,IAGd,kCAEA,0CAAY,2BAAK,YAAY,EAE7B,GAAI,CACF,0CACE,2BAAK,CAAC,EAAI,2BAAK,IAAI,CACnB,2BAAK,CAAC,EAAI,2BAAK,QAAQ,CACvB,2BAAK,CAAC,EAAI,2BAAK,KAAK,CACpB,2BAAK,CAAC,EAAI,2BAAK,eAAe,EAAI,QAAQ,GAAG,CAAC,oBAAoB,CAClE,2BAAK,CAAC,EAAI,2BAAK,IAAI,CACnB,2BAAK,CAAC,EAAI,2BAAK,IAAI,CACnB,2BAAK,CAAC,EAAI,2BAAK,IAAI,CAEvB,CAAE,MAAO,EAAG,CACV,QAAQ,KAAK,CAAC,UAAW,EAAE,OAAO,EAClC,QAAQ,IAAI,EACd,CAEA,QAAQ,GAAG,CAAC","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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read');\n return;\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read');\n return;\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read');\n return;\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read');\n return;\n }\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 }, (err)=>{\n if (err) {\n // Extract the file path by removing the '/liascript/' prefix\n const projectPath = req.params[0];\n console.log(`File not found in liascriptPath, trying project.path: ${projectPath}`, project.path);\n res.sendFile(projectPath, {\n root: project.path\n });\n }\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(`\\u{2728} 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.52');\n console.log('LiaScript: 1.0.0');\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(\"\\u2728 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.52')\n console.log('LiaScript: 1.0.0')\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: any[] = []\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read')\n return\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read')\n return\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read')\n return\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read')\n return\n }\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 }, (err) => {\n if (err) {\n // Extract the file path by removing the '/liascript/' prefix\n const projectPath = req.params[0]\n console.log(\n `File not found in liascriptPath, trying project.path: ${projectPath}`,\n project.path\n )\n res.sendFile(projectPath, { root: project.path })\n }\n })\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","$f14dee9e17222834$var$serverPointer","$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$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","$f14dee9e17222834$var$eventsHandler","currentPath","params","files","readdirSync","filter","e","basePath","pathNames","split","paths","i","length","push","name","href","render","layout","file","map","sort","a","b","toLocaleLowerCase","endsWith","sendFile","root","send","readFile","err","data","status","replace","projectPath","console","log","post","linenumber","body","filename","warn","originalUrl","localURL","server","on","listen","address","$f14dee9e17222834$export$fa6813432f753b0d","close","$f14dee9e17222834$export$5d5b784f9a618ec3","forEach","client","response","write","JSON","stringify","request","next","writeHead","Connection","clientId","Date","now","id","$71fcc9ea54afc905$var$argv","process","argv","slice","$71fcc9ea54afc905$var$liascript","v","version","exit","h","help","node_modules","p","n","r","env","RESPONSIVE_VOICE_KEY","l","live","o","open","t","test","error","message"],"version":3,"file":"index.js.map","sourceRoot":"../"}
|
|
1
|
+
{"mappings":"A,IEiBI,mCAyCA,oC,gB,Q,Y,Y,Q,Q,e,Q,W,U,Q,M,Y,Q,Q,yB,Q,sB,U,Q,M,Y,Q,Q,kB,Q,e,c,Q,U,gB,Q,Y,wC,Y,O,C,U,UA7CJ,MAAM,0BAA2B,iBACjC,0BAAI,GAAG,CAAC,kBAAR,IAAA,IAEA,IAAI,8BAAU,GAEV,oCAAgB,GAChB,qCAAsB,KACtB,8BAAe,KAEf,8BAAiB,EAAE,CAEvB,MAAM,iCAAa,CAAC;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;A;AAgCX,SAAA,CAAC,CAMH,SAAS,0CAAK,CAAmB,CAAE,CAAwB,EAChE,8BAAU,GAAc,YAAA,IAAA,CAAU,wCAAW,MAE7C,mCAAe,GAAmB,Y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K,CAAC,EAAI,2BAAK,KAAK,CACpB,2BAAK,CAAC,EAAI,2BAAK,eAAe,EAAI,QAAQ,GAAG,CAAC,oBAAoB,CAClE,2BAAK,CAAC,EAAI,2BAAK,IAAI,CACnB,2BAAK,CAAC,EAAI,2BAAK,IAAI,CACnB,2BAAK,CAAC,EAAI,2BAAK,IAAI,EAEpB,KAAK,CAAC,AAAC,IACN,QAAQ,KAAK,CAAC,UAAW,EAAE,OAAO,EAClC,QAAQ,IAAI,EACd,GAEF,QAAQ,GAAG,CAAC","sources":["<anon>","src/index.ts","src/lib.ts"],"sourcesContent":["var $aRKkE$minimist = require(\"minimist\");\nvar $aRKkE$path = require(\"path\");\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$reload = require(\"reload\");\nvar $aRKkE$chokidar = require(\"chokidar\");\n\n\n\n\n\nvar $f14dee9e17222834$var$$parcel$__dirname = $aRKkE$path.resolve(__dirname, \"../src\");\n\n\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$liascriptPath = '';\nvar $f14dee9e17222834$var$reloadInstance = null;\nvar $f14dee9e17222834$var$watcher = null;\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$liascriptPath = $aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$node_modules, '@liascript/editor/dist'));\n}\nasync function $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 // Initialize reload BEFORE routes to ensure its routes are registered first\n if (liveReload) {\n const watchPath = $aRKkE$path.join(project.path, project.readme || '');\n console.log(`\\u{2728} watching for changes on: \"${watchPath}\"`);\n try {\n $f14dee9e17222834$var$reloadInstance = await $aRKkE$reload($f14dee9e17222834$var$app);\n // Watch the file for changes using chokidar (more reliable than fs.watch)\n $f14dee9e17222834$var$watcher = $aRKkE$chokidar.watch(watchPath, {\n ignoreInitial: true,\n awaitWriteFinish: {\n stabilityThreshold: 100,\n pollInterval: 50\n }\n });\n $f14dee9e17222834$var$watcher.on('change', (filePath)=>{\n console.log(\"\\uD83D\\uDCDD file changed, reloading...\");\n $f14dee9e17222834$var$reloadInstance.reload();\n });\n $f14dee9e17222834$var$watcher.on('error', (error)=>{\n console.error('Watcher error:', error);\n });\n } catch (err) {\n console.error('Reload could not start:', err);\n }\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read');\n return;\n }\n res.send(data.replace('</head>', `<script type='text/javascript' src='/reload/reload.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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read');\n return;\n }\n res.send(data.replace('</head>', `<script type='text/javascript' src='/reload/reload.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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read');\n return;\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read');\n return;\n }\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 }, (err)=>{\n if (err) {\n // Extract the file path by removing the '/liascript/' prefix\n const projectPath = req.params[0];\n console.log(`File not found in liascriptPath, trying project.path: ${projectPath}`, project.path);\n res.sendFile(projectPath, {\n root: project.path\n });\n }\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 // 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.use('/*', $aRKkE$cors(), function(req, res, next) {\n // Skip reload and socket.io paths - let reload package handle them\n if (req.originalUrl.startsWith('/reload/') || req.originalUrl.startsWith('/socket.io')) return next();\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 = $f14dee9e17222834$var$app.listen(port);\n server.on('error', (e)=>{\n throw e;\n });\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 if ($f14dee9e17222834$var$watcher) {\n $f14dee9e17222834$var$watcher.close();\n $f14dee9e17222834$var$watcher = null;\n }\n if ($f14dee9e17222834$var$reloadInstance) $f14dee9e17222834$var$reloadInstance = null;\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.2.0');\n console.log('LiaScript: 1.0.2');\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);\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).catch((e)=>{\n console.error('Error: ', e.message);\n process.exit();\n});\nconsole.log(\"\\u2728 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.2.0')\n console.log('LiaScript: 1.0.2')\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\nserver\n .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: any) => {\n console.error('Error: ', e.message)\n process.exit()\n })\n\nconsole.log('β¨ hit Ctrl-c to close the server')\n","import * 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')\nconst reload = require('reload')\nconst chokidar = require('chokidar')\n\nconst app: express.Application = express()\napp.use(bodyParser.json())\n\nvar dirname = ''\nvar node_modules\nvar liascriptPath = ''\nvar reloadInstance: any = null\nvar watcher: any = null\n\nvar clients: any[] = []\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 liascriptPath = path.resolve(\n path.join(node_modules, '@liascript/editor/dist'),\n )\n}\n\nexport async 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 // Initialize reload BEFORE routes to ensure its routes are registered first\n if (liveReload) {\n const watchPath = path.join(project.path, project.readme || '')\n console.log(`β¨ watching for changes on: \"${watchPath}\"`)\n\n try {\n reloadInstance = await reload(app)\n\n // Watch the file for changes using chokidar (more reliable than fs.watch)\n watcher = chokidar.watch(watchPath, {\n ignoreInitial: true,\n awaitWriteFinish: {\n stabilityThreshold: 100,\n pollInterval: 50,\n },\n })\n\n watcher.on('change', (filePath: string) => {\n console.log('π file changed, reloading...')\n reloadInstance.reload()\n })\n\n watcher.on('error', (error: any) => {\n console.error('Watcher error:', error)\n })\n } catch (err) {\n console.error('Reload could not start:', err)\n }\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read')\n return\n }\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='/reload/reload.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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read')\n return\n }\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='/reload/reload.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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read')\n return\n }\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 if (err || !data) {\n res.status(500).send('index.html not found or could not be read')\n return\n }\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 }, (err) => {\n if (err) {\n // Extract the file path by removing the '/liascript/' prefix\n const projectPath = req.params[0]\n console.log(\n `File not found in liascriptPath, trying project.path: ${projectPath}`,\n project.path,\n )\n res.sendFile(projectPath, { root: project.path })\n }\n })\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 // 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.use(\n '/*',\n cors(),\n function (\n req: express.Request,\n res: express.Response,\n next: express.NextFunction,\n ) {\n // Skip reload and socket.io paths - let reload package handle them\n if (\n req.originalUrl.startsWith('/reload/') ||\n req.originalUrl.startsWith('/socket.io')\n ) {\n return next()\n }\n res.sendFile(req.originalUrl, { root: project.path })\n },\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 = app.listen(port)\n\n server.on('error', (e: any) => {\n throw e\n })\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 if (watcher) {\n watcher.close()\n watcher = null\n }\n if (reloadInstance) {\n reloadInstance = null\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","$f14dee9e17222834$var$serverPointer","$aRKkE$minimist","require","$aRKkE$path","$aRKkE$express","$aRKkE$fs","$aRKkE$cors","$aRKkE$expresshandlebars","$aRKkE$ip","$aRKkE$open","$aRKkE$bodyparser","$aRKkE$reload","$aRKkE$chokidar","$f14dee9e17222834$var$$parcel$__dirname","resolve","__dirname","$f14dee9e17222834$var$app","use","json","$f14dee9e17222834$var$dirname","$f14dee9e17222834$var$liascriptPath","$f14dee9e17222834$var$reloadInstance","$f14dee9e17222834$var$watcher","$f14dee9e17222834$var$clients","$f14dee9e17222834$var$gotoScript","$f14dee9e17222834$export$2cd8252107eb640b","serverPath","nodeModulesPath","join","$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","watchPath","console","log","watch","ignoreInitial","awaitWriteFinish","stabilityThreshold","pollInterval","on","filePath","reload","error","err","get","req","res","redirect","$f14dee9e17222834$var$eventsHandler","currentPath","params","files","readdirSync","filter","e","basePath","pathNames","split","paths","i","length","push","name","href","render","layout","file","map","sort","a","b","toLocaleLowerCase","endsWith","sendFile","root","send","readFile","data","status","replace","projectPath","post","linenumber","body","filename","warn","next","originalUrl","startsWith","localURL","server","listen","address","$f14dee9e17222834$export$fa6813432f753b0d","close","$f14dee9e17222834$export$5d5b784f9a618ec3","forEach","client","response","write","JSON","stringify","request","writeHead","Connection","clientId","Date","now","id","$71fcc9ea54afc905$var$argv","process","argv","slice","$71fcc9ea54afc905$var$liascript","v","version","exit","h","help","node_modules","p","n","r","env","RESPONSIVE_VOICE_KEY","l","live","o","open","t","test","catch","message"],"version":3,"file":"index.js.map","sourceRoot":"../"}
|
package/dist/lib.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export declare function init(serverPath?: string, nodeModulesPath?: string): void;
|
|
2
|
-
export declare function start(port?: number, hostname?: string, input?: string, responsiveVoice?: string, liveReload?: boolean, openInBrowser?: boolean, testOnline?: boolean, gotoCallback?: (linenumber: number, filename: string) => void): void
|
|
2
|
+
export declare function start(port?: number, hostname?: string, input?: string, responsiveVoice?: string, liveReload?: boolean, openInBrowser?: boolean, testOnline?: boolean, gotoCallback?: (linenumber: number, filename: string) => void): Promise<void>;
|
|
3
3
|
export declare function stop(): void;
|
|
4
4
|
export declare function gotoLine(linenumber: number, filename: string): void;
|
package/dist/lib.js
CHANGED
|
@@ -1,7 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
13
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.init = init;
|
|
40
|
+
exports.start = start;
|
|
41
|
+
exports.stop = stop;
|
|
42
|
+
exports.gotoLine = gotoLine;
|
|
5
43
|
var express = require("express");
|
|
6
44
|
var fs = require("fs");
|
|
7
45
|
var path = require("path");
|
|
@@ -10,12 +48,15 @@ var handlebars = require('express-handlebars');
|
|
|
10
48
|
var ip = require('ip');
|
|
11
49
|
var open = require('open');
|
|
12
50
|
var bodyParser = require('body-parser');
|
|
51
|
+
var reload = require('reload');
|
|
52
|
+
var chokidar = require('chokidar');
|
|
13
53
|
var app = express();
|
|
14
54
|
app.use(bodyParser.json());
|
|
15
55
|
var dirname = '';
|
|
16
56
|
var node_modules;
|
|
17
|
-
var reloadPath = '';
|
|
18
57
|
var liascriptPath = '';
|
|
58
|
+
var reloadInstance = null;
|
|
59
|
+
var watcher = null;
|
|
19
60
|
var clients = [];
|
|
20
61
|
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>";
|
|
21
62
|
var serverPointer;
|
|
@@ -23,244 +64,284 @@ init(__dirname);
|
|
|
23
64
|
function init(serverPath, nodeModulesPath) {
|
|
24
65
|
dirname = serverPath || path.join(__dirname, '..');
|
|
25
66
|
node_modules = nodeModulesPath || path.join(dirname, 'node_modules');
|
|
26
|
-
reloadPath = path.resolve(path.join(node_modules, 'reloadsh.js/reloader.browser.js'));
|
|
27
67
|
liascriptPath = path.resolve(path.join(node_modules, '@liascript/editor/dist'));
|
|
28
68
|
}
|
|
29
|
-
exports.init = init;
|
|
30
69
|
function start(port, hostname, input, responsiveVoice, liveReload, openInBrowser, testOnline, gotoCallback) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
project.path = input;
|
|
46
|
-
}
|
|
47
|
-
else if (stats.isFile()) {
|
|
48
|
-
project.path = path.dirname(input);
|
|
49
|
-
project.readme = path.basename(input);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
app.set('view engine', 'hbs');
|
|
53
|
-
app.engine('hbs', handlebars({
|
|
54
|
-
layoutsDir: path.resolve(path.join(dirname, 'views/layouts')),
|
|
55
|
-
defaultLayout: 'main',
|
|
56
|
-
extname: 'hbs'
|
|
57
|
-
}));
|
|
58
|
-
app.set('views', path.resolve(path.join(dirname, 'views')));
|
|
59
|
-
app.get('/', function (req, res) {
|
|
60
|
-
res.redirect('/home');
|
|
61
|
-
});
|
|
62
|
-
app.get('/gotoLine', eventsHandler);
|
|
63
|
-
app.get('/home*', function (req, res) {
|
|
64
|
-
var currentPath = project.path + '/' + req.params[0];
|
|
65
|
-
var stats = fs.lstatSync(currentPath);
|
|
66
|
-
// Is it a directory?
|
|
67
|
-
if (stats.isDirectory()) {
|
|
68
|
-
var files = fs.readdirSync(currentPath).filter(function (e) {
|
|
69
|
-
return e[0] !== '.';
|
|
70
|
-
});
|
|
71
|
-
var basePath = '/home';
|
|
72
|
-
var pathNames = req.params[0].split('/').filter(function (e) {
|
|
73
|
-
return e !== '';
|
|
74
|
-
});
|
|
75
|
-
var paths = [];
|
|
76
|
-
for (var i = 0; i < pathNames.length; i++) {
|
|
77
|
-
basePath += '/' + pathNames[i];
|
|
78
|
-
paths.push({ name: pathNames[i], href: basePath });
|
|
79
|
-
}
|
|
80
|
-
res.render('main', {
|
|
81
|
-
layout: 'index',
|
|
82
|
-
path: paths,
|
|
83
|
-
file: files
|
|
84
|
-
.map(function (file) {
|
|
85
|
-
return {
|
|
86
|
-
name: file,
|
|
87
|
-
href: "http://".concat(hostname, ":").concat(port, "/home").concat(req.params[0], "/").concat(file),
|
|
88
|
-
isDirectory: fs.lstatSync(currentPath + '/' + file).isDirectory()
|
|
70
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
71
|
+
var project, stats, watchPath, err_1, localURL, server;
|
|
72
|
+
return __generator(this, function (_a) {
|
|
73
|
+
switch (_a.label) {
|
|
74
|
+
case 0:
|
|
75
|
+
port = port || 3000;
|
|
76
|
+
hostname = hostname || 'localhost';
|
|
77
|
+
openInBrowser = openInBrowser || false;
|
|
78
|
+
input = input || '.';
|
|
79
|
+
liveReload = liveReload || false;
|
|
80
|
+
testOnline = testOnline || false;
|
|
81
|
+
project = {
|
|
82
|
+
path: input,
|
|
83
|
+
readme: undefined,
|
|
89
84
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
85
|
+
if (input) {
|
|
86
|
+
stats = fs.lstatSync(input);
|
|
87
|
+
// Is it a directory?
|
|
88
|
+
if (stats.isDirectory()) {
|
|
89
|
+
project.path = input;
|
|
90
|
+
}
|
|
91
|
+
else if (stats.isFile()) {
|
|
92
|
+
project.path = path.dirname(input);
|
|
93
|
+
project.readme = path.basename(input);
|
|
94
|
+
}
|
|
97
95
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
96
|
+
app.set('view engine', 'hbs');
|
|
97
|
+
app.engine('hbs', handlebars({
|
|
98
|
+
layoutsDir: path.resolve(path.join(dirname, 'views/layouts')),
|
|
99
|
+
defaultLayout: 'main',
|
|
100
|
+
extname: 'hbs',
|
|
101
|
+
}));
|
|
102
|
+
app.set('views', path.resolve(path.join(dirname, 'views')));
|
|
103
|
+
if (!liveReload) return [3 /*break*/, 4];
|
|
104
|
+
watchPath = path.join(project.path, project.readme || '');
|
|
105
|
+
console.log("\u2728 watching for changes on: \"".concat(watchPath, "\""));
|
|
106
|
+
_a.label = 1;
|
|
107
|
+
case 1:
|
|
108
|
+
_a.trys.push([1, 3, , 4]);
|
|
109
|
+
return [4 /*yield*/, reload(app)
|
|
110
|
+
// Watch the file for changes using chokidar (more reliable than fs.watch)
|
|
111
|
+
];
|
|
112
|
+
case 2:
|
|
113
|
+
reloadInstance = _a.sent();
|
|
114
|
+
// Watch the file for changes using chokidar (more reliable than fs.watch)
|
|
115
|
+
watcher = chokidar.watch(watchPath, {
|
|
116
|
+
ignoreInitial: true,
|
|
117
|
+
awaitWriteFinish: {
|
|
118
|
+
stabilityThreshold: 100,
|
|
119
|
+
pollInterval: 50,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
watcher.on('change', function (filePath) {
|
|
123
|
+
console.log('π file changed, reloading...');
|
|
124
|
+
reloadInstance.reload();
|
|
125
|
+
});
|
|
126
|
+
watcher.on('error', function (error) {
|
|
127
|
+
console.error('Watcher error:', error);
|
|
128
|
+
});
|
|
129
|
+
return [3 /*break*/, 4];
|
|
130
|
+
case 3:
|
|
131
|
+
err_1 = _a.sent();
|
|
132
|
+
console.error('Reload could not start:', err_1);
|
|
133
|
+
return [3 /*break*/, 4];
|
|
134
|
+
case 4:
|
|
135
|
+
app.get('/', function (req, res) {
|
|
136
|
+
res.redirect('/home');
|
|
137
|
+
});
|
|
138
|
+
app.get('/gotoLine', eventsHandler);
|
|
139
|
+
app.get('/home*', function (req, res) {
|
|
140
|
+
var currentPath = project.path + '/' + req.params[0];
|
|
141
|
+
var stats = fs.lstatSync(currentPath);
|
|
142
|
+
// Is it a directory?
|
|
143
|
+
if (stats.isDirectory()) {
|
|
144
|
+
var files = fs.readdirSync(currentPath).filter(function (e) {
|
|
145
|
+
return e[0] !== '.';
|
|
146
|
+
});
|
|
147
|
+
var basePath = '/home';
|
|
148
|
+
var pathNames = req.params[0].split('/').filter(function (e) {
|
|
149
|
+
return e !== '';
|
|
150
|
+
});
|
|
151
|
+
var paths = [];
|
|
152
|
+
for (var i = 0; i < pathNames.length; i++) {
|
|
153
|
+
basePath += '/' + pathNames[i];
|
|
154
|
+
paths.push({ name: pathNames[i], href: basePath });
|
|
155
|
+
}
|
|
156
|
+
res.render('main', {
|
|
157
|
+
layout: 'index',
|
|
158
|
+
path: paths,
|
|
159
|
+
file: files
|
|
160
|
+
.map(function (file) {
|
|
161
|
+
return {
|
|
162
|
+
name: file,
|
|
163
|
+
href: "http://".concat(hostname, ":").concat(port, "/home").concat(req.params[0], "/").concat(file),
|
|
164
|
+
isDirectory: fs.lstatSync(currentPath + '/' + file).isDirectory(),
|
|
165
|
+
};
|
|
166
|
+
})
|
|
167
|
+
.sort(function (a, b) {
|
|
168
|
+
if (a.isDirectory && !b.isDirectory) {
|
|
169
|
+
return -1;
|
|
170
|
+
}
|
|
171
|
+
else if (!a.isDirectory && b.isDirectory) {
|
|
172
|
+
return 1;
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
|
|
176
|
+
return -1;
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
return 1;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return 0;
|
|
183
|
+
}),
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
else if (stats.isFile()) {
|
|
187
|
+
if (req.params[0].toLocaleLowerCase().endsWith('.md')) {
|
|
188
|
+
if (testOnline) {
|
|
189
|
+
res.redirect("https://LiaScript.github.io/course/?http://".concat(hostname, ":").concat(port, "/").concat(req.params[0]));
|
|
190
|
+
}
|
|
191
|
+
else {
|
|
192
|
+
res.redirect("/liascript/index.html?http://".concat(hostname, ":").concat(port, "/").concat(req.params[0]));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
res.sendFile(req.params[0], { root: project.path });
|
|
197
|
+
}
|
|
101
198
|
}
|
|
102
199
|
else {
|
|
103
|
-
|
|
200
|
+
res.send('ups, something went wrong');
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
app.get('/liascript/', function (req, res) {
|
|
204
|
+
res.redirect('/liascript/index.html');
|
|
205
|
+
});
|
|
206
|
+
app.get('/liascript/index.html', function (req, res) {
|
|
207
|
+
// ------------------------------------
|
|
208
|
+
if (liveReload && responsiveVoice) {
|
|
209
|
+
fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
|
|
210
|
+
if (err || !data) {
|
|
211
|
+
res.status(500).send('index.html not found or could not be read');
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
res.send(data.replace('</head>', "<script type='text/javascript' src='/reload/reload.js'></script>\n <script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=".concat(responsiveVoice, "'></script>\n ").concat(gotoScript, "\n </head>")));
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
// ------------------------------------
|
|
218
|
+
else if (liveReload) {
|
|
219
|
+
fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
|
|
220
|
+
if (err || !data) {
|
|
221
|
+
res.status(500).send('index.html not found or could not be read');
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
res.send(data.replace('</head>', "<script type='text/javascript' src='/reload/reload.js'></script>\n ".concat(gotoScript, "\n </head>")));
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
// ------------------------------------
|
|
228
|
+
else if (responsiveVoice) {
|
|
229
|
+
fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
|
|
230
|
+
if (err || !data) {
|
|
231
|
+
res.status(500).send('index.html not found or could not be read');
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
res.send(data.replace('</head>', "<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=".concat(responsiveVoice, "'></script>\n ").concat(gotoScript, "\n </head>")));
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
|
+
// ------------------------------------
|
|
238
|
+
else {
|
|
239
|
+
fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
|
|
240
|
+
if (err || !data) {
|
|
241
|
+
res.status(500).send('index.html not found or could not be read');
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
res.send(data.replace('</head>', "".concat(gotoScript, "</head>")));
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
// load everything from the liascript folder
|
|
249
|
+
app.get('/liascript/*', function (req, res) {
|
|
250
|
+
res.sendFile(req.params[0], { root: liascriptPath }, function (err) {
|
|
251
|
+
if (err) {
|
|
252
|
+
// Extract the file path by removing the '/liascript/' prefix
|
|
253
|
+
var projectPath = req.params[0];
|
|
254
|
+
console.log("File not found in liascriptPath, trying project.path: ".concat(projectPath), project.path);
|
|
255
|
+
res.sendFile(projectPath, { root: project.path });
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
// ignore this one
|
|
260
|
+
app.get('/sw.js', function (req, res) { });
|
|
261
|
+
app.get('/favicon.ico', function (req, res) { });
|
|
262
|
+
// react to click-events
|
|
263
|
+
app.post('/lineGoto', function (req, res) {
|
|
264
|
+
if (gotoCallback) {
|
|
265
|
+
try {
|
|
266
|
+
var linenumber = req.body.linenumber;
|
|
267
|
+
var filename = req.body.filename;
|
|
268
|
+
gotoCallback(linenumber, filename);
|
|
269
|
+
}
|
|
270
|
+
catch (e) {
|
|
271
|
+
console.warn("lineGoto event with wrong datatype, you have to provide {'linenumber': int, 'filename': string}");
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
return res.json({});
|
|
275
|
+
});
|
|
276
|
+
// everything else comes from the current project folder
|
|
277
|
+
app.use('/*', cors(), function (req, res, next) {
|
|
278
|
+
// Skip reload and socket.io paths - let reload package handle them
|
|
279
|
+
if (req.originalUrl.startsWith('/reload/') ||
|
|
280
|
+
req.originalUrl.startsWith('/socket.io')) {
|
|
281
|
+
return next();
|
|
104
282
|
}
|
|
283
|
+
res.sendFile(req.originalUrl, { root: project.path });
|
|
284
|
+
});
|
|
285
|
+
localURL = 'http://' + hostname + ':' + port;
|
|
286
|
+
if (project.path && project.readme) {
|
|
287
|
+
localURL +=
|
|
288
|
+
'/liascript/index.html?http://' +
|
|
289
|
+
hostname +
|
|
290
|
+
':' +
|
|
291
|
+
port +
|
|
292
|
+
'/' +
|
|
293
|
+
project.readme;
|
|
105
294
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
app.get('/liascript/', function (req, res) {
|
|
128
|
-
res.redirect('/liascript/index.html');
|
|
129
|
-
});
|
|
130
|
-
app.get('/liascript/index.html', function (req, res) {
|
|
131
|
-
// ------------------------------------
|
|
132
|
-
if (liveReload && responsiveVoice) {
|
|
133
|
-
fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
|
|
134
|
-
if (err || !data) {
|
|
135
|
-
res.status(500).send('index.html not found or could not be read');
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
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=".concat(responsiveVoice, "'></script>\n ").concat(gotoScript, "\n </head>")));
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
// ------------------------------------
|
|
142
|
-
else if (liveReload) {
|
|
143
|
-
fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
|
|
144
|
-
if (err || !data) {
|
|
145
|
-
res.status(500).send('index.html not found or could not be read');
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
res.send(data.replace('</head>', "<script type='text/javascript' src='/reloader/reloader.js'></script>\n ".concat(gotoScript, "\n </head>")));
|
|
149
|
-
});
|
|
150
|
-
}
|
|
151
|
-
// ------------------------------------
|
|
152
|
-
else if (responsiveVoice) {
|
|
153
|
-
fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
|
|
154
|
-
if (err || !data) {
|
|
155
|
-
res.status(500).send('index.html not found or could not be read');
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
res.send(data.replace('</head>', "<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=".concat(responsiveVoice, "'></script>\n ").concat(gotoScript, "\n </head>")));
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
// ------------------------------------
|
|
162
|
-
else {
|
|
163
|
-
fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
|
|
164
|
-
if (err || !data) {
|
|
165
|
-
res.status(500).send('index.html not found or could not be read');
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
res.send(data.replace('</head>', "".concat(gotoScript, "</head>")));
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
// load everything from the liascript folder
|
|
173
|
-
app.get('/liascript/*', function (req, res) {
|
|
174
|
-
res.sendFile(req.params[0], { root: liascriptPath }, function (err) {
|
|
175
|
-
if (err) {
|
|
176
|
-
// Extract the file path by removing the '/liascript/' prefix
|
|
177
|
-
var projectPath = req.params[0];
|
|
178
|
-
console.log("File not found in liascriptPath, trying project.path: ".concat(projectPath), project.path);
|
|
179
|
-
res.sendFile(projectPath, { root: project.path });
|
|
295
|
+
if (testOnline && project.readme) {
|
|
296
|
+
localURL =
|
|
297
|
+
'https://LiaScript.github.io/course/?http://' +
|
|
298
|
+
hostname +
|
|
299
|
+
':' +
|
|
300
|
+
port +
|
|
301
|
+
'/' +
|
|
302
|
+
project.readme;
|
|
303
|
+
}
|
|
304
|
+
server = app.listen(port);
|
|
305
|
+
server.on('error', function (e) {
|
|
306
|
+
throw e;
|
|
307
|
+
});
|
|
308
|
+
if (openInBrowser) {
|
|
309
|
+
open(localURL);
|
|
310
|
+
}
|
|
311
|
+
console.log('π‘ starting server');
|
|
312
|
+
console.log(" - local: ".concat(localURL));
|
|
313
|
+
console.log(" - on your network: ".concat(localURL.replace(hostname, ip.address())));
|
|
314
|
+
serverPointer = server;
|
|
315
|
+
return [2 /*return*/];
|
|
180
316
|
}
|
|
181
317
|
});
|
|
182
318
|
});
|
|
183
|
-
// ignore this one
|
|
184
|
-
app.get('/sw.js', function (req, res) { });
|
|
185
|
-
app.get('/favicon.ico', function (req, res) { });
|
|
186
|
-
// pass the reloader, to be used for live updates
|
|
187
|
-
app.get('/reloader/reloader.js', function (req, res) {
|
|
188
|
-
res.sendFile(reloadPath);
|
|
189
|
-
});
|
|
190
|
-
// react to click-events
|
|
191
|
-
app.post('/lineGoto', function (req, res) {
|
|
192
|
-
if (gotoCallback) {
|
|
193
|
-
try {
|
|
194
|
-
var linenumber = req.body.linenumber;
|
|
195
|
-
var filename = req.body.filename;
|
|
196
|
-
gotoCallback(linenumber, filename);
|
|
197
|
-
}
|
|
198
|
-
catch (e) {
|
|
199
|
-
console.warn("lineGoto event with wrong datatype, you have to provide {'linenumber': int, 'filename': string}");
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
return res.json({});
|
|
203
|
-
});
|
|
204
|
-
// everything else comes from the current project folder
|
|
205
|
-
app.get('/*', cors(), function (req, res) {
|
|
206
|
-
res.sendFile(req.originalUrl, { root: project.path });
|
|
207
|
-
});
|
|
208
|
-
var localURL = 'http://' + hostname + ':' + port;
|
|
209
|
-
if (project.path && project.readme) {
|
|
210
|
-
localURL +=
|
|
211
|
-
'/liascript/index.html?http://' +
|
|
212
|
-
hostname +
|
|
213
|
-
':' +
|
|
214
|
-
port +
|
|
215
|
-
'/' +
|
|
216
|
-
project.readme;
|
|
217
|
-
}
|
|
218
|
-
if (testOnline && project.readme) {
|
|
219
|
-
localURL =
|
|
220
|
-
'https://LiaScript.github.io/course/?http://' +
|
|
221
|
-
hostname +
|
|
222
|
-
':' +
|
|
223
|
-
port +
|
|
224
|
-
'/' +
|
|
225
|
-
project.readme;
|
|
226
|
-
}
|
|
227
|
-
var server = require('reloadsh.js')(app, liveReload ? [path.join(project.path, project.readme || '')] : []);
|
|
228
|
-
if (liveReload) {
|
|
229
|
-
console.log("\u2728 watching for changes on: \"".concat(path.join(project.path || '', project.readme || ''), "\""));
|
|
230
|
-
}
|
|
231
|
-
server.on('error', function (e) {
|
|
232
|
-
throw e;
|
|
233
|
-
});
|
|
234
|
-
server.listen(port);
|
|
235
|
-
if (openInBrowser) {
|
|
236
|
-
open(localURL);
|
|
237
|
-
}
|
|
238
|
-
console.log('π‘ starting server');
|
|
239
|
-
console.log(" - local: ".concat(localURL));
|
|
240
|
-
console.log(" - on your network: ".concat(localURL.replace(hostname, ip.address())));
|
|
241
|
-
serverPointer = server;
|
|
242
319
|
}
|
|
243
|
-
exports.start = start;
|
|
244
320
|
function stop() {
|
|
245
321
|
if (serverPointer) {
|
|
246
322
|
serverPointer.close();
|
|
247
323
|
}
|
|
324
|
+
if (watcher) {
|
|
325
|
+
watcher.close();
|
|
326
|
+
watcher = null;
|
|
327
|
+
}
|
|
328
|
+
if (reloadInstance) {
|
|
329
|
+
reloadInstance = null;
|
|
330
|
+
}
|
|
248
331
|
}
|
|
249
|
-
exports.stop = stop;
|
|
250
332
|
function gotoLine(linenumber, filename) {
|
|
251
333
|
clients.forEach(function (client) {
|
|
252
334
|
return client.response.write("data: ".concat(JSON.stringify({
|
|
253
335
|
linenumber: linenumber,
|
|
254
|
-
filename: filename
|
|
336
|
+
filename: filename,
|
|
255
337
|
}), "\n\n"));
|
|
256
338
|
});
|
|
257
339
|
}
|
|
258
|
-
exports.gotoLine = gotoLine;
|
|
259
340
|
function eventsHandler(request, response, next) {
|
|
260
341
|
var headers = {
|
|
261
342
|
'Content-Type': 'text/event-stream',
|
|
262
343
|
Connection: 'keep-alive',
|
|
263
|
-
'Cache-Control': 'no-cache'
|
|
344
|
+
'Cache-Control': 'no-cache',
|
|
264
345
|
};
|
|
265
346
|
response.writeHead(200, headers);
|
|
266
347
|
var data = "data: \n\n";
|
|
@@ -268,11 +349,11 @@ function eventsHandler(request, response, next) {
|
|
|
268
349
|
var clientId = Date.now();
|
|
269
350
|
var newClient = {
|
|
270
351
|
id: clientId,
|
|
271
|
-
response: response
|
|
352
|
+
response: response,
|
|
272
353
|
};
|
|
273
354
|
clients.push(newClient);
|
|
274
355
|
request.on('close', function () {
|
|
275
|
-
console.log(
|
|
356
|
+
//console.log(`${clientId} Connection closed`)
|
|
276
357
|
clients = clients.filter(function (client) { return client.id !== clientId; });
|
|
277
358
|
});
|
|
278
359
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@liascript/devserver",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0--1.0.2",
|
|
4
4
|
"description": "Run a development server for LiaScript locally",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,22 +35,22 @@
|
|
|
35
35
|
"author": "AndrΓ© Dietrich",
|
|
36
36
|
"license": "MIT",
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@liascript/editor": "^1.1.41--1.0.
|
|
39
|
-
"body-parser": "^1.20.
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"express": "^4.
|
|
38
|
+
"@liascript/editor": "^1.1.41--1.0.2",
|
|
39
|
+
"body-parser": "^1.20.4",
|
|
40
|
+
"chokidar": "^4.0.3",
|
|
41
|
+
"cors": "^2.8.6",
|
|
42
|
+
"express": "^4.22.1",
|
|
43
43
|
"express-handlebars": "^5.3.5",
|
|
44
|
-
"ip": "^
|
|
44
|
+
"ip": "^2.0.1",
|
|
45
45
|
"minimist": "^1.2.8",
|
|
46
46
|
"open": "^8.4.2",
|
|
47
|
-
"
|
|
47
|
+
"reload": "^3.3.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@types/express": "^4.17.
|
|
51
|
-
"@types/node": "^
|
|
52
|
-
"parcel": "^2.
|
|
53
|
-
"typescript": "^
|
|
50
|
+
"@types/express": "^4.17.25",
|
|
51
|
+
"@types/node": "^25.2.3",
|
|
52
|
+
"parcel": "^2.16.4",
|
|
53
|
+
"typescript": "^5.9.3"
|
|
54
54
|
},
|
|
55
55
|
"engines": {
|
|
56
56
|
"node": ">= 12"
|
|
@@ -64,7 +64,6 @@
|
|
|
64
64
|
"pkg": {
|
|
65
65
|
"assets": [
|
|
66
66
|
"node_modules/@liascript/editor/dist/**/*",
|
|
67
|
-
"node_modules/reloadsh.js/reloader.browser.js",
|
|
68
67
|
"views/**/*"
|
|
69
68
|
]
|
|
70
69
|
}
|