Skip to content

Scaffolding a new project

Christian edited this page Apr 17, 2019 · 4 revisions

Once AssemblyScript is properly installed, it provides a handy little utility named asinit to scaffold a new project:

Syntax: asinit [project directory]

Sets up a new AssemblyScript project or updates an existing one.

For example, to create a new project in the current directory:

  asinit .

Example output:

This command will make sure that the following files exist in the project
directory '/home/user/mymodule':

  ./assembly
  Directory holding the AssemblyScript sources being compiled to WebAssembly.

  ./assembly/tsconfig.json
  TypeScript configuration inheriting recommended AssemblyScript settings.

  ./assembly/index.ts
  Exemplary entry file being compiled to WebAssembly to get you started.

  ./build
  Build artifact directory where compiled WebAssembly files are stored.

  ./build/.gitignore
  Git configuration that excludes compiled binaries from source control.

  ./index.js
  Main file loading the WebAssembly module and exporting its exports.

  ./package.json
  Package info containing the necessary commands to compile to WebAssembly.

The command will try to update existing files to match the correct settings
for this instance of the compiler in '/home/user/mymodule/node_modules/assemblyscript'.

Do you want to proceed? [Y/n]

- Making sure that the project directory exists...
  Exists: /home/user/mymodule

- Making sure that the 'assembly' directory exists...
  Created: /home/user/mymodule/assembly

- Making sure that 'assembly/tsconfig.json' is set up...
  Created: /home/user/mymodule/assembly/tsconfig.json

- Making sure that 'assembly/index.ts' exists...
  Created: /home/user/mymodule/assembly/index.ts

- Making sure that the 'build' directory exists...
  Created: /home/user/mymodule/build

- Making sure that 'build/.gitignore' is set up...
  Created: /home/user/mymodule/build/.gitignore

- Making sure that 'package.json' contains the build commands...
  Created: /home/user/mymodule/package.json

- Making sure that 'index.js' exists...
  Created: /home/user/mymodule/index.js

Done!

To edit the entry file, open 'assembly/index.ts' in your editor of choice.
Create as many additional files as necessary and use them as imports.

To build the entry file to WebAssembly when you are ready, run:

  npm run asbuild

Running the command above creates the following binaries incl. their respective
text format representations and source maps:

  ./build/untouched.wasm
  ./build/untouched.wasm.map
  ./build/untouched.wat

  ^ The untouched WebAssembly module as generated by the compiler.
    This one matches your sources exactly, without any optimizations.

  ./build/optimized.wasm
  ./build/optimized.wasm.map
  ./build/optimized.wat

  ^ The optimized WebAssembly module using default optimization settings (-O2s).
    You can change the optimization settings in 'package.json'.

Additional documentation is available at the AssemblyScript wiki:

  https://github.com/AssemblyScript/assemblyscript/wiki

Have a nice day!

 

Clone this wiki locally