Launch Week Day 1: Socket for Jira Is Now Available.Learn More
Socket
Book a DemoSign in
Socket

create-as

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

create-as

AssemblyScript project initializer with bilingual (English/Chinese) support, enabling quick creation of WebAssembly projects via 'npm init as'

latest
npmnpm
Version
1.1.2
Version published
Weekly downloads
1
-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

create-as: AssemblyScript Project Initialization Tool

create-as is a lightweight project initializer for AssemblyScript, enabling quick creation of WebAssembly (Wasm) projects via npm init as. It supports both English and Chinese languages, adapting to different developers' preferences.

🌟 Key Features

  • Quick Invocation: Create projects with npm init as <project-directory>, following npm initializer conventions
  • Bilingual Support: Choose between English/Chinese during initialization, with terminal prompts and file comments automatically switching
  • Complete Structure: Generates standard AssemblyScript project structure (source code, build configs, tests, browser example)
  • Smart Adaptation: Automatically detects package manager (npm/yarn/pnpm) and generates corresponding scripts
  • Ready-to-use: Includes add/multiply example functions; compile, test, and preview immediately after installing dependencies

🚀 Getting Started

1. Install & Create Project

No prior installation required - use directly via npm init (supports npm/yarn/pnpm):

# Basic usage: Create project named "my-as-project" (language selection prompt)
npm init as my-as-project

# Advanced: Create in current directory (auto-confirm all options, default English)
npm init as . -y

# Advanced: Create project with terminal colors disabled
npm init as ./demo --no-colors

2. Language Selection

After executing the command (in non--y mode), you'll be prompted to select the project language:

Select project language (Default: English)
1. English (en)
2. Chinese (zh-CN)
Enter number (1/2) or press Enter:
  • Press Enter: Use default language (English)
  • Enter 1: Select English (terminal prompts and file comments in English)
  • Enter 2: Select Chinese (terminal prompts and file comments in Chinese)

3. Project Structure

After creation, the generated project structure looks like this (English example):

my-as-project/
├── assembly/                # AssemblyScript source directory
│   └── index.ts             # Entry file (contains add/multiply examples)
│   └── tsconfig.json        # TS configuration (inherits AssemblyScript standards)
├── build/                   # Wasm build output directory
│   └── .gitignore           # Ignore build artifacts (keep only .gitignore)
├── tests/                   # Test directory
│   └── index.js             # Test file (validates Wasm function functionality)
├── index.html               # Browser preview example (loads and calls Wasm)
├── asconfig.json            # AssemblyScript build configuration (debug/release)
└── package.json             # Project configuration (dependencies, scripts)

📝 Common Commands

After project creation, use these commands for development workflow (automatically adapts to your package manager):

CommandDescriptionExample (npm)
Install dependenciesInstalls AssemblyScript and other development dependenciesnpm install
Build Wasm moduleGenerates both debug (development) and release (optimized) versionsnpm run asbuild
Build debug versionGenerates Wasm with debugging information (for development)npm run asbuild:debug
Build release versionGenerates optimized Wasm (smaller size, better performance)npm run asbuild:release
Run testsExecutes test cases to verify Wasm function correctnessnpm test
Browser previewStarts local server to preview Wasm in browsernpm start

⚙️ Command Line Options

OptionAliasDescription
--help-hShow help information (including usage examples and options)
--yes-yAuto-confirm all options (skips language selection and confirmation)
--no-colors-Disable terminal color output (for plain text environments)
--version-vShow current version of create-as

📋 Example Code

1. Source Code Example (assembly/index.ts)

// AssemblyScript entry file (compiles to WebAssembly)
// Docs: https://www.assemblyscript.org

/**
 * Example: Add two numbers (i32 = 32-bit signed integer)
 * @param a First number
 * @param b Second number
 * @returns Sum of a and b
 */
export function add(a: i32, b: i32): i32 {
  return a + b;
}

/**
 * Extended example: Multiply two numbers
 */
export function multiply(a: i32, b: i32): i32 {
  return a * b;
}

2. Test Example (tests/index.js)

import assert from "assert";
import { add, multiply } from "../build/debug.js";

// Test add function (basic addition)
assert.strictEqual(add(1, 2), 3, "add(1,2) should return 3");
assert.strictEqual(add(-1, 5), 4, "add(-1,5) should return 4");

// Test multiply function (basic multiplication)
assert.strictEqual(multiply(2, 3), 6, "multiply(2,3) should return 6");
assert.strictEqual(multiply(-2, 4), -8, "multiply(-2,4) should return -8");

console.log("✅ All tests passed!");

3. Browser Preview Example (index.html)

Automatically loads the compiled Wasm module and displays results in the browser:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>AssemblyScript Wasm Example</title>
  <script type="module">
    // Load compiled Wasm module (ES Module format)
    import { add, multiply } from "./build/release.js";
    
    // Display results on page
    document.addEventListener("DOMContentLoaded", () => {
      const result = `
        <h2>AssemblyScript Wasm Example</h2>
        <p>add(1, 2) = ${add(1, 2)}</p>
        <p>multiply(3, 4) = ${multiply(3, 4)}</p>
      `;
      document.body.innerHTML = result;
    });
  </script>
</head>
<body></body>
</html>

🎯 Notes

  • Project Directory Requirement: The target directory must be empty when creating a project (non-empty directories will throw an error to prevent overwriting files)
  • Dependency Installation: Run npm install (or yarn install/pnpm install) after project creation - required for compilation
  • Browser Preview: npm start uses the serve tool (automatically invoked via npx, no additional installation needed)
  • AssemblyScript Version: Installs the latest stable version by default. To specify a version, modify devDependencies.assemblyscript in package.json
  • AssemblyScript Official Documentation - Learn AssemblyScript syntax and Wasm compilation details
  • WebAssembly Official Guide - Understand Wasm technology principles and use cases
  • AssemblyScript GitHub - Access source code and changelogs

🐛 Issue Reporting

For bugs, translation errors, or feature requests, please report via:

  • Submit an Issue in the project repository (if open source)
  • Contact maintainer: [Your contact information, e.g., email/GitHub username]

📄 License

MIT License
Free to use, modify, and distribute under the terms of the MIT License.

Keywords

assemblyscript

FAQs

Package last updated on 18 Sep 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts