electronup 0.0.8 → 0.1.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/README.md CHANGED
@@ -1,346 +1,48 @@
1
1
  # electronup
2
+ [![license](https://img.shields.io/badge/license-MIT-green.svg)](./LICENSE) ![](https://img.shields.io/github/stars/QuiteerJs/electronup) ![](https://img.shields.io/github/forks/QuiteerJs/electronup)
2
3
 
4
+ > electronup 是一个集成 Vite4.x、tsup6.x、electron-builder24.x 的桌面端构建工具,一个配置文件完成多环境多目标的构建包。
3
5
 
4
- > 融合构建 electron 应用需要的构建工具,保留原有配置习惯的命令行工具
5
-
6
-
7
-
8
- ## 插件前置
9
-
10
- ```json
11
- {
12
- "peerDependencies": {
13
- "@types/node": ">= 16",
14
- "electron": ">= 20",
15
- "vue": ">= 3"
16
- }
17
- }
18
- ```
6
+ ## 文档地址
19
7
 
8
+ 文档地址 :https://quiteerjs.github.io/electronup
20
9
 
21
10
  ## 安装
22
11
 
23
12
  ```bash
24
- npm i @quiteer/electronup -D
13
+ npm install electronup -D
25
14
  ```
26
15
 
27
16
  ```bash
28
- yarn add @quiteer/electronup -D
17
+ yarn add electronup -D
29
18
  ```
30
19
 
31
20
  ```bash
32
- pnpm add @quiteer/electronup -D
33
- ```
34
-
35
-
36
- ## 使用
37
-
38
- - 查看命令行指令
39
-
40
- - `electornup -h`
41
-
42
- - `electornup build -h`
43
-
44
-
45
- - 查看命令行版本
46
-
47
- - `electornup -v`
48
-
49
-
50
- - 开发环境
51
-
52
- - `electornup`
53
-
54
- - `electornup dev`
55
-
56
- - 指定配置文件 `electornup [config file]`
57
-
58
- - 指定配置文件 `electornup dev [config file]`
59
-
60
-
61
- - 构建打包
62
-
63
- - `electornup build`
64
-
65
- - 指定配置文件 `electornup build [config file]`
66
-
67
- - 开启选项式构建 `electornup build -o` 或 `electornup build --option`
68
-
69
- - 输出选项默认当前平台架构
70
-
71
- - 指定平台 `--win` ,`--mac` ,`--linux`
72
-
73
- - 指定架构 `--ia32` ,`--x64` ,`--arm64`
74
-
75
- - 可不指定平台架构版本, 默认为本机当前平台架构版本
76
-
77
- ## 内置的依赖
78
-
79
- > 部分依赖已内置 无需重复安装 (开发此脚手架的目的也是给项目 package 瘦瘦身)
80
-
81
- ```json
82
- {
83
- "dependencies": {
84
- "@quiteer/parser-config": "^1.0.3",
85
- "cac": "^6.7.14",
86
- "dotenv": "^16.0.3",
87
- "electron-builder": "^23.6.0",
88
- "fs-extra": "^10.1.0",
89
- "inquirer": "8.2.5",
90
- "portfinder": "^1.0.32",
91
- "rimraf": "^3.0.2",
92
- "tsup": "^6.7.0",
93
- "typescript": "^5.0.4",
94
- "vite": "^4.4.9",
95
- "yaml": "^2.2.1"
96
- }
97
- }
21
+ pnpm add electronup -D
98
22
  ```
99
23
 
100
- ### cli配置项
101
-
102
- ```ts
103
- import type { Configuration } from 'electron-builder'
104
- import type { AliasOptions, PluginOption, ResolveOptions, UserConfig } from 'vite'
105
- import type { Options } from 'tsup'
106
-
107
- interface ViteConfig {
108
- resolve?: ResolveOptions & {
109
- alias?: AliasOptions
110
- }
111
- plugins?: PluginOption[]
112
- viteOptions?: Omit<UserConfig, 'plugins' | 'resolve' | 'publicDir'>
113
- }
114
-
115
- interface TsupConfig {
116
- entry?: string[] | Record<string, string>
117
- target?: string | string[]
118
- minify?: boolean
119
- external?: (string | RegExp)[]
120
- noExternal?: (string | RegExp)[]
121
- }
122
-
123
- interface BuilderConfig extends Configuration { }
124
-
125
- interface ElectronupConfig {
126
- viteConfig?: ViteConfig
127
- tsupConfig?: TsupConfig
128
- preloadTsup?: Options | Options[]
129
- builderConfig: BuilderConfig
130
-
131
- /**
132
- * 渲染进程入口目录
133
- * @default 'render'
134
- */
135
- renderDir?: string
136
-
137
- /**
138
- * 主进程入口目录
139
- * @default 'main'
140
- */
141
- mainDir?: string
142
-
143
- /**
144
- * 静态资源目录
145
- * @default 'public'
146
- */
147
- publicDir?: string
148
-
149
- /**
150
- * 动态库目录
151
- * @default 'lib'
152
- */
153
- libDir?: string
154
-
155
- /**
156
- * 资源构建输出目录
157
- * @default 'dist/resource'
158
- */
159
- resourceDir?: string
160
-
161
- /**
162
- * electron-builder 输出目录
163
- * @default 'dist/out'
164
- */
165
- outDir?: string
166
- }
167
-
168
- interface ConfigEnv {
169
- command: 'build' | 'serve'
170
- root: string
171
- }
172
-
173
- type ElectronupConfigFn = (env: ConfigEnv) => ElectronupConfig
174
- type UserElectronupConfig = ElectronupConfig | ElectronupConfigFn
175
-
176
- declare const defineConfig: (config: UserElectronupConfig) => UserElectronupConfig
177
-
178
- export { BuilderConfig, ConfigEnv, ElectronupConfig, TsupConfig, ViteConfig, defineConfig }
179
- ```
180
-
181
- #### 获取类型提示
182
-
183
- 引入导出的 api 即可获取类型提示
184
-
185
- ## 环境变量配置
186
-
187
- 根目录下的 `.env` 文件在任何环境下都会注入到业务代码中
188
-
189
- ### command
190
-
191
- 目前 `command` 命令仅支持 `dev` 及 `build`
24
+ ## 特性
192
25
 
193
- `dev` 指令下向 `process.env` 中注入 `NODE_ENV` 字段 为 `develpoment`
26
+ - **多框架支持** : 使用 `create-electronup` 询问式创建项目模板 , 内置 `vue3` `react` ,`solid` 等项目模板。
27
+ - **Vite + tsup** : 双进程热更新 , 快速开发(主进程代码修改会触发软件重启)。
28
+ - **统一的环境变量** : `dotenv` 加载 , 构建时注入 , 双进程拥有相同的环境变量。
29
+ - **模式构建** : 默认识别当前代码运行的平台输出打包程序 。
30
+ - **可选构建功能提示** : 你将获得可选范围内支持的功能提示 , 选项式自定义构建输出。
31
+ - **TypeScript** : 应用程序级 `JavaScript` 的语言。
32
+ - **集中管理路径** : 解决双进程资源路径的问题。
33
+ - **预置配置** : 内置了很多可以覆盖的构建工具配置。
34
+ - **单文件配置** : 只需一个 **electronup.config.ts** 即可管理项目的运行构建。
35
+ - **多插件** : 作者会继续开发更多无副作用的独立插件,如:创建窗口,预加载,ipc通信,更新等等。
194
36
 
195
- `build` 指令下向 `process.env` 中注入 `NODE_ENV` 字段 为 `production`
37
+ ## 声明
196
38
 
197
- 双进程下区分环境略有不同 , 主进程代码中直接访问 `process.env` 上的 `NODE_ENV` 即可,渲染进程中访问 `vite` 提供的 `import.meta.env` 获取
39
+ 前提条件
40
+ > 熟悉命令行
41
+ > 已安装 16.0 或更高版本的 Node.js
198
42
 
199
- ```typescript
200
- // main.ts
201
- // dev
202
- console.log('NODE_ENV', process.env.NODE_ENV) // NODE_ENV development
203
43
 
204
- // build
205
- console.log('NODE_ENV', process.env.NODE_ENV) // NODE_ENV production
206
- ```
207
-
208
- ```typescript
209
- // render.ts
210
- // dev
211
- console.log('isDev', import.meta.env.DEV) // isDev true
212
-
213
- // build
214
- console.log('isDev', import.meta.env.DEV) // isDev fasle
215
- ```
216
-
217
-
218
-
219
- ### mode
220
-
221
- 通过添加命令行指令 `-m xxx | -mode xxx` 指定加载环境变量文件以满足不同环境下的不同环境变量。
222
-
223
- `mode` 指令传入的 `mode` 字符串需与根目录下的 `env` 文件一致。 规则如下
224
-
225
- ```shell
226
- electronup -m test
227
- ```
228
-
229
- 命令行运行后根据 `mode` 参数加载根目录下的 `.env.test` 环境变量文件
230
-
231
- 即 `electronup -m test`
232
-
233
- `.env`
234
-
235
- `.env.test`
236
-
237
- 不传 mode 参数,默认根据环境区分加载环境变量。
238
-
239
- `electronup dev`
240
-
241
- `.env`
242
-
243
- `.env.devlepoment`
244
-
245
- `electronup build`
246
-
247
- `.env`
248
-
249
- `.env.production`
250
-
251
- 当然也可通过传入 mode 参数使 dev 环境加载 production 的环境变量。
252
-
253
- `electronup dev -m production`
254
-
255
-
256
-
257
- #### 文件命名
258
-
259
- `.env`
260
-
261
- `.env.development`
262
-
263
- `.env.production`
264
-
265
- `.env.test`
266
-
267
- `.env.staging`
268
-
269
-
270
-
271
- ### 预置配置
272
-
273
- 可自定义配置覆盖默认配置。
274
-
275
- #### vite
276
-
277
- - `base` : `./`
278
-
279
- - `mode` : `development` | `production`
280
-
281
- - `root` : `render`
282
-
283
- - `publicDir` : `public`
284
-
285
- - `server` : `{ host: '0.0.0.0' }`
286
-
287
- - `build` :
288
-
289
- ```ts
290
- {
291
- outDir: 'dist',
292
- target: 'esnext',
293
- minify: true,
294
- reportCompressedSize: false,
295
- emptyOutDir: true
296
- }
297
- ```
298
-
299
- 所有选项皆可通过 `viteOptions` 覆盖
300
-
301
- #### tsup配置选项
302
-
303
- - `external` : `['electorn']`
304
- - `target` : `node14`
305
- - `noExternal` : `[]`
306
-
307
- ##### 路径别名
308
-
309
- 直接在项目中配置 `tsconfig.json` 的 `paths` 选项即可在主进程代码中使用路径别名。
310
-
311
- #### electron-builder
312
-
313
- 可全部覆盖,默认配置如下:
314
-
315
- ```typescript
316
- {
317
- asar: true,
318
- appId: 'org.quiteer.electronup',
319
- productName: packages.name,
320
- protocols: {
321
- name: packages.name,
322
- schemes: ['deeplink']
323
- },
324
- nsis: {
325
- oneClick: false,
326
- language: '2052',
327
- perMachine: true,
328
- allowElevation: true,
329
- allowToChangeInstallationDirectory: true,
330
- runAfterFinish: true,
331
- createDesktopShortcut: true,
332
- createStartMenuShortcut: true,
333
- artifactName: `${packages.name} \${arch} Setup ${packages.version}.\${ext}`
334
- },
335
- files: [`${allConfig.resourceDir || DefaultDirs.resourceDir}/**/*`],
336
- extraFiles: [allConfig.libDir || DefaultDirs.libDir],
337
- directories: {
338
- output: allConfig.outDir || config.directories?.output || DefaultDirs.outDir
339
- },
340
- // ...传入同名参数即可完成覆盖
341
- }
342
- ```
44
+ 因为使用了 tsup 构建主进程代码,所以该命令行及脚手架只支持 TypeScript ,不支持 JavaScript。
343
45
 
344
46
  ## 示例
345
47
 
346
- > https://github.com/TaiAiAc/electron-quiet-monorepo/tree/main/experiment/electronup-test
48
+ > https://github.com/QuiteerJs/electronup/tree/main/playground/electronup-test
@@ -29,7 +29,7 @@ var import_node_fs = __toESM(require("fs"));
29
29
  var import_cac = require("cac");
30
30
 
31
31
  // package.json
32
- var version = "0.0.8";
32
+ var version = "0.1.0";
33
33
 
34
34
  // transform/getConfig.ts
35
35
  var import_path = require("path");
@@ -48,11 +48,6 @@ var Store = class _Store {
48
48
  win;
49
49
  mac;
50
50
  linux;
51
- ia32;
52
- x64;
53
- arm64;
54
- armv7l;
55
- universal;
56
51
  dir;
57
52
  asar;
58
53
  targets;
@@ -108,44 +103,33 @@ var import_path2 = require("path");
108
103
  var import_fs_extra2 = require("fs-extra");
109
104
  async function getBuilderConfig(config, allConfig) {
110
105
  const packages = await (0, import_fs_extra2.readJSON)((0, import_path2.resolve)(store.root, "package.json"));
111
- const outConfig = {
112
- targets: store.targets,
113
- x64: store.x64,
114
- ia32: store.ia32,
115
- armv7l: store.armv7l,
116
- arm64: store.arm64,
117
- universal: store.universal,
118
- dir: store.dir
119
- };
120
106
  const defaultConfig = {
121
- config: {
122
- asar: store.asar,
123
- appId: "org.quiteer.electronup",
124
- productName: packages.name,
125
- protocols: {
126
- name: packages.name,
127
- schemes: ["deeplink"]
128
- },
129
- nsis: {
130
- oneClick: false,
131
- language: "2052",
132
- perMachine: true,
133
- allowElevation: true,
134
- allowToChangeInstallationDirectory: true,
135
- runAfterFinish: true,
136
- createDesktopShortcut: true,
137
- createStartMenuShortcut: true,
138
- artifactName: `${packages.name} \${arch} Setup ${packages.version}.\${ext}`
139
- },
140
- files: [`${allConfig.resourceDir || "dist/resource" /* resourceDir */}/**/*`],
141
- extraFiles: [allConfig.libDir || "lib" /* libDir */],
142
- directories: {
143
- output: allConfig.outDir || config.directories?.output || "dist/out" /* outDir */
144
- },
145
- ...config
146
- }
107
+ asar: store.asar,
108
+ appId: "org.quiteer.electronup",
109
+ productName: packages.name,
110
+ protocols: {
111
+ name: packages.name,
112
+ schemes: ["deeplink"]
113
+ },
114
+ nsis: {
115
+ oneClick: false,
116
+ language: "2052",
117
+ perMachine: true,
118
+ allowElevation: true,
119
+ allowToChangeInstallationDirectory: true,
120
+ runAfterFinish: true,
121
+ createDesktopShortcut: true,
122
+ createStartMenuShortcut: true,
123
+ artifactName: `${packages.name} \${arch} Setup ${packages.version}.\${ext}`
124
+ },
125
+ files: [`${allConfig.resourceDir || "dist/resource" /* resourceDir */}/**/*`],
126
+ extraFiles: [allConfig.libDir || "lib" /* libDir */],
127
+ directories: {
128
+ output: allConfig.outDir || config.directories?.output || "dist/out" /* outDir */
129
+ },
130
+ ...config
147
131
  };
148
- return { ...defaultConfig, ...outConfig };
132
+ return { targets: store.targets, config: defaultConfig };
149
133
  }
150
134
 
151
135
  // configs/tsup.ts
@@ -300,109 +284,170 @@ var import_path5 = __toESM(require("path"));
300
284
  var import_electron_builder = require("electron-builder");
301
285
  var import_vite3 = require("vite");
302
286
  var import_tsup3 = require("tsup");
303
- var import_inquirer = __toESM(require("inquirer"));
287
+ var import_prompts = __toESM(require("prompts"));
288
+ var import_kolorist = require("kolorist");
304
289
  var import_yaml = require("yaml");
305
290
  var import_fs_extra3 = require("fs-extra");
291
+ var platformSelect = [
292
+ {
293
+ name: "Windows",
294
+ platform: "win32",
295
+ createTarget: (archs) => {
296
+ if (archs.length)
297
+ return import_electron_builder.Platform.WINDOWS.createTarget(store.dir, ...archs);
298
+ return import_electron_builder.Platform.WINDOWS.createTarget(store.dir, import_electron_builder.Arch.ia32, import_electron_builder.Arch.x64);
299
+ },
300
+ color: import_kolorist.blue,
301
+ disabled: !(store.isMac || store.isWin),
302
+ archs: [{
303
+ name: "x64",
304
+ arch: import_electron_builder.Arch.x64,
305
+ disabled: store.currentArch === "ia32",
306
+ color: import_kolorist.blue
307
+ }, {
308
+ name: "ia32",
309
+ arch: import_electron_builder.Arch.ia32,
310
+ color: import_kolorist.blue,
311
+ disabled: false
312
+ }]
313
+ },
314
+ {
315
+ name: "MacOS",
316
+ platform: "darwin",
317
+ createTarget: (archs) => {
318
+ if (archs.length)
319
+ return import_electron_builder.Platform.MAC.createTarget(store.dir, import_electron_builder.Arch[store.currentArch]);
320
+ return import_electron_builder.Platform.MAC.createTarget(store.dir, ...archs);
321
+ },
322
+ disabled: !store.isMac,
323
+ color: import_kolorist.green,
324
+ archs: [{
325
+ name: "x64",
326
+ arch: import_electron_builder.Arch.x64,
327
+ disabled: false,
328
+ color: import_kolorist.green
329
+ }, {
330
+ name: "arm64",
331
+ arch: import_electron_builder.Arch.arm64,
332
+ disabled: false,
333
+ color: import_kolorist.green
334
+ }, {
335
+ name: "universal",
336
+ arch: import_electron_builder.Arch.universal,
337
+ disabled: false,
338
+ color: import_kolorist.green
339
+ }]
340
+ },
341
+ {
342
+ name: "Linux",
343
+ platform: "linux",
344
+ disabled: !(store.isMac || store.isLinux),
345
+ createTarget: (archs) => {
346
+ if (archs.length)
347
+ return import_electron_builder.Platform.LINUX.createTarget(store.dir, import_electron_builder.Arch[store.currentArch]);
348
+ return import_electron_builder.Platform.LINUX.createTarget(store.dir, ...archs);
349
+ },
350
+ color: import_kolorist.yellow,
351
+ archs: [{
352
+ name: "x64",
353
+ arch: import_electron_builder.Arch.x64,
354
+ disabled: false,
355
+ color: import_kolorist.yellow
356
+ }, {
357
+ name: "arm64",
358
+ arch: import_electron_builder.Arch.arm64,
359
+ disabled: false,
360
+ color: import_kolorist.yellow
361
+ }, {
362
+ name: "armv7l",
363
+ arch: import_electron_builder.Arch.armv7l,
364
+ disabled: false,
365
+ color: import_kolorist.yellow
366
+ }]
367
+ }
368
+ ];
306
369
  async function build2(options) {
307
370
  if (store.option) {
308
- const { isMinify } = await import_inquirer.default.prompt([{ type: "confirm", name: "isMinify", message: "\u662F\u5426\u538B\u7F29\u4EE3\u7801?" }]).catch((err) => {
309
- console.error("err: ", err);
371
+ let result;
372
+ try {
373
+ result = await (0, import_prompts.default)([
374
+ {
375
+ type: "confirm",
376
+ name: "isMinify",
377
+ message: (0, import_kolorist.green)("\u662F\u5426\u538B\u7F29\u4EE3\u7801?")
378
+ },
379
+ {
380
+ type: "confirm",
381
+ name: "isPackage",
382
+ message: (0, import_kolorist.blue)("\u662F\u5426\u751F\u6210\u5B89\u88C5\u5305?")
383
+ },
384
+ {
385
+ type: "select",
386
+ name: "platform",
387
+ message: "\u8BF7\u9009\u62E9\u6784\u5EFA\u6A21\u5F0F ~",
388
+ choices: platformSelect.map((item) => ({ title: item.color(item.name), value: item, disabled: item.disabled }))
389
+ },
390
+ {
391
+ type: "multiselect",
392
+ name: "arch",
393
+ message: "\u8BF7\u9009\u62E9\u6253\u5305\u67B6\u6784\uFF5E",
394
+ choices: (platformSelect2) => {
395
+ return platformSelect2.archs?.map((item) => ({ title: item.color(item.name), value: item.arch, disabled: item.disabled }));
396
+ }
397
+ }
398
+ ], {
399
+ onCancel: () => {
400
+ throw new Error(`${(0, import_kolorist.red)("\u2716")} Operation cancelled`);
401
+ }
402
+ });
403
+ } catch (cancelled) {
404
+ console.error("err: ", cancelled.message);
310
405
  process.exit(1);
311
- });
406
+ }
407
+ const { isMinify, isPackage, platform, arch } = result;
408
+ console.log("isMinify: ", isMinify);
409
+ console.log("isPackage: ", isPackage);
410
+ console.log("platform: ", platform);
411
+ console.log("arch: ", arch);
312
412
  store.minify = isMinify;
313
- const { isPackage } = await import_inquirer.default.prompt([{ type: "confirm", name: "isPackage", message: "\u662F\u5426\u751F\u6210\u5B89\u88C5\u5305?" }]).catch((err) => {
314
- console.error("err: ", err);
315
- process.exit(1);
316
- });
317
- store.dir = !isPackage;
413
+ store.dir = isPackage ? null : "dir";
414
+ store.targets = platform.createTarget(arch);
415
+ } else {
318
416
  if (store.isWin) {
319
- if (store.currentArch === "ia32")
320
- store.ia32 = true;
321
- if (store.currentArch === "x64") {
322
- const { pattern } = await import_inquirer.default.prompt([
323
- {
324
- type: "checkbox",
325
- name: "pattern",
326
- message: "\u8BF7\u9009\u62E9\u6784\u5EFA\u6A21\u5F0F , \u8DF3\u8FC7\u9009\u62E9\u4E3A\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0 ~",
327
- pageSize: 10,
328
- choices: [
329
- { name: "win-x64", value: "x64" },
330
- { name: "win-ia32", value: "ia32" }
331
- ]
332
- }
333
- ]).catch((err) => {
334
- console.error("err: ", err);
335
- process.exit(1);
336
- });
337
- if (pattern.length) {
338
- pattern.forEach((arch) => {
339
- store[arch] = true;
340
- });
341
- }
342
- }
343
- store.dir = !isPackage;
417
+ if (store.win === "ia32")
418
+ store.targets = import_electron_builder.Platform.WINDOWS.createTarget(store.dir, import_electron_builder.Arch.ia32);
419
+ else if (store.win === "x64")
420
+ store.targets = import_electron_builder.Platform.WINDOWS.createTarget(store.dir, import_electron_builder.Arch.x64);
421
+ else
422
+ store.targets = import_electron_builder.Platform.WINDOWS.createTarget(store.dir, import_electron_builder.Arch[store.currentArch]);
344
423
  }
345
424
  if (store.isMac) {
346
- const { outPlatform } = await import_inquirer.default.prompt([
347
- {
348
- type: "list",
349
- name: "outPlatform",
350
- message: "\u8BF7\u9009\u62E9\u6784\u5EFA\u5E73\u53F0 , \u8DF3\u8FC7\u9009\u62E9\u4E3A\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0 ~",
351
- pageSize: 10,
352
- choices: [
353
- { name: "win", value: "win" },
354
- { name: "mac", value: "mac" },
355
- { name: "linux", value: "linux" }
356
- ]
357
- }
358
- ]).catch((err) => {
359
- console.error("err: ", err);
360
- process.exit(1);
361
- });
362
- if (outPlatform === "mac") {
363
- const { pattern } = await import_inquirer.default.prompt([
364
- {
365
- type: "checkbox",
366
- name: "pattern",
367
- message: "\u8BF7\u9009\u62E9\u6784\u5EFA\u6A21\u5F0F , \u8DF3\u8FC7\u9009\u62E9\u4E3A\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0 ~",
368
- pageSize: 10,
369
- choices: [
370
- { name: "mac-x64", value: import_electron_builder.Arch.x64 },
371
- { name: "mac-arm64", value: import_electron_builder.Arch.arm64 }
372
- ]
373
- }
374
- ]).catch((err) => {
375
- console.error("err: ", err);
376
- process.exit(1);
377
- });
378
- const archList = [];
379
- pattern.length ? archList.push(...pattern) : archList.push(import_electron_builder.Arch[store.currentArch]);
380
- store.targets = import_electron_builder.Platform.MAC.createTarget(!isPackage ? "dir" : null, ...archList);
425
+ if (store.win) {
426
+ if (store.win === "ia32")
427
+ store.targets = import_electron_builder.Platform.WINDOWS.createTarget(store.dir, import_electron_builder.Arch.ia32);
428
+ else if (store.win === "x64")
429
+ store.targets = import_electron_builder.Platform.WINDOWS.createTarget(store.dir, import_electron_builder.Arch.x64);
430
+ else
431
+ store.targets = import_electron_builder.Platform.WINDOWS.createTarget(store.dir, import_electron_builder.Arch[store.currentArch]);
432
+ } else if (store.mac) {
433
+ if (store.mac === "x64")
434
+ store.targets = import_electron_builder.Platform.MAC.createTarget(store.dir, import_electron_builder.Arch.x64);
435
+ else if (store.mac === "arm64")
436
+ store.targets = import_electron_builder.Platform.MAC.createTarget(store.dir, import_electron_builder.Arch.arm64);
437
+ else if (store.mac === "universal")
438
+ store.targets = import_electron_builder.Platform.MAC.createTarget(store.dir, import_electron_builder.Arch.universal);
439
+ else
440
+ store.targets = import_electron_builder.Platform.MAC.createTarget(store.dir, import_electron_builder.Arch[store.currentArch]);
441
+ } else if (store.linux) {
442
+ if (store.linux === true)
443
+ store.targets = import_electron_builder.Platform.LINUX.createTarget(store.dir);
444
+ else
445
+ store.targets = import_electron_builder.Platform.LINUX.createTarget(store.dir, import_electron_builder.Arch[store.currentArch]);
446
+ } else {
447
+ store.targets = import_electron_builder.Platform.MAC.createTarget(store.dir, import_electron_builder.Arch[store.currentArch]);
381
448
  }
382
- if (outPlatform === "win") {
383
- const { pattern } = await import_inquirer.default.prompt([
384
- {
385
- type: "checkbox",
386
- name: "pattern",
387
- message: "\u8BF7\u9009\u62E9\u6784\u5EFA\u6A21\u5F0F , \u8DF3\u8FC7\u9009\u62E9\u4E3A\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u5E73\u53F0 ~",
388
- pageSize: 10,
389
- choices: [
390
- { name: "win-x64", value: import_electron_builder.Arch.x64 },
391
- { name: "win-ia32", value: import_electron_builder.Arch.ia32 }
392
- ]
393
- }
394
- ]).catch((err) => {
395
- console.error("err: ", err);
396
- process.exit(1);
397
- });
398
- const archList = [];
399
- pattern.length ? archList.push(...pattern) : archList.push(import_electron_builder.Arch.x64);
400
- store.targets = import_electron_builder.Platform.WINDOWS.createTarget(!isPackage ? "dir" : null, ...archList);
401
- }
402
- if (outPlatform === "linux")
403
- store.targets = import_electron_builder.Platform.LINUX.createTarget(!isPackage ? "dir" : null, import_electron_builder.Arch.armv7l);
404
- }
405
- if (store.isLinux) {
449
+ } else if (store.isLinux) {
450
+ store.targets = import_electron_builder.Platform.LINUX.createTarget(store.dir, import_electron_builder.Arch.armv7l);
406
451
  }
407
452
  }
408
453
  const initConfig = await electronupConfig(options);
@@ -418,19 +463,18 @@ async function build2(options) {
418
463
  // cli.ts
419
464
  var cli = (0, import_cac.cac)("electronup");
420
465
  cli.option("-m , --mode <mode>", "[development | production | test | staging | ...] \u73AF\u5883\u6A21\u5F0F ");
421
- cli.option("--no-minify", "\u4F7F\u4E3B\u8FDB\u7A0B\u548C\u6E32\u67D3\u8FDB\u7A0B\u4EE3\u7801\u538B\u7F29 ");
422
- cli.command("[config-file]", "start dev server").alias("dev").option("-p , --port <port>", "[number] \u6E32\u67D3\u8FDB\u7A0B\u7684\u7AEF\u53E3\u53F7 \uFF0C\u5982\u679C\u5360\u7528\u4F1A\u5207\u6362\u975E\u5360\u7528\u7684\u7AEF\u53E3 ").action(async (configFile, options) => {
466
+ cli.option("--no-minify", "\u4F7F\u4E3B\u8FDB\u7A0B\u548C\u6E32\u67D3\u8FDB\u7A0B\u4EE3\u7801\u4E0D\u8FDB\u884C\u538B\u7F29 ");
467
+ cli.command("[config-file]", "\u7B49\u540C\u4E8Eelectronup dev ,\u542F\u52A8\u5F00\u53D1\u73AF\u5883\u70ED\u66F4\u65B0").alias("dev").option("-p , --port <port>", "[number] \u6E32\u67D3\u8FDB\u7A0B\u7684\u7AEF\u53E3\u53F7 \uFF0C\u5982\u679C\u5360\u7528\u4F1A\u5207\u6362\u975E\u5360\u7528\u7684\u7AEF\u53E3 ").action(async (configFile, options) => {
423
468
  const { mode, port, minify } = options;
424
469
  const option = await getConfig(configFile);
425
470
  emptyDir((0, import_node_path.resolve)(store.root, option.resourceDir || "dist/resource" /* resourceDir */));
426
- emptyDir((0, import_node_path.resolve)(store.root, option.outDir || "dist/out" /* outDir */));
427
471
  store.command = "serve";
428
472
  store.mode = mode || "development";
429
473
  store.port = port || 8090;
430
474
  store.minify = !!minify;
431
475
  watch(option);
432
476
  });
433
- cli.command("build [root]", "\u6784\u5EFA").option("-o , --option", "\u81EA\u5B9A\u4E49 , \u81EA\u5B9A\u4E49\u6784\u5EFA\u9009\u9879 ").option("--dir", "\u53EA\u751F\u6210\u76EE\u5F55").option("--no-asar", "asar false").option("--win", " \u6784\u5EFA win \u5E73\u53F0\u4E0B\u7684\u8F93\u51FA\u5305").option("--mac", " \u6784\u5EFA mac \u5E73\u53F0\u4E0B\u7684\u8F93\u51FA\u5305").option("--linux", " \u6784\u5EFA linux \u5E73\u53F0\u4E0B\u7684\u8F93\u51FA\u5305").option("--ia32", " \u6784\u5EFA ia32 \u67B6\u6784").option("--x64", " \u6784\u5EFA x64 \u67B6\u6784").option("--arm64", " \u6784\u5EFA arm64 \u67B6\u6784").option("--armv7l", " \u6784\u5EFA armv7l \u67B6\u6784").option("--universal", " \u6784\u5EFA universal \u5E73\u53F0\u5305").action(async (configFile, options) => {
477
+ cli.command("build [root]", "\u5F00\u59CB\u6784\u5EFA\u670D\u52A1 , \u82E5\u4E0D\u6307\u5B9A\u5E73\u53F0\u5219\u9ED8\u8BA4\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u7684\u67B6\u6784\u7C7B\u578B").option("-o , --option", "\u81EA\u5B9A\u4E49 , \u81EA\u5B9A\u4E49\u6784\u5EFA\u9009\u9879 ").option("--dir", "\u53EA\u751F\u6210\u76EE\u5F55").option("--no-asar", "asar false").option("--win [arch]", "[ia32 | x64] \u6784\u5EFA win \u5E73\u53F0\u4E0B\u7684\u8F93\u51FA\u5305 , \u4E0D\u6307\u5B9A\u67B6\u6784\u5219\u8F93\u51FA ia32 \u548C x64\u7684\u4E24\u4E2A\u5305").option("--mac [arch]", "[x64 | arm64 | universal] \u6784\u5EFA mac \u5E73\u53F0\u4E0B\u7684\u8F93\u51FA\u5305 , \u82E5\u4E0D\u6307\u5B9A\u67B6\u6784\u5219\u9ED8\u8BA4\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u7684\u67B6\u6784\u7C7B\u578B").option("--linux", "[x64 | arm64 | armv7l] \u6784\u5EFA linux \u5E73\u53F0\u4E0B\u7684\u8F93\u51FA\u5305 , \u82E5\u4E0D\u6307\u5B9A\u67B6\u6784\u5219\u9ED8\u8BA4\u5F53\u524D\u64CD\u4F5C\u7CFB\u7EDF\u7684\u67B6\u6784\u7C7B\u578B").action(async (configFile, options) => {
434
478
  const {
435
479
  mode,
436
480
  minify,
@@ -438,11 +482,6 @@ cli.command("build [root]", "\u6784\u5EFA").option("-o , --option", "\u81EA\u5B9
438
482
  win,
439
483
  mac,
440
484
  linux,
441
- ia32,
442
- x64,
443
- arm64,
444
- armv7l,
445
- universal,
446
485
  dir,
447
486
  asar
448
487
  } = options;
@@ -453,16 +492,11 @@ cli.command("build [root]", "\u6784\u5EFA").option("-o , --option", "\u81EA\u5B9
453
492
  store.mode = mode || "production";
454
493
  store.minify = minify;
455
494
  store.option = !!option;
456
- store.dir = !!dir;
495
+ store.dir = dir ? "dir" : null;
457
496
  store.asar = asar;
458
- store.win = !!win;
459
- store.mac = !!mac;
460
- store.linux = !!linux;
461
- store.ia32 = !!ia32;
462
- store.x64 = !!x64;
463
- store.arm64 = !!arm64;
464
- store.armv7l = !!armv7l;
465
- store.universal = !!universal;
497
+ store.win = win;
498
+ store.mac = mac;
499
+ store.linux = linux;
466
500
  build2(configOption);
467
501
  });
468
502
  cli.help();
@@ -59,13 +59,20 @@ interface ConfigEnv {
59
59
  root: string
60
60
  }
61
61
 
62
- type ElectronupConfigFnObject = (env: ConfigEnv) => ElectronupConfig;
63
- type ElectronupConfigFnPromise = (env: ConfigEnv) => Promise<ElectronupConfig>;
64
- type ElectronupConfigFn = (env: ConfigEnv) => ElectronupConfig | Promise<ElectronupConfig>;
65
- type ElectronupConfigExport = ElectronupConfig | Promise<ElectronupConfig> | ElectronupConfigFnObject | ElectronupConfigFnPromise | ElectronupConfigFn;
62
+ type ElectronupConfigFnObject = (env: ConfigEnv) => ElectronupConfig
63
+ type ElectronupConfigFnPromise = (env: ConfigEnv) => Promise<ElectronupConfig>
64
+ type ElectronupConfigFn = (env: ConfigEnv) => ElectronupConfig | Promise<ElectronupConfig>
65
+
66
+ type ElectronupConfigExport =
67
+ | ElectronupConfig
68
+ | Promise<ElectronupConfig>
69
+ | ElectronupConfigFnObject
70
+ | ElectronupConfigFnPromise
71
+ | ElectronupConfigFn
72
+
66
73
  declare function defineConfig(config: ElectronupConfig): ElectronupConfig;
67
74
  declare function defineConfig(config: Promise<ElectronupConfig>): Promise<ElectronupConfig>;
68
75
  declare function defineConfig(config: ElectronupConfigFnObject): ElectronupConfigFnObject;
69
76
  declare function defineConfig(config: ElectronupConfigExport): ElectronupConfigExport;
70
77
 
71
- export { BuilderConfig, ConfigEnv, ElectronupConfig, ElectronupConfigExport, ElectronupConfigFn, ElectronupConfigFnObject, ElectronupConfigFnPromise, TsupConfig, ViteConfig, defineConfig };
78
+ export { BuilderConfig, ConfigEnv, ElectronupConfig, TsupConfig, ViteConfig, defineConfig };
@@ -59,13 +59,20 @@ interface ConfigEnv {
59
59
  root: string
60
60
  }
61
61
 
62
- type ElectronupConfigFnObject = (env: ConfigEnv) => ElectronupConfig;
63
- type ElectronupConfigFnPromise = (env: ConfigEnv) => Promise<ElectronupConfig>;
64
- type ElectronupConfigFn = (env: ConfigEnv) => ElectronupConfig | Promise<ElectronupConfig>;
65
- type ElectronupConfigExport = ElectronupConfig | Promise<ElectronupConfig> | ElectronupConfigFnObject | ElectronupConfigFnPromise | ElectronupConfigFn;
62
+ type ElectronupConfigFnObject = (env: ConfigEnv) => ElectronupConfig
63
+ type ElectronupConfigFnPromise = (env: ConfigEnv) => Promise<ElectronupConfig>
64
+ type ElectronupConfigFn = (env: ConfigEnv) => ElectronupConfig | Promise<ElectronupConfig>
65
+
66
+ type ElectronupConfigExport =
67
+ | ElectronupConfig
68
+ | Promise<ElectronupConfig>
69
+ | ElectronupConfigFnObject
70
+ | ElectronupConfigFnPromise
71
+ | ElectronupConfigFn
72
+
66
73
  declare function defineConfig(config: ElectronupConfig): ElectronupConfig;
67
74
  declare function defineConfig(config: Promise<ElectronupConfig>): Promise<ElectronupConfig>;
68
75
  declare function defineConfig(config: ElectronupConfigFnObject): ElectronupConfigFnObject;
69
76
  declare function defineConfig(config: ElectronupConfigExport): ElectronupConfigExport;
70
77
 
71
- export { BuilderConfig, ConfigEnv, ElectronupConfig, ElectronupConfigExport, ElectronupConfigFn, ElectronupConfigFnObject, ElectronupConfigFnPromise, TsupConfig, ViteConfig, defineConfig };
78
+ export { BuilderConfig, ConfigEnv, ElectronupConfig, TsupConfig, ViteConfig, defineConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "electronup",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "description": "融合构建 electron 应用需要的构建工具,保留原有配置习惯的命令行工具 ",
5
5
  "author": "quiteer",
6
6
  "license": "MIT",
@@ -43,18 +43,18 @@
43
43
  },
44
44
  "dependencies": {
45
45
  "@quiteer/parser-config": "^1.0.3",
46
+ "@types/prompts": "^2.4.4",
46
47
  "cac": "^6.7.14",
47
48
  "dotenv": "^16.3.1",
48
- "electron": "^21.2.2",
49
- "electron-builder": "^24.6.3",
50
- "fs-extra": "^11.1.1",
51
- "inquirer": "^9.2.10",
49
+ "electron": "^22.3.6",
50
+ "electron-builder": "^24.9.1",
51
+ "fs-extra": "^11.2.0",
52
+ "kolorist": "^1.8.0",
52
53
  "portfinder": "^1.0.32",
54
+ "prompts": "^2.4.2",
53
55
  "tsup": "^7.2.0",
54
- "vite": "^4.4.9",
55
- "yaml": "^2.3.1"
56
+ "vite": "^4.5.1",
57
+ "yaml": "^2.3.4"
56
58
  },
57
- "devDependencies": {
58
- "@types/inquirer": "^9.0.3"
59
- }
59
+ "devDependencies": { }
60
60
  }