MCPcopy Create free account
hub / github.com/arctic-cli/interface / init

Function init

packages/arctic/src/format/index.ts:103–136  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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}

Callers

nothing calls this directly

Calls 3

getFormatterFunction · 0.85
spawnMethod · 0.80
subscribeMethod · 0.45

Tested by

no test coverage detected