@liascript/devserver 1.0.11--0.10.8 → 1.0.12--0.10.8

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 CHANGED
@@ -78,7 +78,7 @@ updated separately, we use two different version, one for the devServer and one
78
78
  for LiaScript.
79
79
 
80
80
  ```text
81
- DevServer: 1.0.11
81
+ DevServer: 1.0.12
82
82
  LiaScript: 0.10.8
83
83
  ```
84
84
 
package/dist/index.js CHANGED
@@ -1,19 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  var $9KXPr$minimist = require("minimist");
4
+ var $9KXPr$path = require("path");
4
5
  var $9KXPr$dotenv = require("dotenv");
5
6
  var $9KXPr$express = require("express");
6
7
  var $9KXPr$fs = require("fs");
7
- var $9KXPr$path = require("path");
8
8
  var $9KXPr$cors = require("cors");
9
9
  var $9KXPr$expresshandlebars = require("express-handlebars");
10
10
  var $9KXPr$ip = require("ip");
11
- var $9KXPr$reloadshjs = require("reloadsh.js");
12
11
  var $9KXPr$open = require("open");
12
+ var $9KXPr$reloadshjs = require("reloadsh.js");
13
+
13
14
 
14
15
 
15
16
 
16
17
 
18
+ var $dbf4313da36ea993$var$__dirname = $9KXPr$path.resolve(__dirname, "../src");
17
19
 
18
20
  $9KXPr$dotenv.config();
19
21
 
@@ -26,9 +28,9 @@ var $dbf4313da36ea993$var$node_modules;
26
28
  var $dbf4313da36ea993$var$reloadPath = '';
27
29
  var $dbf4313da36ea993$var$liascriptPath = '';
28
30
  var $dbf4313da36ea993$var$serverPointer;
29
- $dbf4313da36ea993$export$2cd8252107eb640b(__dirname);
31
+ $dbf4313da36ea993$export$2cd8252107eb640b($dbf4313da36ea993$var$__dirname);
30
32
  function $dbf4313da36ea993$export$2cd8252107eb640b(serverPath, nodeModulesPath) {
31
- $dbf4313da36ea993$var$dirname = serverPath || $9KXPr$path.join(__dirname, '..');
33
+ $dbf4313da36ea993$var$dirname = serverPath || $9KXPr$path.join($dbf4313da36ea993$var$__dirname, '..');
32
34
  $dbf4313da36ea993$var$node_modules = nodeModulesPath || $9KXPr$path.join($dbf4313da36ea993$var$dirname, 'node_modules');
33
35
  $dbf4313da36ea993$var$reloadPath = $9KXPr$path.resolve($9KXPr$path.join($dbf4313da36ea993$var$node_modules, 'reloadsh.js/reloader.browser.js'));
34
36
  $dbf4313da36ea993$var$liascriptPath = $9KXPr$path.resolve($9KXPr$path.join($dbf4313da36ea993$var$node_modules, '@liascript/editor/dist'));
@@ -183,7 +185,7 @@ function $aa3bf3164f10b283$var$liascript() {
183
185
  console.log();
184
186
  }
185
187
  if ($aa3bf3164f10b283$var$argv.v || $aa3bf3164f10b283$var$argv.version) {
186
- console.log('DevServer: 1.0.11');
188
+ console.log('DevServer: 1.0.12');
187
189
  console.log('LiaScript: 0.10.8');
188
190
  process.exit();
189
191
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;ACAA;;;;AAAA,oBAAwB,EAAE;;;;;AAW1B,MAAM,yBAAG,GAAwB,cAAO,EAAE;AAE1C,IAAI,6BAAO,GAAG,EAAE;AAChB,IAAI,kCAAY;AAChB,IAAI,gCAAU,GAAG,EAAE;AACnB,IAAI,mCAAa,GAAG,EAAE;AAEtB,IAAI,mCAAa,AAAK;AAEtB,yCAAI,CAAC,SAAS,CAAC;AAER,SAAS,yCAAI,CAAC,UAAmB,EAAE,eAAwB,EAAE;IAClE,6BAAO,GAAG,UAAU,IAAI,gBAAS,CAAC,SAAS,EAAE,IAAI,CAAC;IAElD,kCAAY,GAAG,eAAe,IAAI,gBAAS,CAAC,6BAAO,EAAE,cAAc,CAAC;IAEpE,gCAAU,GAAG,mBAAY,CACvB,gBAAS,CAAC,kCAAY,EAAE,iCAAiC,CAAC,CAC3D;IAED,mCAAa,GAAG,mBAAY,CAC1B,gBAAS,CAAC,kCAAY,EAAE,wBAAwB,CAAC,CAClD;CACF;;AAEM,SAAS,yCAAK,CACnB,IAAa,EACb,QA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ACnC,OAAO,CAAC,IAAI,EAAE;CACf;AAED,OAAO,CAAC,GAAG,CAAC,oCAAkC,CAAC","sources":["src/index.ts","src/lib.ts"],"sourcesContent":["const argv = require('minimist')(process.argv.slice(2))\n\nimport * as server from './lib'\n\nfunction liascript() {\n console.log(' _ _ ____ _ _')\n console.log('| | (_) __ _/ ___| ___ _ __(_)_ __ | |_')\n console.log(\"| | | |/ _` \\\\___ \\\\ / __| '__| | '_ \\\\| __|\")\n console.log('| |___| | (_| |___) | (__| | | | |_) | |_ ')\n console.log('|_____|_|\\\\__,_|____/ \\\\___|_| |_| .__/ \\\\__|')\n console.log(' |_|')\n console.log()\n}\n\nif (argv.v || argv.version) {\n console.log('DevServer: 1.0.11')\n console.log('LiaScript: 0.10.8')\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')\n\nconst app: express.Application = express()\n\nvar dirname = ''\nvar node_modules\nvar reloadPath = ''\nvar liascriptPath = ''\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) {\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('/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 </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></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></head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else {\n res.sendFile(liascriptPath + '/index.html')\n }\n }\n )\n\n // load everything from the liascript folder\n app.get(\n '/liascript/*',\n function (req: express.Request, res: express.Response) {\n res.sendFile(req.params[0], { root: liascriptPath })\n }\n )\n // ignore this one\n app.get('/sw.js', function (req: express.Request, res: express.Response) {})\n app.get(\n '/favicon.ico',\n function (req: express.Request, res: express.Response) {}\n )\n\n // pass the reloader, to be used for live updates\n app.get(\n '/reloader/reloader.js',\n function (req: express.Request, res: express.Response) {\n res.sendFile(reloadPath)\n }\n )\n\n // 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"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
1
+ {"mappings":";;;;;;;;;;;ACAA;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AG,CAAC,oDAAoD,CAAC;IAEjE,OAAO,CAAC,IAAI,EAAE;CACf;AAED,+BAAS,EAAE;AAEX,yCAAW,CAAC,0BAAI,CAAC,YAAY,CAAC;AAE9B,IAAI;IACF,yCAAY,CACV,0BAAI,CAAC,CAAC,IAAI,0BAAI,CAAC,IAAI,EACnB,0BAAI,CAAC,CAAC,IAAI,0BAAI,CAAC,QAAQ,EACvB,0BAAI,CAAC,CAAC,IAAI,0BAAI,CAAC,KAAK,EACpB,0BAAI,CAAC,CAAC,IAAI,0BAAI,CAAC,eAAe,IAAI,OAAO,CAAC,GAAG,CAAC,oBAAoB,EAClE,0BAAI,CAAC,CAAC,IAAI,0BAAI,CAAC,IAAI,EACnB,0BAAI,CAAC,CAAC,IAAI,0BAAI,CAAC,IAAI,EACnB,0BAAI,CAAC,CAAC,IAAI,0BAAI,CAAC,IAAI,CACpB;CACF,CAAC,OAAO,CAAC,EAAE;IACV,OAAO,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC;IACnC,OAAO,CAAC,IAAI,EAAE;CACf;AAED,OAAO,CAAC,GAAG,CAAC,oCAAkC,CAAC","sources":["src/index.ts","src/lib.ts"],"sourcesContent":["const argv = require('minimist')(process.argv.slice(2))\n\nimport * as server from './lib'\n\nfunction liascript() {\n console.log(' _ _ ____ _ _')\n console.log('| | (_) __ _/ ___| ___ _ __(_)_ __ | |_')\n console.log(\"| | | |/ _` \\\\___ \\\\ / __| '__| | '_ \\\\| __|\")\n console.log('| |___| | (_| |___) | (__| | | | |_) | |_ ')\n console.log('|_____|_|\\\\__,_|____/ \\\\___|_| |_| .__/ \\\\__|')\n console.log(' |_|')\n console.log()\n}\n\nif (argv.v || argv.version) {\n console.log('DevServer: 1.0.12')\n console.log('LiaScript: 0.10.8')\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')\n\nconst app: express.Application = express()\n\nvar dirname = ''\nvar node_modules\nvar reloadPath = ''\nvar liascriptPath = ''\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) {\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('/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 </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></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></head>`\n )\n )\n }\n )\n }\n // ------------------------------------\n else {\n res.sendFile(liascriptPath + '/index.html')\n }\n }\n )\n\n // load everything from the liascript folder\n app.get(\n '/liascript/*',\n function (req: express.Request, res: express.Response) {\n res.sendFile(req.params[0], { root: liascriptPath })\n }\n )\n // ignore this one\n app.get('/sw.js', function (req: express.Request, res: express.Response) {})\n app.get(\n '/favicon.ico',\n function (req: express.Request, res: express.Response) {}\n )\n\n // pass the reloader, to be used for live updates\n app.get(\n '/reloader/reloader.js',\n function (req: express.Request, res: express.Response) {\n res.sendFile(reloadPath)\n }\n )\n\n // 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"],"names":[],"version":3,"file":"index.js.map","sourceRoot":"../"}
package/dist/lib.js ADDED
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.stop = exports.start = exports.init = void 0;
4
+ require('dotenv').config();
5
+ var express = require("express");
6
+ var fs = require("fs");
7
+ var path = require("path");
8
+ var cors = require('cors');
9
+ var handlebars = require('express-handlebars');
10
+ var ip = require('ip');
11
+ var open = require('open');
12
+ var app = express();
13
+ var dirname = '';
14
+ var node_modules;
15
+ var reloadPath = '';
16
+ var liascriptPath = '';
17
+ var serverPointer;
18
+ init(__dirname);
19
+ function init(serverPath, nodeModulesPath) {
20
+ dirname = serverPath || path.join(__dirname, '..');
21
+ node_modules = nodeModulesPath || path.join(dirname, 'node_modules');
22
+ reloadPath = path.resolve(path.join(node_modules, 'reloadsh.js/reloader.browser.js'));
23
+ liascriptPath = path.resolve(path.join(node_modules, '@liascript/editor/dist'));
24
+ }
25
+ exports.init = init;
26
+ function start(port, hostname, input, responsiveVoice, liveReload, openInBrowser, testOnline) {
27
+ port = port || 3000;
28
+ hostname = hostname || 'localhost';
29
+ openInBrowser = openInBrowser || false;
30
+ input = input || '.';
31
+ liveReload = liveReload || false;
32
+ testOnline = testOnline || false;
33
+ var project = {
34
+ path: input,
35
+ readme: undefined
36
+ };
37
+ if (input) {
38
+ var stats = fs.lstatSync(input);
39
+ // Is it a directory?
40
+ if (stats.isDirectory()) {
41
+ project.path = input;
42
+ }
43
+ else if (stats.isFile()) {
44
+ project.path = path.dirname(input);
45
+ project.readme = path.basename(input);
46
+ }
47
+ }
48
+ app.set('view engine', 'hbs');
49
+ app.engine('hbs', handlebars({
50
+ layoutsDir: path.resolve(path.join(dirname, 'views/layouts')),
51
+ defaultLayout: 'main',
52
+ extname: 'hbs'
53
+ }));
54
+ app.set('views', path.resolve(path.join(dirname, 'views')));
55
+ app.get('/', function (req, res) {
56
+ res.redirect('/home');
57
+ });
58
+ app.get('/home*', function (req, res) {
59
+ var currentPath = project.path + '/' + req.params[0];
60
+ var stats = fs.lstatSync(currentPath);
61
+ // Is it a directory?
62
+ if (stats.isDirectory()) {
63
+ var files = fs.readdirSync(currentPath).filter(function (e) {
64
+ return e[0] !== '.';
65
+ });
66
+ var basePath = '/home';
67
+ var pathNames = req.params[0].split('/').filter(function (e) {
68
+ return e !== '';
69
+ });
70
+ var paths = [];
71
+ for (var i = 0; i < pathNames.length; i++) {
72
+ basePath += '/' + pathNames[i];
73
+ paths.push({ name: pathNames[i], href: basePath });
74
+ }
75
+ res.render('main', {
76
+ layout: 'index',
77
+ path: paths,
78
+ file: files
79
+ .map(function (file) {
80
+ return {
81
+ name: file,
82
+ href: "http://".concat(hostname, ":").concat(port, "/home").concat(req.params[0], "/").concat(file),
83
+ isDirectory: fs.lstatSync(currentPath + '/' + file).isDirectory()
84
+ };
85
+ })
86
+ .sort(function (a, b) {
87
+ if (a.isDirectory && !b.isDirectory) {
88
+ return -1;
89
+ }
90
+ else if (!a.isDirectory && b.isDirectory) {
91
+ return 1;
92
+ }
93
+ else {
94
+ if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
95
+ return -1;
96
+ }
97
+ else {
98
+ return 1;
99
+ }
100
+ }
101
+ return 0;
102
+ })
103
+ });
104
+ }
105
+ else if (stats.isFile()) {
106
+ if (req.params[0].toLocaleLowerCase().endsWith('.md')) {
107
+ if (testOnline) {
108
+ res.redirect("https://LiaScript.github.io/course/?http://".concat(hostname, ":").concat(port, "/").concat(req.params[0]));
109
+ }
110
+ else {
111
+ res.redirect("/liascript/index.html?http://".concat(hostname, ":").concat(port, "/").concat(req.params[0]));
112
+ }
113
+ }
114
+ else {
115
+ res.sendFile(req.params[0], { root: project.path });
116
+ }
117
+ }
118
+ else {
119
+ res.send('ups, something went wrong');
120
+ }
121
+ });
122
+ app.get('/liascript/', function (req, res) {
123
+ res.redirect('/liascript/index.html');
124
+ });
125
+ app.get('/liascript/index.html', function (req, res) {
126
+ // ------------------------------------
127
+ if (liveReload && responsiveVoice) {
128
+ fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
129
+ 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 </head>")));
130
+ });
131
+ }
132
+ // ------------------------------------
133
+ else if (liveReload) {
134
+ fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
135
+ res.send(data.replace('</head>', "<script type='text/javascript' src='/reloader/reloader.js'></script></head>"));
136
+ });
137
+ }
138
+ // ------------------------------------
139
+ else if (responsiveVoice) {
140
+ fs.readFile(liascriptPath + '/index.html', 'utf8', function (err, data) {
141
+ res.send(data.replace('</head>', "<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=".concat(responsiveVoice, "'></script></head>")));
142
+ });
143
+ }
144
+ // ------------------------------------
145
+ else {
146
+ res.sendFile(liascriptPath + '/index.html');
147
+ }
148
+ });
149
+ // load everything from the liascript folder
150
+ app.get('/liascript/*', function (req, res) {
151
+ res.sendFile(req.params[0], { root: liascriptPath });
152
+ });
153
+ // ignore this one
154
+ app.get('/sw.js', function (req, res) { });
155
+ app.get('/favicon.ico', function (req, res) { });
156
+ // pass the reloader, to be used for live updates
157
+ app.get('/reloader/reloader.js', function (req, res) {
158
+ res.sendFile(reloadPath);
159
+ });
160
+ // everything else comes from the current project folder
161
+ app.get('/*', cors(), function (req, res) {
162
+ res.sendFile(req.originalUrl, { root: project.path });
163
+ });
164
+ var localURL = 'http://' + hostname + ':' + port;
165
+ if (project.path && project.readme) {
166
+ localURL +=
167
+ '/liascript/index.html?http://' +
168
+ hostname +
169
+ ':' +
170
+ port +
171
+ '/' +
172
+ project.readme;
173
+ }
174
+ if (testOnline && project.readme) {
175
+ localURL =
176
+ 'https://LiaScript.github.io/course/?http://' +
177
+ hostname +
178
+ ':' +
179
+ port +
180
+ '/' +
181
+ project.readme;
182
+ }
183
+ var server = require('reloadsh.js')(app, liveReload ? [path.join(project.path, project.readme || '')] : []);
184
+ if (liveReload) {
185
+ console.log("\u2728 watching for changes on: \"".concat(path.join(project.path || '', project.readme || ''), "\""));
186
+ }
187
+ server.on('error', function (e) {
188
+ throw e;
189
+ });
190
+ server.listen(port);
191
+ if (openInBrowser) {
192
+ open(localURL);
193
+ }
194
+ console.log('📡 starting server');
195
+ console.log(" - local: ".concat(localURL));
196
+ console.log(" - on your network: ".concat(localURL.replace(hostname, ip.address())));
197
+ serverPointer = server;
198
+ }
199
+ exports.start = start;
200
+ function stop() {
201
+ if (serverPointer) {
202
+ serverPointer.close();
203
+ }
204
+ }
205
+ exports.stop = stop;
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@liascript/devserver",
3
- "version": "1.0.11--0.10.8",
3
+ "version": "1.0.12--0.10.8",
4
4
  "description": "Run a development server for LiaScript locally",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
- "build": "npx parcel build src/index.ts && npm run shebang",
7
+ "build": "npx parcel build src/index.ts && npm run shebang && npm run lib",
8
+ "lib": "tsc --module commonjs src/lib.ts --outDir dist",
8
9
  "shebang": "sed -i '1i #!/usr/bin/env node\\n' dist/index.js && chmod +x dist/index.js",
9
10
  "test": "echo \"Error: no test specified\" && exit 1"
10
11
  },
package/views/main.hbs CHANGED
@@ -7,7 +7,7 @@
7
7
  | |___| | (_| |___) | (__| | | | |_) | |_
8
8
  |_____|_|\__,_|____/ \___|_| |_| .__/ \__|
9
9
  |_|
10
- [ DevServer: 1.0.11--0.10.8 ]
10
+ [ DevServer: 1.0.12--0.10.8 ]
11
11
  </pre>
12
12
  </code>
13
13
  </h4>
package/src/index.ts DELETED
@@ -1,62 +0,0 @@
1
- const argv = require('minimist')(process.argv.slice(2))
2
-
3
- import * as server from './lib'
4
-
5
- function liascript() {
6
- console.log(' _ _ ____ _ _')
7
- console.log('| | (_) __ _/ ___| ___ _ __(_)_ __ | |_')
8
- console.log("| | | |/ _` \\___ \\ / __| '__| | '_ \\| __|")
9
- console.log('| |___| | (_| |___) | (__| | | | |_) | |_ ')
10
- console.log('|_____|_|\\__,_|____/ \\___|_| |_| .__/ \\__|')
11
- console.log(' |_|')
12
- console.log()
13
- }
14
-
15
- if (argv.v || argv.version) {
16
- console.log('DevServer: 1.0.11')
17
- console.log('LiaScript: 0.10.8')
18
- process.exit()
19
- }
20
-
21
- if (argv.h || argv.help) {
22
- liascript()
23
-
24
- console.log('-h --help show this help')
25
- console.log('-v --version show version information')
26
- console.log('-i --input input README.md file or folder (default: .)')
27
- console.log('-n --hostname hostname of your server (default: localhost)')
28
- console.log('-p --port used port number (default: 3000)')
29
- console.log('-l --live do live reload on file change')
30
- console.log('-o --open open in default browser')
31
- console.log('-t --test test online on https://LiaScript.github.io')
32
- console.log()
33
- console.log('-r --responsiveVoice add optional responsiveVoice support,')
34
- console.log(' or pass your own responsiveVoice key.')
35
- console.log(' Adding this feature might slow down')
36
- console.log(' the reloading speed.')
37
- console.log(' For more information visit:')
38
- console.log(' https://responsivevoice.org')
39
-
40
- process.exit()
41
- }
42
-
43
- liascript()
44
-
45
- server.init(argv.node_modules)
46
-
47
- try {
48
- server.start(
49
- argv.p || argv.port,
50
- argv.n || argv.hostname,
51
- argv.i || argv.input,
52
- argv.r || argv.responsiveVoice || process.env.RESPONSIVE_VOICE_KEY,
53
- argv.l || argv.live,
54
- argv.o || argv.open,
55
- argv.t || argv.test
56
- )
57
- } catch (e) {
58
- console.error('Error: ', e.message)
59
- process.exit()
60
- }
61
-
62
- console.log('✨ hit Ctrl-c to close the server')
package/src/lib.ts DELETED
@@ -1,318 +0,0 @@
1
- require('dotenv').config()
2
- import * as express from 'express'
3
-
4
- import * as fs from 'fs'
5
- import * as path from 'path'
6
-
7
- const cors = require('cors')
8
- const handlebars = require('express-handlebars')
9
- const ip = require('ip')
10
- const open = require('open')
11
-
12
- const app: express.Application = express()
13
-
14
- var dirname = ''
15
- var node_modules
16
- var reloadPath = ''
17
- var liascriptPath = ''
18
-
19
- var serverPointer: any
20
-
21
- init(__dirname)
22
-
23
- export function init(serverPath?: string, nodeModulesPath?: string) {
24
- dirname = serverPath || path.join(__dirname, '..')
25
-
26
- node_modules = nodeModulesPath || path.join(dirname, 'node_modules')
27
-
28
- reloadPath = path.resolve(
29
- path.join(node_modules, 'reloadsh.js/reloader.browser.js')
30
- )
31
-
32
- liascriptPath = path.resolve(
33
- path.join(node_modules, '@liascript/editor/dist')
34
- )
35
- }
36
-
37
- export function start(
38
- port?: number,
39
- hostname?: string,
40
- input?: string,
41
- responsiveVoice?: string,
42
- liveReload?: boolean,
43
- openInBrowser?: boolean,
44
- testOnline?: boolean
45
- ) {
46
- port = port || 3000
47
- hostname = hostname || 'localhost'
48
- openInBrowser = openInBrowser || false
49
- input = input || '.'
50
- liveReload = liveReload || false
51
- testOnline = testOnline || false
52
-
53
- var project: {
54
- path: string
55
- readme?: string
56
- } = {
57
- path: input,
58
- readme: undefined,
59
- }
60
-
61
- if (input) {
62
- const stats = fs.lstatSync(input)
63
-
64
- // Is it a directory?
65
- if (stats.isDirectory()) {
66
- project.path = input
67
- } else if (stats.isFile()) {
68
- project.path = path.dirname(input)
69
- project.readme = path.basename(input)
70
- }
71
- }
72
-
73
- app.set('view engine', 'hbs')
74
- app.engine(
75
- 'hbs',
76
- handlebars({
77
- layoutsDir: path.resolve(path.join(dirname, 'views/layouts')),
78
- defaultLayout: 'main',
79
- extname: 'hbs',
80
- })
81
- )
82
- app.set('views', path.resolve(path.join(dirname, 'views')))
83
-
84
- app.get('/', function (req: express.Request, res: express.Response) {
85
- res.redirect('/home')
86
- })
87
-
88
- app.get('/home*', function (req: express.Request, res: express.Response) {
89
- const currentPath = project.path + '/' + req.params[0]
90
-
91
- const stats = fs.lstatSync(currentPath)
92
-
93
- // Is it a directory?
94
- if (stats.isDirectory()) {
95
- const files = fs.readdirSync(currentPath).filter((e: string) => {
96
- return e[0] !== '.'
97
- })
98
-
99
- let basePath = '/home'
100
- let pathNames = req.params[0].split('/').filter((e: string) => {
101
- return e !== ''
102
- })
103
-
104
- let paths: { name: string; href: string }[] = []
105
- for (let i = 0; i < pathNames.length; i++) {
106
- basePath += '/' + pathNames[i]
107
- paths.push({ name: pathNames[i], href: basePath })
108
- }
109
-
110
- res.render('main', {
111
- layout: 'index',
112
- path: paths,
113
- file: files
114
- .map((file: string) => {
115
- return {
116
- name: file,
117
- href: `http://${hostname}:${port}/home${req.params[0]}/${file}`,
118
- isDirectory: fs.lstatSync(currentPath + '/' + file).isDirectory(),
119
- }
120
- })
121
- .sort(
122
- (
123
- a: {
124
- name: string
125
- href: string
126
- isDirectory: boolean
127
- },
128
- b: {
129
- name: string
130
- href: string
131
- isDirectory: boolean
132
- }
133
- ) => {
134
- if (a.isDirectory && !b.isDirectory) {
135
- return -1
136
- } else if (!a.isDirectory && b.isDirectory) {
137
- return 1
138
- } else {
139
- if (a.name.toLocaleLowerCase() < b.name.toLocaleLowerCase()) {
140
- return -1
141
- } else {
142
- return 1
143
- }
144
- }
145
- return 0
146
- }
147
- ),
148
- })
149
- } else if (stats.isFile()) {
150
- if (req.params[0].toLocaleLowerCase().endsWith('.md')) {
151
- if (testOnline) {
152
- res.redirect(
153
- `https://LiaScript.github.io/course/?http://${hostname}:${port}/${req.params[0]}`
154
- )
155
- } else {
156
- res.redirect(
157
- `/liascript/index.html?http://${hostname}:${port}/${req.params[0]}`
158
- )
159
- }
160
- } else {
161
- res.sendFile(req.params[0], { root: project.path })
162
- }
163
- } else {
164
- res.send('ups, something went wrong')
165
- }
166
- })
167
-
168
- app.get(
169
- '/liascript/',
170
- function (req: express.Request, res: express.Response) {
171
- res.redirect('/liascript/index.html')
172
- }
173
- )
174
-
175
- app.get(
176
- '/liascript/index.html',
177
- function (req: express.Request, res: express.Response) {
178
- // ------------------------------------
179
- if (liveReload && responsiveVoice) {
180
- fs.readFile(
181
- liascriptPath + '/index.html',
182
- 'utf8',
183
- function (err: any, data: string) {
184
- res.send(
185
- data.replace(
186
- '</head>',
187
- `<script type='text/javascript' src='/reloader/reloader.js'></script>
188
- <script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script>
189
- </head>`
190
- )
191
- )
192
- }
193
- )
194
- }
195
- // ------------------------------------
196
- else if (liveReload) {
197
- fs.readFile(
198
- liascriptPath + '/index.html',
199
- 'utf8',
200
- function (err: any, data: string) {
201
- res.send(
202
- data.replace(
203
- '</head>',
204
- `<script type='text/javascript' src='/reloader/reloader.js'></script></head>`
205
- )
206
- )
207
- }
208
- )
209
- }
210
- // ------------------------------------
211
- else if (responsiveVoice) {
212
- fs.readFile(
213
- liascriptPath + '/index.html',
214
- 'utf8',
215
- function (err: any, data: string) {
216
- res.send(
217
- data.replace(
218
- '</head>',
219
- `<script type='text/javascript' src='https://code.responsivevoice.org/responsivevoice.js?key=${responsiveVoice}'></script></head>`
220
- )
221
- )
222
- }
223
- )
224
- }
225
- // ------------------------------------
226
- else {
227
- res.sendFile(liascriptPath + '/index.html')
228
- }
229
- }
230
- )
231
-
232
- // load everything from the liascript folder
233
- app.get(
234
- '/liascript/*',
235
- function (req: express.Request, res: express.Response) {
236
- res.sendFile(req.params[0], { root: liascriptPath })
237
- }
238
- )
239
- // ignore this one
240
- app.get('/sw.js', function (req: express.Request, res: express.Response) {})
241
- app.get(
242
- '/favicon.ico',
243
- function (req: express.Request, res: express.Response) {}
244
- )
245
-
246
- // pass the reloader, to be used for live updates
247
- app.get(
248
- '/reloader/reloader.js',
249
- function (req: express.Request, res: express.Response) {
250
- res.sendFile(reloadPath)
251
- }
252
- )
253
-
254
- // everything else comes from the current project folder
255
- app.get('/*', cors(), function (req: express.Request, res: express.Response) {
256
- res.sendFile(req.originalUrl, { root: project.path })
257
- })
258
-
259
- let localURL = 'http://' + hostname + ':' + port
260
-
261
- if (project.path && project.readme) {
262
- localURL +=
263
- '/liascript/index.html?http://' +
264
- hostname +
265
- ':' +
266
- port +
267
- '/' +
268
- project.readme
269
- }
270
-
271
- if (testOnline && project.readme) {
272
- localURL =
273
- 'https://LiaScript.github.io/course/?http://' +
274
- hostname +
275
- ':' +
276
- port +
277
- '/' +
278
- project.readme
279
- }
280
-
281
- const server = require('reloadsh.js')(
282
- app,
283
- liveReload ? [path.join(project.path, project.readme || '')] : []
284
- )
285
-
286
- if (liveReload) {
287
- console.log(
288
- `✨ watching for changes on: "${path.join(
289
- project.path || '',
290
- project.readme || ''
291
- )}"`
292
- )
293
- }
294
-
295
- server.on('error', (e: any) => {
296
- throw e
297
- })
298
-
299
- server.listen(port)
300
-
301
- if (openInBrowser) {
302
- open(localURL)
303
- }
304
-
305
- console.log('📡 starting server')
306
- console.log(` - local: ${localURL}`)
307
- console.log(
308
- ` - on your network: ${localURL.replace(hostname, ip.address())}`
309
- )
310
-
311
- serverPointer = server
312
- }
313
-
314
- export function stop() {
315
- if (serverPointer) {
316
- serverPointer.close()
317
- }
318
- }