Skip to content

Commit

Permalink
Merge pull request #1 from darukjs/2.0
Browse files Browse the repository at this point in the history
merge
  • Loading branch information
myywlc authored Sep 9, 2020
2 parents c3d77bf + 72b815d commit 2c45db4
Show file tree
Hide file tree
Showing 86 changed files with 5,979 additions and 750 deletions.
61 changes: 0 additions & 61 deletions CN.md

This file was deleted.

1 change: 1 addition & 0 deletions CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc.darukjs.com
147 changes: 88 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,100 +19,129 @@
![APM](https://img.shields.io/apm/l/vim-mode.svg)
[![Build Status](https://dev.azure.com/designsor/daruk/_apis/build/status/darukjs.daruk?branchName=developer)](https://dev.azure.com/designsor/daruk/_build/latest?definitionId=3&branchName=developer)

# Daruk
## Daruk

[Chinese Document](./CN.md)
[Daruk](https://darukjs.com) 是一款基于 Koa2,使用 Typescript 开发的轻量级 web 框架。Daruk 的初衷是让人们可以更方便的开发 Nodejs Web 应用并能够体会到 Typescript 编程的乐趣。Daruk 本身基于 100%基于 Typescript 开发,使用 inversifyjs 的 IoC 容器管理依赖,让开发者享受最佳的 OOP 和 IoC 的编程体验。

[Daruk](https://darukjs.github.io/daruk.org) is a lightweight web framework base on [Koa](https://github.com/koajs/koa) and written in [Typescript](https://www.typescriptlang.org/). Koa is original http server implementation if you used it. In the daily development,we have to use many open source middleware in Koa to implement scaffold, routing, abstraction and some components such as logging, monitoring, etc.
框架内部集成了许多方便灵活的装饰器函数,让开发者可以写更少的代码来完成更多的事情,Daruk2.0 更改了之前严格要求目录约定的范式,提供给开发者更灵活的操作空间来进行项目约束和编写,但是内置的功能并没有缺失,整个框架的开发能力和 Daruk1.0 能力持平。

We can create your web project by Daruk scaffold for business. Daruk core is lightweight and easy extension and learing, but it can provides more options for developer to rapid development such as constraints directory specification and code style.
比如在 Daruk2.0 中,我们可以使用装饰器来快速定义 service,controller,timer,middleware 等能力来编写 web 应用,且提供了一些基本的内置中间件和路由服务等,更灵活的定义,让 Daruk2.0 可以更灵活的定制你的 web 项目和编写测试脚本。

Daruk, it comes from [The Legend of Zelda: Breath of the Wild](https://en.wikipedia.org/wiki/The_Legend_of_Zelda:_Breath_of_the_Wild) one of the four heroes, it have symbol of guardian ability. The goal of the framework is also as it.
Daruk 来源自塞尔达传说旷野之息里的四英杰之一,拥有在周围张开结界保护自己的力量,框架的目的也是为了给 nodejs server 提供健壮的基础管理能力。

Daruk is base on Koa2, includes features:
Daruk2.0 同样基于 koa2,目前包含以下核心功能:

- Scaffolding
- Directory and file specification
- Auto loader and decorator combination
- Complete Typescript development experience
- Lifecycle and hook.
- Custom(performance logs & business logs) & tracked
- Online performance analysis
- Lightweight link tracking
- The MVC development of object-oriented
- Support the development of the module
- 开启装饰器配置,ts 环境下引入即用,无需脚手架等工具。
- 提供给开发者编写影响框架内部能力的插件机制
- 可以自定义目录结构,在启动时使用 API 加载你自己定义的源文件
- 完整的 typescript 开发体验
- 服务启动完整生命周期 hook
- 自定义(性能日志 & 业务日志) 染色功能
- 支持线上实时性能分析
- 轻量级的链路追踪
- 面向对象的 mvc 开发体验
- 配套的一些周边模块

## Installation scaffolding
## Installation & Quick start

```bash
# install daruk scaffold cli
$ cnpm i -g daruk-cli

# init project
# --ignore ignore local template cache
$ daruk init --ignore daruk-example
安装

# run the project
$ cd daruk-example
$ npm run dev
```bash
mkdir daruk-demo
cd daruk-demo
npm init
npm add daruk ts-node typescript
mkidr src
touch src/index.ts
```

## Quick start

You can write your code shown below :
开始编写 web 应用 `src/index.ts`

```typescript
import { Daruk } from 'daruk';
import { DarukServer, controller, get, DarukContext } from 'daruk';

const myApp = new Daruk('darukProject', {
rootPath: __dirname,
debug: process.env.NODE_ENV === 'dev'
});
(async () => {
const myapp = DarukServer();

myApp.listen(process.env.PORT || 3000);
```
@controller()
class Index {
@get('/')
public async index(ctx: DarukContext) {
ctx.body = 'hello world';
}
}

`controllers/index.ts`:
await myapp.binding();
myapp.listen(3000);
})();
```

```typescript
import { BaseController, config, Context, Daruk, get, middleware, util } from 'daruk';
创建编译时的 `tsconfig.json` 文件

export default class Index extends BaseController {
@util('getToday')
public getToday: Daruk['util']['getToday'];
```bash
touch tsconfig.json
```

@config('author')
public author: Daruk['config']['author'];
```json
{
"compileOnSave": true,
"compilerOptions": {
"target": "es2017",
"module": "commonjs",
"sourceMap": true,
"outDir": "./build",
"rootDir": "./src",
"typeRoots": [],
"types": [],
"experimentalDecorators": true,
"emitDecoratorMetadata": true
},
"exclude": ["node_modules"],
"include": ["./src/**/*.ts"]
}
```

@config('version')
public version: Daruk['config']['version'];
编辑 `package.json` 的启动和编译脚本

@middleware('cors')
@get('/')
public async index(ctx: Context, next: Function) {
const weather = await ctx.service.weather.getWeather();
ctx.body = `Hi, ${this.author}, project version is ${
this.version
}, Today is ${this.getToday()}, weather is ${weather}`;
```json
{
"scripts": {
"dev": "NODE_ENV=dev ts-node --project tsconfig.json --files src/index.ts",
"build": "tsc"
}
}
```

More information you can check out [example/03-weather](./example/03-weather).
启动服务

```bash
npm run dev
> NODE_ENV=dev ts-node --project tsconfig.json --files src/index.ts
[2020-9-1 19:52:12] [debug] [init] [router] get - /
```

打包脚本并启动编译后的脚本

```bash
npm run build
node build/index.js
```

## Docs

More docs: [Quick Start](http://darukjs.com/)
查看 Daruk 文档[快速开始](https://darukjs.com/)吧! TypeDoc 则可以从这里开始 [API DOC](https://doc.darukjs.com/)吧!

## Example

## Features Todo
查看实际的 web 服务例子 [example](https://github.com/darukjs/daruk/tree/2.0/example)

Beta [TodoList](./docs/todo-list.md)
[daruk-demo](https://github.com/darukjs/daruk-demo)

## How to Contribute

Please let us know how can we help. Do check out issues for bug reports or suggestions first.

To become a contributor, please follow our [contributing guide](./docs/how-to-contribute.md)
To become a contributor, please follow our [contributing guide](./docs/CONTRIBUTING.md)

[npm-image]: https://img.shields.io/npm/v/daruk.svg?style=flat-square
[npm-url]: https://www.npmjs.com/package/daruk
Expand Down
27 changes: 27 additions & 0 deletions deployDoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env sh

# abort on errors
set -e

# build
npm run doc

# navigate into the build output directory
cp CNAME docs/
cd docs/

# if you are deploying to a custom domain
# echo 'www.example.com' > CNAME

git init
git add -A
git commit -m 'deploy doc'

# if you are deploying to https://<USERNAME>.github.io
# git push -f git@github.com:<USERNAME>/<USERNAME>.github.io.git master

# if you are deploying to https://<USERNAME>.github.io/<REPO>
# git push -f https://github.com/Youjingyu/clinic-doc-zh.git master:gh-pages
git push -f https://github.com/darukjs/daruk.git master:gh-pages

cd -
1 change: 1 addition & 0 deletions docs/CNAME
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
doc.darukjs.com
1 change: 1 addition & 0 deletions docs/assets/css/main.css

Large diffs are not rendered by default.

Binary file added docs/assets/images/icons.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/icons@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/widgets.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/images/widgets@2x.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 2c45db4

Please sign in to comment.