@puredesktop/create-app 1.0.0-beta.1 → 1.0.0-beta.2
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/bin/create-puredesktop-app.mjs +164 -159
- package/package.json +1 -1
- package/template/README.md +299 -16
- package/template/agents.md +11 -0
- package/template/gitignore.tpl +5 -5
- package/template/index.html +12 -12
- package/template/package.json +22 -21
- package/template/plugin.json +3 -2
- package/template/scripts/validate-puredesktop-app.mjs +277 -0
- package/template/src/App.tsx +49 -49
- package/template/src/bridge/platformBridge.ts +31 -31
- package/template/src/components/AppShell.tsx +31 -31
- package/template/src/constants.ts +1 -1
- package/template/src/hooks/useAppBoot.ts +45 -45
- package/template/src/main.tsx +9 -9
- package/template/src/types.ts +5 -5
- package/template/tsconfig.json +15 -15
- package/template/vite-env.d.ts +1 -1
- package/template/vite.config.js +28 -28
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react'
|
|
2
|
-
import { fetchAppSettings } from '../bridge/platformBridge'
|
|
3
|
-
import type { AppBootState } from '../types'
|
|
4
|
-
|
|
5
|
-
interface UseAppBootResult {
|
|
6
|
-
boot: AppBootState | null
|
|
7
|
-
bootError: Error | null
|
|
8
|
-
booting: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function useAppBoot(ready: boolean): UseAppBootResult {
|
|
12
|
-
const [boot, setBoot] = useState<AppBootState | null>(null)
|
|
13
|
-
const [bootError, setBootError] = useState<Error | null>(null)
|
|
14
|
-
const [booting, setBooting] = useState(false)
|
|
15
|
-
|
|
16
|
-
useEffect(() => {
|
|
17
|
-
if (!ready) return
|
|
18
|
-
|
|
19
|
-
let cancelled = false
|
|
20
|
-
|
|
21
|
-
async function load() {
|
|
22
|
-
setBooting(true)
|
|
23
|
-
setBootError(null)
|
|
24
|
-
try {
|
|
25
|
-
const settings = await fetchAppSettings()
|
|
26
|
-
if (cancelled) return
|
|
27
|
-
setBoot({ settings })
|
|
28
|
-
} catch (error) {
|
|
29
|
-
if (cancelled) return
|
|
30
|
-
setBoot(null)
|
|
31
|
-
setBootError(error instanceof Error ? error : new Error(String(error)))
|
|
32
|
-
} finally {
|
|
33
|
-
if (!cancelled) setBooting(false)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
void load()
|
|
38
|
-
|
|
39
|
-
return () => {
|
|
40
|
-
cancelled = true
|
|
41
|
-
}
|
|
42
|
-
}, [ready])
|
|
43
|
-
|
|
44
|
-
return { boot, bootError, booting }
|
|
45
|
-
}
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
import { fetchAppSettings } from '../bridge/platformBridge'
|
|
3
|
+
import type { AppBootState } from '../types'
|
|
4
|
+
|
|
5
|
+
interface UseAppBootResult {
|
|
6
|
+
boot: AppBootState | null
|
|
7
|
+
bootError: Error | null
|
|
8
|
+
booting: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function useAppBoot(ready: boolean): UseAppBootResult {
|
|
12
|
+
const [boot, setBoot] = useState<AppBootState | null>(null)
|
|
13
|
+
const [bootError, setBootError] = useState<Error | null>(null)
|
|
14
|
+
const [booting, setBooting] = useState(false)
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!ready) return
|
|
18
|
+
|
|
19
|
+
let cancelled = false
|
|
20
|
+
|
|
21
|
+
async function load() {
|
|
22
|
+
setBooting(true)
|
|
23
|
+
setBootError(null)
|
|
24
|
+
try {
|
|
25
|
+
const settings = await fetchAppSettings()
|
|
26
|
+
if (cancelled) return
|
|
27
|
+
setBoot({ settings })
|
|
28
|
+
} catch (error) {
|
|
29
|
+
if (cancelled) return
|
|
30
|
+
setBoot(null)
|
|
31
|
+
setBootError(error instanceof Error ? error : new Error(String(error)))
|
|
32
|
+
} finally {
|
|
33
|
+
if (!cancelled) setBooting(false)
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
void load()
|
|
38
|
+
|
|
39
|
+
return () => {
|
|
40
|
+
cancelled = true
|
|
41
|
+
}
|
|
42
|
+
}, [ready])
|
|
43
|
+
|
|
44
|
+
return { boot, bootError, booting }
|
|
45
|
+
}
|
package/template/src/main.tsx
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { createRoot } from 'react-dom/client'
|
|
2
|
-
import { App } from './App'
|
|
3
|
-
|
|
4
|
-
const root = document.getElementById('root')
|
|
5
|
-
if (!root) {
|
|
6
|
-
throw new Error('Root element #root not found')
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
createRoot(root).render(<App />)
|
|
1
|
+
import { createRoot } from 'react-dom/client'
|
|
2
|
+
import { App } from './App'
|
|
3
|
+
|
|
4
|
+
const root = document.getElementById('root')
|
|
5
|
+
if (!root) {
|
|
6
|
+
throw new Error('Root element #root not found')
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
createRoot(root).render(<App />)
|
package/template/src/types.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type AppSettings = Record<string, unknown>
|
|
2
|
-
|
|
3
|
-
export interface AppBootState {
|
|
4
|
-
settings: AppSettings
|
|
5
|
-
}
|
|
1
|
+
export type AppSettings = Record<string, unknown>
|
|
2
|
+
|
|
3
|
+
export interface AppBootState {
|
|
4
|
+
settings: AppSettings
|
|
5
|
+
}
|
package/template/tsconfig.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2022",
|
|
4
|
-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"moduleResolution": "Bundler",
|
|
7
|
-
"jsx": "react-jsx",
|
|
8
|
-
"strict": true,
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
"noEmit": true,
|
|
11
|
-
"allowImportingTsExtensions": true,
|
|
12
|
-
"isolatedModules": true
|
|
13
|
-
},
|
|
14
|
-
"include": ["src/**/*.ts", "src/**/*.tsx", "vite-env.d.ts"]
|
|
15
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "Bundler",
|
|
7
|
+
"jsx": "react-jsx",
|
|
8
|
+
"strict": true,
|
|
9
|
+
"skipLibCheck": true,
|
|
10
|
+
"noEmit": true,
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"isolatedModules": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src/**/*.ts", "src/**/*.tsx", "vite-env.d.ts"]
|
|
15
|
+
}
|
package/template/vite-env.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
/// <reference types="vite/client" />
|
|
1
|
+
/// <reference types="vite/client" />
|
package/template/vite.config.js
CHANGED
|
@@ -1,28 +1,28 @@
|
|
|
1
|
-
import react from '@vitejs/plugin-react-swc'
|
|
2
|
-
import { readFileSync } from 'node:fs'
|
|
3
|
-
import { dirname, join } from 'node:path'
|
|
4
|
-
import { fileURLToPath } from 'node:url'
|
|
5
|
-
import { defineConfig } from 'vite'
|
|
6
|
-
|
|
7
|
-
/** Keep Vite port in sync with plugin.json entrypoint.url. */
|
|
8
|
-
function devServerFromManifest(metaUrl) {
|
|
9
|
-
const appDir = dirname(fileURLToPath(metaUrl))
|
|
10
|
-
const manifest = JSON.parse(readFileSync(join(appDir, 'plugin.json'), 'utf8'))
|
|
11
|
-
const url = new URL(manifest.entrypoint.url)
|
|
12
|
-
return {
|
|
13
|
-
host: url.hostname,
|
|
14
|
-
port: Number(url.port),
|
|
15
|
-
strictPort: true,
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export default defineConfig({
|
|
20
|
-
plugins: [
|
|
21
|
-
react({
|
|
22
|
-
plugins: [
|
|
23
|
-
['@swc/plugin-styled-components', { displayName: true, fileName: true }],
|
|
24
|
-
],
|
|
25
|
-
}),
|
|
26
|
-
],
|
|
27
|
-
server: devServerFromManifest(import.meta.url),
|
|
28
|
-
})
|
|
1
|
+
import react from '@vitejs/plugin-react-swc'
|
|
2
|
+
import { readFileSync } from 'node:fs'
|
|
3
|
+
import { dirname, join } from 'node:path'
|
|
4
|
+
import { fileURLToPath } from 'node:url'
|
|
5
|
+
import { defineConfig } from 'vite'
|
|
6
|
+
|
|
7
|
+
/** Keep Vite port in sync with plugin.json entrypoint.url. */
|
|
8
|
+
function devServerFromManifest(metaUrl) {
|
|
9
|
+
const appDir = dirname(fileURLToPath(metaUrl))
|
|
10
|
+
const manifest = JSON.parse(readFileSync(join(appDir, 'plugin.json'), 'utf8'))
|
|
11
|
+
const url = new URL(manifest.entrypoint.url)
|
|
12
|
+
return {
|
|
13
|
+
host: url.hostname,
|
|
14
|
+
port: Number(url.port),
|
|
15
|
+
strictPort: true,
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default defineConfig({
|
|
20
|
+
plugins: [
|
|
21
|
+
react({
|
|
22
|
+
plugins: [
|
|
23
|
+
['@swc/plugin-styled-components', { displayName: true, fileName: true }],
|
|
24
|
+
],
|
|
25
|
+
}),
|
|
26
|
+
],
|
|
27
|
+
server: devServerFromManifest(import.meta.url),
|
|
28
|
+
})
|