All files / src wavedrom.ts

25% Statements 2/8
100% Branches 0/0
0% Functions 0/1
25% Lines 2/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34          1x   1x                                                    
/**
 * A wrapper of wavedrom CLI
 * https://github.com/wavedrom/cli
 */
 
import * as utility from "./utility";
 
export async function render(
  wavedromCode: string,
  projectDirectoryPath: string,
): Promise<string> {
  const info = await utility.tempOpen({
    prefix: "mume-wavedrom",
    suffix: ".js",
  });
  await utility.write(info.fd, wavedromCode);
  try {
    const svg = await utility.execFile(
      "npx",
      ["wavedrom-cli", "-i", info.path],
      {
        shell: true,
        cwd: projectDirectoryPath,
      },
    );
    return svg;
  } catch (error) {
    throw new Error(
      "wavedrom CLI is required to be installed.\nCheck http://github.com/wavedrom/cli for more information.\n\n" +
        error.toString(),
    );
  }
}