electron-forge-maker-innosetup 0.3.0 → 0.3.1
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/README.md +154 -50
- package/dist/MakerInnosetup.d.ts +35 -0
- package/dist/MakerInnosetup.js +157 -1
- package/dist/types.d.ts +30 -2
- package/package.json +7 -3
package/README.md
CHANGED
|
@@ -8,25 +8,6 @@
|
|
|
8
8
|
npm install --save-dev electron-forge-maker-innosetup
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
## 前置要求
|
|
12
|
-
|
|
13
|
-
### 选项一:使用内置便携版(推荐)
|
|
14
|
-
|
|
15
|
-
将 Innosetup 便携版放置在 `vendor/innosetup/` 目录:
|
|
16
|
-
|
|
17
|
-
```
|
|
18
|
-
vendor/
|
|
19
|
-
└── innosetup/
|
|
20
|
-
├── ISCC.exe
|
|
21
|
-
├── ISCmplr.dll
|
|
22
|
-
├── Default.isl
|
|
23
|
-
└── Languages/
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
### 选项二:系统安装
|
|
27
|
-
|
|
28
|
-
需要在 Windows 系统上安装 [Innosetup](https://jrsoftware.org/isinfo.php)。
|
|
29
|
-
|
|
30
11
|
## 使用方法
|
|
31
12
|
|
|
32
13
|
### 导入方式
|
|
@@ -45,22 +26,74 @@ import {
|
|
|
45
26
|
} from "electron-forge-maker-innosetup";
|
|
46
27
|
```
|
|
47
28
|
|
|
48
|
-
###
|
|
29
|
+
### 🎉 方式一:使用相对路径
|
|
30
|
+
|
|
31
|
+
**为什么推荐?**
|
|
32
|
+
|
|
33
|
+
- **可移植** - 配置可在不同机器间共享
|
|
34
|
+
- **团队协作** - 每个开发者的路径可以不同
|
|
35
|
+
- **CI/CD 友好** - 自动化构建无需修改配置
|
|
49
36
|
|
|
50
37
|
在 `forge.config.ts` 中:
|
|
51
38
|
|
|
52
39
|
```typescript
|
|
53
40
|
import type { ForgeConfig } from "@electron-forge/shared-types";
|
|
54
|
-
import MakerInnosetup from "electron-forge-maker-innosetup";
|
|
41
|
+
import { MakerInnosetup } from "electron-forge-maker-innosetup";
|
|
55
42
|
|
|
56
43
|
const config: ForgeConfig = {
|
|
57
44
|
makers: [
|
|
58
45
|
new MakerInnosetup(
|
|
59
46
|
{
|
|
60
|
-
|
|
47
|
+
// 基本信息
|
|
48
|
+
appName: "My Electron App",
|
|
49
|
+
appVersion: "1.0.0",
|
|
61
50
|
appPublisher: "My Company",
|
|
62
|
-
|
|
51
|
+
|
|
52
|
+
// 使用相对路径 - 自动基于项目根目录解析
|
|
53
|
+
setupIconFile: "./assets/icons/icon.ico",
|
|
54
|
+
licenseFile: "./LICENSE",
|
|
55
|
+
|
|
63
56
|
createDesktopIcon: true,
|
|
57
|
+
|
|
58
|
+
config: {
|
|
59
|
+
// 使用占位符
|
|
60
|
+
Defines: {
|
|
61
|
+
MyAppName: "My Electron App",
|
|
62
|
+
MyAppExeName: "MyElectronApp.exe",
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
Setup: {
|
|
66
|
+
AppName: "{#MyAppName}",
|
|
67
|
+
// 相对路径会自动解析
|
|
68
|
+
SetupIconFile: "./assets/icons/icon.ico",
|
|
69
|
+
ArchitecturesAllowed: "x64compatible",
|
|
70
|
+
PrivilegesRequired: "admin",
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
Files: [
|
|
74
|
+
{
|
|
75
|
+
// {build} 占位符会被替换为 Electron Forge 的打包输出目录
|
|
76
|
+
Source: "{build}\\*",
|
|
77
|
+
DestDir: "{app}",
|
|
78
|
+
Flags: "ignoreversion recursesubdirs createallsubdirs",
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
|
|
82
|
+
Icons: [
|
|
83
|
+
{
|
|
84
|
+
Name: "{autoprograms}\\{#MyAppName}",
|
|
85
|
+
Filename: "{app}\\{#MyAppExeName}",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
|
|
89
|
+
Run: [
|
|
90
|
+
{
|
|
91
|
+
Filename: "{app}\\{#MyAppExeName}",
|
|
92
|
+
Description: "Launch {#MyAppName}",
|
|
93
|
+
Flags: "nowait postinstall skipifsilent",
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
},
|
|
64
97
|
},
|
|
65
98
|
["win32"]
|
|
66
99
|
),
|
|
@@ -70,7 +103,79 @@ const config: ForgeConfig = {
|
|
|
70
103
|
export default config;
|
|
71
104
|
```
|
|
72
105
|
|
|
73
|
-
|
|
106
|
+
#### 支持的路径占位符
|
|
107
|
+
|
|
108
|
+
- `{project}` - 项目根目录
|
|
109
|
+
- `{build}` - Electron Forge 打包输出目录
|
|
110
|
+
- `{assets}` - 资源文件目录(默认为 `assets`)
|
|
111
|
+
|
|
112
|
+
示例:
|
|
113
|
+
|
|
114
|
+
```typescript
|
|
115
|
+
setupIconFile: "{assets}/icons/icon.ico", // 等同于 "./assets/icons/icon.ico"
|
|
116
|
+
setupIconFile: "{project}/resources/icon.ico",
|
|
117
|
+
Source: "{build}\\*", // Electron Forge 打包后的文件
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
#### 路径配置
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
new MakerInnosetup({
|
|
124
|
+
// ... 其他配置
|
|
125
|
+
|
|
126
|
+
// 路径解析配置
|
|
127
|
+
paths: {
|
|
128
|
+
projectDir: process.cwd(), // 项目根目录,默认为 cwd()
|
|
129
|
+
assetsDir: "resources", // 资源目录,默认为 "assets"
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
// 自动解析相对路径,默认为 true
|
|
133
|
+
resolveRelativePaths: true,
|
|
134
|
+
});
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
> 📖 **详细文档:**[docs/path-resolution.md](docs/path-resolution.md) - 查看完整的路径解析指南,包括更多示例和最佳实践
|
|
138
|
+
|
|
139
|
+
### 方式二:使用绝对路径
|
|
140
|
+
|
|
141
|
+
如果您坚持使用绝对路径,可以禁用自动解析:
|
|
142
|
+
|
|
143
|
+
```typescript
|
|
144
|
+
import type { ForgeConfig } from "@electron-forge/shared-types";
|
|
145
|
+
import MakerInnosetup from "electron-forge-maker-innosetup";
|
|
146
|
+
|
|
147
|
+
const config: ForgeConfig = {
|
|
148
|
+
makers: [
|
|
149
|
+
new MakerInnosetup(
|
|
150
|
+
{
|
|
151
|
+
// 禁用相对路径解析
|
|
152
|
+
resolveRelativePaths: false,
|
|
153
|
+
|
|
154
|
+
// 使用绝对路径
|
|
155
|
+
setupIconFile: "E:\\workSpace\\my-app\\assets\\icon.ico",
|
|
156
|
+
|
|
157
|
+
config: {
|
|
158
|
+
Setup: {
|
|
159
|
+
SetupIconFile: "E:\\workSpace\\my-app\\assets\\icon.ico",
|
|
160
|
+
},
|
|
161
|
+
Files: [
|
|
162
|
+
{
|
|
163
|
+
Source: "E:\\workSpace\\my-app\\out\\*",
|
|
164
|
+
DestDir: "{app}",
|
|
165
|
+
Flags: "ignoreversion recursesubdirs",
|
|
166
|
+
},
|
|
167
|
+
],
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
["win32"]
|
|
171
|
+
),
|
|
172
|
+
],
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
export default config;
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### 方式三:使用配置对象
|
|
74
179
|
|
|
75
180
|
在 `forge.config.js` 中:
|
|
76
181
|
|
|
@@ -82,6 +187,7 @@ module.exports = {
|
|
|
82
187
|
config: {
|
|
83
188
|
appName: "MyApp",
|
|
84
189
|
appPublisher: "My Company",
|
|
190
|
+
// 相对路径会自动解析
|
|
85
191
|
setupIconFile: "./assets/icon.ico",
|
|
86
192
|
},
|
|
87
193
|
},
|
|
@@ -225,22 +331,22 @@ const forgeConfig: ForgeConfig = {
|
|
|
225
331
|
|
|
226
332
|
### MakerInnosetupConfig
|
|
227
333
|
|
|
228
|
-
| 选项 | 类型 | 默认值
|
|
229
|
-
| ----------------------- | ----------------- |
|
|
230
|
-
| `config` | `InnoSetupConfig` | -
|
|
231
|
-
| `scriptPath` | `string` | -
|
|
232
|
-
| `innosetupPath` | `string` | 自动查找
|
|
233
|
-
| `outputDir` | `string` | `./out/
|
|
234
|
-
| `appName` | `string` | -
|
|
235
|
-
| `appVersion` | `string` | -
|
|
236
|
-
| `appPublisher` | `string` | -
|
|
237
|
-
| `appId` | `string` | -
|
|
238
|
-
| `licenseFile` | `string` | -
|
|
239
|
-
| `setupIconFile` | `string` | -
|
|
240
|
-
| `createDesktopIcon` | `boolean` | `false`
|
|
241
|
-
| `createQuickLaunchIcon` | `boolean` | `false`
|
|
242
|
-
| `gui` | `boolean` | `false`
|
|
243
|
-
| `isccOptions` | `string[]` | -
|
|
334
|
+
| 选项 | 类型 | 默认值 | 说明 |
|
|
335
|
+
| ----------------------- | ----------------- | ------------------------- | --------------------------------------- |
|
|
336
|
+
| `config` | `InnoSetupConfig` | - | 完整的 Innosetup 配置对象 |
|
|
337
|
+
| `scriptPath` | `string` | - | 自定义脚本路径(如果提供则忽略 config) |
|
|
338
|
+
| `innosetupPath` | `string` | 自动查找 | Innosetup 编译器路径 |
|
|
339
|
+
| `outputDir` | `string` | `./out/innosetup.windows` | 输出目录 |
|
|
340
|
+
| `appName` | `string` | - | 应用程序名称 |
|
|
341
|
+
| `appVersion` | `string` | - | 应用程序版本 |
|
|
342
|
+
| `appPublisher` | `string` | - | 应用程序发布者 |
|
|
343
|
+
| `appId` | `string` | - | 应用程序唯一 ID |
|
|
344
|
+
| `licenseFile` | `string` | - | 许可证文件路径 |
|
|
345
|
+
| `setupIconFile` | `string` | - | 安装图标文件路径 |
|
|
346
|
+
| `createDesktopIcon` | `boolean` | `false` | 是否创建桌面图标 |
|
|
347
|
+
| `createQuickLaunchIcon` | `boolean` | `false` | 是否创建快速启动图标 |
|
|
348
|
+
| `gui` | `boolean` | `false` | 是否使用 GUI 模式编译 |
|
|
349
|
+
| `isccOptions` | `string[]` | - | 额外的 ISCC 命令行参数 |
|
|
244
350
|
|
|
245
351
|
### InnoSetupConfig
|
|
246
352
|
|
|
@@ -264,8 +370,6 @@ const forgeConfig: ForgeConfig = {
|
|
|
264
370
|
- `CustomMessages` - 自定义消息
|
|
265
371
|
- `Code` - Pascal Script 代码
|
|
266
372
|
|
|
267
|
-
所有配置项都有完整的 TypeScript 类型提示和文档。
|
|
268
|
-
|
|
269
373
|
## 高级用法
|
|
270
374
|
|
|
271
375
|
### 使用预处理器常量 (#define)
|
|
@@ -277,13 +381,13 @@ config: {
|
|
|
277
381
|
config: {
|
|
278
382
|
// 定义预处理器常量
|
|
279
383
|
Defines: {
|
|
280
|
-
MyAppName: "
|
|
384
|
+
MyAppName: "Self Report",
|
|
281
385
|
MyAppVersion: "1.0.0",
|
|
282
|
-
MyAppPublisher: "
|
|
283
|
-
MyAppExeName: "
|
|
284
|
-
MyAppAssocName: "
|
|
386
|
+
MyAppPublisher: "信息科技有限公司",
|
|
387
|
+
MyAppExeName: "Self Report.exe",
|
|
388
|
+
MyAppAssocName: "Self Report File",
|
|
285
389
|
MyAppAssocExt: ".myp",
|
|
286
|
-
MyAppShortcutName: "
|
|
390
|
+
MyAppShortcutName: "XXXX系统",
|
|
287
391
|
},
|
|
288
392
|
Setup: {
|
|
289
393
|
// 使用 {#ConstantName} 引用预处理器常量
|
|
@@ -319,10 +423,10 @@ config: {
|
|
|
319
423
|
; Script generated by the Inno Setup Script Wizard.
|
|
320
424
|
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
|
|
321
425
|
|
|
322
|
-
#define MyAppName "
|
|
426
|
+
#define MyAppName "Self Report"
|
|
323
427
|
#define MyAppVersion "1.0.0"
|
|
324
|
-
#define MyAppPublisher "
|
|
325
|
-
#define MyAppExeName "
|
|
428
|
+
#define MyAppPublisher "信息科技有限公司"
|
|
429
|
+
#define MyAppExeName "Self Report.exe"
|
|
326
430
|
|
|
327
431
|
[Setup]
|
|
328
432
|
AppName={#MyAppName}
|
package/dist/MakerInnosetup.d.ts
CHANGED
|
@@ -8,7 +8,42 @@ export default class MakerInnosetup extends MakerBase<MakerInnosetupConfig> {
|
|
|
8
8
|
name: string;
|
|
9
9
|
defaultPlatforms: ForgePlatform[];
|
|
10
10
|
private scriptGenerator;
|
|
11
|
+
private buildDir;
|
|
12
|
+
private projectDir;
|
|
13
|
+
private assetsDir;
|
|
14
|
+
/**
|
|
15
|
+
* 获取项目根目录
|
|
16
|
+
*/
|
|
17
|
+
private getProjectDir;
|
|
18
|
+
/**
|
|
19
|
+
* 获取构建目录
|
|
20
|
+
*/
|
|
21
|
+
private getBuildDir;
|
|
22
|
+
/**
|
|
23
|
+
* 获取资源目录
|
|
24
|
+
*/
|
|
25
|
+
private getAssetsDir;
|
|
11
26
|
constructor(config?: MakerInnosetupConfig, platforms?: ForgePlatform[]);
|
|
27
|
+
/**
|
|
28
|
+
* 解析路径 - 支持相对路径转换为绝对路径
|
|
29
|
+
* @param pathStr 输入路径
|
|
30
|
+
* @param baseDir 基础目录(默认为 projectDir)
|
|
31
|
+
* @returns 解析后的绝对路径
|
|
32
|
+
*/
|
|
33
|
+
private resolvePath;
|
|
34
|
+
/**
|
|
35
|
+
* 解析配置中的路径占位符
|
|
36
|
+
* 支持:{project}, {assets}, {build}, {app}
|
|
37
|
+
* @param pathStr 包含占位符的路径字符串
|
|
38
|
+
* @returns 解析后的路径
|
|
39
|
+
*/
|
|
40
|
+
private resolvePathPlaceholders;
|
|
41
|
+
/**
|
|
42
|
+
* 处理配置对象中的所有路径
|
|
43
|
+
* @param config Innosetup 配置对象
|
|
44
|
+
* @param appDir 应用目录
|
|
45
|
+
*/
|
|
46
|
+
private resolveConfigPaths;
|
|
12
47
|
/**
|
|
13
48
|
* 从 ISS 文件解析配置
|
|
14
49
|
* @param issFilePath ISS 文件路径
|
package/dist/MakerInnosetup.js
CHANGED
|
@@ -50,12 +50,164 @@ const parser_1 = require("./parser");
|
|
|
50
50
|
* Electron Forge Maker for Innosetup
|
|
51
51
|
*/
|
|
52
52
|
class MakerInnosetup extends maker_base_1.default {
|
|
53
|
+
/**
|
|
54
|
+
* 获取项目根目录
|
|
55
|
+
*/
|
|
56
|
+
getProjectDir() {
|
|
57
|
+
return this.projectDir || this.config?.paths?.projectDir || process.cwd();
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* 获取构建目录
|
|
61
|
+
*/
|
|
62
|
+
getBuildDir() {
|
|
63
|
+
return this.buildDir || this.config?.paths?.buildDir;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* 获取资源目录
|
|
67
|
+
*/
|
|
68
|
+
getAssetsDir() {
|
|
69
|
+
return this.assetsDir || this.config?.paths?.assetsDir || "assets";
|
|
70
|
+
}
|
|
53
71
|
constructor(config = {}, platforms) {
|
|
72
|
+
// 默认启用相对路径解析
|
|
73
|
+
if (config.resolveRelativePaths === undefined) {
|
|
74
|
+
config.resolveRelativePaths = true;
|
|
75
|
+
}
|
|
54
76
|
super(config, platforms);
|
|
55
77
|
this.name = "innosetup";
|
|
56
78
|
this.defaultPlatforms = ["win32"];
|
|
57
79
|
this.scriptGenerator = new generator_1.InnoScriptGenerator();
|
|
58
80
|
}
|
|
81
|
+
/**
|
|
82
|
+
* 解析路径 - 支持相对路径转换为绝对路径
|
|
83
|
+
* @param pathStr 输入路径
|
|
84
|
+
* @param baseDir 基础目录(默认为 projectDir)
|
|
85
|
+
* @returns 解析后的绝对路径
|
|
86
|
+
*/
|
|
87
|
+
resolvePath(pathStr, baseDir) {
|
|
88
|
+
if (!pathStr) {
|
|
89
|
+
return undefined;
|
|
90
|
+
}
|
|
91
|
+
// 如果禁用了相对路径解析,直接返回
|
|
92
|
+
if (this.config?.resolveRelativePaths === false) {
|
|
93
|
+
return pathStr;
|
|
94
|
+
}
|
|
95
|
+
// 如果已经是绝对路径,直接返回
|
|
96
|
+
if (path.isAbsolute(pathStr)) {
|
|
97
|
+
return pathStr;
|
|
98
|
+
}
|
|
99
|
+
// 使用提供的 baseDir 或默认的 projectDir
|
|
100
|
+
const base = baseDir || this.getProjectDir();
|
|
101
|
+
return path.resolve(base, pathStr);
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* 解析配置中的路径占位符
|
|
105
|
+
* 支持:{project}, {assets}, {build}, {app}
|
|
106
|
+
* @param pathStr 包含占位符的路径字符串
|
|
107
|
+
* @returns 解析后的路径
|
|
108
|
+
*/
|
|
109
|
+
resolvePathPlaceholders(pathStr) {
|
|
110
|
+
if (!pathStr) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
let resolved = pathStr;
|
|
114
|
+
const projectDir = this.getProjectDir();
|
|
115
|
+
const buildDir = this.getBuildDir();
|
|
116
|
+
const assetsDir = this.getAssetsDir();
|
|
117
|
+
// {project} - 项目根目录
|
|
118
|
+
resolved = resolved.replace(/\{project\}/g, projectDir);
|
|
119
|
+
// {build} - 构建输出目录
|
|
120
|
+
if (buildDir) {
|
|
121
|
+
resolved = resolved.replace(/\{build\}/g, buildDir);
|
|
122
|
+
}
|
|
123
|
+
// {assets} - 资源目录
|
|
124
|
+
const assetsPath = path.resolve(projectDir, assetsDir);
|
|
125
|
+
resolved = resolved.replace(/\{assets\}/g, assetsPath);
|
|
126
|
+
return resolved;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 处理配置对象中的所有路径
|
|
130
|
+
* @param config Innosetup 配置对象
|
|
131
|
+
* @param appDir 应用目录
|
|
132
|
+
*/
|
|
133
|
+
resolveConfigPaths(config, appDir) {
|
|
134
|
+
if (this.config?.resolveRelativePaths === false) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const projectDir = this.getProjectDir();
|
|
138
|
+
// 解析 Setup 部分的路径
|
|
139
|
+
if (config.Setup) {
|
|
140
|
+
// SetupIconFile
|
|
141
|
+
if (config.Setup.SetupIconFile) {
|
|
142
|
+
config.Setup.SetupIconFile = this.resolvePath(this.resolvePathPlaceholders(config.Setup.SetupIconFile), projectDir);
|
|
143
|
+
}
|
|
144
|
+
// LicenseFile
|
|
145
|
+
if (config.Setup.LicenseFile) {
|
|
146
|
+
config.Setup.LicenseFile = this.resolvePath(this.resolvePathPlaceholders(config.Setup.LicenseFile), projectDir);
|
|
147
|
+
}
|
|
148
|
+
// InfoBeforeFile
|
|
149
|
+
if (config.Setup.InfoBeforeFile) {
|
|
150
|
+
config.Setup.InfoBeforeFile = this.resolvePath(this.resolvePathPlaceholders(config.Setup.InfoBeforeFile), projectDir);
|
|
151
|
+
}
|
|
152
|
+
// InfoAfterFile
|
|
153
|
+
if (config.Setup.InfoAfterFile) {
|
|
154
|
+
config.Setup.InfoAfterFile = this.resolvePath(this.resolvePathPlaceholders(config.Setup.InfoAfterFile), projectDir);
|
|
155
|
+
}
|
|
156
|
+
// WizardImageFile
|
|
157
|
+
if (config.Setup.WizardImageFile) {
|
|
158
|
+
config.Setup.WizardImageFile = this.resolvePath(this.resolvePathPlaceholders(config.Setup.WizardImageFile), projectDir);
|
|
159
|
+
}
|
|
160
|
+
// WizardSmallImageFile
|
|
161
|
+
if (config.Setup.WizardSmallImageFile) {
|
|
162
|
+
config.Setup.WizardSmallImageFile = this.resolvePath(this.resolvePathPlaceholders(config.Setup.WizardSmallImageFile), projectDir);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
// 解析 Languages 部分的路径
|
|
166
|
+
if (config.Languages) {
|
|
167
|
+
config.Languages.forEach((lang) => {
|
|
168
|
+
if (lang.LicenseFile && !lang.LicenseFile.startsWith("compiler:")) {
|
|
169
|
+
lang.LicenseFile = this.resolvePath(this.resolvePathPlaceholders(lang.LicenseFile), projectDir);
|
|
170
|
+
}
|
|
171
|
+
if (lang.InfoBeforeFile &&
|
|
172
|
+
!lang.InfoBeforeFile.startsWith("compiler:")) {
|
|
173
|
+
lang.InfoBeforeFile = this.resolvePath(this.resolvePathPlaceholders(lang.InfoBeforeFile), projectDir);
|
|
174
|
+
}
|
|
175
|
+
if (lang.InfoAfterFile && !lang.InfoAfterFile.startsWith("compiler:")) {
|
|
176
|
+
lang.InfoAfterFile = this.resolvePath(this.resolvePathPlaceholders(lang.InfoAfterFile), projectDir);
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
// 解析 Files 部分的路径
|
|
181
|
+
if (config.Files) {
|
|
182
|
+
config.Files.forEach((file) => {
|
|
183
|
+
// Source 路径处理
|
|
184
|
+
if (file.Source) {
|
|
185
|
+
// 首先替换我们自定义的占位符
|
|
186
|
+
let sourcePath = this.resolvePathPlaceholders(file.Source);
|
|
187
|
+
// 如果替换后不是 Inno Setup 内置常量(如 {app}, {tmp}),则解析为绝对路径
|
|
188
|
+
// Inno Setup 常量通常以 {app}, {tmp}, {src}, {win}, {sys} 等开头
|
|
189
|
+
const isInnoConstant = sourcePath?.match(/^\{(app|tmp|src|win|sys|pf|cf|dao|fonts|userappdata|localappdata|group|autoprograms|autodesktop|commondocs)/i);
|
|
190
|
+
if (sourcePath && !isInnoConstant) {
|
|
191
|
+
// 如果包含 * 通配符,需要特殊处理
|
|
192
|
+
if (sourcePath.includes("*")) {
|
|
193
|
+
const basePath = sourcePath.split("*")[0];
|
|
194
|
+
const wildcard = sourcePath.substring(basePath.length);
|
|
195
|
+
const resolvedBase = this.resolvePath(basePath, appDir);
|
|
196
|
+
sourcePath = resolvedBase ? resolvedBase + wildcard : sourcePath;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
sourcePath = this.resolvePath(sourcePath, appDir);
|
|
200
|
+
}
|
|
201
|
+
file.Source = sourcePath;
|
|
202
|
+
}
|
|
203
|
+
else if (sourcePath) {
|
|
204
|
+
// 是 Inno Setup 常量,保持不变
|
|
205
|
+
file.Source = sourcePath;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
}
|
|
59
211
|
/**
|
|
60
212
|
* 从 ISS 文件解析配置
|
|
61
213
|
* @param issFilePath ISS 文件路径
|
|
@@ -385,6 +537,8 @@ class MakerInnosetup extends maker_base_1.default {
|
|
|
385
537
|
const appVersion = packageJSON.version || "1.0.0";
|
|
386
538
|
const archId = this.getArchIdentifier(targetArch);
|
|
387
539
|
console.log(`Creating Innosetup installer for ${appName} ${appVersion} (${targetArch})...`);
|
|
540
|
+
console.log(`Project directory: ${this.getProjectDir()}`);
|
|
541
|
+
console.log(`Build directory: ${this.getBuildDir()}`);
|
|
388
542
|
// 查找编译器
|
|
389
543
|
const compilerPath = this.findInnosetupCompiler();
|
|
390
544
|
console.log(`Using Innosetup compiler: ${compilerPath}`);
|
|
@@ -403,7 +557,7 @@ class MakerInnosetup extends maker_base_1.default {
|
|
|
403
557
|
let actualOutputDir = outputDir; // 实际的输出目录
|
|
404
558
|
if (this.config.scriptPath) {
|
|
405
559
|
// 使用用户提供的脚本
|
|
406
|
-
scriptPath = this.config.scriptPath;
|
|
560
|
+
scriptPath = this.resolvePath(this.config.scriptPath, this.getProjectDir());
|
|
407
561
|
console.log(`Using custom script: ${scriptPath}`);
|
|
408
562
|
// 解析脚本以获取实际的输出目录
|
|
409
563
|
try {
|
|
@@ -426,6 +580,8 @@ class MakerInnosetup extends maker_base_1.default {
|
|
|
426
580
|
// 生成脚本
|
|
427
581
|
const defaultConfig = this.generateDefaultConfig(dir, appName, appVersion, targetArch, outputDir);
|
|
428
582
|
finalConfig = this.mergeConfig(defaultConfig, this.config.config);
|
|
583
|
+
// 解析配置中的路径
|
|
584
|
+
this.resolveConfigPaths(finalConfig, dir);
|
|
429
585
|
// 添加任务
|
|
430
586
|
this.addTasks(finalConfig, appName);
|
|
431
587
|
// 生成脚本内容
|
package/dist/types.d.ts
CHANGED
|
@@ -604,9 +604,9 @@ export interface MakerInnosetupConfig {
|
|
|
604
604
|
appPublisher?: string;
|
|
605
605
|
/** 应用程序 ID(如果未在 config 中指定) */
|
|
606
606
|
appId?: string;
|
|
607
|
-
/**
|
|
607
|
+
/** 许可证文件路径(支持相对路径) */
|
|
608
608
|
licenseFile?: string;
|
|
609
|
-
/**
|
|
609
|
+
/** 安装图标文件路径(支持相对路径) */
|
|
610
610
|
setupIconFile?: string;
|
|
611
611
|
/** 是否创建桌面图标 */
|
|
612
612
|
createDesktopIcon?: boolean;
|
|
@@ -614,4 +614,32 @@ export interface MakerInnosetupConfig {
|
|
|
614
614
|
createQuickLaunchIcon?: boolean;
|
|
615
615
|
/** 编译超时时间(毫秒),默认 5 分钟 */
|
|
616
616
|
compileTimeout?: number;
|
|
617
|
+
/**
|
|
618
|
+
* 路径解析配置
|
|
619
|
+
* 用于解析配置中的相对路径
|
|
620
|
+
*/
|
|
621
|
+
paths?: {
|
|
622
|
+
/**
|
|
623
|
+
* 项目根目录,相对路径将基于此目录解析
|
|
624
|
+
* 默认为 Electron Forge 的 projectDir
|
|
625
|
+
*/
|
|
626
|
+
projectDir?: string;
|
|
627
|
+
/**
|
|
628
|
+
* 资源文件目录(相对于 projectDir)
|
|
629
|
+
* 默认为 "assets"
|
|
630
|
+
* 用于快速引用图标、许可证等资源文件
|
|
631
|
+
*/
|
|
632
|
+
assetsDir?: string;
|
|
633
|
+
/**
|
|
634
|
+
* 构建输出目录(相对于 projectDir)
|
|
635
|
+
* 默认为 Electron Forge 的打包输出目录
|
|
636
|
+
*/
|
|
637
|
+
buildDir?: string;
|
|
638
|
+
};
|
|
639
|
+
/**
|
|
640
|
+
* 是否自动解析相对路径
|
|
641
|
+
* 默认为 true
|
|
642
|
+
* 设置为 false 时,所有路径将按原样使用(不推荐)
|
|
643
|
+
*/
|
|
644
|
+
resolveRelativePaths?: boolean;
|
|
617
645
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "electron-forge-maker-innosetup",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "An Electron Forge maker for creating Windows installers using Innosetup with full TypeScript support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"build": "tsc",
|
|
9
|
-
"
|
|
10
|
-
"test": "
|
|
9
|
+
"test": "jest",
|
|
10
|
+
"test:watch": "jest --watch",
|
|
11
|
+
"test:coverage": "jest --coverage",
|
|
11
12
|
"setup-portable": "node scripts/setup-portable.js",
|
|
12
13
|
"prepare": "npm run build",
|
|
13
14
|
"preversion": "npm test",
|
|
@@ -19,7 +20,10 @@
|
|
|
19
20
|
"debug": "^4.3.4"
|
|
20
21
|
},
|
|
21
22
|
"devDependencies": {
|
|
23
|
+
"@types/jest": "^30.0.0",
|
|
22
24
|
"@types/node": "^20.0.0",
|
|
25
|
+
"jest": "^30.2.0",
|
|
26
|
+
"ts-jest": "^29.4.6",
|
|
23
27
|
"typescript": "^5.0.0"
|
|
24
28
|
},
|
|
25
29
|
"files": [
|