From ba41930a389157b1e5f3566d06fa5d8f6bda145a Mon Sep 17 00:00:00 2001 From: ION606 Date: Wed, 22 May 2024 20:47:27 -0400 Subject: [PATCH] restructure --- customFileSystem.js => index.js | 0 package-lock.json | 22 ++++++++++++-- package.json | 7 +++-- src/types/index.ts | 54 +++++++++++++++++++++++++++++++++ tests/testmain.js | 2 +- tsonfig.json | 8 +++++ 6 files changed, 88 insertions(+), 5 deletions(-) rename customFileSystem.js => index.js (100%) create mode 100644 src/types/index.ts create mode 100644 tsonfig.json diff --git a/customFileSystem.js b/index.js similarity index 100% rename from customFileSystem.js rename to index.js diff --git a/package-lock.json b/package-lock.json index 4e27ddd..e5a7488 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,28 @@ { "name": "github-to-fs", - "version": "1.0.0", + "version": "1.0.2", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "github-to-fs", - "version": "1.0.0", + "version": "1.0.2", "license": "ISC", "dependencies": { "axios": "^1.7.2", "base-64": "^1.0.0" + }, + "devDependencies": { + "@types/node": "^20.12.12" + } + }, + "node_modules/@types/node": { + "version": "20.12.12", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.12.tgz", + "integrity": "sha512-eWLDGF/FOSPtAvEqeRAQ4C8LSA7M1I7i0ky1I8U7kD1J5ITyW3AsRhQrKVoWf5pFKZ2kILsEGJhsI9r93PYnOw==", + "dev": true, + "dependencies": { + "undici-types": "~5.26.4" } }, "node_modules/asynckit": { @@ -107,6 +119,12 @@ "version": "1.1.0", "resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz", "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==" + }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true } } } diff --git a/package.json b/package.json index f43a1bc..0058adf 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "github-to-fs", "version": "1.0.2", "description": "a package that allows you to use github like file storage", - "main": "customFileSystem.js", + "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, @@ -18,5 +18,8 @@ "fs", "filesystem", "files" - ] + ], + "devDependencies": { + "@types/node": "^20.12.12" + } } diff --git a/src/types/index.ts b/src/types/index.ts new file mode 100644 index 0000000..2b356d4 --- /dev/null +++ b/src/types/index.ts @@ -0,0 +1,54 @@ +type AuthHeaders = { + 'Authorization': string; +}; + +type UpdateData = { + message: string; + content: string; + sha?: string; +}; + +type FileType = { + type: "dir" | "file"; + name: string; +}; + +declare class ghelper { + private ghurl: string; + private authHeaders: AuthHeaders; + private errhelper(err: any): null; + constructor(repoURL: string, token: string); + + appendToFile(fpath: string, toAdd: string): Promise; + addToRepo(fpath: string, contentRaw: string | Buffer, sha?: string): Promise; + remFromRepo(fpath: string): Promise; + readTree(branchName: string): Promise; + getStructure(dPath?: string, getSha?: boolean): Promise; +} + +declare class mockFileObj { + private fpath: string; + private encoding?: string; + private fptrs: Promise[]; + private cfs: customFs; + constructor(cfs: customFs, fpath: string, encoding?: string); + + write(toAdd: string): void; + close(): Promise; +} + +declare class customFs { + private ghs: ghelper; + constructor(repoUrl: string, token: string); + + private getFilesInDir(dirPath: string): Promise; + rmSync(dirPath: string, opts?: { recursive?: boolean }): Promise; + appendToFile(fPath: string, toWrite: string): Promise; + writeFileSync(fPath: string, toWriteRaw: any, opts?: { encoding?: string }): Promise; + writeFile(fName: string, toWrite: any, cb: (err?: any) => void): void; + readFileSync(fName: string): Promise; + readdirSync(dirName: string): Promise; + existsSync(p: string): Promise; + createWriteStream(fpath: string): mockFileObj; + mkdirSync(dirName: string): void; +} diff --git a/tests/testmain.js b/tests/testmain.js index 8aa7c4f..facc8f7 100644 --- a/tests/testmain.js +++ b/tests/testmain.js @@ -1,4 +1,4 @@ -import customFs from "../customFileSystem"; +import customFs from ".."; import fs from 'fs'; const { token } = JSON.parse(fs.readFileSync('config.json')); diff --git a/tsonfig.json b/tsonfig.json new file mode 100644 index 0000000..4184695 --- /dev/null +++ b/tsonfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "typeRoots": [ + "./node_modules/@types", + "./src/types" + ] + } +} \ No newline at end of file