@deot/dev-dever 1.1.1 → 2.0.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/README.md +35 -2
- package/dist/index.cjs.js +111 -29
- package/dist/index.es.js +89 -29
- package/index.ejs +391 -0
- package/package.json +7 -3
- package/shared.config.ts +96 -0
package/README.md
CHANGED
|
@@ -1,5 +1,38 @@
|
|
|
1
1
|
# @deot/dev-dever
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
开发
|
|
4
4
|
|
|
5
|
-
-
|
|
5
|
+
- 优先执行`scripts`下的`dev`
|
|
6
|
+
|
|
7
|
+
## 自定义配置
|
|
8
|
+
|
|
9
|
+
提供环境变量`DEV_OPTIONS`
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
interface DEV_OPTIONS {
|
|
13
|
+
packageFolderName?: string;
|
|
14
|
+
workspace?: string;
|
|
15
|
+
entries: string[];
|
|
16
|
+
html: string;
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
根目录创建`dev.config.ts`, 可以选择`configShared`合并或单独基于`DEV_OPTIONS`配置
|
|
21
|
+
> 也可以是`z.dev.config.ts`, 前缀主要是置底
|
|
22
|
+
|
|
23
|
+
```ts
|
|
24
|
+
import { mergeConfig, defineConfig } from 'vite';
|
|
25
|
+
import configShared from '@deot/dever/shared.config';
|
|
26
|
+
|
|
27
|
+
export default mergeConfig(
|
|
28
|
+
configShared,
|
|
29
|
+
defineConfig({
|
|
30
|
+
plugins: [
|
|
31
|
+
vue(),
|
|
32
|
+
react()
|
|
33
|
+
]
|
|
34
|
+
})
|
|
35
|
+
);
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
取`dev.config.ts`, 是为了方便从`vite`转其他开发工具时,可以不改变文件名
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,36 +1,118 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
5
|
+
const devShared = require('@deot/dev-shared');
|
|
6
|
+
const path = require('node:path');
|
|
7
|
+
const node_url = require('node:url');
|
|
8
|
+
const fs$1 = require('fs-extra');
|
|
9
|
+
const vite = require('vite');
|
|
10
|
+
const chalk = require('chalk');
|
|
11
|
+
const fs = require('node:fs');
|
|
12
|
+
const ejs = require('ejs');
|
|
13
|
+
|
|
14
|
+
function _interopNamespaceDefault(e) {
|
|
15
|
+
const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
|
|
16
|
+
if (e) {
|
|
17
|
+
for (const k in e) {
|
|
18
|
+
if (k !== 'default') {
|
|
19
|
+
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
20
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: () => e[k]
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
n.default = e;
|
|
28
|
+
return Object.freeze(n);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const path__namespace = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
32
|
+
const fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
33
|
+
|
|
34
|
+
const dirname$1 = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs.js', document.baseURI).href))));
|
|
35
|
+
let target = {
|
|
36
|
+
entries: [],
|
|
37
|
+
html: ""
|
|
38
|
+
};
|
|
39
|
+
const walk = (dir) => {
|
|
40
|
+
const { cwd, workspace } = devShared.Locals.impl();
|
|
41
|
+
dir = dir || ".";
|
|
42
|
+
const directory = path__namespace.join(cwd, workspace, dir);
|
|
43
|
+
fs__namespace.readdirSync(directory).forEach((file) => {
|
|
44
|
+
const fullpath = path__namespace.join(directory, file);
|
|
45
|
+
const paths = fullpath.split("/") || [];
|
|
46
|
+
const stat = fs__namespace.statSync(fullpath);
|
|
47
|
+
const extname = path__namespace.extname(fullpath);
|
|
48
|
+
if (stat.isFile() && /\.(t|j)sx?$/.test(extname) && paths.length >= 2 && paths[paths.length - 2] === "examples") {
|
|
49
|
+
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)) {
|
|
53
|
+
const subdir = path__namespace.join(dir, file);
|
|
54
|
+
walk(subdir);
|
|
25
55
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
const get = () => {
|
|
59
|
+
if (target.html)
|
|
60
|
+
return target;
|
|
61
|
+
walk();
|
|
62
|
+
const tpl = fs__namespace.readFileSync(path__namespace.resolve(dirname$1, "../index.ejs"));
|
|
63
|
+
target.html = ejs.render(tpl.toString(), {
|
|
64
|
+
title: "demo",
|
|
65
|
+
base: "/",
|
|
66
|
+
pages: target.entries
|
|
67
|
+
});
|
|
68
|
+
return target;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const dirname = path__namespace.dirname(node_url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (document.currentScript && document.currentScript.src || new URL('index.cjs.js', document.baseURI).href))));
|
|
72
|
+
const run = (options) => devShared.Utils.autoCatch(async () => {
|
|
73
|
+
const locals = devShared.Locals.impl();
|
|
74
|
+
if (typeof options.dryRun === "undefined") {
|
|
75
|
+
options.dryRun = process.env.NODE_ENV === "UNIT";
|
|
76
|
+
}
|
|
77
|
+
if (options.dryRun)
|
|
78
|
+
return devShared.Shell.spawn(`echo development`);
|
|
79
|
+
const { cwd, workspace, packageOptionsMap, packageDirsMap } = locals;
|
|
80
|
+
const { packageName } = options;
|
|
81
|
+
const packageFolderName = devShared.Locals.getPackageFolderName(packageName);
|
|
82
|
+
const packageOptions = packageOptionsMap[packageFolderName];
|
|
83
|
+
const packageDir = packageDirsMap[packageFolderName];
|
|
84
|
+
options.watch = true;
|
|
85
|
+
if (workspace && cwd !== packageDir && packageOptions?.scripts?.["dev"]) {
|
|
86
|
+
await devShared.Shell.spawn(`npm`, ["run", "dev"], { cwd: packageDir });
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (!options.packageFolderName)
|
|
90
|
+
delete options.packageFolderName;
|
|
91
|
+
if (!options.workspace)
|
|
92
|
+
delete options.workspace;
|
|
93
|
+
delete options.packageName;
|
|
94
|
+
let { entries, html } = get();
|
|
95
|
+
process.env.DEV_OPTIONS = encodeURIComponent(JSON.stringify({
|
|
96
|
+
...options,
|
|
97
|
+
workspace,
|
|
98
|
+
entries,
|
|
99
|
+
html
|
|
100
|
+
}));
|
|
101
|
+
if (!entries.length)
|
|
102
|
+
return devShared.Shell.spawn(`echo no entry file found!`);
|
|
103
|
+
let options$ = {};
|
|
104
|
+
if (fs$1.existsSync(`${cwd}/dev.config.ts`)) {
|
|
105
|
+
options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./dev.config.ts"));
|
|
106
|
+
} else if (fs$1.existsSync(`${cwd}/z.dev.config.ts`)) {
|
|
107
|
+
options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./z.dev.config.ts"));
|
|
108
|
+
} else {
|
|
109
|
+
options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(dirname, "../shared.config.ts"));
|
|
110
|
+
}
|
|
111
|
+
const server = await vite.createServer(options$);
|
|
112
|
+
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`)}`));
|
|
34
116
|
});
|
|
35
117
|
|
|
36
118
|
exports.run = run;
|
package/dist/index.es.js
CHANGED
|
@@ -1,34 +1,94 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Locals, Utils, Shell, Logger } from '@deot/dev-shared';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
import fs$1 from 'fs-extra';
|
|
5
|
+
import { createServer } from 'vite';
|
|
6
|
+
import chalk from 'chalk';
|
|
7
|
+
import * as fs from 'node:fs';
|
|
8
|
+
import { render } from 'ejs';
|
|
2
9
|
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
const dirname$1 = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
let target = {
|
|
12
|
+
entries: [],
|
|
13
|
+
html: ""
|
|
14
|
+
};
|
|
15
|
+
const walk = (dir) => {
|
|
16
|
+
const { cwd, workspace } = Locals.impl();
|
|
17
|
+
dir = dir || ".";
|
|
18
|
+
const directory = path.join(cwd, workspace, dir);
|
|
19
|
+
fs.readdirSync(directory).forEach((file) => {
|
|
20
|
+
const fullpath = path.join(directory, file);
|
|
21
|
+
const paths = fullpath.split("/") || [];
|
|
22
|
+
const stat = fs.statSync(fullpath);
|
|
23
|
+
const extname = path.extname(fullpath);
|
|
24
|
+
if (stat.isFile() && /\.(t|j)sx?$/.test(extname) && paths.length >= 2 && paths[paths.length - 2] === "examples") {
|
|
25
|
+
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)) {
|
|
29
|
+
const subdir = path.join(dir, file);
|
|
30
|
+
walk(subdir);
|
|
23
31
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
const get = () => {
|
|
35
|
+
if (target.html)
|
|
36
|
+
return target;
|
|
37
|
+
walk();
|
|
38
|
+
const tpl = fs.readFileSync(path.resolve(dirname$1, "../index.ejs"));
|
|
39
|
+
target.html = render(tpl.toString(), {
|
|
40
|
+
title: "demo",
|
|
41
|
+
base: "/",
|
|
42
|
+
pages: target.entries
|
|
43
|
+
});
|
|
44
|
+
return target;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
48
|
+
const run = (options) => Utils.autoCatch(async () => {
|
|
49
|
+
const locals = Locals.impl();
|
|
50
|
+
if (typeof options.dryRun === "undefined") {
|
|
51
|
+
options.dryRun = process.env.NODE_ENV === "UNIT";
|
|
52
|
+
}
|
|
53
|
+
if (options.dryRun)
|
|
54
|
+
return Shell.spawn(`echo development`);
|
|
55
|
+
const { cwd, workspace, packageOptionsMap, packageDirsMap } = locals;
|
|
56
|
+
const { packageName } = options;
|
|
57
|
+
const packageFolderName = Locals.getPackageFolderName(packageName);
|
|
58
|
+
const packageOptions = packageOptionsMap[packageFolderName];
|
|
59
|
+
const packageDir = packageDirsMap[packageFolderName];
|
|
60
|
+
options.watch = true;
|
|
61
|
+
if (workspace && cwd !== packageDir && packageOptions?.scripts?.["dev"]) {
|
|
62
|
+
await Shell.spawn(`npm`, ["run", "dev"], { cwd: packageDir });
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (!options.packageFolderName)
|
|
66
|
+
delete options.packageFolderName;
|
|
67
|
+
if (!options.workspace)
|
|
68
|
+
delete options.workspace;
|
|
69
|
+
delete options.packageName;
|
|
70
|
+
let { entries, html } = get();
|
|
71
|
+
process.env.DEV_OPTIONS = encodeURIComponent(JSON.stringify({
|
|
72
|
+
...options,
|
|
73
|
+
workspace,
|
|
74
|
+
entries,
|
|
75
|
+
html
|
|
76
|
+
}));
|
|
77
|
+
if (!entries.length)
|
|
78
|
+
return Shell.spawn(`echo no entry file found!`);
|
|
79
|
+
let options$ = {};
|
|
80
|
+
if (fs$1.existsSync(`${cwd}/dev.config.ts`)) {
|
|
81
|
+
options$.configFile = path.relative(cwd, path.resolve(cwd, "./dev.config.ts"));
|
|
82
|
+
} else if (fs$1.existsSync(`${cwd}/z.dev.config.ts`)) {
|
|
83
|
+
options$.configFile = path.relative(cwd, path.resolve(cwd, "./z.dev.config.ts"));
|
|
84
|
+
} else {
|
|
85
|
+
options$.configFile = path.relative(cwd, path.resolve(dirname, "../shared.config.ts"));
|
|
86
|
+
}
|
|
87
|
+
const server = await createServer(options$);
|
|
88
|
+
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`)}`));
|
|
32
92
|
});
|
|
33
93
|
|
|
34
94
|
export { run };
|
package/index.ejs
ADDED
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset='utf-8'>
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
7
|
+
<title><%= title %></title>
|
|
8
|
+
<style>
|
|
9
|
+
* {
|
|
10
|
+
margin: 0;
|
|
11
|
+
padding: 0;
|
|
12
|
+
outline: 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
body {
|
|
16
|
+
padding: 80px 100px;
|
|
17
|
+
font: 13px "Helvetica Neue", "Lucida Grande", "Arial";
|
|
18
|
+
background: #ECE9E9 -webkit-gradient(linear, 0% 0%, 0% 100%, from(#fff), to(#ECE9E9));
|
|
19
|
+
background: #ECE9E9 -moz-linear-gradient(top, #fff, #ECE9E9);
|
|
20
|
+
background-repeat: no-repeat;
|
|
21
|
+
color: #555;
|
|
22
|
+
-webkit-font-smoothing: antialiased;
|
|
23
|
+
}<title><%= title %></title>
|
|
24
|
+
|
|
25
|
+
h1,
|
|
26
|
+
h2,
|
|
27
|
+
h3 {
|
|
28
|
+
font-size: 22px;
|
|
29
|
+
color: #343434;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
h1 em,
|
|
33
|
+
h2 em {
|
|
34
|
+
padding: 0 5px;
|
|
35
|
+
font-weight: normal;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
h1 {
|
|
39
|
+
font-size: 60px;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
h2 {
|
|
43
|
+
margin-top: 10px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
h3 {
|
|
47
|
+
margin: 5px 0 10px 0;
|
|
48
|
+
padding-bottom: 5px;
|
|
49
|
+
border-bottom: 1px solid #eee;
|
|
50
|
+
font-size: 18px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
ul li {
|
|
54
|
+
list-style: none;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
ul li:hover {
|
|
58
|
+
cursor: pointer;
|
|
59
|
+
color: #2e2e2e;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
ul li .path {
|
|
63
|
+
padding-left: 5px;
|
|
64
|
+
font-weight: bold;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
ul li .line {
|
|
68
|
+
padding-right: 5px;
|
|
69
|
+
font-style: italic;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
ul li:first-child .path {
|
|
73
|
+
padding-left: 0;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
p {
|
|
77
|
+
line-height: 1.5;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
a {
|
|
81
|
+
color: #555;
|
|
82
|
+
text-decoration: none;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
a:hover {
|
|
86
|
+
color: #303030;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#stacktrace {
|
|
90
|
+
margin-top: 15px;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.directory h1 {
|
|
94
|
+
margin-bottom: 15px;
|
|
95
|
+
font-size: 18px;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
ul#files {
|
|
99
|
+
width: 100%;
|
|
100
|
+
height: 100%;
|
|
101
|
+
overflow: hidden;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
ul#files li {
|
|
105
|
+
float: left;
|
|
106
|
+
width: 30%;
|
|
107
|
+
line-height: 25px;
|
|
108
|
+
margin: 1px;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
ul#files li a {
|
|
112
|
+
display: block;
|
|
113
|
+
height: 25px;
|
|
114
|
+
border: 1px solid transparent;
|
|
115
|
+
-webkit-border-radius: 5px;
|
|
116
|
+
-moz-border-radius: 5px;
|
|
117
|
+
border-radius: 5px;
|
|
118
|
+
overflow: hidden;
|
|
119
|
+
white-space: nowrap;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
ul#files li a:focus,
|
|
123
|
+
ul#files li a:hover {
|
|
124
|
+
background: rgba(255, 255, 255, 0.65);
|
|
125
|
+
border: 1px solid #ececec;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
ul#files li a.highlight {
|
|
129
|
+
-webkit-transition: background .4s ease-in-out;
|
|
130
|
+
background: #ffff4f;
|
|
131
|
+
border-color: #E9DC51;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#search {
|
|
135
|
+
display: block;
|
|
136
|
+
position: fixed;
|
|
137
|
+
top: 20px;
|
|
138
|
+
right: 20px;
|
|
139
|
+
width: 90px;
|
|
140
|
+
-webkit-transition: width ease 0.2s, opacity ease 0.4s;
|
|
141
|
+
-moz-transition: width ease 0.2s, opacity ease 0.4s;
|
|
142
|
+
-webkit-border-radius: 32px;
|
|
143
|
+
-moz-border-radius: 32px;
|
|
144
|
+
-webkit-box-shadow: inset 0px 0px 3px rgba(0, 0, 0, 0.25), inset 0px 1px 3px rgba(0, 0, 0, 0.7), 0px 1px 0px rgba(255, 255, 255, 0.03);
|
|
145
|
+
-moz-box-shadow: inset 0px 0px 3px rgba(0, 0, 0, 0.25), inset 0px 1px 3px rgba(0, 0, 0, 0.7), 0px 1px 0px rgba(255, 255, 255, 0.03);
|
|
146
|
+
-webkit-font-smoothing: antialiased;
|
|
147
|
+
text-align: left;
|
|
148
|
+
font: 13px "Helvetica Neue", Arial, sans-serif;
|
|
149
|
+
padding: 4px 10px;
|
|
150
|
+
border: none;
|
|
151
|
+
background: transparent;
|
|
152
|
+
margin-bottom: 0;
|
|
153
|
+
outline: none;
|
|
154
|
+
opacity: 0.7;
|
|
155
|
+
color: #888;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#search:focus {
|
|
159
|
+
width: 120px;
|
|
160
|
+
opacity: 1.0;
|
|
161
|
+
}
|
|
162
|
+
/*views*/
|
|
163
|
+
|
|
164
|
+
#files span {
|
|
165
|
+
display: inline-block;
|
|
166
|
+
overflow: hidden;
|
|
167
|
+
text-overflow: ellipsis;
|
|
168
|
+
text-indent: 10px;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
#files .name {
|
|
172
|
+
background-repeat: no-repeat;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#files .icon .name {
|
|
176
|
+
text-indent: 28px;
|
|
177
|
+
}
|
|
178
|
+
/*tiles*/
|
|
179
|
+
|
|
180
|
+
.view-tiles .name {
|
|
181
|
+
width: 100%;
|
|
182
|
+
background-position: 8px 5px;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.view-tiles .size,
|
|
186
|
+
.view-tiles .date {
|
|
187
|
+
display: none;
|
|
188
|
+
}
|
|
189
|
+
/*details*/
|
|
190
|
+
|
|
191
|
+
ul#files.view-details li {
|
|
192
|
+
float: none;
|
|
193
|
+
display: block;
|
|
194
|
+
width: 90%;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
ul#files.view-details li.header {
|
|
198
|
+
height: 25px;
|
|
199
|
+
background: #000;
|
|
200
|
+
color: #fff;
|
|
201
|
+
font-weight: bold;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
.view-details .header {
|
|
205
|
+
border-radius: 5px;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
.view-details .name {
|
|
209
|
+
width: 60%;
|
|
210
|
+
background-position: 8px 5px;
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.view-details .size {
|
|
214
|
+
width: 10%;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.view-details .date {
|
|
218
|
+
width: 30%;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.view-details .size,
|
|
222
|
+
.view-details .date {
|
|
223
|
+
text-align: right;
|
|
224
|
+
direction: rtl;
|
|
225
|
+
}
|
|
226
|
+
/*mobile*/
|
|
227
|
+
|
|
228
|
+
@media (max-width: 768px) {
|
|
229
|
+
body {
|
|
230
|
+
font-size: 13px;
|
|
231
|
+
line-height: 16px;
|
|
232
|
+
padding: 0;
|
|
233
|
+
}
|
|
234
|
+
#search {
|
|
235
|
+
position: static;
|
|
236
|
+
width: 100%;
|
|
237
|
+
font-size: 2em;
|
|
238
|
+
line-height: 1.8em;
|
|
239
|
+
text-indent: 10px;
|
|
240
|
+
border: 0;
|
|
241
|
+
border-radius: 0;
|
|
242
|
+
padding: 10px 0;
|
|
243
|
+
margin: 0;
|
|
244
|
+
}
|
|
245
|
+
#search:focus {
|
|
246
|
+
width: 100%;
|
|
247
|
+
border: 0;
|
|
248
|
+
opacity: 1;
|
|
249
|
+
}
|
|
250
|
+
.directory h1 {
|
|
251
|
+
font-size: 2em;
|
|
252
|
+
line-height: 1.5em;
|
|
253
|
+
color: #fff;
|
|
254
|
+
background: #000;
|
|
255
|
+
padding: 15px 10px;
|
|
256
|
+
margin: 0;
|
|
257
|
+
}
|
|
258
|
+
ul#files {
|
|
259
|
+
border-top: 1px solid #cacaca;
|
|
260
|
+
}
|
|
261
|
+
ul#files li {
|
|
262
|
+
float: none;
|
|
263
|
+
width: auto !important;
|
|
264
|
+
display: block;
|
|
265
|
+
border-bottom: 1px solid #cacaca;
|
|
266
|
+
font-size: 2em;
|
|
267
|
+
line-height: 1.2em;
|
|
268
|
+
text-indent: 0;
|
|
269
|
+
margin: 0;
|
|
270
|
+
}
|
|
271
|
+
ul#files li:nth-child(odd) {
|
|
272
|
+
background: #e0e0e0;
|
|
273
|
+
}
|
|
274
|
+
ul#files li a {
|
|
275
|
+
height: auto;
|
|
276
|
+
border: 0;
|
|
277
|
+
border-radius: 0;
|
|
278
|
+
padding: 15px 10px;
|
|
279
|
+
}
|
|
280
|
+
ul#files li a:focus,
|
|
281
|
+
ul#files li a:hover {
|
|
282
|
+
border: 0;
|
|
283
|
+
}
|
|
284
|
+
#files .header,
|
|
285
|
+
#files .size,
|
|
286
|
+
#files .date {
|
|
287
|
+
display: none !important;
|
|
288
|
+
}
|
|
289
|
+
#files .name {
|
|
290
|
+
float: none;
|
|
291
|
+
display: inline-block;
|
|
292
|
+
width: 100%;
|
|
293
|
+
text-indent: 0;
|
|
294
|
+
background-position: 0 0;
|
|
295
|
+
}
|
|
296
|
+
#files .icon .name {
|
|
297
|
+
text-indent: 41px;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
#files .icon-directory .name {
|
|
302
|
+
background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAMAAAAoLQ9TAAAABGdBTUEAALGPC/xhBQAAAWtQTFRFAAAA/PPQ9Nhc2q402qQ12qs2/PTX2pg12p81+/LM89NE9dto2q82+/fp2rM22qY39d6U+/bo2qo2/frx/vz32q812qs12qE279SU8c4w9NZP+/LK//367s9y7s925cp0/vzw9t92//342po2/vz25s1579B6+OSO2bQ0/v799NyT8tE79dld8Msm+OrC/vzx79KA2IYs7s6I9d6R4cJe9+OF/PLI/fry79OF/v30//328tWB89RJ8c9p8c0u9eCf//7+9txs6sts5Mdr+++5+u2z/vrv+/fq6cFz8dBs8tA57cpq+OaU9uGs27Y8//799NdX/PbY9uB89unJ//z14sNf+emh+emk+vDc+uys9+OL8dJy89NH+eic8tN5+OaV+OWR9N2n9dtl9t529+KF9+GB9Nue9NdU8tR/9t5y89qW9dpj89iO89eG/vvu2pQ12Y4z/vzy2Ict/vvv48dr/vzz4sNg///+2Igty3PqwQAAAAF0Uk5TAEDm2GYAAACtSURBVBjTY2AgA2iYlJWVhfohBPg0yx38y92dS0pKVOVBAqIi6sb2vsWWpfrFeTI8QAEhYQEta28nCwM1OVleZqCAmKCEkUdwYWmhQnFeOStQgL9cySqkNNDHVJGbiY0FKCCuYuYSGRsV5KgjxcXIARRQNncNj09JTgqw0ZbkZAcK5LuFJaRmZqfHeNnpSucDBQoiEtOycnIz4qI9bfUKQA6pKKqAgqIKQyK8BgAZ5yfODmnHrQAAAABJRU5ErkJggg==);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
</style>
|
|
306
|
+
<script>
|
|
307
|
+
function $(id) {
|
|
308
|
+
var el = 'string' == typeof id ?
|
|
309
|
+
document.getElementById(id) :
|
|
310
|
+
id;
|
|
311
|
+
|
|
312
|
+
el.on = function(event, fn) {
|
|
313
|
+
if ('content loaded' == event) {
|
|
314
|
+
event = window.attachEvent ? "load" : "DOMContentLoaded";
|
|
315
|
+
}
|
|
316
|
+
el.addEventListener ?
|
|
317
|
+
el.addEventListener(event, fn, false) :
|
|
318
|
+
el.attachEvent("on" + event, fn);
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
el.all = function(selector) {
|
|
322
|
+
return $(el.querySelectorAll(selector));
|
|
323
|
+
};
|
|
324
|
+
|
|
325
|
+
el.each = function(fn) {
|
|
326
|
+
for (var i = 0, len = el.length; i < len; ++i) {
|
|
327
|
+
fn($(el[i]), i);
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
el.getClasses = function() {
|
|
332
|
+
return this.getAttribute('class').split(/\s+/);
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
el.addClass = function(name) {
|
|
336
|
+
var classes = this.getAttribute('class');
|
|
337
|
+
el.setAttribute('class', classes ?
|
|
338
|
+
classes + ' ' + name :
|
|
339
|
+
name);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
el.removeClass = function(name) {
|
|
343
|
+
var classes = this.getClasses().filter(function(curr) {
|
|
344
|
+
return curr != name;
|
|
345
|
+
});
|
|
346
|
+
this.setAttribute('class', classes.join(' '));
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
return el;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function search() {
|
|
353
|
+
var str = $('search').value,
|
|
354
|
+
links = $('files').all('a');
|
|
355
|
+
|
|
356
|
+
links.each(function(link) {
|
|
357
|
+
var text = link.textContent;
|
|
358
|
+
|
|
359
|
+
if ('..' == text) return;
|
|
360
|
+
if (str.length && ~text.indexOf(str)) {
|
|
361
|
+
link.addClass('highlight');
|
|
362
|
+
} else {
|
|
363
|
+
link.removeClass('highlight');
|
|
364
|
+
}
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
$(window).on('content loaded', function() {
|
|
369
|
+
$('search').on('keyup', search);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
</script>
|
|
373
|
+
</head>
|
|
374
|
+
|
|
375
|
+
<body class="directory">
|
|
376
|
+
<input id="search" type="text" placeholder="Search" autocomplete="off" />
|
|
377
|
+
<div id="wrapper">
|
|
378
|
+
<h1> / </h1>
|
|
379
|
+
<ul id="files" class="view-tiles">
|
|
380
|
+
<% for (var item in pages) { %>
|
|
381
|
+
<li>
|
|
382
|
+
<a href="<%= base %><%= pages[item] %>.html" class="icon icon-directory" title="button">
|
|
383
|
+
<span class="name"><%= pages[item] %></span>
|
|
384
|
+
</a>
|
|
385
|
+
</li>
|
|
386
|
+
<% } %>
|
|
387
|
+
</ul>
|
|
388
|
+
</div>
|
|
389
|
+
</body>
|
|
390
|
+
|
|
391
|
+
</html>
|
package/package.json
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deot/dev-dever",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "dist/index.es.js",
|
|
5
5
|
"module": "dist/index.es.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"files": [
|
|
9
|
-
"dist"
|
|
9
|
+
"dist",
|
|
10
|
+
"index.ejs",
|
|
11
|
+
"shared.config.ts"
|
|
10
12
|
],
|
|
11
13
|
"license": "MIT",
|
|
12
14
|
"publishConfig": {
|
|
13
15
|
"access": "public"
|
|
14
16
|
},
|
|
15
17
|
"dependencies": {
|
|
16
|
-
"@deot/dev-shared": "^
|
|
18
|
+
"@deot/dev-shared": "^2.0.0",
|
|
19
|
+
"ejs": "^3.1.9",
|
|
20
|
+
"vite": "^4.3.9"
|
|
17
21
|
},
|
|
18
22
|
"devDependencies": {
|
|
19
23
|
"cross-env": "^7.0.3"
|
package/shared.config.ts
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import * as path from 'node:path';
|
|
2
|
+
import * as fs from 'node:fs';
|
|
3
|
+
import { createRequire } from "node:module";
|
|
4
|
+
import { defineConfig } from 'vitest/config';
|
|
5
|
+
import type { UserConfig, ViteDevServer } from 'vite';
|
|
6
|
+
|
|
7
|
+
const cwd = process.cwd();
|
|
8
|
+
|
|
9
|
+
// devOptions
|
|
10
|
+
const devOptions = JSON.parse(decodeURIComponent(process.env.DEV_OPTIONS || '{}'));
|
|
11
|
+
const { workspace, html } = devOptions;
|
|
12
|
+
|
|
13
|
+
// alias
|
|
14
|
+
const replacement = (name: string) => path.resolve(cwd, `./packages/${name}/src`);
|
|
15
|
+
const { name } = createRequire(cwd)(path.resolve(cwd, workspace ? `${workspace}/index` : '', 'package.json'));
|
|
16
|
+
|
|
17
|
+
const getHtmlContent = async (url: string) => {
|
|
18
|
+
let fullpath = path.join(cwd, url);
|
|
19
|
+
if (
|
|
20
|
+
/^\/?@vite/.test(url)
|
|
21
|
+
|| (
|
|
22
|
+
fs.existsSync(fullpath)
|
|
23
|
+
&& fs.statSync(fullpath).isFile()
|
|
24
|
+
)
|
|
25
|
+
) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (url === '/') return html;
|
|
30
|
+
|
|
31
|
+
const [packageFolderName, htmlEntry] = url.split('/').filter(i => !!i);
|
|
32
|
+
|
|
33
|
+
fullpath = path.join(
|
|
34
|
+
cwd,
|
|
35
|
+
'packages',
|
|
36
|
+
packageFolderName,
|
|
37
|
+
'examples',
|
|
38
|
+
`${htmlEntry?.replace(/(\.html)/g, '')}.ts`
|
|
39
|
+
);
|
|
40
|
+
if (!fs.existsSync(fullpath)) return html;
|
|
41
|
+
|
|
42
|
+
let contents = '';
|
|
43
|
+
contents += `<!DOCTYPE html>\n`;
|
|
44
|
+
contents += `<html lang="en">\n`;
|
|
45
|
+
contents += ` <head>\n`;
|
|
46
|
+
contents += ` <meta charset="UTF-8" />\n`;
|
|
47
|
+
contents += ` <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n`;
|
|
48
|
+
contents += ` <title>demo-${url}</title>\n`;
|
|
49
|
+
contents += ` </head>\n`;
|
|
50
|
+
contents += ` <body>\n`;
|
|
51
|
+
contents += ` <script type="module">\n`;
|
|
52
|
+
contents += ` import "/${path.relative(cwd, fullpath)}";\n`;
|
|
53
|
+
contents += ` </script>\n`;
|
|
54
|
+
contents += ` </body>\n`;
|
|
55
|
+
contents += `</html>\n`;
|
|
56
|
+
return contents;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export default defineConfig({
|
|
60
|
+
resolve: workspace
|
|
61
|
+
? {
|
|
62
|
+
alias: [
|
|
63
|
+
{
|
|
64
|
+
find: new RegExp(`^${name}$`),
|
|
65
|
+
replacement: replacement('index')
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
|
|
69
|
+
find: new RegExp(`^${name}-(.*?)$`),
|
|
70
|
+
replacement: replacement('$1')
|
|
71
|
+
}
|
|
72
|
+
]
|
|
73
|
+
}
|
|
74
|
+
: {},
|
|
75
|
+
plugins: [
|
|
76
|
+
{
|
|
77
|
+
name: 'vite-plugin-virtual-html',
|
|
78
|
+
configureServer(server: ViteDevServer) {
|
|
79
|
+
server.middlewares.use(async (req, res, next) => {
|
|
80
|
+
const url = req.url as string;
|
|
81
|
+
|
|
82
|
+
const content = await getHtmlContent(url);
|
|
83
|
+
|
|
84
|
+
if (!content) {
|
|
85
|
+
return next();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
res.end(content);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
],
|
|
93
|
+
|
|
94
|
+
// // 因为virtualHtml不需要入口,这样可以不弹出Skipping dependency pre-bundling.
|
|
95
|
+
optimizeDeps: { entries: [] }
|
|
96
|
+
}) as UserConfig;
|