diff --git a/dist/tools/cli.mjs b/dist/tools/cli.mjs index 529c263d0..f03ed6564 100644 --- a/dist/tools/cli.mjs +++ b/dist/tools/cli.mjs @@ -1,6 +1,5 @@ -import { parseCliArgs, getToolRunner } from './lib.mjs'; +import { parseCliArgs, run } from './lib.mjs'; const { agent, tool, command } = parseCliArgs(); -const runner = await getToolRunner(agent, tool); -await runner.run(command); +await run(agent, tool, command); //# sourceMappingURL=cli.mjs.map diff --git a/dist/tools/cli.mjs.map b/dist/tools/cli.mjs.map index 67b162228..74aa92080 100644 --- a/dist/tools/cli.mjs.map +++ b/dist/tools/cli.mjs.map @@ -1 +1 @@ -{"version":3,"file":"cli.mjs","sources":["../../src/tools/cli.ts"],"sourcesContent":["import { getToolRunner, parseCliArgs } from '@lib'\n\nconst { agent, tool, command } = parseCliArgs()\nconst runner = await getToolRunner(agent, tool)\nawait runner.run(command)\n"],"names":[],"mappings":";;AAEA,MAAM,EAAE,KAAA,EAAO,IAAM,EAAA,OAAA,KAAY,YAAa,EAAA,CAAA;AAC9C,MAAM,MAAS,GAAA,MAAM,aAAc,CAAA,KAAA,EAAO,IAAI,CAAA,CAAA;AAC9C,MAAM,MAAA,CAAO,IAAI,OAAO,CAAA"} \ No newline at end of file +{"version":3,"file":"cli.mjs","sources":["../../src/tools/cli.ts"],"sourcesContent":["import { parseCliArgs, run } from '@lib'\nimport type { Commands } from '@tools/gitversion'\n\nconst { agent, tool, command } = parseCliArgs()\nawait run(agent, tool, command as Commands)\n"],"names":[],"mappings":";;AAGA,MAAM,EAAE,KAAA,EAAO,IAAM,EAAA,OAAA,KAAY,YAAa,EAAA,CAAA;AAC9C,MAAM,GAAA,CAAI,KAAO,EAAA,IAAA,EAAM,OAAmB,CAAA"} \ No newline at end of file diff --git a/dist/tools/lib.mjs b/dist/tools/lib.mjs index 66ffd1029..9301368a4 100644 --- a/dist/tools/lib.mjs +++ b/dist/tools/lib.mjs @@ -1,4 +1,5 @@ import { parseArgs } from 'node:util'; +import * as process from 'node:process'; async function getAgent(buildAgent) { const agent = `./${buildAgent}/agent.mjs`; @@ -22,7 +23,14 @@ function parseCliArgs() { } async function run(agent, tool, command) { const runner = await getToolRunner(agent, tool); - return await runner.run(command); + const { code, stdout, stderr } = await runner.run(command); + if (stdout) { + process.stdout.write(stdout); + } + if (stderr) { + process.stderr.write(stderr); + } + process.exit(code); } export { getAgent, getToolRunner, parseCliArgs, run }; diff --git a/dist/tools/lib.mjs.map b/dist/tools/lib.mjs.map index 1aa6ac2b6..fd4b31b4f 100644 --- a/dist/tools/lib.mjs.map +++ b/dist/tools/lib.mjs.map @@ -1 +1 @@ -{"version":3,"file":"lib.mjs","sources":["../../src/tools/lib.ts"],"sourcesContent":["import { parseArgs } from 'node:util'\n\nimport { type ExecResult, type IBuildAgent } from '@agents/common'\nimport { type IRunner } from '@tools/common'\n\ntype CliArgs = {\n agent: string\n tool: string\n command: string\n}\n\nexport async function getAgent(buildAgent: string | undefined): Promise {\n const agent = `./${buildAgent}/agent.mjs`\n const module = (await import(agent)) as { BuildAgent: new () => IBuildAgent }\n return new module.BuildAgent()\n}\n\nexport async function getToolRunner(buildAgent: string | undefined, tool: string | undefined): Promise {\n const agent = await getAgent(buildAgent)\n const toolRunner = `./libs/${tool}.mjs`\n const module = (await import(toolRunner)) as { Runner: new (buildAgent: IBuildAgent) => IRunner }\n return new module.Runner(agent)\n}\n\nexport function parseCliArgs(): CliArgs {\n return parseArgs({\n options: {\n agent: { type: 'string', short: 'a' },\n tool: { type: 'string', short: 't' },\n command: { type: 'string', short: 'c' }\n }\n }).values as CliArgs\n}\n\nexport async function run(agent: string, tool: string, command: string): Promise {\n const runner = await getToolRunner(agent, tool)\n return await runner.run(command)\n}\n"],"names":[],"mappings":";;AAWA,eAAsB,SAAS,UAAsD,EAAA;AACjF,EAAM,MAAA,KAAA,GAAQ,KAAK,UAAU,CAAA,UAAA,CAAA,CAAA;AAC7B,EAAM,MAAA,MAAA,GAAU,MAAM,OAAO,KAAA,CAAA,CAAA;AAC7B,EAAO,OAAA,IAAI,OAAO,UAAW,EAAA,CAAA;AACjC,CAAA;AAEsB,eAAA,aAAA,CAAc,YAAgC,IAA4C,EAAA;AAC5G,EAAM,MAAA,KAAA,GAAQ,MAAM,QAAA,CAAS,UAAU,CAAA,CAAA;AACvC,EAAM,MAAA,UAAA,GAAa,UAAU,IAAI,CAAA,IAAA,CAAA,CAAA;AACjC,EAAM,MAAA,MAAA,GAAU,MAAM,OAAO,UAAA,CAAA,CAAA;AAC7B,EAAO,OAAA,IAAI,MAAO,CAAA,MAAA,CAAO,KAAK,CAAA,CAAA;AAClC,CAAA;AAEO,SAAS,YAAwB,GAAA;AACpC,EAAA,OAAO,SAAU,CAAA;AAAA,IACb,OAAS,EAAA;AAAA,MACL,KAAO,EAAA,EAAE,IAAM,EAAA,QAAA,EAAU,OAAO,GAAI,EAAA;AAAA,MACpC,IAAM,EAAA,EAAE,IAAM,EAAA,QAAA,EAAU,OAAO,GAAI,EAAA;AAAA,MACnC,OAAS,EAAA,EAAE,IAAM,EAAA,QAAA,EAAU,OAAO,GAAI,EAAA;AAAA,KAC1C;AAAA,GACH,CAAE,CAAA,MAAA,CAAA;AACP,CAAA;AAEsB,eAAA,GAAA,CAAI,KAAe,EAAA,IAAA,EAAc,OAAsC,EAAA;AACzF,EAAA,MAAM,MAAS,GAAA,MAAM,aAAc,CAAA,KAAA,EAAO,IAAI,CAAA,CAAA;AAC9C,EAAO,OAAA,MAAM,MAAO,CAAA,GAAA,CAAI,OAAO,CAAA,CAAA;AACnC;;;;"} \ No newline at end of file +{"version":3,"file":"lib.mjs","sources":["../../src/tools/lib.ts"],"sourcesContent":["import { parseArgs } from 'node:util'\nimport * as process from 'node:process'\n\nimport { type IBuildAgent } from '@agents/common'\nimport { type IRunner } from '@tools/common'\n\ntype CliArgs = {\n agent: string\n tool: string\n command: string\n}\n\nexport async function getAgent(buildAgent: string | undefined): Promise {\n const agent = `./${buildAgent}/agent.mjs`\n const module = (await import(agent)) as { BuildAgent: new () => IBuildAgent }\n return new module.BuildAgent()\n}\n\nexport async function getToolRunner(buildAgent: string | undefined, tool: string | undefined): Promise {\n const agent = await getAgent(buildAgent)\n const toolRunner = `./libs/${tool}.mjs`\n const module = (await import(toolRunner)) as { Runner: new (buildAgent: IBuildAgent) => IRunner }\n return new module.Runner(agent)\n}\n\nexport function parseCliArgs(): CliArgs {\n return parseArgs({\n options: {\n agent: { type: 'string', short: 'a' },\n tool: { type: 'string', short: 't' },\n command: { type: 'string', short: 'c' }\n }\n }).values as CliArgs\n}\n\nexport async function run(agent: string, tool: string, command: string): Promise {\n const runner = await getToolRunner(agent, tool)\n const { code, stdout, stderr } = await runner.run(command)\n if (stdout) {\n process.stdout.write(stdout)\n }\n if (stderr) {\n process.stderr.write(stderr)\n }\n process.exit(code)\n}\n"],"names":[],"mappings":";;;AAYA,eAAsB,SAAS,UAAsD,EAAA;AACjF,EAAM,MAAA,KAAA,GAAQ,KAAK,UAAU,CAAA,UAAA,CAAA,CAAA;AAC7B,EAAM,MAAA,MAAA,GAAU,MAAM,OAAO,KAAA,CAAA,CAAA;AAC7B,EAAO,OAAA,IAAI,OAAO,UAAW,EAAA,CAAA;AACjC,CAAA;AAEsB,eAAA,aAAA,CAAc,YAAgC,IAA4C,EAAA;AAC5G,EAAM,MAAA,KAAA,GAAQ,MAAM,QAAA,CAAS,UAAU,CAAA,CAAA;AACvC,EAAM,MAAA,UAAA,GAAa,UAAU,IAAI,CAAA,IAAA,CAAA,CAAA;AACjC,EAAM,MAAA,MAAA,GAAU,MAAM,OAAO,UAAA,CAAA,CAAA;AAC7B,EAAO,OAAA,IAAI,MAAO,CAAA,MAAA,CAAO,KAAK,CAAA,CAAA;AAClC,CAAA;AAEO,SAAS,YAAwB,GAAA;AACpC,EAAA,OAAO,SAAU,CAAA;AAAA,IACb,OAAS,EAAA;AAAA,MACL,KAAO,EAAA,EAAE,IAAM,EAAA,QAAA,EAAU,OAAO,GAAI,EAAA;AAAA,MACpC,IAAM,EAAA,EAAE,IAAM,EAAA,QAAA,EAAU,OAAO,GAAI,EAAA;AAAA,MACnC,OAAS,EAAA,EAAE,IAAM,EAAA,QAAA,EAAU,OAAO,GAAI,EAAA;AAAA,KAC1C;AAAA,GACH,CAAE,CAAA,MAAA,CAAA;AACP,CAAA;AAEsB,eAAA,GAAA,CAAI,KAAe,EAAA,IAAA,EAAc,OAAgC,EAAA;AACnF,EAAA,MAAM,MAAS,GAAA,MAAM,aAAc,CAAA,KAAA,EAAO,IAAI,CAAA,CAAA;AAC9C,EAAM,MAAA,EAAE,MAAM,MAAQ,EAAA,MAAA,KAAW,MAAM,MAAA,CAAO,IAAI,OAAO,CAAA,CAAA;AACzD,EAAA,IAAI,MAAQ,EAAA;AACR,IAAQ,OAAA,CAAA,MAAA,CAAO,MAAM,MAAM,CAAA,CAAA;AAAA,GAC/B;AACA,EAAA,IAAI,MAAQ,EAAA;AACR,IAAQ,OAAA,CAAA,MAAA,CAAO,MAAM,MAAM,CAAA,CAAA;AAAA,GAC/B;AACA,EAAA,OAAA,CAAQ,KAAK,IAAI,CAAA,CAAA;AACrB;;;;"} \ No newline at end of file diff --git a/src/tools/cli.ts b/src/tools/cli.ts index 83c3bd837..b10a6db6e 100644 --- a/src/tools/cli.ts +++ b/src/tools/cli.ts @@ -1,5 +1,5 @@ -import { getToolRunner, parseCliArgs } from '@lib' +import { parseCliArgs, run } from '@lib' +import { type Commands } from '@tools/gitversion' const { agent, tool, command } = parseCliArgs() -const runner = await getToolRunner(agent, tool) -await runner.run(command) +await run(agent, tool, command as Commands) diff --git a/src/tools/lib.ts b/src/tools/lib.ts index 5260a95a6..a869afd75 100644 --- a/src/tools/lib.ts +++ b/src/tools/lib.ts @@ -1,6 +1,7 @@ import { parseArgs } from 'node:util' +import * as process from 'node:process' -import { type ExecResult, type IBuildAgent } from '@agents/common' +import { type IBuildAgent } from '@agents/common' import { type IRunner } from '@tools/common' type CliArgs = { @@ -32,7 +33,14 @@ export function parseCliArgs(): CliArgs { }).values as CliArgs } -export async function run(agent: string, tool: string, command: string): Promise { +export async function run(agent: string, tool: string, command: string): Promise { const runner = await getToolRunner(agent, tool) - return await runner.run(command) + const { code, stdout, stderr } = await runner.run(command) + if (stdout) { + process.stdout.write(stdout) + } + if (stderr) { + process.stderr.write(stderr) + } + process.exit(code) }