From a4fdedfcac02cb53608d9d3b9e96de0526140fd7 Mon Sep 17 00:00:00 2001 From: Kevin J Hoerr Date: Sun, 10 Nov 2019 14:34:18 -0500 Subject: Move TS files into /src --- formats.ts | 33 --------------------- index.ts | 91 --------------------------------------------------------- metadata.ts | 3 -- src/formats.ts | 33 +++++++++++++++++++++ src/index.ts | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/metadata.ts | 3 ++ tsconfig.json | 2 +- 7 files changed, 128 insertions(+), 128 deletions(-) delete mode 100644 formats.ts delete mode 100644 index.ts delete mode 100644 metadata.ts create mode 100644 src/formats.ts create mode 100644 src/index.ts create mode 100644 src/metadata.ts diff --git a/formats.ts b/formats.ts deleted file mode 100644 index b5a24bf..0000000 --- a/formats.ts +++ /dev/null @@ -1,33 +0,0 @@ -interface Format { - parse_coverage: (file: Document) => number; -} - -interface FormatList { - [key: string]: Format -} - -interface FormatObj { - formats: FormatList, - list_formats: () => string[], - get_format: (format: string) => Format, -} - -const FormatsObj: FormatObj = { - formats: { - tarpaulin: { - parse_coverage: (file: Document) => { - return 0.0; - } - }, - }, - - list_formats: function () { - return Object.keys(this.formats); - }, - - get_format: function (format: string) { - return this.formats[format]; - } -} - -export default FormatsObj; \ No newline at end of file diff --git a/index.ts b/index.ts deleted file mode 100644 index 5e54c84..0000000 --- a/index.ts +++ /dev/null @@ -1,91 +0,0 @@ -import dotenv from 'dotenv'; -import express from 'express'; -import badgen from 'badgen'; -import path from 'path'; -import fs from 'fs'; - -import formats from './formats'; -import metadata from './metadata'; - -// Start-up configuration -dotenv.config(); -const PORT = process.env.PORT ? Number(process.env.PORT) : 3000; -const TOKEN = process.env.TOKEN || ""; -const HOST_DIR = process.env.HOST_DIR || (() => { - throw Error("HOST_DIR must be defined"); -})(); - -const app: express.Application = express(); - -// serve script for posting coverage report -app.use('/bash', express.static(path.join(__dirname, '..', 'public', 'bash'))); - -// Upload HTML file -app.post('/v1/:org/:repo/:branch/:commit.html', (req, res) => { - - const {org, repo, branch, commit} = req.params; - console.info("POST request to /v1/%s/%s/%s/%s.html", org, repo, branch, commit); - - const {token, format} = req.query; - if (token != TOKEN) { - return res.status(401).send(); - } - - const reporter = format || "tarpaulin"; - if (!formats.list_formats().includes(reporter)) { - return res.status(406).send(); - } - - return res.status(501).send(); - - //TODO acquire file, verify file size/content type (HTML) - const contents = ""; - //req.on('data', (raw) => {}); - //req.on('end', () => {}); - - // const doc = new DOMParser().parseFromString(contents, "text/html"); - // const coverage = formats.get_format(reporter).parse_coverage(doc); - //TODO create badge for coverage % - //TODO store coverage % badge at %HOST_DIR%/%org%/%repo%/%commit%/badge.svg - //TODO store uploaded file at %HOST_DIR%/%org%/%repo%/%commit%/index.html - - //TODO set branch alias for coverage % / uploaded file -}); - -app.get('/v1/:org/:repo/:branch.svg', (req, res) => { - const {org, repo, branch} = req.params; - console.info("GET request to /v1/%s/%s/%s.svg", org, repo, branch); - - //TODO link the badge via metadata - return res.status(501).send(); -}); - -app.get('/v1/:org/:repo/:branch.html', (req, res) => { - const {org, repo, branch} = req.params; - console.info("GET request to /v1/%s/%s/%s.html", org, repo, branch); - - //TODO link the file via metadata - return res.status(501).send(); -}); - -// provide hard link for commit -app.get('/v1/:org/:repo/:branch/:commit.svg', (req, res) => { - const {org, repo, branch, commit} = req.params; - console.info("GET request to /v1/%s/%s/%s/%s.svg", org, repo, branch, commit); - - //TODO link the badge - return res.status(501).send(); -}); - -// provide hard link for commit -app.get('/v1/:org/:repo/:branch/:commit.html', (req, res) => { - const {org, repo, branch, commit} = req.params; - console.info("GET request to /v1/%s/%s/%s/%s.html", org, repo, branch, commit); - - //TODO link the file - return res.status(501).send(); -}); - -app.listen(PORT, () => { - console.log('Express started on port ' + PORT); -}); diff --git a/metadata.ts b/metadata.ts deleted file mode 100644 index 353d9bf..0000000 --- a/metadata.ts +++ /dev/null @@ -1,3 +0,0 @@ -const metadata = {}; - -export default metadata; \ No newline at end of file diff --git a/src/formats.ts b/src/formats.ts new file mode 100644 index 0000000..b5a24bf --- /dev/null +++ b/src/formats.ts @@ -0,0 +1,33 @@ +interface Format { + parse_coverage: (file: Document) => number; +} + +interface FormatList { + [key: string]: Format +} + +interface FormatObj { + formats: FormatList, + list_formats: () => string[], + get_format: (format: string) => Format, +} + +const FormatsObj: FormatObj = { + formats: { + tarpaulin: { + parse_coverage: (file: Document) => { + return 0.0; + } + }, + }, + + list_formats: function () { + return Object.keys(this.formats); + }, + + get_format: function (format: string) { + return this.formats[format]; + } +} + +export default FormatsObj; \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..5e54c84 --- /dev/null +++ b/src/index.ts @@ -0,0 +1,91 @@ +import dotenv from 'dotenv'; +import express from 'express'; +import badgen from 'badgen'; +import path from 'path'; +import fs from 'fs'; + +import formats from './formats'; +import metadata from './metadata'; + +// Start-up configuration +dotenv.config(); +const PORT = process.env.PORT ? Number(process.env.PORT) : 3000; +const TOKEN = process.env.TOKEN || ""; +const HOST_DIR = process.env.HOST_DIR || (() => { + throw Error("HOST_DIR must be defined"); +})(); + +const app: express.Application = express(); + +// serve script for posting coverage report +app.use('/bash', express.static(path.join(__dirname, '..', 'public', 'bash'))); + +// Upload HTML file +app.post('/v1/:org/:repo/:branch/:commit.html', (req, res) => { + + const {org, repo, branch, commit} = req.params; + console.info("POST request to /v1/%s/%s/%s/%s.html", org, repo, branch, commit); + + const {token, format} = req.query; + if (token != TOKEN) { + return res.status(401).send(); + } + + const reporter = format || "tarpaulin"; + if (!formats.list_formats().includes(reporter)) { + return res.status(406).send(); + } + + return res.status(501).send(); + + //TODO acquire file, verify file size/content type (HTML) + const contents = ""; + //req.on('data', (raw) => {}); + //req.on('end', () => {}); + + // const doc = new DOMParser().parseFromString(contents, "text/html"); + // const coverage = formats.get_format(reporter).parse_coverage(doc); + //TODO create badge for coverage % + //TODO store coverage % badge at %HOST_DIR%/%org%/%repo%/%commit%/badge.svg + //TODO store uploaded file at %HOST_DIR%/%org%/%repo%/%commit%/index.html + + //TODO set branch alias for coverage % / uploaded file +}); + +app.get('/v1/:org/:repo/:branch.svg', (req, res) => { + const {org, repo, branch} = req.params; + console.info("GET request to /v1/%s/%s/%s.svg", org, repo, branch); + + //TODO link the badge via metadata + return res.status(501).send(); +}); + +app.get('/v1/:org/:repo/:branch.html', (req, res) => { + const {org, repo, branch} = req.params; + console.info("GET request to /v1/%s/%s/%s.html", org, repo, branch); + + //TODO link the file via metadata + return res.status(501).send(); +}); + +// provide hard link for commit +app.get('/v1/:org/:repo/:branch/:commit.svg', (req, res) => { + const {org, repo, branch, commit} = req.params; + console.info("GET request to /v1/%s/%s/%s/%s.svg", org, repo, branch, commit); + + //TODO link the badge + return res.status(501).send(); +}); + +// provide hard link for commit +app.get('/v1/:org/:repo/:branch/:commit.html', (req, res) => { + const {org, repo, branch, commit} = req.params; + console.info("GET request to /v1/%s/%s/%s/%s.html", org, repo, branch, commit); + + //TODO link the file + return res.status(501).send(); +}); + +app.listen(PORT, () => { + console.log('Express started on port ' + PORT); +}); diff --git a/src/metadata.ts b/src/metadata.ts new file mode 100644 index 0000000..353d9bf --- /dev/null +++ b/src/metadata.ts @@ -0,0 +1,3 @@ +const metadata = {}; + +export default metadata; \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json index ce03ebf..2d4594b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,7 +13,7 @@ // "sourceMap": true, /* Generates corresponding '.map' file. */ // "outFile": "./", /* Concatenate and emit output to single file. */ "outDir": "./build/", /* Redirect output structure to the directory. */ - // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + "rootDir": "./src/", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ // "composite": true, /* Enable project compilation */ // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ // "removeComments": true, /* Do not emit comments to output. */ -- cgit