diff --git a/tools/canyon-uploader/package.json b/tools/canyon-uploader/package.json index f87a2f82..82f2e29a 100644 --- a/tools/canyon-uploader/package.json +++ b/tools/canyon-uploader/package.json @@ -1,6 +1,6 @@ { "name": "canyon-uploader", - "version": "0.0.1-beta.2", + "version": "0.0.1-beta.3", "files": [ "bin", "dist" @@ -20,7 +20,10 @@ "rolldown": "nightly" }, "dependencies": { + "axios": "^1.7.7", + "body-parser": "^1.20.3", "chalk": "^5.3.0", - "commander": "^12.1.0" + "commander": "^12.1.0", + "express": "^4.21.1" } } diff --git a/tools/canyon-uploader/src/commands/hit.ts b/tools/canyon-uploader/src/commands/hit.ts index a4f41e63..2700d72a 100644 --- a/tools/canyon-uploader/src/commands/hit.ts +++ b/tools/canyon-uploader/src/commands/hit.ts @@ -1,3 +1,20 @@ +import fs from "node:fs"; +import path from "node:path"; +import * as process from "node:process"; +import axios from "axios"; export async function hitCommand(params, options) { - console.log("hitCommand", "aasaaaaa"); + const files = fs.readdirSync(path.resolve(process.cwd(), ".canyon_output")); + let data = {}; + for (let i = 0; i < files.length; i++) { + const fileCoverageString = fs.readFileSync( + path.resolve(process.cwd(), ".canyon_output", files[i]), + "utf-8", + ); + data = { + ...data, + ...JSON.parse(fileCoverageString), + }; + } + + await axios.post("http://localhost:3000/upload", data, {}); } diff --git a/tools/canyon-uploader/src/main.ts b/tools/canyon-uploader/src/main.ts index 1e08906e..cbd4d396 100644 --- a/tools/canyon-uploader/src/main.ts +++ b/tools/canyon-uploader/src/main.ts @@ -76,6 +76,6 @@ export const cli = async (args: string[]) => { try { await program.parseAsync(args); } catch (e) { - console.error(e); - } + console.error(e); + } }; diff --git a/tools/canyon-uploader/test-server.js b/tools/canyon-uploader/test-server.js new file mode 100644 index 00000000..f76210eb --- /dev/null +++ b/tools/canyon-uploader/test-server.js @@ -0,0 +1,15 @@ +const express = require('express'); +const app = express(); +const bodyParser = require('body-parser'); + +app.use(bodyParser.json()); +// app.use(express.static('public')); + +app.post('/upload', (req, res) => { + console.log(req.body) + res.send('File uploaded!'); +}); + +app.listen(3000, () => { + console.log('Server is running on http://localhost:3000'); +});