diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 00000000..eabf7327 Binary files /dev/null and b/.DS_Store differ diff --git a/.babelrc b/.babelrc new file mode 100644 index 00000000..ddf4051f --- /dev/null +++ b/.babelrc @@ -0,0 +1,15 @@ +{ + "presets": [ + "@babel/typescript", + [ + "@babel/preset-env", + { + "targets": { "browsers": "defaults, not ie 11", "node": true }, + "modules": false, + "useBuiltIns": false, + "loose": true + } + ] + ], + "plugins": ["@babel/plugin-proposal-optional-chaining", "@babel/plugin-transform-modules-commonjs"] +} diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml new file mode 100644 index 00000000..c7641d25 --- /dev/null +++ b/.github/workflows/cd.yml @@ -0,0 +1,46 @@ +name: NPM publish CD workflow + +on: + release: + # This specifies that the build will be triggered when we publish a release + types: [published] + +jobs: + build: + + # Run on latest version of ubuntu + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + # "ref" specifies the branch to check out. + # "github.event.release.target_commitish" is a global variable and specifies the branch the release targeted + ref: ${{ github.event.release.target_commitish }} + # install Node.js + - name: Use Node.js 14 + uses: actions/setup-node@v1 + with: + node-version: 14 + # Specifies the registry, this field is required! + registry-url: https://npm.pkg.github.com/ + scope: "@Yuripetusko" + # clean install of your projects' deps. We use "npm ci" to avoid package lock changes + - run: yarn install + # set up git since we will later push to the repo + - run: git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" && git config --global user.name "$GITHUB_ACTOR" + # upgrade npm version in package.json to the tag used in the release. + - run: yarn version ${{ github.event.release.tag_name }} + # build the project + - run: yarn build + # run tests just in case + - run: yarn test + # publish to NPM -> there is one caveat, continue reading for the fix + - run: yarn publish + env: + NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} + # push the version changes to GitHub + - run: git push + env: + # The secret is passed automatically. Nothing to configure. + github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 00000000..3b11df6a --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,15 @@ +name: Tests CI +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run unit tests + uses: actions/setup-node@v1 + with: + node-version: '14' + - run: yarn install + - run: yarn test + + diff --git a/.gitignore b/.gitignore index 51ee8e6b..aeb33a5b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,8 +4,9 @@ build archive .vscode .idea +.npmrc +dist -/dist/rmrk.js /remarks*.json /dump-*.json -throwaway.js \ No newline at end of file +throwaway.js diff --git a/README.md b/README.md index d433df8f..df33355c 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,52 @@ Typescript implementation of the [RMRK spec](https://github.com/Swader/rmrk-spec/). + + +## Installation + +> Note: NodeJS 14+ is required. Please install with [NVM](https://nvm.sh). + +`yarn install git+https://github.com/Swader/rmrk-tools` + ## Usage +### ESM / Typescript + +``` +import { fetchRemarks, utils, Consolidator } from 'rmrk-tools'; +import { ApiPromise, WsProvider } from '@polkadot/api'; + +const wsProvider = new WsProvider('wss://node.rmrk.app'); + +const fetchAndConsolidate = async () => { + try { + const api = await ApiPromise.create({ provider: wsProvider }); + const to = await utils.getLatestFinalizedBlock(api); + + const remarkBlocks = await fetchRemarks(api, 6431422, to, ['']); + if (remarkBlocks && !isEmpty(remarkBlocks)) { + const remarks = utils.getRemarksFromBlocks(remarkBlocks); + const consolidator = new Consolidator(); + const { nfts, collections } = consolidator.consolidate(remarks); + console.log('Consolidated nfts:', nfts); + console.log('Consolidated collections:', collections); + } + } catch (error) { + console.log(error) + } +} +``` + +### Browser + +``` + + +``` + TBD ## Helper Tools @@ -15,7 +59,7 @@ Grabs all `system.remark` extrinsics in a block range and logs an array of them Export functionality will be added soon (SQL and file, total and in chunks). ```bash -yarn fetch +yarn cli:fetch ``` Optional parameters: @@ -61,7 +105,7 @@ The return data will look like this: Takes as input a JSON file and processes all remarks within it to reach a final state of the NFT ecosystem based on that JSON. ```bash - yarn consolidate --json=dumps/remarks-4892957-5437981-0x726d726b.json + yarn cli:consolidate --json=dumps/remarks-4892957-5437981-0x726d726b.json ``` Todo: @@ -78,7 +122,7 @@ Todo: A local chain must be running in `--dev` mode for this to work. ```bash -yarn seed --folder=[folder] +yarn cli:seed --folder=[folder] ``` When running a local chain, you can run `yarn seed` to populate the chain with pre-written NFT configurations. This is good for testing UIs, wallets, etc. It will use the unlocked ALICE, BOB, and CHARLIE accounts so `--dev` is required here. diff --git a/dist/index.html b/browser/index.html similarity index 76% rename from dist/index.html rename to browser/index.html index f1e76625..84c99c35 100644 --- a/dist/index.html +++ b/browser/index.html @@ -13,6 +13,7 @@