milkio-electron 1.0.0-beta.201 → 1.0.0-beta.204

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.
@@ -1,56 +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:
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
56
  GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
@@ -1,97 +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
- }
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
97
  }
package/LICENSE CHANGED
@@ -1,26 +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
-
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
26
  Good luck and Godspeed.
package/__VERSION__.mjs CHANGED
@@ -1 +1 @@
1
- export const __VERSION__ = "1.0.0-beta.201";
1
+ export const __VERSION__ = "1.0.0-beta.202";
package/__VERSION__.ts ADDED
@@ -0,0 +1 @@
1
+ export const __VERSION__ = '1.0.0-beta.204'
package/index.mjs CHANGED
@@ -1,424 +1,424 @@
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
- async function handleError(error) {
20
- console.error('❌ Process failed:', error.message);
21
-
22
- try {
23
- if (currentDirCleanupNeeded) {
24
- if (mostRecentDir && targetDir) {
25
- const packageLockPath = path.join(targetDir, 'package-lock.json');
26
- if (fs.existsSync(packageLockPath)) {
27
- try {
28
- const content = fs.readFileSync(packageLockPath, 'utf8');
29
- const destPath = path.join(mostRecentDir, 'package-lock.json');
30
- fs.writeFileSync(destPath, content);
31
- console.log(`♻️ Restored package-lock.json to old version directory: ${mostRecentDir}`);
32
- } catch (err) {
33
- console.warn('⚠️ Could not restore package-lock.json to old version directory:', err.message);
34
- }
35
- }
36
- }
37
-
38
- try {
39
- if (fs.existsSync(targetDir)) {
40
- fse.removeSync(targetDir);
41
- console.log(`🗑️ Deleted current version directory due to error: ${targetDir}`);
42
- }
43
- } catch (err) {
44
- console.warn(`⚠️ Could not delete current version directory ${targetDir}:`, err.message);
45
- }
46
- }
47
- } finally {
48
- process.exit(1);
49
- }
50
- }
51
-
52
- await (async () => {
53
- try {
54
- const pkgPath = path.join(cwd, 'package.json');
55
- if (!fs.existsSync(pkgPath)) {
56
- throw new Error('package.json not found in current directory');
57
- }
58
-
59
- let pkg;
60
- try {
61
- pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
62
- } catch (error) {
63
- throw new Error(`Error reading package.json: ${error.message}`);
64
- }
65
-
66
- const allDependencies = {
67
- ...pkg.dependencies,
68
- ...pkg.devDependencies
69
- };
70
-
71
- if (!Object.keys(allDependencies).includes('electron')) {
72
- throw new Error('electron dependency not found in package.json');
73
- }
74
- } catch (error) {
75
- await handleError(error);
76
- }
77
- })();
78
-
79
- let baseDir;
80
- await (async () => {
81
- try {
82
- const homeDir = os.homedir();
83
- baseDir = path.join(homeDir, '.milkio-electron');
84
- fse.ensureDirSync(baseDir);
85
- } catch (error) {
86
- await handleError(new Error(`Error creating directory ${baseDir}: ${error.message}`));
87
- }
88
- })();
89
-
90
- let hash;
91
- await (async () => {
92
- try {
93
- const hashGenerator = crypto.createHash('sha256');
94
- hashGenerator.update(cwd);
95
- hash = hashGenerator.digest('hex').slice(0, 16);
96
- } catch (error) {
97
- console.warn('⚠️ Error generating directory hash, using timestamp instead:', error.message);
98
- hash = Date.now().toString();
99
- }
100
- })();
101
-
102
- const hashDir = path.join(baseDir, hash);
103
- targetDir = path.join(hashDir, startTime.toString());
104
- await (async () => {
105
- try {
106
- fse.ensureDirSync(hashDir);
107
- } catch (error) {
108
- await handleError(new Error(`Error creating directory ${hashDir}: ${error.message}`));
109
- }
110
- })();
111
-
112
- await (async () => {
113
- currentDirCleanupNeeded = true;
114
- try {
115
- const projectConfigDir = path.join(cwd, '.milkio-electron');
116
- fse.ensureDirSync(projectConfigDir);
117
- const projectConfigPath = path.join(projectConfigDir, 'config.json');
118
- if (!fs.existsSync(projectConfigPath)) {
119
- fs.writeFileSync(projectConfigPath, JSON.stringify({
120
- entry: "./foo.js",
121
- bundlerOutDir: "./dist",
122
- packageJson: {
123
- version: "1.0.0",
124
- repository: {
125
- "type": "git",
126
- "url": "https://github.com/akirarika/milkio-electron.git"
127
- },
128
- author: "my",
129
- name: "my-electron-project",
130
- description: "This is My Electron Project, a simple application built with Electron.",
131
- scripts: {
132
- "build:mac": "electron-builder --mac",
133
- "build:win": "electron-builder --win",
134
- "build:linux": "electron-builder --linux",
135
- },
136
- build: {
137
- "appId": "com.example.electron",
138
- "copyright": "Your Copyright",
139
- "artifactName": "setup_${version}_${arch}.${ext}",
140
- "directories": {
141
- "output": "release"
142
- },
143
- "files": [
144
- "dist"
145
- ],
146
- "win": {
147
- "target": [
148
- {
149
- "target": "nsis",
150
- "arch": [
151
- "x64"
152
- ]
153
- }
154
- ],
155
- "icon": "icon.ico"
156
- },
157
- "nsis": {
158
- "oneClick": false,
159
- "perMachine": false,
160
- "allowToChangeInstallationDirectory": true,
161
- "deleteAppDataOnUninstall": false,
162
- "createDesktopShortcut": "always",
163
- "createStartMenuShortcut": true
164
- },
165
- "mac": {
166
- "target": [
167
- {
168
- "target": "dmg",
169
- "arch": [
170
- "arm64"
171
- ]
172
- },
173
- {
174
- "target": "zip",
175
- "arch": [
176
- "arm64"
177
- ]
178
- }
179
- ],
180
- "icon": "public/icon.png",
181
- "identity": "Your Identity",
182
- "gatekeeperAssess": false,
183
- "hardenedRuntime": false,
184
- "entitlements": null,
185
- "entitlementsInherit": null,
186
- "type": "development",
187
- "strictVerify": false,
188
- "sign": null,
189
- "forceCodeSigning": false
190
- },
191
- "dmg": {
192
- "sign": false,
193
- "contents": [
194
- {
195
- "x": 140,
196
- "y": 150,
197
- "type": "file"
198
- },
199
- {
200
- "x": 400,
201
- "y": 150,
202
- "type": "link",
203
- "path": "/Applications"
204
- }
205
- ]
206
- },
207
- "linux": {
208
- "target": "AppImage",
209
- "icon": "icon.png"
210
- }
211
- },
212
- dependencies: {
213
- },
214
- devDependencies: {
215
- "electron": "37.2.3",
216
- "electron-builder": "26.0.12",
217
- }
218
- }
219
- }, null, 2));
220
- console.log('📝 Created project-level config file');
221
-
222
- const projectWorkflowsDir = path.join(projectConfigDir, '.github', 'workflows');
223
- fse.ensureDirSync(projectWorkflowsDir);
224
- const projectBuildYmlPath = path.join(projectWorkflowsDir, 'build.yml');
225
-
226
- const buildYmlContent = `
227
- name: Build/release Electron app
228
-
229
- on:
230
- push:
231
- branches:
232
- - main
233
-
234
- jobs:
235
- release:
236
- runs-on: \${{ matrix.os }}
237
-
238
- strategy:
239
- matrix:
240
- os: [ubuntu-latest, macos-latest, windows-latest]
241
-
242
- steps:
243
- - name: Check out Git repository
244
- uses: actions/checkout@v3
245
-
246
- - name: Install Node.js
247
- uses: actions/setup-node@v3
248
- with:
249
- node-version: 16
250
-
251
- - name: Install Dependencies
252
- run: npm install
253
-
254
- - name: build-linux
255
- if: matrix.os == 'ubuntu-latest'
256
- run: npm run build:linux
257
-
258
- - name: build-mac
259
- if: matrix.os == 'macos-latest'
260
- run: npm run build:mac
261
-
262
- - name: build-win
263
- if: matrix.os == 'windows-latest'
264
- run: npm run build:win
265
-
266
- - name: release
267
- uses: softprops/action-gh-release@v1
268
- with:
269
- draft: true
270
- files: |
271
- release/*.exe
272
- release/*.zip
273
- release/*.dmg
274
- release/*.AppImage
275
- release/*.snap
276
- release/*.deb
277
- release/*.rpm
278
- release/*.tar.gz
279
- release/*.yml
280
- release/*.blockmap
281
- env:
282
- GITHUB_TOKEN: \${{ secrets.GH_TOKEN }}
283
- `.trim();
284
- fs.writeFileSync(projectBuildYmlPath, buildYmlContent, 'utf8');
285
- console.log('📝 Created default build.yml in project config directory');
286
-
287
-
288
- console.log('✅ The project initialization is complete. Please modify .milkio-electron/config.json and then run it again.');
289
-
290
- exit(0);
291
- } else {
292
- const items = fs.readdirSync(projectConfigDir);
293
- for (const item of items) {
294
- if (item === 'config.json') continue;
295
-
296
- const source = path.join(projectConfigDir, item);
297
- const dest = path.join(targetDir, item);
298
-
299
- if (fs.statSync(source).isDirectory()) {
300
- fse.copySync(source, dest, { recursive: true });
301
- } else {
302
- fse.copySync(source, dest);
303
- }
304
-
305
- console.log(`📝 Copied configuration: ${item}`);
306
- }
307
- }
308
- } catch (error) {
309
- await handleError(new Error(`Error copying files: ${error.message}`));
310
- }
311
- })();
312
-
313
- const publisherConfigJson = JSON.parse(fs.readFileSync(path.join(cwd, '.milkio-electron', 'config.json'), 'utf8'));
314
- const distTarget = path.join(targetDir, 'dist');
315
- fse.ensureDirSync(distTarget);
316
- fse.copySync(path.join(cwd, publisherConfigJson.bundlerOutDir ?? "dist"), distTarget);
317
- console.log(`📂 Copied dist files to: ${distTarget}`);
318
-
319
- await (async () => {
320
- try {
321
- const packageJsonPath = path.join(targetDir, 'package.json');
322
- const erunPath = path.join(distTarget, '__ERUN__.mjs');
323
- const gitignorePath = path.join(targetDir, '.gitignore');
324
-
325
- baseDir = path.join(targetDir, '.github', 'workflows');
326
- fse.ensureDirSync(baseDir);
327
-
328
- if (fs.existsSync(packageJsonPath) || fs.existsSync(erunPath)) {
329
- throw new Error('The dist directory should not contain package.json or __ERUN__.mjs files. Please remove them from your dist directory.');
330
- }
331
-
332
- const packageJsonContent = {
333
- "type": "module",
334
- "main": "dist/__ERUN__.mjs",
335
- };
336
- fs.writeFileSync(packageJsonPath, JSON.stringify(deepmerge(publisherConfigJson.packageJson || {}, packageJsonContent)), 'utf8');
337
-
338
- const erunContent = `
339
- import electron from 'electron';
340
- globalThis.electron = electron;
341
- await import('${publisherConfigJson.entry}');
342
- `.trim();
343
- fs.writeFileSync(erunPath, erunContent, 'utf8');
344
-
345
- if (!fs.existsSync(gitignorePath)) {
346
- fs.writeFileSync(gitignorePath, 'node_modules\nout\ndist\n');
347
- }
348
-
349
- console.log('✅ Created package.json and dist/__ERUN__.mjs');
350
- } catch (error) {
351
- await handleError(error);
352
- }
353
- })();
354
-
355
- await (async () => {
356
- try {
357
- oldDirs = fs.readdirSync(hashDir)
358
- .map(dir => path.join(hashDir, dir))
359
- .filter(dir => {
360
- const isDir = fs.lstatSync(dir).isDirectory();
361
- return isDir && path.basename(dir) !== startTime.toString();
362
- });
363
-
364
- if (oldDirs.length >= 1) {
365
- const sortedDirs = oldDirs
366
- .map(dir => ({ path: dir, time: parseInt(path.basename(dir)) }))
367
- .sort((a, b) => b.time - a.time);
368
-
369
- if (sortedDirs.length > 0) {
370
- mostRecentDir = sortedDirs[0].path;
371
-
372
- ['node_modules', 'package-lock.json'].forEach(item => {
373
- const source = path.join(mostRecentDir, item);
374
- const dest = path.join(targetDir, item);
375
-
376
- if (fs.existsSync(source)) {
377
- try {
378
- fse.moveSync(source, dest, { overwrite: true });
379
- console.log(`♻️ Moved ${item} from previous version`);
380
- } catch (error) {
381
- console.warn(`⚠️ Could not move ${item}: ${error.message}`);
382
- }
383
- }
384
- });
385
- }
386
- }
387
- } catch (error) {
388
- await handleError(error);
389
- }
390
- })();
391
-
392
- await (async () => {
393
- try {
394
- console.log('⏳ Running npm install...');
395
- execFileSync('npm', ['install'], { cwd: targetDir, stdio: 'inherit' });
396
- console.log('✅ npm install completed successfully');
397
- } catch (error) {
398
- await handleError(new Error(`npm install failed: ${error.message}`));
399
- }
400
-
401
- const totalTime = ((Date.now() - startTime) / 1000).toFixed(2);
402
- console.log(`✨ All tasks completed in ${totalTime} seconds`);
403
-
404
- execFileSync('npm', ['run', ...argv.slice(2)], { cwd: targetDir, stdio: 'inherit' });
405
- })();
406
-
407
- await (async () => {
408
- if (oldDirs.length > 0) {
409
- try {
410
- oldDirs.forEach(dir => {
411
- try {
412
- fse.removeSync(dir);
413
- console.log(`🗑️ Deleted old directory: ${dir}`);
414
- } catch (error) {
415
- console.warn(`⚠️ Could not delete old directory ${dir}:`, error.message);
416
- }
417
- });
418
- } catch (error) {
419
- console.warn('⚠️ Error during old version cleanup:', error.message);
420
- }
421
- }
422
- })();
423
-
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
+ async function handleError(error) {
20
+ console.error('❌ Process failed:', error.message);
21
+
22
+ try {
23
+ if (currentDirCleanupNeeded) {
24
+ if (mostRecentDir && targetDir) {
25
+ const packageLockPath = path.join(targetDir, 'package-lock.json');
26
+ if (fs.existsSync(packageLockPath)) {
27
+ try {
28
+ const content = fs.readFileSync(packageLockPath, 'utf8');
29
+ const destPath = path.join(mostRecentDir, 'package-lock.json');
30
+ fs.writeFileSync(destPath, content);
31
+ console.log(`♻️ Restored package-lock.json to old version directory: ${mostRecentDir}`);
32
+ } catch (err) {
33
+ console.warn('⚠️ Could not restore package-lock.json to old version directory:', err.message);
34
+ }
35
+ }
36
+ }
37
+
38
+ try {
39
+ if (fs.existsSync(targetDir)) {
40
+ fse.removeSync(targetDir);
41
+ console.log(`🗑️ Deleted current version directory due to error: ${targetDir}`);
42
+ }
43
+ } catch (err) {
44
+ console.warn(`⚠️ Could not delete current version directory ${targetDir}:`, err.message);
45
+ }
46
+ }
47
+ } finally {
48
+ process.exit(1);
49
+ }
50
+ }
51
+
52
+ await (async () => {
53
+ try {
54
+ const pkgPath = path.join(cwd, 'package.json');
55
+ if (!fs.existsSync(pkgPath)) {
56
+ throw new Error('package.json not found in current directory');
57
+ }
58
+
59
+ let pkg;
60
+ try {
61
+ pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf8'));
62
+ } catch (error) {
63
+ throw new Error(`Error reading package.json: ${error.message}`);
64
+ }
65
+
66
+ const allDependencies = {
67
+ ...pkg.dependencies,
68
+ ...pkg.devDependencies
69
+ };
70
+
71
+ if (!Object.keys(allDependencies).includes('electron')) {
72
+ throw new Error('electron dependency not found in package.json');
73
+ }
74
+ } catch (error) {
75
+ await handleError(error);
76
+ }
77
+ })();
78
+
79
+ let baseDir;
80
+ await (async () => {
81
+ try {
82
+ const homeDir = os.homedir();
83
+ baseDir = path.join(homeDir, '.milkio-electron');
84
+ fse.ensureDirSync(baseDir);
85
+ } catch (error) {
86
+ await handleError(new Error(`Error creating directory ${baseDir}: ${error.message}`));
87
+ }
88
+ })();
89
+
90
+ let hash;
91
+ await (async () => {
92
+ try {
93
+ const hashGenerator = crypto.createHash('sha256');
94
+ hashGenerator.update(cwd);
95
+ hash = hashGenerator.digest('hex').slice(0, 16);
96
+ } catch (error) {
97
+ console.warn('⚠️ Error generating directory hash, using timestamp instead:', error.message);
98
+ hash = Date.now().toString();
99
+ }
100
+ })();
101
+
102
+ const hashDir = path.join(baseDir, hash);
103
+ targetDir = path.join(hashDir, startTime.toString());
104
+ await (async () => {
105
+ try {
106
+ fse.ensureDirSync(hashDir);
107
+ } catch (error) {
108
+ await handleError(new Error(`Error creating directory ${hashDir}: ${error.message}`));
109
+ }
110
+ })();
111
+
112
+ await (async () => {
113
+ currentDirCleanupNeeded = true;
114
+ try {
115
+ const projectConfigDir = path.join(cwd, '.milkio-electron');
116
+ fse.ensureDirSync(projectConfigDir);
117
+ const projectConfigPath = path.join(projectConfigDir, 'config.json');
118
+ if (!fs.existsSync(projectConfigPath)) {
119
+ fs.writeFileSync(projectConfigPath, JSON.stringify({
120
+ entry: "./foo.js",
121
+ bundlerOutDir: "./dist",
122
+ packageJson: {
123
+ version: "1.0.0",
124
+ repository: {
125
+ "type": "git",
126
+ "url": "https://github.com/akirarika/milkio-electron.git"
127
+ },
128
+ author: "my",
129
+ name: "my-electron-project",
130
+ description: "This is My Electron Project, a simple application built with Electron.",
131
+ scripts: {
132
+ "build:mac": "electron-builder --mac",
133
+ "build:win": "electron-builder --win",
134
+ "build:linux": "electron-builder --linux",
135
+ },
136
+ build: {
137
+ "appId": "com.example.electron",
138
+ "copyright": "Your Copyright",
139
+ "artifactName": "setup_${version}_${arch}.${ext}",
140
+ "directories": {
141
+ "output": "release"
142
+ },
143
+ "files": [
144
+ "dist"
145
+ ],
146
+ "win": {
147
+ "target": [
148
+ {
149
+ "target": "nsis",
150
+ "arch": [
151
+ "x64"
152
+ ]
153
+ }
154
+ ],
155
+ "icon": "icon.ico"
156
+ },
157
+ "nsis": {
158
+ "oneClick": false,
159
+ "perMachine": false,
160
+ "allowToChangeInstallationDirectory": true,
161
+ "deleteAppDataOnUninstall": false,
162
+ "createDesktopShortcut": "always",
163
+ "createStartMenuShortcut": true
164
+ },
165
+ "mac": {
166
+ "target": [
167
+ {
168
+ "target": "dmg",
169
+ "arch": [
170
+ "arm64"
171
+ ]
172
+ },
173
+ {
174
+ "target": "zip",
175
+ "arch": [
176
+ "arm64"
177
+ ]
178
+ }
179
+ ],
180
+ "icon": "public/icon.png",
181
+ "identity": "Your Identity",
182
+ "gatekeeperAssess": false,
183
+ "hardenedRuntime": false,
184
+ "entitlements": null,
185
+ "entitlementsInherit": null,
186
+ "type": "development",
187
+ "strictVerify": false,
188
+ "sign": null,
189
+ "forceCodeSigning": false
190
+ },
191
+ "dmg": {
192
+ "sign": false,
193
+ "contents": [
194
+ {
195
+ "x": 140,
196
+ "y": 150,
197
+ "type": "file"
198
+ },
199
+ {
200
+ "x": 400,
201
+ "y": 150,
202
+ "type": "link",
203
+ "path": "/Applications"
204
+ }
205
+ ]
206
+ },
207
+ "linux": {
208
+ "target": "AppImage",
209
+ "icon": "icon.png"
210
+ }
211
+ },
212
+ dependencies: {
213
+ },
214
+ devDependencies: {
215
+ "electron": "37.2.3",
216
+ "electron-builder": "26.0.12",
217
+ }
218
+ }
219
+ }, null, 2));
220
+ console.log('📝 Created project-level config file');
221
+
222
+ const projectWorkflowsDir = path.join(projectConfigDir, '.github', 'workflows');
223
+ fse.ensureDirSync(projectWorkflowsDir);
224
+ const projectBuildYmlPath = path.join(projectWorkflowsDir, 'build.yml');
225
+
226
+ const buildYmlContent = `
227
+ name: Build/release Electron app
228
+
229
+ on:
230
+ push:
231
+ branches:
232
+ - main
233
+
234
+ jobs:
235
+ release:
236
+ runs-on: \${{ matrix.os }}
237
+
238
+ strategy:
239
+ matrix:
240
+ os: [ubuntu-latest, macos-latest, windows-latest]
241
+
242
+ steps:
243
+ - name: Check out Git repository
244
+ uses: actions/checkout@v3
245
+
246
+ - name: Install Node.js
247
+ uses: actions/setup-node@v3
248
+ with:
249
+ node-version: 16
250
+
251
+ - name: Install Dependencies
252
+ run: npm install
253
+
254
+ - name: build-linux
255
+ if: matrix.os == 'ubuntu-latest'
256
+ run: npm run build:linux
257
+
258
+ - name: build-mac
259
+ if: matrix.os == 'macos-latest'
260
+ run: npm run build:mac
261
+
262
+ - name: build-win
263
+ if: matrix.os == 'windows-latest'
264
+ run: npm run build:win
265
+
266
+ - name: release
267
+ uses: softprops/action-gh-release@v1
268
+ with:
269
+ draft: true
270
+ files: |
271
+ release/*.exe
272
+ release/*.zip
273
+ release/*.dmg
274
+ release/*.AppImage
275
+ release/*.snap
276
+ release/*.deb
277
+ release/*.rpm
278
+ release/*.tar.gz
279
+ release/*.yml
280
+ release/*.blockmap
281
+ env:
282
+ GITHUB_TOKEN: \${{ secrets.GH_TOKEN }}
283
+ `.trim();
284
+ fs.writeFileSync(projectBuildYmlPath, buildYmlContent, 'utf8');
285
+ console.log('📝 Created default build.yml in project config directory');
286
+
287
+
288
+ console.log('✅ The project initialization is complete. Please modify .milkio-electron/config.json and then run it again.');
289
+
290
+ exit(0);
291
+ } else {
292
+ const items = fs.readdirSync(projectConfigDir);
293
+ for (const item of items) {
294
+ if (item === 'config.json') continue;
295
+
296
+ const source = path.join(projectConfigDir, item);
297
+ const dest = path.join(targetDir, item);
298
+
299
+ if (fs.statSync(source).isDirectory()) {
300
+ fse.copySync(source, dest, { recursive: true });
301
+ } else {
302
+ fse.copySync(source, dest);
303
+ }
304
+
305
+ console.log(`📝 Copied configuration: ${item}`);
306
+ }
307
+ }
308
+ } catch (error) {
309
+ await handleError(new Error(`Error copying files: ${error.message}`));
310
+ }
311
+ })();
312
+
313
+ const publisherConfigJson = JSON.parse(fs.readFileSync(path.join(cwd, '.milkio-electron', 'config.json'), 'utf8'));
314
+ const distTarget = path.join(targetDir, 'dist');
315
+ fse.ensureDirSync(distTarget);
316
+ fse.copySync(path.join(cwd, publisherConfigJson.bundlerOutDir ?? "dist"), distTarget);
317
+ console.log(`📂 Copied dist files to: ${distTarget}`);
318
+
319
+ await (async () => {
320
+ try {
321
+ const packageJsonPath = path.join(targetDir, 'package.json');
322
+ const erunPath = path.join(distTarget, '__ERUN__.mjs');
323
+ const gitignorePath = path.join(targetDir, '.gitignore');
324
+
325
+ baseDir = path.join(targetDir, '.github', 'workflows');
326
+ fse.ensureDirSync(baseDir);
327
+
328
+ if (fs.existsSync(packageJsonPath) || fs.existsSync(erunPath)) {
329
+ throw new Error('The dist directory should not contain package.json or __ERUN__.mjs files. Please remove them from your dist directory.');
330
+ }
331
+
332
+ const packageJsonContent = {
333
+ "type": "module",
334
+ "main": "dist/__ERUN__.mjs",
335
+ };
336
+ fs.writeFileSync(packageJsonPath, JSON.stringify(deepmerge(publisherConfigJson.packageJson || {}, packageJsonContent)), 'utf8');
337
+
338
+ const erunContent = `
339
+ import electron from 'electron';
340
+ globalThis.electron = electron;
341
+ await import('${publisherConfigJson.entry}');
342
+ `.trim();
343
+ fs.writeFileSync(erunPath, erunContent, 'utf8');
344
+
345
+ if (!fs.existsSync(gitignorePath)) {
346
+ fs.writeFileSync(gitignorePath, 'node_modules\nout\ndist\n');
347
+ }
348
+
349
+ console.log('✅ Created package.json and dist/__ERUN__.mjs');
350
+ } catch (error) {
351
+ await handleError(error);
352
+ }
353
+ })();
354
+
355
+ await (async () => {
356
+ try {
357
+ oldDirs = fs.readdirSync(hashDir)
358
+ .map(dir => path.join(hashDir, dir))
359
+ .filter(dir => {
360
+ const isDir = fs.lstatSync(dir).isDirectory();
361
+ return isDir && path.basename(dir) !== startTime.toString();
362
+ });
363
+
364
+ if (oldDirs.length >= 1) {
365
+ const sortedDirs = oldDirs
366
+ .map(dir => ({ path: dir, time: parseInt(path.basename(dir)) }))
367
+ .sort((a, b) => b.time - a.time);
368
+
369
+ if (sortedDirs.length > 0) {
370
+ mostRecentDir = sortedDirs[0].path;
371
+
372
+ ['node_modules', 'package-lock.json'].forEach(item => {
373
+ const source = path.join(mostRecentDir, item);
374
+ const dest = path.join(targetDir, item);
375
+
376
+ if (fs.existsSync(source)) {
377
+ try {
378
+ fse.moveSync(source, dest, { overwrite: true });
379
+ console.log(`♻️ Moved ${item} from previous version`);
380
+ } catch (error) {
381
+ console.warn(`⚠️ Could not move ${item}: ${error.message}`);
382
+ }
383
+ }
384
+ });
385
+ }
386
+ }
387
+ } catch (error) {
388
+ await handleError(error);
389
+ }
390
+ })();
391
+
392
+ await (async () => {
393
+ try {
394
+ console.log('⏳ Running npm install...');
395
+ execFileSync('npm', ['install'], { cwd: targetDir, stdio: 'inherit' });
396
+ console.log('✅ npm install completed successfully');
397
+ } catch (error) {
398
+ await handleError(new Error(`npm install failed: ${error.message}`));
399
+ }
400
+
401
+ const totalTime = ((Date.now() - startTime) / 1000).toFixed(2);
402
+ console.log(`✨ All tasks completed in ${totalTime} seconds`);
403
+
404
+ execFileSync('npm', ['run', ...argv.slice(2)], { cwd: targetDir, stdio: 'inherit' });
405
+ })();
406
+
407
+ await (async () => {
408
+ if (oldDirs.length > 0) {
409
+ try {
410
+ oldDirs.forEach(dir => {
411
+ try {
412
+ fse.removeSync(dir);
413
+ console.log(`🗑️ Deleted old directory: ${dir}`);
414
+ } catch (error) {
415
+ console.warn(`⚠️ Could not delete old directory ${dir}:`, error.message);
416
+ }
417
+ });
418
+ } catch (error) {
419
+ console.warn('⚠️ Error during old version cleanup:', error.message);
420
+ }
421
+ }
422
+ })();
423
+
424
424
  currentDirCleanupNeeded = false;
package/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "milkio-electron",
3
- "version": "1.0.0-beta.201",
3
+ "version": "1.0.0-beta.204",
4
4
  "type": "module",
5
5
  "description": "Automated Electron project publisher",
6
6
  "main": "index.mjs",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/akirarika/milkio"
10
+ },
7
11
  "bin": {
8
12
  "milkio-electron": "index.mjs"
9
13
  },
package/tsconfig.json CHANGED
@@ -1,29 +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
- }
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
+ }