1.0.0 • Published 4 years ago
@sparrowjs/framework v1.0.0
SparrowJS
本项目不建议用于生产环境使用,推荐互相学习,一起学 typescript + nodejs。
灵感来源于 eggjs 和 midwayjs, 基于 koa 开发,运行在 nodejs 上的网络框架。
安装
$ npm install sparrowjs --save
使用
import "reflect-metadata"
import { Sparrow } from '@sparrowjs/framework'
const app = new Sparrow(__dirname)
app.router.get('/', ctx => {
ctx.body = 'hello, world'
})
app.run(8080, function onReady() {
console.log('Listen on http://localhost:8080')
})
file: app/controller/home.ts
@priority(-1)
@controller('/')
export class Home {
@route('/page/home')
@route('*')
async index(ctx: Context) {
ctx.render('index.html')
}
@route('*', { methods: ['GET'] })
async fallback(ctx: Context) {
ctx.status = 200
cxt.type = 'text/plan'
ctx.body = 'Document not found.'
}
}
启动项目
你需要安装 node.js 的版本为 nodejs >= 8.0
。
克隆此仓库后运行:
# 安装依赖,推荐使用 yarn 安装
$ npm install
# 启动 example 服务
$ npm run dev
# 启动文档编辑模式
$ npm run docs:dev
# 构建文档静态页
$ npm run docs:build
在 package.json
文件的 scripts
部分还有一些其他脚本可用.
开发计划
框架层 sparrowjs
- Sparrow 框架主体
- PluginManager 插件管理器
核心 @sparrowjs/core
- Application 应用主体
- Runtime 当前运行环境
内置模块 @sparrowjs/builtin
- Tasks 微任务管理
- Finder 文件模糊查找
- Loader 模块加载器
内置插件 @sparrowjs/internal-plugins
- config 多环境配置
- controller 发现并自动注册控制器
- service 发现并自动注册服务
- extend 拓展应用原型链
- And more
拓展模块
@sparrowjs/logging
@sparrowjs/shared
引入了 微软的 tsyringe
依赖注入插件,但是还需要一些时间学习
版本发布
# 更新版本号,内置代码检查
$ npm version <new_version|major|minor|patch>
# 发布代码包,自动代码
$ npm publish
可使用 npm version --help
查看帮助信息
感谢
感谢这些开源贡献给予的灵感,以下排名不分先后。
1.0.0
4 years ago