milkio-electron 1.0.0-beta.117

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.
@@ -0,0 +1,56 @@
1
+ name: Build/release Electron app
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ${{ matrix.os }}
11
+
12
+ strategy:
13
+ matrix:
14
+ os: [ubuntu-latest, macos-latest, windows-latest]
15
+
16
+ steps:
17
+ - name: Check out Git repository
18
+ uses: actions/checkout@v3
19
+
20
+ - name: Install Node.js
21
+ uses: actions/setup-node@v3
22
+ with:
23
+ node-version: 16
24
+
25
+ - name: Install Dependencies
26
+ run: npm install
27
+
28
+ - name: build-linux
29
+ if: matrix.os == 'ubuntu-latest'
30
+ run: npm run build:linux
31
+
32
+ - name: build-mac
33
+ if: matrix.os == 'macos-latest'
34
+ run: npm run build:mac
35
+
36
+ - name: build-win
37
+ if: matrix.os == 'windows-latest'
38
+ run: npm run build:win
39
+
40
+ - name: release
41
+ uses: softprops/action-gh-release@v1
42
+ with:
43
+ draft: true
44
+ files: |
45
+ release/*.exe
46
+ release/*.zip
47
+ release/*.dmg
48
+ release/*.AppImage
49
+ release/*.snap
50
+ release/*.deb
51
+ release/*.rpm
52
+ release/*.tar.gz
53
+ release/*.yml
54
+ release/*.blockmap
55
+ env:
56
+ GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
@@ -0,0 +1,97 @@
1
+ {
2
+ "entry": "./foo.js",
3
+ "bundlerOutDir": "./dist",
4
+ "packageJson": {
5
+ "version": "1.0.0",
6
+ "author": "my",
7
+ "name": "my-electron-project",
8
+ "description": "This is My Electron Project, a simple application built with Electron.",
9
+ "scripts": {
10
+ "start": "electron .",
11
+ "build:mac": "electron-builder --mac",
12
+ "build:win": "electron-builder --win",
13
+ "build:linux": "electron-builder --linux"
14
+ },
15
+ "build": {
16
+ "appId": "com.example.electron",
17
+ "copyright": "Your Copyright",
18
+ "artifactName": "setup_${version}_${arch}.${ext}",
19
+ "directories": {
20
+ "output": "release"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "win": {
26
+ "target": [
27
+ {
28
+ "target": "nsis",
29
+ "arch": [
30
+ "x64"
31
+ ]
32
+ }
33
+ ],
34
+ "icon": "icon.ico"
35
+ },
36
+ "nsis": {
37
+ "oneClick": false,
38
+ "perMachine": false,
39
+ "allowToChangeInstallationDirectory": true,
40
+ "deleteAppDataOnUninstall": false,
41
+ "createDesktopShortcut": "always",
42
+ "createStartMenuShortcut": true
43
+ },
44
+ "mac": {
45
+ "target": [
46
+ {
47
+ "target": "dmg",
48
+ "arch": [
49
+ "arm64"
50
+ ]
51
+ },
52
+ {
53
+ "target": "zip",
54
+ "arch": [
55
+ "arm64"
56
+ ]
57
+ }
58
+ ],
59
+ "icon": "public/icon.png",
60
+ "identity": "Your Identity",
61
+ "gatekeeperAssess": false,
62
+ "hardenedRuntime": false,
63
+ "entitlements": null,
64
+ "entitlementsInherit": null,
65
+ "type": "development",
66
+ "strictVerify": false,
67
+ "sign": null,
68
+ "forceCodeSigning": false
69
+ },
70
+ "dmg": {
71
+ "sign": false,
72
+ "contents": [
73
+ {
74
+ "x": 140,
75
+ "y": 150,
76
+ "type": "file"
77
+ },
78
+ {
79
+ "x": 400,
80
+ "y": 150,
81
+ "type": "link",
82
+ "path": "/Applications"
83
+ }
84
+ ]
85
+ },
86
+ "linux": {
87
+ "target": "AppImage",
88
+ "icon": "icon.png"
89
+ }
90
+ },
91
+ "dependencies": {},
92
+ "devDependencies": {
93
+ "electron": "37.2.3",
94
+ "electron-builder": "26.0.12"
95
+ }
96
+ }
97
+ }
package/.pkgrc ADDED
@@ -0,0 +1 @@
1
+ npm
package/LICENSE ADDED
@@ -0,0 +1,26 @@
1
+ GLWTS(Good Luck With That Shit) Public License
2
+ Copyright (c) Every-fucking-one, except the Author
3
+
4
+ Everyone is permitted to copy, distribute, modify, merge, sell, publish,
5
+ sublicense or whatever the fuck they want with this software but at their
6
+ OWN RISK.
7
+
8
+ Preamble
9
+
10
+ The author has absolutely no fucking clue what the code in this project
11
+ does. It might just fucking work or not, there is no third option.
12
+
13
+
14
+ GOOD LUCK WITH THAT SHIT PUBLIC LICENSE
15
+ TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION
16
+
17
+ 0. You just DO WHATEVER THE FUCK YOU WANT TO as long as you NEVER LEAVE
18
+ A FUCKING TRACE TO TRACK THE AUTHOR of the original product to blame for
19
+ or hold responsible.
20
+
21
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24
+ DEALINGS IN THE SOFTWARE.
25
+
26
+ Good luck and Godspeed.
package/README.md ADDED
File without changes
@@ -0,0 +1 @@
1
+ export const __VERSION__ = "1.0.0-beta.117";
package/index.mjs ADDED
@@ -0,0 +1,450 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import os from 'node:os';
6
+ import crypto from 'node:crypto';
7
+ import fse from 'fs-extra';
8
+ import deepmerge from 'deepmerge';
9
+ import { execFileSync } from 'node:child_process';
10
+ import { argv, exit } from 'node:process';
11
+
12
+ const startTime = Date.now();
13
+ const cwd = process.cwd();
14
+ let targetDir;
15
+ let mostRecentDir = null;
16
+ let oldDirs = [];
17
+ let currentDirCleanupNeeded = false;
18
+
19
+ // 错误处理函数
20
+ async function handleError(error) {
21
+ console.error('❌ Process failed:', error.message);
22
+
23
+ try {
24
+ // 需要清理当前目录时才执行
25
+ if (currentDirCleanupNeeded) {
26
+ // 尝试将package-lock.json内容写入旧版本
27
+ if (mostRecentDir && targetDir) {
28
+ const packageLockPath = path.join(targetDir, 'package-lock.json');
29
+ if (fs.existsSync(packageLockPath)) {
30
+ try {
31
+ const content = fs.readFileSync(packageLockPath, 'utf8');
32
+ const destPath = path.join(mostRecentDir, 'package-lock.json');
33
+ fs.writeFileSync(destPath, content);
34
+ console.log(`♻️ Restored package-lock.json to old version directory: ${mostRecentDir}`);
35
+ } catch (err) {
36
+ console.warn('⚠️ Could not restore package-lock.json to old version directory:', err.message);
37
+ }
38
+ }
39
+ }
40
+
41
+ // 删除当前出错的目录
42
+ try {
43
+ if (fs.existsSync(targetDir)) {
44
+ fse.removeSync(targetDir);
45
+ console.log(`🗑️ Deleted current version directory due to error: ${targetDir}`);
46
+ }
47
+ } catch (err) {
48
+ console.warn(`⚠️ Could not delete current version directory ${targetDir}:`, err.message);
49
+ }
50
+ }
51
+ } finally {
52
+ process.exit(1);
53
+ }
54
+ }
55
+
56
+ // ========== 检查electron依赖 ==========
57
+ await (async () => {
58
+ try {
59
+ const pkgPath = path.join(cwd, 'package.json');
60
+ if (!fs.existsSync(pkgPath)) {
61
+ throw new Error('package.json not found in current directory');
62
+ }
63
+
64
+ let pkg;
65
+ try {
66
+ pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
67
+ } catch (error) {
68
+ throw new Error(`Error reading package.json: ${error.message}`);
69
+ }
70
+
71
+ const allDependencies = {
72
+ ...(pkg.dependencies || {}),
73
+ ...(pkg.devDependencies || {})
74
+ };
75
+
76
+ if (!Object.keys(allDependencies).includes('electron')) {
77
+ throw new Error('electron dependency not found in package.json');
78
+ }
79
+ } catch (error) {
80
+ await handleError(error);
81
+ }
82
+ })();
83
+
84
+ // ========== 创建基础目录 ==========
85
+ let baseDir;
86
+ await (async () => {
87
+ try {
88
+ const homeDir = os.homedir();
89
+ baseDir = path.join(homeDir, '.milkio-electron');
90
+ fse.ensureDirSync(baseDir);
91
+ } catch (error) {
92
+ await handleError(new Error(`Error creating directory ${baseDir}: ${error.message}`));
93
+ }
94
+ })();
95
+
96
+ // ========== 生成目录哈希值 ==========
97
+ let hash;
98
+ await (async () => {
99
+ try {
100
+ const hashGenerator = crypto.createHash('sha256');
101
+ hashGenerator.update(cwd);
102
+ hash = hashGenerator.digest('hex').slice(0, 16);
103
+ } catch (error) {
104
+ console.warn('⚠️ Error generating directory hash, using timestamp instead:', error.message);
105
+ hash = Date.now().toString();
106
+ }
107
+ })();
108
+
109
+ // ========== 创建哈希目录 ==========
110
+ const hashDir = path.join(baseDir, hash);
111
+ targetDir = path.join(hashDir, startTime.toString());
112
+ await (async () => {
113
+ try {
114
+ fse.ensureDirSync(hashDir);
115
+ } catch (error) {
116
+ await handleError(new Error(`Error creating directory ${hashDir}: ${error.message}`));
117
+ }
118
+ })();
119
+
120
+ // ========== 复制文件到目标目录 ==========
121
+ await (async () => {
122
+ currentDirCleanupNeeded = true; // 标记为需要清理
123
+ try {
124
+ const projectConfigDir = path.join(cwd, '.milkio-electron');
125
+ fse.ensureDirSync(projectConfigDir);
126
+ const projectConfigPath = path.join(projectConfigDir, 'config.json');
127
+ if (!fs.existsSync(projectConfigPath)) {
128
+ fs.writeFileSync(projectConfigPath, JSON.stringify({
129
+ entry: "./foo.js",
130
+ bundlerOutDir: "./dist",
131
+ packageJson: {
132
+ version: "1.0.0",
133
+ repository: {
134
+ "type": "git",
135
+ "url": "https://github.com/akirarika/milkio-electron.git"
136
+ },
137
+ author: "my",
138
+ name: "my-electron-project",
139
+ description: "This is My Electron Project, a simple application built with Electron.",
140
+ scripts: {
141
+ "build:mac": "electron-builder --mac",
142
+ "build:win": "electron-builder --win",
143
+ "build:linux": "electron-builder --linux",
144
+ },
145
+ build: {
146
+ "appId": "com.example.electron",
147
+ "copyright": "Your Copyright",
148
+ "artifactName": "setup_${version}_${arch}.${ext}",
149
+ "directories": {
150
+ "output": "release"
151
+ },
152
+ "files": [
153
+ "dist"
154
+ ],
155
+ "win": {
156
+ "target": [
157
+ {
158
+ "target": "nsis",
159
+ "arch": [
160
+ "x64"
161
+ ]
162
+ }
163
+ ],
164
+ "icon": "icon.ico"
165
+ },
166
+ "nsis": {
167
+ "oneClick": false,
168
+ "perMachine": false,
169
+ "allowToChangeInstallationDirectory": true,
170
+ "deleteAppDataOnUninstall": false,
171
+ "createDesktopShortcut": "always",
172
+ "createStartMenuShortcut": true
173
+ },
174
+ "mac": {
175
+ "target": [
176
+ {
177
+ "target": "dmg",
178
+ "arch": [
179
+ "arm64"
180
+ ]
181
+ },
182
+ {
183
+ "target": "zip",
184
+ "arch": [
185
+ "arm64"
186
+ ]
187
+ }
188
+ ],
189
+ "icon": "public/icon.png",
190
+ "identity": "Your Identity",
191
+ "gatekeeperAssess": false,
192
+ "hardenedRuntime": false,
193
+ "entitlements": null,
194
+ "entitlementsInherit": null,
195
+ "type": "development",
196
+ "strictVerify": false,
197
+ "sign": null,
198
+ "forceCodeSigning": false
199
+ },
200
+ "dmg": {
201
+ "sign": false,
202
+ "contents": [
203
+ {
204
+ "x": 140,
205
+ "y": 150,
206
+ "type": "file"
207
+ },
208
+ {
209
+ "x": 400,
210
+ "y": 150,
211
+ "type": "link",
212
+ "path": "/Applications"
213
+ }
214
+ ]
215
+ },
216
+ "linux": {
217
+ "target": "AppImage",
218
+ "icon": "icon.png"
219
+ }
220
+ },
221
+ dependencies: {
222
+ },
223
+ devDependencies: {
224
+ "electron": "37.2.3",
225
+ "electron-builder": "26.0.12",
226
+ }
227
+ }
228
+ }, null, 2));
229
+ console.log('📝 Created project-level config file');
230
+
231
+ // 创建 .github/workflows 目录
232
+ const projectWorkflowsDir = path.join(projectConfigDir, '.github', 'workflows');
233
+ fse.ensureDirSync(projectWorkflowsDir);
234
+ const projectBuildYmlPath = path.join(projectWorkflowsDir, 'build.yml');
235
+
236
+ // 创建 build.yml
237
+ const buildYmlContent = `
238
+ name: Build/release Electron app
239
+
240
+ on:
241
+ push:
242
+ branches:
243
+ - main
244
+
245
+ jobs:
246
+ release:
247
+ runs-on: \${{ matrix.os }}
248
+
249
+ strategy:
250
+ matrix:
251
+ os: [ubuntu-latest, macos-latest, windows-latest]
252
+
253
+ steps:
254
+ - name: Check out Git repository
255
+ uses: actions/checkout@v3
256
+
257
+ - name: Install Node.js
258
+ uses: actions/setup-node@v3
259
+ with:
260
+ node-version: 16
261
+
262
+ - name: Install Dependencies
263
+ run: npm install
264
+
265
+ - name: build-linux
266
+ if: matrix.os == 'ubuntu-latest'
267
+ run: npm run build:linux
268
+
269
+ - name: build-mac
270
+ if: matrix.os == 'macos-latest'
271
+ run: npm run build:mac
272
+
273
+ - name: build-win
274
+ if: matrix.os == 'windows-latest'
275
+ run: npm run build:win
276
+
277
+ - name: release
278
+ uses: softprops/action-gh-release@v1
279
+ with:
280
+ draft: true
281
+ files: |
282
+ release/*.exe
283
+ release/*.zip
284
+ release/*.dmg
285
+ release/*.AppImage
286
+ release/*.snap
287
+ release/*.deb
288
+ release/*.rpm
289
+ release/*.tar.gz
290
+ release/*.yml
291
+ release/*.blockmap
292
+ env:
293
+ GITHUB_TOKEN: \${{ secrets.GH_TOKEN }}
294
+ `.trim();
295
+ fs.writeFileSync(projectBuildYmlPath, buildYmlContent, 'utf8');
296
+ console.log('📝 Created default build.yml in project config directory');
297
+
298
+
299
+ console.log('✅ The project initialization is complete. Please modify .milkio-electron/config.json and then run it again.');
300
+
301
+ exit(0);
302
+ } else {
303
+ // 复制除config.json外的所有项目配置
304
+ const items = fs.readdirSync(projectConfigDir);
305
+ for (const item of items) {
306
+ if (item === 'config.json') continue;
307
+
308
+ const source = path.join(projectConfigDir, item);
309
+ const dest = path.join(targetDir, item);
310
+
311
+ if (fs.statSync(source).isDirectory()) {
312
+ fse.copySync(source, dest, { recursive: true });
313
+ } else {
314
+ fse.copySync(source, dest);
315
+ }
316
+
317
+ console.log(`📝 Copied configuration: ${item}`);
318
+ }
319
+ }
320
+ } catch (error) {
321
+ await handleError(new Error(`Error copying files: ${error.message}`));
322
+ }
323
+ })();
324
+
325
+ // ========== 检查并创建必要文件 ==========
326
+ const publisherConfigJson = JSON.parse(fs.readFileSync(path.join(cwd, '.milkio-electron', 'config.json'), 'utf8'));
327
+ // 确保dist目录存在
328
+ const distTarget = path.join(targetDir, 'dist');
329
+ fse.ensureDirSync(distTarget);
330
+ // 复制构建输出的dist文件到targetDir/dist
331
+ fse.copySync(path.join(cwd, publisherConfigJson.bundlerOutDir ?? "dist"), distTarget);
332
+ console.log(`📂 Copied dist files to: ${distTarget}`);
333
+
334
+ await (async () => {
335
+ try {
336
+ // 检查禁止文件是否存在
337
+ const packageJsonPath = path.join(targetDir, 'package.json');
338
+ const erunPath = path.join(distTarget, '__ERUN__.mjs');
339
+ const gitignorePath = path.join(targetDir, '.gitignore');
340
+
341
+ // 确保目标目录的.github/workflows已经存在(如果已复制)
342
+ baseDir = path.join(targetDir, '.github', 'workflows');
343
+ fse.ensureDirSync(baseDir);
344
+
345
+ if (fs.existsSync(packageJsonPath) || fs.existsSync(erunPath)) {
346
+ throw new Error('The dist directory should not contain package.json or __ERUN__.mjs files. Please remove them from your dist directory.');
347
+ }
348
+
349
+ const packageJsonContent = {
350
+ "type": "module",
351
+ "main": "dist/__ERUN__.mjs",
352
+ };
353
+ fs.writeFileSync(packageJsonPath, JSON.stringify(deepmerge(publisherConfigJson.packageJson || {}, packageJsonContent)), 'utf8');
354
+
355
+ // 创建 __ERUN__.mjs 在dist目录下
356
+ const erunContent = `
357
+ import electron from 'electron';
358
+ globalThis.electron = electron;
359
+ await import('${publisherConfigJson.entry}');
360
+ `.trim();
361
+ fs.writeFileSync(erunPath, erunContent, 'utf8');
362
+
363
+ // 创建 .gitignore
364
+ if (!fs.existsSync(gitignorePath)) {
365
+ fs.writeFileSync(gitignorePath, 'node_modules\nout\ndist\n');
366
+ }
367
+
368
+ console.log('✅ Created package.json and dist/__ERUN__.mjs');
369
+ } catch (error) {
370
+ await handleError(error);
371
+ }
372
+ })();
373
+
374
+ // ========== 查找历史版本 ==========
375
+ await (async () => {
376
+ try {
377
+ oldDirs = fs.readdirSync(hashDir)
378
+ .map(dir => path.join(hashDir, dir))
379
+ .filter(dir => {
380
+ const isDir = fs.lstatSync(dir).isDirectory();
381
+ return isDir && path.basename(dir) !== startTime.toString();
382
+ });
383
+
384
+ if (oldDirs.length >= 1) {
385
+ // 找到最近的历史目录
386
+ const sortedDirs = oldDirs
387
+ .map(dir => ({ path: dir, time: parseInt(path.basename(dir)) }))
388
+ .sort((a, b) => b.time - a.time);
389
+
390
+ if (sortedDirs.length > 0) {
391
+ mostRecentDir = sortedDirs[0].path;
392
+
393
+ // 移动 node_modules 和 package-lock.json
394
+ ['node_modules', 'package-lock.json'].forEach(item => {
395
+ const source = path.join(mostRecentDir, item);
396
+ const dest = path.join(targetDir, item);
397
+
398
+ if (fs.existsSync(source)) {
399
+ try {
400
+ fse.moveSync(source, dest, { overwrite: true });
401
+ console.log(`♻️ Moved ${item} from previous version`);
402
+ } catch (error) {
403
+ console.warn(`⚠️ Could not move ${item}: ${error.message}`);
404
+ }
405
+ }
406
+ });
407
+ }
408
+ }
409
+ } catch (error) {
410
+ await handleError(error);
411
+ }
412
+ })();
413
+
414
+ // ========== 运行 npm install ==========
415
+ await (async () => {
416
+ try {
417
+ console.log('⏳ Running npm install...');
418
+ execFileSync('npm', ['install'], { cwd: targetDir, stdio: 'inherit' });
419
+ console.log('✅ npm install completed successfully');
420
+ } catch (error) {
421
+ await handleError(new Error(`npm install failed: ${error.message}`));
422
+ }
423
+
424
+ execFileSync('npm', ['run', ...argv.slice(2)], { cwd: targetDir, stdio: 'inherit' });
425
+ })();
426
+
427
+ // ========== 清理旧版本 ==========
428
+ await (async () => {
429
+ if (oldDirs.length > 0) {
430
+ try {
431
+ oldDirs.forEach(dir => {
432
+ try {
433
+ fse.removeSync(dir);
434
+ console.log(`🗑️ Deleted old directory: ${dir}`);
435
+ } catch (error) {
436
+ console.warn(`⚠️ Could not delete old directory ${dir}:`, error.message);
437
+ }
438
+ });
439
+ } catch (error) {
440
+ console.warn('⚠️ Error during old version cleanup:', error.message);
441
+ }
442
+ }
443
+ })();
444
+
445
+ // ========== 最终清理标记 ==========
446
+ currentDirCleanupNeeded = false;
447
+
448
+ // ========== 输出总耗时 ==========
449
+ const totalTime = ((Date.now() - startTime) / 1000).toFixed(2);
450
+ console.log(`✨ All tasks completed in ${totalTime} seconds`);
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "milkio-electron",
3
+ "version": "1.0.0-beta.117",
4
+ "type": "module",
5
+ "description": "Automated Electron project publisher",
6
+ "main": "index.mjs",
7
+ "bin": {
8
+ "milkio-electron": "index.mjs"
9
+ },
10
+ "scripts": {
11
+ "dev": "node index.mjs"
12
+ },
13
+ "keywords": [
14
+ "electron",
15
+ "publisher",
16
+ "automation"
17
+ ],
18
+ "author": "Your Name",
19
+ "license": "MIT",
20
+ "devDependencies": {
21
+ "electron": "*"
22
+ },
23
+ "dependencies": {
24
+ "deepmerge": "^4.3.1",
25
+ "fs-extra": "^11.2.0"
26
+ }
27
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "compilerOptions": {
3
+ // Environment setup & latest features
4
+ "lib": ["ESNext"],
5
+ "target": "ESNext",
6
+ "module": "Preserve",
7
+ "moduleDetection": "force",
8
+ "jsx": "react-jsx",
9
+ "allowJs": true,
10
+
11
+ // Bundler mode
12
+ "moduleResolution": "bundler",
13
+ "allowImportingTsExtensions": true,
14
+ "verbatimModuleSyntax": true,
15
+ "noEmit": true,
16
+
17
+ // Best practices
18
+ "strict": true,
19
+ "skipLibCheck": true,
20
+ "noFallthroughCasesInSwitch": true,
21
+ "noUncheckedIndexedAccess": true,
22
+ "noImplicitOverride": true,
23
+
24
+ // Some stricter flags (disabled by default)
25
+ "noUnusedLocals": false,
26
+ "noUnusedParameters": false,
27
+ "noPropertyAccessFromIndexSignature": false
28
+ }
29
+ }