oipage 0.2.0-alpha.0 → 0.2.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 CHANGED
@@ -38,4 +38,6 @@ v0.2.0:
38
38
  * plain 读取文本内容
39
39
  * form 表单录入
40
40
  (包括:input输入框、select列表选择)
41
+ * server hander方法补充api
42
+ (包括:getFileInfo()、filePath)
41
43
 
package/README.md CHANGED
@@ -116,10 +116,6 @@ module.exports = {
116
116
  - [rasterize 十二栅格化](./docs/stylecss/rasterize.md)
117
117
  - [skeleton 骨架屏动画](./docs/stylecss/skeleton.md)
118
118
 
119
- ### 前端开发框架
120
-
121
- 一个简单易用的用于快速开发前端页面的框架:[前端开发框架](./docs/framework/index.md)
122
-
123
119
  ## 版权
124
120
 
125
121
  MIT License
@@ -1,10 +1,13 @@
1
1
  import { getStyleType } from "./getStyle"
2
+ import { setStyleType } from "./setStyle"
2
3
  import { onReadyType } from "./onReady"
3
4
 
4
5
  export default class Corejs {
5
6
  static getStyle: getStyleType
7
+ static setStyle: setStyleType
6
8
  static onReady: onReadyType
7
9
  }
8
10
 
9
11
  export let getStyle: getStyleType
12
+ export let setStyle: setStyleType
10
13
  export let onReady: onReadyType
@@ -1,7 +1,9 @@
1
1
  import { getStyle } from "./getStyle/index.js";
2
+ import { setStyle } from "./setStyle/index.js";
2
3
  import { onReady } from "./onReady/index.js";
3
4
 
4
5
  export default {
5
6
  getStyle: getStyle,
7
+ setStyle: setStyle,
6
8
  onReady: onReady
7
9
  };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * 设置节点样式
3
+ */
4
+ export interface setStyleType {
5
+ (el: HTMLElement, styles: {
6
+ [key: string]: string | number
7
+ }): void
8
+ }
9
+
10
+ export let setStyle: setStyleType
@@ -0,0 +1,5 @@
1
+ export function setStyle(el, styles) {
2
+ for (var key in styles) {
3
+ el.style[key] = styles[key];
4
+ }
5
+ };
@@ -44,12 +44,40 @@ module.exports = function (config = {}) {
44
44
  request.on('end', () => {
45
45
  let url = decodeURIComponent(request.url);
46
46
 
47
+ url = url.split("?")[0];
48
+
49
+ // 请求的文件路径
50
+ let filePath = path.join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
51
+
47
52
  log("[" + index++ + "]" + url);
48
53
 
54
+ let getFileInfo = function (filePath) {
55
+ let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
56
+ let type = mineTypes[dotName];
57
+ if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) {
58
+ return {
59
+ type,
60
+ path: filePath
61
+ };
62
+ } else {
63
+ for (let suffix of suffixs) {
64
+ if (fs.existsSync(filePath + suffix) && !fs.lstatSync(filePath + suffix).isDirectory()) {
65
+ type = mineTypes[suffix.replace(/^\./, "")];
66
+ return {
67
+ type,
68
+ path: filePath + suffix
69
+ };
70
+ }
71
+ }
72
+ }
73
+ };
74
+
49
75
  // 自定义拦截
50
76
  if (handler.call({
51
77
  data: requestData,
52
- base: basePath
78
+ base: basePath,
79
+ getFileInfo,
80
+ filePath
53
81
  }, request, response)) return;
54
82
 
55
83
  // proxy拦截
@@ -101,13 +129,6 @@ module.exports = function (config = {}) {
101
129
  }
102
130
  }
103
131
 
104
- url = url.split("?")[0];
105
-
106
- // 请求的文件路径
107
- let filePath = path.join(basePath, url == "/" ? "index.html" : url.replace(/^\//, ""));
108
-
109
- let dotName = /\./.test(filePath) ? filePath.match(/\.([^.]+)$/)[1] : "";
110
-
111
132
  let is404 = true;
112
133
  let doResponse = function (type, filePath) {
113
134
  response.writeHead(200, {
@@ -119,17 +140,9 @@ module.exports = function (config = {}) {
119
140
  is404 = false;
120
141
  };
121
142
 
122
- // 文件类型
123
- type = mineTypes[dotName];
124
- if (fs.existsSync(filePath) && !fs.lstatSync(filePath).isDirectory()) {
125
- doResponse(type, filePath);
126
- } else {
127
- for (let suffix of suffixs) {
128
- if (fs.existsSync(filePath + suffix) && !fs.lstatSync(filePath + suffix).isDirectory()) {
129
- type = mineTypes[suffix.replace(/^\./, "")];
130
- doResponse(type, filePath + suffix);
131
- }
132
- }
143
+ let fileInfo = getFileInfo(filePath);
144
+ if (fileInfo) { // 如果文件存在
145
+ doResponse(fileInfo.type, fileInfo.path);
133
146
  }
134
147
 
135
148
  if (is404) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oipage",
3
- "version": "0.2.0-alpha.0",
3
+ "version": "0.2.0-alpha.1",
4
4
  "description": "OI页面快速开发辅助库,包括核心包、Nodejs、浏览器、样式文件等",
5
5
  "main": "./nodejs/index.js",
6
6
  "typings": "./types/index.d.ts",