Skip to content

Commit

Permalink
Merge branch 'main' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
Akalanka47000 committed Mar 2, 2024
2 parents e716270 + 7d15964 commit cb0710a
Show file tree
Hide file tree
Showing 27 changed files with 190 additions and 93 deletions.
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.2",
"version": "2.3.2",
"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
26 changes: 17 additions & 9 deletions packages/automatic-versioning/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ yarn bump-version
## Commit message prefixes and associated version bumping

```bash
- Feat! - bump major version
- Feature! | Feat! | Fix! | Patch! - bump major version
```

```bash
- Feat - bump minor version
- Feature | Feat - bump minor version
```

```bash
- Fix - bump patch version
- Fix | Patch - bump patch version
```

## Skip commit <br/>
Expand Down Expand Up @@ -119,12 +119,6 @@ yarn bump-version
npx automatic-versioning --name=<package_name> --recursive
```

## Custom prerelease tag<br/>

```bash
npx automatic-versioning --name=<package_name> --prerelease-tag=<name>
```

## Prerelease branch<br/>

- If this option is specified and the current branch matches it, the versioning will be evaluated as follows <br/>
Expand All @@ -137,6 +131,20 @@ yarn bump-version
npx automatic-versioning --name=<package_name> --prerelease-branch=<branch_name>
```

## Prerelease<br/>

- If this is specified, the versioning will always be one of prerelease, premajor, preminor or prepatch depending on the above commit mapping

```bash
npx automatic-versioning --name=<package_name> --prerelease
```

## Custom prerelease tag<br/>

```bash
npx automatic-versioning --name=<package_name> --prerelease-tag=<name>
```

## Ignore prefixes<br/>

- A list of comma separated prefixes to ignore when evaluating the commit message. By default we stop searching for commits once we come across any prefix considered by commitlint as valid prefixes. You can use this option to ignore a few of them if the need arises<br/>
Expand Down
8 changes: 6 additions & 2 deletions packages/automatic-versioning/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ program
)
.option("-r, --root <string>", "root directory to use when executing the script")
.option("--skip-commit", "do not commit the incremented version")
.option("--tag-based", "run versioning based on git tags");
.option("--tag-based", "run versioning based on git tags")
.option("--disable-auto-sync", "disable aligning the package version with the last published version");

[
new Option("--recursive", "recursively search for a matching commit prefix"),
new Option("--prerelease <boolean>", "run a prerelase version bump"),
new Option("--prerelease-tag <string>", "prerelease identifier to use when creating a prerelease"),
new Option("--prerelease-branch <string>", "run prereleases on this branch"),
new Option("--prerelease-branch <string>", "run prereleases on this branch. This is useful for CI/CD workflows"),
new Option(
"--ignore-prefixes <string>",
"comma separated list of commit prefixes to ignore when searching for a matching prefix"
Expand Down Expand Up @@ -54,6 +56,8 @@ const run = async () => {
opts.name,
opts.skipCommit,
opts.recursive,
opts.disableAutoSync,
opts.prerelease,
opts.prereleaseTag,
opts.prereleaseBranch,
opts.ignorePrefixes
Expand Down
70 changes: 47 additions & 23 deletions packages/automatic-versioning/src/types/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,48 @@ const getCommitPrefix = async (recursive, ignorePrefixes, n = 1) => {
return getCommitPrefix(recursive, ignorePrefixes, n + 1);
};

const runner = (name, noCommit, recursive = false, prereleaseTag, prereleaseBranch, ignorePrefixes) => {
const getCurrentVersion = async () =>
(await run("npm version"))?.split(",")?.[0]?.split(":")?.[1]?.replace(/'/g, "")?.trim();

const getPackageVersion = async (name, disableAutoSync) => {
if (!disableAutoSync) {
try {
const versions = await run(`npm view ${name} time`).then((res) =>
res
.replace(/{|}|,|'/g, "")
.trim()
.split("\n")
.filter((v) => !v.includes("modified:") && !v.includes("created:"))
);
versions.sort(
(v1, v2) => new Date(v1.trim().split(" ")[1]).getTime() - new Date(v2.trim().split(" ")[1]).getTime()
);
return versions.pop().split(":")?.[0].trim();
} catch (e) {
return getCurrentVersion();
}
} else {
return getCurrentVersion();
}
};

const runner = (
name,
noCommit,
recursive = false,
disableAutoSync,
prerelease,
prereleaseTag,
prereleaseBranch,
ignorePrefixes
) => {
return run("git show --first-parent ./").then(async (diff) => {
if (diff) {
console.info(`Diff found, running versioning for ${name}`.green);
const { commitMessage, commitPrefix, noBump } = await getCommitPrefix(recursive, ignorePrefixes);
if (!noBump) {
let versionUpdate;
if (["feature!", "feat!", "f!"].includes(commitPrefix)) {
if (["feature!", "feat!", "f!", "fix!", "patch!"].includes(commitPrefix)) {
versionUpdate = "major";
} else if (["feature", "feat", "f"].includes(commitPrefix)) {
versionUpdate = "minor";
Expand All @@ -38,26 +72,14 @@ const runner = (name, noCommit, recursive = false, prereleaseTag, prereleaseBran
console.info(`No suitable commit prefix found in commit message, skipping version bump`.yellow);
return;
}
if (prereleaseBranch && ["major", "minor", "patch"].includes(versionUpdate)) {
const currentBranch = (await run("git rev-parse --abbrev-ref HEAD"))?.trim();
if (currentBranch === prereleaseBranch) {
let prerelease = false;
let currentVersion;
try {
const versions = await run(`npm view ${name} time`).then((res) =>
res
.replace(/{|}|,|'/g, "")
.trim()
.split("\n")
.filter((v) => !v.includes("modified:") && !v.includes("created:"))
);
versions.sort(
(v1, v2) => new Date(v1.trim().split(" ")[1]).getTime() - new Date(v2.trim().split(" ")[1]).getTime()
);
currentVersion = versions.pop().split(":")?.[0].trim();
} catch (e) {
currentVersion = (await run("npm version"))?.split(",")?.[0]?.split(":")?.[1]?.replace(/'/g, "")?.trim();
}
if ((prerelease || prereleaseBranch) && ["major", "minor", "patch"].includes(versionUpdate)) {
if (!prerelease) {
const currentBranch = (await run("git rev-parse --abbrev-ref HEAD"))?.trim();
prerelease = currentBranch === prereleaseBranch;
}
if (prerelease) {
prerelease = false;
const currentVersion = await getPackageVersion(name, disableAutoSync);
if (currentVersion?.includes(prereleaseTag)) {
await run(
`npm --workspaces-update=false --no-git-tag-version version --allow-same-version ${currentVersion}`
Expand All @@ -84,7 +106,9 @@ const runner = (name, noCommit, recursive = false, prereleaseTag, prereleaseBran
versionUpdate === "prerelease" ? versionUpdate : `${versionUpdate} release`
}"`;
await run("git add .").then(async () => {
await run(`git commit -m ${successMsg} --no-verify`).then(() => console.info(successMsg.green));
await run(`git commit -m ${successMsg} --trailer "skip-checks:true" --no-verify`).then(() =>
console.info(successMsg.green)
);
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/automatic-versioning/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const commit = async (message, empty) => {
await run(`git commit -m "${message}" ${empty ? "--allow-empty" : ""}`);
};

export const getLastCommitMessage = async () => (await run("git log -1 --pretty=%B"))?.trim();
export const getLastCommitMessage = async () => (await run("git log -1 --pretty=%B"))?.split("\n")?.[0]?.trim();

export const getCurrentBranch = async () => (await run("git rev-parse --abbrev-ref HEAD"))?.trim();

Expand Down
2 changes: 1 addition & 1 deletion packages/express-http-context/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sliit-foss/express-http-context",
"version": "1.0.0-blizzard.0",
"version": "1.1.1",
"description": "A rework of the express-http-context package to use the new async_hooks API",
"main": "dist/index.js",
"browser": "dist/browser.js",
Expand Down
5 changes: 5 additions & 0 deletions packages/express-http-context/src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export const middleware = (req, res, next) => {
throw new Error("`middleware` cannot be called from the browser code.");
};

export const isolate = (fn) => {
throw new Error("`isolate` cannot be called from the browser code.");
};

export const get = () => null;

export const set = (key, value) => {};
Expand All @@ -14,6 +18,7 @@ export const ns = null;

export default {
middleware,
isolate,
get,
set,
store: null,
Expand Down
16 changes: 10 additions & 6 deletions packages/express-http-context/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ export const store = new AsyncLocalStorage();

/** Express.js middleware that is responsible for initializing the context for each request. */
export const middleware = (req, res, next) => {
store.run({}, () => {
next();
});
store.run({}, next);
};

/** Runs a given function in an isolated context */
export const isolate = (fn) => {
store.run({}, fn);
};

/**
Expand All @@ -35,8 +38,9 @@ export const ns = null;

export default {
middleware,
get: get,
set: set,
store: store,
isolate,
get,
set,
store,
ns: null
};
3 changes: 3 additions & 0 deletions packages/express-http-context/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import { AsyncLocalStorage } from "async_hooks";
/** Express.js middleware that is responsible for initializing the context for each request. */
export declare function middleware(req: Request, res: Response, next: NextFunction): void;

/** Runs a given function in an isolated context */
export declare function isolate(fn: Function): void;

/**
* Gets a value from the context by key. Will return undefined if the context has not yet been initialized for this request or if a value is not found for the specified key.
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/functions/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sliit-foss/functions",
"version": "2.6.0",
"version": "2.7.1",
"description": "Just a small set of utility functions",
"main": "dist/index.js",
"types": "types/index.d.ts",
Expand All @@ -13,7 +13,7 @@
"test": "bash ../../scripts/test/test.sh"
},
"dependencies": {
"@sliit-foss/module-logger": "1.2.4",
"@sliit-foss/module-logger": "1.3.1",
"chalk": "4.1.2",
"express-http-context": "1.2.4"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/http-logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sliit-foss/http-logger",
"version": "1.2.2",
"version": "1.3.1",
"description": "Http logging middleware for Express.js",
"main": "dist/index.js",
"scripts": {
Expand All @@ -12,7 +12,7 @@
"test": "bash ../../scripts/test/test.sh"
},
"dependencies": {
"@sliit-foss/module-logger": "1.2.4"
"@sliit-foss/module-logger": "1.3.1"
},
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/module-logger/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@sliit-foss/module-logger",
"version": "1.2.5",
"version": "1.3.1",
"description": "A modularized logger wrapped around winston to make working with nodeJS microservices easier.",
"main": "dist/index.js",
"types": "types/index.d.ts",
Expand Down
3 changes: 2 additions & 1 deletion packages/module-logger/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ logger.info("This is a modularized info log written to a file");
},
},
transportOverrides: [], // array of transport overrides
globalAttributes: {}, // attributes which will be added to all logs
globalAttributes: {}, // attributes which will be added to all logs,
traceKey: "correlationId", // key to be used for tracing
}
```
13 changes: 7 additions & 6 deletions packages/module-logger/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ let _defaultConfig = {
enabled: false,
options: {}
},
globalAttributes: {}
globalAttributes: {},
traceKey: "correlationId"
};

const _defaultKeys = ["level", "correlationId", "timestamp", "message"];

const _createLogger = () => {
let transports = [];

const _defaultKeys = ["level", _defaultConfig.traceKey, "timestamp", "message"];

if (_defaultConfig.console?.enabled) {
transports.push(
new winston.transports.Console({
Expand Down Expand Up @@ -54,12 +55,12 @@ const _createLogger = () => {
_logger = winston.createLogger({
format: winston.format.combine(
winston.format((infoObj) => {
let correlationId = context.get("correlationId");
let correlationId = context.get(_defaultConfig.traceKey);
if (!correlationId) {
correlationId = crypto.randomBytes(16).toString("hex");
context.set("correlationId", correlationId);
context.set(_defaultConfig.traceKey, correlationId);
}
infoObj["correlationId"] = chalk.blue(correlationId);
infoObj[_defaultConfig.traceKey] = chalk.blue(correlationId);
return { ...infoObj, ...(_defaultConfig.globalAttributes ?? {}) };
})(),
winston.format.timestamp(),
Expand Down
1 change: 1 addition & 0 deletions packages/module-logger/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ declare interface Config {
options?: any;
};
globalAttributes?: any;
traceKey?: string;
}

/**
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",
"version": "4.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/mongoose-filter-query/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const mongooseFilterQuery = (req, res, next) => {
} else {
req.query.sort = {};
}
req.query.include = req.query.include?.split(",") ?? [];
req.query.select = req.query.select?.split(",")?.join(" ") ?? "";
req.query.include = req.query.include?.split(",");
req.query.select = req.query.select?.split(",")?.join(" ");
} catch (e) {
console.error("[ FilterQuery ] - Failed to parse query", e);
}
Expand Down
9 changes: 8 additions & 1 deletion packages/mongoose-filter-query/src/utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
export const replaceOperator = (value, operator) => {
value = value.replace(`${operator}(`, "").slice(0, -1);
return isNaN(value) ? value : Number(value);
if (isNaN(value)) {
if (!isNaN(Date.parse(value))) {
value = new Date(value);
}
} else {
value = Number(value);
}
return value;
};

export const mapValue = (value) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mongoose-filter-query/test/__mocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const basicFilterResult = {
address: { $in: ["address1", "address2", "address3"] },
weight: { $gte: 50 },
height: { $lt: 180 },
birthdate: { $lte: "2000-01-01" },
birthdate: { $lte: new Date("2000-01-01") },
isAlive: { $exists: true },
isVerified: { $eq: true },
isDeleted: "false"
Expand Down
Loading

0 comments on commit cb0710a

Please sign in to comment.