mm_statics 1.9.1 → 1.9.2

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 CHANGED
@@ -29,7 +29,7 @@ const { statics } = require('mm_statics');
29
29
  const app = new Koa();
30
30
 
31
31
  // 使用默认配置(root 为 ./static)
32
- app.use(statics({ root: './static' }));
32
+ app.use(statics({ name: 'static', root: './static' }));
33
33
 
34
34
  app.listen(3000, () => {
35
35
  console.log('服务器运行在 http://localhost:3000');
@@ -46,6 +46,7 @@ const app = new Koa();
46
46
 
47
47
  // 自定义配置
48
48
  app.use(statics({
49
+ name: 'public', // 驱动名称(必填)
49
50
  root: './public', // 静态文件根目录
50
51
  path: '/src', // 需要转换的文件路径前缀
51
52
  files: ['.js', '.vue'], // 需要转换的文件类型
@@ -64,6 +65,7 @@ app.listen(3000);
64
65
 
65
66
  | 配置项 | 类型 | 默认值 | 描述 |
66
67
  |--------|------|--------|------|
68
+ | `name` | string | 无(必填) | 驱动名称 |
67
69
  | `root` | string | `''` | 静态文件根目录,为空时由 `dir` 推导,处理器兜底为 `./static` |
68
70
  | `path` | string | `''` | 路由根路径,为空时自动生成 `/${app}/` |
69
71
  | `files` | array | `['.js', '.vue', '.html']` | 需要转换的文件类型 |
@@ -87,6 +89,7 @@ app.listen(3000);
87
89
  ```javascript
88
90
  // 禁用AMD转换,仅提供静态文件服务
89
91
  app.use(statics({
92
+ name: 'public',
90
93
  convert_amd: false,
91
94
  compile_vue: false,
92
95
  root: './public'
@@ -98,6 +101,7 @@ app.use(statics({
98
101
  ```javascript
99
102
  // 启用AMD转换,自动转换ES6模块
100
103
  app.use(statics({
104
+ name: 'modules',
101
105
  convert_amd: true,
102
106
  compile_vue: false,
103
107
  root: './src',
@@ -111,6 +115,7 @@ app.use(statics({
111
115
  ```javascript
112
116
  // 启用AMD转换,将Vue组件转换为AMD格式
113
117
  app.use(statics({
118
+ name: 'vue',
114
119
  convert_amd: true,
115
120
  compile_vue: true,
116
121
  root: './components',
@@ -124,6 +129,7 @@ app.use(statics({
124
129
  ```javascript
125
130
  // 禁用AMD转换,但启用Vue编译,生成可直接使用的组件
126
131
  app.use(statics({
132
+ name: 'vue_component',
127
133
  convert_amd: false,
128
134
  compile_vue: true,
129
135
  root: './components',
package/lib/manager.js CHANGED
@@ -13,11 +13,6 @@ class StaticManager extends Manager {
13
13
  * @type {object}
14
14
  */
15
15
  static config = {
16
- /**
17
- * 名称
18
- * @type {string}
19
- */
20
- name: "",
21
16
  /**
22
17
  * 标题
23
18
  * @type {string}
@@ -76,7 +71,7 @@ class StaticManager extends Manager {
76
71
  */
77
72
  async run(ctx, next) {
78
73
  var done;
79
- var infos = this._getInfos();
74
+ var infos = this.configs;
80
75
  var len = infos.length;
81
76
  let path = ctx.path || (ctx.params && ctx.params.path) || '';
82
77
  if (path.indexOf(".") !== -1) {
@@ -101,7 +96,8 @@ class StaticManager extends Manager {
101
96
  async _tryServeFile(ctx, infos, len, next) {
102
97
  for (var i = 0; i < len; i++) {
103
98
  var info = infos[i];
104
- if (info.state === 1) {
99
+ let is_running = await this.isRunning(info.name);
100
+ if (is_running) {
105
101
  let mod = this.get(info.name);
106
102
  if (mod) {
107
103
  await this._initDrive(mod);
@@ -126,7 +122,8 @@ class StaticManager extends Manager {
126
122
  var q = this._getQueryString(ctx);
127
123
  for (var i = 0; i < len; i++) {
128
124
  var info = infos[i];
129
- if (info.state === 1) {
125
+ let is_running = await this.isRunning(info.name);
126
+ if (is_running) {
130
127
  let mod = this.get(info.name);
131
128
  if (mod) {
132
129
  var p = mod.config.path;
@@ -246,15 +243,13 @@ StaticManager.prototype._getInfos = function () {
246
243
  };
247
244
 
248
245
  /**
249
- * 初始化驱动实例(仅未初始化时执行生命周期 init,重复调用安全)
246
+ * 初始化驱动实例(重复调用安全由驱动自身保证)
250
247
  * @param {object} drive 驱动实例
251
248
  * @returns {Promise<void>} 初始化完成
252
249
  * @private
253
250
  */
254
251
  StaticManager.prototype._initDrive = async function (drive) {
255
- if (await drive.isState("created")) {
256
- await drive.init();
257
- }
252
+ await drive.init();
258
253
  };
259
254
 
260
255
  /**
package/lib/static.js CHANGED
@@ -17,8 +17,6 @@ class Static extends Item {
17
17
  'root': '',
18
18
  // 路由根路径
19
19
  'path': '',
20
- // 名称
21
- 'name': '',
22
20
  // 首页
23
21
  'index': 'index.html',
24
22
  // 重定向
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mm_statics",
3
- "version": "1.9.1",
3
+ "version": "1.9.2",
4
4
  "description": "这是超级美眉statics函数模块,用于web服务端statics缓存",
5
5
  "main": "index.js",
6
6
  "scripts": {