Skip to content

Commit c21f77c

Browse files
sgtcoolguylokeshchdhry
authored andcommitted
feat: use babel-plugin-transform-titanium when transpiling (#11400)
* 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
1 parent dd7b319 commit c21f77c

File tree

7 files changed

+120
-5
lines changed

7 files changed

+120
-5
lines changed

android/titanium/prebuild.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ const util = require('util');
1313
constexec=util.promisify(require('child_process').exec);// eslint-disable-line security/detect-child-process
1414
constfs=require('fs-extra');
1515
constglob=util.promisify(require('glob'));
16-
constmoment=require('moment');
1716
constpath=require('path');
17+
consttimestamp=require('../../build/lib/utils').timestamp;
1818

1919
// Determine if we're running on a Windows machine.
2020
constisWindows=(process.platform==='win32');
@@ -81,13 +81,18 @@ async function generateBuildProperties() {
8181
buildGitHash='HEAD';
8282
}
8383

84+
letbuildTimestamp=process.env.TI_SDK_BUILD_TIMESTAMP;
85+
if(!buildTimestamp){
86+
buildTimestamp=timestamp();
87+
}
88+
8489
// Create the "build.properties" content.
8590
constfileContentString
8691
='#Generated by Titanium\n'
8792
+'\n'
8893
+'build.version='+escapeValue(buildVersion)+'\n'
8994
+'build.githash='+escapeValue(buildGitHash)+'\n'
90-
+'build.timestamp='+escapeValue(moment().format('YYYY/MM/DD HH:mm'))+'\n';
95+
+'build.timestamp='+escapeValue(buildTimestamp)+'\n';
9196

9297
// Create the "build.properties" file under the "assets" directory.
9398
constdirectoryPath=path.join(__dirname,'assets','Resources','ti.internal');

build/lib/android/index.js

+21-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ class Android {
2626
* @param {String} options.sdkVersion version of Titanium SDK
2727
* @param {String} options.versionTag version of the Titanium SDK package folder/zip
2828
* @param {String} options.gitHash SHA of Titanium SDK HEAD
29+
* @param {string} options.timestamp Value injected for Ti.buildDate
2930
* @constructor
3031
*/
3132
constructor(options){
@@ -34,6 +35,7 @@ class Android {
3435
this.sdkVersion=options.sdkVersion;
3536
this.versionTag=options.versionTag;
3637
this.gitHash=options.gitHash;
38+
this.timestamp=options.timestamp;
3739
}
3840

3941
babelOptions(){
@@ -44,7 +46,24 @@ class Android {
4446
return{
4547
targets: {
4648
chrome: version
47-
}
49+
},
50+
transform: {
51+
platform: 'android',
52+
Ti: {
53+
version: this.sdkVersion,
54+
buildHash: this.gitHash,
55+
buildDate: this.timestamp,
56+
Platform: {
57+
osname: 'android',
58+
name: 'android',
59+
runtime: 'v8',
60+
},
61+
Filesystem: {
62+
lineEnding: '\n',
63+
separator: '/',
64+
},
65+
},
66+
},
4867
};
4968
}
5069

@@ -69,6 +88,7 @@ class Android {
6988
// Build the "titanium" library project only.
7089
process.env.TI_SDK_BUILD_VERSION=this.sdkVersion;
7190
process.env.TI_SDK_BUILD_GIT_HASH=this.gitHash;
91+
process.env.TI_SDK_BUILD_TIMESTAMP=this.timestamp;
7292
process.env.TI_SDK_VERSION_TAG=this.versionTag;
7393
awaitgradlew(':titanium:assembleRelease');
7494
}

build/lib/builder.js

+4
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,13 @@ function determineBabelOptions(babelOptions) {
3939
useBuiltIns: 'entry',
4040
corejs: 3
4141
};
42+
// extract out options.transform used by babel-plugin-transform-titanium
43+
consttransform=options.transform||{};
44+
deleteoptions.transform;
4245

4346
return{
4447
presets: [['@babel/env',options]],
48+
plugins: [[require.resolve('babel-plugin-transform-titanium'),transform]],
4549
exclude: 'node_modules/**'
4650
};
4751
}

build/lib/ios.js

+17-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,23 @@ class IOS {
3434
return{
3535
targets: {
3636
ios: minIosVersion
37-
}
37+
},
38+
transform: {
39+
platform: 'ios',
40+
Ti: {
41+
version: this.sdkVersion,
42+
buildHash: this.gitHash,
43+
buildDate: this.timestamp,
44+
Platform: {
45+
runtime: 'javascriptcore',
46+
manufacturer: 'apple',
47+
},
48+
Filesystem: {
49+
lineEnding: '\n',
50+
separator: '/',
51+
},
52+
},
53+
},
3854
};
3955
}
4056

cli/lib/tasks/process-js-task.js

+65-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,71 @@ class ProcessJsTask extends IncrementalFileTask {
4848
this.jsFiles=options.jsFiles;
4949
this.jsBootstrapFiles=options.jsBootstrapFiles;
5050
this.sdkCommonFolder=options.sdkCommonFolder;
51-
this.defaultAnalyzeOptions=options.defaultAnalyzeOptions;
51+
52+
// set up the object used by babel-plugin-transform-titanium to inline statics/etc
53+
consttransform={
54+
platform: this.platform,
55+
deploytype: this.builder.deployType,
56+
target: this.builder.target,
57+
Ti: {
58+
version: this.builder.cli.tiapp['sdk-version'],
59+
// TODO: add buildHash
60+
// TODO: add buildDate
61+
App: {
62+
copyright: this.builder.cli.tiapp.copyright,
63+
deployType: this.builder.deployType,
64+
description: this.builder.cli.tiapp.description,
65+
guid: this.builder.cli.tiapp.guid,
66+
id: this.builder.cli.tiapp.id,
67+
name: this.builder.cli.tiapp.name,
68+
publisher: this.builder.cli.tiapp.publisher,
69+
url: this.builder.cli.tiapp.url,
70+
version: this.builder.cli.tiapp.version,
71+
},
72+
Platform: {
73+
runtime: 'javascriptcore',// overridden below for android
74+
},
75+
Filesystem: {
76+
// overridden below for windows
77+
lineEnding: '\n',
78+
separator: '/',
79+
}
80+
}
81+
};
82+
switch(this.platform){
83+
case'android':
84+
transform.Ti.Platform.osname='android';
85+
transform.Ti.Platform.name='android';
86+
transform.Ti.Platform.runtime='v8';// override
87+
break;
88+
case'ios':
89+
// if not 'universal' it is 'ipad' or 'iphone'
90+
if(this.builder.deviceFamily!=='universal'){
91+
transform.Ti.Platform.osname=this.builder.deviceFamily;
92+
}
93+
transform.Ti.Platform.manufacturer='apple';
94+
break;
95+
case'windows':
96+
// override Ti.Filesystem property values
97+
transform.Ti.Filesystem.separator='\\';
98+
transform.Ti.Filesystem.lineEnding='\r\n';
99+
switch(this.builder.target){
100+
// windows store targets
101+
case'ws-simulator':
102+
case'ws-local':
103+
case'ws-remote':
104+
case'dist-winstore':
105+
transform.Ti.Platform.osname='windowsstore';
106+
break;
107+
default:
108+
transform.Ti.Platform.osname='windowsphone';// TODO: no longer support windows phones on SDK 9+!
109+
break;
110+
}
111+
transform.Ti.Platform.name='windows';
112+
break;
113+
}
114+
115+
this.defaultAnalyzeOptions=Object.assign({},options.defaultAnalyzeOptions,{ transform });
52116

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

package-lock.json

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
"@seadub/danger-plugin-dependencies": "0.1.0",
130130
"@seadub/danger-plugin-eslint": "^1.0.1",
131131
"@seadub/danger-plugin-junit": "0.1.2",
132+
"babel-plugin-transform-titanium": "^0.1.1",
132133
"chai": "^4.2.0",
133134
"clang-format": "1.2.3",
134135
"commander": "^4.0.1",

0 commit comments

Comments
 (0)
close