Skip to content

Commit

Permalink
feat: update scripts and build system (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsaz authored Aug 1, 2024
1 parent 61556dc commit ac38096
Show file tree
Hide file tree
Showing 10 changed files with 282 additions and 184 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Regular folders
dist/
node_modules/
lib

# Ignore lock files
*-lock.json
Expand Down
Empty file added CHANGELOG.md
Empty file.
118 changes: 111 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@
"name": "@expressots/boost-ts",
"version": "1.2.0",
"description": "Expressots: Boost is a collection of libraries for the TypeScript programming language designed to enhance its capabilities across various domains. (@boost-ts)",
"types": "./dist/index.d.ts",
"main": "./lib/cjs/index.js",
"types": "./lib/cjs/types/index.d.ts",
"exports": {
".": {
"import": {
"types": "./lib/esm/types/index.d.ts",
"default": "./lib/esm/index.mjs"
},
"require": {
"types": "./lib/cjs/types/index.d.ts",
"default": "./lib/cjs/index.js"
}
}
},
"files": [
"lib/**/*"
],
"license": "MIT",
"keywords": [],
"keywords": [
"pattern-matching",
"text-utils",
"expressots"
],
"repository": {
"type": "git",
"url": "git+https://github.com/expressots/boost-ts.git"
Expand All @@ -17,21 +37,105 @@
},
"author": "Richard Zampieri",
"scripts": {
"start": "tsnd --respawn --transpile-only --ignore-watch node_modules src/main.ts",
"build": "rimraf dist && tsc -p tsconfig.json",
"build:prod": "npm run build && node dist/main.js",
"prepare": "husky",
"clean": "node scripts/rm.js lib",
"copy": "node scripts/copy.js package.json README.md CHANGELOG.md lib",
"build": "npm run clean && npm run build:cjs && npm run copy",
"build:cjs": "tsc -p tsconfig.cjs.json",
"release": "release-it",
"prepublish": "npm run build && npm pack",
"test": "jest"
"publish": "npm publish --tag latest",
"test": "vitest run --reporter default",
"test:watch": "vitest run --watch",
"coverage": "vitest run --coverage",
"format": "prettier --write \"src/**/*.ts\" --cache",
"lint": "eslint \"src/**/*.ts\"",
"lint:fix": "eslint \"src/**/*.ts\" --fix"
},
"devDependencies": {
"@swc/core": "1.3.37",
"@swc/jest": "0.2.24",
"@types/jest": "29.5.0",
"jest": "29.5.0",
"ts-node-dev": "2.0.0",
"typescript": "5.0.2"
"@codecov/vite-plugin": "0.0.1-beta.6",
"@commitlint/cli": "19.2.1",
"@commitlint/config-conventional": "19.2.2",
"@expressots/core": "2.15.0",
"@release-it/conventional-changelog": "8.0.1",
"@types/express": "4.17.21",
"@types/node": "20.14.10",
"@typescript-eslint/eslint-plugin": "7.16.1",
"@typescript-eslint/parser": "7.16.1",
"@vitest/coverage-v8": "2.0.3",
"eslint": "8.57.0",
"eslint-config-prettier": "9.1.0",
"husky": "9.1.1",
"prettier": "3.3.3",
"release-it": "17.6.0",
"typescript": "5.5.3",
"vite": "5.3.4",
"vite-tsconfig-paths": "4.3.2",
"vitest": "2.0.3"
},
"dependencies": {
"rimraf": "6.0.1"
},
"release-it": {
"git": {
"commitMessage": "chore(release): ${version}"
},
"github": {
"release": true
},
"npm": {
"publish": false
},
"plugins": {
"@release-it/conventional-changelog": {
"infile": "CHANGELOG.md",
"preset": {
"name": "conventionalcommits",
"types": [
{
"type": "feat",
"section": "Features"
},
{
"type": "fix",
"section": "Bug Fixes"
},
{
"type": "perf",
"section": "Performance Improvements"
},
{
"type": "revert",
"section": "Reverts"
},
{
"type": "docs",
"section": "Documentation"
},
{
"type": "refactor",
"section": "Code Refactoring"
},
{
"type": "test",
"section": "Tests"
},
{
"type": "build",
"section": "Build System"
},
{
"type": "ci",
"section": "Continuous Integrations"
}
]
}
}
}
}
}
30 changes: 30 additions & 0 deletions scripts/copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const fs = require("fs");
const path = require("path");

function copyRecursiveSync(src, dest) {
const exists = fs.existsSync(src);
const stats = exists && fs.statSync(src);
const isDirectory = exists && stats.isDirectory();

if (isDirectory) {
fs.mkdirSync(dest);
fs.readdirSync(src).forEach(function (childItemName) {
copyRecursiveSync(path.join(src, childItemName), path.join(dest, childItemName));
});
} else {
fs.copyFileSync(src, dest);
}
}

if (process.argv.length < 4) {
process.stderr.write("Usage: node copy.js <origin1> <origin2> ... <destination>\n");
process.exit(1);
}

const destination = process.argv[process.argv.length - 1];

for (let i = 2; i < process.argv.length - 1; i++) {
const origin = process.argv[i];
copyRecursiveSync(origin, path.join(destination, path.basename(origin)));
process.stdout.write(`Copied: ${origin} to ${destination}\n`);
}
28 changes: 28 additions & 0 deletions scripts/mv.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const fs = require("fs").promises;

const moveFile = async (origin, destination) => {
try {
await fs.access(origin);
} catch (error) {
process.stderr.write(`Error: Origin '${origin}' not found\n`);
process.exit(1);
}

try {
await fs.rename(origin, destination);
process.stdout.write(`Move: ${origin} to ${destination}\n`);
} catch (error) {
process.stderr.write(`Error: Unable to move '${origin}' to '${destination}'\n`);
process.exit(1);
}
};

if (process.argv.length !== 4) {
process.stderr.write("Usage: node mv.js <origin> <destination>\n");
process.exit(1);
}

const origin = process.argv[2];
const destination = process.argv[3];

moveFile(origin, destination);
19 changes: 19 additions & 0 deletions scripts/rm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const fs = require("fs").promises;

const removeTarget = async (target) => {
try {
await fs.rm(target, { recursive: true, force: true });
process.stdout.write(`Removed: ${target}\n`);
} catch (error) {
process.stderr.write(`Error: Unable to remove '${target}'\n`);
process.exit(1);
}
};

if (process.argv.length !== 3) {
process.stderr.write("Usage: node rm.js <dir/file>\n");
process.exit(1);
}

const target = process.argv[2];
removeTarget(target);
90 changes: 46 additions & 44 deletions tests/match-pattern.test.ts
Original file line number Diff line number Diff line change
@@ -1,48 +1,50 @@
import { match } from '../src/match-pattern';
import { match } from "../src/match-pattern";
import { describe, test, expect } from "vitest";

describe('testing match pattern function', () => {
describe("testing match pattern function", () => {
const matchValidates = {
0: () => "this is 0",
99: () => "this is 99",
"11..=22": () => "this number is in between 11 and 22",
"/abc/": () => "this is a regex",
"2 | 3 | 5 | 8": () => "this number is a prime number",
false: () => "this is a boolean",
"a..=d": () => "this is a char",
"1..=13": () => "Between 1 and 13",
"25 | 50 | 100": () => "A bill",
"/[a-z]/": () => "A lowercase letter",
_: () => "default",
};

const matchValidates = {
0: () => "this is 0",
99: () => "this is 99",
"11..=22": () => "this number is in between 11 and 22",
"/abc/": () => "this is a regex",
"2 | 3 | 5 | 8": () => "this number is a prime number",
false: () => "this is a boolean",
"a..=d": () => "this is a char",
"1..=13": () => "Between 1 and 13",
"25 | 50 | 100": () => "A bill",
"/[a-z]/": () => "A lowercase letter",
"_": () => "default",
};
const enum Coin {
Penny,
Nickel,
Dime,
Quarter,
}

const enum Coin {
Penny,
Nickel,
Dime,
Quarter
}
test("match pattern - validates", () => {
expect(match(0, matchValidates)).toBe("this is 0");
expect(match(99, matchValidates)).toBe("this is 99");
expect(match(11, matchValidates)).toBe("this number is in between 11 and 22");
expect(match(/abc/, matchValidates)).toBe("this is a regex");
expect(match(false, matchValidates)).toBe("this is a boolean");
expect(match("a", matchValidates)).toBe("this is a char");
expect(match(5, matchValidates)).toBe("this number is a prime number");
expect(match(10, matchValidates)).toBe("Between 1 and 13");
expect(match(25, matchValidates)).toBe("A bill");
expect(match("z", matchValidates)).toBe("A lowercase letter");
expect(match("1", matchValidates)).toBe("default");
});

test('match pattern - validates', () => {
expect(match(0, matchValidates)).toBe("this is 0");
expect(match(99, matchValidates)).toBe("this is 99");
expect(match(11, matchValidates)).toBe("this number is in between 11 and 22");
expect(match(/abc/, matchValidates)).toBe("this is a regex");
expect(match(false, matchValidates)).toBe("this is a boolean");
expect(match("a", matchValidates)).toBe("this is a char");
expect(match(5, matchValidates)).toBe("this number is a prime number");
expect(match(10, matchValidates)).toBe("Between 1 and 13");
expect(match(25, matchValidates)).toBe("A bill");
expect(match("z", matchValidates)).toBe("A lowercase letter");
expect(match("1", matchValidates)).toBe("default");
});

test('match pattern - enum', () => {
expect(match(Coin.Dime, {
[Coin.Penny]: () => 1,
[Coin.Nickel]: () => 5,
[Coin.Dime]: () => 10,
[Coin.Quarter]: () => 25,
})).toBe(10);
});
});
test("match pattern - enum", () => {
expect(
match(Coin.Dime, {
[Coin.Penny]: () => 1,
[Coin.Nickel]: () => 5,
[Coin.Dime]: () => 10,
[Coin.Quarter]: () => 25,
})
).toBe(10);
});
});
37 changes: 20 additions & 17 deletions tests/optional-pattern.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { Some, None, Optional } from "../src/optional-pattern";
import { match } from '../src/match-pattern';
import { match } from "../src/match-pattern";
import { describe, test, expect } from "vitest";

describe("testing optional pattern function", () => {
const v1: Optional<number> = Some(1);
const v2: Optional<number> = None();

describe('testing optional pattern function', () => {
const v1: Optional<number> = Some(1);
const v2: Optional<number> = None();
test("optional pattern", () => {
expect(
match(v1, {
Some: (x) => x + 1,
None: 0,
})
).toBe(2);

test('optional pattern', () => {
expect(match(v1, {
Some: (x) => x + 1,
None: 0,
})).toBe(2);

expect(match(v2, {
Some: (x) => x + 1,
None: 0,
})).toBe(0);
})

})
expect(
match(v2, {
Some: (x) => x + 1,
None: 0,
})
).toBe(0);
});
});
10 changes: 10 additions & 0 deletions tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "ES2021",
"moduleResolution": "node",
"outDir": "lib/cjs",
"declarationDir": "lib/cjs/types"
}
}
Loading

0 comments on commit ac38096

Please sign in to comment.