Skip to content

Commit 91f8b50

Browse files
committed
feat: ability to specify path for custom diagram.json
1 parent cfd2078 commit 91f8b50

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/help.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export function cliHelp() {
1212
{green --expect-text} <string> Expect the given text in the output
1313
{green --fail-text} <string> Fail if the given text is found in the output
1414
{green --elf} <path> ELF file to simulate (default: read from wokwi.toml)
15+
{green --diagram-file} <path> Path to the diagram.json file, relative to project root (default: diagram.json)
1516
{green --interactive} Redirect stdin to the simulated serial port
1617
{green --scenario} <path> Run the given scenario (yaml) file, path is relative to project root
1718
{green --serial-log-file} <path> Save the serial monitor output to the given file

src/main.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ async function main() {
2626
'--help': Boolean,
2727
'--quiet': Boolean,
2828
'--version': Boolean,
29+
'--diagram-file': String,
2930
'--elf': String,
3031
'--expect-text': String,
3132
'--fail-text': String,
@@ -48,6 +49,7 @@ async function main() {
4849
const expectText = args['--expect-text'];
4950
const failText = args['--fail-text'];
5051
const interactive = args['--interactive'];
52+
const diagramFile = args['--diagram-file'];
5153
const serialLogFile = args['--serial-log-file'];
5254
const scenarioFile = args['--scenario'];
5355
const timeout = args['--timeout'] ?? 30000;
@@ -76,16 +78,16 @@ async function main() {
7678
}
7779

7880
const rootDir = args._[0] || '.';
79-
const configPath = `${rootDir}/wokwi.toml`;
80-
const diagramFile = `${rootDir}/diagram.json`;
81+
const configPath = path.join(rootDir, 'wokwi.toml');
82+
const diagramFilePath = path.join(rootDir, diagramFile ?? 'diagram.json');
8183
const configExists = existsSync(configPath);
8284

8385
if (!elf && !configExists) {
8486
console.error(`Error: wokwi.toml not found in ${path.resolve(rootDir)}`);
8587
process.exit(1);
8688
}
8789

88-
if (!existsSync(diagramFile)) {
90+
if (!existsSync(diagramFilePath)) {
8991
console.error(`Error: diagram.json not found in ${path.resolve(rootDir)}`);
9092
process.exit(1);
9193
}
@@ -117,7 +119,7 @@ async function main() {
117119
process.exit(1);
118120
}
119121

120-
const diagram = readFileSync(diagramFile, 'utf8');
122+
const diagram = readFileSync(diagramFilePath, 'utf8');
121123

122124
const chips = loadChips(config?.chip ?? [], rootDir);
123125

0 commit comments

Comments
 (0)