@geastack/cli 0.1.79 → 0.1.80

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/docs/SETUP.md CHANGED
@@ -14,7 +14,7 @@ npx gea doctor
14
14
  ## Minimum Setup
15
15
 
16
16
  ```sh
17
- npx @geastack/create-geastack my-app
17
+ npx create-geastack my-app
18
18
  cd my-app
19
19
  npx gea setup
20
20
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/cli",
3
- "version": "0.1.79",
3
+ "version": "0.1.80",
4
4
  "description": "Command-line front door for GeaStack apps, targets, and local toolchains.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -43,7 +43,8 @@
43
43
  },
44
44
  "starterDependencies": {
45
45
  "@geastack/core": "^0.1.23",
46
- "@geastack/targets": "^0.1.77"
46
+ "@geastack/targets": "^0.1.77",
47
+ "@geastack/apple": "^0.2.9"
47
48
  },
48
49
  "scripts": {
49
50
  "check": "node --check bin/gea.mjs && node --check bin/create-geastack.mjs && find src test packages -name '*.mjs' -print0 | xargs -0 -n1 node --check",
@@ -348,7 +348,8 @@ function packageJson({ appId, displayName, targets, entry, coreDependency, cliDe
348
348
  '@geastack/core': coreDependency,
349
349
  '@geastack/cli': cliDependency,
350
350
  ...(needsTargetsPackage(targets) ? { '@geastack/targets': sourcePackage.dependencies?.['@geastack/targets'] || targetsDependencyDefault } : {}),
351
- ...(targets.windows ? { '@geastack/windows': sourcePackage.dependencies?.['@geastack/windows'] || windowsDependencyDefault } : {})
351
+ ...(targets.windows ? { '@geastack/windows': sourcePackage.dependencies?.['@geastack/windows'] || windowsDependencyDefault } : {}),
352
+ ...(targets.macos || targets.ios ? { '@geastack/apple': sourcePackage.dependencies?.['@geastack/apple'] || appleDependencyDefault } : {})
352
353
  },
353
354
  devDependencies: {
354
355
  ...(sourcePackage.devDependencies || {}),
@@ -370,6 +371,11 @@ function needsTargetsPackage(targets) {
370
371
  // own dependencies by `gea build --target windows`.
371
372
  const windowsDependencyDefault = '^0.1.0'
372
373
 
374
+ // The macOS and iOS targets ship inside @geastack/apple, resolved the same way
375
+ // by `gea build --target macos` and `gea build --target ios`. An app that
376
+ // declares either target without the package has nothing to build with.
377
+ const appleDependencyDefault = starterDependencies['@geastack/apple'] || '^0.2.9'
378
+
373
379
  function indexTsx(displayName) {
374
380
  return `import { ReactiveComponent, mount } from '@geastack/core'
375
381
  import './styles.css'
@@ -509,7 +515,11 @@ npx gea flash --monitor`
509
515
  ? `npx gea setup
510
516
  npx gea build --target windows
511
517
  npx gea run --target windows`
512
- : `npx gea setup
518
+ : targets.ios && !targets.macos
519
+ ? `npx gea setup
520
+ npx gea build --target ios
521
+ npx gea run --target ios`
522
+ : `npx gea setup
513
523
  npx gea build`
514
524
  return `# ${displayName}
515
525
 
package/src/gea.mjs CHANGED
@@ -95,11 +95,24 @@ export async function runGea(argv, io = {}) {
95
95
  // this host is not (a Windows-only app on a Mac, a Mac-only app on Linux)
96
96
  // has nothing to select: falling into board selection would report a
97
97
  // missing --board for an app that declares no board at all.
98
- if (command === 'build' && !target && app && !declaresBoardTarget(app) && (app.targets?.macos || app.targets?.windows)) {
99
- const desktop = ['macos', 'windows'].filter((platform) => app.targets?.[platform])
98
+ if (command === 'build' && !target && app && !declaresBoardTarget(app) && (app.targets?.macos || app.targets?.windows || app.targets?.ios)) {
99
+ const desktop = ['macos', 'windows', 'ios'].filter((platform) => app.targets?.[platform])
100
100
  fail(`'${app.id}' declares no target that builds on this host by default. Pass --target ${desktop.join(' or --target ')}.`, ExitCode.usage)
101
101
  }
102
102
  }
103
+ // iOS is the third platform driven by one script inside @geastack/apple,
104
+ // resolved like macOS from the app's own dependencies. It never has a host
105
+ // default: a bare `gea build` cannot know simulator from device, so the iOS
106
+ // build is always the documented `gea build --target ios [--mode simulator|device]`,
107
+ // and `gea run --target ios` builds, installs and launches it.
108
+ if ((command === 'build' || command === 'run') && target === 'ios') {
109
+ const app = parsed.options.app || rest[0] ? findAppById(ctx, String(parsed.options.app || rest[0])) : findCurrentApp(cwd)
110
+ if (!app?.targets?.ios) {
111
+ fail(app ? `'${app.id}' does not declare gea.targets.ios.` : 'No app selected. Pass --app <id> or run inside a Gea app folder.', ExitCode.usage)
112
+ }
113
+ const { runIos } = await import('./ios/adapter.mjs')
114
+ return runIos({ app, env, dryRun: flag(parsed, 'dry-run'), stdout, mode: option(parsed, 'mode', ''), run: command === 'run' })
115
+ }
103
116
  // `web` names two targets, and both are driven by gea, so it leaves the
104
117
  // refusal below the way macos does above. `gea simulate` is the WASM device
105
118
  // simulator; `gea {dev,build} --target web` is a real DOM/CSS web app. A bare
@@ -217,6 +230,12 @@ ${heading('Run on this machine (no board needed):')}
217
230
  gea dev [app] [--port N] real DOM + CSS dev server with HMR (same as --target web)
218
231
  gea build --target web [app] [--out-dir d] build the app as a real web app
219
232
 
233
+ ${heading('Native desktop and mobile apps (scripts ship in @geastack/apple and @geastack/windows):')}
234
+ gea build --target macos [app] build a Mac .app (a bare gea build does this on a Mac for a Mac-only app)
235
+ gea build --target ios [app] [--mode simulator|device] generate the Xcode project and build the iOS .app
236
+ gea run --target ios [app] [--mode simulator|device] build, then install and launch on a simulator or iPhone
237
+ gea build|run --target windows [app] build (and launch) the Windows executable
238
+
220
239
  ${heading('Build and deploy (device commands take --board <alias>, see gea boards list; with one registered board it can be left out):')}
221
240
  gea build --board <alias> [--app <id>] build firmware (ESP-IDF / Pico SDK / geaos) [--verbose] [--output file.bin]
222
241
  gea flash --board <alias> [--app <id>] build + flash over USB [--monitor] [--manual-boot] [--no-reset] [--flash-baud N]
@@ -0,0 +1,30 @@
1
+ import { spawnSync } from 'node:child_process'
2
+
3
+ import { CliError, ExitCode, fail } from '../errors.mjs'
4
+ import { appleChildEnv, appleTargetScript } from '../macos/adapter.mjs'
5
+ import { formatCommand } from '../run.mjs'
6
+
7
+ // iOS mirrors macOS: a platform, not a board, driven by one script shipped
8
+ // inside @geastack/apple and resolved from the app's own dependencies. The
9
+ // script takes a destination -- `simulator` (the default) or `device` -- which
10
+ // `--mode` selects. `gea build --target ios` compiles the .app and stops;
11
+ // `gea run --target ios` also installs and launches it on the picked simulator
12
+ // or attached iPhone, which is the script's own default behaviour. The script
13
+ // reads GEA_IOS_SKIP_LAUNCH, so a caller who already set it keeps their choice.
14
+ export function runIos({ app, env, dryRun = false, stdout, mode = '', run = false }) {
15
+ const destination = mode || 'simulator'
16
+ if (destination !== 'simulator' && destination !== 'device') {
17
+ fail(`--mode ${mode} is not an iOS destination; expected simulator or device.`, ExitCode.usage)
18
+ }
19
+ const { script, require } = appleTargetScript(app, 'ios', 'build-ios.sh')
20
+ const childEnv = appleChildEnv(app, env, require)
21
+ if (!run && childEnv.GEA_IOS_SKIP_LAUNCH === undefined) childEnv.GEA_IOS_SKIP_LAUNCH = '1'
22
+ if (dryRun) {
23
+ stdout(formatCommand(['bash', script, app.id, destination]))
24
+ return 0
25
+ }
26
+ const result = spawnSync('bash', [script, app.id, destination], { cwd: app.root, env: childEnv, stdio: 'inherit' })
27
+ if (result.error) throw result.error
28
+ if (result.status !== 0) throw new CliError(`iOS build failed (${result.status ?? 1}).`, ExitCode.deployFailed)
29
+ return 0
30
+ }
@@ -13,31 +13,48 @@ import { formatCommand } from '../run.mjs'
13
13
  // app's own module resolution is what finds it. An app declares `targets.macos`
14
14
  // and nothing else; the script reads the rest from the same manifest.
15
15
  export function runMacos({ app, env, dryRun = false, stdout }) {
16
+ const { script, require } = appleTargetScript(app, 'macos', 'build-macos.sh')
17
+ const childEnv = appleChildEnv(app, env, require)
18
+ if (dryRun) {
19
+ stdout(formatCommand(['bash', script, app.id]))
20
+ return 0
21
+ }
22
+ const result = spawnSync('bash', [script, app.id], { cwd: app.root, env: childEnv, stdio: 'inherit' })
23
+ if (result.error) throw result.error
24
+ if (result.status !== 0) throw new CliError(`macOS build failed (${result.status ?? 1}).`, ExitCode.deployFailed)
25
+ return 0
26
+ }
27
+
28
+ // Both Apple targets ship as one script each inside @geastack/apple, and both
29
+ // resolve it the same way: through the app's own dependencies. iOS reuses this
30
+ // from src/ios/adapter.mjs rather than restating the resolution.
31
+ export function appleTargetScript(app, platform, scriptName) {
16
32
  const require = createRequire(path.join(app.root, 'package.json'))
17
33
  let appleRoot = ''
18
34
  try {
19
35
  appleRoot = path.dirname(require.resolve('@geastack/apple/package.json'))
20
36
  } catch {
21
- fail(`'${app.id}' targets macOS but @geastack/apple is not installed in ${app.root} — run npm install there.`, ExitCode.missingDependency)
37
+ fail(`'${app.id}' targets ${platformLabel(platform)} but @geastack/apple is not installed in ${app.root} — run npm install there.`, ExitCode.missingDependency)
22
38
  }
23
- const script = path.join(appleRoot, 'targets', 'macos', 'build-macos.sh')
24
- if (!existsSync(script)) fail(`macOS build script not found: ${script}`, ExitCode.missingDependency)
25
- // The script resolves the app through this CLI again. It is spawned with the
26
- // app's own folder as its cwd and that is the whole handoff: `createContext`
27
- // resolves a project from cwd, and a root's own package.json is one of the
28
- // places discovery looks, so an app outside the examples workspace resolves
29
- // like any other. Nothing announces the path a second time.
39
+ const script = path.join(appleRoot, 'targets', platform, scriptName)
40
+ if (!existsSync(script)) fail(`${platformLabel(platform)} build script not found: ${script}`, ExitCode.missingDependency)
41
+ return { script, require }
42
+ }
43
+
44
+ // The script resolves the app through this CLI again. It is spawned with the
45
+ // app's own folder as its cwd and that is the whole handoff: `createContext`
46
+ // resolves a project from cwd, and a root's own package.json is one of the
47
+ // places discovery looks, so an app outside the examples workspace resolves
48
+ // like any other. Nothing announces the path a second time.
49
+ export function appleChildEnv(app, env, require) {
30
50
  const childEnv = { ...env }
31
51
  const plugins = geatscPluginsOf(app, require)
32
52
  if (plugins.length > 0) childEnv.GEA_EXTRA_GEATSC_PLUGINS = plugins.join(path.delimiter)
33
- if (dryRun) {
34
- stdout(formatCommand(['bash', script, app.id]))
35
- return 0
36
- }
37
- const result = spawnSync('bash', [script, app.id], { cwd: app.root, env: childEnv, stdio: 'inherit' })
38
- if (result.error) throw result.error
39
- if (result.status !== 0) throw new CliError(`macOS build failed (${result.status ?? 1}).`, ExitCode.deployFailed)
40
- return 0
53
+ return childEnv
54
+ }
55
+
56
+ function platformLabel(platform) {
57
+ return platform === 'ios' ? 'iOS' : 'macOS'
41
58
  }
42
59
 
43
60
  // Compiler plugins come from the packages the app depends on.
@@ -152,7 +152,7 @@ export function buildSimulatorApp({ app, env, dryRun = false, stdout }) {
152
152
 
153
153
  export async function runSimulate({ ctx, app, env, dryRun = false, stdout, port, open = true, view = {} }) {
154
154
  const { simulatorDir, paths } = buildSimulatorApp({ app, env, dryRun, stdout })
155
- const url = await startSimulatorServer({ ctx, app, env, simulatorDir, paths, port, dryRun, stdout })
155
+ const url = await startSimulatorServer({ ctx, app, env, simulatorDir, paths, port, dryRun, stdout, view })
156
156
  if (dryRun) return 0
157
157
  stdout(`Simulating ${app.id}: ${url}`)
158
158
  if (open) openBrowser(url, env)
@@ -166,7 +166,7 @@ export async function runSimulate({ ctx, app, env, dryRun = false, stdout, port,
166
166
  // the relocated dist root be passed as inline config that vite merges over the
167
167
  // package's own vite.config.ts, instead of being smuggled through env vars the
168
168
  // config would have to read back.
169
- async function startSimulatorServer({ ctx, app, env, simulatorDir, paths, port, dryRun, stdout }) {
169
+ async function startSimulatorServer({ ctx, app, env, simulatorDir, paths, port, dryRun, stdout, view = {} }) {
170
170
  const appRoot = path.join(simulatorDir, 'simulator')
171
171
  const configFile = path.join(appRoot, 'vite.config.ts')
172
172
  if (dryRun) {
@@ -182,7 +182,11 @@ async function startSimulatorServer({ ctx, app, env, simulatorDir, paths, port,
182
182
  // Vite's default cacheDir is <root>/node_modules/.vite -- inside the
183
183
  // installed package, which may be read-only and is not this app's to dirty.
184
184
  cacheDir: paths.viteCache,
185
- define: { __GEA_APP_INDEX__: JSON.stringify(appIndexFor(ctx, app)) },
185
+ publicDir: path.dirname(paths.public),
186
+ define: {
187
+ __GEA_APP_INDEX__: JSON.stringify(appIndexFor(ctx, app)),
188
+ __GEA_WEB_DIST_FS_ROOT__: JSON.stringify(paths.dist)
189
+ },
186
190
  server: {
187
191
  port,
188
192
  fs: { allow: [appRoot, paths.dist, paths.public] }