Skip to content

Commit 36e890a

Browse files
committed
[init] 初始化功能
0 parents  commit 36e890a

15 files changed

Lines changed: 866 additions & 0 deletions
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
name: Bug report
3+
about: Create a report to help us improve
4+
title: ''
5+
labels: 'bug'
6+
assignees: ''
7+
---
8+
9+
**Describe the bug**
10+
11+
A clear and concise description of what the bug is.
12+
13+
**To Reproduce**
14+
15+
Steps to reproduce the behavior:
16+
1. Go to '...'
17+
2. Click on '....'
18+
3. Scroll down to '....'
19+
4. See error
20+
21+
**Expected behavior**
22+
23+
A clear and concise description of what you expected to happen.
24+
25+
**Screenshots**
26+
27+
If applicable, add screenshots to help explain your problem.
28+
29+
**Desktop (please complete the following information):**
30+
31+
- OS: [e.g. iOS]
32+
- Browser [e.g. chrome, safari]
33+
- Version [e.g. 22]
34+
35+
**Additional context**
36+
37+
Add any other context about the problem here.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
name: 问题反馈
3+
about: 创建报告以帮助我们改进
4+
title: ''
5+
labels: 'bug'
6+
assignees: ''
7+
---
8+
9+
**描述错误**
10+
11+
对 bug 的简要概述。
12+
13+
**复现**
14+
15+
再现行为的步骤:
16+
1. 转到“…”
17+
2. 单击“….”
18+
3. 向下滚动至“….”
19+
4. 参见错误
20+
21+
**预期行为**
22+
23+
对你期望发生的事情进行清晰且简要的概述。
24+
25+
**屏幕截图**
26+
27+
如果可以,请添加屏幕截图以帮助解释您的问题。
28+
29+
**桌面(请填写以下信息):**
30+
31+
- 操作系统:[例如iOS]
32+
- 系统版本:[例如windows11]
33+
- 浏览器:[例如chrome、safari]
34+
- 浏览器版本:[例如100]
35+
36+
**附加上下文**
37+
38+
在此处添加有关该问题的任何其他上下文。

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!-- 请勿删除注释,需要使用时请复制一遍 -->
2+
## PR 类型
3+
4+
- [ ] 问题修复
5+
- [ ] 优化
6+
- [ ] 新功能
7+
- [ ] 测试用例
8+
9+
<!-- 详细的描述这个修改的背景和原因 -->
10+
## PR 描述
11+
12+
<!-- 请描述具体改动了哪些地方,为什么修改 -->
13+
### 修改说明
14+
1.

.github/workflows/ci.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: CI
2+
3+
on:
4+
push: {}
5+
merge_group:
6+
pull_request:
7+
types:
8+
- opened
9+
- synchronize
10+
- ready_for_review
11+
paths:
12+
- 'source/**.ts'
13+
- 'source/scripts/*.js'
14+
- '.github/workfows/ci.yaml'
15+
16+
permissions:
17+
contents: read
18+
19+
jobs:
20+
check-tests:
21+
runs-on: ubuntu-latest
22+
strategy:
23+
matrix:
24+
node-version: [18.x]
25+
steps:
26+
- uses: actions/checkout@v3
27+
28+
- name: Setup Node.js ${{ matrix.node-version }}
29+
uses: actions/setup-node@v3
30+
with:
31+
node-version: ${{ matrix.node-version }}
32+
33+
- name: Run CI
34+
run: npm run ci

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
dist
3+
4+
.temp
5+
tsconfig.tsbuildinfo

package-lock.json

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "@itharbors/module",
3+
"version": "0.1.1",
4+
"description": "",
5+
"main": "dist/index.js",
6+
"scripts": {
7+
"build": "npx tsc",
8+
"test": "node --test ./test/*.spec.js",
9+
"ci": "npm install && npm run build && npm run test"
10+
},
11+
"author": "VisualSJ",
12+
"license": "MIT",
13+
"publishConfig": {
14+
"access": "public"
15+
},
16+
"devDependencies": {
17+
"typescript": "^5.8.3"
18+
}
19+
}

readme.md

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
# Module System
2+
3+
一个简易的模块管理系统,主要职责:
4+
1. 管理模块列表
5+
2. 管理模块的生命周期
6+
3. 定义模块间的交互方式
7+
8+
# 模块设计文档: Module System
9+
10+
[![NPM](https://img.shields.io/npm/v/@itharbors/module)](https://www.npmjs.com/package/@itharbors/module)
11+
[![CI Status](https://github.com/itharbors/module/actions/workflows/ci.yaml/badge.svg)](https://github.com/itharbors/module/actions/workflows/ci.yaml)
12+
13+
一个简易的模块管理系统,主要职责:
14+
1. 管理模块列表
15+
2. 管理模块的生命周期
16+
3. 定义模块间的交互方式
17+
18+
## 需求分析
19+
20+
### 功能需求
21+
22+
- 管理模块的生命周期函数
23+
- register、load、unload、unregister
24+
- 管理模块对外暴露的方法
25+
- 将所有方法收敛到一个出入口
26+
- 简易的数据管理
27+
- 定义、修改数据
28+
- 数据变化的监听
29+
- 对象上的缓存数据管理
30+
31+
### 非功能需求
32+
33+
-
34+
35+
## 整体架构设计
36+
37+
## 代码范例
38+
39+
### 基础用法
40+
41+
```ts
42+
import { generateModule } from '@itharbors/module';
43+
44+
export const instance = generateModule({
45+
stash(): {} {
46+
return {};
47+
},
48+
49+
data(): {} {
50+
return {};
51+
},
52+
53+
register() {
54+
55+
},
56+
57+
register() {
58+
59+
},
60+
61+
load() {
62+
63+
},
64+
65+
unload() {
66+
67+
},
68+
69+
method: {
70+
async test(num: string) {
71+
return num + 1;
72+
}
73+
},
74+
});
75+
76+
77+
instance.run('register');
78+
instance.run('load');
79+
instance.run('unload');
80+
instance.run('unregister');
81+
82+
const num = await instance.execture('test', 1); // 2
83+
```
84+
85+
```ts
86+
// params 是 initWorkflow 时传入的那个 params
87+
// 主要用于项目内控制部分流程,比如构建的时候只构建脚本、只构建样式等功能
88+
exports.remove = function(params) {
89+
return ['./dist'];
90+
};
91+
exports.npm = function(params) {
92+
return [{
93+
message: '安装依赖',
94+
path: './',
95+
params: ['install'],
96+
detail: '依赖安装失败,请检查网络和配置',
97+
}];
98+
};
99+
exports.tsc = function(params) {
100+
return ['./'];
101+
};
102+
```
103+
104+
### 配置文件
105+
106+
### 注册自定义任务
107+
108+
```ts
109+
import { readFile } from 'fs';
110+
import { ModuleContainer, TModule } from '@itharbors/module';
111+
112+
export class Plugin extends ModuleContainer {
113+
public info: TPluginInfo;
114+
public path: string;
115+
116+
constructor(path: string) {
117+
const pkg = require(join(path, 'package.json'));
118+
const module = require(pkg.main) as Partial<TModule>;
119+
super({
120+
stash: module.stash || function () { return {}; },
121+
data: module.data || function () { return {}; },
122+
method: module.method || {},
123+
});
124+
}
125+
}
126+
```
127+
128+
## 决策点
129+
130+
-
131+
132+
## 异常处理设计
133+
134+
-
135+
136+
## 性能优化
137+
138+
-
139+
140+
## 附件与参考文档
141+
142+
-

source/index.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { TModule, TMethod, TData, TStash } from './types';
2+
3+
import { ModuleContainer } from './module';
4+
5+
/**
6+
* 创建于一个模块容器
7+
* @param module
8+
* @returns
9+
*/
10+
export function generateModule<M extends TMethod, D extends () => TData, S extends () => TStash>(module: TModule<M, D, S>) {
11+
const container = new ModuleContainer(module);
12+
return container;
13+
}
14+
15+
export type { TModule, TMethod, TData, TStash } from './types';
16+
17+
export { ModuleContainer } from './module';

0 commit comments

Comments
 (0)