Skip to content

Binarium - API documentation

Functions

build()

ts
function build(params: BuilderParams): Promise<undefined>

Package your cli application for different platforms and architectures.

Parameters

ParameterTypeDescription
paramsBuilderParamsThe parameters for creating the binaries.

Returns

Promise<undefined>

  • A promise that resolves when the binary creation process is complete.

Example

ts
import { build } from 'binarium'

build({
  input: 'examples/app',
  // name: 'my-app-name',
  // output: resolve('build'),
  // type: 'all',
})

buildAuto()

ts
function buildAuto(params: BuilderParams): Promise<undefined>

Package your cli application for different platforms and architectures. Autodectect runtime (node, deno, bun).

Parameters

ParameterTypeDescription
paramsBuilderParamsThe parameters for creating the binaries.

Returns

Promise<undefined>

  • A promise that resolves when the binary creation process is complete.

Example

ts
import { buildAuto } from 'binarium'

buildAuto({
  input: 'examples/app',
  // name: 'my-app-name',
  // output: resolve('build'),
  // type: 'all',
})

buildBun()

ts
function buildBun(params: BuilderParams): Promise<undefined>

Package your Bun cli application for different platforms and architectures.

Parameters

ParameterTypeDescription
paramsBuilderParamsThe parameters for creating the binaries.

Returns

Promise<undefined>

  • A promise that resolves when the binary creation process is complete.

Example

ts
import { buildBun } from 'binarium'

buildBun({
  input: 'examples/app',
  // name: 'my-app-name',
  // output: resolve('build'),
  // type: 'all',
})

buildDeno()

ts
function buildDeno(params: BuilderParams): Promise<undefined>

Package your Deno cli application for different platforms and architectures.

Parameters

ParameterTypeDescription
paramsBuilderParamsThe parameters for creating the binaries.

Returns

Promise<undefined>

  • A promise that resolves when the binary creation process is complete.

Example

ts
import { buildDeno } from 'binarium'

buildDeno({
  input: 'examples/app',
  // name: 'my-app-name',
  // output: resolve('build'),
  // type: 'all',
})

buildNode()

ts
function buildNode(params: BuilderParams): Promise<undefined>

Package your Node.js cli application for different platforms and architectures.

Parameters

ParameterTypeDescription
paramsBuilderParamsThe parameters for creating the binaries.

Returns

Promise<undefined>

  • A promise that resolves when the binary creation process is complete.

Example

ts
import { buildNode } from 'binarium'

buildNode({
  input: 'examples/app',
  // name: 'my-app-name',
  // output: resolve('build'),
  // type: 'all',
})

defineConfig()

ts
function defineConfig(config: {
  assets: {
     from: string;
     to: string;
    }[];
  bunOptions: {
     flags: string[];
    };
  config: string;
  denoOptions: {
     flags: string[];
    };
  input: string;
  name: string;
  nodeOptions: {
     esbuild: false | {};
     ncc: false | {
        assetBuilds: boolean;
        cache: string | false;
        externals: string[];
        filterAssetBase: string;
        license: string;
        minify: boolean;
        sourceMap: boolean;
        sourceMapBasePrefix: string;
        sourceMapRegister: boolean;
        target: string;
        v8cache: boolean;
        watch: boolean;
       };
     pkg: {
        assets: string | string[];
        compress: "Gzip" | "Brotli";
        flags: string[];
        ignore: string[];
        input: string;
        name: string;
        output: string;
        scripts: string | string[];
        targets: string[];
       };
    };
  onlyOs: boolean;
  output: string;
  type: "bin" | "all" | "bundle" | "compress";
 }): {
  assets: {
     from: string;
     to: string;
    }[];
  bunOptions: {
     flags: string[];
    };
  config: string;
  denoOptions: {
     flags: string[];
    };
  input: string;
  name: string;
  nodeOptions: {
     esbuild: false | {};
     ncc: false | {
        assetBuilds: boolean;
        cache: string | false;
        externals: string[];
        filterAssetBase: string;
        license: string;
        minify: boolean;
        sourceMap: boolean;
        sourceMapBasePrefix: string;
        sourceMapRegister: boolean;
        target: string;
        v8cache: boolean;
        watch: boolean;
       };
     pkg: {
        assets: string | string[];
        compress: "Gzip" | "Brotli";
        flags: string[];
        ignore: string[];
        input: string;
        name: string;
        output: string;
        scripts: string | string[];
        targets: string[];
       };
    };
  onlyOs: boolean;
  output: string;
  type: "bin" | "all" | "bundle" | "compress";
}

Define the configuration for the binary builder.

Parameters

ParameterTypeDescription
configobjectThe configuration object.
config.assets?{ from: string; to: string; }[]Experimental Assets for you app. Example { * from: 'src/assets', * to: 'assets' * }
config.bunOptions?objectCustom bun build configuration. Override options for Bun executable build.
config.bunOptions.flagsstring[]Custom flags for bun build --compile cmd. For help, run: bun build --help. See https://bun.sh/docs/bundler Example [ '--minify' ]
config.config?stringConfig file path. Files supported: .mjs, .js, .json, .yml, .yaml, .toml, .tml. Default undefined
config.denoOptions?objectCustom deno build configuration. Override options for deno executable build.
config.denoOptions.flagsstring[]Custom flags for deno compile cmd. For help, run: deno compile --help. See https://docs.deno.com/go/compile Example [ '--allow-all', '--no-prompt' ]
config.input?stringThe app input file. The input can be provided without an extension. If the extension is omitted, the system will automatically look for the following extensions: .ts, .js, .mjs, .mts.
config.name?stringBinary name.
config.nodeOptions?objectExperimental Custom node build configuration. Override build options for different build steps. Use this for advanced use cases.
config.nodeOptions.esbuild?false | {}Experimental ESBUILD configuration. See https://esbuild.github.io/api/#build
config.nodeOptions.ncc?false | { assetBuilds: boolean; cache: string | false; externals: string[]; filterAssetBase: string; license: string; minify: boolean; sourceMap: boolean; sourceMapBasePrefix: string; sourceMapRegister: boolean; target: string; v8cache: boolean; watch: boolean; }Experimental NCC configuration. See https://github.com/vercel/ncc?tab=readme-ov-file#programmatically-from-nodejs
config.nodeOptions.pkg?objectExperimental PKG configuration. See https://www.npmjs.com/package/@yao-pkg/pkg
config.nodeOptions.pkg.assets?string | string[]Assets is a glob or list of globs. Files specified as assets will be packaged into executable as raw content without modifications. Javascript files may also be specified as assets. Their sources will not be stripped as it improves execution performance of the files and simplifies debugging. Relative to input. Default input: build/cjs. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#assets
config.nodeOptions.pkg.compress?"Gzip" | "Brotli"Pass --compress Brotli or --compress GZip to pkg to compress further the content of the files store in the exectable. This option can reduce the size of the embedded file system by up to 60%. The startup time of the application might be reduced slightly.
config.nodeOptions.pkg.flags?string[]Custom flags for the pkg command. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#usage
config.nodeOptions.pkg.ignore?string[]Ignore is a list of globs. Files matching the paths specified as ignore will be excluded from the final executable. This is useful when you want to exclude some files from the final executable, like tests, documentation or build files that could have been included by a dependency. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#ignore-files
config.nodeOptions.pkg.input?stringInput of the js code.
config.nodeOptions.pkg.name?stringBinary name. This overrirides the default name.
config.nodeOptions.pkg.output?stringOutput for the binaries. This overrirides the default output path.
config.nodeOptions.pkg.scripts?string | string[]Scripts is a glob or list of globs. Files specified as scripts will be compiled using v8::ScriptCompiler and placed into executable without sources. They must conform to the JS standards of those Node.js versions you target. Relative to input. Default input: build/cjs. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#scripts
config.nodeOptions.pkg.targets?string[]Targets of your binary. Must be a list of strings in the following format: {nodeRange}-{platform}-[arch]. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#targets Example [ 'node18-macos-x64', 'node14-linux-arm64']
config.onlyOs?booleanBuild only binary for your current OS. Default false
config.output?stringDirectory for the output build. Default './build'
config.type?"bin" | "all" | "bundle" | "compress"The build type Result [all

Returns

ts
{
  assets: {
     from: string;
     to: string;
    }[];
  bunOptions: {
     flags: string[];
    };
  config: string;
  denoOptions: {
     flags: string[];
    };
  input: string;
  name: string;
  nodeOptions: {
     esbuild: false | {};
     ncc: false | {
        assetBuilds: boolean;
        cache: string | false;
        externals: string[];
        filterAssetBase: string;
        license: string;
        minify: boolean;
        sourceMap: boolean;
        sourceMapBasePrefix: string;
        sourceMapRegister: boolean;
        target: string;
        v8cache: boolean;
        watch: boolean;
       };
     pkg: {
        assets: string | string[];
        compress: "Gzip" | "Brotli";
        flags: string[];
        ignore: string[];
        input: string;
        name: string;
        output: string;
        scripts: string | string[];
        targets: string[];
       };
    };
  onlyOs: boolean;
  output: string;
  type: "bin" | "all" | "bundle" | "compress";
}
  • The configuration object.
NameTypeDescription
assets?{ from: string; to: string; }[]Experimental Assets for you app. Example { * from: 'src/assets', * to: 'assets' * }
bunOptions?{ flags: string[]; }Custom bun build configuration. Override options for Bun executable build.
bunOptions.flagsstring[]Custom flags for bun build --compile cmd. For help, run: bun build --help. See https://bun.sh/docs/bundler Example [ '--minify' ]
config?stringConfig file path. Files supported: .mjs, .js, .json, .yml, .yaml, .toml, .tml. Default undefined
denoOptions?{ flags: string[]; }Custom deno build configuration. Override options for deno executable build.
denoOptions.flagsstring[]Custom flags for deno compile cmd. For help, run: deno compile --help. See https://docs.deno.com/go/compile Example [ '--allow-all', '--no-prompt' ]
input?stringThe app input file. The input can be provided without an extension. If the extension is omitted, the system will automatically look for the following extensions: .ts, .js, .mjs, .mts.
name?stringBinary name.
nodeOptions?{ esbuild: false | {}; ncc: false | { assetBuilds: boolean; cache: string | false; externals: string[]; filterAssetBase: string; license: string; minify: boolean; sourceMap: boolean; sourceMapBasePrefix: string; sourceMapRegister: boolean; target: string; v8cache: boolean; watch: boolean; }; pkg: { assets: string | string[]; compress: "Gzip" | "Brotli"; flags: string[]; ignore: string[]; input: string; name: string; output: string; scripts: string | string[]; targets: string[]; }; }Experimental Custom node build configuration. Override build options for different build steps. Use this for advanced use cases.
nodeOptions.esbuild?false | {}Experimental ESBUILD configuration. See https://esbuild.github.io/api/#build
nodeOptions.ncc?false | { assetBuilds: boolean; cache: string | false; externals: string[]; filterAssetBase: string; license: string; minify: boolean; sourceMap: boolean; sourceMapBasePrefix: string; sourceMapRegister: boolean; target: string; v8cache: boolean; watch: boolean; }Experimental NCC configuration. See https://github.com/vercel/ncc?tab=readme-ov-file#programmatically-from-nodejs
nodeOptions.pkg?{ assets: string | string[]; compress: "Gzip" | "Brotli"; flags: string[]; ignore: string[]; input: string; name: string; output: string; scripts: string | string[]; targets: string[]; }Experimental PKG configuration. See https://www.npmjs.com/package/@yao-pkg/pkg
nodeOptions.pkg.assets?string | string[]Assets is a glob or list of globs. Files specified as assets will be packaged into executable as raw content without modifications. Javascript files may also be specified as assets. Their sources will not be stripped as it improves execution performance of the files and simplifies debugging. Relative to input. Default input: build/cjs. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#assets
nodeOptions.pkg.compress?"Gzip" | "Brotli"Pass --compress Brotli or --compress GZip to pkg to compress further the content of the files store in the exectable. This option can reduce the size of the embedded file system by up to 60%. The startup time of the application might be reduced slightly.
nodeOptions.pkg.flags?string[]Custom flags for the pkg command. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#usage
nodeOptions.pkg.ignore?string[]Ignore is a list of globs. Files matching the paths specified as ignore will be excluded from the final executable. This is useful when you want to exclude some files from the final executable, like tests, documentation or build files that could have been included by a dependency. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#ignore-files
nodeOptions.pkg.input?stringInput of the js code.
nodeOptions.pkg.name?stringBinary name. This overrirides the default name.
nodeOptions.pkg.output?stringOutput for the binaries. This overrirides the default output path.
nodeOptions.pkg.scripts?string | string[]Scripts is a glob or list of globs. Files specified as scripts will be compiled using v8::ScriptCompiler and placed into executable without sources. They must conform to the JS standards of those Node.js versions you target. Relative to input. Default input: build/cjs. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#scripts
nodeOptions.pkg.targets?string[]Targets of your binary. Must be a list of strings in the following format: {nodeRange}-{platform}-[arch]. See https://github.com/yao-pkg/pkg?tab=readme-ov-file#targets Example [ 'node18-macos-x64', 'node14-linux-arm64']
onlyOs?booleanBuild only binary for your current OS. Default false
output?stringDirectory for the output build. Default './build'
type?"bin" | "all" | "bundle" | "compress"The build type Result [all

Example

ts
import { defineConfig } from 'binarium'

export default defineConfig({
  name: 'my-app-name',
  onlyOs: true,
  nodeOptions: {
    esbuild: {
       tsconfig: './tsconfig.custom.json'
    }
  }
})

Type Aliases

BuilderContructorParams

ts
type BuilderContructorParams: GetDataParams & {
  data: Awaited<ReturnType<typeof getData>>;
};

Type declaration

NameType
dataAwaited<ReturnType<typeof getData>>

BuilderErrors

ts
type BuilderErrors: typeof CONSTS.ERROR_ID[keyof typeof CONSTS.ERROR_ID];

BuilderParams

ts
type BuilderParams: {
  config: string;
  input: string;
  name: string;
  onlyOs: boolean;
  output: string;
  type: typeof CONSTS.BUILDER_TYPE[keyof typeof CONSTS.BUILDER_TYPE];
};

Type declaration

NameTypeDescription
config?stringConfig file path. Files supported: .mjs, .js, .json, .yml, .yaml, .toml, .tml. Default undefined
inputstringThe app input file. The input can be provided without an extension. If the extension is omitted, the system will automatically look for the following extensions: .ts, .js, .mjs, .mts.
name?stringBinary name.
onlyOs?booleanBuild only binary for your current OS. Default false
output?stringDirectory for the output build. Default './build'
type?typeof CONSTS.BUILDER_TYPE[keyof typeof CONSTS.BUILDER_TYPE]The build type Result [all

Cmd

ts
type Cmd: typeof CONSTS.CMD[keyof typeof CONSTS.CMD];

ConfigParams

ts
type ConfigParams: Prettify<Partial<BuilderParams> & Config & {
  assets: {
     from: string;
     to: string;
    }[];
}>;

GetDataParams

ts
type GetDataParams: BuilderParams & {
  catchError: typeof catchError;
  consts: typeof CONSTS;
  Error: typeof BuildError;
  log: ReturnType<typeof getLog>;
};

Type declaration

NameType
catchErrortypeof catchError
conststypeof CONSTS
Errortypeof BuildError
logReturnType<typeof getLog>

Variables

BINARIUM_CONSTS

ts
const BINARIUM_CONSTS: {
  debug: boolean;
  desc: string;
  docsURL: string;
  icon: string;
  name: string;
  onHelp: () => void;
  onVersion: () => void;
};

Type declaration

NameType
debug?boolean
desc?string
docsURL?string
icon?string
name?string
onHelp?() => void
onVersion?() => void