Skip to content

Commit

Permalink
JS SDK support (#1862)
Browse files Browse the repository at this point in the history
feat: major refactor, JS SDK support, CLI user prompts
  • Loading branch information
maxhr authored Aug 8, 2022
1 parent 95c2e24 commit a00488e
Show file tree
Hide file tree
Showing 130 changed files with 63,477 additions and 8,423 deletions.
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
dist
node_modules
templates/contracts/js/src/contract.ts
templates/integration-tests/shared/js-tests/src/main.ava.ts
templates/integration-tests/overrides/js-contract/js-tests/src/main.ava.ts
src/*.js
jest.config.js
_testrun
6 changes: 2 additions & 4 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ rules:
indent:
- warn
- 2
- { "SwitchCase": 1 }
linebreak-style:
- warn
- unix
Expand All @@ -20,7 +21,7 @@ rules:
- single
semi:
- warn
- never
- always
no-console: off
globals:
Cookies: true
Expand All @@ -36,6 +37,3 @@ globals:
testSettings: true
walletAccount: true
window: true
settings:
react:
version: detect
4 changes: 2 additions & 2 deletions .github/workflows/linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install modules
run: yarn
run: npm install
- name: Run ESLint
run: yarn lint --max-warnings 0
run: npm run lint --max-warnings=0
110 changes: 110 additions & 0 deletions .github/workflows/test-e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Tests E2E
on:
workflow_dispatch:

push:
branches:
- 'master'
jobs:
tests-bash:
strategy:
fail-fast: false
matrix:
platform: [ ubuntu-latest, macos-latest ]
nodejs: [ 16 ]
contract: [ js, rust, assemblyscript ]
frontend: [ react, vanilla, none ]
tests: [ js, rust ]
# exclude:
# - frontend: vanilla
# - frontend: none
# include:
# - contract: js
# frontend: vanilla
# tests: js
# - contract: js
# frontend: none
# tests: js
runs-on: ${{ matrix.platform }}
timeout-minutes: 60
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.nodejs }}
- name: Install modules
run: |
npm install
npm run build
- name: Scaffold template
run: |
node index.js _testrun --contract ${{ matrix.contract }} --frontend ${{ matrix.frontend }} --tests ${{ matrix.tests }} --install
- name: Build template
env:
NEAR_ENV: ci
IS_GITHUB_ACTION: true
run: |
cd _testrun
npm run build
- name: Test template
if: matrix.platform != 'macos-latest'
env:
NEAR_ENV: ci
IS_GITHUB_ACTION: true
run: |
cd _testrun
npm run test
# tests-wsl:
# defaults:
# run:
# shell: wsl-bash {0}
# strategy:
# fail-fast: false
# matrix:
# platform: [ windows-latest ]
# nodejs: [ 16 ]
# contract: [ js, rust ]
# frontend: [ react, vanilla, none ]
# tests: [ js, rust ]
# exclude:
# - contract: js
# - tests: js
# runs-on: ${{ matrix.platform }}
# timeout-minutes: 60
# steps:
# - name: Setup WSL
# uses: Vampire/[email protected]
# with:
# distribution: Ubuntu-22.04
# - uses: actions/checkout@v2
# - name: Setup node
# run: |
# sudo apt-get install curl
# curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
# sudo apt-get install -y nodejs
# - name: rust-toolchain
# uses: actions-rs/[email protected]
# with:
# toolchain: stable
# - name: Install modules
# run: |
# npm install
# npm run build
# - name: Scaffold template
# run: |
# node index.js _testrun --contract ${{ matrix.contract }} --frontend ${{ matrix.frontend }} --tests ${{ matrix.tests }} --install
# - name: Build template
# env:
# NEAR_ENV: ci
# IS_GITHUB_ACTION: true
# run: |
# cd _testrun
# npm run build
# - name: Test template
# env:
# NEAR_ENV: ci
# IS_GITHUB_ACTION: true
# run: |
# cd _testrun
# npm run test
14 changes: 3 additions & 11 deletions .github/workflows/test-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@ jobs:
tests:
strategy:
matrix:
platform: [ubuntu-latest, macos-latest]
contract: [assemblyscript, rust]
frontend: ['vanilla', 'react', 'none']
platform: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: '16'
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: wasm32-unknown-unknown
- name: Install modules
run: yarn
run: npm install
- name: Run tests
env:
CONTRACT: ${{ matrix.contract }}
FRONTEND: ${{ matrix.frontend }}
NEAR_ENV: ci
IS_GITHUB_ACTION: true
run: yarn test
run: npm test
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
dist
_testrun

# dependencies
node_modules
/.pnp
.pnp.js
out
package-lock.json
templates/out
/neardev
# testing
/coverage
Expand All @@ -23,7 +24,6 @@ tmp-project
.env.test.local
.env.production.local
.idea
/templates/**/yarn.lock
/templates/*/neardev/dev-account*

npm-debug.log*
Expand Down
2 changes: 1 addition & 1 deletion .gitpod.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
tasks:
- init: yarn install
- init: npm install
github:
prebuilds:
addBadge: true
4 changes: 2 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
contracts/rust/target
contracts/out
templates/contracts/rust/target
templates/contracts/out
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Please note that for technical contributions, NEAR runs a battery of continuous

It's encouraged to write unit tests on new features. Many NEAR repositories have built-in scripts that run tests locally. Tests may check linting and must be addressed.

For example, a repository might have `yarn test` available. It's a good idea to run tests locally before submitting a pull request, as these will be caught during the CI process.
For example, a repository might have `npm test` available. It's a good idea to run tests locally before submitting a pull request, as these will be caught during the CI process.

### Thank you

Expand Down
68 changes: 37 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,62 +1,70 @@
create-near-app
# Create NEAR App
===============
[![Gitpod Ready-to-Code](https://img.shields.io/badge/Gitpod-Ready--to--Code-blue?logo=gitpod)](https://gitpod.io/#https:/nearprotocol/create-near-app)

Quickly build apps backed by the [NEAR](https://near.org) blockchain


Prerequisites
=============
## Prerequisites

Make sure you have a [current version of Node.js](https://nodejs.org/en/about/releases/) installed – we are targeting versions `12+`.
**Note**: if using Node version 13 please be advised that you will need version >= 13.7.0
Make sure you have a [current version of Node.js](https://nodejs.org/en/about/releases/) installed – we are targeting versions `16+`.

Read about other [prerequisites](https://docs.near.org/develop/prerequisites) in our docs.

Getting Started
===============
## Getting Started

To create a new NEAR project run this and follow interactive prompts:

To create a new NEAR project with default settings, you just need one command
npx create-near-app

Using [npm's npx](https://blog.npmjs.org/post/162869356040/introducing-npx-an-npm-package-runner):
Follow the instructions in the README.md in the project you just created! 🚀

npx create-near-app [options] new-awesome-project
You can create contracts written in:

**Or**, if you prefer [yarn](https://classic.yarnpkg.com/en/docs/cli/create/):
- [JavaScript](https://docs.near.org/develop/quickstart-guide)
- [Rust](https://docs.near.org/develop/prerequisites)
- AssemblyScript

yarn create near-app [options] new-awesome-project
You can create a frontend template in:

Without any options, this will create a project with a **vanilla JavaScript** frontend and an [AssemblyScript](https://docs.near.org/develop/quickstart-guide) smart contract
- [React](https://reactjs.org/)
- Vanilla JavaScript

Other options:
For testing we use a sandboxed environment of NEAR (called Workspaces).
You can write the tests in JavaScript or Rust.

* `--frontend=react` – use [React](https://reactjs.org/) for your frontend template
* `--contract=rust` – use [Rust](https://docs.near.org/develop/prerequisites) for your smart contract
### Using CLI arguments to run `create-near-app`

This CLI supports arguments to skip interactive prompts:

Develop your own Dapp
=====================
```shell
npx create-near-app
<project-name>
--contract js|rust|assemblyscript
--frontend vanilla|react|none
--tests js|rust
--install
```

Follow the instructions in the README.md in the project you just created! 🚀
Use `--install` to automatically install dependencies from all `package.json` files.

When using arguments, all arguments are required, except for `--install`.

Getting Help
============
## Getting Help

Check out our [documentation](https://docs.near.org) or chat with us on [Discord](http://near.chat). We'd love to hear from you!


Contributing
============
## Contributing to `create-near-app`

To make changes to `create-near-app` itself:

* clone the repository (Windows users, [use `git clone -c core.symlinks=true`](https://stackoverflow.com/a/42137273/249801))
* in your terminal, enter one of the folders inside `templates`, such as `templates/vanilla`
* now you can run `yarn` to install dependencies and `yarn dev` to run the local development server, just like you can in a new app created with `create-near-app`
* now you can run `npm install` to install dependencies and `npm run dev` to run the local development server, just like you can in a new app created with `create-near-app`


about commit messages
---------------------
#### About commit messages

`create-near-app` uses semantic versioning and auto-generates nice release notes & a changelog all based off of the commits. We do this by enforcing [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/). In general the pattern mostly looks like this:

Expand All @@ -73,8 +81,7 @@ Real world examples can look like this:
If your change should show up in release notes as a feature, use `feat:`. If it should show up as a fix, use `fix:`. Otherwise, you probably want `refactor:` or `chore:`. [More info](https:/conventional-changelog/commitlint/#what-is-commitlint)


Deploy
------
#### Deploy `create-near-app`

If you want to deploy a new version, you will need two prerequisites:

Expand All @@ -85,13 +92,12 @@ If you want to deploy a new version, you will need two prerequisites:

Then run one script:

yarn release
npm run release

Or just `release-it`


License
=======
## License

This repository is distributed under the terms of both the MIT license and the Apache License (Version 2.0).
See [LICENSE](LICENSE) and [LICENSE-APACHE](LICENSE-APACHE) for details.
4 changes: 0 additions & 4 deletions contracts/assemblyscript/.gitignore

This file was deleted.

1 change: 0 additions & 1 deletion contracts/assemblyscript/as-pect.config.js

This file was deleted.

11 changes: 0 additions & 11 deletions contracts/assemblyscript/assembly/__tests__/main.spec.ts

This file was deleted.

13 changes: 0 additions & 13 deletions contracts/assemblyscript/package.json

This file was deleted.

Loading

0 comments on commit a00488e

Please sign in to comment.