83 lines
1.5 KiB
JavaScript
Executable File
83 lines
1.5 KiB
JavaScript
Executable File
#!/usr/bin/env node
|
|
import fs from 'node:fs';
|
|
|
|
function parseArgs(argv) {
|
|
let inputPath = null;
|
|
let compact = false;
|
|
|
|
for (let i = 0; i < argv.length; i += 1) {
|
|
const arg = argv[i];
|
|
|
|
if (arg === '--input') {
|
|
inputPath = argv[i + 1] ?? null;
|
|
i += 1;
|
|
continue;
|
|
}
|
|
|
|
if (arg.startsWith('--input=')) {
|
|
inputPath = arg.slice('--input='.length);
|
|
continue;
|
|
}
|
|
|
|
if (arg === '--compact') {
|
|
compact = true;
|
|
continue;
|
|
}
|
|
}
|
|
|
|
return { inputPath, compact };
|
|
}
|
|
|
|
function readInput(inputPath) {
|
|
if (!inputPath) {
|
|
return {
|
|
ok: false,
|
|
error: 'missing_required_input',
|
|
};
|
|
}
|
|
|
|
try {
|
|
const raw = fs.readFileSync(inputPath, 'utf8');
|
|
return {
|
|
ok: true,
|
|
bytes: Buffer.byteLength(raw, 'utf8'),
|
|
};
|
|
} catch (error) {
|
|
return {
|
|
ok: false,
|
|
error: error instanceof Error ? error.message : String(error),
|
|
};
|
|
}
|
|
}
|
|
|
|
const { inputPath, compact } = parseArgs(process.argv.slice(2));
|
|
const input = readInput(inputPath);
|
|
|
|
const response = {
|
|
ok: input.ok,
|
|
status: input.ok ? 'placeholder_receipt' : 'input_error',
|
|
binding: 'approved_plan_dispatch',
|
|
compact,
|
|
inputPath,
|
|
receipt: input.ok
|
|
? {
|
|
placeholder: true,
|
|
planId: null,
|
|
currentTask: null,
|
|
nextDerivedAction: null,
|
|
dispatchedAt: null,
|
|
}
|
|
: null,
|
|
input: input.ok
|
|
? {
|
|
ok: true,
|
|
bytes: input.bytes,
|
|
}
|
|
: {
|
|
ok: false,
|
|
error: input.error,
|
|
},
|
|
};
|
|
|
|
process.stdout.write(`${JSON.stringify(response)}\n`);
|