@brookesia/simulator 0.1.0
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/dist/env.d.ts +10 -0
- package/dist/env.d.ts.map +1 -0
- package/dist/env.js +50 -0
- package/dist/env.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/spawn-gui.d.ts +14 -0
- package/dist/spawn-gui.d.ts.map +1 -0
- package/dist/spawn-gui.js +72 -0
- package/dist/spawn-gui.js.map +1 -0
- package/dist/spawn-runtime.d.ts +9 -0
- package/dist/spawn-runtime.d.ts.map +1 -0
- package/dist/spawn-runtime.js +32 -0
- package/dist/spawn-runtime.js.map +1 -0
- package/dist/toolchain-install.d.ts +14 -0
- package/dist/toolchain-install.d.ts.map +1 -0
- package/dist/toolchain-install.js +56 -0
- package/dist/toolchain-install.js.map +1 -0
- package/package.json +41 -0
package/dist/env.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type BrookesiaConfig, type BrookesiaState } from '@brookesia/shared-utils';
|
|
2
|
+
export declare function writeEnvSh(state: BrookesiaState): void;
|
|
3
|
+
export interface DetectSimulatorPathsInput {
|
|
4
|
+
projectRoot: string;
|
|
5
|
+
config: BrookesiaConfig;
|
|
6
|
+
simulatorBinary?: string;
|
|
7
|
+
guiProjectDir?: string;
|
|
8
|
+
}
|
|
9
|
+
export declare function detectAndSaveSimulatorPaths(input: DetectSimulatorPathsInput): BrookesiaState;
|
|
10
|
+
//# sourceMappingURL=env.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EAOL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAGjC,wBAAgB,UAAU,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI,CA2BtD;AAED,MAAM,WAAW,yBAAyB;IACxC,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,eAAe,CAAC;IACxB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,yBAAyB,GAAG,cAAc,CA0B5F"}
|
package/dist/env.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { ENV_FILE, STATE_DIR, detectRuntimeEnvPaths, resolveBundledSimulatorBinary, resolveGuiProjectDir, saveState, } from '@brookesia/shared-utils';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
export function writeEnvSh(state) {
|
|
4
|
+
fs.mkdirSync(STATE_DIR, { recursive: true });
|
|
5
|
+
const lines = [
|
|
6
|
+
'# Generated by brookesia toolchain — source before brookesia simulate',
|
|
7
|
+
];
|
|
8
|
+
const simBinary = state.simulators?.binary ?? state.simulators?.runtime?.binary;
|
|
9
|
+
if (simBinary) {
|
|
10
|
+
lines.push(`export BROOKESIA_SIMULATOR="${simBinary}"`);
|
|
11
|
+
}
|
|
12
|
+
if (state.boostPrefix) {
|
|
13
|
+
lines.push(`export CMAKE_PREFIX_PATH="${state.boostPrefix}:\${CMAKE_PREFIX_PATH:-}"`);
|
|
14
|
+
lines.push(`export LD_LIBRARY_PATH="${state.boostPrefix}/lib:\${LD_LIBRARY_PATH:-}"`);
|
|
15
|
+
}
|
|
16
|
+
if (state.quickjsRoot) {
|
|
17
|
+
lines.push(`export QUICKJS_ROOT="${state.quickjsRoot}"`);
|
|
18
|
+
}
|
|
19
|
+
if (state.quickjsBuildDir) {
|
|
20
|
+
lines.push(`export QUICKJS_BUILD_DIR="${state.quickjsBuildDir}"`);
|
|
21
|
+
}
|
|
22
|
+
if (state.wasmtimeCApi) {
|
|
23
|
+
lines.push(`export WASMTIME_C_API="${state.wasmtimeCApi}"`);
|
|
24
|
+
lines.push(`export LD_LIBRARY_PATH="${state.wasmtimeCApi}/lib:\${LD_LIBRARY_PATH:-}"`);
|
|
25
|
+
}
|
|
26
|
+
fs.writeFileSync(ENV_FILE, `${lines.join('\n')}\n`, 'utf8');
|
|
27
|
+
}
|
|
28
|
+
export function detectAndSaveSimulatorPaths(input) {
|
|
29
|
+
const binary = input.simulatorBinary ?? resolveBundledSimulatorBinary();
|
|
30
|
+
if (!binary) {
|
|
31
|
+
throw new Error('brookesia_simulator not found. Pass --simulator-binary or install esp-brookesia-toolkit with simulator/brookesia_simulator');
|
|
32
|
+
}
|
|
33
|
+
const projectDir = input.guiProjectDir?.trim()
|
|
34
|
+
?? resolveGuiProjectDir({
|
|
35
|
+
projectRoot: input.projectRoot,
|
|
36
|
+
config: input.config,
|
|
37
|
+
});
|
|
38
|
+
const env = detectRuntimeEnvPaths();
|
|
39
|
+
const state = {
|
|
40
|
+
simulators: {
|
|
41
|
+
binary,
|
|
42
|
+
...(projectDir ? { gui: { projectDir } } : {}),
|
|
43
|
+
},
|
|
44
|
+
...env,
|
|
45
|
+
};
|
|
46
|
+
saveState(state);
|
|
47
|
+
writeEnvSh(state);
|
|
48
|
+
return state;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=env.js.map
|
package/dist/env.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"env.js","sourceRoot":"","sources":["../src/env.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,SAAS,EACT,qBAAqB,EACrB,6BAA6B,EAC7B,oBAAoB,EACpB,SAAS,GAGV,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,MAAM,UAAU,UAAU,CAAC,KAAqB;IAC9C,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC7C,MAAM,KAAK,GAAa;QACtB,uEAAuE;KACxE,CAAC;IAEF,MAAM,SAAS,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,aAAa,EAAE,IAAI,EAAE;WACxB,oBAAoB,CAAC;YACtB,WAAW,EAAE,KAAK,CAAC,WAAW;YAC9B,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC,CAAC;IAEL,MAAM,GAAG,GAAG,qBAAqB,EAAE,CAAC;IACpC,MAAM,KAAK,GAAmB;QAC5B,UAAU,EAAE;YACV,MAAM;YACN,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAC/C;QACD,GAAG,GAAG;KACP,CAAC;IACF,SAAS,CAAC,KAAK,CAAC,CAAC;IACjB,UAAU,CAAC,KAAK,CAAC,CAAC;IAClB,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,wBAAwB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type ProjectContext } from '@brookesia/shared-utils';
|
|
2
|
+
export interface SpawnGuiOptions {
|
|
3
|
+
ctx: ProjectContext;
|
|
4
|
+
/** Load app package JSON UI via BROOKESIA_GUI_ROOT (off by default). */
|
|
5
|
+
appPreview?: boolean;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Default GUI simulator: general_test built-in Settings demo (seven documents).
|
|
9
|
+
* Does not set BROOKESIA_GUI_ROOT — see simulator/gui/general_test/src/main.cpp.
|
|
10
|
+
*/
|
|
11
|
+
export declare function spawnSettingsGuiSimulator(projectRoot: string): Promise<number>;
|
|
12
|
+
/** Optional: preview current app package JSON UI under assets/apps/<id>/res/. */
|
|
13
|
+
export declare function spawnGuiSimulator(opts: SpawnGuiOptions): Promise<number>;
|
|
14
|
+
//# sourceMappingURL=spawn-gui.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-gui.d.ts","sourceRoot":"","sources":["../src/spawn-gui.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAKjC,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,cAAc,CAAC;IACpB,wEAAwE;IACxE,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAkBD;;;GAGG;AACH,wBAAsB,yBAAyB,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAcpF;AAED,iFAAiF;AACjF,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO,CAAC,MAAM,CAAC,CA2C9E"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { loadBrookesiaConfig, loadManifestFromDir, loadState, logStep, requireGuiSimulatorPaths, } from '@brookesia/shared-utils';
|
|
2
|
+
import { execa } from 'execa';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import path from 'node:path';
|
|
5
|
+
function guiSpawnEnv(state) {
|
|
6
|
+
const boostPrefix = state.boostPrefix ?? process.env.BROOKESIA_BOOST_PREFIX ?? '/opt/boost-1.87';
|
|
7
|
+
const ldPaths = [
|
|
8
|
+
path.join(boostPrefix, 'lib'),
|
|
9
|
+
process.env.LD_LIBRARY_PATH,
|
|
10
|
+
].filter(Boolean).join(':');
|
|
11
|
+
const env = {
|
|
12
|
+
...process.env,
|
|
13
|
+
LD_LIBRARY_PATH: ldPaths,
|
|
14
|
+
};
|
|
15
|
+
delete env.BROOKESIA_GUI_ROOT;
|
|
16
|
+
delete env.BROOKESIA_GUI_SCREEN;
|
|
17
|
+
return env;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Default GUI simulator: general_test built-in Settings demo (seven documents).
|
|
21
|
+
* Does not set BROOKESIA_GUI_ROOT — see simulator/gui/general_test/src/main.cpp.
|
|
22
|
+
*/
|
|
23
|
+
export async function spawnSettingsGuiSimulator(projectRoot) {
|
|
24
|
+
const config = await loadBrookesiaConfig(projectRoot);
|
|
25
|
+
const state = loadState();
|
|
26
|
+
const { binary, projectDir } = requireGuiSimulatorPaths({ projectRoot, config, state });
|
|
27
|
+
logStep(`GUI simulator: Settings demo (${projectDir})`);
|
|
28
|
+
const result = await execa(binary, [], {
|
|
29
|
+
cwd: projectDir,
|
|
30
|
+
stdio: 'inherit',
|
|
31
|
+
env: guiSpawnEnv(state),
|
|
32
|
+
});
|
|
33
|
+
return result.exitCode ?? 0;
|
|
34
|
+
}
|
|
35
|
+
/** Optional: preview current app package JSON UI under assets/apps/<id>/res/. */
|
|
36
|
+
export async function spawnGuiSimulator(opts) {
|
|
37
|
+
if (!opts.appPreview) {
|
|
38
|
+
return spawnSettingsGuiSimulator(opts.ctx.projectRoot);
|
|
39
|
+
}
|
|
40
|
+
const state = loadState();
|
|
41
|
+
const { binary, projectDir } = requireGuiSimulatorPaths({
|
|
42
|
+
projectRoot: opts.ctx.projectRoot,
|
|
43
|
+
config: opts.ctx.config,
|
|
44
|
+
state,
|
|
45
|
+
});
|
|
46
|
+
const assetsSyncDir = opts.ctx.config.simulator?.gui?.assetsSyncDir ?? 'assets/apps';
|
|
47
|
+
const sourceDir = opts.ctx.config.pack?.skipBuildMirror ? opts.ctx.sourceRoot : opts.ctx.buildDir;
|
|
48
|
+
const manifest = loadManifestFromDir(sourceDir);
|
|
49
|
+
const pkgId = manifest.package.id;
|
|
50
|
+
const resSrc = path.join(sourceDir, manifest.runtime.resource_dir || 'res');
|
|
51
|
+
const resDest = path.join(projectDir, assetsSyncDir, pkgId, 'res');
|
|
52
|
+
if (await fs.pathExists(resSrc)) {
|
|
53
|
+
await fs.emptyDir(resDest);
|
|
54
|
+
await fs.copy(resSrc, resDest);
|
|
55
|
+
}
|
|
56
|
+
const guiRootRel = path.posix.join(assetsSyncDir, pkgId, manifest.gui?.root ?? 'res/root.json');
|
|
57
|
+
let guiScreen = 'root';
|
|
58
|
+
if (manifest.gui?.screen_path) {
|
|
59
|
+
guiScreen = manifest.gui.screen_path.replace(/^\//, '');
|
|
60
|
+
}
|
|
61
|
+
logStep(`GUI simulator: app preview ${guiRootRel} (screen=${guiScreen})`);
|
|
62
|
+
const env = guiSpawnEnv(state);
|
|
63
|
+
env.BROOKESIA_GUI_ROOT = guiRootRel;
|
|
64
|
+
env.BROOKESIA_GUI_SCREEN = guiScreen;
|
|
65
|
+
const result = await execa(binary, [], {
|
|
66
|
+
cwd: projectDir,
|
|
67
|
+
stdio: 'inherit',
|
|
68
|
+
env,
|
|
69
|
+
});
|
|
70
|
+
return result.exitCode ?? 0;
|
|
71
|
+
}
|
|
72
|
+
//# sourceMappingURL=spawn-gui.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-gui.js","sourceRoot":"","sources":["../src/spawn-gui.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,mBAAmB,EACnB,SAAS,EACT,OAAO,EACP,wBAAwB,GAEzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,IAAI,MAAM,WAAW,CAAC;AAQ7B,SAAS,WAAW,CAAC,KAAmC;IACtD,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,sBAAsB,IAAI,iBAAiB,CAAC;IACjG,MAAM,OAAO,GAAG;Q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AC,WAAW,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,CAAC,8BAA8B,UAAU,YAAY,SAAS,GAAG,CAAC,CAAC;IAE1E,MAAM,GAAG,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC;IAC/B,GAAG,CAAC,kBAAkB,GAAG,UAAU,CAAC;IACpC,GAAG,CAAC,oBAAoB,GAAG,SAAS,CAAC;IAErC,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE;QACrC,GAAG,EAAE,UAAU;QACf,KAAK,EAAE,SAAS;QAChB,GAAG;KACJ,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type ProjectContext } from '@brookesia/shared-utils';
|
|
2
|
+
export interface SpawnRuntimeOptions {
|
|
3
|
+
ctx: ProjectContext;
|
|
4
|
+
bpkPath: string;
|
|
5
|
+
verify?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function findLatestBpk(distDir: string): Promise<string>;
|
|
8
|
+
export declare function spawnRuntimeSimulator(opts: SpawnRuntimeOptions): Promise<number>;
|
|
9
|
+
//# sourceMappingURL=spawn-runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-runtime.d.ts","sourceRoot":"","sources":["../src/spawn-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACpB,MAAM,yBAAyB,CAAC;AAMjC,MAAM,WAAW,mBAAmB;IAClC,GAAG,EAAE,cAAc,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAOpE;AAED,wBAAsB,qBAAqB,CAAC,IAAI,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC,CAqBtF"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { buildRuntimeSimulatorEnv, loadState, requireRuntimeBinaryPath, } from '@brookesia/shared-utils';
|
|
2
|
+
import { execa } from 'execa';
|
|
3
|
+
import fs from 'fs-extra';
|
|
4
|
+
import os from 'node:os';
|
|
5
|
+
import path from 'node:path';
|
|
6
|
+
export async function findLatestBpk(distDir) {
|
|
7
|
+
const files = await fs.readdir(distDir);
|
|
8
|
+
const bpks = files.filter((f) => f.endsWith('.bpk')).sort();
|
|
9
|
+
if (bpks.length === 0) {
|
|
10
|
+
throw new Error(`No .bpk in ${distDir}; run brookesia build first`);
|
|
11
|
+
}
|
|
12
|
+
return path.join(distDir, bpks[bpks.length - 1]);
|
|
13
|
+
}
|
|
14
|
+
export async function spawnRuntimeSimulator(opts) {
|
|
15
|
+
const state = loadState();
|
|
16
|
+
const binary = requireRuntimeBinaryPath({
|
|
17
|
+
projectRoot: opts.ctx.projectRoot,
|
|
18
|
+
config: opts.ctx.config,
|
|
19
|
+
state,
|
|
20
|
+
});
|
|
21
|
+
const bpk = path.resolve(opts.bpkPath);
|
|
22
|
+
const inst = await fs.mkdtemp(path.join(os.tmpdir(), 'brookesia-inst-'));
|
|
23
|
+
const args = [bpk, inst];
|
|
24
|
+
if (opts.verify) {
|
|
25
|
+
const pub = path.join(opts.ctx.signDir, 'public.pem');
|
|
26
|
+
args.push(pub);
|
|
27
|
+
}
|
|
28
|
+
const env = buildRuntimeSimulatorEnv(opts.ctx.config, binary, state);
|
|
29
|
+
const result = await execa(binary, args, { stdio: 'inherit', env });
|
|
30
|
+
return result.exitCode ?? 0;
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=spawn-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"spawn-runtime.js","sourceRoot":"","sources":["../src/spawn-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,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AAG,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;IAEzB,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAChB,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACtD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACjB,CAAC;IAED,MAAM,GAAG,GAAG,wBAAwB,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAErE,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,MAAM,EAAE,IAAI,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC;IACpE,OAAO,MAAM,CAAC,QAAQ,IAAI,CAAC,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type BrookesiaConfig } from '@brookesia/shared-utils';
|
|
2
|
+
import type { DoctorEffectiveProfile } from '@brookesia/doctor';
|
|
3
|
+
/** Record brookesia_simulator path (no esp-brookesia SDK tree required). */
|
|
4
|
+
export declare function runSimulatorBinaryInstall(simulatorBinary: string): Promise<void>;
|
|
5
|
+
/** @deprecated Use {@link runSimulatorBinaryInstall}. */
|
|
6
|
+
export declare function runRuntimeSimulatorInstall(runtimeBinary: string): Promise<void>;
|
|
7
|
+
/**
|
|
8
|
+
* Record simulator paths and env.sh (bundled or configured brookesia_simulator + optional GUI projectDir).
|
|
9
|
+
*/
|
|
10
|
+
export declare function runToolchainInstall(projectRoot: string, config: BrookesiaConfig, profile: DoctorEffectiveProfile, opts?: {
|
|
11
|
+
simulatorBinary?: string;
|
|
12
|
+
guiProjectDir?: string;
|
|
13
|
+
}): Promise<void>;
|
|
14
|
+
//# sourceMappingURL=toolchain-install.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"toolchain-install.d.ts","sourceRoot":"","sources":["../src/toolchain-install.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAahE,4EAA4E;AAC5E,wBAAsB,yBAAyB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAgBtF;AAED,yDAAyD;AACzD,wBAAsB,0BAA0B,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAErF;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,eAAe,EACvB,OAAO,EAAE,sBAAsB,EAC/B,IAAI,CAAC,EAAE;IAAE,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAE,GAC1D,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { loadState, logStep, logSuccess, logWarn, mergeState, } from '@brookesia/shared-utils';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
4
|
+
import { detectAndSaveSimulatorPaths } from './env.js';
|
|
5
|
+
function assertExecutable(filePath) {
|
|
6
|
+
try {
|
|
7
|
+
fs.accessSync(filePath, fs.constants.X_OK);
|
|
8
|
+
}
|
|
9
|
+
catch {
|
|
10
|
+
throw new Error(`Not executable: ${filePath}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/** Record brookesia_simulator path (no esp-brookesia SDK tree required). */
|
|
14
|
+
export async function runSimulatorBinaryInstall(simulatorBinary) {
|
|
15
|
+
const resolved = path.resolve(simulatorBinary);
|
|
16
|
+
if (!fs.existsSync(resolved)) {
|
|
17
|
+
throw new Error(`brookesia_simulator not found: ${resolved}`);
|
|
18
|
+
}
|
|
19
|
+
assertExecutable(resolved);
|
|
20
|
+
logStep(`toolchain install: recording brookesia_simulator ${resolved}`);
|
|
21
|
+
const prev = loadState();
|
|
22
|
+
mergeState({
|
|
23
|
+
simulators: {
|
|
24
|
+
...prev.simulators,
|
|
25
|
+
binary: resolved,
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
logSuccess('Wrote ~/.brookesia/state.json (simulators.binary)');
|
|
29
|
+
logSuccess('Simulate: brookesia build && brookesia simulate --target runtime|gui');
|
|
30
|
+
}
|
|
31
|
+
/** @deprecated Use {@link runSimulatorBinaryInstall}. */
|
|
32
|
+
export async function runRuntimeSimulatorInstall(runtimeBinary) {
|
|
33
|
+
return runSimulatorBinaryInstall(runtimeBinary);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Record simulator paths and env.sh (bundled or configured brookesia_simulator + optional GUI projectDir).
|
|
37
|
+
*/
|
|
38
|
+
export async function runToolchainInstall(projectRoot, config, profile, opts) {
|
|
39
|
+
logStep(`toolchain install (profile=${profile}): brookesia_simulator`);
|
|
40
|
+
const state = detectAndSaveSimulatorPaths({
|
|
41
|
+
projectRoot,
|
|
42
|
+
config,
|
|
43
|
+
simulatorBinary: opts?.simulatorBinary,
|
|
44
|
+
guiProjectDir: opts?.guiProjectDir,
|
|
45
|
+
});
|
|
46
|
+
logSuccess('Wrote ~/.brookesia/state.json and env.sh');
|
|
47
|
+
if (profile === 'gui' && !state.simulators?.gui?.projectDir) {
|
|
48
|
+
logWarn('GUI simulate needs simulator.gui.projectDir in brookesia.config.js '
|
|
49
|
+
+ '(or pass --gui-project-dir to toolchain install).');
|
|
50
|
+
}
|
|
51
|
+
if (profile !== 'pack-only' && !opts?.simulatorBinary) {
|
|
52
|
+
logWarn('To refresh the PC simulator binary, rebuild in esp-brookesia/simulator and run '
|
|
53
|
+
+ 'npm run stage:simulator -- <path/to/brookesia_simulator> in the toolkit monorepo.');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=toolchain-install.js.map
|
|
@@ -0,0 +1 @@
|
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pE,OAAO,yBAAyB,CAAC,aAAa,CAAC,CAAC;AAClD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,WAAmB,EACnB,MAAuB,EACvB,OAA+B,EAC/B,IAA2D;IAE3D,OAAO,CAAC,8BAA8B,OAAO,wBAAwB,CAAC,CAAC;IACvE,MAAM,KAAK,GAAG,2BAA2B,CAAC;QACxC,WAAW;QACX,MAAM;QACN,eAAe,EAAE,IAAI,EAAE,eAAe;QACtC,aAAa,EAAE,IAAI,EAAE,aAAa;KACnC,CAAC,CAAC;IACH,UAAU,CAAC,0CAA0C,CAAC,CAAC;IAEvD,IAAI,OAAO,KAAK,KAAK,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC;QAC5D,OAAO,CACL,qEAAqE;cACnE,mDAAmD,CACtD,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,KAAK,WAAW,IAAI,CAAC,IAAI,EAAE,eAAe,EAAE,CAAC;QACtD,OAAO,CACL,iFAAiF;cAC/E,mFAAmF,CACtF,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@brookesia/simulator",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Spawn ESP-Brookesia PC runtime and GUI simulators",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"main": "./dist/index.js",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"dist"
|
|
11
|
+
],
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public",
|
|
14
|
+
"registry": "https://registry.npmjs.org/"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/espressif/esp-brookesia-toolkit.git",
|
|
19
|
+
"directory": "packages/simulator"
|
|
20
|
+
},
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.js"
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tsc -p tsconfig.json",
|
|
29
|
+
"clean": "rm -rf dist"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@brookesia/doctor": "0.1.0",
|
|
33
|
+
"@brookesia/shared-utils": "0.1.0",
|
|
34
|
+
"execa": "^9.5.2",
|
|
35
|
+
"fs-extra": "^11.3.0"
|
|
36
|
+
},
|
|
37
|
+
"devDependencies": {
|
|
38
|
+
"@types/fs-extra": "^11.0.4",
|
|
39
|
+
"typescript": "^5.7.3"
|
|
40
|
+
}
|
|
41
|
+
}
|