Skip to content

Commit

Permalink
Fixed dev process on Windows and better stability overall
Browse files Browse the repository at this point in the history
  • Loading branch information
OrigamingWasTaken committed Feb 26, 2024
1 parent 2a12e35 commit e491734
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 27 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Build App

on:
push:
branches:
- main # Change this to your main branch name

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install Dependencies
run: npm ci # Adjust this based on your project's dependencies

- name: Build app for all platforms
run: npm run build

- name: Zip artifacts
run: |
cd dist
for dir in */; do
zip -r "${dir%/}.zip" "$dir"
done
- name: List artifacts
run: ls dist | grep .zip

- name: Upload (linux_arm64)
uses: actions/upload-artifact@v4
with:
name: AutoEvent_linux_arm64
path: dist/linux_arm64.zip
- name: Upload (linux_armhf)
uses: actions/upload-artifact@v4
with:
name: AutoEvent_linux_armhf
path: dist/linux_armhf.zip
- name: Upload (linux_x64)
uses: actions/upload-artifact@v4
with:
name: AutoEvent_linux_x64
path: dist/linux_x64.zip
- name: Upload (mac_universal)
uses: actions/upload-artifact@v4
with:
name: AutoEvent_mac_universal
path: dist/mac_universal.zip
- name: Upload (win_x64)
uses: actions/upload-artifact@v4
with:
name: AutoEvent_win_x64
path: dist/win_x64.zip
4 changes: 2 additions & 2 deletions neutralino.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
"binaryVersion": "4.14.1",
"clientVersion": "3.12.0",
"frontendLibrary": {
"buildCommand": "npm run neu:checkup",
"buildCommand": "npm run neu:empty",
"patchFile": "/frontend/index.html",
"devUrl": "http://localhost:5173",
"devCommand": "npm run vite:dev",
"devCommand": "npm run neu:empty",
"projectPath": "/",
"initCommand": "npm install"
}
Expand Down
80 changes: 79 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dev": "vite-node scripts/package/dev.ts",
"build": "vite-node scripts/build/ts/index.ts",
"check": "svelte-check --tsconfig ./tsconfig.json",
"neu:checkup": ""
"neu:empty": ""
},
"keywords": [
"svelte",
Expand All @@ -20,10 +20,12 @@
"author": "OrigamingWasTaken",
"license": "MIT",
"devDependencies": {
"@expo/spawn-async": "^1.7.2",
"@neutralinojs/neu": "^10.1.0",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"@tsconfig/svelte": "^5.0.2",
"@types/signale": "^1.4.7",
"@types/tar": "^6.1.11",
"await-exec-typescript": "github:artemhp/await-exec-typescript",
"jszip": "^3.10.1",
"resedit": "^2.0.0",
Expand All @@ -35,8 +37,7 @@
"typescript": "^5.3.3",
"vite": "^5.1.3",
"vite-node": "^1.3.1",
"vite-plugin-html": "^3.2.2",
"@types/tar": "^6.1.11"
"vite-plugin-html": "^3.2.2"
},
"dependencies": {
"@neutralinojs/lib": "^5.0.0"
Expand Down
10 changes: 10 additions & 0 deletions scripts/build/ts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import fs from 'fs';
import {winBuild} from './win-bundle';
import {Signale} from 'signale';
import {linuxBuild} from './linux-bundle';
import { exec } from "child_process"

export async function build() {
const initTime = performance.now();
Expand Down Expand Up @@ -34,6 +35,15 @@ export async function build() {
copyFolderSync(path.resolve('.tmpbuild'), path.resolve('./dist'));
fs.rmSync(path.resolve('.tmpbuild'), {recursive: true, force: true});
logger.success(`Built in ${((performance.now() - initTime) / 1000).toFixed(3)}s`);
switch (process.platform) {
case "linux":
case "darwin":
exec(`open ${path.resolve("./dist")}`);
break;
case "win32":
exec(`start ${path.resolve("./dist")}`);
break;
}
}

build();
43 changes: 32 additions & 11 deletions scripts/package/dev.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import {spawn} from 'child_process';
import spawn, { type SpawnPromise, type SpawnResult} from '@expo/spawn-async';
import path from 'path';
import {existsSync, chmodSync} from 'fs';
import { existsSync, chmodSync, rmSync } from 'fs';

function main() {
async function main() {
// Clear terminal
process.stdout.write('\x1b[2J')
process.stdout.write('\x1b[0f');

// Get the correct binary name
let binaryOS = 'linux';
switch (process.platform) {
case 'darwin':
Expand All @@ -11,37 +16,53 @@ function main() {
case 'win32':
binaryOS = 'win';
break;
default:
break;
}
const vite = spawn('vite', {
// Start the vite dev server
const vite = spawn('vite', ["dev"], {
cwd: process.cwd(),
detached: false,
stdio: 'inherit',
});
// Delay to be sure vite was built
console.log("Waiting 2500ms...")
await new Promise(r => setTimeout(r, 2500));

const args = [
'--window-enable-inspector=true',
'--export-auth-info',
'--load-dir-res',
`--path=${path.resolve('.')}`,
'--neu-dev-extension',
'--url=http://localhost:5173',
"--port=5174"
];
chmodSync(`./bin/neutralino-${binaryOS}_${process.arch}`,"755")
const neu = spawn(`./bin/neutralino-${binaryOS}_${process.arch}`, args, {
// Chmod +x the binary to be able to run it
let bpath: string;
if (process.platform !== "win32") {
bpath = path.resolve(`./bin/neutralino-${binaryOS}_${process.arch}`)
chmodSync(bpath,"755");
} else {
bpath = path.resolve(`./bin/neutralino-${binaryOS}_winx64.exe`)
}

await spawn(bpath, args, {
cwd: process.cwd(),
detached: false,
stdio: 'inherit',
}).on('close', () => {
vite.kill();
}).child.on('close', () => {
vite.child.kill();
process.exit();
});
}

// If the binary folder doesn't exist, then we download it
if (!existsSync(path.resolve('./bin'))) {
const neuInstall = spawn('npx', ['neu', 'update'], {
spawn('npx', ['neu', 'update'], {
cwd: process.cwd(),
detached: false,
stdio: 'inherit',
}).on('exit', main);
}).child.on('exit', main);
} else {
main();
}
12 changes: 2 additions & 10 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@ import {defineConfig} from 'vite';
import {svelte} from '@sveltejs/vite-plugin-svelte';
import * as path from 'path';
import {createHtmlPlugin} from 'vite-plugin-html';
import {readFileSync, existsSync} from 'node:fs';

function getUrl() {
try {
const {port} = JSON.parse(readFileSync('./.tmp/auth_info.json', 'utf-8'));
return `http://localhost:${port}`;
} catch {
return '%PUBLIC_URL%';
}
}
const NEU_PORRT = 5174

// https://vitejs.dev/config/
export default defineConfig({
Expand All @@ -22,7 +14,7 @@ export default defineConfig({
template: 'index.html',
inject: {
data: {
url: getUrl(),
url: `http://localhost:5174`
},
},
}),
Expand Down

0 comments on commit e491734

Please sign in to comment.