build: improved publish script, fixed imports/exports, added note about private repo
This commit is contained in:
parent
e02763dcdd
commit
ffafb3e5db
10 changed files with 60 additions and 24 deletions
1
.npmrc
Normal file
1
.npmrc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
@mtcute:registry=https://npm.tei.su
|
12
README.md
12
README.md
|
@ -25,6 +25,18 @@ Work-in-progress library for MTProto in TypeScript.
|
||||||
> If you encounter errors related to storage, either
|
> If you encounter errors related to storage, either
|
||||||
> reset your storage by removing the file, or fix it manually.
|
> reset your storage by removing the file, or fix it manually.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
MTCute is currently only published in my private NPM registry.
|
||||||
|
|
||||||
|
You can install it by running:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm config set --location project @mtcute:registry https://npm.tei.su
|
||||||
|
|
||||||
|
npm install @mtcute/node # or any other package
|
||||||
|
```
|
||||||
|
|
||||||
## Setting up for development:
|
## Setting up for development:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
@ -4,5 +4,4 @@ import { randomBytes } from 'crypto'
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export const _defaultCryptoProviderFactory = () => new NodeCryptoProvider()
|
export const _defaultCryptoProviderFactory = () => new NodeCryptoProvider()
|
||||||
|
|
||||||
/** @internal */
|
|
||||||
export const _randomBytes = randomBytes
|
export const _randomBytes = randomBytes
|
||||||
|
|
|
@ -4,7 +4,6 @@ import { typedArrayToBuffer } from '../buffer-utils'
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export const _defaultCryptoProviderFactory = () => new ForgeCryptoProvider()
|
export const _defaultCryptoProviderFactory = () => new ForgeCryptoProvider()
|
||||||
|
|
||||||
/** @internal */
|
|
||||||
export function _randomBytes(size: number): Buffer {
|
export function _randomBytes(size: number): Buffer {
|
||||||
const ret = new Uint8Array(size)
|
const ret = new Uint8Array(size)
|
||||||
crypto.getRandomValues(ret)
|
crypto.getRandomValues(ret)
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
"name": "@mtcute/crypto-node",
|
"name": "@mtcute/crypto-node",
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"description": "Native crypto implementation for NodeJS",
|
"description": "Native crypto implementation for NodeJS",
|
||||||
|
"author": "Alisa Sireneva <me@tei.su>",
|
||||||
"main": "src/index.ts",
|
"main": "src/index.ts",
|
||||||
"private": true,
|
"private": true,
|
||||||
"license": "LGPL-3.0",
|
"license": "LGPL-3.0",
|
||||||
|
|
|
@ -10,9 +10,11 @@ import {
|
||||||
tl,
|
tl,
|
||||||
throttle,
|
throttle,
|
||||||
Logger,
|
Logger,
|
||||||
|
TlBinaryReader,
|
||||||
|
TlReaderMap,
|
||||||
|
TlWriterMap,
|
||||||
} from '@mtcute/core'
|
} from '@mtcute/core'
|
||||||
import sqlite3 from 'better-sqlite3'
|
import sqlite3 from 'better-sqlite3'
|
||||||
import { TlBinaryReader, TlReaderMap, TlWriterMap } from '../tl-runtime'
|
|
||||||
|
|
||||||
// todo: add testMode to "self"
|
// todo: add testMode to "self"
|
||||||
|
|
||||||
|
|
9
packages/tl-runtime/README.md
Normal file
9
packages/tl-runtime/README.md
Normal file
|
@ -0,0 +1,9 @@
|
||||||
|
# @mtcute/tl-runtime
|
||||||
|
|
||||||
|
This package contains runtime for TL (de-)serialization.
|
||||||
|
It only contains binary reader and writer implementations,
|
||||||
|
and is used by `@mtcute/core`.
|
||||||
|
|
||||||
|
`@mtcute/tl-utils` on the other hand has utilities like codegen
|
||||||
|
and schema manipulation, which is only needed at runtime if you
|
||||||
|
are patching the schema (which is a rare case anyways).
|
|
@ -4,8 +4,7 @@
|
||||||
"outDir": "./dist"
|
"outDir": "./dist"
|
||||||
},
|
},
|
||||||
"include": [
|
"include": [
|
||||||
"./src/reader.ts",
|
"./src",
|
||||||
"./src/writer.ts",
|
|
||||||
],
|
],
|
||||||
"typedocOptions": {
|
"typedocOptions": {
|
||||||
"name": "@mtcute/tl-runtime",
|
"name": "@mtcute/tl-runtime",
|
||||||
|
@ -14,8 +13,7 @@
|
||||||
"listInvalidSymbolLinks": true,
|
"listInvalidSymbolLinks": true,
|
||||||
"excludePrivate": true,
|
"excludePrivate": true,
|
||||||
"entryPoints": [
|
"entryPoints": [
|
||||||
"./src/reader.ts",
|
"./src/index.ts"
|
||||||
"./src/writer.ts"
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
packages/tl-utils/README.md
Normal file
3
packages/tl-utils/README.md
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
# @mtcute/tl-utils
|
||||||
|
|
||||||
|
This package contains utilities for TL schema parsing and manipulation.
|
|
@ -20,13 +20,11 @@ function publishSinglePackage(name) {
|
||||||
'binary/rsa-keys.js',
|
'binary/rsa-keys.js',
|
||||||
'binary/writer.d.ts',
|
'binary/writer.d.ts',
|
||||||
'binary/writer.js',
|
'binary/writer.js',
|
||||||
'errors.d.ts',
|
|
||||||
'errors.js',
|
|
||||||
'index.d.ts',
|
'index.d.ts',
|
||||||
'index.js',
|
'index.js',
|
||||||
'raw-errors.json',
|
'raw-errors.json',
|
||||||
'raw-schema.d.ts',
|
'mtp-schema.json',
|
||||||
'raw-schema.json',
|
'api-schema.json',
|
||||||
'package.json',
|
'package.json',
|
||||||
'README.md',
|
'README.md',
|
||||||
]
|
]
|
||||||
|
@ -39,7 +37,7 @@ function publishSinglePackage(name) {
|
||||||
} else {
|
} else {
|
||||||
// build ts
|
// build ts
|
||||||
cp.execSync(
|
cp.execSync(
|
||||||
'yarn run ' + (name === 'crypto-node' ? 'build-ts' : 'build'),
|
'pnpm run ' + (name === 'crypto-node' ? 'build-ts' : 'build'),
|
||||||
{
|
{
|
||||||
cwd: dir,
|
cwd: dir,
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
|
@ -56,15 +54,9 @@ function publishSinglePackage(name) {
|
||||||
content = content.replace('/// <reference types="node" />', '')
|
content = content.replace('/// <reference types="node" />', '')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (content.match(/@mtcute\/[a-z]+\/src/)) {
|
if (content.match(/@mtcute\/[a-z-]+\/src/)) {
|
||||||
changed = true
|
changed = true
|
||||||
content = content.replace(/(@mtcute\/[a-z]+)\/src/g, '$1')
|
content = content.replace(/(@mtcute\/[a-z-]+)\/src/g, '$1')
|
||||||
}
|
|
||||||
|
|
||||||
if (content.trim().match(/^export {};?$/)) {
|
|
||||||
// no public exports, we can safely remove this module
|
|
||||||
changed = false
|
|
||||||
fs.unlinkSync(f)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) fs.writeFileSync(f, content)
|
if (changed) fs.writeFileSync(f, content)
|
||||||
|
@ -75,9 +67,9 @@ function publishSinglePackage(name) {
|
||||||
let content = fs.readFileSync(f, 'utf8')
|
let content = fs.readFileSync(f, 'utf8')
|
||||||
let changed = false
|
let changed = false
|
||||||
|
|
||||||
if (content.match(/@mtcute\/[a-z]+\/src/)) {
|
if (content.match(/@mtcute\/[a-z-]+\/src/)) {
|
||||||
changed = true
|
changed = true
|
||||||
content = content.replace(/(@mtcute\/[a-z]+)\/src/g, '$1')
|
content = content.replace(/(@mtcute\/[a-z-]+)\/src/g, '$1')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changed) fs.writeFileSync(f, content)
|
if (changed) fs.writeFileSync(f, content)
|
||||||
|
@ -192,9 +184,28 @@ function publishSinglePackage(name) {
|
||||||
throw new Error(`${name}'s package.json does not contain "main"`)
|
throw new Error(`${name}'s package.json does not contain "main"`)
|
||||||
|
|
||||||
// since "src" is compiled to "dist", we need to remove that prefix
|
// since "src" is compiled to "dist", we need to remove that prefix
|
||||||
packJson.main = packJson.main.replace(/^(?:\.\/)?src\//, '')
|
packJson.main = packJson.main
|
||||||
|
.replace(/^(?:\.\/)?src\//, '')
|
||||||
|
.replace(/\.ts$/, '.js')
|
||||||
packJson.private = false
|
packJson.private = false
|
||||||
|
|
||||||
|
function replaceWorkspaceDependencies(field) {
|
||||||
|
if (packJson[field]) {
|
||||||
|
const dependencies = packJson[field]
|
||||||
|
for (const name of Object.keys(dependencies)) {
|
||||||
|
const value = dependencies[name]
|
||||||
|
if (value.startsWith('workspace:')) {
|
||||||
|
dependencies[name] = value.replace('workspace:', '')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
replaceWorkspaceDependencies('dependencies')
|
||||||
|
replaceWorkspaceDependencies('devDependencies')
|
||||||
|
replaceWorkspaceDependencies('peerDependencies')
|
||||||
|
replaceWorkspaceDependencies('optionalDependencies')
|
||||||
|
|
||||||
fs.writeFileSync(
|
fs.writeFileSync(
|
||||||
path.join(dir, 'dist/package.json'),
|
path.join(dir, 'dist/package.json'),
|
||||||
JSON.stringify(packJson, null, 4)
|
JSON.stringify(packJson, null, 4)
|
||||||
|
@ -225,7 +236,7 @@ function publishSinglePackage(name) {
|
||||||
console.log('[i] Publishing %s', name)
|
console.log('[i] Publishing %s', name)
|
||||||
|
|
||||||
// publish to npm
|
// publish to npm
|
||||||
cp.execSync('yarn publish', {
|
cp.execSync('npm publish', {
|
||||||
cwd: dir,
|
cwd: dir,
|
||||||
stdio: 'inherit',
|
stdio: 'inherit',
|
||||||
})
|
})
|
||||||
|
@ -243,6 +254,7 @@ if (require.main === module) {
|
||||||
if (arg === 'all') {
|
if (arg === 'all') {
|
||||||
for (const f of fs.readdirSync(path.join(__dirname, '../packages'))) {
|
for (const f of fs.readdirSync(path.join(__dirname, '../packages'))) {
|
||||||
if (LOCAL.indexOf(f) > -1) continue
|
if (LOCAL.indexOf(f) > -1) continue
|
||||||
|
if (f[0] === '.') continue
|
||||||
|
|
||||||
publishSinglePackage(f)
|
publishSinglePackage(f)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue