@geastack/cli 0.1.102 → 0.1.104

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/src/run.mjs CHANGED
@@ -68,6 +68,9 @@ export async function runStep(command, args, options = {}) {
68
68
  label = command,
69
69
  logFile = null,
70
70
  appendLog = false,
71
+ // A nonzero exit the caller knows to be harmless, judged from the log:
72
+ // returns the note to show instead of the failure, or '' when it failed.
73
+ accept = null,
71
74
  stdout = console.log,
72
75
  stderr = console.error
73
76
  } = options
@@ -100,6 +103,11 @@ export async function runStep(command, args, options = {}) {
100
103
  progress.stop(`${label} ${pc.dim(`(log: ${logFile})`)}`)
101
104
  return { status, quiet: true }
102
105
  }
106
+ const accepted = accept ? accept(status) : ''
107
+ if (accepted) {
108
+ progress.stop(`${label} ${pc.dim(`(${accepted}; log: ${logFile})`)}`)
109
+ return { status, quiet: true, accepted: true }
110
+ }
103
111
 
104
112
  progress.stop(pc.red(`${label} failed`), 1)
105
113
  stderr(failureExcerpt(logFile))
@@ -98,19 +98,19 @@ function detectWindowsSerialDevices(env) {
98
98
  // Windows PowerShell writes in the console's OEM code page, so a port
99
99
  // label like "Serielles USB-Gerät" arrives mangled when read as UTF-8.
100
100
  // Setting the output encoding first makes the pipe match the decoding.
101
+ // A composite device (an ESP32's native USB CDC) puts the port on an
102
+ // interface (`...&MI_00\<synthesised>`); the serial is on its parent.
101
103
  '[Console]::OutputEncoding=[System.Text.Encoding]::UTF8;' +
102
- 'Get-CimInstance Win32_SerialPort | Select-Object DeviceID,Name,PNPDeviceID | ConvertTo-Json -Compress'
104
+ 'Get-CimInstance Win32_SerialPort | ForEach-Object { $parent = ""; ' +
105
+ 'try { $parent = (Get-PnpDeviceProperty -InstanceId $_.PNPDeviceID -KeyName DEVPKEY_Device_Parent -ErrorAction Stop).Data } catch {}; ' +
106
+ '[pscustomobject]@{ DeviceID = $_.DeviceID; Name = $_.Name; PNPDeviceID = $_.PNPDeviceID; Parent = $parent } } | ConvertTo-Json -Compress'
103
107
  ],
104
108
  { encoding: 'utf8', env, stdio: ['ignore', 'pipe', 'pipe'] }
105
109
  ).trim()
106
110
  if (!output) return []
107
111
  const parsed = JSON.parse(output)
108
112
  return (Array.isArray(parsed) ? parsed : [parsed])
109
- .map((entry) => normalizeDevice({
110
- path: entry.DeviceID || '',
111
- label: entry.Name || '',
112
- serial: serialFromDeviceName(entry.PNPDeviceID || '')
113
- }))
113
+ .map(windowsSerialPortDevice)
114
114
  .filter((device) => device.path)
115
115
  .sort((a, b) => a.path.localeCompare(b.path))
116
116
  } catch {
@@ -118,6 +118,18 @@ function detectWindowsSerialDevices(env) {
118
118
  }
119
119
  }
120
120
 
121
+ // One Win32_SerialPort row (plus its PnP parent) as a device. A port on an
122
+ // interface of a composite device (`&MI_xx`) carries a synthesised instance
123
+ // ID; the serial is the parent device's.
124
+ export function windowsSerialPortDevice(entry) {
125
+ const id = entry.PNPDeviceID || ''
126
+ return normalizeDevice({
127
+ path: entry.DeviceID || '',
128
+ label: entry.Name || '',
129
+ serial: serialFromDeviceName(id) || (/&MI_[0-9A-F]{2}\\/i.test(id) ? serialFromDeviceName(entry.Parent || '') : '')
130
+ })
131
+ }
132
+
121
133
  function normalizeDevice(input) {
122
134
  if (typeof input === 'string') return normalizeDevice({ path: input })
123
135
  const devicePath = String(input.path || '').trim()
@@ -10,7 +10,7 @@ import { configureChipSelection, loadChipCatalog, validateGpioAssignments } from
10
10
  import { flag, option } from './args.mjs'
11
11
  import { ExitCode, fail } from './errors.mjs'
12
12
  import { espIdfVersion as readInstalledEspIdfVersion, findEspIdf, findIdfPythonEnv } from './esp32/idf-env.mjs'
13
- import { extractIdfVersionFromText, fetchLatestEspIdfVersion, idfVersionMeetsTarget, resolveEspIdfVersion } from './esp32/idf-version.mjs'
13
+ import { espIdfVersionForTarget, extractIdfVersionFromText, fetchLatestEspIdfVersion, idfVersionMeetsTarget, resolveEspIdfVersion } from './esp32/idf-version.mjs'
14
14
  import { exists, readJson, writeJson } from './fs-utils.mjs'
15
15
  import { BACK, ask, choose, confirm, createPrompt, ui } from './prompts.mjs'
16
16
  import { runExternal, runQuiet } from './run.mjs'
@@ -19,6 +19,11 @@ import { commandVersion } from './toolchain.mjs'
19
19
 
20
20
  const espIdfInstallTargets = 'esp32,esp32s3,esp32p4'
21
21
 
22
+ // The ESP32-S31 (Mosaico) exists only on ESP-IDF master, a 6.2-dev line the
23
+ // build looks for next to the stable install (espIdfVersionForTarget):
24
+ // ~/esp32/esp-idf-v6.2-dev, its tools installed for esp32s31.
25
+ const s31EspIdf = { version: '6.2-dev', ref: 'master', dir: path.join('esp32', 'esp-idf-v6.2-dev'), targets: 'esp32s31' }
26
+
22
27
  export async function runSetupWizard(ctx, parsed, io) {
23
28
  const stdout = io.stdout || console.log
24
29
  const prompt = createPrompt(io)
@@ -30,7 +35,7 @@ export async function runSetupWizard(ctx, parsed, io) {
30
35
  ])
31
36
  if (option(parsed, 'esp-idf') === true) {
32
37
  renderStep(io, 'Toolchain', ['Checking ESP-IDF for ESP32 builds.'])
33
- await maybeSetupEspIdf(ctx, parsed, io, prompt, { force: true, targetVersion: targetIdfVersion })
38
+ await setupAllEspIdf(ctx, parsed, io, prompt, targetIdfVersion)
34
39
  return 0
35
40
  }
36
41
  const mode = await choose(prompt, {
@@ -68,7 +73,7 @@ export async function runSetupWizard(ctx, parsed, io) {
68
73
 
69
74
  if (mode === 'esp-idf') {
70
75
  renderStep(io, 'Toolchain', ['Checking ESP-IDF for ESP32 builds.'])
71
- await maybeSetupEspIdf(ctx, parsed, io, prompt, { force: true, targetVersion: targetIdfVersion })
76
+ await setupAllEspIdf(ctx, parsed, io, prompt, targetIdfVersion)
72
77
  return 0
73
78
  }
74
79
 
@@ -82,7 +87,11 @@ export async function runSetupWizard(ctx, parsed, io) {
82
87
  }
83
88
 
84
89
  renderStep(io, 'Toolchain', ['Checking ESP-IDF before board initialization.'])
85
- await maybeSetupEspIdf(ctx, parsed, io, prompt, { targetVersion: targetIdfVersion })
90
+ if (boardSetup?.target && espIdfVersionForTarget(boardSetup.target) === s31EspIdf.version) {
91
+ await maybeSetupS31EspIdf(ctx, parsed, io, prompt)
92
+ } else {
93
+ await maybeSetupEspIdf(ctx, parsed, io, prompt, { targetVersion: targetIdfVersion })
94
+ }
86
95
  if (option(parsed, 'install') === true) {
87
96
  await maybeInstallNpmDependencies(ctx, parsed, io, prompt, { force: true })
88
97
  }
@@ -150,7 +159,7 @@ async function setupKnownBoard(ctx, parsed, io, prompt) {
150
159
  writeJsonEnsured(configPath, config)
151
160
  ui(io).success(`Wrote board alias '${alias}' to ${configPath}`)
152
161
  ui(io).message(`Target: ${board.target}`)
153
- return { alias, flashReady: true }
162
+ return { alias, target: board.target, flashReady: true }
154
163
  }
155
164
 
156
165
  async function setupCustomBoard(ctx, parsed, io, prompt) {
@@ -253,7 +262,10 @@ async function setupCustomBoard(ctx, parsed, io, prompt) {
253
262
 
254
263
  const configPath = boardConfigPath(ctx, parsed)
255
264
  const definitionPath = path.join(path.dirname(configPath), 'targets', `${alias}.json`)
256
- const relativeDefinition = path.relative(path.dirname(configPath), definitionPath)
265
+ // boards.json is shared between machines (a project's .gea/boards.json is
266
+ // committed), so the reference is written with forward slashes: every host
267
+ // reads those, while a backslash is part of a file name on macOS and Linux.
268
+ const relativeDefinition = path.relative(path.dirname(configPath), definitionPath).split(path.sep).join('/')
257
269
  const entry = compactObject({
258
270
  target: alias,
259
271
  targetDefinition: relativeDefinition,
@@ -447,7 +459,7 @@ async function resolveEspIdfVersionForWizard(parsed, io) {
447
459
  async function maybeSetupEspIdf(ctx, parsed, io, prompt, { force = false, targetVersion } = {}) {
448
460
  const env = io.env || process.env
449
461
  const resolvedVersion = targetVersion || await resolveEspIdfVersionForWizard(parsed, io)
450
- const status = detectEspIdf(env, resolvedVersion)
462
+ const status = detectEspIdf(env, resolvedVersion, option(parsed, 'idf-dir'))
451
463
  if (status.available) {
452
464
  if (force) ui(io).success(`ESP-IDF found: ${status.detail}`)
453
465
  return 0
@@ -463,10 +475,72 @@ async function maybeSetupEspIdf(ctx, parsed, io, prompt, { force = false, target
463
475
  }
464
476
 
465
477
  const idfDir = option(parsed, 'idf-dir') || env.GEA_ESP_IDF_DIR || path.join(os.homedir(), 'esp', 'esp-idf')
478
+ // An explicit master/6.2+ checkout is the S31's line, so it gets its tools too.
479
+ const targets = idfVersionMeetsTarget(extractIdfVersionFromText(resolvedVersion), 'v6.2.0') || resolvedVersion === s31EspIdf.ref
480
+ ? `${espIdfInstallTargets},${s31EspIdf.targets}`
481
+ : espIdfInstallTargets
482
+ installEspIdf(ctx, parsed, io, { idfDir, ref: resolvedVersion, targets })
483
+ return 0
484
+ }
485
+
486
+ // `gea setup --esp-idf`: the stable release every other board builds with,
487
+ // and, unless one install was asked for by version or directory, the S31's
488
+ // 6.2-dev line too. Either is left alone when it is already installed.
489
+ async function setupAllEspIdf(ctx, parsed, io, prompt, targetVersion) {
490
+ await maybeSetupEspIdf(ctx, parsed, io, prompt, { force: true, targetVersion })
491
+ if (option(parsed, 'idf-version') || option(parsed, 'idf-dir')) return 0
492
+ return maybeSetupS31EspIdf(ctx, parsed, io, prompt, { force: true })
493
+ }
494
+
495
+ async function maybeSetupS31EspIdf(ctx, parsed, io, prompt, { force = false } = {}) {
496
+ const env = io.env || process.env
497
+ const home = env.HOME || env.USERPROFILE || os.homedir()
498
+ const status = detectS31EspIdf(env, home)
499
+ if (status.available) {
500
+ if (force) ui(io).success(`ESP-IDF ${s31EspIdf.version} for the ESP32-S31 found: ${status.detail}`)
501
+ return 0
502
+ }
503
+ const install = force || await confirm(prompt, {
504
+ message: `The ESP32-S31 builds with ESP-IDF ${s31EspIdf.version} (master), which was not found${status.detail ? ` (found ${status.detail})` : ''}. Install it now?`,
505
+ defaultValue: false
506
+ })
507
+ if (!install) {
508
+ ui(io).warn('ESP-IDF install later: npx gea setup --esp-idf')
509
+ return 0
510
+ }
511
+ installEspIdf(ctx, parsed, io, { idfDir: status.dir || path.join(home, s31EspIdf.dir), ref: s31EspIdf.ref, targets: s31EspIdf.targets })
512
+ return 0
513
+ }
514
+
515
+ // The 6.2-dev checkout the build would pick for the S31. IDF_PATH and the
516
+ // export hints count only when they point at that line: the stable install
517
+ // they usually name is not one.
518
+ function detectS31EspIdf(env, home) {
519
+ const dir = findEspIdf({ ...env, IDF_PATH: '', GEA_EMBEDDED_IDF_EXPORT: '', ESP_IDF_EXPORT: '' }, home, { defaultVersion: s31EspIdf.version }) ||
520
+ (isS31EspIdfDir(env.IDF_PATH) ? path.resolve(env.IDF_PATH) : '')
521
+ if (!dir) {
522
+ const conventional = path.join(home, s31EspIdf.dir)
523
+ // A clone that was never installed is resumed in place, not cloned again.
524
+ return { available: false, detail: '', dir: exists(path.join(conventional, 'tools', 'idf.py')) ? conventional : '' }
525
+ }
526
+ const toolsInstalled = Boolean(findIdfPythonEnv(dir, env, home))
527
+ return {
528
+ available: toolsInstalled,
529
+ detail: `${readInstalledEspIdfVersion(dir)?.full || 'unknown version'} at ${dir}${toolsInstalled ? '' : ' (tools not installed)'}`,
530
+ dir
531
+ }
532
+ }
533
+
534
+ function isS31EspIdfDir(dir) {
535
+ return Boolean(dir) && exists(path.join(dir, 'tools', 'idf.py')) && readInstalledEspIdfVersion(dir)?.majorMinor === '6.2'
536
+ }
537
+
538
+ function installEspIdf(ctx, parsed, io, { idfDir, ref, targets }) {
539
+ const env = io.env || process.env
466
540
  const dryRun = flag(parsed, 'dry-run')
467
541
  if (!dryRun) fs.mkdirSync(path.dirname(idfDir), { recursive: true })
468
542
  if (!exists(path.join(idfDir, 'install.sh')) && !exists(path.join(idfDir, 'install.bat'))) {
469
- runExternal('git', ['clone', '-b', resolvedVersion, '--recursive', 'https://github.com/espressif/esp-idf.git', idfDir], {
543
+ runExternal('git', ['clone', '-b', ref, '--recursive', 'https://github.com/espressif/esp-idf.git', idfDir], {
470
544
  cwd: ctx.cwd,
471
545
  env,
472
546
  dryRun,
@@ -476,7 +550,7 @@ async function maybeSetupEspIdf(ctx, parsed, io, prompt, { force = false, target
476
550
  }
477
551
 
478
552
  const installScript = process.platform === 'win32' ? path.join(idfDir, 'install.bat') : path.join(idfDir, 'install.sh')
479
- runExternal(installScript, [espIdfInstallTargets], {
553
+ runExternal(installScript, [targets], {
480
554
  cwd: idfDir,
481
555
  env,
482
556
  dryRun,
@@ -487,15 +561,20 @@ async function maybeSetupEspIdf(ctx, parsed, io, prompt, { force = false, target
487
561
  const exportScript = process.platform === 'win32' ? path.join(idfDir, 'export.bat') : path.join(idfDir, 'export.sh')
488
562
  ui(io).success(`ESP-IDF installed at ${idfDir}`)
489
563
  ui(io).message(process.platform === 'win32' ? `For future shells: ${exportScript}` : `For future shells: . "${exportScript}"`)
490
- return 0
491
564
  }
492
565
 
493
566
  // Prefers the same conventional-directory detection the build path uses
494
567
  // (`findEspIdf` + its version.cmake), which lets a version-floor check run;
495
568
  // falls back to a bare `idf.py --version` on PATH when no such directory is
496
569
  // found but some ESP-IDF install has still put idf.py on PATH.
497
- function detectEspIdf(env, targetVersion) {
498
- const idfDir = findEspIdf(env)
570
+ // An explicit --idf-dir is the only directory that counts: another install
571
+ // elsewhere is not the one asked for, and a branch target such as `master`
572
+ // has no version for the floor check to tell the two apart.
573
+ function detectEspIdf(env, targetVersion, explicitDir = '') {
574
+ if (explicitDir && !fs.existsSync(path.join(explicitDir, 'tools', 'idf.py'))) {
575
+ return { available: false, detail: '' }
576
+ }
577
+ const idfDir = explicitDir ? path.resolve(explicitDir) : findEspIdf(env)
499
578
  if (idfDir) {
500
579
  const installed = readInstalledEspIdfVersion(idfDir)
501
580
  // A checkout is not an installation. `install.bat`/`install.sh` still has to
package/src/toolchain.mjs CHANGED
@@ -23,7 +23,27 @@ export function commandVersion(command, args, env = process.env) {
23
23
  // it -- a toolchain a build needs is worth failing on before the build starts,
24
24
  // with the same answer doctor would have given.
25
25
  export function onPath(name, env = process.env) {
26
- return envPath(env)
27
- .split(path.delimiter)
28
- .some((dir) => dir && existsSync(path.join(dir, name)))
26
+ return Boolean(findOnPath(name, env))
27
+ }
28
+
29
+ // The file a command resolves to on this PATH, or ''.
30
+ export function findOnPath(name, env = process.env) {
31
+ const names = executableNames(name, env)
32
+ for (const dir of envPath(env).split(path.delimiter)) {
33
+ if (!dir) continue
34
+ const found = names.map((candidate) => path.join(dir, candidate)).find((file) => existsSync(file))
35
+ if (found) return found
36
+ }
37
+ return ''
38
+ }
39
+
40
+ // Windows executables carry an extension from PATHEXT, so probing for the bare
41
+ // name finds nothing even when the tool is installed and on PATH -- which is
42
+ // how an ESP-IDF install that ships ninja.exe still read as "no ninja".
43
+ // PATHEXT spells the extensions in capitals; files on disk are `cmake.exe`,
44
+ // and a path the CLI prints or runs reads the same way.
45
+ function executableNames(name, env) {
46
+ if (process.platform !== 'win32') return [name]
47
+ const extensions = String(env.PATHEXT || '.COM;.EXE;.BAT;.CMD').split(';').filter(Boolean)
48
+ return [name, ...extensions.map((extension) => name + extension.toLowerCase())]
29
49
  }