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

[TIMOB-25059] Use module hooks instead of plugins #254

Merged
merged 9 commits into from
Nov 9, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.DS_Store
build/
node_modules
android/plugins/hyperloop/metabase/hyperloop/
android/plugins/hyperloop/hooks/hyperloop.js
android/hooks/hyperloop-init.js
android/LICENSE
android/libs/
android/documentation/
Expand All @@ -17,7 +16,8 @@ project.xcworkspace
*.zip
*.bak
npm-debug.log
metabase/ios/bin/metabase
packages/hyperloop-ios-metabase/bin/metabase
windows/hooks/hyperloop-init.js

# Coverage directory and nyc output
coverage
Expand Down
49 changes: 21 additions & 28 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.axway.AppcCLI;
def nodeVersion = '6.9.5'
def platformEnvironment = 'prod' // 'preprod'
def credentialsId = '895d8db1-87c2-4d96-a786-349c2ed2c04a' // preprod = '65f9aaaf-cfef-4f22-a8aa-b1fb0d934b64'
def sdkVersion = '6.2.0.GA'
def sdkVersion = '7.0.0.v20171101175057'
def androidAPILevel = '26'

// gets assigned once we read the package.json file
Expand Down Expand Up @@ -73,6 +73,8 @@ stage('Build') {

dir('android') {
sh "sed -i.bak 's/VERSION/${packageVersion}/g' ./manifest"
sh "sed -i.bak 's/0.0.0-PLACEHOLDER/${packageVersion}/g' ./hooks/package.json"

writeFile file: 'build.properties', text: """
titanium.platform=${activeSDKPath}/android
android.platform=${androidSDK}/platforms/android-${androidAPILevel}
Expand All @@ -83,31 +85,36 @@ google.apis=${androidSDK}/add-ons/addon-google_apis-google-${androidAPILevel}
sh 'rm -rf build/'
sh 'rm -rf dist/'
sh 'rm -rf libs/'

// Run hook tests and then prune to production deps
dir('hooks') {
sh 'npm install'
sh 'npm test'
sh 'npm prune --production'
}

appc.loggedIn {
// Even setting config needs login, ugh
sh "appc ti config android.sdkPath ${androidSDK}"
sh "appc ti config android.ndkPath ${androidNDK}"
sh 'appc run -p android --build-only'
} // appc.loggedIn
// This doesn't package up the Android hyperloop plugin hook!
// We need to unzip, and hack it in!

// Clean dist zip
dir('dist') {
sh 'rm -f hyperloop-android.jar'
sh "unzip hyperloop-android-${packageVersion}.zip"
sh "rm -rf hyperloop-android-${packageVersion}.zip"
sh 'cp -R ../plugins plugins/' // Copy in plugins folder from android
sh 'rm -rf plugins/hyperloop/test' // wipe android hook tests
// copy top-level plugin hook
sh 'cp ../../plugins/hyperloop.js plugins/hyperloop/hooks/hyperloop.js'
dir ('plugins/hyperloop/hooks/android') { // install the android-specific hook npm dependencies
sh 'npm install --production'
sh 'rm -rf package-lock.json' // Now remove the package-lock.json!
sh 'rm -rf test' // remove the test directory

dir ('modules/android/hyperloop/${packageVersion}/hooks') {
sh 'rm -rf package-lock.json'
sh 'rm -rf test'
}
sh 'rm -rf plugins/hyperloop/hooks/android@tmp' // remove this bogus dir if it exists

// Remove docs and examples
sh "rm -rf modules/android/hyperloop/${packageVersion}/example"
sh "rm -rf modules/android/hyperloop/${packageVersion}/documentation"

// Now zip it back up
sh "zip -r hyperloop-android-${packageVersion}.zip ."
}
Expand All @@ -128,6 +135,7 @@ google.apis=${androidSDK}/add-ons/addon-google_apis-google-${androidAPILevel}
echo 'Building iOS module...'
dir('iphone') {
sh "sed -i.bak 's/VERSION/${packageVersion}/g' ./manifest"
sh "sed -i.bak 's/0.0.0-PLACEHOLDER/${packageVersion}/g' ./hooks/package.json"

// Check if xcpretty gem is installed
// if (sh(returnStatus: true, script: 'which xcpretty') != 0) {
Expand Down Expand Up @@ -192,18 +200,13 @@ google.apis=${androidSDK}/add-ons/addon-google_apis-google-${androidAPILevel}
appc.loggedIn {
sh 'appc run -p windows --build-only'
} // appc.loggedIn
// This doesn't package up the Windows hyperloop plugin hook!
// We need to unzip, and hack it in!

sh 'rm -rf zip/'
sh 'mkdir zip/'
sh "mv hyperloop-windows-${packageVersion}.zip zip/hyperloop-windows-${packageVersion}.zip"
dir('zip') {
sh "unzip hyperloop-windows-${packageVersion}.zip"
sh "rm -rf hyperloop-windows-${packageVersion}.zip"
sh 'mkdir -p plugins/hyperloop/hooks'
sh 'cp -R ../sdk_plugins/windows plugins/hyperloop/hooks/' // Copy in plugins folder from windows
// copy top-level plugin hook
sh 'cp ../../plugins/hyperloop.js plugins/hyperloop/hooks/hyperloop.js'
// Remove docs and examples
sh "rm -rf modules/windows/hyperloop/${packageVersion}/example"
sh "rm -rf modules/windows/hyperloop/${packageVersion}/documentation"
Expand Down Expand Up @@ -243,18 +246,8 @@ stage('Package') {
sh "rm -f hyperloop-iphone-${packageVersion}.zip"
sh "unzip -o hyperloop-windows-${packageVersion}.zip"
sh "rm -f hyperloop-windows-${packageVersion}.zip"

// Here we extract and force the version of the plugin into the folder structure
sh 'mkdir -p temp'
sh 'cp -R plugins/hyperloop/* temp'
sh 'rm -rf plugins'
sh "mkdir -p plugins/hyperloop/${packageVersion}"
sh "cp -R temp/* plugins/hyperloop/${packageVersion}"
sh 'rm -rf temp'

sh "zip -q -r hyperloop-${packageVersion}.zip * --exclude=*test* --exclude=*.DS_Store* --exclude=*.git* --exclude *.travis.yml* --exclude *.gitignore* --exclude *.npmignore* --exclude *CHANGELOG* --exclude *.jshintrc*"
sh 'rm -rf modules'
sh 'rm -rf plugins'
}
archiveArtifacts "dist/hyperloop-${packageVersion}.zip"
}
Expand Down
36 changes: 17 additions & 19 deletions android/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
<!-- Copy license -->
<copy todir="${basedir}" file="${basedir}/../LICENSE"/>

<!-- Copy common CLI hook -->
<copy todir="${basedir}/plugins/hyperloop/hooks" file="${basedir}/../plugins/hyperloop.js"/>
<!-- Copy shared module hook -->
<copy todir="${basedir}/hooks" file="${basedir}/../hooks/hyperloop-init.js"/>
</target>

<target name="post.clean">
Expand All @@ -56,32 +56,30 @@
<delete dir="${basedir}/example" quiet="true"/>
<delete dir="${basedir}/libs" quiet="true"/>
<delete file="${basedir}/LICENSE" quiet="true"/>
<delete dir="${basedir}/plugins/hyperloop/node_modules" quiet="true"/>
<delete file="${basedir}/plugins/hyperloop/hooks/hyperloop.js" quiet="true"/>
<delete dir="${basedir}/plugins/hyperloop/hooks/android/metabase/hyperloop" quiet="true"/>
<delete dir="${basedir}/plugins/hyperloop/hooks/android/coverage" quiet="true"/>
<delete dir="${basedir}/plugins/hyperloop/hooks/android/.nyc_output" quiet="true"/>
<delete file="${basedir}/plugins/hyperloop/hooks/android/junit_report.xml" quiet="true"/>
<delete dir="${basedir}/hooks/node_modules" quiet="true"/>
<delete dir="${basedir}/hooks/coverage" quiet="true"/>
<delete dir="${basedir}/hooks/.nyc_output" quiet="true"/>
<delete file="${basedir}/hooks/junit_report.xml" quiet="true"/>
</target>

<target name="post.dist" description="Include plugins folder in module zip">
<!-- NPM Install for plugin hook -->
<exec executable="npm" dir="${basedir}/plugins/hyperloop/hooks/android" failonerror="true">
<target name="post.dist" description="Include hooks folder in module zip">
<!-- NPM Install for module hook -->
<exec executable="npm" dir="${basedir}/hooks" failonerror="true">
<arg value="install"/>
<arg value="--production"/>
</exec>

<!-- Remove some test directories from NPM packages manually -->
<delete dir="${basedir}/plugins/hyperloop/hooks/android/node_modules/ejs/test"/>
<delete dir="${basedir}/plugins/hyperloop/hooks/android/node_modules/findit/example"/>
<delete dir="${basedir}/plugins/hyperloop/hooks/android/node_modules/findit/test"/>
<delete dir="${basedir}/plugins/hyperloop/hooks/android/node_modules/node-appc/test"/>
<delete dir="${basedir}/hooks/node_modules/ejs/test"/>
<delete dir="${basedir}/hooks/node_modules/findit/example"/>
<delete dir="${basedir}/hooks/node_modules/findit/test"/>
<delete dir="${basedir}/hooks/node_modules/node-appc/test"/>

<!-- Include hyperloop wrappers into module zip -->
<!-- Include Hyperloop hooks into module zip -->
<zip destfile="${dist}/${module.id}-android-${manifest.version}.zip" update="true">
<zipfileset dir="${ti.module.root}/plugins" prefix="plugins">
<!-- Remove plugin hook test directory manually -->
<exclude name="hyperloop/hooks/android/test/"/>
<zipfileset dir="${ti.module.root}/hooks" prefix="modules/android/hyperloop/${manifest.version}/hooks">
<exclude name="test/"/>
<exclude name="package-lock.json"/>
</zipfileset>
</zip>
</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ exports.cliVersion = '>=3.2';
ScanReferencesTask = require('./tasks/scan-references-task');

// set this to enforce a minimum Titanium SDK
var TI_MIN = '6.1.0';
var TI_MIN = '7.0.0';

/*
State.
Expand Down

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

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hyperloop",
"version": "2.2.0",
"version": "0.0.0-PLACEHOLDER",
"description": "Access native Android and Java APIs from within Titanium.",
"author": "Chris Williams",
"license": "Appcelerator Software Subscription",
Expand Down
12 changes: 1 addition & 11 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ onexit () {

trap onexit 0 1 2 3 6 9 15

TISDK_SEMVER=">=6.0.0"
TISDK_SEMVER=">=7.0.0"
CHECK="✓ "

# Make sure the Android SDK is installed
Expand Down Expand Up @@ -134,7 +134,6 @@ then
fi

cp -R build/zip/modules/ ../dist/modules
cp -R build/zip/plugins/ ../dist/plugins/
cd ..

# Build Windows module
Expand All @@ -150,16 +149,7 @@ cd ../../
# Combine all modules to one masterpiece
echo "Creating combined zip with iOS, Android and Windows..."
cd dist
mkdir -p temp
cp -R plugins/hyperloop/* temp
rm -rf plugins
mkdir -p plugins/hyperloop/$VERSION
cp -R temp/* plugins/hyperloop/$VERSION
rm -rf temp
cp -R ../windows/sdk_plugins/windows plugins/hyperloop/$VERSION/hooks/
zip -q -r hyperloop-$VERSION.zip *
rm -rf modules
rm -rf plugins

echo "$CHECK Combined zip completed successfully"
echo "$CHECK Distribution is available at dist/hyperloop-$VERSION.zip"
Expand Down
77 changes: 77 additions & 0 deletions hooks/hyperloop-init.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
'use strict';

const fs = require('fs');
const path = require('path');

exports.id = 'com.appcelerator.hyperloop.init';
exports.cliVersion = '>=3.2';
exports.init = (logger, config, cli, appc) => {
cli.on('cli:check-plugins', () => {
for (const plugin of cli.tiapp.plugins) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use forEach here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm trying to use for...of whenever possible because it allows break and continue logic and doesn't overrides the context because no new function is created.

Copy link
Contributor

Choose a reason for hiding this comment

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

Fine then

if (plugin.id === 'hyperloop') {
logger.error('Legacy Hyperloop plugin detected! Please remove any references to the Hyperloop plugin tag from your tiapp.xml. Since Hyperloop 3.0 you only need to enable it as a module.');
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe phrase it Hyperloop "<plugin>" tag ?

process.exit(1);
}
}
});
cli.on('build.pre.compile', {
priority: 1300,
post: function (builder, callback) {
const factory = new HyperloopBuilderFactory(logger, config, cli, appc, builder);
const instance = factory.createHyperloopBuilder();
instance.init(callback);
}
});
};

class HyperloopBuilderFactory {
constructor(logger, config, cli, appc, builder) {
this.logger = logger;
this.config = config;
this.cli = cli;
this.appc = appc;
this.builder = builder;
}

createHyperloopBuilder() {
const hyperloopConfig = this.loadConfiguration();
const platformHookFile = path.join(__dirname, 'hyperloop.js');

if (!fs.existsSync(platformHookFile)) {
this.logger.error(`Hyperloop builder not found at expected path ${platformHookFile}.`);
process.exit(1);
}

var Builder = require(platformHookFile);
return new Builder(this.logger, this.config, this.cli, this.appc, hyperloopConfig, this.builder);
}

loadConfiguration() {
const possibleConfigurtionFiles = [
path.join(this.builder.projectDir, 'appc.js'),
path.join(this.builder.projectDir, '.appc.js'),
path.join(process.env.HOME || process.env.USERPROFILE, '.appc.js')
];
let config = {};

for (let configurationFile of possibleConfigurtionFiles) {
if (fs.existsSync(configurationFile)) {
this.mergeObjectProperties(config, require(configurationFile));
}
}

return config;
}

mergeObjectProperties(target, source) {
if (!source) {
return;
}

for (var k in source) {
if (source.hasOwnProperty(k)) {
target[k] = source[k];
}
}
}
}
21 changes: 7 additions & 14 deletions iphone/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
# Script buid building and packaging the Hyperloop iOS package
#
CWD=`pwd`
METABASE=$CWD/build/zip/plugins/hyperloop/hooks/ios/node_modules/hyperloop-metabase
CURVERSION=`grep "^version:" manifest`
VERSION=`grep "^version:" manifest | cut -c 10-`
METABASE_VERSION=`grep "\"version\":" ../metabase/ios/package.json | cut -d \" -f 4`
METABASE_VERSION=`grep "\"version\":" ../packages/hyperloop-ios-metabase/package.json | cut -d \" -f 4`
export TITANIUM_SDK="`node ../tools/tiver.js`"

XC=`which xcpretty`
Expand All @@ -31,7 +30,6 @@ then
fi

mkdir -p build/zip/modules/iphone/hyperloop/$VERSION
mkdir -p build/zip/plugins/hyperloop/hooks/ios
cp manifest module.xcconfig build/zip/modules/iphone/hyperloop/$VERSION

# Build for the Apple JavaScriptCore built-in
Expand All @@ -49,27 +47,22 @@ xcodebuild -sdk iphonesimulator -configuration Debug GCC_PREPROCESSOR_DEFINITION
lipo build/Debug-iphonesimulator/libhyperloop.a build/Release-iphoneos/libhyperloop.a -create -output build/zip/modules/iphone/hyperloop/$VERSION/libhyperloop-ticore.a

echo "\nPackaging iOS module..."
# make sure to update the plugin with the latest version in it's package.json
node -e "j=JSON.parse(require('fs').readFileSync('plugins/hyperloop/hooks/ios/package.json'));j.version='$VERSION';console.log(JSON.stringify(j,null,2))" > build/zip/plugins/hyperloop/hooks/ios/package.json

cp ../plugins/hyperloop.js build/zip/plugins/hyperloop/hooks/hyperloop.js
cp plugins/hyperloop/hooks/ios/hyperloop.js build/zip/plugins/hyperloop/hooks/ios
cp plugins/hyperloop/hooks/ios/filter.sh build/zip/plugins/hyperloop/hooks/ios
cp ../LICENSE build/zip/plugins/hyperloop
cp -R hooks build/zip/modules/iphone/hyperloop/$VERSION
cp -R ../hooks build/zip/modules/iphone/hyperloop/$VERSION
cp ../LICENSE build/zip/modules/iphone/hyperloop/$VERSION

# package the metabase into the .zip
echo "Packaging metabase..."
cd ../metabase/ios
echo "Packaging iOS metabase..."
cd ../packages/hyperloop-ios-metabase
rm *.tgz
npm pack >/dev/null 2>&1
cd $CWD

# Install dependencies
echo "Installing npm dependencies..."
cd build/zip/plugins/hyperloop/hooks/ios
cd build/zip/modules/iphone/hyperloop/$VERSION/hooks
npm i --production
npm i $CWD/../metabase/ios/hyperloop-metabase-$METABASE_VERSION.tgz
npm i $CWD/../packages/hyperloop-ios-metabase/hyperloop-metabase-$METABASE_VERSION.tgz
rm -rf node_modules/findit/test
rm -rf package-lock.json
cd $CWD
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ module.exports = HyperloopiOSBuilder;
// set this to enforce a ios-min-version
var IOS_MIN = '8.0';
// set this to enforce a minimum Titanium SDK
var TI_MIN = '6.2.0';
var TI_MIN = '7.0.0';
// set the iOS SDK minium
var IOS_SDK_MIN = '9.0';
// enum for ios javascript core
Expand Down