oipage 0.3.0 → 1.0.0-alpha.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.
- package/CHANGELOG +15 -13
- package/README.md +1 -102
- package/bin/mineTypes.json +105 -0
- package/{nodejs/core → bin}/network.js +7 -4
- package/bin/resolve404.js +78 -0
- package/bin/run +8 -200
- package/bin/serve.js +64 -0
- package/images/file.png +0 -0
- package/images/folder.png +0 -0
- package/images/goback.png +0 -0
- package/{corejs → nodejs}/animation/index.js +8 -2
- package/nodejs/deeplog/index.d.ts +10 -0
- package/nodejs/deeplog/index.js +35 -0
- package/nodejs/linelog/index.d.ts +9 -0
- package/nodejs/{core/log.js → linelog/index.js} +12 -55
- package/{corejs → nodejs}/throttle/index.js +9 -3
- package/package.json +12 -5
- package/web/animation/index.d.ts +12 -0
- package/web/animation/index.js +108 -0
- package/{browserjs → web}/getStyle/index.js +8 -2
- package/{browserjs → web}/onReady/index.js +8 -2
- package/web/setStyle/index.js +11 -0
- package/web/throttle/index.d.ts +31 -0
- package/web/throttle/index.js +56 -0
- package/AUTHORS.txt +0 -6
- package/bin/options.js +0 -74
- package/browserjs/index.d.ts +0 -13
- package/browserjs/index.js +0 -9
- package/browserjs/setStyle/index.js +0 -5
- package/corejs/index.d.ts +0 -10
- package/corejs/index.js +0 -7
- package/nodejs/core/file.js +0 -163
- package/nodejs/core/image.js +0 -5
- package/nodejs/core/options.js +0 -49
- package/nodejs/core/remote.js +0 -60
- package/nodejs/core/responseFileList.js +0 -28
- package/nodejs/core/server.js +0 -190
- package/nodejs/data/404.js +0 -52
- package/nodejs/data/images/file.js +0 -1
- package/nodejs/data/images/folder.js +0 -1
- package/nodejs/data/mime.types.js +0 -112
- package/nodejs/form/common.js +0 -3
- package/nodejs/form/index.js +0 -80
- package/nodejs/form/select.js +0 -10
- package/nodejs/index.js +0 -58
- package/nodejs/loader/simpleScss.js +0 -248
- package/nodejs/loader/xhtml.js +0 -521
- package/nodejs/reader/plain.js +0 -20
- package/stylecss/index.css +0 -3
- package/stylecss/normalize.css +0 -94
- package/stylecss/rasterize.css +0 -318
- package/stylecss/skeleton.css +0 -16
- package/types/get-options.d.ts +0 -6
- package/types/index.d.ts +0 -187
- /package/{corejs → nodejs}/animation/index.d.ts +0 -0
- /package/{corejs → nodejs}/throttle/index.d.ts +0 -0
- /package/{browserjs → web}/getStyle/index.d.ts +0 -0
- /package/{browserjs → web}/onReady/index.d.ts +0 -0
- /package/{browserjs → web}/setStyle/index.d.ts +0 -0
package/CHANGELOG
CHANGED
|
@@ -40,17 +40,19 @@ v0.2.0:
|
|
|
40
40
|
(包括:input输入框、select列表选择)
|
|
41
41
|
* server hander方法补充api
|
|
42
42
|
(包括:getFileInfo()、filePath)
|
|
43
|
-
|
|
44
|
-
date:
|
|
43
|
+
v1.0.0:
|
|
44
|
+
date:
|
|
45
45
|
changes:
|
|
46
|
-
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
*
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
46
|
+
- 原v0.x的功能将独立一个分支继续维护:https://github.com/oi-contrib/OIPage/blob/v0.x/CHANGELOG
|
|
47
|
+
(v0.x保持对零碎方法这种形式的支持和维护,此版本开始将作为一个框架或一个系统的工具箱以提供更高效的使用方式,这是一次彻底的非兼容改造)
|
|
48
|
+
- 初始化版本(v1.x)
|
|
49
|
+
1、API模块
|
|
50
|
+
* animation 动画
|
|
51
|
+
* deeplog 进度打印
|
|
52
|
+
* getStyle 获取节点样式
|
|
53
|
+
* linglog 单行打印
|
|
54
|
+
* onReady 等待DOM加载完毕执行
|
|
55
|
+
* setStyle 设置节点样式
|
|
56
|
+
* throttle 节流函数
|
|
57
|
+
2、命令
|
|
58
|
+
* serve 开发服务器
|
package/README.md
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
# [OIPage](https://github.com/oi-contrib/OIPage)
|
|
2
|
-
|
|
2
|
+
前端网页或应用快速开发助手,包括开发服务器、辅助命令、实用API等
|
|
3
3
|
|
|
4
4
|
<p>
|
|
5
5
|
<a href="https://zxl20070701.github.io/toolbox/#/npm-download?packages=oipage&interval=7">
|
|
@@ -15,107 +15,6 @@ OI页面快速开发辅助库,包括核心包、Nodejs、浏览器、样式文
|
|
|
15
15
|
|
|
16
16
|
<img src="https://nodei.co/npm/oipage.png?downloads=true&downloadRank=true&stars=true" alt="NPM">
|
|
17
17
|
|
|
18
|
-
## 使用方式
|
|
19
|
-
|
|
20
|
-
你可以作为一个命令行使用,那么你需要全局安装:
|
|
21
|
-
|
|
22
|
-
```shell
|
|
23
|
-
npm install -g oipage
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
也可以作为项目开发中的一个功能加强,在 package.json 中配置命令或nodejs文件中引入需要的模块使用,那么就在项目中执行安装命令:
|
|
27
|
-
|
|
28
|
-
```shell
|
|
29
|
-
npm install oipage --save
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
全局安装后,就可以直接作为命令行使用了。你可以打印帮助查看:
|
|
33
|
-
|
|
34
|
-
```shell
|
|
35
|
-
oipage-cli -h
|
|
36
|
-
```
|
|
37
|
-
|
|
38
|
-
比如会出现下列内容:
|
|
39
|
-
|
|
40
|
-
```
|
|
41
|
-
Usage: oipage-cli <command>
|
|
42
|
-
|
|
43
|
-
where <command> is one of:
|
|
44
|
-
--help, -h, --server, -s, --version, -v, --config, -c, --delete, --copy, --pick, --move, --network, --get, --post, --cat, --run
|
|
45
|
-
|
|
46
|
-
oipage-cli --help|-h <term> search for help on <term>
|
|
47
|
-
oipage-cli --help|-h involved overview
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
比如--server或-s命令如何查看具体使用说明?只需要:
|
|
51
|
-
|
|
52
|
-
```shell
|
|
53
|
-
oipage-cli -h s
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
然后看见打印提示:
|
|
57
|
-
|
|
58
|
-
```
|
|
59
|
-
oipage-cli --server|-s [port|20000] [2]render source server.
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
根据提示我们知道,这是一个快速启动一个本地资源服务器的命令,使用的时候可以设置服务器端口号,端口号缺省是20000。
|
|
63
|
-
|
|
64
|
-
比如我们启动端口为8080的服务器:
|
|
65
|
-
|
|
66
|
-
```shell
|
|
67
|
-
oipage-cli -s 8080
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
对于更复杂的业务,我们推荐使用配置文件的方式。比如我们准备了配置文件 oipage.config.js ,那么就可以:
|
|
71
|
-
|
|
72
|
-
```shell
|
|
73
|
-
oipage-cli -c ./oipage.config.js
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
配置文件的内容如下:
|
|
77
|
-
|
|
78
|
-
```js
|
|
79
|
-
module.exports = {
|
|
80
|
-
devServer: {
|
|
81
|
-
// 可配置参数和“服务器”一致
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
```
|
|
85
|
-
|
|
86
|
-
如果你需要在项目中更灵活的使用,我们也提供了一些有用的API,具体如下:
|
|
87
|
-
|
|
88
|
-
### 核心包
|
|
89
|
-
|
|
90
|
-
- [animation 动画](./docs/corejs/animation.md)
|
|
91
|
-
- [throttle 节流函数](./docs/corejs/throttle.md)
|
|
92
|
-
|
|
93
|
-
### Nodejs
|
|
94
|
-
|
|
95
|
-
- [服务器](./docs/nodejs/server.md)
|
|
96
|
-
- [命令行参数解析](./docs/nodejs/options.md)
|
|
97
|
-
- [文件相关操作](./docs/nodejs/file.md)
|
|
98
|
-
- [控制台打印](./docs/nodejs/console.md)
|
|
99
|
-
- [网络请求(ajax)](./docs/nodejs/ajax.md)
|
|
100
|
-
- [网络信息等](./docs/nodejs/network.md)
|
|
101
|
-
- [资源数据](./docs/nodejs/data.md)
|
|
102
|
-
- [图片相关操作](./docs/nodejs/image.md)
|
|
103
|
-
- [文件解析](./docs/nodejs/loader.md)
|
|
104
|
-
- [文件读取](./docs/nodejs/reader.md)
|
|
105
|
-
- [表单录入](./docs/nodejs/form.md)
|
|
106
|
-
|
|
107
|
-
### 浏览器
|
|
108
|
-
|
|
109
|
-
- [getStyle 获取节点样式](./docs/browserjs/getStyle.md)
|
|
110
|
-
- [onReady 解析完执行](./docs/browserjs/onReady.md)
|
|
111
|
-
|
|
112
|
-
### 样式文件
|
|
113
|
-
|
|
114
|
-
> 统一浏览器样式 `normalize.css` 直接: `import 'oipage/stylecss/normalize.css'` 即可!
|
|
115
|
-
|
|
116
|
-
- [rasterize 十二栅格化](./docs/stylecss/rasterize.md)
|
|
117
|
-
- [skeleton 骨架屏动画](./docs/stylecss/skeleton.md)
|
|
118
|
-
|
|
119
18
|
## 版权
|
|
120
19
|
|
|
121
20
|
MIT License
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
{
|
|
2
|
+
"html": "text/html",
|
|
3
|
+
"htm": "text/html",
|
|
4
|
+
"shtml": "text/html",
|
|
5
|
+
"css": "text/css",
|
|
6
|
+
"xml": "text/xml",
|
|
7
|
+
"gif": "image/gif",
|
|
8
|
+
"jpeg": "image/jpeg",
|
|
9
|
+
"jpg": "image/jpeg",
|
|
10
|
+
"js": "application/javascript",
|
|
11
|
+
"atom": "application/atom+xml",
|
|
12
|
+
"rss": "application/rss+xml",
|
|
13
|
+
"mml": "text/mathml",
|
|
14
|
+
"txt": "text/plain",
|
|
15
|
+
"jad": "text/vnd.sun.j2me.app-descriptor",
|
|
16
|
+
"wml": "text/vnd.wap.wml",
|
|
17
|
+
"htc": "text/x-component",
|
|
18
|
+
"png": "image/png",
|
|
19
|
+
"tif": "image/tiff",
|
|
20
|
+
"tiff": "image/tiff",
|
|
21
|
+
"wbmp": "image/vnd.wap.wbmp",
|
|
22
|
+
"ico": "image/x-icon",
|
|
23
|
+
"jng": "image/x-jng",
|
|
24
|
+
"bmp": "image/x-ms-bmp",
|
|
25
|
+
"svg": "image/svg+xml",
|
|
26
|
+
"svgz": "image/svg+xml",
|
|
27
|
+
"webp": "image/webp",
|
|
28
|
+
"woff": "application/font-woff",
|
|
29
|
+
"jar": "application/java-archive",
|
|
30
|
+
"war": "application/java-archive",
|
|
31
|
+
"ear": "application/java-archive",
|
|
32
|
+
"json": "application/json",
|
|
33
|
+
"hqx": "application/mac-binhex40",
|
|
34
|
+
"doc": "application/msword",
|
|
35
|
+
"pdf": "application/pdf",
|
|
36
|
+
"ps": "application/postscript",
|
|
37
|
+
"eps": "application/postscript",
|
|
38
|
+
"ai": "application/postscript",
|
|
39
|
+
"rtf": "application/rtf",
|
|
40
|
+
"m3u8": "application/vnd.apple.mpegurl",
|
|
41
|
+
"xls": "application/vnd.ms-excel",
|
|
42
|
+
"eot": "application/vnd.ms-fontobject",
|
|
43
|
+
"ppt": "application/vnd.ms-powerpoint",
|
|
44
|
+
"wmlc": "application/vnd.wap.wmlc",
|
|
45
|
+
"kml": "application/vnd.google-earth.kml+xml",
|
|
46
|
+
"kmz": "application/vnd.google-earth.kmz",
|
|
47
|
+
"7z": "application/x-7z-compressed",
|
|
48
|
+
"cco": "application/x-cocoa",
|
|
49
|
+
"jardiff": "application/x-java-archive-diff",
|
|
50
|
+
"jnlp": "application/x-java-jnlp-file",
|
|
51
|
+
"run": "application/x-makeself",
|
|
52
|
+
"pl": "application/x-perl",
|
|
53
|
+
"pm": "application/x-perl",
|
|
54
|
+
"prc": "application/x-pilot",
|
|
55
|
+
"pdb": "application/x-pilot",
|
|
56
|
+
"rar": "application/x-rar-compressed",
|
|
57
|
+
"rpm": "application/x-redhat-package-manager",
|
|
58
|
+
"sea": "application/x-sea",
|
|
59
|
+
"swf": "application/x-shockwave-flash",
|
|
60
|
+
"sit": "application/x-stuffit",
|
|
61
|
+
"tcl": "application/x-tcl",
|
|
62
|
+
"tk": "application/x-tcl",
|
|
63
|
+
"der": "application/x-x509-ca-cert",
|
|
64
|
+
"pem": "application/x-x509-ca-cert",
|
|
65
|
+
"crt": "application/x-x509-ca-cert",
|
|
66
|
+
"xpi": "application/x-xpinstall",
|
|
67
|
+
"xhtml": "application/xhtml+xml",
|
|
68
|
+
"xspf": "application/xspf+xml",
|
|
69
|
+
"zip": "application/zip",
|
|
70
|
+
"bin": "application/octet-stream",
|
|
71
|
+
"exe": "application/octet-stream",
|
|
72
|
+
"dll": "application/octet-stream",
|
|
73
|
+
"deb": "application/octet-stream",
|
|
74
|
+
"dmg": "application/octet-stream",
|
|
75
|
+
"iso": "application/octet-stream",
|
|
76
|
+
"img": "application/octet-stream",
|
|
77
|
+
"msi": "application/octet-stream",
|
|
78
|
+
"msp": "application/octet-stream",
|
|
79
|
+
"msm": "application/octet-stream",
|
|
80
|
+
"docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
|
81
|
+
"xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
82
|
+
"pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
|
83
|
+
"mid": "audio/midi",
|
|
84
|
+
"midi": "audio/midi",
|
|
85
|
+
"kar": "audio/midi",
|
|
86
|
+
"mp3": "audio/mpeg",
|
|
87
|
+
"ogg": "audio/ogg",
|
|
88
|
+
"m4a": "audio/x-m4a",
|
|
89
|
+
"ra": "audio/x-realaudio",
|
|
90
|
+
"3gpp": "video/3gpp",
|
|
91
|
+
"3gp": "video/3gpp",
|
|
92
|
+
"ts": "video/mp2t",
|
|
93
|
+
"mp4": "video/mp4",
|
|
94
|
+
"mpeg": "video/mpeg",
|
|
95
|
+
"mpg": "video/mpeg",
|
|
96
|
+
"mov": "video/quicktime",
|
|
97
|
+
"webm": "video/webm",
|
|
98
|
+
"flv": "video/x-flv",
|
|
99
|
+
"m4v": "video/x-m4v",
|
|
100
|
+
"mng": "video/x-mng",
|
|
101
|
+
"asx": "video/x-ms-asf",
|
|
102
|
+
"asf": "video/x-ms-asf",
|
|
103
|
+
"wmv": "video/x-ms-wmv",
|
|
104
|
+
"avi": "video/x-msvideo"
|
|
105
|
+
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
const { networkInterfaces } = require("os");
|
|
2
|
+
|
|
3
|
+
// 网络信息
|
|
1
4
|
module.exports = function () {
|
|
2
5
|
|
|
3
6
|
let infomation = {
|
|
@@ -5,9 +8,9 @@ module.exports = function () {
|
|
|
5
8
|
IPv6: []
|
|
6
9
|
};
|
|
7
10
|
|
|
8
|
-
let networks =
|
|
11
|
+
let networks = networkInterfaces();
|
|
9
12
|
|
|
10
|
-
let IPv4Had = {}, IPv6Had = {}
|
|
13
|
+
let IPv4Had = {}, IPv6Had = {};
|
|
11
14
|
|
|
12
15
|
for (let typeName in networks) {
|
|
13
16
|
let network = networks[typeName]
|
|
@@ -20,7 +23,7 @@ module.exports = function () {
|
|
|
20
23
|
mac: network[index].mac
|
|
21
24
|
});
|
|
22
25
|
|
|
23
|
-
IPv4Had[network[index].mac] = true
|
|
26
|
+
IPv4Had[network[index].mac] = true;
|
|
24
27
|
}
|
|
25
28
|
} else if (network[index].family == 'IPv6' && network[index].address != '::1') {
|
|
26
29
|
if (!IPv6Had[network[index].mac]) {
|
|
@@ -29,7 +32,7 @@ module.exports = function () {
|
|
|
29
32
|
mac: network[index].mac
|
|
30
33
|
});
|
|
31
34
|
|
|
32
|
-
IPv6Had[network[index].mac] = true
|
|
35
|
+
IPv6Had[network[index].mac] = true;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const { readdirSync, lstatSync, readFileSync } = require("fs");
|
|
2
|
+
const { join } = require("path");
|
|
3
|
+
|
|
4
|
+
const img_folder = "data:image/png;base64," + readFileSync(join(__dirname, "../images/folder.png")).toString('base64');
|
|
5
|
+
const img_file = "data:image/png;base64," + readFileSync(join(__dirname, "../images/file.png")).toString('base64');
|
|
6
|
+
const img_goback = "data:image/png;base64," + readFileSync(join(__dirname, "../images/goback.png")).toString('base64');
|
|
7
|
+
|
|
8
|
+
module.exports = function (filePath) {
|
|
9
|
+
|
|
10
|
+
let subItems = [];
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
subItems = readdirSync(filePath);
|
|
14
|
+
} catch (e) {
|
|
15
|
+
try {
|
|
16
|
+
filePath = join(filePath, "../");
|
|
17
|
+
subItems = readdirSync(filePath);
|
|
18
|
+
} catch (e) { }
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let template = "<a class='goback' href='../'>返回</a>";
|
|
22
|
+
for (let i in subItems) {
|
|
23
|
+
let isDirectory = lstatSync(join(filePath, subItems[i])).isDirectory();
|
|
24
|
+
template += "<a class='" + (isDirectory ? "folder" : "file") + "' href='./" + subItems[i] + (isDirectory ? "/" : "") + "'>" + subItems[i] + "</a>";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return `<!DOCTYPE html>
|
|
28
|
+
<html lang="zh-cn">
|
|
29
|
+
|
|
30
|
+
<head>
|
|
31
|
+
<meta charset="UTF-8">
|
|
32
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
33
|
+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
|
34
|
+
<title>404 Not Found</title>
|
|
35
|
+
<style>
|
|
36
|
+
body{
|
|
37
|
+
margin: 0px;
|
|
38
|
+
background-color:#fcfcfc;
|
|
39
|
+
display: flex;
|
|
40
|
+
flex-wrap:wrap;
|
|
41
|
+
padding:100px;
|
|
42
|
+
}
|
|
43
|
+
body>a{
|
|
44
|
+
text-decoration: none;
|
|
45
|
+
padding:10px;
|
|
46
|
+
color:#000000;
|
|
47
|
+
text-align:center;
|
|
48
|
+
width:100px;
|
|
49
|
+
background-repeat: no-repeat;
|
|
50
|
+
background-position: center 0px;
|
|
51
|
+
padding-top: 65px;
|
|
52
|
+
margin-top: 50px;
|
|
53
|
+
font-size:12px;
|
|
54
|
+
background-size: 55% auto;
|
|
55
|
+
}
|
|
56
|
+
body>a:hover{
|
|
57
|
+
outline:1px solid #55b9e6;
|
|
58
|
+
}
|
|
59
|
+
body>a.folder{
|
|
60
|
+
background-image:url('${img_folder}');
|
|
61
|
+
}
|
|
62
|
+
body>a.file{
|
|
63
|
+
background-image:url('${img_file}');
|
|
64
|
+
}
|
|
65
|
+
body>a.goback{
|
|
66
|
+
background-image:url('${img_goback}');
|
|
67
|
+
}
|
|
68
|
+
</style>
|
|
69
|
+
</head>
|
|
70
|
+
|
|
71
|
+
<body>
|
|
72
|
+
|
|
73
|
+
${template}
|
|
74
|
+
|
|
75
|
+
</body>
|
|
76
|
+
|
|
77
|
+
</html>`;
|
|
78
|
+
};
|
package/bin/run
CHANGED
|
@@ -4,206 +4,14 @@
|
|
|
4
4
|
|
|
5
5
|
process.title = 'OIPage';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const { get, post } = require("../nodejs/core/remote");
|
|
13
|
-
const fs = require("fs");
|
|
14
|
-
const path = require("path");
|
|
15
|
-
const { exec } = require('child_process');
|
|
16
|
-
|
|
17
|
-
const jsonfile = require("../package.json");
|
|
18
|
-
|
|
19
|
-
// 组装好缩写和全写的映射
|
|
20
|
-
let shortHands = {};
|
|
21
|
-
for (let key in options) {
|
|
22
|
-
if (options[key].short) shortHands["-" + options[key].short] = "--" + key;
|
|
7
|
+
// 开发服务器
|
|
8
|
+
if (process.argv[2] == "serve") {
|
|
9
|
+
require("./serve")({
|
|
10
|
+
|
|
11
|
+
});
|
|
23
12
|
}
|
|
24
13
|
|
|
25
|
-
//
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
(() => {
|
|
29
|
-
|
|
30
|
-
// 打印版本
|
|
31
|
-
if (Array.isArray(parsed.version)) {
|
|
32
|
-
log("\nOIPage@v" + jsonfile.version + "\n");
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// 基于配置文件运行
|
|
36
|
-
else if (Array.isArray(parsed.config)) {
|
|
37
|
-
if (parsed.config.length < 1) parsed.config[0] = './oipage.config.js';
|
|
38
|
-
|
|
39
|
-
// 读取配置
|
|
40
|
-
let configFile = require(path.join(process.cwd(), parsed.config[0]));
|
|
41
|
-
|
|
42
|
-
// 如果配置了服务器
|
|
43
|
-
if ("devServer" in configFile) {
|
|
44
|
-
server(configFile.devServer);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
// 删除
|
|
49
|
-
else if (Array.isArray(parsed.delete)) {
|
|
50
|
-
|
|
51
|
-
// 获取绝对路径
|
|
52
|
-
let targetPath = fullPathSync(parsed.delete[0]);
|
|
53
|
-
|
|
54
|
-
deleteSync(targetPath);
|
|
55
|
-
log(`> delete ${targetPath.replace(process.cwd(), '.')}`);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// 复制
|
|
59
|
-
else if (Array.isArray(parsed.copy)) {
|
|
60
|
-
|
|
61
|
-
// 获取绝对路径
|
|
62
|
-
let sourcePath = fullPathSync(parsed.copy[0]);
|
|
63
|
-
let targetPath = fullPathSync(parsed.copy[1]);
|
|
64
|
-
|
|
65
|
-
// 如果存在
|
|
66
|
-
copySync(sourcePath, targetPath);
|
|
67
|
-
log(`> copy ${sourcePath.replace(process.cwd(), '.')} ➔ ${targetPath.replace(process.cwd(), '.')}`);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// 复制文件(一级展开)
|
|
71
|
-
else if (Array.isArray(parsed.pick)) {
|
|
72
|
-
|
|
73
|
-
// 如果目标文件夹不存在,创建
|
|
74
|
-
if (!fs.existsSync(parsed.pick[1])) {
|
|
75
|
-
fs.mkdirSync(parsed.pick[1], { recursive: true });
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
listFileSync(parsed.pick[0], fileInfo => {
|
|
79
|
-
|
|
80
|
-
// 获取路径
|
|
81
|
-
let sourcePath = fullPathSync(fileInfo.path);
|
|
82
|
-
let targetPath = fullPathSync(path.join(parsed.pick[1], fileInfo.name));
|
|
83
|
-
|
|
84
|
-
let index = 1;
|
|
85
|
-
while (fs.existsSync(targetPath)) {
|
|
86
|
-
targetPath = fullPathSync(path.join(parsed.pick[1], "【" + index + "】" + fileInfo.name));
|
|
87
|
-
index += 1;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
log(`> copy ${sourcePath.replace(process.cwd(), '.')} ➔ ${targetPath.replace(process.cwd(), '.')}`);
|
|
91
|
-
copySync(sourcePath, targetPath);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// 移动
|
|
96
|
-
else if (Array.isArray(parsed.move)) {
|
|
97
|
-
|
|
98
|
-
// 获取绝对路径
|
|
99
|
-
let sourcePath = fullPathSync(parsed.move[0]);
|
|
100
|
-
let targetPath = fullPathSync(parsed.move[1]);
|
|
101
|
-
|
|
102
|
-
// 如果存在
|
|
103
|
-
moveSync(sourcePath, targetPath);
|
|
104
|
-
log(`> move ${sourcePath.replace(process.cwd(), '.')} ➔ ${targetPath.replace(process.cwd(), '.')}`);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
// 网络信息
|
|
108
|
-
else if (Array.isArray(parsed.network)) {
|
|
109
|
-
log(JSON.stringify(network(), null, 4));
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// GET请求
|
|
113
|
-
else if (Array.isArray(parsed.get)) {
|
|
114
|
-
get(parsed.get[0]).then(data => {
|
|
115
|
-
log(data);
|
|
116
|
-
}).catch(e => {
|
|
117
|
-
error(e);
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// PSOT请求
|
|
122
|
-
else if (Array.isArray(parsed.post)) {
|
|
123
|
-
post(parsed.post[0]).then(data => {
|
|
124
|
-
log(data);
|
|
125
|
-
}).catch(e => {
|
|
126
|
-
error(e);
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// 查看文件
|
|
131
|
-
else if (Array.isArray(parsed.cat)) {
|
|
132
|
-
try {
|
|
133
|
-
let filepath = fullPathSync(parsed.cat[0])
|
|
134
|
-
|
|
135
|
-
log(fs.readFileSync(filepath, {
|
|
136
|
-
encoding: "utf8"
|
|
137
|
-
}));
|
|
138
|
-
} catch (e) {
|
|
139
|
-
error(e);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
// 运行多命令
|
|
144
|
-
else if (Array.isArray(parsed.run)) {
|
|
145
|
-
for (let index = 0; index < parsed.run.length; index++) {
|
|
146
|
-
const child = exec(parsed.run[index]);
|
|
147
|
-
|
|
148
|
-
// 监听子线程的stdout
|
|
149
|
-
child.stdout.on('data', (data) => {
|
|
150
|
-
console.log(`[${index + 1}] log:${data}`);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
// 监听子线程的stderr
|
|
154
|
-
child.stderr.on('data', (data) => {
|
|
155
|
-
console.error(`[${index + 1}] error:${data}`);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// 子线程结束处理
|
|
159
|
-
child.on('close', (code) => {
|
|
160
|
-
console.log(`[${index + 1}] 子线程结束,退出码 ${code}`);
|
|
161
|
-
});
|
|
162
|
-
|
|
163
|
-
// 子线程出错处理
|
|
164
|
-
child.on('error', (error) => {
|
|
165
|
-
console.error(`[${index + 1}] 子线程错误: ${error.message}`);
|
|
166
|
-
});
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
// 服务器
|
|
171
|
-
else if (Array.isArray(parsed.server)) {
|
|
172
|
-
server({
|
|
173
|
-
port: parsed.server[0],
|
|
174
|
-
basePath: parsed.server[1]
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// 否则就是帮助
|
|
179
|
-
else {
|
|
180
|
-
let helpParsed = Array.isArray(parsed.help) ? parsed.help : parsed.__terminal__;
|
|
181
|
-
|
|
182
|
-
// 打印具体的配置提示
|
|
183
|
-
if (helpParsed && helpParsed.length > 0) {
|
|
184
|
-
let help0 = helpParsed[0];
|
|
185
|
-
|
|
186
|
-
// 缩写转全拼
|
|
187
|
-
if (help0.length == 1) {
|
|
188
|
-
help0 = shortHands["-" + help0];
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (help0) {
|
|
192
|
-
help0 = help0.replace(/^--/, "");
|
|
193
|
-
|
|
194
|
-
// 根据需要帮助的命令获取对应的信息
|
|
195
|
-
const help0Option = options[help0];
|
|
196
|
-
if (help0Option) {
|
|
197
|
-
log(`
|
|
198
|
-
` + help0Option.demo + ` ` + help0Option.info + `
|
|
199
|
-
`);
|
|
200
|
-
|
|
201
|
-
return;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
}
|
|
205
|
-
}
|
|
14
|
+
// 默认,帮助
|
|
15
|
+
else {
|
|
206
16
|
|
|
207
|
-
|
|
208
|
-
}
|
|
209
|
-
})();
|
|
17
|
+
}
|
package/bin/serve.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const { join } = require("path");
|
|
2
|
+
const { existsSync, lstatSync, readFileSync } = require("fs");
|
|
3
|
+
const { createServer } = require('http');
|
|
4
|
+
const packageValue = require("../package.json");
|
|
5
|
+
const network = require("./network");
|
|
6
|
+
const mineTypes = require("./mineTypes.json");
|
|
7
|
+
const resolve404 = require("./resolve404.js");
|
|
8
|
+
|
|
9
|
+
// 开发服务器
|
|
10
|
+
module.exports = function (config) {
|
|
11
|
+
let startTime = new Date().valueOf();
|
|
12
|
+
|
|
13
|
+
const port = config.port || 8080; // 端口号
|
|
14
|
+
const basePath = join(process.cwd(), "./"); // 服务器根路径
|
|
15
|
+
|
|
16
|
+
let Server = createServer(function (request, response) {
|
|
17
|
+
|
|
18
|
+
let url = decodeURIComponent(request.url);
|
|
19
|
+
url = url.split("?")[0];
|
|
20
|
+
|
|
21
|
+
// 请求的文件路径
|
|
22
|
+
let filePath = join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
|
|
23
|
+
|
|
24
|
+
// 如果存在且是文件
|
|
25
|
+
if (existsSync(filePath) && !lstatSync(filePath).isDirectory()) {
|
|
26
|
+
|
|
27
|
+
let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
|
|
28
|
+
let fileType = mineTypes[dotName]; // 文件类型
|
|
29
|
+
|
|
30
|
+
response.writeHead('200', {
|
|
31
|
+
'Content-type': (fileType || "text/plain") + ";charset=utf-8",
|
|
32
|
+
'Access-Control-Allow-Origin': '*',
|
|
33
|
+
'Server': 'Powered by OIPage-dev-server@' + packageValue.version
|
|
34
|
+
});
|
|
35
|
+
response.write(readFileSync(filePath));
|
|
36
|
+
response.end();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// 否则就是404
|
|
40
|
+
else {
|
|
41
|
+
response.writeHead(404, {
|
|
42
|
+
'Content-type': "text/html;charset=utf-8",
|
|
43
|
+
'Access-Control-Allow-Origin': '*',
|
|
44
|
+
'Server': 'Powered by OIPage-dev-server@' + packageValue.version
|
|
45
|
+
});
|
|
46
|
+
response.write(resolve404(filePath));
|
|
47
|
+
response.end();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
Server.listen(port);
|
|
53
|
+
|
|
54
|
+
// 获取网络信息
|
|
55
|
+
let networkValue = network();
|
|
56
|
+
|
|
57
|
+
// 打印成功提示
|
|
58
|
+
console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] Project is running at:\x1b[0m');
|
|
59
|
+
console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] Loopback: \x1b[36mhttp://localhost:/' + port + '\x1b[0m');
|
|
60
|
+
for (let ipv4Item of networkValue.IPv4) console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] On Your Network (IPv4):\x1b[36m http://' + ipv4Item.address + ':' + port + '/\x1b[0m');
|
|
61
|
+
for (let ipv6Item of networkValue.IPv6) console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] On Your Network (IPv6): \x1b[36mhttp://[' + ipv6Item.address + ']:' + port + '/\x1b[0m');
|
|
62
|
+
console.log('<i> \x1b[1m\x1b[32m[OIPage-dev-server] Content not from OIPage is served from \x1b[36m"' + basePath + '" \x1b[0mdirectory');
|
|
63
|
+
console.log('\nOIPage ' + packageValue.version + ' compiled \x1b[1m\x1b[32msuccessfully\x1b[0m in ' + (new Date().valueOf() - startTime) + ' ms')
|
|
64
|
+
};
|
package/images/file.png
ADDED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* animation of OIPage v1.0.0-alpha.0
|
|
3
|
+
* git+https://github.com/oi-contrib/OIPage.git
|
|
4
|
+
*/
|
|
5
|
+
|
|
1
6
|
//当前正在运动的动画的tick函数堆栈
|
|
2
7
|
var $timers = [];
|
|
3
8
|
//唯一定时器的定时间隔
|
|
@@ -13,7 +18,7 @@ var $timerId;
|
|
|
13
18
|
*
|
|
14
19
|
* @returns {function} 返回一个函数,调用该函数,可以提前结束动画
|
|
15
20
|
*/
|
|
16
|
-
|
|
21
|
+
function animation(doback, duration, callback) {
|
|
17
22
|
if (arguments.length < 2) duration = 400;
|
|
18
23
|
if (arguments.length < 3) callback = function () { };
|
|
19
24
|
|
|
@@ -99,4 +104,5 @@ export function animation(doback, duration, callback) {
|
|
|
99
104
|
}
|
|
100
105
|
};
|
|
101
106
|
|
|
102
|
-
};
|
|
107
|
+
};
|
|
108
|
+
exports.animation = animation;
|