@yongdall/live-server 0.5.4 → 0.6.1

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.
@@ -4,14 +4,23 @@ import root from "@yongdall/root";
4
4
  import { middleware } from "#index";
5
5
 
6
6
  //#region cli/live-server/cli/live-server.mjs
7
- /** @import { IncomingMessage, ServerResponse } from 'node:http' */
8
7
  /** @import { Cli } from '@yongdall/cli-parse' */
9
8
  /**
10
9
  *
10
+ * @param {boolean} development
11
+ */
12
+ async function createHttp(development) {
13
+ const { default: init } = await import("@yongdall/init");
14
+ const { default: createCallback } = await import("@yongdall/http/callback");
15
+ await init({ development });
16
+ return await createCallback({ development });
17
+ }
18
+ /**
19
+ *
11
20
  * @param {Cli.Env} env
12
21
  */
13
22
  async function live_server_default({ development, options, parameters }) {
14
- let server = `http://127.0.0.1:8888`;
23
+ let server = ``;
15
24
  let port = 0;
16
25
  for (const s of options.server || []) {
17
26
  if (!s) continue;
@@ -43,13 +52,14 @@ async function live_server_default({ development, options, parameters }) {
43
52
  break;
44
53
  }
45
54
  }
55
+ const open = Boolean(options.open?.length);
46
56
  liveServer.start({
47
57
  host: process.env.IP,
48
58
  port,
49
- open: true,
59
+ open,
50
60
  mount: [["/assets", path.resolve(root, "assets")], ["/", path.resolve(root, "public")]],
51
- proxy: ["/api/", "/fileCabinets/"].map((path) => [path, `${server}${path}`]),
52
- middleware: [middleware()],
61
+ proxy: server ? [["/api/", `${server}/api/`]] : [],
62
+ middleware: server ? [middleware()] : [await createHttp(development), middleware()],
53
63
  logLevel: 2,
54
64
  file: "assets/index.html"
55
65
  });
@@ -1 +1 @@
1
- {"version":3,"file":"live-server.mjs","names":[],"sources":["../../../cli/live-server/cli/live-server.mjs"],"sourcesContent":["/** @import { IncomingMessage, ServerResponse } from 'node:http' */\n/** @import { Cli } from '@yongdall/cli-parse' */\nimport * as path from 'node:path';\n// @ts-ignore\nimport liveServer from 'live-server';\nimport root from '@yongdall/root';\nimport {middleware} from '#index';\n\n\n\n/**\n * \n * @param {Cli.Env} env \n */\nexport default async function ({ development, options, parameters }) {\n\tlet server = `http://127.0.0.1:8888`;\n\tlet port = 0;\n\tfor (const s of options.server || []) {\n\t\tif (!s) { continue; }\n\t\tlet port = 0;\n\t\tif (/^\\d(_?\\d)*$/.test(s)) {\n\t\t\tport = parseInt(s.replace(/_/g, ''));\n\t\t} else if (/^0x[a-f\\d](_?[a-f\\d]+)$/i.test(s)) {\n\t\t\tport = parseInt(s.replace(/_/g, '').slice(2), 16);\n\t\t}\n\t\tif (port > 0 && port <= 0xffff) {\n\t\t\tserver = `http://127.0.0.1:${port}`;\n\t\t\tbreak;\n\t\t}\n\t\tif (/^(\\[[:.a-f\\d]+\\]|[\\.a-z\\d-]+)(:\\d+)?$/i.test(s)) {\n\t\t\tserver = `http://${s}`;\n\t\t\tbreak;\n\t\t}\n\t\ttry {\n\t\t\tconst url = new URL(s);\n\t\t\tif (!['http:', 'https:'].includes(url.protocol.toLowerCase())) { continue; }\n\t\t\tserver = url.origin;\n\t\t\tbreak;\n\t\t} catch {}\n\t}\n\tfor (const s of options.port || []) {\n\t\tif (!s) { continue; }\n\t\tlet v = 0;\n\t\tif (/^\\d(_?\\d)*$/.test(s)) {\n\t\t\tv = parseInt(s.replace(/_/g, ''));\n\t\t} else if (/^0x[a-f\\d](_?[a-f\\d]+)$/i.test(s)) {\n\t\t\tv = parseInt(s.replace(/_/g, '').slice(2), 16);\n\t\t}\n\t\tif (v > 0 && v <= 0xffff) {\n\t\t\tport = v;\n\t\t\tbreak;\n\t\t}\n\t}\n\tliveServer.start({\n\t\thost: process.env.IP,\n\t\tport,\n\t\topen: true,\n\t\tmount: [['/assets', path.resolve(root, 'assets')], ['/', path.resolve(root, 'public')]],\n\t\t// @ts-ignore\n\t\tproxy: ['/api/', '/fileCabinets/'].map(path => [path, `${server}${path}`]),\n\t\tmiddleware: [middleware()],\n\t\tlogLevel: 2,\n\t\tfile: 'assets/index.html',\n\t});\n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AS,OAAO,CAAC;EAC1E,YAAY,CAAC,YAAY,CAAC;EAC1B,UAAU;EACV,MAAM;EACN,CAAC"}
1
+ {"version":3,"file":"live-server.mjs","names":[],"sources":["../../../cli/live-server/cli/live-server.mjs"],"sourcesContent":["/** @import { Cli } from '@yongdall/cli-parse' */\nimport * as path from 'node:path';\n// @ts-ignore\nimport liveServer from 'live-server';\nimport root from '@yongdall/root';\nimport {middleware} from '#index';\n\n\n/**\n * \n * @param {boolean} development \n */\nasync function createHttp(development) {\n\tconst { default: init } = await import('@yongdall/init');\n\tconst { default: createCallback } = await import('@yongdall/http/callback');\n\tawait init({ development });\n\treturn await createCallback({ development });\n}\n\n\n/**\n * \n * @param {Cli.Env} env \n */\nexport default async function ({ development, options, parameters }) {\n\tlet server = ``;\n\tlet port = 0;\n\tfor (const s of options.server || []) {\n\t\tif (!s) { continue; }\n\t\tlet port = 0;\n\t\tif (/^\\d(_?\\d)*$/.test(s)) {\n\t\t\tport = parseInt(s.replace(/_/g, ''));\n\t\t} else if (/^0x[a-f\\d](_?[a-f\\d]+)$/i.test(s)) {\n\t\t\tport = parseInt(s.replace(/_/g, '').slice(2), 16);\n\t\t}\n\t\tif (port > 0 && port <= 0xffff) {\n\t\t\tserver = `http://127.0.0.1:${port}`;\n\t\t\tbreak;\n\t\t}\n\t\tif (/^(\\[[:.a-f\\d]+\\]|[\\.a-z\\d-]+)(:\\d+)?$/i.test(s)) {\n\t\t\tserver = `http://${s}`;\n\t\t\tbreak;\n\t\t}\n\t\ttry {\n\t\t\tconst url = new URL(s);\n\t\t\tif (!['http:', 'https:'].includes(url.protocol.toLowerCase())) { continue; }\n\t\t\tserver = url.origin;\n\t\t\tbreak;\n\t\t} catch {}\n\t}\n\tfor (const s of options.port || []) {\n\t\tif (!s) { continue; }\n\t\tlet v = 0;\n\t\tif (/^\\d(_?\\d)*$/.test(s)) {\n\t\t\tv = parseInt(s.replace(/_/g, ''));\n\t\t} else if (/^0x[a-f\\d](_?[a-f\\d]+)$/i.test(s)) {\n\t\t\tv = parseInt(s.replace(/_/g, '').slice(2), 16);\n\t\t}\n\t\tif (v > 0 && v <= 0xffff) {\n\t\t\tport = v;\n\t\t\tbreak;\n\t\t}\n\t}\n\tconst open = Boolean(options.open?.length);\n\tliveServer.start({\n\t\thost: process.env.IP,\n\t\tport,\n\t\topen,\n\t\tmount: [['/assets', path.resolve(root, 'assets')], ['/', path.resolve(root, 'public')]],\n\t\t// @ts-ignore\n\t\tproxy: server ? [['/api/', `${server}/api/`]] : [],\n\t\tmiddleware: server ? [middleware()] : [await createHttp(development), middleware()],\n\t\tlogLevel: 2,\n\t\tfile: 'assets/index.html',\n\t});\n\n}\n"],"mappings":";;;;;;;;;;;AAYA,eAAe,WAAW,aAAa;CACtC,MAAM,EAAE,SAAS,SAAS,MAAM,OAAO;CACvC,MAAM,EAAE,SAAS,mBAAmB,MAAM,OAAO;AACjD,OAAM,KAAK,EAAE,aAAa,CAAC;AAC3B,QAAO,MAAM,eAAe,EAAE,aAAa,CAAC;;;;;;AAQ7C,mCAA+B,EAAE,aAAa,SAAS,cAAc;CACpE,IAAI,SAAS;CACb,IAAI,OAAO;AACX,MAAK,MAAM,KAAK,QAAQ,UAAU,EAAE,EAAE;AACrC,MAAI,CAAC,EAAK;EACV,IAAI,OAAO;AACX,MAAI,cAAc,KAAK,EAAE,CACxB,QAAO,SAAS,EAAE,QAAQ,MAAM,GAAG,CAAC;WAC1B,2BAA2B,KAAK,EAAE,CAC5C,QAAO,SAAS,EAAE,QAAQ,MAAM,GAAG,CAAC,MAAM,EAAE,EAAE,GAAG;AAElD,MAAI,OAAO,KAAK,QAAQ,OAAQ;AAC/B,YAAS,oBAAoB;AAC7B;;AAED,MAAI,yCAAyC,KAAK,EAAE,EAAE;AACrD,YAAS,UAAU;AACnB;;AAED,MAAI;GACH,MAAM,MAAM,IAAI,IAAI,EAAE;AACtB,OAAI,CAAC,CAAC,SAAS,SAAS,CAAC,SAAS,IAAI,SAAS,aAAa,CAAC,CAAI;AACjE,YAAS,IAAI;AACb;UACO;;AAET,MAAK,MAAM,KAAK,QAAQ,QAAQ,EAAE,EAAE;AACnC,MAAI,CAAC,EAAK;EACV,IAAI,IAAI;AACR,MAAI,cAAc,KAAK,EAAE,CACxB,KAAI,SAAS,EAAE,QAAQ,MAAM,GAAG,CAAC;WACvB,2BAA2B,KAAK,EAAE,CAC5C,KAAI,SAAS,EAAE,QAAQ,MAAM,GAAG,CAAC,MAAM,EAAE,EAAE,GAAG;AAE/C,MAAI,IAAI,KAAK,KAAK,OAAQ;AACzB,UAAO;AACP;;;CAGF,MAAM,OAAO,QAAQ,QAAQ,MAAM,OAAO;AAC1C,YAAW,MAAM;EAChB,MAAM,QAAQ,IAAI;EAClB;EACA;EACA,OAAO,CAAC,CAAC,WAAW,KAAK,QAAQ,MAAM,SAAS,CAAC,EAAE,CAAC,KAAK,KAAK,QAAQ,MAAM,SAAS,CAAC,CAAC;EAEvF,OAAO,SAAS,CAAC,CAAC,SAAS,GAAG,OAAO,OAAO,CAAC,GAAG,EAAE;EAClD,YAAY,SAAS,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,WAAW,YAAY,EAAE,YAAY,CAAC;EACnF,UAAU;EACV,MAAM;EACN,CAAC"}
package/package.json CHANGED
@@ -1,19 +1,21 @@
1
1
  {
2
2
  "name": "@yongdall/live-server",
3
- "version": "0.5.4",
3
+ "version": "0.6.1",
4
4
  "type": "module",
5
5
  "main": "./index.mjs",
6
6
  "imports": {
7
7
  "#index": "./index.mjs"
8
8
  },
9
9
  "dependencies": {
10
- "@yongdall/root": "^0.5.0",
10
+ "@yongdall/http": "^0.6.1",
11
+ "@yongdall/init": "^0.6.1",
12
+ "@yongdall/root": "^0.6.1",
11
13
  "amaro": "^1.1.8",
12
14
  "live-server": "^1.2.2"
13
15
  },
14
16
  "devDependencies": {
15
17
  "@types/live-server": "^1.2.3",
16
- "@yongdall/cli-parse": "^0.5.0"
18
+ "@yongdall/cli-parse": "^0.6.1"
17
19
  },
18
20
  "exports": {
19
21
  ".": "./index.mjs"