@liascript/devserver 1.1.50--0.17.10 → 1.1.51--0.17.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/lib.js +16 -0
- package/package.json +1 -1
- package/views/main.hbs +1 -1
package/README.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -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$reloadPath=$aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$node_modules,"reloadsh.js/reloader.browser.js")),$f14dee9e17222834$var$liascriptPath=$aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$node_modules,"@liascript/editor/dist"))}function $f14dee9e17222834$export$b3571188c770cc5a(e,a,r,o,$,
|
|
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$reloadPath=$aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$node_modules,"reloadsh.js/reloader.browser.js")),$f14dee9e17222834$var$liascriptPath=$aRKkE$path.resolve($aRKkE$path.join($f14dee9e17222834$var$node_modules,"@liascript/editor/dist"))}function $f14dee9e17222834$export$b3571188c770cc5a(e,a,r,o,t,$,i,n){e=e||3e3,a=a||"localhost",$=$||!1,t=t||!1,i=i||!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))}$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"))),$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]),i="/home",n=r.params[0].split("/").filter(e=>""!==e),s=[];for(let e=0;e<n.length;e++)i+="/"+n[e],s.push({name:n[e],href:i});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")?i?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){if(e||!r)return void a.status(500).send("index.html not found or could not be read");a.send(r.replace("</head>",`<script type='text/javascript' src='/reloader/reloader.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>`))})
|
|
38
|
+
</head>`))}):t?$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){if(e||!r)return void a.status(500).send("index.html not found or could not be read");a.send(r.replace("</head>",`<script type='text/javascript' src='/reloader/reloader.js'></script>
|
|
39
39
|
${$f14dee9e17222834$var$gotoScript}
|
|
40
|
-
</head>`))}):o?$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){a.send(r.replace("</head>",`<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${o}'></script>
|
|
40
|
+
</head>`))}):o?$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){if(e||!r)return void 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){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.get("/reloader/reloader.js",function(e,a){a.sendFile($f14dee9e17222834$var$reloadPath)}),$f14dee9e17222834$var$app.post("/lineGoto",function(e,a){if(n)try{let a=e.body.linenumber,r=e.body.filename;n(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.get("/*",$aRKkE$cors(),function(e,a){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),i&&s.readme&&(c="https://LiaScript.github.io/course/?http://"+a+":"+e+"/"+s.readme);let l=$aRKkE$reloadshjs($f14dee9e17222834$var$app
|
|
42
|
+
</head>`))}):$aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath+"/index.html","utf8",function(e,r){if(e||!r)return void 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.get("/reloader/reloader.js",function(e,a){a.sendFile($f14dee9e17222834$var$reloadPath)}),$f14dee9e17222834$var$app.post("/lineGoto",function(e,a){if(n)try{let a=e.body.linenumber,r=e.body.filename;n(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.get("/*",$aRKkE$cors(),function(e,a){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),i&&s.readme&&(c="https://LiaScript.github.io/course/?http://"+a+":"+e+"/"+s.readme);let l=$aRKkE$reloadshjs($f14dee9e17222834$var$app,t?[$aRKkE$path.join(s.path,s.readme||"")]:[]);t&&console.log(`\u{2728} watching for changes on: "${$aRKkE$path.join(s.path||"",s.readme||"")}"`),l.on("error",e=>{throw e}),l.listen(e),$&&$aRKkE$open(c),console.log("\uD83D\uDCE1 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()}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
|
|
46
|
+
`;a.write(o);let t=Date.now();$f14dee9e17222834$var$clients.push({id:t,response:a}),e.on("close",()=>{console.log(`${t} Connection closed`),$f14dee9e17222834$var$clients=$f14dee9e17222834$var$clients.filter(e=>e.id!==t)})}$f14dee9e17222834$export$2cd8252107eb640b($f14dee9e17222834$var$$parcel$__dirname);let $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.1.51"),console.log("LiaScript: 0.17.10"),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);try{$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,wC,Y,O,C,U,UAxDJ,cAAA,MAAA,GAYA,IAAM,0BAA2B,iBACjC,0BAAI,GAAG,CAAC,kBAAR,IAAA,IAEA,IAA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Q,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 res.send(data.replace('</head>', `<script type='text/javascript' src='/reloader/reloader.js'></script>\n <script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${$f14dee9e17222834$var$gotoScript}\n </head>`));\n });\n else if (liveReload) $aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath + '/index.html', 'utf8', function(err, data) {\n res.send(data.replace('</head>', `<script type='text/javascript' src='/reloader/reloader.js'></script>\n ${$f14dee9e17222834$var$gotoScript}\n </head>`));\n });\n else if (responsiveVoice) $aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath + '/index.html', 'utf8', function(err, data) {\n res.send(data.replace('</head>', `<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${$f14dee9e17222834$var$gotoScript}\n </head>`));\n });\n else $aRKkE$fs.readFile($f14dee9e17222834$var$liascriptPath + '/index.html', 'utf8', function(err, data) {\n res.send(data.replace('</head>', `${$f14dee9e17222834$var$gotoScript}</head>`));\n });\n });\n // load everything from the liascript folder\n $f14dee9e17222834$var$app.get('/liascript/*', function(req, res) {\n res.sendFile(req.params[0], {\n root: $f14dee9e17222834$var$liascriptPath\n }, (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.50');\n console.log('LiaScript: 0.17.10');\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.50')\n console.log('LiaScript: 0.17.10')\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 res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='/reloader/reloader.js'></script>\n <script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${gotoScript}\n </head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else if (liveReload) {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='/reloader/reloader.js'></script>\n ${gotoScript}\n </head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else if (responsiveVoice) {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(\n data.replace(\n '</head>',\n `<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>\n ${gotoScript}\n </head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else {\n fs.readFile(\n liascriptPath + '/index.html',\n 'utf8',\n function (err: any, data: string) {\n res.send(data.replace('</head>', `${gotoScript}</head>`))\n }\n )\n }\n }\n )\n\n // load everything from the liascript folder\n app.get(\n '/liascript/*',\n function (req: express.Request, res: express.Response) {\n res.sendFile(req.params[0], { root: liascriptPath }, (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","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,IEgBI,mCAwCA,oC,gB,Q,Y,Y,Q,Q,c,Q,U,e,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,GAAG,CAAC,+CACZ,QAAQ,GAAG,CAAC,sDACZ,QAAQ,GAAG,CAAC,sDAEZ,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.51');\n console.log('LiaScript: 0.17.10');\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.51')\n console.log('LiaScript: 0.17.10')\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":"../"}
|
package/dist/lib.js
CHANGED
|
@@ -131,24 +131,40 @@ function start(port, hostname, input, responsiveVoice, liveReload, openInBrowser
|
|
|
131
131
|
// ------------------------------------
|
|
132
132
|
if (liveReload && responsiveVoice) {
|
|
133
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
|
+
}
|
|
134
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>")));
|
|
135
139
|
});
|
|
136
140
|
}
|
|
137
141
|
// ------------------------------------
|
|
138
142
|
else if (liveReload) {
|
|
139
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
|
+
}
|
|
140
148
|
res.send(data.replace('</head>', "<script type='text/javascript' src='/reloader/reloader.js'></script>\n ".concat(gotoScript, "\n </head>")));
|
|
141
149
|
});
|
|
142
150
|
}
|
|
143
151
|
// ------------------------------------
|
|
144
152
|
else if (responsiveVoice) {
|
|
145
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
|
+
}
|
|
146
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>")));
|
|
147
159
|
});
|
|
148
160
|
}
|
|
149
161
|
// ------------------------------------
|
|
150
162
|
else {
|
|
151
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
|
+
}
|
|
152
168
|
res.send(data.replace('</head>', "".concat(gotoScript, "</head>")));
|
|
153
169
|
});
|
|
154
170
|
}
|
package/package.json
CHANGED