Skip to content

Commit cd7683d

Browse files
authored
feat(setup/zephyr): adds support for windows (#224)
* feat(setup/zephyr): adds support for windows * chore(workflows/release): unset NODE_AUTH_TOKEN * chore: configure auto to not set npmrc token for publishing * chore: attempt to resolve npm publishing in CI * chore: allow release token to updating issues, PRs
1 parent 0daceba commit cd7683d

File tree

4 files changed

+86
-10
lines changed

4 files changed

+86
-10
lines changed

.github/workflows/release.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ env:
1111
permissions:
1212
id-token: write
1313
contents: read
14+
issues: write
15+
pull-requests: write
1416

1517
jobs:
1618
release:
@@ -40,13 +42,12 @@ jobs:
4042
with:
4143
node-version: 24
4244
cache: 'pnpm'
43-
registry-url: 'https://registry.npmjs.org'
4445

4546
- name: Install dependencies
4647
run: pnpm install
4748

4849
- name: Release It
4950
run: |
50-
pnpm release
51+
NODE_AUTH_TOKEN="" pnpm release
5152
env:
5253
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"engines": {
88
"node": ">=20"
99
},
10+
"publishConfig": {
11+
"registry": "https://registry.npmjs.org/",
12+
"access": "public"
13+
},
1014
"bin": {
1115
"xs-dev": "build/src/cli.js"
1216
},
@@ -116,7 +120,12 @@
116120
"auto": {
117121
"plugins": [
118122
"magic-zero",
119-
"npm",
123+
[
124+
"npm",
125+
{
126+
"setRcToken": false
127+
}
128+
],
120129
"all-contributors",
121130
"conventional-commits",
122131
"first-time-contributor",

src/toolbox/setup/zephyr.ts

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ import { INSTALL_DIR, EXPORTS_FILE_PATH } from './constants'
44
import upsert from '../patching/upsert'
55
import { installDeps as installMacDeps } from './zephyr/mac'
66
import { installDeps as installLinuxDeps } from './zephyr/linux'
7+
import { installDeps as installWinDeps } from './zephyr/windows'
78
import { moddableExists } from './moddable'
89
import { sourceEnvironment } from '../system/exec'
910
import { failure, successVoid, isFailure } from '../system/errors'
1011
import type { SetupResult } from '../../types'
1112
import { detectPython } from '../system/python'
13+
import { ensureModdableCommandPrompt, setEnv } from './windows'
1214

1315
export default async function(): Promise<SetupResult> {
1416
const OS = platformType().toLowerCase()
17+
const isWindows = OS === 'windows_nt'
1518
const ZEPHYR_ROOT =
1619
process.env.ZEPHYR_ROOT ?? filesystem.resolve(INSTALL_DIR, 'zephyrproject')
1720
const ZEPHYR_BASE =
@@ -31,6 +34,11 @@ export default async function(): Promise<SetupResult> {
3134
)
3235
return failure('Moddable platform tooling required. Run `xs-dev setup` before trying again.')
3336
}
37+
38+
if (isWindows) {
39+
const result = await ensureModdableCommandPrompt(spinner)
40+
if (isFailure(result)) return result
41+
}
3442
spinner.info('Ensuring zephyr directory')
3543
filesystem.dir(ZEPHYR_ROOT)
3644

@@ -45,6 +53,11 @@ export default async function(): Promise<SetupResult> {
4553
const result = await installLinuxDeps(spinner)
4654
if (isFailure(result)) return result
4755
}
56+
if (isWindows) {
57+
spinner.start('Installing dependencies with winget')
58+
const result = await installWinDeps(spinner)
59+
if (isFailure(result)) return result
60+
}
4861
spinner.succeed()
4962

5063
// 2. Create zephyr virtual environment
@@ -60,7 +73,18 @@ export default async function(): Promise<SetupResult> {
6073
spinner.succeed()
6174
}
6275
// 3. Activate virtual environment
63-
await upsert(EXPORTS_FILE_PATH, `source ${ZEPHYR_VENV_ACTIVATE}`)
76+
if (isWindows) {
77+
await upsert(
78+
EXPORTS_FILE_PATH,
79+
`call "${ZEPHYR_ROOT}\\.venv\\Scripts\\activate.bat"`,
80+
)
81+
await system.exec(`${ZEPHYR_ROOT}\\.venv\\Scripts\\activate.bat`, {
82+
stdout: process.stdout,
83+
shell: true,
84+
})
85+
} else {
86+
await upsert(EXPORTS_FILE_PATH, `source ${ZEPHYR_VENV_ACTIVATE}`)
87+
}
6488
await sourceEnvironment()
6589

6690
// 4. Install West with pip
@@ -86,11 +110,19 @@ export default async function(): Promise<SetupResult> {
86110

87111
// 6. Install west packages
88112
spinner.start(`Installing west packages`)
89-
await system.exec(`west packages pip --install`, {
90-
process,
91-
shell: process.env.SHELL,
92-
stdout: process.stdout
93-
})
113+
if (isWindows) {
114+
await system.exec(`cmd /c zephyr\\scripts\\utils\\west-packages-pip-install.cmd`, {
115+
cwd: ZEPHYR_ROOT,
116+
process,
117+
shell: process.env.SHELL,
118+
})
119+
} else {
120+
await system.exec(`west packages pip --install`, {
121+
process,
122+
shell: process.env.SHELL,
123+
stdout: process.stdout
124+
})
125+
}
94126
spinner.succeed()
95127

96128
// 7. Install Zephyr SDK
@@ -103,7 +135,11 @@ export default async function(): Promise<SetupResult> {
103135
spinner.succeed()
104136

105137
if (process.env.ZEPHYR_BASE === undefined) {
106-
await upsert(EXPORTS_FILE_PATH, `export ZEPHYR_BASE=${ZEPHYR_BASE}`)
138+
if (isWindows) {
139+
await setEnv('ZEPHYR_BASE', ZEPHYR_BASE)
140+
} else {
141+
await upsert(EXPORTS_FILE_PATH, `export ZEPHYR_BASE=${ZEPHYR_BASE}`)
142+
}
107143
}
108144

109145
print.success(`
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { print, system } from 'gluegun'
2+
import type { GluegunPrint } from 'gluegun'
3+
import type { Result } from '../../../types'
4+
import { failure, successVoid } from '../../system/errors'
5+
6+
export async function installDeps(
7+
spinner: ReturnType<GluegunPrint['spin']>,
8+
): Promise<Result<void>> {
9+
10+
spinner.start('Downloading ESP-IDF Tools Installer')
11+
try {
12+
await system.exec('where winget')
13+
} catch (error) {
14+
print.error(
15+
'winget is required to install dependencies for Zephyr tooling.',
16+
)
17+
print.info(
18+
'You can install winget via the App Installer package in the Microsoft Store.',
19+
)
20+
spinner.fail()
21+
return failure('winget is required to install dependencies for Zephyr tooling.')
22+
}
23+
await system.exec(
24+
'winget install Kitware.CMake Ninja-build.Ninja oss-winget.gperf Python.Python.3.12 Git.Git oss-winget.dtc wget 7zip.7zip',
25+
{ stdio: 'inherit', shell: true },
26+
)
27+
spinner.succeed()
28+
return successVoid()
29+
}
30+

0 commit comments

Comments
 (0)