jenkins-pipeline-generator 1.0.0
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/.vscode/settings.json +7 -0
- package/README.md +39 -0
- package/bin/cli.js +144 -0
- package/example-config.json +12 -0
- package/package.json +30 -0
- package/prod-config.json +12 -0
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Jenkins Pipeline Generator
|
|
2
|
+
|
|
3
|
+
自動生成 Jenkinsfile 的 CLI 工具
|
|
4
|
+
|
|
5
|
+
## 安裝
|
|
6
|
+
|
|
7
|
+
### 本地使用
|
|
8
|
+
```bash
|
|
9
|
+
npm install
|
|
10
|
+
npm link
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### 發佈到 npm 後安裝
|
|
14
|
+
```bash
|
|
15
|
+
npm install -g jenkins-pipeline-generator
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## 使用方式
|
|
19
|
+
|
|
20
|
+
### 互動式生成
|
|
21
|
+
```bash
|
|
22
|
+
jenkins-gen generate
|
|
23
|
+
# 或使用簡寫
|
|
24
|
+
jenkins-gen gen
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## 指令列表
|
|
28
|
+
|
|
29
|
+
| 指令 | 說明 |
|
|
30
|
+
|------|------|
|
|
31
|
+
| `jenkins-gen generate` | 互動式生成 Jenkinsfile |
|
|
32
|
+
| `jenkins-gen --help` | 顯示幫助 |
|
|
33
|
+
|
|
34
|
+
## 範例
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
# 快速開始
|
|
38
|
+
jenkins-gen gen
|
|
39
|
+
```
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { program } from 'commander';
|
|
4
|
+
import inquirer from 'inquirer';
|
|
5
|
+
import fs from 'fs';
|
|
6
|
+
import path from 'path';
|
|
7
|
+
|
|
8
|
+
program
|
|
9
|
+
.version('1.0.0')
|
|
10
|
+
.description('Jenkins Pipeline Configuration Generator');
|
|
11
|
+
|
|
12
|
+
program
|
|
13
|
+
.command('generate')
|
|
14
|
+
.alias('gen')
|
|
15
|
+
.description('Generate Jenkinsfile with interactive prompts')
|
|
16
|
+
.option('-o, --output <path>', 'Output file path', 'Jenkinsfile')
|
|
17
|
+
.action(async (options) =>
|
|
18
|
+
{
|
|
19
|
+
try
|
|
20
|
+
{
|
|
21
|
+
const answers = await inquirer.prompt([
|
|
22
|
+
{
|
|
23
|
+
type: 'input',
|
|
24
|
+
name: 'projectCode',
|
|
25
|
+
message: '* 請輸入專案代碼',
|
|
26
|
+
default: 'HSF',
|
|
27
|
+
validate: (input) => input.trim() !== '' || 'Project code is required'
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
type: 'number',
|
|
31
|
+
name: 'pipelineTimeout',
|
|
32
|
+
message: '* 請輸入Jenkins Timeout 時間 (單位:minutes):',
|
|
33
|
+
default: 20,
|
|
34
|
+
validate: (input) => input > 0 || 'Must be greater than 0'
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
type: 'input',
|
|
38
|
+
name: 'gameConfig',
|
|
39
|
+
message: '* 請輸入Game Config Path(遊戲Config設定檔):',
|
|
40
|
+
default: 'Model.Cocos/assets/Json/GameConfig.json'
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
type: 'input',
|
|
44
|
+
name: 'buildTarget',
|
|
45
|
+
message: '* 請輸入Build Target:',
|
|
46
|
+
default: 'Model.Cocos'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'input',
|
|
50
|
+
name: 'buildConfig',
|
|
51
|
+
message: '* 請輸入Build Config Path:',
|
|
52
|
+
default: 'Model.Cocos/BuildConfig.json'
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
type: 'input',
|
|
56
|
+
name: 'cocosVersion',
|
|
57
|
+
message: 'Cocos Engine Version:',
|
|
58
|
+
default: '3.8.3'
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
type: 'list',
|
|
62
|
+
name: 'environment',
|
|
63
|
+
message: 'Environment:',
|
|
64
|
+
choices: ['Test', 'Release'],
|
|
65
|
+
default: 'Test'
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
type: 'input',
|
|
69
|
+
name: 'bucketName',
|
|
70
|
+
message: 'GCP Bucket Name:',
|
|
71
|
+
default: 'ws-cocos-web-pdd5-slot-data'
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
type: 'input',
|
|
75
|
+
name: 'deployPath',
|
|
76
|
+
message: '* 請輸入Deploy Path(部署路徑):',
|
|
77
|
+
default: 'MahjongTag'
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
type: 'confirm',
|
|
81
|
+
name: 'forceConnect',
|
|
82
|
+
message: '* 請輸入Force Connect(是否強制設定連線 會將Config ConnectMode 設定為2):',
|
|
83
|
+
default: true
|
|
84
|
+
}
|
|
85
|
+
]);
|
|
86
|
+
|
|
87
|
+
const jenkinsfile = generateJenkinsfile(answers);
|
|
88
|
+
const outputPath = path.resolve(options.output);
|
|
89
|
+
|
|
90
|
+
fs.writeFileSync(outputPath, jenkinsfile, 'utf8');
|
|
91
|
+
console.log(`\n建立 Jenkinsfile 成功,檔案位置: ${outputPath}`);
|
|
92
|
+
|
|
93
|
+
} catch (error)
|
|
94
|
+
{
|
|
95
|
+
console.error('Error generating Jenkinsfile:', error.message);
|
|
96
|
+
process.exit(1);
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
function generateJenkinsfile(config)
|
|
101
|
+
{
|
|
102
|
+
return `@Library('ShareLib') _
|
|
103
|
+
jenkinsPipeline {
|
|
104
|
+
PROJECT_CODE = '${config.projectCode}'
|
|
105
|
+
|
|
106
|
+
PipelineTimeout = ${config.pipelineTimeout} //設定 Pipeline 最長執行時間(分鐘)
|
|
107
|
+
/***
|
|
108
|
+
** GAME_CONFIG
|
|
109
|
+
***/
|
|
110
|
+
GAME_CONFIG = '${config.gameConfig}'
|
|
111
|
+
|
|
112
|
+
/***
|
|
113
|
+
** 專案路徑
|
|
114
|
+
***/
|
|
115
|
+
BUILD_TARGET = '${config.buildTarget}'
|
|
116
|
+
/***
|
|
117
|
+
** Cocos專案路徑
|
|
118
|
+
***/
|
|
119
|
+
BUILD_CONFIG = '${config.buildConfig}'
|
|
120
|
+
/***
|
|
121
|
+
** Cocos Engine 版本
|
|
122
|
+
***/
|
|
123
|
+
COCOS_VERSION = '${config.cocosVersion}'
|
|
124
|
+
/***
|
|
125
|
+
** 上傳到 GCP 的參數
|
|
126
|
+
***/
|
|
127
|
+
CocosWebUploadGcp = [
|
|
128
|
+
'Environment': '${config.environment}',
|
|
129
|
+
//要佈署的目錄名稱(自動產稱)
|
|
130
|
+
'BucketName': '${config.bucketName}',
|
|
131
|
+
//要佈署的目錄名稱(自動產稱)
|
|
132
|
+
'DeployPath': "${config.deployPath}",
|
|
133
|
+
'ForceConnect': ${config.forceConnect}
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
program.parse(process.argv);
|
|
140
|
+
|
|
141
|
+
if (!process.argv.slice(2).length)
|
|
142
|
+
{
|
|
143
|
+
program.outputHelp();
|
|
144
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"projectCode": "HSF",
|
|
3
|
+
"pipelineTimeout": 20,
|
|
4
|
+
"gameConfig": "Model.Cocos/assets/Json/GameConfig.json",
|
|
5
|
+
"buildTarget": "Model.Cocos",
|
|
6
|
+
"buildConfig": "Model.Cocos/BuildConfig.json",
|
|
7
|
+
"cocosVersion": "3.8.3",
|
|
8
|
+
"environment": "Test",
|
|
9
|
+
"bucketName": "ws-cocos-web-pdd5-slot-data",
|
|
10
|
+
"deployPath": "MahjongTag",
|
|
11
|
+
"forceConnect": true
|
|
12
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "jenkins-pipeline-generator",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "CLI tool to generate Jenkinsfile for Cocos projects",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"jenkins-gen": "bin/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"scripts": {
|
|
10
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"jenkins",
|
|
14
|
+
"jenkinsfile",
|
|
15
|
+
"cocos",
|
|
16
|
+
"pipeline",
|
|
17
|
+
"generator",
|
|
18
|
+
"cli"
|
|
19
|
+
],
|
|
20
|
+
"author": "",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/WaninRichardHsu/jenkins-pipeline-generator.git"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"commander": "^14.0.2",
|
|
28
|
+
"inquirer": "^10.2.2"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/prod-config.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
{
|
|
2
|
+
"projectCode": "HSF",
|
|
3
|
+
"pipelineTimeout": 20,
|
|
4
|
+
"gameConfig": "Model.Cocos/assets/Json/GameConfig.json",
|
|
5
|
+
"buildTarget": "Model.Cocos",
|
|
6
|
+
"buildConfig": "Model.Cocos/BuildConfig.json",
|
|
7
|
+
"cocosVersion": "3.8.3",
|
|
8
|
+
"environment": "Test",
|
|
9
|
+
"bucketName": "ws-cocos-web-pdd5-slot-data",
|
|
10
|
+
"deployPath": "MahjongTag",
|
|
11
|
+
"forceConnect": true
|
|
12
|
+
}
|