Marble.js 项目教程

Marble.js 项目教程

marble Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS. 项目地址: https://gitcode.com/gh_mirrors/ma/marble

1. 项目的目录结构及介绍

Marble.js 项目的目录结构如下:

marble/
├── assets/
├── benchmarks/
├── packages/
├── scripts/
├── .commitlintrc.js
├── .editorconfig
├── .eslintignore
├── .eslintrc.js
├── .gitignore
├── .istanbul.yml
├── LICENSE
├── README.md
├── SECURITY.md
├── codecov.yml
├── docker-compose.yml
├── jest.config.js
├── lerna.json
├── package.json
├── tsconfig.json
├── tsconfig.test.json
└── yarn.lock

目录结构介绍

  • assets/: 存放项目相关的静态资源文件。
  • benchmarks/: 存放性能测试相关的文件。
  • packages/: 存放项目的各个模块,如核心模块、HTTP模块、WebSocket模块等。
  • scripts/: 存放项目的脚本文件,用于自动化任务。
  • .commitlintrc.js: 配置文件,用于规范Git提交信息。
  • .editorconfig: 配置文件,用于统一代码编辑器的设置。
  • .eslintignore: 配置文件,用于指定ESLint忽略的文件或目录。
  • .eslintrc.js: 配置文件,用于配置ESLint规则。
  • .gitignore: 配置文件,用于指定Git忽略的文件或目录。
  • .istanbul.yml: 配置文件,用于配置代码覆盖率工具Istanbul。
  • LICENSE: 项目的开源许可证文件。
  • README.md: 项目的介绍文档。
  • SECURITY.md: 项目的安全相关文档。
  • codecov.yml: 配置文件,用于配置代码覆盖率服务Codecov。
  • docker-compose.yml: 配置文件,用于配置Docker容器。
  • jest.config.js: 配置文件,用于配置Jest测试框架。
  • lerna.json: 配置文件,用于配置Lerna多包管理工具。
  • package.json: 项目的npm配置文件,包含项目的依赖、脚本等信息。
  • tsconfig.json: 配置文件,用于配置TypeScript编译选项。
  • tsconfig.test.json: 配置文件,用于配置TypeScript测试编译选项。
  • yarn.lock: 锁定文件,用于锁定项目依赖的版本。

2. 项目的启动文件介绍

Marble.js 项目的启动文件通常位于 packages/ 目录下的某个模块中。以 @marblejs/core 模块为例,启动文件通常是一个 TypeScript 文件,例如 main.ts

启动文件示例

import { createServer } from '@marblejs/core';
import { logger$ } from '@marblejs/middleware-logger';
import { bodyParser$ } from '@marblejs/middleware-body';
import { httpListener } from '@marblejs/http';
import { api$ } from './api';

const middlewares = [
  logger$(),
  bodyParser$(),
];

const effects = [
  api$,
];

const listener = httpListener({
  middlewares,
  effects,
});

const server = createServer({
  port: 1337,
  hostname: '127.0.0.1',
  listener,
});

server.run();

启动文件介绍

  • createServer: 创建HTTP服务器的函数,配置端口、主机名等参数。
  • logger$: 日志中间件,用于记录HTTP请求和响应。
  • bodyParser$: 请求体解析中间件,用于解析HTTP请求体。
  • httpListener: 配置HTTP监听器,包含中间件和路由效果。
  • api$: 定义API路由的效果函数。

3. 项目的配置文件介绍

Marble.js 项目的配置文件主要包括以下几个:

1. .commitlintrc.js

module.exports = {
  extends: ['@commitlint/config-conventional'],
};

2. .editorconfig

root = true

[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

3. .eslintrc.js

module.exports = {
  extends: ['eslint:recommended'],
  parserOptions: {
    ecmaVersion: 2020,
    sourceType: 'module',
  },
  rules: {
    // 自定义规则
  },
};

4. .gitignore

node_modules/
dist/
*.log

5. .istanbul.yml

instrumentation:
  root: src
  excludes: ['**/*.spec.ts']

6. package.json

{
  "name": "marblejs",
  "version": "1.0.0",
  "scripts": {
    "start": "node dist/main.js",
    "build": "tsc",
    "test": "jest"
  },
  "dependencies": {
    "@marblejs/core": "^4.0.0",
    "@marblejs/http": "^4.0.0"
  },
  "devDependencies": {
    "typescript": "^4.0.0",
    "jest": "^26.0.0"
  }
}

7. tsconfig.json

{
  "compilerOptions": {
    "target": "ES2020",
    "module": "commonjs",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "**/*.spec.ts"]
}

8. tsconfig.test.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "module": "commonjs",
    "types": ["jest"]
  },
  "include": ["src/**/*.spec.ts"]
}

配置文件介绍

  • .commitlintrc.js: 配置Git提交信息的规范。
  • .editorconfig: 配置代码编辑器的统一设置。
  • .eslintrc.js: 配置ESLint规则。
  • .gitignore: 指定Git忽略的文件或目录。
  • .istanbul.yml: 配置代码覆盖率工具Istanbul。
  • package.json: 项目的npm配置文件,包含项目的依赖、脚本等信息。
  • tsconfig.json: 配置TypeScript编译选项。
  • tsconfig.test.json: 配置TypeScript测试编译选项。

通过以上配置文件,可以确保项目在开发、测试、部署等各个环节的一致性和规范性。

marble Marble.js - functional reactive Node.js framework for building server-side applications, based on TypeScript and RxJS. 项目地址: https://gitcode.com/gh_mirrors/ma/marble

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卢颜娜

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值