Skip to content

Commit

Permalink
feat: add support for ESP-IDF v5 & mcpack (#149)
Browse files Browse the repository at this point in the history
* feat(esp32): support esp-idf v5 in setup, update if latest moddable SDK available

* feat(build/run): add mcpack detection

* refactor: resolve linting feedback
  • Loading branch information
HipsterBrown committed Oct 12, 2023
1 parent d625a9d commit 0200d56
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
12 changes: 10 additions & 2 deletions src/toolbox/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,16 @@ export async function build({
configArgs.push(`${element}="${value}"`)
})

const canUseMCPack = system.which('mcpack') !== null && filesystem.exists(filesystem.resolve(projectPath, 'package.json')) === 'file'
let rootCommand = 'mcconfig'

if (canUseMCPack) {
rootCommand = 'mcpack'
configArgs.unshift('mcconfig')
}

if (log) {
const logOutput = spawn('mcconfig', configArgs, { cwd: projectPath, stdio: 'inherit', shell: true });
const logOutput = spawn(rootCommand, configArgs, { cwd: projectPath, stdio: 'inherit', shell: true });
logOutput.on('close', (exitCode) => {
if (exitCode !== null) {
process.exit(exitCode)
Expand All @@ -257,7 +265,7 @@ export async function build({
void system.exec(`pkill serial2xsbug`)
})
try {
await system.exec(`mcconfig ${configArgs.join(' ')}`, {
await system.exec(`${rootCommand} ${configArgs.join(' ')}`, {
cwd: projectPath,
stdio: 'inherit',
shell: true,
Expand Down
11 changes: 7 additions & 4 deletions src/toolbox/setup/esp32.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { print, filesystem, system } from 'gluegun'
import { print, filesystem, system, semver } from 'gluegun'
import { type as platformType } from 'os'
import { INSTALL_DIR, EXPORTS_FILE_PATH } from './constants'
import { moddableExists } from './moddable'
import { moddableExists, getModdableVersion } from './moddable'
import upsert from '../patching/upsert'
import { installDeps as installMacDeps } from './esp32/mac'
import { installDeps as installLinuxDeps } from './esp32/linux'
Expand All @@ -13,7 +13,8 @@ export default async function(): Promise<void> {
const OS = platformType().toLowerCase()
const isWindows = OS === "windows_nt"
const ESP_IDF_REPO = 'https://github.com/espressif/esp-idf.git'
const ESP_BRANCH = 'v4.4.3'
const ESP_BRANCH_V4 = 'v4.4.3'
const ESP_BRANCH_V5 = 'v5.1.1'
const ESP32_DIR = filesystem.resolve(INSTALL_DIR, 'esp32')
const IDF_PATH = filesystem.resolve(ESP32_DIR, 'esp-idf')

Expand Down Expand Up @@ -41,8 +42,10 @@ export default async function(): Promise<void> {
// 2. clone esp-idf into ~/.local/share/esp32/esp-idf
if (filesystem.exists(IDF_PATH) === false) {
spinner.start('Cloning esp-idf repo')
const moddableVersion = await getModdableVersion() ?? ''
const branch = (moddableVersion.includes("branch") || semver.satisfies(moddableVersion ?? '', '>= 4.2.x')) ? ESP_BRANCH_V5 : ESP_BRANCH_V4
await system.spawn(
`git clone --depth 1 --single-branch -b ${ESP_BRANCH} --recursive ${ESP_IDF_REPO} ${IDF_PATH}`
`git clone --depth 1 --single-branch -b ${branch} --recursive ${ESP_IDF_REPO} ${IDF_PATH}`
)
spinner.succeed()
}
Expand Down
3 changes: 2 additions & 1 deletion src/toolbox/setup/moddable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export function moddableExists(): boolean {
return (
process.env.MODDABLE !== undefined &&
filesystem.exists(process.env.MODDABLE) === 'dir' &&
(releaseTools === 'dir' || debugTools === 'dir')
(releaseTools === 'dir' ||
debugTools === 'dir')
)
}

Expand Down
11 changes: 7 additions & 4 deletions src/toolbox/update/esp32.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { print, filesystem, system, patching } from 'gluegun'
import { print, filesystem, system, patching, semver } from 'gluegun'
import { type as platformType } from 'os'
import { INSTALL_DIR, EXPORTS_FILE_PATH } from '../setup/constants'
import { moddableExists } from '../setup/moddable'
import { getModdableVersion, moddableExists } from '../setup/moddable'
import upsert from '../patching/upsert'
import { installDeps as installMacDeps } from '../setup/esp32/mac'
import { installDeps as installLinuxDeps } from '../setup/esp32/linux'
import { sourceEnvironment } from '../system/exec'

export default async function(): Promise<void> {
const OS = platformType().toLowerCase()
const ESP_BRANCH = 'v4.4.3'
const ESP_BRANCH_V4 = 'v4.4.3'
const ESP_BRANCH_V5 = 'v5.1.1'
const ESP32_DIR = filesystem.resolve(INSTALL_DIR, 'esp32')
const IDF_PATH = filesystem.resolve(ESP32_DIR, 'esp-idf')

Expand Down Expand Up @@ -41,8 +42,10 @@ export default async function(): Promise<void> {
// 2. update local esp-idf repo
if (filesystem.exists(IDF_PATH) === 'dir') {
spinner.start('Updating esp-idf repo')
const moddableVersion = await getModdableVersion() ?? ''
const branch = (moddableVersion.includes("branch") || semver.satisfies(moddableVersion ?? '', '>= 4.2.x')) ? ESP_BRANCH_V5 : ESP_BRANCH_V4
await system.spawn(`git fetch --all --tags`, { cwd: IDF_PATH })
await system.spawn(`git checkout ${ESP_BRANCH}`, { cwd: IDF_PATH })
await system.spawn(`git checkout ${branch}`, { cwd: IDF_PATH })
await system.spawn(`git submodule update --init --recursive`, {
cwd: IDF_PATH,
})
Expand Down

0 comments on commit 0200d56

Please sign in to comment.