build: prepare to publish x3
various package json fixes, improved node meta-package
This commit is contained in:
parent
21d69e466e
commit
8cbd6e14c8
3 changed files with 68 additions and 6 deletions
|
@ -12,6 +12,7 @@
|
||||||
"docs": "npx typedoc"
|
"docs": "npx typedoc"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/node": "^15.12.1",
|
||||||
"@types/events": "^3.0.0",
|
"@types/events": "^3.0.0",
|
||||||
"@mtcute/tl": "~1.129.0",
|
"@mtcute/tl": "~1.129.0",
|
||||||
"leemon": "6.2.0",
|
"leemon": "6.2.0",
|
||||||
|
@ -23,8 +24,5 @@
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/ws": "^7.4.1",
|
"@types/ws": "^7.4.1",
|
||||||
"ws": "^7.4.4"
|
"ws": "^7.4.4"
|
||||||
},
|
|
||||||
"peerDependencies": {
|
|
||||||
"@types/node": "^15.12.1"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import { TelegramClient } from '@mtcute/client'
|
import { TelegramClient, User } from '@mtcute/client'
|
||||||
import { BaseTelegramClient } from '@mtcute/core'
|
import { BaseTelegramClient } from '@mtcute/core'
|
||||||
import { NodeNativeCryptoProvider } from '@mtcute/crypto-node'
|
import { NodeNativeCryptoProvider } from '@mtcute/crypto-node'
|
||||||
import { HtmlMessageEntityParser } from '@mtcute/html-parser'
|
import { HtmlMessageEntityParser } from '@mtcute/html-parser'
|
||||||
import { MarkdownMessageEntityParser } from '@mtcute/markdown-parser'
|
import { MarkdownMessageEntityParser } from '@mtcute/markdown-parser'
|
||||||
import { SqliteStorage } from '@mtcute/sqlite'
|
import { SqliteStorage } from '@mtcute/sqlite'
|
||||||
|
import { createInterface, Interface as RlInterface } from 'readline'
|
||||||
|
|
||||||
export * from '@mtcute/dispatcher'
|
export * from '@mtcute/dispatcher'
|
||||||
|
export { SqliteStorage }
|
||||||
|
|
||||||
export namespace NodeTelegramClient {
|
export namespace NodeTelegramClient {
|
||||||
export interface Options
|
export interface Options
|
||||||
|
@ -33,6 +35,25 @@ export namespace NodeTelegramClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let rl: RlInterface | null = null
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tiny wrapper over Node `readline` package
|
||||||
|
* for simpler user input for `.run()` method
|
||||||
|
*
|
||||||
|
* @param text Text of the question
|
||||||
|
*/
|
||||||
|
export const input = (text: string): Promise<string> => {
|
||||||
|
if (!rl) {
|
||||||
|
rl = createInterface({
|
||||||
|
input: process.stdin,
|
||||||
|
output: process.stdout,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Promise((res) => rl!.question(text, res))
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tiny wrapper over `TelegramClient` for usage inside Node JS.
|
* Tiny wrapper over `TelegramClient` for usage inside Node JS.
|
||||||
*
|
*
|
||||||
|
@ -55,4 +76,15 @@ export class NodeTelegramClient extends TelegramClient {
|
||||||
if (opts.defaultParseMode)
|
if (opts.defaultParseMode)
|
||||||
this.setDefaultParseMode(opts.defaultParseMode)
|
this.setDefaultParseMode(opts.defaultParseMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
run(
|
||||||
|
params: Parameters<TelegramClient['start']>[0],
|
||||||
|
then?: (user: User) => void | Promise<void>
|
||||||
|
): void {
|
||||||
|
if (!params.phone) params.phone = () => input('Phone > ')
|
||||||
|
if (!params.code) params.code = () => input('Code > ')
|
||||||
|
if (!params.password) params.password = () => input('2FA password > ')
|
||||||
|
|
||||||
|
return super.run(params, then)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,18 +85,50 @@ function publishSinglePackage(name) {
|
||||||
|
|
||||||
if (name === 'client') {
|
if (name === 'client') {
|
||||||
// make TelegramClient a class, not an interface
|
// make TelegramClient a class, not an interface
|
||||||
const content = fs.readFileSync(
|
const dTsContent = fs.readFileSync(
|
||||||
path.join(dir, 'dist/client.d.ts'),
|
path.join(dir, 'dist/client.d.ts'),
|
||||||
'utf8'
|
'utf8'
|
||||||
)
|
)
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(dir, 'dist/client.d.ts'),
|
path.join(dir, 'dist/client.d.ts'),
|
||||||
content.replace(
|
dTsContent.replace(
|
||||||
'export interface TelegramClient',
|
'export interface TelegramClient',
|
||||||
'export class TelegramClient'
|
'export class TelegramClient'
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// make methods prototype methods, not properties
|
||||||
|
let jsContent = fs.readFileSync(
|
||||||
|
path.join(dir, 'dist/client.js'),
|
||||||
|
'utf8'
|
||||||
|
)
|
||||||
|
|
||||||
|
let methods = []
|
||||||
|
jsContent = jsContent.replace(
|
||||||
|
/^\s*this\.([a-zA-Z0-9_]+) = ([a-zA-Z0-9_]+\.[a-zA-Z0-9_]+);\r?\n/gm,
|
||||||
|
(_, name, imported) => {
|
||||||
|
methods.push(
|
||||||
|
`TelegramClient.prototype.${name} = ${imported};`
|
||||||
|
)
|
||||||
|
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
const idx = jsContent.indexOf(
|
||||||
|
'exports.TelegramClient = TelegramClient;'
|
||||||
|
)
|
||||||
|
if (idx === -1)
|
||||||
|
throw new Error('client.js exports.TelegramClient not found')
|
||||||
|
|
||||||
|
jsContent =
|
||||||
|
jsContent.substr(0, idx) +
|
||||||
|
methods.join('\n') +
|
||||||
|
'\n' +
|
||||||
|
jsContent.substr(idx)
|
||||||
|
|
||||||
|
fs.writeFileSync(path.join(dir, 'dist/client.js'), jsContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name === 'crypto-node') {
|
if (name === 'crypto-node') {
|
||||||
|
|
Loading…
Reference in a new issue