Skip to content

Commit 91dd5c5

Browse files
authored
feat: add v4 template (#74)
* feat: add v4 template * test: fix v3/v4 * feat: Added Node.js CI workflow support for v3 and v4 builds * chore: update * fix: remove pnm * fix: dir * chore: update
1 parent 81e1765 commit 91dd5c5

32 files changed

+490
-33
lines changed

.github/workflows/nodejs.yml

Lines changed: 52 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,67 @@ name: Node.js CI
33
on: [push, pull_request]
44

55
jobs:
6-
build:
7-
6+
build-v3:
87
runs-on: ubuntu-latest
9-
108
strategy:
119
matrix:
12-
node-version: [16.x, 18.x]
13-
10+
node-version: [18.x]
1411
steps:
1512
- uses: actions/checkout@v2
1613
- name: Use Node.js ${{ matrix.node-version }}
1714
uses: actions/setup-node@v1
1815
with:
1916
node-version: ${{ matrix.node-version }}
20-
- run: npm install
21-
- run: npm run test
17+
- name: Install dependencies (v3)
18+
run: npm install
19+
- name: Test (v3)
20+
run: npm run test
21+
env:
22+
PKG_ROOT: v3
2223

23-
build-windows:
24+
build-v4:
25+
runs-on: ubuntu-latest
26+
strategy:
27+
matrix:
28+
node-version: [20.x]
29+
steps:
30+
- uses: actions/checkout@v2
31+
- name: Use Node.js ${{ matrix.node-version }}
32+
uses: actions/setup-node@v1
33+
with:
34+
node-version: ${{ matrix.node-version }}
35+
- name: Install dependencies (v4)
36+
run: npm install
37+
- name: Test (v4)
38+
run: npm run test
39+
env:
40+
PKG_ROOT: v4
2441

42+
build-v3-windows:
2543
runs-on: windows-latest
26-
2744
strategy:
2845
matrix:
29-
node-version: [16.x, 18.x]
46+
node-version: [18.x]
47+
steps:
48+
- name: Configure git
49+
run: git config --global core.autocrlf false
50+
- uses: actions/checkout@v2
51+
- name: Use Node.js ${{ matrix.node-version }}
52+
uses: actions/setup-node@v1
53+
with:
54+
node-version: ${{ matrix.node-version }}
55+
- name: Install dependencies (v3, Windows)
56+
run: npm install
57+
- name: Test (v3, Windows)
58+
run: npm run test
59+
env:
60+
PKG_ROOT: v3
3061

62+
build-v4-windows:
63+
runs-on: windows-latest
64+
strategy:
65+
matrix:
66+
node-version: [20.x]
3167
steps:
3268
- name: Configure git
3369
run: git config --global core.autocrlf false
@@ -36,5 +72,9 @@ jobs:
3672
uses: actions/setup-node@v1
3773
with:
3874
node-version: ${{ matrix.node-version }}
39-
- run: npm install
40-
- run: npm run test
75+
- name: Install dependencies (v4, Windows)
76+
run: npm install
77+
- name: Test (v4, Windows)
78+
run: npm run test
79+
env:
80+
PKG_ROOT: v4

lerna.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"packages": [
33
"v3/*",
4+
"v4/*",
45
"midway-boilerplate-list",
56
"create-midway"
67
],

midway-boilerplate-list/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,22 @@ module.exports = {
4141
package: "@midwayjs-examples/application-koa-esm-v3",
4242
group: "v3-esm",
4343
},
44+
"koa-v4": {
45+
desc: "A web application boilerplate with midway v4(koa), now in beta",
46+
package: "@midwayjs-examples/application-koa-v4",
47+
group: "v4(beta)",
48+
},
4449
web: {
4550
desc: "A web application boilerplate with midway and Egg.js",
4651
package: "@midwayjs-examples/application-web",
4752
group: "v2",
53+
hidden: true,
4854
},
4955
koa: {
5056
desc: "A web application boilerplate with midway and koa",
5157
package: "@midwayjs-examples/application-koa",
5258
group: "v2",
59+
hidden: true,
5360
},
5461
express: {
5562
desc: "A web application boilerplate with midway and express",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"scripts": {
1212
"release": "lerna publish",
1313
"test": "cross-env ./scripts/prepare.sh",
14-
"test_once": "cross-env ./scripts/prepare.sh v3/midway-framework-web",
14+
"test_once": "cross-env ./scripts/prepare.sh v4/midway-framework-koa",
1515
"build": "lerna run build"
1616
},
1717
"engines": {

scripts/prepare.sh

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,40 @@ tmpdir=$origin_cwd/tmp
99
rm -rf $tmpdir
1010
mkdir -p $tmpdir
1111

12-
if [ -z "$1" ]
12+
run_for_pkg() {
13+
pkg_path=$1
14+
pkg_name=${pkg_path#*/}
15+
cd $tmpdir
16+
echo $origin_cwd/$pkg_path
17+
node $generator_script $tmpdir/$pkg_name $origin_cwd/$pkg_path
18+
cd $pkg_name
19+
npm install
20+
npm run lint --if-present || exit 1
21+
npm run test || exit 1
22+
echo $tmpdir/$pkg_name
23+
}
24+
25+
if [ ! -z "$PKG_ROOT" ] && { [ "$PKG_ROOT" = "v3" ] || [ "$PKG_ROOT" = "v4" ]; }
1326
then
14-
# v3
1527
cwd=$origin_cwd
1628
cd $origin_cwd
17-
1829
rm -rf $tmpdir
1930
mkdir -p $tmpdir
20-
21-
pkgs=`find v3 -maxdepth 1 -mindepth 1`
22-
31+
pkgs=`find $PKG_ROOT -maxdepth 1 -mindepth 1`
2332
for pkg in $pkgs
2433
do
25-
cd $tmpdir
26-
echo $cwd/$pkg
27-
node $generator_script $tmpdir/${pkg#*/} $cwd/$pkg
28-
cd ${pkg#*/}
29-
npm install
30-
npm run lint --if-present || exit 1
31-
npm run test || exit 1
32-
echo $tmpdir/${pkg#*/}
34+
run_for_pkg $pkg
3335
done
36+
elif [ -z "$1" ]
37+
then
38+
# 兼容老逻辑,默认不处理
39+
echo "请通过 PKG_ROOT 指定目录或传入具体包路径"
40+
exit 1
3441
else
3542
cwd=$origin_cwd
3643
cd $tmpdir
3744
pkg=$1
38-
echo $cwd/$pkg
39-
node $generator_script $tmpdir/${pkg#*/} $cwd/$pkg
40-
cd ${pkg#*/}
41-
npm install
42-
npm run lint --if-present || exit 1
43-
npm run test || exit 1
45+
run_for_pkg $pkg
4446
fi
4547

4648
echo 'complete'

v4/midway-framework-koa/.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

v4/midway-framework-koa/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# midway koa boilerplate
2+
3+
midway for koa 脚手架。

v4/midway-framework-koa/after.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const fse = require('fs').promises;
2+
const { join } = require('path');
3+
4+
function random(start, end) {
5+
return Math.floor(Math.random() * (end - start) + start);
6+
}
7+
8+
module.exports = async options => {
9+
const currentFilePath = join(options.targetRoot, 'src/config/config.default.ts');
10+
let contents = await fse.readFile(currentFilePath, 'utf-8');
11+
contents = contents.replace('{{keys}}', Date.now() + '_' + random(100, 10000));
12+
13+
await fse.writeFile(currentFilePath, contents);
14+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# my_midway_project
2+
3+
## QuickStart
4+
5+
<!-- add docs here for user -->
6+
7+
see [midway docs][midway] for more detail.
8+
9+
### Development
10+
11+
```bash
12+
$ npm i
13+
$ npm run dev
14+
$ open http://localhost:7001/
15+
```
16+
17+
### Deploy
18+
19+
```bash
20+
$ npm start
21+
```
22+
23+
### npm scripts
24+
25+
- Use `npm run lint` to check code style.
26+
- Use `npm test` to run unit test.
27+
28+
29+
[midway]: https://midwayjs.org
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# my_midway_project
2+
3+
## 快速入门
4+
5+
<!-- 在此次添加使用文档 -->
6+
7+
如需进一步了解,参见 [midway 文档][midway]
8+
9+
### 本地开发
10+
11+
```bash
12+
$ npm i
13+
$ npm run dev
14+
$ open http://localhost:7001/
15+
```
16+
17+
### 部署
18+
19+
```bash
20+
$ npm start
21+
```
22+
23+
### 内置指令
24+
25+
- 使用 `npm run lint` 来做代码风格检查。
26+
- 使用 `npm test` 来执行单元测试。
27+
28+
29+
[midway]: https://midwayjs.org

0 commit comments

Comments
 (0)