()
| 101 | } |
| 102 | |
| 103 | export function init() { |
| 104 | log.info("init") |
| 105 | Bus.subscribe(File.Event.Edited, async (payload) => { |
| 106 | const file = payload.properties.file |
| 107 | log.info("formatting", { file }) |
| 108 | const ext = path.extname(file) |
| 109 | |
| 110 | for (const item of await getFormatter(ext)) { |
| 111 | log.info("running", { command: item.command }) |
| 112 | try { |
| 113 | const proc = Bun.spawn({ |
| 114 | cmd: item.command.map((x) => x.replace("$FILE", file)), |
| 115 | cwd: Instance.directory, |
| 116 | env: { ...process.env, ...item.environment }, |
| 117 | stdout: "ignore", |
| 118 | stderr: "ignore", |
| 119 | }) |
| 120 | const exit = await proc.exited |
| 121 | if (exit !== 0) |
| 122 | log.error("failed", { |
| 123 | command: item.command, |
| 124 | ...item.environment, |
| 125 | }) |
| 126 | } catch (error) { |
| 127 | log.error("failed to format file", { |
| 128 | error, |
| 129 | command: item.command, |
| 130 | ...item.environment, |
| 131 | file, |
| 132 | }) |
| 133 | } |
| 134 | } |
| 135 | }) |
| 136 | } |
| 137 | } |
nothing calls this directly
no test coverage detected