diff --git a/.gitignore b/.gitignore index b72bc76..7f86865 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ node_modules/ # Compile output lib/ -types/ \ No newline at end of file +types/*.ts +!types/internal/commands.d.ts \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..55712c1 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "typescript.tsdk": "node_modules/typescript/lib" +} \ No newline at end of file diff --git a/eng/gencmd.ts b/eng/gencmd.ts new file mode 100644 index 0000000..963718d --- /dev/null +++ b/eng/gencmd.ts @@ -0,0 +1,36 @@ +import axios from 'axios'; +import { parse, Node } from 'node-html-parser'; + +interface Commands { + command: string; + args: string | null; + summary: string; +} + +async function dodo() { + const res = await axios.get('https://redis.io/commands'); + const html = await res.data; + const root = parse(html); + const commands = root.querySelectorAll('#commands li a') + .map(e => e.childNodes.filter(cn => cn.nodeType === 1)) + .map(e => handleHTMLElement(e)); + + convertCommandsToTypeScript(commands); +} + +function handleHTMLElement(datas: Node[]) { + const command = datas[0]?.childNodes[0]?.rawText.trim(); + const args = datas[0]?.childNodes[1]?.childNodes[0]?.rawText.trim().split(/(\n| )+/).join('') || null; + const summary = datas[1]?.childNodes[0]?.rawText.trim(); + return { + command, + args, + summary + } as Commands; +} + +function convertCommandsToTypeScript(commands: Commands[]) { + console.log(commands); +} + +dodo(); \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 10392e8..dda2b96 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { - "name": "template", - "version": "1.3.0", + "name": "redis", + "version": "0.0.1", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -549,6 +549,15 @@ "integrity": "sha512-+Ryf6g3BKoRc7jfp7ad8tM4TtMiaWvbF/1/sQcZPkkS7ag3D5nMBCe2UfOTONtAkaG0tO0ij3C5Lwmf1EiyjHg==", "dev": true }, + "axios": { + "version": "0.21.0", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.0.tgz", + "integrity": "sha512-fmkJBknJKoZwem3/IKSSLpkdNXZeBu5Q7GA/aRsr2btgrptmSCxi2oFjZHqGdK9DoTil9PIHlPIZw2EcRJXRvw==", + "dev": true, + "requires": { + "follow-redirects": "^1.10.0" + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", @@ -1153,6 +1162,12 @@ "integrity": "sha512-tW+UkmtNg/jv9CSofAKvgVcO7c2URjhTdW1ZTkcAritblu8tajiYy7YisnIflEwtKssCtOxpnBRoCB7iap0/TA==", "dev": true }, + "follow-redirects": { + "version": "1.13.0", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz", + "integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA==", + "dev": true + }, "foreground-child": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/foreground-child/-/foreground-child-2.0.0.tgz", @@ -1822,6 +1837,15 @@ "integrity": "sha1-Sr6/7tdUHywnrPspvbvRXI1bpPc=", "dev": true }, + "node-html-parser": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/node-html-parser/-/node-html-parser-2.0.0.tgz", + "integrity": "sha512-3wJdYSxiVIBxuiFm9UtfNWAlBw2P+Vb/RN1nqf40q2JeZDpcJ1HsrWuWV3j15SSJ25TvfnOoac2Q+uDU9iY0sw==", + "dev": true, + "requires": { + "he": "1.2.0" + } + }, "node-preload": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/node-preload/-/node-preload-0.2.1.tgz", diff --git a/package.json b/package.json index 81092fb..42b0f66 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { - "name": "template", - "version": "1.3.0", - "main": "lib/app.js", + "name": "redis", + "version": "0.0.1", + "main": "lib/index.js", "repository": { "type": "git", "url": "https://github.com/pikadun/redis" @@ -12,7 +12,8 @@ "coverage": "nyc --nycrc-path=./eng/.nycrc.json npm test", "format": "ts-node ./eng/lint.ts", "watch": "tsc --build ./eng/tsconfig.dev.json --watch", - "compile": "tsc --build ./eng/tsconfig.prod.json" + "compile": "tsc --build ./eng/tsconfig.prod.json", + "gencmd": "ts-node ./eng/gencmd.ts" }, "keywords": [], "husky": { @@ -29,9 +30,11 @@ "@types/node": "^14.14.10", "@typescript-eslint/eslint-plugin": "^4.9.1", "@typescript-eslint/parser": "^4.9.1", + "axios": "^0.21.0", "eslint": "^7.15.0", "husky": "^4.3.5", "mocha": "^8.2.1", + "node-html-parser": "^2.0.0", "nyc": "^15.1.0", "ts-node": "^9.1.1", "typescript": "^4.1.2" diff --git a/src/client.ts b/src/client.ts new file mode 100644 index 0000000..afef3fa --- /dev/null +++ b/src/client.ts @@ -0,0 +1,32 @@ +import { Socket } from 'net'; + +export interface IClientOptions { + host?: string; + port?: number; + auth?: string; +} + +interface IClient { + connect(): void; +} + +export class Client implements IClient { + private socket = new Socket(); + constructor( + private readonly options: IClientOptions = {} + ) { + this.initOptions(options); + } + + public connect(): void { + this.socket.connect( + this.options.port as number, + this.options.host as string + ); + } + + private initOptions(options: IClientOptions): void { + options.host = options.host || '127.0.0.1'; + options.port = options.port || 6379; + } +} \ No newline at end of file diff --git a/src/index.ts b/src/index.ts new file mode 100644 index 0000000..1333459 --- /dev/null +++ b/src/index.ts @@ -0,0 +1 @@ +export { Client, IClientOptions } from './client'; \ No newline at end of file