Skip to content

Commit

Permalink
Migrating shared code to new protocol library
Browse files Browse the repository at this point in the history
  • Loading branch information
aaroncox committed Oct 19, 2023
1 parent 4d9643b commit e360b6a
Show file tree
Hide file tree
Showing 21 changed files with 3,933 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false
27 changes: 27 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"root": true,
"ignorePatterns": ["lib/*", "node_modules/**"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:prettier/recommended"
],
"rules": {
"prettier/prettier": "warn",
"no-console": "warn",
"sort-imports": [
"warn",
{
"ignoreCase": true,
"ignoreDeclarationSort": true
}
],
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-namespace": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-empty-function": "warn",
"no-inner-declarations": "off"
}
}
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
custom: 'https://greymass.com/support-us'
23 changes: 23 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Tests
on: push
jobs:
test-node-js:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
node-version: [14, 16, 18]
name: Node.js v${{ matrix.node-version }}
steps:
- name: Setup Node.js
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- name: Checkout code
uses: actions/checkout@v2
- name: Install dependencies
run: make node_modules
- name: Run checks
run: make check
- name: Run tests
run: make ci-test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
lib/
8 changes: 8 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
arrowParens: "always"
bracketSpacing: false
endOfLine: "lf"
printWidth: 100
semi: false
singleQuote: true
tabWidth: 4
trailingComma: "es5"
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright (c) 2023 Greymass Inc. All Rights Reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

1. Redistribution of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

2. Redistribution in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
may be used to endorse or promote products derived from this software without
specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.

YOU ACKNOWLEDGE THAT THIS SOFTWARE IS NOT DESIGNED, LICENSED OR INTENDED FOR USE
IN THE DESIGN, CONSTRUCTION, OPERATION OR MAINTENANCE OF ANY MILITARY FACILITY.
81 changes: 81 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
SHELL := /bin/bash
SRC_FILES := $(shell find src -name '*.ts')
TEST_FILES := $(shell find test/tests -name '*.ts')
BIN := ./node_modules/.bin
MOCHA_OPTS := -u tdd -r ts-node/register -r tsconfig-paths/register --extension ts
NYC_OPTS := --temp-dir build/nyc_output --report-dir build/coverage

lib: ${SRC_FILES} package.json tsconfig.json node_modules rollup.config.mjs
@${BIN}/rollup -c && touch lib

.PHONY: test
test: node_modules
@TS_NODE_PROJECT='./test/tsconfig.json' MOCK_DIR='./test/data' \
${BIN}/mocha ${MOCHA_OPTS} ${TEST_FILES} --grep '$(grep)'

build/coverage: ${SRC_FILES} ${TEST_FILES} node_modules
@TS_NODE_PROJECT='./test/tsconfig.json' \
${BIN}/nyc ${NYC_OPTS} --reporter=html \
${BIN}/mocha ${MOCHA_OPTS} -R nyan ${TEST_FILES}

.PHONY: coverage
coverage: build/coverage
@open build/coverage/index.html

.PHONY: ci-test
ci-test: node_modules
@TS_NODE_PROJECT='./test/tsconfig.json' MOCK_DIR='./test/data' \
${BIN}/nyc ${NYC_OPTS} --reporter=text \
${BIN}/mocha ${MOCHA_OPTS} -R list ${TEST_FILES}

.PHONY: check
check: node_modules
@${BIN}/eslint src --ext .ts --max-warnings 0 --format unix && echo "Ok"

.PHONY: format
format: node_modules
@${BIN}/eslint src --ext .ts --fix

.PHONY: publish
publish: | distclean node_modules
@git diff-index --quiet HEAD || (echo "Uncommitted changes, please commit first" && exit 1)
@git fetch origin && git diff origin/master --quiet || (echo "Changes not pushed to origin, please push first" && exit 1)
@yarn config set version-tag-prefix "" && yarn config set version-git-message "Version %s"
@yarn publish && git push && git push --tags

.PHONY: docs
docs: build/docs
@open build/docs/index.html

build/docs: $(SRC_FILES) node_modules
@${BIN}/typedoc --out build/docs \
--excludeInternal --excludePrivate --excludeProtected \
--includeVersion --hideGenerator --readme none \
src/index.ts

build/pages: build/docs test/browser.html
@mkdir -p build/pages
@cp -r build/docs/* build/pages/
@cp test/browser.html build/pages/tests.html

.PHONY: deploy-pages
deploy-pages: | clean build/pages node_modules
@${BIN}/gh-pages -d build/pages

test/browser.html: $(SRC_FILES) $(TEST_FILES) test/rollup.config.mjs node_modules
@${BIN}/rollup -c test/rollup.config.mjs

.PHONY: browser-test
browser-test: test/browser.html
@open test/browser.html

node_modules:
yarn install --non-interactive --frozen-lockfile --ignore-scripts

.PHONY: clean
clean:
rm -rf lib/ build/ test/browser.html

.PHONY: distclean
distclean: clean
rm -rf node_modules/
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# @wharfkit/protocol-scatter

A Session Kit wallet plugin for the [Scatter](https://github.com/GetScatter/ScatterDesktop) wallet.

## Usage

Include this wallet plugin while initializing the SessionKit.

**NOTE**: This wallet plugin will only work with the SessionKit and requires a browser-based environment.

```ts
import {WalletPluginScatter} from '@wharfkit/protocol-scatter'

const kit = new SessionKit({
// ... your other options
walletPlugins: [new WalletPluginScatter()],
})
```

## Developing

You need [Make](https://www.gnu.org/software/make/), [node.js](https://nodejs.org/en/) and [yarn](https://classic.yarnpkg.com/en/docs/install) installed.

Clone the repository and run `make` to checkout all dependencies and build the project. See the [Makefile](./Makefile) for other useful targets. Before submitting a pull request make sure to run `make lint`.

---

Made with ☕️ & ❤️ by [Greymass](https://greymass.com), if you find this useful please consider [supporting us](https://greymass.com/support-us).
73 changes: 73 additions & 0 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import fs from 'fs'
import dts from 'rollup-plugin-dts'
import typescript from '@rollup/plugin-typescript'
import commonjs from '@rollup/plugin-commonjs'
import nodePolyfills from 'rollup-plugin-polyfill-node'
import resolve from '@rollup/plugin-node-resolve'
import json from '@rollup/plugin-json'

import {createRequire} from 'module'
const require = createRequire(import.meta.url)
const pkg = require('./package.json')

const name = pkg.name
const license = fs.readFileSync('LICENSE').toString('utf-8').trim()
const banner = `
/**
* ${name} v${pkg.version}
* ${pkg.homepage}
*
* @license
* ${license.replace(/\n/g, '\n * ')}
*/
`.trim()

const external = [...Object.keys(pkg.peerDependencies)]

/** @type {import('rollup').RollupOptions} */
export default [
{
input: 'src/index.ts',
output: {
banner,
file: pkg.main,
format: 'cjs',
sourcemap: true,
exports: 'named',
},
plugins: [
typescript({target: 'es6'}),
commonjs({
defaultIsModuleExports: false,
}),
nodePolyfills(),
resolve({browser: true}),
json(),
],
external,
},
{
input: 'src/index.ts',
output: {
banner,
file: pkg.module,
format: 'esm',
sourcemap: true,
},
plugins: [
typescript({target: 'es2020'}),
commonjs({
defaultIsModuleExports: false,
}),
nodePolyfills(),
resolve({browser: true}),
json(),
],
external,
},
{
input: 'src/index.ts',
output: {banner, file: pkg.types, format: 'esm'},
plugins: [dts()],
},
]
Loading

0 comments on commit e360b6a

Please sign in to comment.