修改一些目录结构

This commit is contained in:
周炽键 2021-08-16 22:29:43 +08:00
parent 6a1f9a3f6b
commit f7771815d8
9 changed files with 228 additions and 103 deletions

43
README.md Normal file
View File

@ -0,0 +1,43 @@
```shell
.
├── @types
│ └── index.d.ts
├── README.md
├── app.js
├── build # 构建脚本 在shell下直接执行 ./build
├── check-config # 检查启动环境所需的配置文件 ./check-config
├── ci # CI相关脚本一般是在CI容器里执行
│ └── build_tag.sh
├── dto
│ ├── admin.ts
│ └── init.ts
├── entity # ORM映射
│ └── user.ts
├── event.js # 全局事件管理工具
├── example.env # 环境变量示例文件
├── middlewares # 中间件
│ ├── ValidateDto.js # 验证DTO
│ ├── auth.js # 鉴权
│ └── page_auth.js
├── nodemon.json # nodemon配置
├── ormconfig.example.json # ORM配置示例文件
├── ormconfig.json # ORM配置
├── package.json
├── public
│ └── stylesheets
│ ├── style.css
│ └── style.less
├── routes # 路由
│ ├── admin.js
│ ├── index.js
│ └── users.js
├── tsconfig.json
├── utils
│ ├── auth.js # 鉴权工具加密生成token/解密token
│ └── id.ts # ID生成器
├── views
│ ├── error.hjs
│ └── index.hjs
├── www
└── yarn.lock
```

97
bin/www
View File

@ -1,97 +0,0 @@
#!/usr/bin/env node
/**
* Module dependencies.
*/
const {resolve} = require('path')
require('dotenv').config({ path:resolve(__dirname,'../.env') })
var app = require(resolve(__dirname,'../app'))
var debug = require('debug')('express-im:server')
var http = require('http')
const event = require(resolve(__dirname,'../event'))
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000')
app.set('port', port)
/**
* Create HTTP server.
*/
var server = http.createServer(app)
/**
* Listen on provided port, on all network interfaces.
*/
event.on('typeorm-connection',()=>{
server.listen(port,()=>{
console.log(`服务启动成功,监听端口${port}`)
})
})
server.on('error', onError)
server.on('listening', onListening)
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort (val) {
var port = parseInt(val, 10)
if (isNaN(port)) {
// named pipe
return val
}
if (port >= 0) {
// port number
return port
}
return false
}
/**
* Event listener for HTTP server "error" event.
*/
function onError (error) {
if (error.syscall !== 'listen') {
throw error
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges')
process.exit(1)
break
case 'EADDRINUSE':
console.error(bind + ' is already in use')
process.exit(1)
break
default:
throw error
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening () {
var addr = server.address()
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port
debug('Listening on ' + bind)
}

15
build Executable file
View File

@ -0,0 +1,15 @@
#!/bin/env node
const shell = require('shelljs')
const path = require('path')
const dist_dir_path = path.resolve(__dirname,'dist')
shell.rm('-rf',dist_dir_path)
shell.exec('tsc')
shell.exec('./check-config')
shell.cp('./.env',dist_dir_path)
shell.cp('./ormconfig.json',dist_dir_path)
shell.cp('-r','./views',dist_dir_path)

11
check-config Executable file
View File

@ -0,0 +1,11 @@
#!/bin/env node
const path = require('path')
const fs = require('fs')
if(!fs.existsSync(path.join(__dirname,'.env'))) {
throw new Error('环境变量文件 [ .env ] 不存在')
}
if(!fs.existsSync(path.join(__dirname,'ormconfig.json'))) {
throw new Error('orm配置文件 [ ormconfig.json ] 不存在')
}

View File

@ -1 +0,0 @@
PORT=5500

View File

@ -13,5 +13,5 @@
"NODE_ENV": "development"
},
"ext":"js,json,ts",
"exec":"ts-node ./bin/www"
"exec":"ts-node ./www"
}

View File

@ -1,10 +1,11 @@
{
"name": "express-my-admin",
"version": "0.0.0",
"name": "express-template",
"version": "0.0.1",
"private": true,
"repository": "git@git.zcj.plus:zhouchijian/express-my-admin.git",
"repository": "git@git.zcj.plus:zhouchijian/express-template.git",
"scripts": {
"build": "rm -rf dist && tsc && cp .env dist/.env && cp ormconfig.json dist/ormconfig.json && cp -r bin dist/bin && cp -r views ./dist/views",
"bu": "./build",
"start:prod": "cd dist && node ./bin/www",
"dev": "nodemon"
},
@ -23,6 +24,7 @@
"mysql": "^2.18.1",
"mysql2": "^2.2.5",
"reflect-metadata": "^0.1.13",
"shelljs": "^0.8.4",
"ts-node": "^10.1.0",
"typeorm": "^0.2.34"
},
@ -31,8 +33,10 @@
"@types/express": "^4.17.12",
"@types/http-errors": "^1.8.0",
"@types/less-middleware": "^2.0.31",
"@types/md5": "^2.3.1",
"@types/morgan": "^1.9.2",
"@types/node": "^15.12.3",
"@types/uuid": "^8.3.1",
"@typescript-eslint/eslint-plugin": "^4.27.0",
"@typescript-eslint/parser": "^4.27.0",
"eslint": "^7.29.0",

97
www Normal file
View File

@ -0,0 +1,97 @@
#!/usr/bin/env node
/**
* Module dependencies.
*/
const { resolve } = require('path')
const package = require('./package.json')
require('dotenv').config({ path:resolve(__dirname,'./.env') })
var app = require(resolve(__dirname,'./app'))
var debug = require('debug')(package.name + ':server')
var http = require('http')
const event = require(resolve(__dirname,'./event'))
/**
* Get port from environment and store in Express.
*/
var port = normalizePort(process.env.PORT || '3000')
app.set('port', port)
/**
* Create HTTP server.
*/
var server = http.createServer(app)
/**
* Listen on provided port, on all network interfaces.
*/
event.on('typeorm-connection',()=>{
server.listen(port,()=>{
console.log(`服务启动成功,监听端口${port}`)
})
})
server.on('error', onError)
server.on('listening', onListening)
/**
* Normalize a port into a number, string, or false.
*/
function normalizePort (val) {
var port = parseInt(val, 10)
if (isNaN(port)) {
// named pipe
return val
}
if (port >= 0) {
// port number
return port
}
return false
}
/**
* Event listener for HTTP server "error" event.
*/
function onError (error) {
if (error.syscall !== 'listen') {
throw error
}
var bind = typeof port === 'string'
? 'Pipe ' + port
: 'Port ' + port
// handle specific listen errors with friendly messages
switch (error.code) {
case 'EACCES':
console.error(bind + ' requires elevated privileges')
process.exit(1)
break
case 'EADDRINUSE':
console.error(bind + ' is already in use')
process.exit(1)
break
default:
throw error
}
}
/**
* Event listener for HTTP server "listening" event.
*/
function onListening () {
var addr = server.address()
var bind = typeof addr === 'string'
? 'pipe ' + addr
: 'port ' + addr.port
debug('Listening on ' + bind)
}

View File

@ -168,6 +168,13 @@
dependencies:
"@types/express" "*"
"@types/md5@^2.3.1":
version "2.3.1"
resolved "https://registry.yarnpkg.com/@types/md5/-/md5-2.3.1.tgz#010bcf3bb50a2cff3a574cb1c0b4051a9c67d6bc"
integrity sha512-OK3oe+ALIoPSo262lnhAYwpqFNXbiwH2a+0+Z5YBnkQEwWD8fk5+PIeRhYA48PzvX9I4SGNpWy+9bLj8qz92RQ==
dependencies:
"@types/node" "*"
"@types/mime@^1":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"
@ -208,6 +215,11 @@
"@types/mime" "^1"
"@types/node" "*"
"@types/uuid@^8.3.1":
version "8.3.1"
resolved "https://registry.yarnpkg.com/@types/uuid/-/uuid-8.3.1.tgz#1a32969cf8f0364b3d8c8af9cc3555b7805df14f"
integrity sha512-Y2mHTRAbqfFkpjldbkHGY8JIzRN6XqYRliG8/24FcHm2D2PwW24fl5xMRTVGdrb7iMrwCaIEbLWerGIkXuFWVg==
"@types/validator@^13.1.3":
version "13.6.3"
resolved "https://registry.yarnpkg.com/@types/validator/-/validator-13.6.3.tgz#31ca2e997bf13a0fffca30a25747d5b9f7dbb7de"
@ -1352,7 +1364,7 @@ glob-parent@^5.1.2, glob-parent@~5.1.2:
dependencies:
is-glob "^4.0.1"
glob@^7.1.3, glob@^7.1.6:
glob@^7.0.0, glob@^7.1.3, glob@^7.1.6:
version "7.1.7"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90"
integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==
@ -1598,6 +1610,11 @@ ini@~1.3.0:
resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.8.tgz#a29da425b48806f34767a4efce397269af28432c"
integrity sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==
interpret@^1.0.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.4.0.tgz#665ab8bc4da27a774a40584e812e3e0fa45b1a1e"
integrity sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==
ipaddr.js@1.9.1:
version "1.9.1"
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.9.1.tgz#bff38543eeb8984825079ff3a2a8e6cbd46781b3"
@ -1617,6 +1634,13 @@ is-ci@^2.0.0:
dependencies:
ci-info "^2.0.0"
is-core-module@^2.2.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/is-core-module/-/is-core-module-2.5.0.tgz#f754843617c70bfd29b7bd87327400cda5c18491"
integrity sha512-TXCMSDsEHMEEZ6eCA8rwRDbLu55MRGmrctljsBX/2v1d9/GzqHOxW5c5oPSgrUt2vBFXebu9rGqckXGPWOlYpg==
dependencies:
has "^1.0.3"
is-extglob@^2.1.1:
version "2.1.1"
resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-2.1.1.tgz#a88c02535791f02ed37c76a1b9ea9773c833f8c2"
@ -2187,6 +2211,11 @@ path-key@^3.1.0:
resolved "https://registry.yarnpkg.com/path-key/-/path-key-3.1.1.tgz#581f6ade658cbba65a0d3380de7753295054f375"
integrity sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==
path-parse@^1.0.6:
version "1.0.7"
resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.7.tgz#fbc114b60ca42b30d9daf5858e4bd68bbedb6735"
integrity sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==
path-to-regexp@0.1.7:
version "0.1.7"
resolved "https://registry.yarnpkg.com/path-to-regexp/-/path-to-regexp-0.1.7.tgz#df604178005f522f15eb4490e7247a1bfaa67f8c"
@ -2342,6 +2371,13 @@ readdirp@~3.6.0:
dependencies:
picomatch "^2.2.1"
rechoir@^0.6.2:
version "0.6.2"
resolved "https://registry.yarnpkg.com/rechoir/-/rechoir-0.6.2.tgz#85204b54dba82d5742e28c96756ef43af50e3384"
integrity sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=
dependencies:
resolve "^1.1.6"
reflect-metadata@^0.1.13:
version "0.1.13"
resolved "https://registry.yarnpkg.com/reflect-metadata/-/reflect-metadata-0.1.13.tgz#67ae3ca57c972a2aa1642b10fe363fe32d49dc08"
@ -2409,6 +2445,14 @@ resolve-from@^4.0.0:
resolved "https://registry.yarnpkg.com/resolve-from/-/resolve-from-4.0.0.tgz#4abcd852ad32dd7baabfe9b40e00a36db5f392e6"
integrity sha512-pb/MYmXstAkysRFx8piNI1tGFNQIFA3vkE3Gq4EuA1dF6gHp/+vgZqsCGJapvy8N3Q+4o7FwvquPJcnZ7RYy4g==
resolve@^1.1.6:
version "1.20.0"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.20.0.tgz#629a013fb3f70755d6f0b7935cc1c2c5378b1975"
integrity sha512-wENBPt4ySzg4ybFQW2TT1zMQucPK95HSh/nq2CFTZVOGut2+pQvSsgtda4d26YrYcr067wjbmzOG8byDPBX63A==
dependencies:
is-core-module "^2.2.0"
path-parse "^1.0.6"
responselike@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/responselike/-/responselike-1.0.2.tgz#918720ef3b631c5642be068f15ade5a46f4ba1e7"
@ -2538,6 +2582,15 @@ shebang-regex@^3.0.0:
resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-3.0.0.tgz#ae16f1644d873ecad843b0307b143362d4c42172"
integrity sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==
shelljs@^0.8.4:
version "0.8.4"
resolved "https://registry.yarnpkg.com/shelljs/-/shelljs-0.8.4.tgz#de7684feeb767f8716b326078a8a00875890e3c2"
integrity sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==
dependencies:
glob "^7.0.0"
interpret "^1.0.0"
rechoir "^0.6.2"
signal-exit@^3.0.2:
version "3.0.3"
resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.3.tgz#a1410c2edd8f077b08b4e253c8eacfcaf057461c"