rust_to_npm/generators/
start.rs

1/// create the start script for the repo
2pub fn generate_start(name: &String) -> String {
3    format!(
4        r#"#!/usr/bin/env node
5
6const {{ exec }} = require("child_process");
7
8const controller = typeof AbortController !== "undefined" ? new AbortController() : {{ abort: () => {{}}, signal: typeof AbortSignal !== "undefined" ? new AbortSignal() : undefined }};
9const {{ signal }} = controller;
10
11exec("{name}", {{ signal }}, (error, stdout, stderr) => {{
12  stdout && console.log(stdout);
13  stderr && console.error(stderr);
14  if (error !== null) {{
15    console.log(`exec error: ${{error}}`);
16  }}
17}});
18
19process.on("SIGTERM", () => {{
20  controller && controller.abort();
21}});
22
23process.on("SIGINT", () => {{
24  controller && controller.abort();
25}});
26    "#
27    )
28}