-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #130 from sliit-foss/feature/timekeeper
Added initial version of timekeeper cli
- Loading branch information
Showing
15 changed files
with
1,097 additions
and
849 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{ | ||
"name": "@sliit-foss/timekeeper", | ||
"version": "0.0.0", | ||
"description": "CLI tool for automated function tracing", | ||
"main": "dist/index.js", | ||
"bin": "dist/index.js", | ||
"scripts": { | ||
"build": "node ../../scripts/esbuild.config.js", | ||
"build:watch": "bash ../../scripts/esbuild.watch.sh", | ||
"bump-version": "bash ../../scripts/bump-version.sh", | ||
"lint": "bash ../../scripts/lint.sh", | ||
"release": "bash ../../scripts/release.sh", | ||
"test": "rimraf ./babel.config.js && dotenv -- jest --coverage --verbose --runInBand --forceExit" | ||
}, | ||
"dependencies": { | ||
"@babel/cli": "7.23.4", | ||
"@babel/core": "7.23.6", | ||
"@babel/preset-env": "7.23.6", | ||
"@colors/colors": "1.5.0", | ||
"@sliit-foss/babel-plugin-transform-trace": "workspace:*", | ||
"@sliit-foss/functions": "workspace:*", | ||
"commander": "11.1.0" | ||
}, | ||
"author": "SLIIT FOSS", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sliit-foss/npm-catalogue.git" | ||
}, | ||
"homepage": "https://github.com/sliit-foss/npm-catalogue/blob/main/packages/timekeeper/readme.md", | ||
"keywords": [ | ||
"tracing", | ||
"automated-tracing" | ||
], | ||
"bugs": { | ||
"url": "https://github.com/sliit-foss/npm-catalogue/issues" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# @sliit-foss/timekeeper | ||
|
||
### CLI tool for automated function tracing. More information can be found [here](https://timekeeper.sliitfoss.org/) at the official website. | ||
|
||
<br/> | ||
|
||
--- | ||
|
||
## Installation | ||
|
||
```bash | ||
# using npm | ||
npm install -g @sliit-foss/timekeeper | ||
|
||
# using yarn | ||
yarn global add @sliit-foss/timekeeper | ||
``` | ||
|
||
## Usage | ||
|
||
> script.js | ||
```js | ||
const sum = (a, b) => { | ||
return a + b; | ||
}; | ||
|
||
console.log(sum(4, 5)); | ||
``` | ||
|
||
> execute | ||
```bash | ||
timekeeper script.js | ||
``` | ||
|
||
> output | ||
```bash | ||
{"correlationId": "34fedb32f80e6ac4cd329a948e5ac2cc", "level": "info", "message": "[tracer] - sum execution initiated", "timestamp": "2023-05-25T04:25:52.180Z"} | ||
{"correlationId": "34fedb32f80e6ac4cd329a948e5ac2cc", "level": "info", "message": "[tracer] - sum execution completed - execution_time : 0.05579999997280538ms", "timestamp": "2023-05-25T04:25:52.180Z"} | ||
9 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env node | ||
|
||
/* eslint-disable no-console */ | ||
|
||
import { program } from "commander"; | ||
import { version } from "../package.json"; | ||
import { default as run } from "./runner"; | ||
|
||
require("@colors/colors"); | ||
|
||
program.name("timekeeper").description("CLI tool for automated function tracing").version(version); | ||
|
||
program | ||
.option("--ignore-functions <string>", "comma separated list of functions to skip tracing") | ||
.option("--clean", "skip tracing of anonymous functions") | ||
.option("--live-reload", "live reload the script when it changes") | ||
.arguments("<path>", "path to the script to trace") | ||
.action(run) | ||
.parse(process.argv); | ||
|
||
export default run; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* eslint-disable no-console */ | ||
|
||
import { default as fs } from "fs"; | ||
import { default as path } from "path"; | ||
import { default as util } from "util"; | ||
|
||
const exec = util.promisify(require("child_process").exec); | ||
|
||
const config = { | ||
presets: ["@babel/preset-env"], | ||
plugins: [["@sliit-foss/babel-plugin-transform-trace"]] | ||
}; | ||
|
||
const runner = async (p, options) => { | ||
config.plugins[0].push({ | ||
"ignore-functions": options.ignoreFunctions?.split(",") ?? [], | ||
clean: options.clean ?? false | ||
}); | ||
|
||
fs.writeFileSync("./babel.config.js", `module.exports = ${JSON.stringify(config)}`); | ||
|
||
console.info(`[Timekeeper] transpiling...`.green); | ||
|
||
await exec(`bash -c "node_modules/.bin/babel ${p} --out-dir ./out --copy-files --config-file=./babel.config.js"`); | ||
|
||
console.info(`[Timekeeper] executing...`.green); | ||
|
||
await exec(`bash -c "node out/${path.basename(p)}"`).then(({ stdout, stderr }) => { | ||
if (stdout) console.log(stdout); | ||
if (stderr) console.error(stderr.red); | ||
}); | ||
}; | ||
|
||
export default runner; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe("timekeeper", () => { | ||
it("should work", () => { | ||
expect(true).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.