Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: use external compiler package #952

Open
wants to merge 20 commits into
base: next
Choose a base branch
from

Conversation

janvennemann
Copy link
Contributor

@janvennemann janvennemann commented Jan 24, 2020

JIRA: https://jira.appcelerator.org/browse/ALOY-1725

This rips out everything that is relating to compiling Alloy components and moves it into a new package. The goal is to get a reusable compiler package that can be used across different projects. A first example of this is the alloy-loader.

Overview of the changes this PR contains:

  • Moved compiler into new alloy-compiler package.
  • Moved shared utilities into new alloy-utils package
  • Updated the code in this repo to use the newly created packages.
  • Updated unit tests to use the new packages. Moved over the test for the optimizer-plugin to alloy-compiler. The actual compiler tests are still in this repo since they rely on all the test apps in this repo and i didn't want to move too much stuff around. Also they are built on outdated tools like jake and Jasmine v1.x, so i'd prefer to update the testing setup before moving all that into the new alloy-compiler package.
  • Removed references to mobileweb as a platform.

@build
Copy link

build commented Jan 24, 2020

Warnings
⚠️

Please ensure to add a changelog entry for your changes. Edit the CHANGELOG.md file and add your change under the Unreleased items header

Messages
📖

✅ All tests are passing
Nice one! All 1847 tests are passing.

New dependencies added: alloy-compiler, alloy-utils and strip-ansi.

alloy-compiler

Author: Axway Appcelerator

Description: Compiler for Alloy components

Homepage: https://github.com/appcelerator/alloy-devkit/tree/develop/packages/alloy-compiler#readme

Created4 months ago
Last Updated3 days ago
LicenseApache-2.0
Maintainers1
Releases8
Direct Dependencies@babel/generator, @babel/parser, @babel/traverse, @babel/types, alloy-utils, chmodr, fs-extra, jsonlint, lodash, node.extend, walk-sync and xmldom
Keywordsalloy and compiler
README

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.

alloy-utils

Author: Axway Appcelerator

Description: Common utils for Alloy

Homepage: https://github.com/appcelerator/alloy-devkit/tree/develop/packages/alloy-utils#readme

Created4 months ago
Last Updated3 days ago
LicenseApache-2.0
Maintainers1
Releases7
Direct Dependencies@babel/code-frame, chmodr, colors, fs-extra, global-paths, jsonlint, lodash, moment, resolve and xmldom
Keywordsalloy, common and utils
README

alloy-utils

Alloy utility library

Installation

npm i alloy-utils

Usage

const {
  utils, // Utility functions
  logger, // Alloy logger
  constants, // Constants used in Alloy
  platforms, // Platform information
  tiapp, // Utils to work with tiapp.xml
  tssGrammar // TSS grammar defintion
} = require('alloy-utils');

strip-ansi

Author: Sindre Sorhus

Description: Strip ANSI escape codes from a string

Homepage: https://github.com/chalk/strip-ansi#readme

Createdover 6 years ago
Last Updated6 months ago
LicenseMIT
Maintainers2
Releases16
Direct Dependenciesansi-regex
Keywordsstrip, trim, remove, ansi, styles, color, colour, colors, terminal, console, string, tty, escape, formatting, rgb, 256, shell, xterm, log, logging, command-line and text
README

strip-ansi Build Status

Strip ANSI escape codes from a string

Install

$ npm install strip-ansi

Usage

const stripAnsi = require('strip-ansi');

stripAnsi('\u001B[4mUnicorn\u001B[0m');
//=> 'Unicorn'

stripAnsi('\u001B]8;;https://github.com\u0007Click\u001B]8;;\u0007');
//=> 'Click'

strip-ansi for enterprise

Available as part of the Tidelift Subscription.

The maintainers of strip-ansi and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. Learn more.

Related

Maintainers

Generated by 🚫 dangerJS against af691f2

@janvennemann janvennemann added this to the 2.0.0 milestone Mar 4, 2020
@janvennemann janvennemann marked this pull request as ready for review March 4, 2020 13:43
Copy link
Contributor

@ewanharris ewanharris left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good, some comments but only the version number comment is required. Incredible work @janvennemann!

Moving on to do some more thorough testing

path.join(paths.resources, titaniumFolder, 'alloy'),
{ rootDir: paths.project, restrictionPath: restrictionPath }
// NOTE: copies `alloy-utils/lib/constants.js` into `<project-dir>/Resources/<platform>/alloy`
U.copyFileSync(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's a huge deal as it's only the constants file, but we'd lose the restrictionPath filtering by just using copyFileSync here

});
let finalCode = code;
const relativeOutfile = path.relative(compileConfig.dir.project, componentOutputPath);
if (compileConfig.sourcemap !== false) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self to check debugging in studio/vscode

@@ -1161,13 +816,11 @@ function optimizeCompiledCode(alloyConfig, paths) {
});
}

// TODO: Remove once @titanium-sdk/babel-preset-app is in place
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this an ALOY ticket to handle, or will it be done at the SDK level?

Alloy/commands/compile/index.js Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants