mirror of https://github.com/status-im/js-waku.git
Move cli chat to examples folder
This commit is contained in:
parent
906d118d7d
commit
abd5709f86
|
@ -0,0 +1,45 @@
|
|||
name: Examples CI
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- 'main'
|
||||
- 'staging'
|
||||
- 'trying'
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
examples_build_and_test:
|
||||
strategy:
|
||||
matrix:
|
||||
example: [ cli-chat ]
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Install NodeJS
|
||||
uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: '14'
|
||||
|
||||
- name: Cache npm cache
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: examples-node-v1-${{ hashFiles('**/package-lock.json') }}
|
||||
|
||||
- name: "[js-waku] install using npm ci"
|
||||
uses: bahmutov/npm-install@v1
|
||||
|
||||
- name: "[js-waku] build"
|
||||
run: npm run build
|
||||
|
||||
- name: ${{ matrix.example }} install using npm i
|
||||
run: npm install
|
||||
working-directory: examples/${{ matrix.example }}
|
||||
|
||||
- name: ${{ matrix.example }} test
|
||||
run: npm run test
|
||||
working-directory: examples/${{ matrix.example }}
|
|
@ -67,8 +67,11 @@ Then, install and run:
|
|||
|
||||
```shell
|
||||
git clone https://github.com/status-im/js-waku/ ; cd js-waku
|
||||
npm install
|
||||
npm run chat -- --staticNode /ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ
|
||||
npm install # Install dependencies for js-waku
|
||||
npm run build # Build js-waku
|
||||
cd examples/cli-chat
|
||||
npm install # Install dependencies for the cli app
|
||||
npm run start -- --staticNode /ip4/134.209.139.210/tcp/30303/p2p/16Uiu2HAmPLe7Mzm8TsYUubgCAW1aJoeFScxrLj8ppHFivPo97bUZ
|
||||
```
|
||||
|
||||
You can also specify an optional `listenAddr` parameter (.e.g `--listenAddr /ip4/0.0.0.0/tcp/7777/ws`).
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
status = [
|
||||
"build_and_test (14, ubuntu-latest)",
|
||||
"build_and_test (14, macos-latest)",
|
||||
"web_chat_build_and_test"
|
||||
"web_chat_build_and_test",
|
||||
"examples_build_and_test (cli-chat)"
|
||||
]
|
||||
block_labels = ["work-in-progress"]
|
||||
delete_merged_branches = true
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"root": true,
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": { "project": "./tsconfig.json" },
|
||||
"env": { "es6": true },
|
||||
"ignorePatterns": ["node_modules"],
|
||||
"plugins": ["import", "eslint-comments", "functional"],
|
||||
"extends": [
|
||||
"eslint:recommended",
|
||||
"plugin:eslint-comments/recommended",
|
||||
"plugin:@typescript-eslint/recommended",
|
||||
"plugin:import/typescript",
|
||||
"prettier",
|
||||
"prettier/@typescript-eslint"
|
||||
],
|
||||
"globals": { "BigInt": true, "console": true, "WebAssembly": true },
|
||||
"rules": {
|
||||
"@typescript-eslint/no-non-null-assertion": "off",
|
||||
"@typescript-eslint/explicit-module-boundary-types": "off",
|
||||
"eslint-comments/disable-enable-pair": [
|
||||
"error",
|
||||
{ "allowWholeFile": true }
|
||||
],
|
||||
"eslint-comments/no-unused-disable": "error",
|
||||
"import/order": [
|
||||
"error",
|
||||
{ "newlines-between": "always", "alphabetize": { "order": "asc" } }
|
||||
],
|
||||
"no-constant-condition": ["error", { "checkLoops": false }],
|
||||
"sort-imports": [
|
||||
"error",
|
||||
{ "ignoreDeclarationSort": true, "ignoreCase": true }
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
# Generated directories:
|
||||
.nyc_output/
|
||||
node_modules/
|
||||
/tsconfig.tsbuildinfo
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"extension": ["ts"],
|
||||
"spec": "src/**/*.spec.ts",
|
||||
"require": "ts-node/register"
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
# A NodeJS CLI Chat App powered by js-waku
|
||||
|
||||
See js-waku [README](../../README.md#cli-chat-app-nodejs) for details.
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,76 @@
|
|||
{
|
||||
"name": "js-waku-cli-chat",
|
||||
"version": "1.0.0",
|
||||
"description": "A NodeJS CLI Chat App powered by js-waku",
|
||||
"main": "./index.ts",
|
||||
"repository": "https://github.com/status-im/js-waku",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"keywords": [
|
||||
"waku",
|
||||
"decentralised",
|
||||
"communication"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "run-s build:*",
|
||||
"build:main": "tsc -p tsconfig.json",
|
||||
"fix": "run-s fix:*",
|
||||
"fix:prettier": "prettier \"src/**/*.ts\" \"./*.json\" --write",
|
||||
"fix:lint": "eslint src --ext .ts --fix",
|
||||
"start": "ts-node src/index.ts",
|
||||
"test": "run-s build test:*",
|
||||
"test:lint": "eslint src --ext .ts",
|
||||
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" --list-different",
|
||||
"test:spelling": "cspell \"{README.md,src/**/*.ts}\" -c ../../.cspell.json",
|
||||
"test:unit": "nyc --silent mocha",
|
||||
"watch:build": "tsc -p tsconfig.json -w",
|
||||
"watch:test": "nyc --silent mocha --watch",
|
||||
"version": "standard-version",
|
||||
"reset-hard": "git clean -dfx && git reset --hard && npm i"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=14"
|
||||
},
|
||||
"dependencies": {
|
||||
"libp2p-tcp": "^0.15.4",
|
||||
"prompt-sync": "^4.2.0",
|
||||
"waku": "../../build/main/lib"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@istanbuljs/nyc-config-typescript": "^1.0.1",
|
||||
"@types/app-root-path": "^1.2.4",
|
||||
"@types/chai": "^4.2.15",
|
||||
"@types/mocha": "^8.2.2",
|
||||
"@types/node": "^14.14.31",
|
||||
"@typescript-eslint/eslint-plugin": "^4.0.1",
|
||||
"@typescript-eslint/parser": "^4.0.1",
|
||||
"chai": "^4.3.4",
|
||||
"cspell": "^4.1.0",
|
||||
"eslint": "^7.8.0",
|
||||
"eslint-config-prettier": "^6.11.0",
|
||||
"eslint-plugin-eslint-comments": "^3.2.0",
|
||||
"eslint-plugin-functional": "^3.0.2",
|
||||
"eslint-plugin-import": "^2.22.0",
|
||||
"mocha": "^8.3.2",
|
||||
"npm-run-all": "^4.1.5",
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^2.1.1",
|
||||
"standard-version": "^9.0.0",
|
||||
"ts-node": "^9.1.1",
|
||||
"typedoc": "^0.20.29",
|
||||
"typescript": "^4.0.2"
|
||||
},
|
||||
"prettier": {
|
||||
"singleQuote": true
|
||||
},
|
||||
"files": [
|
||||
"!**/*.spec.*",
|
||||
"!**/*.json",
|
||||
"README.md"
|
||||
],
|
||||
"nyc": {
|
||||
"extends": "@istanbuljs/nyc-config-typescript",
|
||||
"exclude": [
|
||||
"**/*.spec.js"
|
||||
]
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
import { expect } from 'chai';
|
||||
import { ChatMessage } from 'waku/chat_message';
|
||||
|
||||
import { formatMessage } from './chat';
|
||||
|
||||
describe('CLI Chat app', () => {
|
||||
it('Format message', () => {
|
||||
const date = new Date(234325324);
|
||||
const chatMessage = new ChatMessage(date, 'alice', 'Hello world!');
|
||||
|
||||
expect(formatMessage(chatMessage)).to.match(/^<.*> alice: Hello world!$/);
|
||||
});
|
||||
});
|
|
@ -3,16 +3,15 @@ import util from 'util';
|
|||
|
||||
import TCP from 'libp2p-tcp';
|
||||
import { multiaddr, Multiaddr } from 'multiaddr';
|
||||
|
||||
import { ChatMessage } from '../lib/chat_message';
|
||||
import Waku from '../lib/waku';
|
||||
import { WakuMessage } from '../lib/waku_message';
|
||||
import { RelayDefaultTopic } from '../lib/waku_relay';
|
||||
import { StoreCodec } from '../lib/waku_store';
|
||||
import { ChatMessage } from 'waku/chat_message';
|
||||
import Waku from 'waku/waku';
|
||||
import { WakuMessage } from 'waku/waku_message';
|
||||
import { RelayDefaultTopic } from 'waku/waku_relay';
|
||||
import { StoreCodec } from 'waku/waku_store';
|
||||
|
||||
const ChatContentTopic = 'dingpu';
|
||||
|
||||
(async function (): Promise<void> {
|
||||
export default async function startChat(): Promise<void> {
|
||||
const opts = processArguments();
|
||||
|
||||
const waku = await Waku.create({
|
||||
|
@ -50,7 +49,7 @@ const ChatContentTopic = 'dingpu';
|
|||
const wakuMsg = WakuMessage.decode(event.data);
|
||||
if (wakuMsg.payload) {
|
||||
const chatMsg = ChatMessage.decode(wakuMsg.payload);
|
||||
printMessage(chatMsg);
|
||||
console.log(formatMessage(chatMsg));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -75,7 +74,7 @@ const ChatContentTopic = 'dingpu';
|
|||
messages?.map((msg) => {
|
||||
if (msg.payload) {
|
||||
const chatMsg = ChatMessage.decode(msg.payload);
|
||||
printMessage(chatMsg);
|
||||
console.log(formatMessage(chatMsg));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -91,7 +90,7 @@ const ChatContentTopic = 'dingpu';
|
|||
const msg = WakuMessage.fromBytes(chatMessage.encode(), ChatContentTopic);
|
||||
await waku.relay.send(msg);
|
||||
}
|
||||
})();
|
||||
}
|
||||
|
||||
interface Options {
|
||||
staticNode?: Multiaddr;
|
||||
|
@ -123,7 +122,7 @@ function processArguments(): Options {
|
|||
return opts;
|
||||
}
|
||||
|
||||
function printMessage(chatMsg: ChatMessage): void {
|
||||
export function formatMessage(chatMsg: ChatMessage): string {
|
||||
const timestamp = chatMsg.timestamp.toLocaleString([], {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
|
@ -131,5 +130,5 @@ function printMessage(chatMsg: ChatMessage): void {
|
|||
minute: '2-digit',
|
||||
hour12: false,
|
||||
});
|
||||
console.log(`<${timestamp}> ${chatMsg.nick}: ${chatMsg.message}`);
|
||||
return `<${timestamp}> ${chatMsg.nick}: ${chatMsg.message}`;
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import startChat from './chat';
|
||||
|
||||
(async () => {
|
||||
await startChat();
|
||||
})();
|
|
@ -0,0 +1,5 @@
|
|||
declare module 'libp2p-tcp' {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
const TCP: any;
|
||||
export = TCP;
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"incremental": true,
|
||||
"target": "es2017",
|
||||
"rootDir": "src",
|
||||
"noEmit": true,
|
||||
"moduleResolution": "node",
|
||||
"module": "commonjs",
|
||||
"declaration": true,
|
||||
"inlineSourceMap": true,
|
||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
|
||||
"resolveJsonModule": true /* Include modules imported with .json extension. */,
|
||||
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
|
||||
/* Strict Type-Checking Options */
|
||||
"noImplicitAny": true /* Raise error on expressions and declarations with an implied 'any' type. */,
|
||||
"strictNullChecks": true /* Enable strict null checks. */,
|
||||
"strictFunctionTypes": true /* Enable strict checking of function types. */,
|
||||
"strictPropertyInitialization": true /* Enable strict checking of property initialization in classes. */,
|
||||
"noImplicitThis": true /* Raise error on 'this' expressions with an implied 'any' type. */,
|
||||
"alwaysStrict": true /* Parse in strict mode and emit "use strict" for each source file. */,
|
||||
|
||||
/* Additional Checks */
|
||||
"noUnusedLocals": true /* Report errors on unused locals. */,
|
||||
"noUnusedParameters": true /* Report errors on unused parameters. */,
|
||||
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,
|
||||
"noFallthroughCasesInSwitch": true /* Report errors for fallthrough cases in switch statement. */,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
|
||||
/* Debugging Options */
|
||||
"traceResolution": false /* Report module resolution log messages. */,
|
||||
"listEmittedFiles": false /* Print names of generated files part of the compilation. */,
|
||||
"listFiles": false /* Print names of files part of the compilation. */,
|
||||
"pretty": true /* Stylize errors and messages using color and context. */,
|
||||
|
||||
// Due to broken types in indirect dependencies
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Experimental Options */
|
||||
// "experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
|
||||
// "emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,
|
||||
|
||||
"lib": ["es2017"],
|
||||
"types": ["node", "mocha"],
|
||||
"typeRoots": ["node_modules/@types", "src/types"]
|
||||
},
|
||||
"include": ["src/**/*.ts"],
|
||||
"exclude": ["node_modules/**"],
|
||||
"compileOnSave": false,
|
||||
"ts-node": {
|
||||
"files": true
|
||||
}
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
"packages": {
|
||||
"": {
|
||||
"version": "1.0.0",
|
||||
"license": "MIT",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"dependencies": {
|
||||
"@bitauth/libauth": "^1.17.1",
|
||||
"debug": "^4.3.1",
|
||||
|
@ -62,7 +62,7 @@
|
|||
"typescript": "^4.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
"node": ">=14"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/code-frame": {
|
||||
|
|
|
@ -7,7 +7,11 @@
|
|||
"module": "build/module/index.js",
|
||||
"repository": "https://github.com/status-im/js-waku",
|
||||
"license": "MIT OR Apache-2.0",
|
||||
"keywords": ["waku", "decentralised", "communication"],
|
||||
"keywords": [
|
||||
"waku",
|
||||
"decentralised",
|
||||
"communication"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "run-s build:*",
|
||||
"build:main": "tsc -p tsconfig.json",
|
||||
|
@ -19,7 +23,6 @@
|
|||
"pretest:1-init-git-submodules": "[ -f './nim-waku/build/wakunode2' ] || git submodule update --init --recursive",
|
||||
"pretest:2-build-nim-waku": "[ -f './nim-waku/build/wakunode2' ] || run-s nim-waku:build",
|
||||
"nim-waku:build": "(cd nim-waku; NIMFLAGS=\"-d:chronicles_colors=off -d:chronicles_sinks=textlines -d:chronicles_log_level=TRACE\" make -j$(nproc --all 2>/dev/null || echo 2) wakunode2)",
|
||||
"chat": "ts-node src/chat/index.ts",
|
||||
"test": "run-s build test:*",
|
||||
"test:lint": "eslint src --ext .ts",
|
||||
"test:prettier": "prettier \"src/**/*.ts\" \"./*.json\" --list-different",
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
"react": "^16.14.0",
|
||||
"react-dom": "^16.14.0",
|
||||
"server-name-generator": "^1.0.5",
|
||||
"waku": "file:../build/main/lib",
|
||||
"waku-chat": "file:../build/main/chat",
|
||||
"waku": "../build/main/lib",
|
||||
"web-vitals": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -31,7 +30,9 @@
|
|||
"typescript": "^4.2.4"
|
||||
}
|
||||
},
|
||||
"../build/main/chat": {},
|
||||
"../build/main/chat": {
|
||||
"extraneous": true
|
||||
},
|
||||
"../build/main/lib": {},
|
||||
"node_modules/@babel/code-frame": {
|
||||
"version": "7.12.13",
|
||||
|
@ -22888,10 +22889,6 @@
|
|||
"resolved": "../build/main/lib",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/waku-chat": {
|
||||
"resolved": "../build/main/chat",
|
||||
"link": true
|
||||
},
|
||||
"node_modules/walker": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/walker/-/walker-1.0.7.tgz",
|
||||
|
@ -43276,9 +43273,6 @@
|
|||
"waku": {
|
||||
"version": "file:../build/main/lib"
|
||||
},
|
||||
"waku-chat": {
|
||||
"version": "file:../build/main/chat"
|
||||
},
|
||||
"walker": {
|
||||
"version": "1.0.7",
|
||||
"resolved": "https://registry.npmjs.org/walker/-/walker-1.0.7.tgz",
|
||||
|
|
|
@ -8,8 +8,7 @@
|
|||
"react": "^16.14.0",
|
||||
"react-dom": "^16.14.0",
|
||||
"server-name-generator": "^1.0.5",
|
||||
"waku": "file:../build/main/lib",
|
||||
"waku-chat": "file:../build/main/chat",
|
||||
"waku": "../build/main/lib",
|
||||
"web-vitals": "^1.1.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -2,7 +2,7 @@ import { multiaddr } from 'multiaddr';
|
|||
import PeerId from 'peer-id';
|
||||
import { useEffect, useState } from 'react';
|
||||
import './App.css';
|
||||
import { ChatMessage } from 'waku-chat/chat_message';
|
||||
import { ChatMessage } from 'waku/chat_message';
|
||||
import { WakuMessage } from 'waku/waku_message';
|
||||
import { RelayDefaultTopic } from 'waku/waku_relay';
|
||||
import { StoreCodec } from 'waku/waku_store';
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { useEffect, useRef } from 'react';
|
||||
import { ChatMessage } from '../../build/main/chat/chat_message';
|
||||
import { ChatMessage } from 'waku/chat_message';
|
||||
import {
|
||||
Message,
|
||||
MessageText,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { useState } from 'react';
|
||||
import { ChatMessage } from 'waku-chat/chat_message';
|
||||
import { ChatMessage } from 'waku/chat_message';
|
||||
import { WakuMessage } from 'waku/waku_message';
|
||||
import { ChatContentTopic } from './App';
|
||||
import ChatList from './ChatList';
|
||||
|
|
Loading…
Reference in New Issue