Skip to content

Commit

Permalink
feat: use babel-plugin-transform-titanium when transpiling (#11400)
Browse files Browse the repository at this point in the history
* chore(package): add babel-plugin-transform-titanium 0.1.1

* chore(package): update lockfile

* feat: pass options for babel-plugin-transfrom-titanium during jsanalyze

* build: use babel-plugin-transform-titanium when bundling ti.main.js

* build(android): use same timestamp format in all build processes
  • Loading branch information
sgtcoolguy authored and lokeshchdhry committed Jan 27, 2020
1 parent dd7b319 commit c21f77c
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 5 deletions.
9 changes: 7 additions & 2 deletions android/titanium/prebuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ const util = require('util');
const exec = util.promisify(require('child_process').exec); // eslint-disable-line security/detect-child-process
const fs = require('fs-extra');
const glob = util.promisify(require('glob'));
const moment = require('moment');
const path = require('path');
const timestamp = require('../../build/lib/utils').timestamp;

// Determine if we're running on a Windows machine.
const isWindows = (process.platform === 'win32');
Expand Down Expand Up @@ -81,13 +81,18 @@ async function generateBuildProperties() {
buildGitHash = 'HEAD';
}

let buildTimestamp = process.env.TI_SDK_BUILD_TIMESTAMP;
if (!buildTimestamp) {
buildTimestamp = timestamp();
}

// Create the "build.properties" content.
const fileContentString
= '#Generated by Titanium\n'
+ '\n'
+ 'build.version=' + escapeValue(buildVersion) + '\n'
+ 'build.githash=' + escapeValue(buildGitHash) + '\n'
+ 'build.timestamp=' + escapeValue(moment().format('YYYY/MM/DD HH:mm')) + '\n';
+ 'build.timestamp=' + escapeValue(buildTimestamp) + '\n';

// Create the "build.properties" file under the "assets" directory.
const directoryPath = path.join(__dirname, 'assets', 'Resources', 'ti.internal');
Expand Down
22 changes: 21 additions & 1 deletion build/lib/android/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Android {
* @param {String} options.sdkVersion version of Titanium SDK
* @param {String} options.versionTag version of the Titanium SDK package folder/zip
* @param {String} options.gitHash SHA of Titanium SDK HEAD
* @param {string} options.timestamp Value injected for Ti.buildDate
* @constructor
*/
constructor (options) {
Expand All @@ -34,6 +35,7 @@ class Android {
this.sdkVersion = options.sdkVersion;
this.versionTag = options.versionTag;
this.gitHash = options.gitHash;
this.timestamp = options.timestamp;
}

babelOptions() {
Expand All @@ -44,7 +46,24 @@ class Android {
return {
targets: {
chrome: version
}
},
transform: {
platform: 'android',
Ti: {
version: this.sdkVersion,
buildHash: this.gitHash,
buildDate: this.timestamp,
Platform: {
osname: 'android',
name: 'android',
runtime: 'v8',
},
Filesystem: {
lineEnding: '\n',
separator: '/',
},
},
},
};
}

Expand All @@ -69,6 +88,7 @@ class Android {
// Build the "titanium" library project only.
process.env.TI_SDK_BUILD_VERSION = this.sdkVersion;
process.env.TI_SDK_BUILD_GIT_HASH = this.gitHash;
process.env.TI_SDK_BUILD_TIMESTAMP = this.timestamp;
process.env.TI_SDK_VERSION_TAG = this.versionTag;
await gradlew(':titanium:assembleRelease');
}
Expand Down
4 changes: 4 additions & 0 deletions build/lib/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ function determineBabelOptions(babelOptions) {
useBuiltIns: 'entry',
corejs: 3
};
// extract out options.transform used by babel-plugin-transform-titanium
const transform = options.transform || {};
delete options.transform;

return {
presets: [ [ '@babel/env', options ] ],
plugins: [ [ require.resolve('babel-plugin-transform-titanium'), transform ] ],
exclude: 'node_modules/**'
};
}
Expand Down
18 changes: 17 additions & 1 deletion build/lib/ios.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,23 @@ class IOS {
return {
targets: {
ios: minIosVersion
}
},
transform: {
platform: 'ios',
Ti: {
version: this.sdkVersion,
buildHash: this.gitHash,
buildDate: this.timestamp,
Platform: {
runtime: 'javascriptcore',
manufacturer: 'apple',
},
Filesystem: {
lineEnding: '\n',
separator: '/',
},
},
},
};
}

Expand Down
66 changes: 65 additions & 1 deletion cli/lib/tasks/process-js-task.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,71 @@ class ProcessJsTask extends IncrementalFileTask {
this.jsFiles = options.jsFiles;
this.jsBootstrapFiles = options.jsBootstrapFiles;
this.sdkCommonFolder = options.sdkCommonFolder;
this.defaultAnalyzeOptions = options.defaultAnalyzeOptions;

// set up the object used by babel-plugin-transform-titanium to inline statics/etc
const transform = {
platform: this.platform,
deploytype: this.builder.deployType,
target: this.builder.target,
Ti: {
version: this.builder.cli.tiapp['sdk-version'],
// TODO: add buildHash
// TODO: add buildDate
App: {
copyright: this.builder.cli.tiapp.copyright,
deployType: this.builder.deployType,
description: this.builder.cli.tiapp.description,
guid: this.builder.cli.tiapp.guid,
id: this.builder.cli.tiapp.id,
name: this.builder.cli.tiapp.name,
publisher: this.builder.cli.tiapp.publisher,
url: this.builder.cli.tiapp.url,
version: this.builder.cli.tiapp.version,
},
Platform: {
runtime: 'javascriptcore', // overridden below for android
},
Filesystem: {
// overridden below for windows
lineEnding: '\n',
separator: '/',
}
}
};
switch (this.platform) {
case 'android':
transform.Ti.Platform.osname = 'android';
transform.Ti.Platform.name = 'android';
transform.Ti.Platform.runtime = 'v8'; // override
break;
case 'ios':
// if not 'universal' it is 'ipad' or 'iphone'
if (this.builder.deviceFamily !== 'universal') {
transform.Ti.Platform.osname = this.builder.deviceFamily;
}
transform.Ti.Platform.manufacturer = 'apple';
break;
case 'windows':
// override Ti.Filesystem property values
transform.Ti.Filesystem.separator = '\\';
transform.Ti.Filesystem.lineEnding = '\r\n';
switch (this.builder.target) {
// windows store targets
case 'ws-simulator':
case 'ws-local':
case 'ws-remote':
case 'dist-winstore':
transform.Ti.Platform.osname = 'windowsstore';
break;
default:
transform.Ti.Platform.osname = 'windowsphone'; // TODO: no longer support windows phones on SDK 9+!
break;
}
transform.Ti.Platform.name = 'windows';
break;
}

this.defaultAnalyzeOptions = Object.assign({}, options.defaultAnalyzeOptions, { transform });

this.dataFilePath = path.join(this.incrementalDirectory, 'data.json');

Expand Down
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
"@seadub/danger-plugin-dependencies": "0.1.0",
"@seadub/danger-plugin-eslint": "^1.0.1",
"@seadub/danger-plugin-junit": "0.1.2",
"babel-plugin-transform-titanium": "^0.1.1",
"chai": "^4.2.0",
"clang-format": "1.2.3",
"commander": "^4.0.1",
Expand Down

0 comments on commit c21f77c

Please sign in to comment.