janky tooling to get this working properly

This commit is contained in:
Holly Stubbs 2023-06-22 11:32:40 +01:00
parent 07fa9c0ecf
commit 9aa1ad9a5d
6 changed files with 2127 additions and 21 deletions

1
.gitignore vendored
View file

@ -1,5 +1,6 @@
# Build folder
lib/
combined.ts
# Logs
logs

View file

@ -1,6 +1,7 @@
.github/*
enums/*
index.ts
combined.ts
readers/*
writers/*

2056
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,12 +1,15 @@
{
"name": "bufferstuff",
"version": "1.2.1",
"version": "1.3.1",
"description": "A set of utility classes for reading and writing binary data in NodeJS and the browser",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"scripts": {
"updateCheck": "check-outdated",
"build": "tsc --build",
"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": {
@ -22,8 +25,9 @@
"homepage": "https://github.com/tgpholly/bufferStuff#readme",
"devDependencies": {
"check-outdated": "^2.11.0",
"ts-loader": "^9.4.2",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"typescript": "^5.0.4"
"typescript": "^5.1.3",
"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");

66
tooling/fileSmasher.ts Normal file
View file

@ -0,0 +1,66 @@
// fileSmasher ~.~
// for when you're just too lazy to
// do it properly.
import { readdirSync, statSync, readFileSync, writeFileSync, mkdirSync, existsSync } from "fs";
let tsFileData:Array<string> = new Array<string>();
function readDir(nam:string) {
const files = readdirSync(nam);
for (const file of files) {
if (nam == "./" && (file.startsWith(".") || file == "tooling" || file == "lib" || file == "node_modules" || file == "combined.ts")) {
continue;
}
// This is a very dumb way of checking for folders
// protip: don't do this.
if (statSync(`${nam}/${file}`).size == 0) {
readDir(`${nam}/${file}`);
} else if (file.endsWith(".ts")) {
tsFileData.push(readFileSync((`${nam}/${file}`).replace("//", "/")).toString());
}
}
}
readDir("./");
const combinedFiles = tsFileData.join("\n");
const splitLines = combinedFiles.split("\n");
const resultLines:Array<string> = new Array<string>();
const unExport = [
"class:ReaderBase",
"class:ReaderLE",
"class:ReaderBE",
"class:WriterBase",
"class:WriterLE",
"class:WriterBE",
];
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));
//resultLines.push(line.replace("export class", "class").replace("export interface", "interface").replace("export enum", "enum"));
}
writeFileSync("./combined.ts", resultLines.join("\n"));