This commit is contained in:
Holly Stubbs 2023-07-28 12:18:56 +01:00
parent 0bebe14e2d
commit ad1d575d93
8 changed files with 2919 additions and 0 deletions

4
.gitignore vendored
View file

@ -1,3 +1,7 @@
# Build folder
lib/
combined.ts
# Logs # Logs
logs logs
*.log *.log

139
.npmignore Normal file
View file

@ -0,0 +1,139 @@
.github/*
enums/*
index.ts
combined.ts
readers/*
writers/*
tooling/*
tsconfig.json
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*
.pnpm-debug.log*
# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
# Runtime data
pids
*.pid
*.seed
*.pid.lock
# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov
# Coverage directory used by tools like istanbul
coverage
*.lcov
# nyc test coverage
.nyc_output
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt
# Bower dependency directory (https://bower.io/)
bower_components
# node-waf configuration
.lock-wscript
# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
# Dependency directories
node_modules/
jspm_packages/
# Snowpack dependency directory (https://snowpack.dev/)
web_modules/
# TypeScript cache
*.tsbuildinfo
# Optional npm cache directory
.npm
# Optional eslint cache
.eslintcache
# Optional stylelint cache
.stylelintcache
# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# Optional REPL history
.node_repl_history
# Output of 'npm pack'
*.tgz
# Yarn Integrity file
.yarn-integrity
# dotenv environment variable files
.env
.env.development.local
.env.test.local
.env.production.local
.env.local
# parcel-bundler cache (https://parceljs.org/)
.cache
.parcel-cache
# Next.js build output
.next
out
# Nuxt.js build / generate output
.nuxt
dist
# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and not Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public
# vuepress build output
.vuepress/dist
# vuepress v2.x temp and cache directory
.temp
.cache
# Docusaurus cache and generated files
.docusaurus
# Serverless directories
.serverless/
# FuseBox cache
.fusebox/
# DynamoDB Local files
.dynamodb/
# TernJS port file
.tern-port
# Stores VSCode versions used for testing VSCode extensions
.vscode-test
# yarn v2
.yarn/cache
.yarn/unplugged
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

106
index.ts Normal file
View file

@ -0,0 +1,106 @@
const resetEsc = 0;
const boldEsc = 1;
const dimEsc = 2;
const italicEsc = 3;
const underlineEsc = 4;
const overlineEsc = 53;
const inverseEsc = 7;
const hiddenEsc = 8;
const strikethroughEsc = 9;
const blackEsc = 30;
const redEsc = 31;
const greenEsc = 32;
const yellowEsc = 33;
const blueEsc = 34;
const magentaEsc = 35;
const cyanEsc = 36;
const whiteEsc = 37;
const grayEsc = 90;
const redBrightEsc = 91;
const greenBrightEsc = 92;
const yellowBrightEsc = 93;
const blueBrightEsc = 94;
const magentaBrightEsc = 95;
const cyanBrightEsc = 96;
const whiteBrightEsc = 97;
const bgBlackEsc = 40;
const bgRedEsc = 41;
const bgGreenEsc = 42;
const bgYellowEsc = 43;
const bgBlueEsc = 44;
const bgMagentaEsc = 45;
const bgCyanEsc = 46;
const bgWhiteEsc = 47;
const bgGrayEsc = 100;
const bgRedBrightEsc = 101;
const bgGreenBrightEsc = 102;
const bgYellowBrightEsc = 103;
const bgBlueBrightEsc = 104;
const bgMagentaBrightEsc = 105;
const bgCyanBrightEsc = 106;
const bgWhiteBrightEsc = 107;
const STRING_RESET_ESC = `\u001b[${resetEsc}m`;
function format(format:number, s:string) : string {
// Exclude reset escapes if already present
if (s.endsWith(STRING_RESET_ESC)) {
return `\u001b[${format}m${s}`;
}
return `\u001b[${format}m${s}${STRING_RESET_ESC}`;
}
// Generic
export function bold(s:string) : string { return format(boldEsc, s) }
export function dim(s:string) : string { return format(dimEsc, s) }
export function italic(s:string) : string { return format(italicEsc, s) }
export function underline(s:string) : string { return format(underlineEsc, s) }
export function overline(s:string) : string { return format(overlineEsc, s) }
export function inverse(s:string) : string { return format(inverseEsc, s) }
export function hidden(s:string) : string { return format(hiddenEsc, s) }
export function strikethrough(s:string) : string { return format(strikethroughEsc, s) }
// Colours
export function black(s:string) : string { return format(blackEsc, s) }
export function red(s:string) : string { return format(redEsc, s) }
export function green(s:string) : string { return format(greenEsc, s) }
export function yellow(s:string) : string { return format(yellowEsc, s) }
export function blue(s:string) : string { return format(blueEsc, s) }
export function magenta(s:string) : string { return format(magentaEsc, s) }
export function cyan(s:string) : string { return format(cyanEsc, s) }
export function white(s:string) : string { return format(whiteEsc, s) }
export function gray(s:string) : string { return format(grayEsc, s) }
export function grey(s:string) : string { return gray(s) }
export function blackBright(s:string) : string { return gray(s) }
export function redBright(s:string) : string { return format(redBrightEsc, s) }
export function greenBright(s:string) : string { return format(greenBrightEsc, s) }
export function yellowBright(s:string) : string { return format(yellowBrightEsc, s) }
export function blueBright(s:string) : string { return format(blueBrightEsc, s) }
export function magentaBright(s:string) : string { return format(magentaBrightEsc, s) }
export function cyanBright(s:string) : string { return format(cyanBrightEsc, s) }
export function whiteBright(s:string) : string { return format(whiteBrightEsc, s) }
export function bgBlack(s:string) : string { return format(bgBlackEsc, s) }
export function bgRed(s:string) : string { return format(bgRedEsc, s) }
export function bgGreen(s:string) : string { return format(bgGreenEsc, s) }
export function bgYellow(s:string) : string { return format(bgYellowEsc, s) }
export function bgBlue(s:string) : string { return format(bgBlueEsc, s) }
export function bgMagenta(s:string) : string { return format(bgMagentaEsc, s) }
export function bgCyan(s:string) : string { return format(bgCyanEsc, s) }
export function bgWhite(s:string) : string { return format(bgWhiteEsc, s) }
export function bgGray(s:string) : string { return format(bgGrayEsc, s) }
export function bgGrey(s:string) : string { return bgGray(s) }
export function bgBlackBright(s:string) : string { return bgGray(s) }
export function bgRedBright(s:string) : string { return format(bgRedBrightEsc, s) }
export function bgGreenBright(s:string) : string { return format(bgGreenBrightEsc, s) }
export function bgYellowBright(s:string) : string { return format(bgYellowBrightEsc, s) }
export function bgBlueBright(s:string) : string { return format(bgBlueBrightEsc, s) }
export function bgMagentaBright(s:string) : string { return format(bgMagentaBrightEsc, s) }
export function bgCyanBright(s:string) : string { return format(bgCyanBrightEsc, s) }
export function bgWhiteBright(s:string) : string { return format(bgWhiteBrightEsc, s) }

2551
package-lock.json generated Normal file

File diff suppressed because it is too large Load diff

33
package.json Normal file
View file

@ -0,0 +1,33 @@
{
"name": "dyetty",
"version": "1.0.0",
"description": "",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"updateCheck": "check-outdated",
"build": "npm-run-all build:*",
"build:smash": "ts-node ./tooling/fileSmasher.ts",
"build:build": "tsc --build",
"build:cleanup": "ts-node ./tooling/cleanup.ts",
"_clean": "tsc --build --clean"
},
"repository": {
"type": "git",
"url": "git+https://github.com/tgpholly/dyetty.git"
},
"keywords": [],
"author": "",
"license": "MIT",
"bugs": {
"url": "https://github.com/tgpholly/dyetty/issues"
},
"homepage": "https://github.com/tgpholly/dyetty#readme",
"devDependencies": {
"check-outdated": "^2.11.0",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"typescript": "^5.1.6",
"npm-run-all": "^4.1.5"
}
}

12
tooling/cleanup.ts Normal file
View file

@ -0,0 +1,12 @@
import { readdirSync, rmSync, renameSync } from "fs";
const libFiles = readdirSync("./lib");
for (const file of libFiles) {
if (!file.startsWith("combined")) {
rmSync(`./lib/${file}`, { recursive: true });
}
}
renameSync("./lib/combined.js", "./lib/index.js");
renameSync("./lib/combined.d.ts", "./lib/index.d.ts");

61
tooling/fileSmasher.ts Normal file
View file

@ -0,0 +1,61 @@
// fileSmasher ~.~
// for when you're just too lazy to
// do it properly.
import { readdirSync, lstatSync, readFileSync, writeFileSync } from "fs";
const tsFileData:Array<string> = new Array<string>();
// Github Actions forced my hand
const toolinglessFolderPath = __dirname.replace("/tooling", "/");
function readDir(nam:string) {
const files = readdirSync(nam);
for (const file of files) {
if (nam == toolinglessFolderPath && (file.startsWith(".") || file == "tooling" || file == "lib" || file == "node_modules" || file == "combined.ts")) {
continue;
}
if (lstatSync(`${nam}/${file}`).isDirectory()) {
readDir(`${nam}/${file}`);
} else if (file.endsWith(".ts")) {
tsFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
}
}
}
readDir(toolinglessFolderPath);
const combinedFiles = tsFileData.join("\n");
const splitLines = combinedFiles.split("\n");
const resultLines:Array<string> = new Array<string>();
const unExport:string[] = [
];
function checkForMatchAndReplace(s:string) {
for (const tUExp of unExport) {
const spl = tUExp.split(":");
const type = spl[0];
if (s.startsWith(`export ${type} ${spl[1]}`)) {
return s.replace(`export ${type} ${spl[1]}`, `${type} ${spl[1]}`);
}
}
return s;
}
// Let's process the file to make it usable
for (const line of splitLines) {
// Throw away imports as they aren't needed
// TODO: Add allow list for npm module imports
if (line.startsWith("import")) {
continue;
}
// Fix up classes, interfaces and such.
resultLines.push(checkForMatchAndReplace(line));
}
writeFileSync("./combined.ts", resultLines.join("\n"));

13
tsconfig.json Normal file
View file

@ -0,0 +1,13 @@
{
"compilerOptions": {
"module": "CommonJS",
"moduleResolution": "node",
"target": "es6",
"esModuleInterop": true,
"resolveJsonModule": true,
"rootDir": "./",
"outDir": "./lib/",
"strict": true,
"declaration": true
}
}