Skip to content

Commit

Permalink
Merge branch 'master' into vector
Browse files Browse the repository at this point in the history
  • Loading branch information
ailisp committed May 20, 2022
2 parents 182a1b4 + 5b28b91 commit 366c75e
Show file tree
Hide file tree
Showing 10 changed files with 667 additions and 629 deletions.
39 changes: 39 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

.ONESHELL: # Applies to every targets in the file!
QUIET := @

OS = $(shell uname -s)
ARCH = $(shell uname -m)

all: setup build yarn

setup:
cd jsvm && ./setup.sh && cd ..

build: jsvm qjsc

jsvm:
echo "Building jsvm.wasm..."
cd jsvm && ./build.sh && cd ..
cp jsvm/jsvm.wasm res/jsvm.wasm

qjsc:
echo "Building qjsc bytecode compiler"
cd quickjs && ./build.sh && cd ..
cp quickjs/qjsc res/$(OS)-$(ARCH)-qjsc

yarn:
$(QUIET)yarn

clean: clean-vendor clean-node

clean-vendor:
$(QUIET)rm -rf jsvm/vendor

clean-node:
$(QUIET)rm -rf node_modules


.PHONY: all setup build yarn
.PHONY: jsvm qjsc
.PHONY: clean clean-vendor clean-node
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ This README is a work in porgress. The best way to start using `near-sdk-js` is
It is tested on Ubuntu 20.04 and Intel Mac. Other linux and M1 Macs should also work but they're not tested.

1. Make sure you have `wget`, `make`, `cmake` and `nodejs`. On Linux, also make sure you have `gcc`.
2. Run `./rebuild_recources.sh` to get platform specific `qjsc` and `jsvm` contract in `res` folder.
2. Run `make` to get platform specific `qjsc` and `jsvm` contract in `res` folder.

## Usage
1. `cd examples/<example>`
Expand Down Expand Up @@ -35,7 +35,7 @@ near call <jsvm-account> remove_js_contract --accountId <your-account>

1. Build the jsvm contract
```
./rebuild_recources.sh
make
```

2. Go to nearcore, Build and start a local node
Expand Down
35 changes: 22 additions & 13 deletions cli/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ import { babel } from '@rollup/plugin-babel';

import { rollup } from 'rollup';

import { exec } from 'child_process';
import { exec as exec_ } from 'child_process';
import { promisify } from 'util';

const exec = promisify(exec_);

//TODO: build passed file instead of hardcoded one
yargs(hideBin(process.argv))
Expand Down Expand Up @@ -44,25 +47,31 @@ async function build(argv) {

console.log('Creating <>.base64 file with the use of QJSC...');
const SAVE_BYTECODE = './node_modules/near-sdk-js/cli/save_bytecode.js';
const QJSC = './node_modules/near-sdk-js/res/qjsc';
const os = await executeCommand('uname -s', true);
const arch = await executeCommand('uname -m', true);
const QJSC = `./node_modules/near-sdk-js/res/${os}-${arch}-qjsc`;
const TEMP = 'build/contract.h';
const TARGET = 'build/contract.base64';
const CONTRACT_JS_FILE = 'build/contract.js';
await executeCommand(`${QJSC} -c -m -o ${TEMP} -N code ${CONTRACT_JS_FILE}`);
await executeCommand(`node ${SAVE_BYTECODE} ${TEMP} ${TARGET}`);
}

async function executeCommand(command) {
async function executeCommand(command, silent=false) {
console.log(command);
exec(command, (error, stdout, stderr) => {
if (error) {
console.log(error);
process.exit(1);
}
if (stderr) {
console.log(stderr);
process.exit(1);
}
const {error, stdout, stderr} = await exec(command);

if (error) {
console.log(error);
process.exit(1);
}
if (stderr && !silent) {
console.error(stderr);
}

if (silent) {
return stdout.trim();
} else {
console.log(stdout);
});
}
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "near-sdk-js",
"version": "0.1.0",
"version": "0.1.1",
"description": "High Level JavaScript SDK for building smart contracts on NEAR",
"main": "src/index.js",
"type": "module",
Expand Down Expand Up @@ -37,9 +37,9 @@
"yargs": "^17.5.1"
},
"files": [
"contract-builder",
"cli",
"res",
"scripts",
"src"
]
}
}
10 changes: 0 additions & 10 deletions rebuild_resources.sh

This file was deleted.

Binary file added res/Darwin-arm64-qjsc
Binary file not shown.
File renamed without changes.
Binary file added res/Linux-x86_64-qjsc
Binary file not shown.
Binary file modified res/jsvm.wasm
Binary file not shown.
Loading

0 comments on commit 366c75e

Please sign in to comment.