Skip to content

armgit / Pake

Public Imported from GitHub
0

Turn any website into a lightweight desktop app with one command, on macOS, Windows and Linux.

Add iterative build mode, stream file downloads, and refactor name utilities and tests

Tw939d60bda10bbc
diff --git a/bin/builders/MacBuilder.ts b/bin/builders/MacBuilder.ts
index 0ef7c926..f097ff12 100644
--- a/bin/builders/MacBuilder.ts
+++ b/bin/builders/MacBuilder.ts
@@ -15,7 +15,7 @@ export default class MacBuilder extends BaseBuilder {
? options.targets
: 'auto';
- if (process.env.PAKE_CREATE_APP === '1') {
+ if (options.iterativeBuild || process.env.PAKE_CREATE_APP === '1') {
this.buildFormat = 'app';
} else {
this.buildFormat = 'dmg';
diff --git a/bin/cli.ts b/bin/cli.ts
index 50cf4aad..69eff1d6 100644
--- a/bin/cli.ts
+++ b/bin/cli.ts
@@ -219,6 +219,14 @@ program
.default(DEFAULT.ignoreCertificateErrors)
.hideHelp(),
)
+ .addOption(
+ new Option(
+ '--iterative-build',
+ 'Turn on rapid build mode (app only, no dmg/deb/msi), good for debugging',
+ )
+ .default(DEFAULT.iterativeBuild)
+ .hideHelp(),
+ )
.version(packageJson.version, '-v, --version')
.configureHelp({
sortSubcommands: true,
diff --git a/bin/defaults.ts b/bin/defaults.ts
index 4a6b3576..0eb784d8 100644
--- a/bin/defaults.ts
+++ b/bin/defaults.ts
@@ -16,7 +16,18 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
userAgent: '',
showSystemTray: false,
multiArch: false,
- targets: 'deb',
+ targets: (() => {
+ switch (process.platform) {
+ case 'linux':
+ return 'deb';
+ case 'darwin':
+ return 'dmg';
+ case 'win32':
+ return 'msi';
+ default:
+ return 'deb';
+ }
+ })(),
useLocalFile: false,
systemTrayIcon: '',
proxyUrl: '',
@@ -31,6 +42,7 @@ export const DEFAULT_PAKE_OPTIONS: PakeCliOptions = {
multiInstance: false,
startToTray: false,
forceInternalNavigation: false,
+ iterativeBuild: false,
zoom: 100,
minWidth: 0,
minHeight: 0,
diff --git a/bin/helpers/merge.ts b/bin/helpers/merge.ts
index 406fd9fd..b11c66c7 100644
--- a/bin/helpers/merge.ts
+++ b/bin/helpers/merge.ts
@@ -3,17 +3,10 @@ import fsExtra from 'fs-extra';
import combineFiles from '@/utils/combine';
import logger from '@/options/logger';
-import { generateSafeFilename, generateIdentifierSafeName } from '@/utils/name';
+import { generateSafeFilename, generateIdentifierSafeName, getSafeAppName } from '@/utils/name';
import { PakeAppOptions, PlatformMap } from '@/types';
import { tauriConfigDirectory, npmDirectory } from '@/utils/dir';
-/**
- * Helper function to generate safe lowercase app name for file paths
- */
-function getSafeAppName(name: string): string {
- return generateSafeFilename(name).toLowerCase();
-}
-
export async function mergeConfig(
url: string,
options: PakeAppOptions,
diff --git a/bin/types.ts b/bin/types.ts
index 50379f02..c90f0b6e 100644
--- a/bin/types.ts
+++ b/bin/types.ts
@@ -111,6 +111,9 @@ export interface PakeCliOptions {
// Ignore certificate errors (for self-signed certs), default false
ignoreCertificateErrors: boolean;
+
+ // Turn on rapid build mode (app only, no dmg/deb/msi), good for debugging
+ iterativeBuild: boolean;
}
export interface PakeAppOptions extends PakeCliOptions {
diff --git a/bin/utils/name.test.ts b/bin/utils/name.test.ts
new file mode 100644
index 00000000..23ffcb11
--- /dev/null
+++ b/bin/utils/name.test.ts
@@ -0,0 +1,87 @@
+
+import { describe, it, expect } from 'vitest';
+import { getSafeAppName } from './name';
+
+describe('getSafeAppName', () => {
+ it('should handle simple names', () => {
+ expect(getSafeAppName('MyApp')).toBe('myapp');
+ });
+
+ it('should handle names with spaces', () => {
+ expect(getSafeAppName('My App')).toBe('my_app');
+ });
+
+ it('should handle names with hyphens', () => {
+ expect(getSafeAppName('my-app')).toBe('my-app');
+ });
+
+ it('should handle Chinese names', () => {
+ expect(getSafeAppName('我的应用')).toBe('我的应用');
+ });
+
+ it('should handle mixed Chinese and English', () => {
+ expect(getSafeAppName('我的 App')).toBe('我的_app');
+ });
+
+ it('should preserve special characters like @', () => {
+ expect(getSafeAppName('App@2024')).toBe('app@2024');
+ });
+
+ it('should replace forward slashes', () => {
+ expect(getSafeAppName('My/App')).toBe('my_app');
+ });
+
+ it('should replace backslashes', () => {
+ expect(getSafeAppName('My\\App')).toBe('my_app');
+ });
+
+ it('should replace colons', () => {
+ expect(getSafeAppName('App:Name')).toBe('app_name');
+ });
+
+ it('should replace asterisks', () => {
+ expect(getSafeAppName('App*Name')).toBe('app_name');
+ });
+
+ it('should replace question marks', () => {
+ expect(getSafeAppName('App?Name')).toBe('app_name');
+ });
+
+ it('should replace double quotes', () => {
+ expect(getSafeAppName('App"Name')).toBe('app_name');
+ });
+
+ it('should replace angle brackets', () => {
+ expect(getSafeAppName('App<Name>')).toBe('app_name_');
+ });
+
+ it('should replace pipes', () => {
+ expect(getSafeAppName('App|Name')).toBe('app_name');
+ });
+
+ it('should handle all uppercase names', () => {
+ expect(getSafeAppName('APP')).toBe('app');
+ });
+
+ it('should handle single character names', () => {
+ expect(getSafeAppName('a')).toBe('a');
+ });
+
+ it('should handle numeric names', () => {
+ expect(getSafeAppName('123')).toBe('123');
+ });
+
+ it('should handle leading/trailing spaces', () => {
+ expect(getSafeAppName(' App ')).toBe('_app_');
+ });
+
+ it('should handle trailing dots', () => {
+ expect(getSafeAppName('App...')).toBe('app');
+ });
+
+ it('should truncate very long names', () => {
+ const longName = 'A'.repeat(300);
+ const expected = 'a'.repeat(255);
+ expect(getSafeAppName(longName)).toBe(expected);
+ });
+});
diff --git a/bin/utils/name.ts b/bin/utils/name.ts
index 519a87d8..dc315bf4 100644
--- a/bin/utils/name.ts
+++ b/bin/utils/name.ts
@@ -6,6 +6,10 @@ export function generateSafeFilename(name: string): string {
.slice(0, 255);
}
+export function getSafeAppName(name: string): string {
+ return generateSafeFilename(name).toLowerCase();
+}
+
export function generateLinuxPackageName(name: string): string {
return name
.toLowerCase()