@deot/dev-dever 2.0.1 → 2.1.0

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/dist/index.cjs.js CHANGED
@@ -36,6 +36,7 @@ let target = {
36
36
  entries: [],
37
37
  html: ""
38
38
  };
39
+ const excludes = ["tpl", "_", "dist", "node_modules", "__tests__"];
39
40
  const walk = (dir) => {
40
41
  const { cwd, workspace } = devShared.Locals.impl();
41
42
  dir = dir || ".";
@@ -47,9 +48,10 @@ const walk = (dir) => {
47
48
  const extname = path__namespace.extname(fullpath);
48
49
  if (stat.isFile() && /\.(t|j)sx?$/.test(extname) && paths.length >= 2 && paths[paths.length - 2] === "examples") {
49
50
  const basename = path__namespace.basename(file, extname);
50
- const name = path__namespace.join(dir, basename);
51
- target.entries.push(name.replace(/\/examples/, ""));
52
- } else if (stat.isDirectory() && !["dist", "node_modules", "__tests__"].includes(file)) {
51
+ let name = path__namespace.join(dir, basename).split("/");
52
+ name.splice(name.length - 2, 1);
53
+ target.entries.push(name.join("/"));
54
+ } else if (stat.isDirectory() && !excludes.includes(file)) {
53
55
  const subdir = path__namespace.join(dir, file);
54
56
  walk(subdir);
55
57
  }
@@ -100,7 +102,11 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
100
102
  }));
101
103
  if (!entries.length)
102
104
  return devShared.Shell.spawn(`echo no entry file found!`);
103
- let options$ = {};
105
+ let options$ = {
106
+ server: {
107
+ host: true
108
+ }
109
+ };
104
110
  if (fs$1.existsSync(`${cwd}/z.dev.config.ts`)) {
105
111
  options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./z.dev.config.ts"));
106
112
  } else if (fs$1.existsSync(`${cwd}/dev.config.ts`)) {
@@ -110,9 +116,9 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
110
116
  }
111
117
  const server = await vite.createServer(options$);
112
118
  const $server = await server.listen();
113
- const $port = $server.config.server.port;
114
- const $host = $server.config.server.host || "0.0.0.0";
115
- entries.forEach((item) => devShared.Logger.log(` > ${item}: ${chalk.cyan(`http://${$host}:${$port}/${item}.html`)}`));
119
+ const { local = [], network = [] } = $server.resolvedUrls || {};
120
+ const url = network[0] || local[0] || `http://localhost:${$server.config.server.port}`;
121
+ entries.forEach((item) => devShared.Logger.log(` > ${item}: ${chalk.cyan(`${url}${item}.html`)}`));
116
122
  });
117
123
 
118
124
  exports.run = run;
package/dist/index.es.js CHANGED
@@ -12,6 +12,7 @@ let target = {
12
12
  entries: [],
13
13
  html: ""
14
14
  };
15
+ const excludes = ["tpl", "_", "dist", "node_modules", "__tests__"];
15
16
  const walk = (dir) => {
16
17
  const { cwd, workspace } = Locals.impl();
17
18
  dir = dir || ".";
@@ -23,9 +24,10 @@ const walk = (dir) => {
23
24
  const extname = path.extname(fullpath);
24
25
  if (stat.isFile() && /\.(t|j)sx?$/.test(extname) && paths.length >= 2 && paths[paths.length - 2] === "examples") {
25
26
  const basename = path.basename(file, extname);
26
- const name = path.join(dir, basename);
27
- target.entries.push(name.replace(/\/examples/, ""));
28
- } else if (stat.isDirectory() && !["dist", "node_modules", "__tests__"].includes(file)) {
27
+ let name = path.join(dir, basename).split("/");
28
+ name.splice(name.length - 2, 1);
29
+ target.entries.push(name.join("/"));
30
+ } else if (stat.isDirectory() && !excludes.includes(file)) {
29
31
  const subdir = path.join(dir, file);
30
32
  walk(subdir);
31
33
  }
@@ -76,7 +78,11 @@ const run = (options) => Utils.autoCatch(async () => {
76
78
  }));
77
79
  if (!entries.length)
78
80
  return Shell.spawn(`echo no entry file found!`);
79
- let options$ = {};
81
+ let options$ = {
82
+ server: {
83
+ host: true
84
+ }
85
+ };
80
86
  if (fs$1.existsSync(`${cwd}/z.dev.config.ts`)) {
81
87
  options$.configFile = path.relative(cwd, path.resolve(cwd, "./z.dev.config.ts"));
82
88
  } else if (fs$1.existsSync(`${cwd}/dev.config.ts`)) {
@@ -86,9 +92,9 @@ const run = (options) => Utils.autoCatch(async () => {
86
92
  }
87
93
  const server = await createServer(options$);
88
94
  const $server = await server.listen();
89
- const $port = $server.config.server.port;
90
- const $host = $server.config.server.host || "0.0.0.0";
91
- entries.forEach((item) => Logger.log(` > ${item}: ${chalk.cyan(`http://${$host}:${$port}/${item}.html`)}`));
95
+ const { local = [], network = [] } = $server.resolvedUrls || {};
96
+ const url = network[0] || local[0] || `http://localhost:${$server.config.server.port}`;
97
+ entries.forEach((item) => Logger.log(` > ${item}: ${chalk.cyan(`${url}${item}.html`)}`));
92
98
  });
93
99
 
94
100
  export { run };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/dev-dever",
3
- "version": "2.0.1",
3
+ "version": "2.1.0",
4
4
  "main": "dist/index.es.js",
5
5
  "module": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -15,9 +15,9 @@
15
15
  "access": "public"
16
16
  },
17
17
  "dependencies": {
18
- "@deot/dev-shared": "^2.0.0",
18
+ "@deot/dev-shared": "^2.1.0",
19
19
  "ejs": "^3.1.9",
20
- "vite": "^4.3.9"
20
+ "vite": "^4.4.1"
21
21
  },
22
22
  "devDependencies": {
23
23
  "cross-env": "^7.0.3"
package/shared.config.ts CHANGED
@@ -15,29 +15,34 @@ const replacement = (name: string) => path.resolve(cwd, `./packages/${name}/src`
15
15
  const { name } = createRequire(cwd)(path.resolve(cwd, workspace ? `${workspace}/index` : '', 'package.json'));
16
16
 
17
17
  const getHtmlContent = async (url: string) => {
18
- let fullpath = path.join(cwd, url);
18
+ let fullpath = path.join(cwd, workspace, url);
19
+
19
20
  if (
20
- /^\/?@vite/.test(url)
21
- || (
22
- fs.existsSync(fullpath)
23
- && fs.statSync(fullpath).isFile()
24
- )
21
+ /^\/?@vite/.test(url)
22
+ || (fs.existsSync(fullpath) && fs.statSync(fullpath).isFile())
25
23
  ) {
26
24
  return;
27
25
  }
28
26
 
29
27
  if (url === '/') return html;
30
28
 
31
- const [packageFolderName, htmlEntry] = url.split('/').filter(i => !!i);
29
+ const info = url.split('/').filter(i => !!i);
30
+
31
+ const prefix = info.slice(0, -1);
32
+ const entry = info.slice(-1)[0];
33
+
34
+ if (prefix[prefix.length - 1] !== 'examples') {
35
+ prefix.push('examples');
36
+ }
32
37
 
33
38
  fullpath = path.join(
34
39
  cwd,
35
40
  workspace,
36
- packageFolderName,
37
- 'examples',
38
- `${htmlEntry?.replace(/(\.html)/g, '')}.ts`
41
+ prefix.join('/'),
42
+ `${entry?.replace(/(\.html)$/, '.ts')}`
39
43
  );
40
- if (!fs.existsSync(fullpath)) return html;
44
+
45
+ if (!fs.existsSync(fullpath)) return /\.[\s\S]+$/.test(entry) ? undefined : html;
41
46
 
42
47
  let contents = '';
43
48
  contents += `<!DOCTYPE html>\n`;