cmyr-template-cli 1.32.2 → 1.32.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/plopfile.js
CHANGED
|
@@ -148,7 +148,7 @@ const TEMPLATES_META_LIST = [
|
|
|
148
148
|
language: 'typescript',
|
|
149
149
|
runtime: 'nodejs',
|
|
150
150
|
vueVersion: 0,
|
|
151
|
-
docker:
|
|
151
|
+
docker: true,
|
|
152
152
|
priority: 0,
|
|
153
153
|
},
|
|
154
154
|
{
|
|
@@ -433,7 +433,7 @@ async function initProject(answers) {
|
|
|
433
433
|
}
|
|
434
434
|
async function init(projectPath, answers) {
|
|
435
435
|
var _a;
|
|
436
|
-
const { template, isOpenSource, isInitReadme, isInitContributing, isInitHusky, isInitSemanticRelease, isInitDocker,
|
|
436
|
+
const { template, isOpenSource, isInitReadme, isInitContributing, isInitHusky, isInitSemanticRelease, isInitDocker, isInitTest } = answers;
|
|
437
437
|
try {
|
|
438
438
|
const templateMeta = getTemplateMeta(template);
|
|
439
439
|
await asyncExec('git --version', {
|
|
@@ -477,8 +477,8 @@ async function init(projectPath, answers) {
|
|
|
477
477
|
await initTsconfig(projectPath, answers);
|
|
478
478
|
await initEslint(projectPath, answers);
|
|
479
479
|
await initStylelint(projectPath);
|
|
480
|
-
if (
|
|
481
|
-
await
|
|
480
|
+
if (isInitTest) {
|
|
481
|
+
await initTest(projectPath, answers);
|
|
482
482
|
}
|
|
483
483
|
await sortProjectJson(projectPath);
|
|
484
484
|
await initYarn(projectPath, answers);
|
|
@@ -1300,7 +1300,7 @@ async function initDocker(projectPath, answers) {
|
|
|
1300
1300
|
const loading = ora__default["default"]('正在初始化 Docker ……').start();
|
|
1301
1301
|
try {
|
|
1302
1302
|
const templateMeta = getTemplateMeta(answers.template);
|
|
1303
|
-
const files = ['.dockerignore', 'docker-compose.yml'];
|
|
1303
|
+
const files = ['.dockerignore', 'docker-compose.yml', '.github/workflows/docker.yml'];
|
|
1304
1304
|
await copyFilesFromTemplates(projectPath, files);
|
|
1305
1305
|
let dockerfile = 'Dockerfile';
|
|
1306
1306
|
const newPath = path__default["default"].join(projectPath, 'Dockerfile');
|
|
@@ -1319,7 +1319,7 @@ async function initDocker(projectPath, answers) {
|
|
|
1319
1319
|
if (!await fs__default["default"].pathExists(scriptsDir)) {
|
|
1320
1320
|
await fs__default["default"].mkdir(scriptsDir);
|
|
1321
1321
|
}
|
|
1322
|
-
await copyFilesFromTemplates(projectPath, ['scripts/minify-docker.
|
|
1322
|
+
await copyFilesFromTemplates(projectPath, ['scripts/minify-docker.cjs']);
|
|
1323
1323
|
}
|
|
1324
1324
|
const pkg = await getProjectJson(projectPath);
|
|
1325
1325
|
const mainFile = pkg === null || pkg === void 0 ? void 0 : pkg.main;
|
|
@@ -1347,35 +1347,69 @@ async function initDocker(projectPath, answers) {
|
|
|
1347
1347
|
loading.fail('Docker 初始化失败!');
|
|
1348
1348
|
}
|
|
1349
1349
|
}
|
|
1350
|
-
async function
|
|
1351
|
-
|
|
1350
|
+
async function initTest(projectPath, answers) {
|
|
1351
|
+
var _a, _b;
|
|
1352
|
+
const loading = ora__default["default"]('正在初始化测试 ……').start();
|
|
1352
1353
|
try {
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1354
|
+
if (answers.isInitTest === 'vitest') {
|
|
1355
|
+
const files = ['vitest.config.ts'];
|
|
1356
|
+
await copyFilesFromTemplates(projectPath, files);
|
|
1357
|
+
const pkg = await getProjectJson(projectPath);
|
|
1358
|
+
const devDependencies = {
|
|
1359
|
+
vitest: '^2.1.6',
|
|
1360
|
+
};
|
|
1361
|
+
if (!((_a = pkg === null || pkg === void 0 ? void 0 : pkg.dependencies) === null || _a === void 0 ? void 0 : _a.vite) && !((_b = pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies) === null || _b === void 0 ? void 0 : _b.vite)) {
|
|
1362
|
+
devDependencies.vite = '^6.0.1';
|
|
1363
|
+
}
|
|
1364
|
+
const newPkg = lodash.merge({}, pkg, {
|
|
1365
|
+
scripts: {
|
|
1366
|
+
test: 'vitest run',
|
|
1367
|
+
'test:coverage': 'vitest run --coverage',
|
|
1368
|
+
...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
|
|
1369
|
+
},
|
|
1370
|
+
devDependencies: {
|
|
1371
|
+
...devDependencies,
|
|
1372
|
+
...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
|
|
1373
|
+
},
|
|
1374
|
+
});
|
|
1375
|
+
await saveProjectJson(projectPath, newPkg);
|
|
1376
|
+
loading.succeed('Vitest 初始化成功!');
|
|
1377
|
+
return;
|
|
1378
|
+
}
|
|
1379
|
+
if (answers.isInitTest === 'jest') {
|
|
1380
|
+
const files = ['jest.config.ts'];
|
|
1381
|
+
await copyFilesFromTemplates(projectPath, files);
|
|
1382
|
+
const pkg = await getProjectJson(projectPath);
|
|
1383
|
+
const devDependencies = {
|
|
1384
|
+
'@types/jest': '^29.5.12',
|
|
1385
|
+
jest: '^29.7.0',
|
|
1386
|
+
'ts-jest': '^29.1.2',
|
|
1387
|
+
'ts-node': '^10.9.2',
|
|
1388
|
+
};
|
|
1389
|
+
const newPkg = lodash.merge({}, pkg, {
|
|
1390
|
+
scripts: {
|
|
1391
|
+
test: 'jest --config jest.config.ts',
|
|
1392
|
+
'test:coverage': 'jest --config jest.config.ts --coverage',
|
|
1393
|
+
...pkg === null || pkg === void 0 ? void 0 : pkg.scripts,
|
|
1394
|
+
},
|
|
1395
|
+
devDependencies: {
|
|
1396
|
+
...devDependencies,
|
|
1397
|
+
...pkg === null || pkg === void 0 ? void 0 : pkg.devDependencies,
|
|
1398
|
+
},
|
|
1399
|
+
});
|
|
1400
|
+
newPkg.jest = undefined;
|
|
1401
|
+
await saveProjectJson(projectPath, newPkg);
|
|
1402
|
+
loading.succeed('Jest 初始化成功!');
|
|
1403
|
+
return;
|
|
1404
|
+
}
|
|
1405
|
+
if (answers.isInitTest === 'none') {
|
|
1406
|
+
loading.succeed('未选择测试框架,跳过测试初始化');
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
loading.succeed('未选择测试框架,跳过测试初始化');
|
|
1376
1410
|
}
|
|
1377
1411
|
catch (error) {
|
|
1378
|
-
loading.fail('
|
|
1412
|
+
loading.fail('测试初始化失败!');
|
|
1379
1413
|
}
|
|
1380
1414
|
}
|
|
1381
1415
|
async function jsFileExtRename(projectPath) {
|
|
@@ -1693,7 +1727,11 @@ module.exports = function (plop) {
|
|
|
1693
1727
|
},
|
|
1694
1728
|
default(answers) {
|
|
1695
1729
|
const templateMeta = getTemplateMeta(answers.template);
|
|
1696
|
-
|
|
1730
|
+
if (!['nodejs'].includes(templateMeta === null || templateMeta === void 0 ? void 0 : templateMeta.runtime)) {
|
|
1731
|
+
return '';
|
|
1732
|
+
}
|
|
1733
|
+
const nodeVersion = Number(process.version.split('.')[0].slice(1)) - 4;
|
|
1734
|
+
return nodeVersion >= 18 ? 'esm' : 'cjs';
|
|
1697
1735
|
},
|
|
1698
1736
|
when(answers) {
|
|
1699
1737
|
const templateMeta = getTemplateMeta(answers.template);
|
|
@@ -1840,11 +1878,14 @@ module.exports = function (plop) {
|
|
|
1840
1878
|
},
|
|
1841
1879
|
},
|
|
1842
1880
|
{
|
|
1843
|
-
type: '
|
|
1844
|
-
name: '
|
|
1845
|
-
message: '
|
|
1881
|
+
type: 'list',
|
|
1882
|
+
name: 'isInitTest',
|
|
1883
|
+
message: '请选择测试框架',
|
|
1884
|
+
choices() {
|
|
1885
|
+
return ['vitest', 'jest', 'none'];
|
|
1886
|
+
},
|
|
1846
1887
|
default(answers) {
|
|
1847
|
-
return answers.isPublishToNpm;
|
|
1888
|
+
return answers.isPublishToNpm ? 'vitest' : 'none';
|
|
1848
1889
|
},
|
|
1849
1890
|
when(answers) {
|
|
1850
1891
|
return answers.isOpenSource;
|
package/package.json
CHANGED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
name: Publish Docker Image
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
branches:
|
|
7
|
+
- master
|
|
8
|
+
|
|
9
|
+
# 仅取消针对当前工作流正在进行的作业或运行
|
|
10
|
+
concurrency:
|
|
11
|
+
group: ${{ github.workflow }}-${{ github.ref }}
|
|
12
|
+
cancel-in-progress: true
|
|
13
|
+
|
|
14
|
+
jobs:
|
|
15
|
+
test:
|
|
16
|
+
name: Test
|
|
17
|
+
runs-on: ubuntu-latest
|
|
18
|
+
timeout-minutes: 10
|
|
19
|
+
steps:
|
|
20
|
+
- uses: actions/checkout@v4
|
|
21
|
+
- name: Setup pnpm
|
|
22
|
+
uses: pnpm/action-setup@v4
|
|
23
|
+
with:
|
|
24
|
+
version: "latest"
|
|
25
|
+
- name: Setup Node.js@lts environment
|
|
26
|
+
uses: actions/setup-node@v4
|
|
27
|
+
with:
|
|
28
|
+
node-version: "lts/*"
|
|
29
|
+
cache: "pnpm"
|
|
30
|
+
- name: Cache Dependency
|
|
31
|
+
uses: actions/cache@v4
|
|
32
|
+
with:
|
|
33
|
+
path: |
|
|
34
|
+
~/.npm
|
|
35
|
+
~/.yarn
|
|
36
|
+
~/.cache/pnpm
|
|
37
|
+
~/cache
|
|
38
|
+
!~/cache/exclude
|
|
39
|
+
**/node_modules
|
|
40
|
+
key: pnpm-${{ runner.os }}-${{ hashFiles('package.json') }}
|
|
41
|
+
restore-keys: pnpm-${{ runner.os }}
|
|
42
|
+
- run: pnpm i --frozen-lockfile
|
|
43
|
+
- run: pnpm run lint
|
|
44
|
+
- run: pnpm run build
|
|
45
|
+
- run: pnpm run test
|
|
46
|
+
build:
|
|
47
|
+
needs: test # 等待 test 执行成功
|
|
48
|
+
runs-on: ubuntu-latest
|
|
49
|
+
timeout-minutes: 30
|
|
50
|
+
permissions:
|
|
51
|
+
packages: write
|
|
52
|
+
contents: read
|
|
53
|
+
steps:
|
|
54
|
+
- uses: actions/checkout@v4
|
|
55
|
+
with:
|
|
56
|
+
persist-credentials: false
|
|
57
|
+
- name: Set up QEMU
|
|
58
|
+
uses: docker/setup-qemu-action@v3
|
|
59
|
+
- name: Set up Docker Buildx
|
|
60
|
+
uses: docker/setup-buildx-action@v3
|
|
61
|
+
- name: Login to GitHub Container Registry
|
|
62
|
+
uses: docker/login-action@v3
|
|
63
|
+
with:
|
|
64
|
+
registry: ghcr.io
|
|
65
|
+
username: ${{ github.actor }}
|
|
66
|
+
password: ${{ secrets.GITHUB_TOKEN }}
|
|
67
|
+
# - name: Login to Docker Hub
|
|
68
|
+
# uses: docker/login-action@v3
|
|
69
|
+
# with:
|
|
70
|
+
# username: ${{ secrets.DOCKER_USERNAME }}
|
|
71
|
+
# password: ${{ secrets.DOCKER_PASSWORD }}
|
|
72
|
+
# - name: Login to Alibaba Cloud Container Registry
|
|
73
|
+
# uses: docker/login-action@v3
|
|
74
|
+
# with:
|
|
75
|
+
# registry: registry.cn-hangzhou.aliyuncs.com
|
|
76
|
+
# username: ${{ secrets.ALIYUN_USERNAME }}
|
|
77
|
+
# password: ${{ secrets.ALIYUN_PASSWORD }}
|
|
78
|
+
- name: Extract Docker metadata
|
|
79
|
+
id: metadata
|
|
80
|
+
uses: docker/metadata-action@v5
|
|
81
|
+
with:
|
|
82
|
+
# 发布到 docker.io / ghcr.io / registry.cn-hangzhou.aliyuncs.com
|
|
83
|
+
# registry.cn-hangzhou.aliyuncs.com/${{ github.repository }}
|
|
84
|
+
images: |
|
|
85
|
+
${{ github.repository }}
|
|
86
|
+
ghcr.io/${{ github.repository }}
|
|
87
|
+
tags: |
|
|
88
|
+
type=raw,value=latest,enable=true
|
|
89
|
+
type=raw,value={{date 'YYYY-MM-DD' tz='Asia/Shanghai'}},enable=true
|
|
90
|
+
type=sha,format=short,prefix=sha-,enable=true
|
|
91
|
+
flavor: latest=false
|
|
92
|
+
- name: Build and push Docker images
|
|
93
|
+
uses: docker/build-push-action@v5
|
|
94
|
+
with:
|
|
95
|
+
context: .
|
|
96
|
+
file: ./Dockerfile
|
|
97
|
+
# 推送到 dockerhub
|
|
98
|
+
push: false
|
|
99
|
+
tags: ${{ steps.metadata.outputs.tags }}
|
|
100
|
+
labels: ${{ steps.metadata.outputs.labels }}
|
|
101
|
+
platforms: linux/amd64,linux/arm64
|
|
102
|
+
# - name: Docker Hub README & description sync
|
|
103
|
+
# uses: meeDamian/sync-readme@v1.0.6
|
|
104
|
+
# with:
|
|
105
|
+
# user: ${{ secrets.DOCKER_USERNAME }}
|
|
106
|
+
# pass: ${{ secrets.DOCKER_PASSWORD }}
|
|
107
|
+
# slug: ${{ github.repository }}
|
|
108
|
+
# description: "基于 Hono 和 TypeScript 的云函数模板"
|
package/templates/Dockerfile
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
FROM caomeiyouren/alpine-nodejs:latest AS nodejs
|
|
2
2
|
|
|
3
|
-
RUN npm config set registry https://registry.npmmirror.com && \
|
|
4
|
-
|
|
3
|
+
# RUN npm config set registry https://registry.npmmirror.com && \
|
|
4
|
+
# pnpm config set registry https://registry.npmmirror.com
|
|
5
5
|
|
|
6
6
|
FROM caomeiyouren/alpine-nodejs-minimize:latest AS runtime
|
|
7
7
|
|
|
@@ -28,7 +28,7 @@ RUN pnpm add @vercel/nft@0.24.4 fs-extra@11.2.0 --save-prod
|
|
|
28
28
|
COPY --from=builder /app /app
|
|
29
29
|
|
|
30
30
|
RUN export PROJECT_ROOT=/app/ && \
|
|
31
|
-
node /app/scripts/minify-docker.
|
|
31
|
+
node /app/scripts/minify-docker.cjs && \
|
|
32
32
|
rm -rf /app/node_modules /app/scripts && \
|
|
33
33
|
mv /app/app-minimal/node_modules /app/ && \
|
|
34
34
|
rm -rf /app/app-minimal
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import { defineConfig } from 'vitest/config'
|
|
3
|
+
|
|
4
|
+
export default defineConfig({
|
|
5
|
+
test: {
|
|
6
|
+
globals: true,
|
|
7
|
+
environment: 'node',
|
|
8
|
+
},
|
|
9
|
+
resolve: {
|
|
10
|
+
alias: {
|
|
11
|
+
'@': path.resolve(__dirname, 'src'),
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
root: path.resolve('./'),
|
|
15
|
+
coverage: {
|
|
16
|
+
clean: true,
|
|
17
|
+
reportsDirectory: path.resolve('./coverage'),
|
|
18
|
+
},
|
|
19
|
+
})
|
|
File without changes
|