Skip to content

Commit

Permalink
Add publish script (Emurgo#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt authored Jul 7, 2020
1 parent 7050377 commit 9fda3d2
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 1,701 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
dist/
rust/target
publish/
rust/target
tsconfig.tsbuildinfo
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,30 @@

**WARNING** this library is experimental.

This is a library for serialization & deserialization of types related to Cardano's Haskell implementation of Shelley.
This is a library for serialization & deserialization of data structures used in Cardano's Haskell implementation of Shelley along with useful utility functions.

Serialization/deserialization code is generated automatically from the CDDL specification using [cddl-codegen](https://github.com/Emurgo/cddl-codegen).

This code is available in:

- Native Rust (this repository)
- [React-Native mobile bindings](https://github.com/Emurgo/react-native-haskell-shelley)
- [nodejs WASM package](https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-nodejs)
- [browser WASM package](https://www.npmjs.com/package/@emurgo/cardano-serialization-lib-browser)

If you are looking for legacy bindings, you can find them at the following:

- [Byron WASM bindings](https://github.com/input-output-hk/js-cardano-wasm/tree/master/cardano-wallet)
- [Jormungandr WASM bindings](https://github.com/emurgo/js-chain-libs)

## Original specs

Here are the location of the original [CDDL](http://cbor.io/tools.html) specifications:

- Byron: [link](https://github.com/input-output-hk/cardano-ledger-specs/blob/master/byron/cddl-spec/byron.cddl)
- Shelley: [link](https://github.com/input-output-hk/cardano-ledger-specs/blob/master/shelley/chain-and-ledger/cddl-spec/shelley.cddl#L72)
- Byron: [link](https://github.com/input-output-hk/cardano-ledger-specs/tree/master/byron/cddl-spec)
- Shelley: [link](https://github.com/input-output-hk/cardano-ledger-specs/tree/master/shelley/chain-and-ledger/executable-spec/cddl-files)

# Building
## Building

If you need to install Rust, do the following:
```
Expand All @@ -25,27 +39,20 @@ To build this repository, do the following:
```
git submodule update --init --recursive
nvm install && nvm use
npm run rust:build
npm run rust:build-nodejs
npm install
```

# Testing
## Testing

```
npm run rust:test
npm run js:test
```

# Generating CDDL instances
## Publishing

First you need to install `cddl`
```
sudo apt install ruby
sudo gem install cddl
sudo gem install cbor-diag
npm run js:publish-nodejs
npm run js:publish-browser
```

You can generate new tests with
1) `cddl specs/shelley.cddl generate 1 > test/name_here.diag`
2) `diag2cbor.rb test/name_here.diag > test/name_here.cbor`

You can combine these together with `cddl specs/shelley.cddl generate 1 | diag2cbor.rb > test/name_here.cbor`
90 changes: 54 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 15 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@
"description": "processing Haskell Shelley testnet",
"main": "dist/index.js",
"scripts": {
"rust:build": "cd rust; wasm-pack build --target=nodejs; wasm-pack pack; cd ..",
"rust:build-nodejs": "rimraf ./rust/pkg && cd rust; wasm-pack build --target=nodejs; wasm-pack pack; cd .. && npm run js:flowgen",
"rust:build-browser": "rimraf ./rust/pkg && cd rust; wasm-pack build --target=browser; wasm-pack pack; cd .. && npm run js:flowgen",
"rust:test": "cd rust; cargo test; cd ..",
"js:build": "rm -rf dist && tsc",
"js:dev": "rimraf ./dist && node ./src/index.ts",
"js:lint": "eslint \"src/**/*.ts\"",
"js:test:watch": "mocha -w",
"js:test": "mocha",
"js:flowgen": "npm run rust:build && flowgen ./rust/pkg/cddl_lib.d.ts -o ./rust/pkg/cddl_lib.js.flow --add-flow-header"
"js:flowgen": "flowgen ./rust/pkg/cardano_serialization_lib.d.ts -o ./rust/pkg/cardano_serialization_lib.js.flow --add-flow-header",
"js:prepublish": "npm run rust:test && rimraf ./publish && cp -r ./rust/pkg ./publish && cp README.md publish/ && cp LICENSE publish/",
"js:publish-nodejs": "npm run rust:build-nodejs && npm run js:prepublish && node ./scripts/publish-helper -nodejs && cd publish && npm publish --access public",
"js:publish-browser": "npm run rust:build-browser && npm run js:prepublish && node ./scripts/publish-helper -browser && cd publish && npm publish --access public"
},
"husky": {
"hooks": {
Expand All @@ -20,25 +24,29 @@
},
"author": "EMURGO",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/Emurgo/cardano-serialization-lib.git"
},
"dependencies": {
"io-ts": "2.2.6",
"io-ts": "2.2.7",
"cbor": "5.0.2",
"@types/cbor": "5.0.0"
},
"devDependencies": {
"@types/chai": "4.2.11",
"@types/mocha": "7.0.2",
"@typescript-eslint/eslint-plugin": "3.4.0",
"@typescript-eslint/parser": "3.4.0",
"@typescript-eslint/eslint-plugin": "3.6.0",
"@typescript-eslint/parser": "3.6.0",
"bip39": "3.0.2",
"chai": "4.2.0",
"eslint": "7.3.1",
"eslint": "7.4.0",
"flowgen": "1.11.0",
"husky": "4.2.5",
"mocha": "8.0.1",
"rust-lib": "file:rust/pkg",
"source-map-support": "0.5.19",
"ts-node": "8.10.2",
"typescript": "3.9.5"
"typescript": "3.9.6"
}
}
26 changes: 13 additions & 13 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "cddl-lib"
name = "cardano-serialization-lib"
version = "0.1.0"
edition = "2018"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Flowtype definitions for cddl_lib
* Flowtype definitions for cardano_serialization_lib
* Generated by Flowgen from a Typescript Definition
* Flowgen v1.11.0
* @flow
Expand Down
9 changes: 9 additions & 0 deletions scripts/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
},
"extends": [
"eslint:recommended",
}
}
12 changes: 12 additions & 0 deletions scripts/publish-helper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require('fs');
const oldPkg = require('../publish/package.json');

const flowFile = 'cardano_serialization_lib.js.flow';
if (oldPkg.files.find(entry => entry === flowFile) == null) {
oldPkg.files.push('cardano_serialization_lib.js.flow');
}
if (oldPkg.name === 'cardano-serialization-lib') {
oldPkg.name = '@emurgo/' + oldPkg.name + process.argv.slice(2)[0];
}
console.log(oldPkg);
fs.writeFileSync('./publish/package.json', JSON.stringify(oldPkg, null, 2));
14 changes: 14 additions & 0 deletions specs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Generating CDDL instances

First you need to install `cddl`
```
sudo apt install ruby
sudo gem install cddl
sudo gem install cbor-diag
```

You can generate new tests with
1) `cddl specs/shelley.cddl generate 1 > test/name_here.diag`
2) `diag2cbor.rb test/name_here.diag > test/name_here.cbor`

You can combine these together with `cddl specs/shelley.cddl generate 1 | diag2cbor.rb > test/name_here.cbor`
Loading

0 comments on commit 9fda3d2

Please sign in to comment.