Skip to content

Commit

Permalink
npmify
Browse files Browse the repository at this point in the history
  • Loading branch information
singpolyma committed Jun 19, 2024
1 parent 3cffc8a commit a00b0f2
Show file tree
Hide file tree
Showing 9 changed files with 558 additions and 512 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,14 @@ jobs:
haxelib --quiet install sha
haxelib --quiet install thenshim
haxelib --quiet install hxcpp
haxelib --quiet install hxtsdgen
haxelib --quiet git hxtsdgen https://github.com/singpolyma/hxtsdgen
haxelib --quiet install utest
- name: NPM Dependencies
run: |
cd npm
npm i
- name: Tests
run: make test

Expand All @@ -62,12 +67,12 @@ jobs:
libsnikket.so
cpp/snikket.h
- name: NPM Tarball
run: tar -cjf npm.tar.gz npm/

- name: JS Artifact
uses: actions/upload-artifact@v4
with:
name: browser.js
name: npm.tar.gz
path: |
browser.js
browser.haxe.d.ts
browser.haxe-enums.ts
npm.tar.gz
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
npm/package-lock.json
npm/*.d.ts
npm/snikket.js
npm/snikket-enums.ts
npm/snikket-enums.js
npm/index.js
node_modules
22 changes: 15 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
HAXE_PATH=$$HOME/Software/haxe-4.3.1/hxnodejs/12,1,0/src

.PHONY: all test cpp/output.dso browser.js
.PHONY: all test cpp/output.dso npm/snikket.js

all: browser.js libsnikket.so
all: npm libsnikket.so

test:
haxe test.hxml

browser.js:
haxe browser.hxml
echo "var exports = {};" > browser.js
cat snikket/persistence/*.js >> browser.js
echo "export const { snikket } = exports;" >> browser.js
npm/snikket.js:
haxe js.hxml
sed -i 's/import { snikket }/import { snikket as enums }/' npm/snikket.d.ts
sed -i 's/snikket\.UiState/enums.UiState/g' npm/snikket.d.ts
sed -i 's/snikket\.MessageStatus/enums.MessageStatus/g' npm/snikket.d.ts
sed -i 's/snikket\.MessageDirection/enums.MessageDirection/g' npm/snikket.d.ts
sed -i '1ivar exports = {};' npm/snikket.js
echo "export const snikket = exports.snikket;" >> npm/snikket.js
cd npm && npx tsc --esModuleInterop --lib esnext,dom --target esnext --preserveConstEnums -d index.ts
sed -i '1iimport { snikket as enums } from "./snikket-enums";' npm/index.js

npm: npm/snikket.js snikket/persistence/browser.js
cp snikket/persistence/browser.js npm

cpp/output.dso:
haxe cpp.hxml
Expand Down
2 changes: 1 addition & 1 deletion browser.hxml → js.hxml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ snikket.Push
-D js-es=6
-D hxtsdgen_enums_ts
-D hxtsdgen_namespaced
--js browser.haxe.js
--js npm/snikket.js
27 changes: 27 additions & 0 deletions npm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import browserp from "./browser";
import { snikket as enums } from "./snikket-enums";
import { snikket } from "./snikket";

// TODO: should we autogenerate this?
export import AvailableChat = snikket.AvailableChat;
export import Caps = snikket.Caps;
export import Channel = snikket.Channel;
export import Chat = snikket.Chat;
export import ChatAttachment = snikket.ChatAttachment;
export import ChatMessage = snikket.ChatMessage;
export import Client = snikket.Client;
export import DirectChat = snikket.DirectChat;
export import Identicon = snikket.Identicon;
export import Identity = snikket.Identity;
export import Notification = snikket.Notification;
export import SerializedChat = snikket.SerializedChat;
export import jingle = snikket.jingle;

export import UiState = enums.UiState;
export import MessageStatus = enums.MessageStatus;
export import MessageDirection = enums.MessageDirection;

export namespace persistence {
export import browser = browserp;
export import Dummy = snikket.persistence.Dummy;
}
21 changes: 21 additions & 0 deletions npm/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "snikket-sdk",
"version": "0.0.0",
"description": "Chat SDK",
"main": "index.js",
"files": [
"*.js",
"*.ts"
],
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "Apache-2.0",
"dependencies": {
"sasl-scram-sha-1": "github:singpolyma/js-sasl-scram-sha-1"
},
"devDependencies": {
"typescript": "^5.4.5"
}
}
9 changes: 0 additions & 9 deletions snikket/Chat.hx
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ enum abstract UiState(Int) {
var Closed; // Archived
}

#if js
@:expose("UiState")
class UiStateImpl {
static public final Pinned = UiState.Pinned;
static public final Open = UiState.Open;
static public final Closed = UiState.Closed;
}
#end

#if cpp
@:build(HaxeCBridge.expose())
@:build(HaxeSwiftBridge.expose())
Expand Down
18 changes: 0 additions & 18 deletions snikket/Message.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,13 @@ enum abstract MessageDirection(Int) {
var MessageSent;
}

#if js
@:expose("MessageDirection")
class MessageDirectionImpl {
static public final MessageReceived = MessageDirection.MessageReceived;
static public final MessageSent = MessageDirection.MessageSent;
}
#end

enum abstract MessageStatus(Int) {
var MessagePending; // Message is waiting in client for sending
var MessageDeliveredToServer; // Server acknowledged receipt of the message
var MessageDeliveredToDevice; //The message has been delivered to at least one client device
var MessageFailedToSend; // There was an error sending this message
}

#if js
@:expose("MessageStatus")
class MessageStatusImpl {
static public final MessagePending = MessageStatus.MessagePending;
static public final MessageDeliveredToServer = MessageStatus.MessageDeliveredToServer;
static public final MessageDeliveredToDevice = MessageStatus.MessageDeliveredToDevice;
static public final MessageFailedToSend = MessageStatus.MessageFailedToSend;
}
#end

enum MessageStanza {
ErrorMessageStanza(stanza: Stanza);
ChatMessageStanza(message: ChatMessage);
Expand Down
Loading

0 comments on commit a00b0f2

Please sign in to comment.