Loading files
import { existsSync, mkdirSync, readFileSync, writeFileSync } from 'node:fs'
import path from 'node:path'
const dependenciesByPlatform = {
m5stack_cores3: [['espressif/esp32-camera', '^2.0.10']],
m5stackchan_cores3: [
['espressif/esp_audio_codec', '^2.6.0'],
['espressif/esp32-camera', '^2.0.10'],
],
}
/**
* Seeds a generated CoreS3 IDF manifest before Moddable adds dependencies.
* @param {{outputDirectory: string, platformName: string, applicationName: string, mode: string}} options - Build output configuration.
* @returns {string} Path to the prepared IDF component manifest.
*/
export function prepareCoreS3IdfDependencies({ outputDirectory, platformName, applicationName, mode }) {
if (!outputDirectory) throw new Error('Build output directory is required')
const dependencies = dependenciesByPlatform[platformName]
if (!dependencies) throw new Error(`Unsupported CoreS3 platform: ${platformName}`)
if (!applicationName) throw new Error('Application name is required')
if (!['debug', 'instrument', 'release'].includes(mode)) throw new Error(`Unsupported build mode: ${mode}`)
const mainDirectory = path.join(
outputDirectory,
'tmp',
'esp32',
platformName,
mode,
applicationName,
'xsProj-esp32s3',
'main',
)
const manifestPath = path.join(mainDirectory, 'idf_component.yml')
mkdirSync(mainDirectory, { recursive: true })
const originalManifest = existsSync(manifestPath) ? readFileSync(manifestPath, 'utf8') : null
let manifest =
originalManifest ?? "## IDF Component Manager Manifest File\ndependencies:\n idf:\n version: '>=4.1.0'\n"
if (!/^dependencies:\s*$/m.test(manifest)) {
throw new Error(`IDF component manifest has no dependencies block: ${manifestPath}`)
}
for (const [name, version] of dependencies) {
if (manifest.includes(` ${name}:`)) continue
if (!manifest.endsWith('\n')) manifest += '\n'
manifest += ` ${name}: ${version}\n`
}
// Moddable 8.3.1 joins multiple `idf.py add-dependency` commands with `&` on
// POSIX, so clean builds can race while updating this file. Seed both entries
// before mcconfig runs and its generated checks become no-ops.
if (manifest !== originalManifest) writeFileSync(manifestPath, manifest)
console.log(`[stack-chan] prepared IDF dependencies: ${manifestPath}`)
return manifestPath
}
71daecf65This file is pinned to the selected release. Download the original to open it in your design tool.