mirror of
https://github.com/hexedtech/codemp.git
synced 2024-12-22 21:04:53 +01:00
feat(js): multi-platform publishing
added loader index, moved directories around a bit to better work with napi
This commit is contained in:
parent
5ca3fe52d7
commit
4be0e3481b
4 changed files with 410 additions and 4 deletions
4
dist/js/package.json
vendored
4
dist/js/package.json
vendored
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"name": "codemp",
|
||||
"version": "0.0.0"
|
||||
}
|
89
dist/js/publish/README.md
vendored
Normal file
89
dist/js/publish/README.md
vendored
Normal file
|
@ -0,0 +1,89 @@
|
|||
[![codemp](https://codemp.dev/static/banner.png)](https://codemp.dev)
|
||||
|
||||
[![Actions Status](https://github.com/hexedtech/codemp/actions/workflows/ci.yml/badge.svg)](https://github.com/hexedtech/codemp/actions)
|
||||
[![docs.rs](https://img.shields.io/docsrs/codemp)](https://docs.rs/codemp/0.7.0-beta.2/codemp/)
|
||||
[![Crates.io Version](https://img.shields.io/crates/v/codemp)](https://crates.io/crates/codemp)
|
||||
[![NPM Version](https://img.shields.io/npm/v/codemp)](https://npmjs.org/package/codemp)
|
||||
[![PyPI - Version](https://img.shields.io/pypi/v/codemp)](https://pypi.org/project/codemp)
|
||||
[![Crates.io License](https://img.shields.io/crates/l/codemp)](https://github.com/hexedtech/codemp/blob/dev/LICENSE)
|
||||
[![Gitter](https://img.shields.io/gitter/room/hexedtech/codemp)](https://gitter.im/hexedtech/codemp)
|
||||
|
||||
> `codemp` is a **collaborative** text editing solution to work remotely.
|
||||
|
||||
It seamlessly integrates in your editor providing remote cursors and instant text synchronization,
|
||||
as well as a remote virtual workspace for you and your team.
|
||||
|
||||
> `codemp` is build with state-of-the-art CRDT technology, guaranteeing eventual consistency.
|
||||
|
||||
This means everyone in a workspace will always be working on the exact same file _eventually_:
|
||||
even under unreliable networks or constrained resources, the underlying CRDT will always reach a
|
||||
convergent state across all users. Even with this baseline, `codemp`'s protocol is optimized for speed
|
||||
and low network footprint, meaning even slow connections can provide stable real-time editing.
|
||||
|
||||
The full documentation is available on [docs.rs](https://docs.rs/codemp/0.7.0-beta.2/codemp/).
|
||||
|
||||
# Usage
|
||||
`codemp` is primarily used as a plugin in your editor of choice.
|
||||
|
||||
## Installation
|
||||
> [!IMPORTANT]
|
||||
> The editor plugins are in active development. Expect frequent changes.
|
||||
|
||||
`codemp` is available as a plugin for a growing number of text editors. Currently we support:
|
||||
- [NeoVim](https://github.com/hexedtech/codemp-nvim)
|
||||
- [VSCode](https://github.com/hexedtech/codemp-vscode)
|
||||
- [Sublime Text](https://github.com/hexedtech/codemp-sublime)
|
||||
<!-- - [IntelliJ Platform](https://github.com/hexedtech/codemp-intellij) -->
|
||||
|
||||
## Registration
|
||||
The `codemp` protocol is [openly available](https://github.com/hexedtech/codemp-proto/) and servers may be freely developed with it.
|
||||
|
||||
A reference instance is provided by hexed.technology at [codemp.dev](https://codemp.dev). You may create an account for it [here](https://codemp.dev/register).
|
||||
During the initial closed beta, registrations will require an invite code. Get in contact if interested.
|
||||
|
||||
An open beta is going to follow with free access to a single workspace per user.
|
||||
After such period, [codemp.dev](https://codemp.dev) will switch to a subscription-based model.
|
||||
|
||||
# Development
|
||||
This is the main client library for `codemp`. It provides a batteries-included fully-featured `Client`, managed by the library itself, and exposes a number of functions to interact with it. The host program can obtain a `Client` handle by connecting, and from that reference can retrieve every other necessary component.
|
||||
|
||||
`codemp` is primarily a rlib and can be used as such, but is also available in other languages via FFI.
|
||||
|
||||
Adding a dependency on `codemp` is **easy**:
|
||||
|
||||
### From Rust
|
||||
Just `cargo add codemp` and check the docs for some examples.
|
||||
|
||||
### From supported languages
|
||||
We provide first-class bindings for:
|
||||
- [JavaScript](./dist/js/README.md): available from `npm` as [`codemp`](https://npmjs.org/package/codemp)
|
||||
- [Python](./dist/lua/README.md): available from `PyPI` as [`codemp`](https://pypi.org/project/codemp)
|
||||
- [Lua](./dist/lua/README.md): run `cargo build --features=lua`
|
||||
- [Java](./dist/java/README.md): run `gradle build` in `dist/java/` (requires Gradle)
|
||||
|
||||
As a design philosophy, our binding APIs attempt to perfectly mimic their Rust counterparts, so the main documentation can still be referenced as source of truth.
|
||||
Refer to specific language documentation for specifics, differences and quirks.
|
||||
|
||||
### From other languages
|
||||
> [!IMPORTANT]
|
||||
> The common C bindings are not available yet!
|
||||
|
||||
Any other language with C FFI capabilities will be able to use `codemp` via its bare C bindings.
|
||||
This may be more complex and may require wrapping the native calls underneath.
|
||||
|
||||
# Get in Touch
|
||||
We love to hear back from users! Be it to give feedback, propose new features or highlight bugs, don't hesitate to reach out!
|
||||
|
||||
## Contacts
|
||||
We have a public [Gitter](https://gitter.im) room available on [gitter.im/hexedtech/codemp](https://gitter.im/hexedtech/codemp).
|
||||
It's possible to freely browse the room history, but to send new messages it will be necessary to sign in with your GitHub account.
|
||||
|
||||
If you have a [Matrix](https://matrix.org) account, you can join the gitter room directly at [#hexedtech_codemp:gitter.im](https://matrix.to/#/#hexedtech_codemp:gitter.im)
|
||||
|
||||
## Contributing
|
||||
If you find bugs or would like to see new features implemented, be sure to open an issue on this repository.
|
||||
|
||||
> [!WARNING]
|
||||
> The CLA necessary for code contributions is not yet available!
|
||||
|
||||
In case you wish to contribute code, that's great! We love external contributions, but we require you to sign our CLA first (available soon).
|
309
dist/js/publish/index.js
vendored
Normal file
309
dist/js/publish/index.js
vendored
Normal file
|
@ -0,0 +1,309 @@
|
|||
// this file is manually adapted from https://github.com/napi-rs/cross-build/blob/main/01-pure-rust/index.js
|
||||
|
||||
const { existsSync, readFileSync } = require('fs')
|
||||
const { join } = require('path')
|
||||
|
||||
const { platform, arch } = process
|
||||
|
||||
let nativeBinding = null
|
||||
let localFileExisted = false
|
||||
let loadError = null
|
||||
|
||||
function isMusl() {
|
||||
// For Node 10
|
||||
if (!process.report || typeof process.report.getReport !== 'function') {
|
||||
try {
|
||||
const lddPath = require('child_process').execSync('which ldd').toString().trim()
|
||||
return readFileSync(lddPath, 'utf8').includes('musl')
|
||||
} catch (e) {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
const { glibcVersionRuntime } = process.report.getReport().header
|
||||
return !glibcVersionRuntime
|
||||
}
|
||||
}
|
||||
|
||||
switch (platform) {
|
||||
case 'android':
|
||||
switch (arch) {
|
||||
case 'arm64':
|
||||
localFileExisted = existsSync(join(__dirname, 'codemp.android-arm64.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.android-arm64.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-android-arm64')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'arm':
|
||||
localFileExisted = existsSync(join(__dirname, 'codemp.android-arm-eabi.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.android-arm-eabi.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-android-arm-eabi')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported architecture on Android ${arch}`)
|
||||
}
|
||||
break
|
||||
case 'win32':
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.win32-x64-msvc.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.win32-x64-msvc.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-win32-x64-msvc')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'ia32':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.win32-ia32-msvc.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.win32-ia32-msvc.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-win32-ia32-msvc')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'arm64':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.win32-arm64-msvc.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.win32-arm64-msvc.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-win32-arm64-msvc')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported architecture on Windows: ${arch}`)
|
||||
}
|
||||
break
|
||||
case 'darwin':
|
||||
localFileExisted = existsSync(join(__dirname, 'codemp.darwin-universal.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.darwin-universal.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-darwin-universal')
|
||||
}
|
||||
break
|
||||
} catch {}
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
localFileExisted = existsSync(join(__dirname, 'codemp.darwin-x64.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.darwin-x64.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-darwin-x64')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'arm64':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.darwin-arm64.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.darwin-arm64.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-darwin-arm64')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported architecture on macOS: ${arch}`)
|
||||
}
|
||||
break
|
||||
case 'freebsd':
|
||||
if (arch !== 'x64') {
|
||||
throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
|
||||
}
|
||||
localFileExisted = existsSync(join(__dirname, 'codemp.freebsd-x64.node'))
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.freebsd-x64.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-freebsd-x64')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
case 'linux':
|
||||
switch (arch) {
|
||||
case 'x64':
|
||||
if (isMusl()) {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.linux-x64-musl.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.linux-x64-musl.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-linux-x64-musl')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
} else {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.linux-x64-gnu.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.linux-x64-gnu.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-linux-x64-gnu')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'arm64':
|
||||
if (isMusl()) {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.linux-arm64-musl.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.linux-arm64-musl.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-linux-arm64-musl')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
} else {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.linux-arm64-gnu.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.linux-arm64-gnu.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-linux-arm64-gnu')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'arm':
|
||||
if (isMusl()) {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.linux-arm-musleabihf.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.linux-arm-musleabihf.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-linux-arm-musleabihf')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
} else {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.linux-arm-gnueabihf.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.linux-arm-gnueabihf.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-linux-arm-gnueabihf')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
}
|
||||
break
|
||||
case 'riscv64':
|
||||
if (isMusl()) {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.linux-riscv64-musl.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.linux-riscv64-musl.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-linux-riscv64-musl')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
} else {
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.linux-riscv64-gnu.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.linux-riscv64-gnu.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-linux-riscv64-gnu')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
}
|
||||
break
|
||||
case 's390x':
|
||||
localFileExisted = existsSync(
|
||||
join(__dirname, 'codemp.linux-s390x-gnu.node')
|
||||
)
|
||||
try {
|
||||
if (localFileExisted) {
|
||||
nativeBinding = require('./codemp.linux-s390x-gnu.node')
|
||||
} else {
|
||||
nativeBinding = require('codemp-linux-s390x-gnu')
|
||||
}
|
||||
} catch (e) {
|
||||
loadError = e
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported architecture on Linux: ${arch}`)
|
||||
}
|
||||
break
|
||||
default:
|
||||
throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
|
||||
}
|
||||
|
||||
if (!nativeBinding) {
|
||||
if (loadError) {
|
||||
throw loadError
|
||||
}
|
||||
throw new Error(`Failed to load native binding`)
|
||||
}
|
||||
|
||||
module.exports = nativeBinding
|
12
dist/js/publish/package.json
vendored
Normal file
12
dist/js/publish/package.json
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"name": "codemp",
|
||||
"version": "0.0.5",
|
||||
"devDependencies": {
|
||||
"@napi-rs/cli": "^2.18.4"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"codemp-win32-x64-msvc": "0.0.4",
|
||||
"codemp-darwin-x64": "0.0.4",
|
||||
"codemp-linux-x64-gnu": "0.0.4"
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue