Skip to content

Commit

Permalink
refactor: monorepo structure (#1082)
Browse files Browse the repository at this point in the history
  • Loading branch information
Innei authored Jun 4, 2023
1 parent 92a5460 commit ffdc153
Show file tree
Hide file tree
Showing 376 changed files with 848 additions and 381 deletions.
6 changes: 5 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ module.exports = {
},
overrides: [
{
files: ['src/migration/**/*.ts', 'src/modules/serverless/pack/**/*.ts'],
files: [
'apps/core/src/migration/**/*.ts',
'apps/core/src/modules/serverless/pack/**/*.ts',
'apps/core/test/**/*.ts',
],
rules: {
'import/no-default-export': 'off',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions

name: Node.js Build CI
name: Build (core)

on:
push:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,24 @@ jobs:
with:
version: 8.x
run_install: true

- name: Test
working-directory: ./apps/core
timeout-minutes: 10
run: |
npm run lint
npm run test
- name: Build project
working-directory: ./apps/core
run: |
pnpm run bundle
- name: Test Bundle Server
run: |
bash scripts/workflow/test-server.sh
- name: Zip Assets
run: |
sh scripts/zip-asset.sh
sh apps/core/zip-asset.sh
- name: Create Release
id: create_release
uses: actions/create-release@v1
Expand Down Expand Up @@ -136,7 +139,7 @@ jobs:
pnpm run bundle
- name: Zip Assets
run: |
sh scripts/zip-asset.sh
sh apps/core/zip-asset.sh
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
Expand Down
14 changes: 10 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,17 @@ jobs:
- uses: pnpm/[email protected]
with:
version: 8.x
run_install: true
- name: Run Test
run_install: false
- name: Install Dependencies
run: |
yarn lint
yarn test
pnpm i
- name: Run Lint
run: |
npm run lint
- name: Run Tests
run: |
npm run test
env:
CI: true
8 changes: 0 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,3 @@ assets

scripts/workflow/docker-compose.yml
scripts/workflow/data

schema.gql

app.config.js

webpack-dist

admin/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ node index.js
## 开发环境

```
git clone https://github.com/mx-space/mx-server
cd mx-server
git clone https://github.com/mx-space/core mx-core
cd mx-core
pnpm i
pnpm dev
```
Expand Down
10 changes: 10 additions & 0 deletions apps/core/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
schema.gql

app.config.js

webpack-dist

./admin
dist

tmp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const { join } = require('path')
const { fetch, $ } = require('zx-cjs')
const {
dashboard: { repo, version },
} = require('../package.json')
} = require('./package.json')

const endpoint = `https://api.github.com/repos/${repo}/releases/tags/v${version}`
!(async () => {
Expand Down
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions apps/core/external/pino/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// why this, because we dont need pino logger, and this logger can not bundle whole package into only one file with ncc.
// only work with fastify v4+ with pino v8+

module.exports = {
symbols: {
// https://github.com/pinojs/pino/blob/master/lib/symbols.js
serializersSym: Symbol.for('pino.serializers'),
},
stdSerializers: {
error: function asErrValue(err) {
const obj = {
type: err.constructor.name,
msg: err.message,
stack: err.stack,
}
for (const key in err) {
if (obj[key] === undefined) {
obj[key] = err[key]
}
}
return obj
},
},
}
4 changes: 4 additions & 0 deletions apps/core/external/pino/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "pino",
"main": "./index.js"
}
1 change: 1 addition & 0 deletions apps/core/external/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is folder used to override dependencies.
3 changes: 3 additions & 0 deletions apps/core/external/request/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// why do this.
// we dont need request, because we get image color only by buffer, and we dont need send request.
module.exports = {}
4 changes: 4 additions & 0 deletions apps/core/external/request/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "request",
"main": "index.js"
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ const axios = require('axios')
const { fs } = require('zx-cjs')
const {
dashboard: { repo },
} = require('../package.json')
const Package = require('../package.json')
} = require('./package.json')
const Package = require('../../package.json')
const endpoint = `https://api.github.com/repos/${repo}/releases/latest`

const latestVersion = async () => {
Expand All @@ -17,7 +17,7 @@ async function main() {
Package.dashboard.version = version

await fs.writeFile(
resolve(__dirname, '../package.json'),
resolve(__dirname, './package.json'),
JSON.stringify(Package, null, 2),
)

Expand Down
1 change: 1 addition & 0 deletions global.d.ts → apps/core/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Consola } from 'consola'
import { Document, PaginateModel } from 'mongoose'

import 'zx-cjs/globals'

import { ModelType } from '@typegoose/typegoose/lib/types'
Expand Down
File renamed without changes.
163 changes: 163 additions & 0 deletions apps/core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
{
"name": "@mx-space/core",
"version": "4.0.2",
"author": "Innei <https://innei.ren>",
"private": true,
"license": "AGPLv3",
"dashboard": {
"repo": "mx-space/mx-admin",
"version": "3.30.3"
},
"repository": {
"directory": "mx-space/core",
"url": "https://github.com/mx-space/core"
},
"homepage": "https://github.com/mx-space/core#readme",
"issues": "https://github.com/mx-space/core/issues",
"scripts": {
"prebuild": "rimraf dist",
"build": "nest build",
"build:webpack": "nest build --webpack --webpackPath ./configs/webpack.config.js -c ./configs/nest-cli.webpack.json",
"dev": "npm run start",
"repl": "npm run start -- --entryFile repl",
"bundle": "rimraf out && npm run build && cd dist/src && npx ncc build main.js -o ../../out -m -t && cd ../.. && chmod +x out/index.js",
"format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" \"packages/**/*.ts\"",
"start": "cross-env NODE_ENV=development nest start -w --path tsconfig.json -- ",
"start:debug": "cross-env NODE_ENV=development nest start --debug --watch",
"start:cluster": "cross-env NODE_ENV=development nest start --watch -- --cluster --workers 2",
"start:prod": "cross-env NODE_ENV=production node dist/src/main",
"lint": "eslint \"{src,apps,libs,test,packages}/**/*.ts\" --fix",
"prod": "cross-env NODE_ENV=production pm2-runtime start ecosystem.config.js",
"prod:pm2": "cross-env NODE_ENV=production pm2 restart ecosystem.config.js",
"prod:stop": "pm2 stop ecosystem.config.js",
"prod:debug": "cross-env NODE_ENV=production nest start --debug --watch",
"test": "NODE_ENV=development vitest",
"test:watch": "NODE_ENV=development vitest -w",
"docs": "npx @compodoc/compodoc -p tsconfig.json -s -d docs"
},
"bump": {
"before": [
"git pull --rebase",
"pnpm i",
"node scripts/get-latest-admin-version.js"
],
"after": [
"sh ./scripts/assets-push.sh"
],
"changelog": true
},
"dependencies": {
"@algolia/client-search": "^4.17.1",
"@babel/core": "7.22.1",
"@babel/plugin-transform-modules-commonjs": "7.21.5",
"@babel/plugin-transform-typescript": "7.22.3",
"@babel/types": "^7.22.4",
"@fastify/cookie": "8.3.0",
"@fastify/multipart": "7.6.0",
"@fastify/static": "6.10.2",
"@innei/next-async": "0.3.0",
"@nestjs/cache-manager": "1.0.0",
"@nestjs/common": "9.4.2",
"@nestjs/core": "9.4.2",
"@nestjs/event-emitter": "1.4.1",
"@nestjs/mapped-types": "^1.2.2",
"@nestjs/platform-fastify": "9.4.2",
"@nestjs/platform-socket.io": "9.4.2",
"@nestjs/schedule": "2.2.2",
"@nestjs/throttler": "4.0.0",
"@nestjs/websockets": "9.4.2",
"@socket.io/redis-adapter": "7.2.0",
"@socket.io/redis-emitter": "4.1.1",
"@typegoose/auto-increment": "3.2.0",
"@typegoose/typegoose": "11.2.0",
"@types/jsonwebtoken": "9.0.2",
"algoliasearch": "4.17.1",
"axios": "^1.4.0",
"axios-retry": "3.5.0",
"bcrypt": "5.1.0",
"cache-manager": "4.1.0",
"cache-manager-ioredis": "2.1.0",
"class-transformer": "0.5.1",
"class-validator": "0.13.2",
"class-validator-jsonschema": "npm:@innei/[email protected]",
"commander": "10.0.1",
"consola": "*",
"dayjs": "1.11.8",
"ejs": "3.1.9",
"form-data": "4.0.0",
"get-image-colors": "4.0.1",
"image-size": "1.0.2",
"inquirer": "*",
"isbot": "3.6.10",
"js-yaml": "*",
"json5": "2.2.3",
"jsonwebtoken": "9.0.0",
"jszip": "3.10.1",
"linkedom": "0.14.26",
"lodash": "*",
"lru-cache": "9.1.1",
"marked": "5.0.4",
"mime-types": "*",
"mkdirp": "*",
"mongoose": "7.2.2",
"mongoose-aggregate-paginate-v2": "1.0.6",
"mongoose-autopopulate": "1.0.1",
"mongoose-lean-getters": "1.1.0",
"mongoose-lean-id": "0.5.0",
"mongoose-lean-virtuals": "0.9.1",
"mongoose-paginate-v2": "1.7.1",
"nanoid": "3.3.4",
"node-machine-id": "1.1.12",
"node-pty": "0.10.1",
"nodemailer": "6.9.3",
"pluralize": "*",
"qs": "6.11.2",
"reflect-metadata": "0.1.13",
"rxjs": "7.8.1",
"semver": "7.5.1",
"slugify": "1.6.6",
"snakecase-keys": "5.4.5",
"ua-parser-js": "1.0.35",
"vm2": "3.9.19",
"wildcard-match": "5.1.2",
"xss": "1.0.14",
"zx-cjs": "7.0.7-0"
},
"devDependencies": {
"@nestjs/cli": "9.5.0",
"@nestjs/schematics": "9.2.0",
"@nestjs/testing": "9.4.2",
"@swc/core": "1.3.4",
"@types/babel__core": "7.20.1",
"@types/bcrypt": "5.0.0",
"@types/cache-manager": "4.0.2",
"@types/cron": "2.0.1",
"@types/ejs": "3.1.2",
"@types/get-image-colors": "4.0.2",
"@types/js-yaml": "4.0.5",
"@types/lodash": "4.14.195",
"@types/marked": "4.3.1",
"@types/mime-types": "2.1.1",
"@types/mongoose-aggregate-paginate-v2": "1.0.9",
"@types/node": "18.16.16",
"@types/nodemailer": "6.4.8",
"@types/qs": "6.9.7",
"@types/semver": "7.5.0",
"@types/ua-parser-js": "0.7.36",
"@types/validator": "13.7.17",
"@vercel/ncc": "0.36.1",
"cron": "*",
"husky": "8.0.3",
"ioredis": "5.3.2",
"rollup-plugin-swc": "0.2.1",
"socket.io": "4.6.2",
"vite": "3.2.5",
"vite-tsconfig-paths": "4.2.0",
"vitest": "0.25.3",
"zx": "7.2.2"
},
"optionalDependencies": {
"mongodb-memory-server": "*",
"redis-memory-server": "*"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* @module decorator/cache
* @author Surmon <https://github.com/surmon-china>
*/
import { CacheKey, CacheTTL, SetMetadata } from '@nestjs/common'
import { CacheKey, CacheTTL } from '@nestjs/cache-manager'
import { SetMetadata } from '@nestjs/common'

import * as META from '~/constants/meta.constant'

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { omit } from 'lodash'

import { CacheKey, CacheTTL, Get, Query } from '@nestjs/common'
import { CacheKey, CacheTTL } from '@nestjs/cache-manager'
import { Get, Query } from '@nestjs/common'

import { ApiController } from '~/common/decorators/api-controller.decorator'
import { Auth } from '~/common/decorators/auth.decorator'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import xss from 'xss'

import { CacheKey, CacheTTL, Controller, Get, Header } from '@nestjs/common'
import { CacheKey, CacheTTL } from '@nestjs/cache-manager'
import { Controller, Get, Header } from '@nestjs/common'

import { HTTPDecorators } from '~/common/decorators/http.decorator'
import { CacheKeys } from '~/constants/cache.constant'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CacheKey, CacheTTL, Controller, Get, Header } from '@nestjs/common'
import { CacheKey, CacheTTL } from '@nestjs/cache-manager'
import { Controller, Get, Header } from '@nestjs/common'

import { HTTPDecorators } from '~/common/decorators/http.decorator'
import { CacheKeys } from '~/constants/cache.constant'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* @module processor/cache/module
* @author Surmon <https://github.com/surmon-china>
*/
import { Global, Module, CacheModule as NestCacheModule } from '@nestjs/common'
import { CacheModule as NestCacheModule } from '@nestjs/cache-manager'
import { Global, Module } from '@nestjs/common'

import { CacheService } from './cache.service'
import { RedisConfigService } from './redis.config.service'
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit ffdc153

Please sign in to comment.