@peteradeojo/typegencli
Advanced tools
Comparing version 0.1.1 to 0.2.0
@@ -52,3 +52,2 @@ "use strict"; | ||
const request = this.buildRequest(); | ||
console.log(request); | ||
if (request.method !== 'POST') { | ||
@@ -55,0 +54,0 @@ this.setStatus(400); |
#!/usr/bin/env node | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
@@ -18,10 +9,8 @@ return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
const commander_1 = require("commander"); | ||
const http_1 = require("http"); | ||
const url_1 = __importDefault(require("url")); | ||
const handler_1 = __importDefault(require("./handler")); | ||
const axios_1 = __importDefault(require("axios")); | ||
const ws_1 = require("./ws"); | ||
Object.defineProperty(exports, "sendData", { enumerable: true, get: function () { return ws_1.sendData; } }); | ||
const figlet_1 = __importDefault(require("figlet")); | ||
if (require.main === module) { | ||
const figlet = require('figlet'); | ||
const program = new commander_1.Command(); | ||
console.log(figlet.textSync('Typegen')); | ||
console.log(figlet_1.default.textSync('Typegen')); | ||
program.version('1.0.0').description('Typegen CLI for generating types'); | ||
@@ -31,46 +20,5 @@ program.option('-l, --listen [port]', 'Listen to a port other than the default port', '3000'); | ||
const options = program.opts(); | ||
const server = (0, http_1.createServer)(); | ||
const respond = (req, res, data) => { | ||
const handler = new handler_1.default(req, res, data); | ||
return handler.handle(); | ||
}; | ||
server.on('request', (req, res) => { | ||
let reqBody = null; | ||
const parsedURl = url_1.default.parse(req.url, true); | ||
const queries = parsedURl.query; | ||
if (req.method == 'POST') { | ||
reqBody = ''; | ||
req.on('data', (chunk) => { | ||
// console.log(typeof chunk) | ||
reqBody += chunk.toString(); | ||
}); | ||
return req.on('end', () => { | ||
const response = respond(req, res, JSON.parse(reqBody || '{}')); | ||
res.writeHead(response.status, response.statusMessage, response.headers); | ||
res.end(response.response); | ||
}); | ||
} | ||
const response = respond(req, res); | ||
res.writeHead(response.status, response.statusMessage, response.headers); | ||
res.end(response.response); | ||
}); | ||
const port = Number(options.listen); | ||
server.listen(port); | ||
console.log('Server listening on port', port); | ||
(0, ws_1.Server)(port); | ||
} | ||
const sendData = (port = 3000) => { | ||
return (name, data) => __awaiter(void 0, void 0, void 0, function* () { | ||
try { | ||
const res = yield axios_1.default.post(`http://localhost:${port}`, { | ||
name, | ||
data, | ||
}); | ||
// console.log(res.data) | ||
} | ||
catch (err) { | ||
console.error(err.message); | ||
} | ||
}); | ||
}; | ||
exports.sendData = sendData; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@peteradeojo/typegencli", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"main": "dist/index.js", | ||
@@ -19,3 +19,6 @@ "bin": { | ||
"figlet": "^1.7.0", | ||
"joi": "^17.12.1" | ||
"joi": "^17.12.1", | ||
"prompt-sync": "^4.2.0", | ||
"prompt-sync-history": "^1.0.1", | ||
"ws": "^8.16.0" | ||
}, | ||
@@ -30,4 +33,7 @@ "scripts": { | ||
"@types/node": "^20.11.19", | ||
"@types/prompt-sync": "^4.2.3", | ||
"@types/prompt-sync-history": "^1.0.4", | ||
"@types/ws": "^8.5.10", | ||
"typescript": "^5.3.3" | ||
} | ||
} |
@@ -87,4 +87,2 @@ import { IncomingMessage, ServerResponse } from 'http'; | ||
console.log(request); | ||
if (request.method !== 'POST') { | ||
@@ -91,0 +89,0 @@ this.setStatus(400); |
#!/usr/bin/env node | ||
import { Command } from 'commander'; | ||
import { IncomingMessage, ServerResponse, createServer } from 'http'; | ||
import url from 'url'; | ||
import RequestHandler from './handler'; | ||
import axios from 'axios'; | ||
import { Server, sendData } from './ws'; | ||
import figlet from 'figlet'; | ||
if (require.main === module) { | ||
const figlet = require('figlet'); | ||
const program = new Command(); | ||
@@ -24,59 +20,6 @@ console.log(figlet.textSync('Typegen')); | ||
const options = program.opts(); | ||
const server = createServer(); | ||
const respond = ( | ||
req: IncomingMessage, | ||
res: ServerResponse<IncomingMessage>, | ||
data?: any | ||
) => { | ||
const handler = new RequestHandler(req, res, data); | ||
return handler.handle(); | ||
}; | ||
server.on('request', (req, res) => { | ||
let reqBody: string | null = null; | ||
const parsedURl = url.parse(req.url!, true); | ||
const queries = parsedURl.query; | ||
if (req.method == 'POST') { | ||
reqBody = ''; | ||
req.on('data', (chunk) => { | ||
// console.log(typeof chunk) | ||
reqBody += chunk.toString(); | ||
}); | ||
return req.on('end', () => { | ||
const response = respond(req, res, JSON.parse(reqBody || '{}')); | ||
res.writeHead( | ||
response.status, | ||
response.statusMessage, | ||
response.headers | ||
); | ||
res.end(response.response); | ||
}); | ||
} | ||
const response = respond(req, res); | ||
res.writeHead(response.status, response.statusMessage, response.headers); | ||
res.end(response.response); | ||
}); | ||
const port = Number(options.listen); | ||
server.listen(port); | ||
console.log('Server listening on port', port); | ||
Server(port); | ||
} | ||
export const sendData = (port: number = 3000) => { | ||
return async (name: string, data: any) => { | ||
try { | ||
const res = await axios.post(`http://localhost:${port}`, { | ||
name, | ||
data, | ||
}); | ||
// console.log(res.data) | ||
} catch (err: any) { | ||
console.error(err.message); | ||
} | ||
}; | ||
}; | ||
export { sendData }; |
@@ -11,3 +11,6 @@ { | ||
"moduleResolution": "node" | ||
} | ||
}, | ||
"exclude": [ | ||
"typegen" | ||
] | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31566
21
658
8
6
2
+ Addedprompt-sync@^4.2.0
+ Addedprompt-sync-history@^1.0.1
+ Addedws@^8.16.0
+ Addedansi-regex@4.1.1(transitive)
+ Addedprompt-sync@4.2.0(transitive)
+ Addedprompt-sync-history@1.0.1(transitive)
+ Addedstrip-ansi@5.2.0(transitive)
+ Addedws@8.18.0(transitive)