JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q45295F
  • License MIT

The JavaScript Move Builder for Initia

Package Exports

    This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@initia/builder.js) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

    Readme

    initia builder.js

    This SDK is a Javascript wrapper for Initia Move Compiler using ffi-napi library.

    How to install

    $ npm install @initia/builder.js

    How to use

    Build Move Package

    import { MoveBuilder } from '@initia/builder.js';
    
    async function buildExample() {
        // recommend to use full package path, not relative path
        // ex) path.resolve(__dirname, "../relative_path")
        const builder = new MoveBuilder(
            path.resolve(__dirname, 'moon_coin'), // move package path 
            {} // build options
        );
    
        // execute move compiler via ffi
        await builder.build();
        
        // load compiled module bytes as `Buffer`
        const compiledModuleBytes = await builder.get(
            'moon_coin' // module name
        );
        console.info(compiledModuleBytes.toString('hex'));
    
        // change module name to what you want
        const nameConvertedModuleBytes = await MoveBuilder.convert_module_name(
            compiledModuleBytes,  // compiled module bytes
            'sun_coin' // new module name 
        );
        console.info(nameConvertedModuleBytes.toString('hex'));
    }
    

    Create and Clean Move Package

    import { MoveBuilder } from '@initia/builder.js';
    
    async function createAndCleanExample() {
        const builder = new MoveBuilder(path.resolve(__dirname, 'moon_coin'), {});
        
        // create new move package
        await builder.new('new'/* package name */);
        
        await builder.build();
        
        // clean /build directory
        await builder.clean();
    }

    Read Move Package

    import { MoveBuilder } from '@initia/builder.js';
    
    async function readExample() {
        const builder = new MoveBuilder(path.resolve(__dirname, 'moon_coin'), {});
    
        const binary = await builder.get('moon_coin');
    
        // read module bytes
        const moduleInfo = await MoveBuilder.read_module_info(binary)
        console.log(moduleInfo)
    
        // decode module bytes
        const decodedModule = await MoveBuilder.decode_module_bytes(binary);
        console.log(decodedModule)
    }

    Options

    For more details on the available options, refer to the source code.

    BuildOptions

    The BuildOptions interface provides various options to customize the build process.

    export interface BuildOptions {
        devMode?: boolean
        testMode?: boolean
        generateDocs?: boolean
        generateAbis?: boolean
        installDir?: string
        forceRecompilation?: boolean
        fetchDepsOnly?: boolean
        skipFetchLatestGitDeps?: boolean
        bytecodeVersion?: number
        compilerVersion?: string
        languageVersion?: string
        addtionalNamedAddresses?: [string, string][]
    }

    CleanOptions

    The CleanOptions interface provides options to clean the build artifacts.

    export interface CleanOptions {
        cleanCache?: boolean
        cleanByProduct?: boolean
    }

    TestOptions

    The TestOptions interface provides options to customize the testing process.

    export interface TestOptions {
        filter?: string
        reportStatistics?: boolean
        reportStorageOnError?: boolean
        ignoreCompileWarnings?: boolean
        computeCoverage?: boolean
    }