Skip to content

Commit

Permalink
Merge pull request #130 from sliit-foss/feature/timekeeper
Browse files Browse the repository at this point in the history
Added initial version of timekeeper cli
  • Loading branch information
Akalanka47000 authored Dec 17, 2023
2 parents 095c9a5 + 150fa49 commit 1885fd9
Show file tree
Hide file tree
Showing 15 changed files with 1,097 additions and 849 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ yarn-error.log*

.vscode

packages/automatic-versioning/tmp
packages/automatic-versioning/
packages/timekeeper/babel.config.js

p*/**/dist/

Expand Down
2 changes: 2 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ module.exports = {
"Patch",
"Prerelease",
"Chore",
"Debug",
"Build",
"Refactor",
"Revert",
"Style",
"CI",
"Test",
"Docs",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"test": "dotenv -- turbo run test"
},
"dependencies": {
"@babel/core": "7.20.12",
"@babel/preset-env": "7.20.2",
"@babel/core": "7.23.6",
"@babel/preset-env": "7.23.6",
"@sliit-foss/automatic-versioning": "workspace:*",
"dotenv-cli": "7.0.0",
"esbuild": "0.17.5",
Expand Down
2 changes: 1 addition & 1 deletion packages/automatic-versioning/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sliit-foss/automatic-versioning",
"version": "2.0.1-blizzard.0",
"version": "2.0.1",
"description": "A script which will automatically increment your app package version in accordance with conventional commits",
"main": "dist/index.js",
"bin": "dist/index.js",
Expand Down
2 changes: 1 addition & 1 deletion packages/bashaway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"dependencies": {
"@sliit-foss/actions-exec-wrapper": "1.1.1",
"axios": "1.5.0",
"axios": "1.6.0",
"glob": "10.3.3"
},
"repository": {
Expand Down
4 changes: 2 additions & 2 deletions packages/leaderboard/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sliit-foss/leaderboard",
"version": "1.2.0",
"version": "1.2.1",
"description": "A utility package for fetching a list of contributor scores to a GitHub organization or repository",
"main": "dist/index.js",
"types": "types/index.d.ts",
Expand All @@ -13,7 +13,7 @@
"test": "bash ../../scripts/test/conditional-test/test.sh -k GITHUB_ACCESS_TOKEN"
},
"dependencies": {
"axios": "1.3.2"
"axios": "1.6.0"
},
"author": "SLIIT FOSS",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/mongoose-filter-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sliit-foss/mongoose-filter-query",
"version": "2.0.0-blizzard.0",
"version": "2.0.0",
"description": "Middleware which implements a standardized format and maps an incoming http request's query params to a format which is supported by mongoose",
"main": "dist/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions packages/service-connector/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sliit-foss/service-connector",
"version": "2.0.0",
"version": "2.0.1",
"description": "A package to isolate filters and sorts from a given request's query parameters",
"main": "dist/index.js",
"scripts": {
Expand All @@ -13,7 +13,7 @@
},
"dependencies": {
"@sliit-foss/module-logger": "1.1.5",
"axios": "1.3.2",
"axios": "1.6.0",
"express-http-context": "1.2.4",
"http-errors": "2.0.0"
},
Expand Down
38 changes: 38 additions & 0 deletions packages/timekeeper/package.json
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"
}
}
43 changes: 43 additions & 0 deletions packages/timekeeper/readme.md
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
```
21 changes: 21 additions & 0 deletions packages/timekeeper/src/index.js
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;
34 changes: 34 additions & 0 deletions packages/timekeeper/src/runner.js
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;
5 changes: 5 additions & 0 deletions packages/timekeeper/test/index.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe("timekeeper", () => {
it("should work", () => {
expect(true).toBe(true);
});
});
1 change: 1 addition & 0 deletions plugins/babel-plugin-transform-trace/src/exclusions.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default [
"defineProperty",
"defineProperties",
"doneResult",
"getOwnPropertyNames",
"getProto",
"getPrototypeOf",
"handle",
Expand Down
Loading

0 comments on commit 1885fd9

Please sign in to comment.