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

feat(jsanalyze): integrate babel-plugin-transform-titanium #131

Merged
merged 5 commits into from Dec 18, 2019

Conversation

sgtcoolguy
Copy link
Contributor

JIRA: https://jira.appcelerator.org/browse/TIMOB-27167

Description
Integrates appcelerator/babel-plugin-transform-titanium 0.1.1

Will require changes to appcelerator/titanium_mobile to pass along the options used by the plugin.

The goal here is pass along an object with static values about the target platform/app that our custom babel plugin can use to inline the static values and replace typical platform sniffing expressions. (As well as do some of what appcelerator/alloy has done in it's compile for years, like having special OS_*, DIST_*, ENV_* defines). See the plugin's README for more details.

@build
Copy link

build commented Dec 17, 2019

Messages
📖

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

📖 🎉 - congrats on your new release

New dependencies added: babel-plugin-transform-titanium.

babel-plugin-transform-titanium

Author: cwilliams

Description: Replace known values in Titanium apps to allow for further simplification via dead code/evaluation in babel minify

Homepage: http://npmjs.com/package/babel-plugin-transform-titanium

Created11 months ago
Last Updated6 months ago
LicenseNO LICENSE FOUND
Maintainers1
Releases3
Keywordsbabel-plugin
README

Greenkeeper badge

This is a babel plugin intended to optimize Titanium SDK applications by inlining various static values. Once inlined, Other babel plugins may performa additional optimizations to help strip away "dead code".

Information about the current Titanium application build should be passed to the plugin's options object.

Plugin Options

const options = {
	deploytype: 'development', // one of 'development', 'test', 'production'
	platform: undefined, // one of 'android', 'ios', 'windows'
	target: undefined, // one of 'dist-playstore', 'dist-appstore', 'dist-adhoc', null/undefined
	Ti: {
		version: undefined, // string, SDK version
		App: {
			id: undefined, // string, application id from tiapp.xml
			name: undefined, // string, application name from tiapp.xml
			version: undefined, // string, application version from tiapp.xml
		}
		Platform: {
			osname: undefined, // one of 'android', 'ipad', 'iphone', 'windowsphone', 'windowsstore'
		}
	}
};

Special "defines"

It can:

  • replace special OS_* references with boolean values
    • OS_IOS - true iff pluginOptions.platform === 'ios'
    • OS_ANDROID - true iff pluginOptions.platform === 'android'
    • OS_WINDOWS - true iff pluginOptions.platform === 'windows'
    • Useful for if/else guards for platform specific code. Once booleans are inlined the false blocks can be removed.
  • replace special ENV_* references with boolean values
    • ENV_DEV and ENV_DEVELOPMENT - true iff pluginOptions.deploytype === 'development' (typically simulator builds)
    • ENV_TEST - true iff pluginOptions.deploytype === 'test' (typically device builds)
    • ENV_PROD and ENV_PRODUCTION - true iff pluginOptions.deploytype === 'production' (typically app store/ad hoc builds)
  • replace special DIST_* references with boolean values
    • DIST_ADHOC - true iff pluginOptions.target === 'dist-adhoc'
    • DIST_STORE - true iff pluginOptions.target === 'dist-appstore' || pluginOptions.target === 'dist-playstore'

OS "sniffing" via Ti.Platform.osname

  • replace typical "sniff" expressions for iOS/Windows using Ti.Platform.osname with static boolean values
    i.e.
if (Ti.Platform.osname === 'iphone' || Ti.Platform.osname === 'ipad') {
	Ti.API.info('on ios!');
}
if (Ti.Platform.osname === 'windowsstore' || Ti.Platform.osname === 'windowsphone') {
	Ti.API.info('on windows!');
}

Generated by 🚫 dangerJS against dc2654b

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.

This looks good to me!

Merging to allow integrating into tidev/titanium-sdk/pull/11400

@ewanharris ewanharris merged commit 8409b5a into tidev:master Dec 18, 2019
@sgtcoolguy sgtcoolguy deleted the TIMOB-27167 branch December 18, 2019 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants