build: preparing to publish
This commit is contained in:
parent
2cd443d6d1
commit
1d21cd5e65
8 changed files with 182 additions and 9 deletions
|
@ -1,8 +0,0 @@
|
||||||
let mod
|
|
||||||
try {
|
|
||||||
mod = require('./build/Release/crypto')
|
|
||||||
} catch (e) {
|
|
||||||
mod = require('./build/Debug/crypto')
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = mod
|
|
8
packages/crypto-node/src/native.js
Normal file
8
packages/crypto-node/src/native.js
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
let mod
|
||||||
|
try {
|
||||||
|
mod = require('../build/Release/crypto')
|
||||||
|
} catch (e) {
|
||||||
|
mod = require('../build/Debug/crypto')
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = mod
|
56
packages/node/index.ts
Normal file
56
packages/node/index.ts
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
import { TelegramClient } from '@mtcute/client'
|
||||||
|
import { BaseTelegramClient } from '@mtcute/core'
|
||||||
|
import { NodeNativeCryptoProvider } from '@mtcute/crypto-node'
|
||||||
|
import { HtmlMessageEntityParser } from '@mtcute/html-parser'
|
||||||
|
import { MarkdownMessageEntityParser } from '@mtcute/markdown-parser'
|
||||||
|
import { SqliteStorage } from '@mtcute/sqlite'
|
||||||
|
|
||||||
|
export * from '@mtcute/dispatcher'
|
||||||
|
|
||||||
|
export namespace NodeTelegramClient {
|
||||||
|
export interface Options extends Omit<BaseTelegramClient.Options, 'storage'> {
|
||||||
|
/**
|
||||||
|
* Default parse mode to use.
|
||||||
|
*
|
||||||
|
* Both HTML and Markdown parse modes are
|
||||||
|
* registered automatically.
|
||||||
|
*
|
||||||
|
* Defaults to `html`
|
||||||
|
*/
|
||||||
|
defaultParseMode?: 'html' | 'markdown'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage to use.
|
||||||
|
*
|
||||||
|
* You can pass a file name as a simple string,
|
||||||
|
* which will be passed directly to `SqliteStorage`
|
||||||
|
*
|
||||||
|
* Defaults to in-memory SQLite storage.
|
||||||
|
*/
|
||||||
|
storage?: BaseTelegramClient.Options['storage'] | string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tiny wrapper over `TelegramClient` for usage inside Node JS.
|
||||||
|
*
|
||||||
|
* This automatically sets the parse modes, native
|
||||||
|
* crypto addon and defaults to SQLite session.
|
||||||
|
*/
|
||||||
|
export class NodeTelegramClient extends TelegramClient {
|
||||||
|
constructor(opts: NodeTelegramClient.Options) {
|
||||||
|
super({
|
||||||
|
crypto: () => new NodeNativeCryptoProvider(),
|
||||||
|
...opts,
|
||||||
|
storage:
|
||||||
|
typeof opts.storage === 'string'
|
||||||
|
? new SqliteStorage(opts.storage)
|
||||||
|
: opts.storage ?? new SqliteStorage(':memory:'),
|
||||||
|
})
|
||||||
|
|
||||||
|
this.registerParseMode(new HtmlMessageEntityParser())
|
||||||
|
this.registerParseMode(new MarkdownMessageEntityParser())
|
||||||
|
if (opts.defaultParseMode)
|
||||||
|
this.setDefaultParseMode(opts.defaultParseMode)
|
||||||
|
}
|
||||||
|
}
|
22
packages/node/package.json
Normal file
22
packages/node/package.json
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
{
|
||||||
|
"name": "@mtcute/node",
|
||||||
|
"private": true,
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "Meta-package for Node JS",
|
||||||
|
"author": "Alisa Sireneva <me@tei.su>",
|
||||||
|
"license": "MIT",
|
||||||
|
"main": "index.ts",
|
||||||
|
"scripts": {
|
||||||
|
"test": "mocha -r ts-node/register tests/**/*.spec.ts",
|
||||||
|
"docs": "npx typedoc",
|
||||||
|
"build": "tsc"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@mtcute/client": "^0.0.0",
|
||||||
|
"@mtcute/sqlite": "^0.0.0",
|
||||||
|
"@mtcute/markdown-parser": "^0.0.0",
|
||||||
|
"@mtcute/html-parser": "^0.0.0",
|
||||||
|
"@mtcute/dispatcher": "^0.0.0",
|
||||||
|
"@mtcute/crypto-node": "^0.0.0"
|
||||||
|
}
|
||||||
|
}
|
19
packages/node/tsconfig.json
Normal file
19
packages/node/tsconfig.json
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
{
|
||||||
|
"extends": "../../tsconfig.json",
|
||||||
|
"compilerOptions": {
|
||||||
|
"outDir": "./dist"
|
||||||
|
},
|
||||||
|
"include": [
|
||||||
|
"./index.ts"
|
||||||
|
],
|
||||||
|
"typedocOptions": {
|
||||||
|
"name": "@mtcute/node",
|
||||||
|
"includeVersion": true,
|
||||||
|
"out": "../../docs/packages/node",
|
||||||
|
"listInvalidSymbolLinks": true,
|
||||||
|
"excludePrivate": true,
|
||||||
|
"entryPoints": [
|
||||||
|
"./src/index.ts"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,7 +4,7 @@
|
||||||
"outDir": "./dist"
|
"outDir": "./dist"
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./src"
|
"./index.ts"
|
||||||
],
|
],
|
||||||
"typedocOptions": {
|
"typedocOptions": {
|
||||||
"name": "@mtcute/sqlite",
|
"name": "@mtcute/sqlite",
|
||||||
|
|
76
scripts/publish.js
Normal file
76
scripts/publish.js
Normal file
|
@ -0,0 +1,76 @@
|
||||||
|
const fs = require('fs')
|
||||||
|
const path = require('path')
|
||||||
|
const cp = require('child_process')
|
||||||
|
|
||||||
|
function publishSinglePackage(name) {
|
||||||
|
let dir = path.join(__dirname, '../packages', name)
|
||||||
|
|
||||||
|
if (name !== 'tl') {
|
||||||
|
// tl package is already generated ready to publish
|
||||||
|
|
||||||
|
console.log('[i] Building %s', name)
|
||||||
|
// build ts
|
||||||
|
cp.execSync('yarn run build', {
|
||||||
|
cwd: dir,
|
||||||
|
stdio: 'inherit',
|
||||||
|
})
|
||||||
|
|
||||||
|
// copy package.json, replacing private with false
|
||||||
|
const packJson = JSON.parse(
|
||||||
|
fs.readFileSync(path.join(dir, 'package.json'), 'utf8')
|
||||||
|
)
|
||||||
|
if (!packJson.main)
|
||||||
|
throw new Error(`${name}'s package.json does not contain "main"`)
|
||||||
|
|
||||||
|
// since "src" is compiled to "dist", we need to remove that prefix
|
||||||
|
packJson.main = packJson.main.replace(/^(?:\.\/)?src\//, '')
|
||||||
|
packJson.private = false
|
||||||
|
|
||||||
|
fs.writeFileSync(
|
||||||
|
path.join(dir, 'dist/package.json'),
|
||||||
|
JSON.stringify(packJson, null, 4)
|
||||||
|
)
|
||||||
|
|
||||||
|
// copy readme
|
||||||
|
try {
|
||||||
|
fs.copyFileSync(
|
||||||
|
path.join(dir, 'README.md'),
|
||||||
|
path.join(dir, 'dist/README.md')
|
||||||
|
)
|
||||||
|
} catch (e) {
|
||||||
|
if (e.code !== 'ENOENT') throw e
|
||||||
|
}
|
||||||
|
|
||||||
|
dir = path.join(dir, 'dist')
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('[i] Publishing %s', name)
|
||||||
|
|
||||||
|
// publish to npm
|
||||||
|
// cp.execSync('npm publish', {
|
||||||
|
// cwd: ,
|
||||||
|
// })
|
||||||
|
}
|
||||||
|
|
||||||
|
const LOCAL = [
|
||||||
|
'crypto',
|
||||||
|
'tl-reference'
|
||||||
|
]
|
||||||
|
|
||||||
|
if (require.main === module) {
|
||||||
|
const arg = process.argv[2]
|
||||||
|
if (!arg) {
|
||||||
|
console.log('Usage: publish.js <package name | all>')
|
||||||
|
process.exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (arg === 'all') {
|
||||||
|
for (const f of fs.readdirSync(path.join('../packages'))) {
|
||||||
|
if (LOCAL.indexOf(f) > -1) continue
|
||||||
|
|
||||||
|
publishSinglePackage(f)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
publishSinglePackage(arg)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue