@hanzogui/static 7.0.0 → 7.3.0
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/LICENSE +40 -19
- package/dist/check-dep-versions.cjs +1 -1
- package/dist/checkDeps.cjs +11 -11
- package/dist/constants.cjs +2 -2
- package/dist/exports.cjs +2 -2
- package/dist/extractor/bundle.cjs +6 -6
- package/dist/extractor/bundleConfig.cjs +45 -45
- package/dist/extractor/createExtractor.cjs +39 -39
- package/dist/extractor/createLogger.cjs +1 -1
- package/dist/extractor/extractHelpers.cjs +1 -1
- package/dist/extractor/extractMediaStyle.cjs +7 -7
- package/dist/extractor/extractToClassNames.cjs +9 -9
- package/dist/extractor/extractToNative.cjs +7 -7
- package/dist/extractor/{getHanzoguiConfigPathFromOptionsConfig.cjs → getGuiConfigPathFromOptionsConfig.cjs} +5 -5
- package/dist/extractor/getPrefixLogs.cjs +1 -1
- package/dist/extractor/getStaticBindingsForScope.cjs +2 -2
- package/dist/extractor/{loadHanzogui.cjs → loadGui.cjs} +65 -65
- package/dist/extractor/regenerateConfig.cjs +20 -20
- package/dist/extractor/{watchHanzoguiConfig.cjs → watchGuiConfig.cjs} +15 -15
- package/dist/getPragmaOptions.cjs +6 -6
- package/dist/helpers/{requireHanzoguiCore.cjs → requireGuiCore.cjs} +12 -12
- package/dist/registerRequire.cjs +20 -20
- package/dist/worker.cjs +3 -3
- package/package.json +25 -24
- package/src/check-dep-versions.ts +1 -1
- package/src/checkDeps.ts +27 -27
- package/src/constants.ts +2 -2
- package/src/exports.ts +2 -2
- package/src/extractor/bundle.ts +9 -9
- package/src/extractor/bundleConfig.ts +56 -56
- package/src/extractor/createEvaluator.ts +2 -2
- package/src/extractor/createExtractor.ts +55 -55
- package/src/extractor/createLogger.ts +3 -3
- package/src/extractor/extractHelpers.ts +12 -12
- package/src/extractor/extractMediaStyle.ts +13 -13
- package/src/extractor/extractToClassNames.ts +11 -11
- package/src/extractor/extractToNative.ts +13 -13
- package/src/extractor/{getHanzoguiConfigPathFromOptionsConfig.ts → getGuiConfigPathFromOptionsConfig.ts} +3 -3
- package/src/extractor/getPrefixLogs.ts +3 -3
- package/src/extractor/getStaticBindingsForScope.ts +2 -2
- package/src/extractor/{loadHanzogui.ts → loadGui.ts} +85 -85
- package/src/extractor/regenerateConfig.ts +23 -23
- package/src/extractor/{watchHanzoguiConfig.ts → watchGuiConfig.ts} +10 -10
- package/src/getPragmaOptions.ts +6 -6
- package/src/helpers/requireGuiCore.ts +28 -0
- package/src/registerRequire.ts +27 -27
- package/src/server.ts +2 -2
- package/src/types.ts +10 -10
- package/src/worker.ts +7 -7
- package/types/constants.d.ts.map +1 -1
- package/types/exports.d.ts +2 -2
- package/types/exports.d.ts.map +1 -1
- package/types/extractor/bundle.d.ts +2 -2
- package/types/extractor/bundle.d.ts.map +1 -1
- package/types/extractor/bundleConfig.d.ts +12 -12
- package/types/extractor/bundleConfig.d.ts.map +1 -1
- package/types/extractor/createEvaluator.d.ts +2 -2
- package/types/extractor/createEvaluator.d.ts.map +1 -1
- package/types/extractor/createExtractor.d.ts +5 -5
- package/types/extractor/createExtractor.d.ts.map +1 -1
- package/types/extractor/createLogger.d.ts +2 -2
- package/types/extractor/createLogger.d.ts.map +1 -1
- package/types/extractor/extractHelpers.d.ts +8 -8
- package/types/extractor/extractHelpers.d.ts.map +1 -1
- package/types/extractor/extractMediaStyle.d.ts +4 -4
- package/types/extractor/extractMediaStyle.d.ts.map +1 -1
- package/types/extractor/extractToClassNames.d.ts +2 -2
- package/types/extractor/extractToClassNames.d.ts.map +1 -1
- package/types/extractor/extractToNative.d.ts +3 -3
- package/types/extractor/extractToNative.d.ts.map +1 -1
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts +3 -0
- package/types/extractor/getGuiConfigPathFromOptionsConfig.d.ts.map +1 -0
- package/types/extractor/getPrefixLogs.d.ts +2 -2
- package/types/extractor/getPrefixLogs.d.ts.map +1 -1
- package/types/extractor/loadGui.d.ts +22 -0
- package/types/extractor/loadGui.d.ts.map +1 -0
- package/types/extractor/regenerateConfig.d.ts +4 -4
- package/types/extractor/regenerateConfig.d.ts.map +1 -1
- package/types/extractor/watchGuiConfig.d.ts +5 -0
- package/types/extractor/watchGuiConfig.d.ts.map +1 -0
- package/types/helpers/requireGuiCore.d.ts +3 -0
- package/types/helpers/requireGuiCore.d.ts.map +1 -0
- package/types/registerRequire.d.ts +3 -3
- package/types/registerRequire.d.ts.map +1 -1
- package/types/server.d.ts +2 -2
- package/types/server.d.ts.map +1 -1
- package/types/types.d.ts +10 -10
- package/types/types.d.ts.map +1 -1
- package/types/worker.d.ts +4 -4
- package/types/worker.d.ts.map +1 -1
- package/src/helpers/requireHanzoguiCore.ts +0 -28
- package/types/extractor/getHanzoguiConfigPathFromOptionsConfig.d.ts +0 -3
- package/types/extractor/getHanzoguiConfigPathFromOptionsConfig.d.ts.map +0 -1
- package/types/extractor/loadHanzogui.d.ts +0 -22
- package/types/extractor/loadHanzogui.d.ts.map +0 -1
- package/types/extractor/watchHanzoguiConfig.d.ts +0 -5
- package/types/extractor/watchHanzoguiConfig.d.ts.map +0 -1
- package/types/helpers/requireHanzoguiCore.d.ts +0 -3
- package/types/helpers/requireHanzoguiCore.d.ts.map +0 -1
|
@@ -6,12 +6,12 @@ import template from '@babel/template'
|
|
|
6
6
|
import * as t from '@babel/types'
|
|
7
7
|
import { basename } from 'node:path'
|
|
8
8
|
import { getPragmaOptions } from '../getPragmaOptions'
|
|
9
|
-
import type {
|
|
9
|
+
import type { GuiOptions } from '../types'
|
|
10
10
|
import { createExtractor } from './createExtractor'
|
|
11
11
|
import { createLogger } from './createLogger'
|
|
12
12
|
import { isSimpleSpread } from './extractHelpers'
|
|
13
13
|
import { literalToAst } from './literalToAst'
|
|
14
|
-
import {
|
|
14
|
+
import { loadGuiBuildConfigSync } from './loadGui'
|
|
15
15
|
|
|
16
16
|
const importNativeView = template(`
|
|
17
17
|
const __ReactNativeView = require('react-native').View;
|
|
@@ -26,12 +26,12 @@ const importWithStyle = template.ast(`import { _withStableStyle } from '@hanzogu
|
|
|
26
26
|
|
|
27
27
|
const extractor = createExtractor({ platform: 'native' })
|
|
28
28
|
|
|
29
|
-
let
|
|
29
|
+
let guiBuildOptionsLoaded: GuiOptions | null
|
|
30
30
|
|
|
31
31
|
export function extractToNative(
|
|
32
32
|
sourceFileName: string,
|
|
33
33
|
sourceCode: string,
|
|
34
|
-
options:
|
|
34
|
+
options: GuiOptions
|
|
35
35
|
): BabelFileResult {
|
|
36
36
|
const ast = parse(sourceCode, {
|
|
37
37
|
sourceType: 'module',
|
|
@@ -55,15 +55,15 @@ export function extractToNative(
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
export function getBabelPlugin() {
|
|
58
|
-
return declare((api, options:
|
|
58
|
+
return declare((api, options: GuiOptions) => {
|
|
59
59
|
api.assertVersion(7)
|
|
60
60
|
return getBabelParseDefinition(options)
|
|
61
61
|
})
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
export function getBabelParseDefinition(options:
|
|
64
|
+
export function getBabelParseDefinition(options: GuiOptions) {
|
|
65
65
|
return {
|
|
66
|
-
name: '
|
|
66
|
+
name: 'gui',
|
|
67
67
|
|
|
68
68
|
visitor: {
|
|
69
69
|
Program: {
|
|
@@ -106,16 +106,16 @@ export function getBabelParseDefinition(options: HanzoguiOptions) {
|
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
if (!options.config && !options.components) {
|
|
109
|
-
// if no config/components given try and load from the
|
|
110
|
-
|
|
109
|
+
// if no config/components given try and load from the gui.build.ts file
|
|
110
|
+
guiBuildOptionsLoaded ||= loadGuiBuildConfigSync({})
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
const finalOptions = {
|
|
114
114
|
// @ts-ignore just in case they leave it out
|
|
115
115
|
platform: 'native',
|
|
116
|
-
...
|
|
116
|
+
...guiBuildOptionsLoaded,
|
|
117
117
|
...options,
|
|
118
|
-
} satisfies
|
|
118
|
+
} satisfies GuiOptions
|
|
119
119
|
|
|
120
120
|
const printLog = createLogger(sourcePath, finalOptions)
|
|
121
121
|
|
|
@@ -419,7 +419,7 @@ export function getBabelParseDefinition(options: HanzoguiOptions) {
|
|
|
419
419
|
if (message.includes('Unexpected return value from visitor method')) {
|
|
420
420
|
message = 'Unexpected return value from visitor method'
|
|
421
421
|
}
|
|
422
|
-
console.warn('Error in
|
|
422
|
+
console.warn('Error in Gui parse, skipping', message, err.stack)
|
|
423
423
|
return
|
|
424
424
|
}
|
|
425
425
|
}
|
|
@@ -466,7 +466,7 @@ function assertValidTag(node: t.JSXOpeningElement) {
|
|
|
466
466
|
if (node.attributes.find((x) => x.type === 'JSXAttribute' && x.name.name === 'style')) {
|
|
467
467
|
// we can just deopt here instead and log warning
|
|
468
468
|
// need to make onExtractTag have a special catch error or similar
|
|
469
|
-
if (process.env.DEBUG?.startsWith('
|
|
469
|
+
if (process.env.DEBUG?.startsWith('gui')) {
|
|
470
470
|
console.warn('⚠️ Cannot pass style attribute to extracted style')
|
|
471
471
|
}
|
|
472
472
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { isAbsolute, join } from 'node:path'
|
|
2
2
|
|
|
3
3
|
import { statSync } from 'node:fs'
|
|
4
|
-
import type {
|
|
4
|
+
import type { GuiOptions } from '../types'
|
|
5
5
|
|
|
6
|
-
export function
|
|
7
|
-
config: NonNullable<
|
|
6
|
+
export function getGuiConfigPathFromOptionsConfig(
|
|
7
|
+
config: NonNullable<GuiOptions['config']>
|
|
8
8
|
) {
|
|
9
9
|
if (isAbsolute(config)) {
|
|
10
10
|
return config
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Color, colorString } from '@hanzogui/cli-color'
|
|
2
|
-
import type {
|
|
2
|
+
import type { GuiOptions } from '../types'
|
|
3
3
|
|
|
4
|
-
export function getPrefixLogs(options?:
|
|
4
|
+
export function getPrefixLogs(options?: GuiOptions) {
|
|
5
5
|
return (
|
|
6
6
|
options?.prefixLogs ??
|
|
7
|
-
` 🐥 [
|
|
7
|
+
` 🐥 [gui] ${colorString(Color.FgYellow, options?.platform || 'web')}`
|
|
8
8
|
)
|
|
9
9
|
}
|
|
@@ -137,9 +137,9 @@ export async function getStaticBindingsForScope(
|
|
|
137
137
|
} catch (err: any) {
|
|
138
138
|
if (shouldPrintDebug) {
|
|
139
139
|
console.warn(
|
|
140
|
-
` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=
|
|
140
|
+
` | Skipping partial evaluation of constant file: ${moduleName} (DEBUG=gui for more)`
|
|
141
141
|
)
|
|
142
|
-
} else if (process.env.DEBUG?.startsWith('
|
|
142
|
+
} else if (process.env.DEBUG?.startsWith('gui')) {
|
|
143
143
|
console.info(`Error in partial evaluation`, err.message, err.stack)
|
|
144
144
|
}
|
|
145
145
|
}
|
|
@@ -1,43 +1,43 @@
|
|
|
1
1
|
import { basename, dirname, extname, join, relative, resolve } from 'node:path'
|
|
2
2
|
// @ts-ignore why
|
|
3
3
|
import { Color, colorLog } from '@hanzogui/cli-color'
|
|
4
|
-
import type { CLIResolvedOptions, CLIUserOptions,
|
|
5
|
-
import type {
|
|
4
|
+
import type { CLIResolvedOptions, CLIUserOptions, GuiOptions } from '@hanzogui/types'
|
|
5
|
+
import type { GuiInternalConfig } from '@hanzogui/web'
|
|
6
6
|
import esbuild from 'esbuild'
|
|
7
7
|
import * as esbuildWasm from 'esbuild-wasm'
|
|
8
8
|
import * as fsExtra from 'fs-extra'
|
|
9
9
|
|
|
10
10
|
import { SHOULD_DEBUG } from '../constants'
|
|
11
|
-
import {
|
|
11
|
+
import { requireGuiCore } from '../helpers/requireGuiCore'
|
|
12
12
|
import { getNameToPaths, registerRequire } from '../registerRequire'
|
|
13
13
|
import {
|
|
14
|
-
type
|
|
14
|
+
type GuiProjectInfo,
|
|
15
15
|
getBundledConfig,
|
|
16
16
|
getLoadedConfig,
|
|
17
17
|
hasBundledConfigChanged,
|
|
18
18
|
loadComponentsSync,
|
|
19
|
-
|
|
19
|
+
writeGuiCSS,
|
|
20
20
|
} from './bundleConfig'
|
|
21
|
-
import {
|
|
21
|
+
import { getGuiConfigPathFromOptionsConfig } from './getGuiConfigPathFromOptionsConfig'
|
|
22
22
|
import {
|
|
23
|
-
|
|
23
|
+
generateGuiThemes,
|
|
24
24
|
regenerateConfig,
|
|
25
25
|
regenerateConfigSync,
|
|
26
26
|
} from './regenerateConfig'
|
|
27
27
|
|
|
28
|
-
const getFilledOptions = (propsIn: Partial<
|
|
28
|
+
const getFilledOptions = (propsIn: Partial<GuiOptions>): GuiOptions => ({
|
|
29
29
|
// defaults
|
|
30
|
-
platform: (process.env.
|
|
31
|
-
config: '
|
|
32
|
-
components: ['
|
|
33
|
-
...(propsIn as Partial<
|
|
30
|
+
platform: (process.env.GUI_TARGET as any) || 'web',
|
|
31
|
+
config: 'gui.config.ts',
|
|
32
|
+
components: ['gui'],
|
|
33
|
+
...(propsIn as Partial<GuiOptions>),
|
|
34
34
|
})
|
|
35
35
|
|
|
36
36
|
let isLoadingPromise: null | Promise<any>
|
|
37
37
|
|
|
38
|
-
export async function
|
|
39
|
-
propsIn: Partial<
|
|
40
|
-
): Promise<
|
|
38
|
+
export async function loadGui(
|
|
39
|
+
propsIn: Partial<GuiOptions>
|
|
40
|
+
): Promise<GuiProjectInfo | null> {
|
|
41
41
|
if (isLoadingPromise) return await isLoadingPromise
|
|
42
42
|
|
|
43
43
|
let resolvePromise
|
|
@@ -53,7 +53,7 @@ export async function loadHanzogui(
|
|
|
53
53
|
const bundleInfo = await getBundledConfig(props)
|
|
54
54
|
if (!bundleInfo) {
|
|
55
55
|
console.warn(
|
|
56
|
-
`No bundled config generated, maybe an error in bundling. Set DEBUG=
|
|
56
|
+
`No bundled config generated, maybe an error in bundling. Set DEBUG=gui and re-run to get logs.`
|
|
57
57
|
)
|
|
58
58
|
resolvePromise(null)
|
|
59
59
|
return null
|
|
@@ -62,11 +62,11 @@ export async function loadHanzogui(
|
|
|
62
62
|
// this affects the bundled config so run it first
|
|
63
63
|
await generateThemesAndLog(props)
|
|
64
64
|
|
|
65
|
-
// if they accidently pass in a config without
|
|
66
|
-
const
|
|
67
|
-
if (
|
|
68
|
-
const {
|
|
69
|
-
bundleInfo.
|
|
65
|
+
// if they accidently pass in a config without createGui called,call it
|
|
66
|
+
const maybeGuiConfig = bundleInfo.guiConfig as GuiInternalConfig
|
|
67
|
+
if (maybeGuiConfig && !maybeGuiConfig.parsed) {
|
|
68
|
+
const { createGui } = requireGuiCore(props.platform || 'web')
|
|
69
|
+
bundleInfo.guiConfig = createGui(bundleInfo.guiConfig as any)
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
if (!hasBundledConfigChanged()) {
|
|
@@ -89,20 +89,20 @@ export async function loadHanzogui(
|
|
|
89
89
|
// debounce a bit
|
|
90
90
|
let waiting = false
|
|
91
91
|
|
|
92
|
-
export const generateThemesAndLog = async (options:
|
|
92
|
+
export const generateThemesAndLog = async (options: GuiOptions, force = false) => {
|
|
93
93
|
if (waiting) return
|
|
94
94
|
if (!options.themeBuilder) return
|
|
95
95
|
try {
|
|
96
96
|
waiting = true
|
|
97
97
|
await new Promise((res) => setTimeout(res, 30))
|
|
98
|
-
const didGenerate = await
|
|
98
|
+
const didGenerate = await generateGuiThemes(options, force)
|
|
99
99
|
|
|
100
100
|
// only logs when changed
|
|
101
101
|
if (didGenerate) {
|
|
102
102
|
const whitespaceBefore = ` `
|
|
103
103
|
colorLog(
|
|
104
104
|
Color.FgYellow,
|
|
105
|
-
`${whitespaceBefore}➡ [
|
|
105
|
+
`${whitespaceBefore}➡ [gui] generated themes: ${relative(
|
|
106
106
|
process.cwd(),
|
|
107
107
|
options.themeBuilder.output
|
|
108
108
|
)}`
|
|
@@ -111,7 +111,7 @@ export const generateThemesAndLog = async (options: HanzoguiOptions, force = fal
|
|
|
111
111
|
if (options.outputCSS) {
|
|
112
112
|
const loadedConfig = getLoadedConfig()
|
|
113
113
|
if (loadedConfig) {
|
|
114
|
-
await
|
|
114
|
+
await writeGuiCSS(options.outputCSS, loadedConfig)
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -120,20 +120,20 @@ export const generateThemesAndLog = async (options: HanzoguiOptions, force = fal
|
|
|
120
120
|
}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
const last: Record<string,
|
|
123
|
+
const last: Record<string, GuiProjectInfo | null> = {}
|
|
124
124
|
const lastVersion: Record<string, string> = {}
|
|
125
125
|
|
|
126
126
|
// esbuild-wasm state - initialized once per process
|
|
127
127
|
let esbuildWasmInitialized = false
|
|
128
128
|
|
|
129
129
|
/**
|
|
130
|
-
* Load
|
|
130
|
+
* Load gui.build.ts config using esbuild-wasm transform
|
|
131
131
|
* Uses WASM to avoid native esbuild service lifecycle issues (EPIPE errors)
|
|
132
132
|
*/
|
|
133
|
-
export async function
|
|
134
|
-
|
|
135
|
-
): Promise<
|
|
136
|
-
const buildFilePath =
|
|
133
|
+
export async function loadGuiBuildConfigAsync(
|
|
134
|
+
guiOptions: Partial<GuiOptions> | undefined
|
|
135
|
+
): Promise<GuiOptions> {
|
|
136
|
+
const buildFilePath = guiOptions?.buildFile ?? './gui.build.ts'
|
|
137
137
|
const absolutePath =
|
|
138
138
|
buildFilePath[0] === '.' ? join(process.cwd(), buildFilePath) : buildFilePath
|
|
139
139
|
|
|
@@ -166,36 +166,36 @@ export async function loadHanzoguiBuildConfigAsync(
|
|
|
166
166
|
throw new Error(`No default export found in ${buildFilePath}: ${out}`)
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
|
|
170
|
-
...
|
|
169
|
+
guiOptions = {
|
|
170
|
+
...guiOptions,
|
|
171
171
|
...out,
|
|
172
172
|
}
|
|
173
173
|
} catch (err) {
|
|
174
|
-
console.error(`[
|
|
174
|
+
console.error(`[gui] Error loading ${buildFilePath}:`, err)
|
|
175
175
|
throw err
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
|
|
179
|
-
if (!
|
|
179
|
+
if (!guiOptions) {
|
|
180
180
|
throw new Error(
|
|
181
|
-
`No
|
|
181
|
+
`No gui build options found either via input props or at gui.build.ts`
|
|
182
182
|
)
|
|
183
183
|
}
|
|
184
184
|
|
|
185
185
|
return {
|
|
186
|
-
config: '
|
|
187
|
-
components: ['
|
|
188
|
-
...
|
|
189
|
-
} as
|
|
186
|
+
config: 'gui.config.ts',
|
|
187
|
+
components: ['gui', '@hanzogui/core'],
|
|
188
|
+
...guiOptions,
|
|
189
|
+
} as GuiOptions
|
|
190
190
|
}
|
|
191
191
|
|
|
192
192
|
/**
|
|
193
|
-
* @deprecated Use
|
|
193
|
+
* @deprecated Use loadGuiBuildConfigAsync instead to avoid EPIPE errors
|
|
194
194
|
*/
|
|
195
|
-
export function
|
|
196
|
-
|
|
195
|
+
export function loadGuiBuildConfigSync(
|
|
196
|
+
guiOptions: Partial<GuiOptions> | undefined
|
|
197
197
|
) {
|
|
198
|
-
const buildFilePath =
|
|
198
|
+
const buildFilePath = guiOptions?.buildFile ?? './gui.build.ts'
|
|
199
199
|
if (fsExtra.existsSync(buildFilePath)) {
|
|
200
200
|
const registered = registerRequire('web')
|
|
201
201
|
try {
|
|
@@ -206,35 +206,35 @@ export function loadHanzoguiBuildConfigSync(
|
|
|
206
206
|
throw new Error(`No default export found in ${buildFilePath}: ${out}`)
|
|
207
207
|
}
|
|
208
208
|
|
|
209
|
-
|
|
210
|
-
...
|
|
209
|
+
guiOptions = {
|
|
210
|
+
...guiOptions,
|
|
211
211
|
...out,
|
|
212
212
|
}
|
|
213
213
|
} finally {
|
|
214
214
|
registered.unregister()
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
|
-
if (!
|
|
217
|
+
if (!guiOptions) {
|
|
218
218
|
throw new Error(
|
|
219
|
-
`No
|
|
219
|
+
`No gui build options found either via input props or at gui.build.ts`
|
|
220
220
|
)
|
|
221
221
|
}
|
|
222
222
|
return {
|
|
223
|
-
config: '
|
|
224
|
-
components: ['
|
|
225
|
-
...
|
|
226
|
-
} as
|
|
223
|
+
config: 'gui.config.ts',
|
|
224
|
+
components: ['gui', '@hanzogui/core'],
|
|
225
|
+
...guiOptions,
|
|
226
|
+
} as GuiOptions
|
|
227
227
|
}
|
|
228
228
|
|
|
229
229
|
// loads in-process using esbuild-register
|
|
230
|
-
export function
|
|
230
|
+
export function loadGuiSync({
|
|
231
231
|
forceExports,
|
|
232
232
|
cacheKey,
|
|
233
233
|
...propsIn
|
|
234
|
-
}: Partial<
|
|
234
|
+
}: Partial<GuiOptions> & {
|
|
235
235
|
forceExports?: boolean
|
|
236
236
|
cacheKey?: string
|
|
237
|
-
}):
|
|
237
|
+
}): GuiProjectInfo {
|
|
238
238
|
const key = JSON.stringify(propsIn)
|
|
239
239
|
|
|
240
240
|
if (last[key] && !hasBundledConfigChanged()) {
|
|
@@ -250,7 +250,7 @@ export function loadHanzoguiSync({
|
|
|
250
250
|
// lets shim require and avoid importing react-native + react-native-web
|
|
251
251
|
// we just need to read the config around them
|
|
252
252
|
process.env.IS_STATIC = 'is_static'
|
|
253
|
-
process.env.
|
|
253
|
+
process.env.GUI_IS_SERVER = 'true'
|
|
254
254
|
|
|
255
255
|
const { unregister } = registerRequire(props.platform || 'web', {
|
|
256
256
|
proxyWormImports: !!forceExports,
|
|
@@ -262,18 +262,18 @@ export function loadHanzoguiSync({
|
|
|
262
262
|
|
|
263
263
|
try {
|
|
264
264
|
// config
|
|
265
|
-
let
|
|
265
|
+
let guiConfig: GuiInternalConfig | null = null
|
|
266
266
|
if (propsIn.config) {
|
|
267
|
-
const configPath =
|
|
267
|
+
const configPath = getGuiConfigPathFromOptionsConfig(propsIn.config)
|
|
268
268
|
const exp = require(configPath)
|
|
269
269
|
|
|
270
270
|
if (!exp || exp._isProxyWorm) {
|
|
271
271
|
throw new Error(`Got a empty / proxied config!`)
|
|
272
272
|
}
|
|
273
273
|
|
|
274
|
-
|
|
274
|
+
guiConfig = (exp['default'] || exp['config'] || exp) as GuiInternalConfig
|
|
275
275
|
|
|
276
|
-
if (!
|
|
276
|
+
if (!guiConfig || !guiConfig.parsed) {
|
|
277
277
|
const confPath = require.resolve(configPath)
|
|
278
278
|
throw new Error(`Can't find valid config in ${confPath}:
|
|
279
279
|
|
|
@@ -281,9 +281,9 @@ export function loadHanzoguiSync({
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
// set up core
|
|
284
|
-
if (
|
|
285
|
-
const {
|
|
286
|
-
|
|
284
|
+
if (guiConfig) {
|
|
285
|
+
const { createGui } = requireGuiCore(props.platform || 'web')
|
|
286
|
+
createGui(guiConfig as any)
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
|
|
@@ -292,7 +292,7 @@ export function loadHanzoguiSync({
|
|
|
292
292
|
if (!components) {
|
|
293
293
|
throw new Error(`No components loaded`)
|
|
294
294
|
}
|
|
295
|
-
if (process.env.DEBUG === '
|
|
295
|
+
if (process.env.DEBUG === 'gui') {
|
|
296
296
|
console.info(`components`, components)
|
|
297
297
|
}
|
|
298
298
|
|
|
@@ -302,14 +302,14 @@ export function loadHanzoguiSync({
|
|
|
302
302
|
|
|
303
303
|
const info = {
|
|
304
304
|
components,
|
|
305
|
-
|
|
305
|
+
guiConfig,
|
|
306
306
|
nameToPaths: getNameToPaths(),
|
|
307
|
-
} satisfies
|
|
307
|
+
} satisfies GuiProjectInfo
|
|
308
308
|
|
|
309
|
-
if (
|
|
309
|
+
if (guiConfig) {
|
|
310
310
|
const { outputCSS } = props
|
|
311
311
|
if (outputCSS) {
|
|
312
|
-
|
|
312
|
+
writeGuiCSS(outputCSS, guiConfig)
|
|
313
313
|
}
|
|
314
314
|
|
|
315
315
|
regenerateConfigSync(props, info)
|
|
@@ -325,7 +325,7 @@ export function loadHanzoguiSync({
|
|
|
325
325
|
if (err instanceof Error) {
|
|
326
326
|
if (!SHOULD_DEBUG && !forceExports) {
|
|
327
327
|
console.warn(
|
|
328
|
-
`Error loading
|
|
328
|
+
`Error loading gui.config.ts (set DEBUG=gui to see full stack), running gui without custom config`
|
|
329
329
|
)
|
|
330
330
|
console.info(`\n\n ${err.message}\n\n`)
|
|
331
331
|
} else {
|
|
@@ -334,12 +334,12 @@ export function loadHanzoguiSync({
|
|
|
334
334
|
}
|
|
335
335
|
}
|
|
336
336
|
} else {
|
|
337
|
-
console.error(`Error loading
|
|
337
|
+
console.error(`Error loading gui.config.ts`, err)
|
|
338
338
|
}
|
|
339
339
|
|
|
340
340
|
return {
|
|
341
341
|
components: [],
|
|
342
|
-
|
|
342
|
+
guiConfig: null,
|
|
343
343
|
nameToPaths: {},
|
|
344
344
|
}
|
|
345
345
|
}
|
|
@@ -351,11 +351,11 @@ export function loadHanzoguiSync({
|
|
|
351
351
|
export async function getOptions({
|
|
352
352
|
root = process.cwd(),
|
|
353
353
|
tsconfigPath = 'tsconfig.json',
|
|
354
|
-
|
|
354
|
+
guiOptions,
|
|
355
355
|
host,
|
|
356
356
|
debug,
|
|
357
357
|
}: Partial<CLIUserOptions> = {}): Promise<CLIResolvedOptions> {
|
|
358
|
-
const dotDir = join(root, '.
|
|
358
|
+
const dotDir = join(root, '.gui')
|
|
359
359
|
let pkgJson = {}
|
|
360
360
|
|
|
361
361
|
try {
|
|
@@ -371,18 +371,18 @@ export async function getOptions({
|
|
|
371
371
|
pkgJson,
|
|
372
372
|
debug,
|
|
373
373
|
tsconfigPath,
|
|
374
|
-
|
|
375
|
-
platform: (process.env.
|
|
376
|
-
components: ['
|
|
377
|
-
...
|
|
374
|
+
guiOptions: {
|
|
375
|
+
platform: (process.env.GUI_TARGET as any) || 'web',
|
|
376
|
+
components: ['gui'],
|
|
377
|
+
...guiOptions,
|
|
378
378
|
config:
|
|
379
|
-
|
|
380
|
-
(await
|
|
379
|
+
guiOptions?.config ??
|
|
380
|
+
(await getDefaultGuiConfigPath(root, guiOptions?.config)),
|
|
381
381
|
},
|
|
382
382
|
paths: {
|
|
383
383
|
root,
|
|
384
384
|
dotDir,
|
|
385
|
-
conf: join(dotDir, '
|
|
385
|
+
conf: join(dotDir, 'gui.config.json'),
|
|
386
386
|
types: join(dotDir, 'types.json'),
|
|
387
387
|
},
|
|
388
388
|
}
|
|
@@ -393,7 +393,7 @@ export function resolveWebOrNativeSpecificEntry(entry: string) {
|
|
|
393
393
|
const resolved = require.resolve(entry, { paths: [workspaceRoot] })
|
|
394
394
|
const ext = extname(resolved)
|
|
395
395
|
const fileName = basename(resolved).replace(ext, '')
|
|
396
|
-
const specificExt = process.env.
|
|
396
|
+
const specificExt = process.env.GUI_TARGET === 'web' ? 'web' : 'native'
|
|
397
397
|
const specificFile = join(dirname(resolved), fileName + '.' + specificExt + ext)
|
|
398
398
|
if (fsExtra.existsSync(specificFile)) {
|
|
399
399
|
return specificFile
|
|
@@ -401,10 +401,10 @@ export function resolveWebOrNativeSpecificEntry(entry: string) {
|
|
|
401
401
|
return entry
|
|
402
402
|
}
|
|
403
403
|
|
|
404
|
-
const defaultPaths = ['
|
|
404
|
+
const defaultPaths = ['gui.config.ts', join('src', 'gui.config.ts')]
|
|
405
405
|
let hasWarnedOnce = false
|
|
406
406
|
|
|
407
|
-
async function
|
|
407
|
+
async function getDefaultGuiConfigPath(root: string, configPath?: string) {
|
|
408
408
|
const searchPaths = [
|
|
409
409
|
...new Set(
|
|
410
410
|
[configPath, ...defaultPaths].filter(Boolean).map((p) => join(root, p as string))
|
|
@@ -419,13 +419,13 @@ async function getDefaultHanzoguiConfigPath(root: string, configPath?: string) {
|
|
|
419
419
|
|
|
420
420
|
if (!hasWarnedOnce) {
|
|
421
421
|
hasWarnedOnce = true
|
|
422
|
-
console.warn(`Warning: couldn't find
|
|
422
|
+
console.warn(`Warning: couldn't find gui.config.ts in the following paths given configuration "${configPath}":
|
|
423
423
|
${searchPaths.join(`\n `)}
|
|
424
424
|
`)
|
|
425
425
|
}
|
|
426
426
|
}
|
|
427
427
|
|
|
428
|
-
export type {
|
|
428
|
+
export type { GuiProjectInfo }
|
|
429
429
|
|
|
430
430
|
export async function esbuildWatchFiles(entry: string, onChanged: () => void) {
|
|
431
431
|
let hasRunOnce = false
|