0.2.7 • Published 3 years ago

alloy-compiler v0.2.7

Weekly downloads
12
License
Apache-2.0
Repository
github
Last release
3 years ago

alloy-compiler

Compiler for Alloy components

This packages contains the standalone Alloy compiler. In most cases you should be using it in Webpack powered Alloy projects, you will only need it separately if you are writing build tools with very specific needs.

Installation

npm i alloy-compiler

Usage

const { createCompiler, createCompileConfig } = require('alloy-compiler');

API

createCompiler(options)

Creates a new Alloy compiler instance.

Example

const { createCompiler } = require('alloy-compiler');
const compiler = createCompiler({
  compileConfig: {
    projectDir: '/path/to/my/project',
    alloyConfig: {
      platform: 'ios',
      deploytype: 'development'
    }
  },
  webpack: true
});

Options

Expects an options object with the following properties:

  • compileConfig

    • Type: object

    Configuration that will be passed to the Alloy compiler.

    You can either pass an object returned by createCompileConfig or directly pass the same options accepted by that function. The config object will then be created from the passed options.

  • webpack

    • Type: boolean
    • Default: false

    Whether or not to create a special compiler instance that creates optimized output Webpack.

createCompileConfig(options)

Creates a new Alloy compile configuration based on the passed options.

Example

const { createCompileConfig } = require('alloy-compiler');
const compileConfig = createCompileConfig({
  projectDir: '/path/to/my/project',
  alloyConfig: {
    platform: 'ios',
    deploytype: 'development'
  }
});

Parameters

Expects an options object with the following properties:

  • projectDir

    • Type: string

    Path to the root directory of the Alloy project.

  • alloyConfig

    • Type: object

    Alloy configuration. Expects an object with the following structure:

    {
      platform: string // 'ios' or 'android'
      deploytype: string // 'development', 'test' or 'production'
    }
  • logLevel

    Log level for the internal logger.

  • buildLog

    • Type: BuildLog
    • Default: BuildLog for the specified projectDir

compiler.compileComponent(options)

Compiles the controller and view of an Alloy component.

Returns a result object with the following structure:

{
  code: string,
  map: object, // Source map
  dependencies: array // List of dependencies used during compilation like view and style file
}

Example

const { createCompiler } = require('alloy-compiler');
const compiler = createCompiler({
  compileConfig: {
    projectDir: '/path/to/my/project',
    alloyConfig: {
      platform: 'ios',
      deploytype: 'development'
    }
  }
});
const result = compiler.compileComponent({
  file: '/path/to/my/project/app/controllers/index.js'
});

Parameters

Expects an options object with the following properties:

  • file

    • Type: string

    Full path to the controller or view file that should be compiled. The compiler will automatically look for all possible associated files of the component (controller/view/style) and process them.

  • content

    • Type: string

    Content of file, if already known. The compiler will automatically read the file's content if this is omitted.

  • inputSourceMap

    • Type: object

    Input source map. The compiler will create a new source map if this is omitted.

0.2.7

3 years ago

0.2.6

4 years ago

0.2.5

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago