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

Fix react-native 0.53 prompt glitches when linking #252

Merged
merged 4 commits into from
Feb 28, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 1 addition & 18 deletions appcenter-analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,8 @@
"appcenter": "1.3.0"
},
"rnpm": {
"params": [
{
"type": "list",
"name": "whenToEnableAnalytics",
"message": "For the Android app, should user tracking be enabled automatically?",
"choices": [
{
"name": "Enable Automatically",
"value": "ALWAYS_SEND"
},
{
"name": "Enable in JavaScript",
"value": "ENABLE_IN_JS"
}
]
}
],
"android": {
"packageInstance": "new AppCenterReactNativeAnalyticsPackage(MainApplication.this, ${whenToEnableAnalytics})"
"packageInstance": "new AppCenterReactNativeAnalyticsPackage(MainApplication.this, getResources().getString(R.string.appCenterAnalytics_whenToEnableAnalytics))"
},
"commands": {
"prelink": "node node_modules/appcenter-analytics/scripts/prelink",
Expand Down
51 changes: 41 additions & 10 deletions appcenter-analytics/scripts/postlink.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
const rnpmlink = require('appcenter-link-scripts');
const npmPackages = require('./../package.json');
const inquirer = require('inquirer');

return rnpmlink.ios.checkIfAppDelegateExists()
.then(() => rnpmlink.ios.initAppCenterConfig().catch((e) => {
console.log(`Could not create or update AppCenter config file (AppCenter-Config.plist). Error Reason - ${e.message}`);
return Promise.reject();
}))
.then(() => {
const prompt = npmPackages.rnpm.params[0];
prompt.message = prompt.message.replace(/Android/, 'iOS');
return rnpmlink.inquirer.prompt(prompt)
.catch((e) => {
console.log(`Could not determine when to enable AppCenter analytics. Error Reason - ${e.message}`);
return Promise.reject();
});
return inquirer.prompt([{
type: 'list',
name: 'whenToEnableAnalytics',
message: 'For the Android app, should user tracking be enabled automatically?',
choices: [
{
name: 'Enable Automatically',
value: 'ALWAYS_SEND'
},
{
name: 'Enable in JavaScript',
value: 'ENABLE_IN_JS'
}]
}]).catch((e) => {
console.log(`Could not determine when to enable AppCenter analytics. Error Reason - ${e.message}`);
return Promise.reject();
});
})
.then((androidAnswer) => {
rnpmlink.android.patchStrings('appCenterAnalytics_whenToEnableAnalytics',
androidAnswer.whenToEnableAnalytics);
return inquirer.prompt([{
type: 'list',
name: 'whenToEnableAnalytics',
message: 'For the iOS app, should user tracking be enabled automatically?',
choices: [
{
name: 'Enable Automatically',
value: 'ALWAYS_SEND'
},
{
name: 'Enable in JavaScript',
value: 'ENABLE_IN_JS'
}]
}]).catch((e) => {
console.log(`Could not determine when to enable AppCenter analytics. Error Reason - ${e.message}`);
return Promise.reject();
});
})
.then((answer) => {
const code = answer.whenToEnableAnalytics === 'ALWAYS_SEND' ?
.then((iosAnswer) => {
const code = iosAnswer.whenToEnableAnalytics === 'ALWAYS_SEND' ?
' [AppCenterReactNativeAnalytics registerWithInitiallyEnabled:true]; // Initialize AppCenter analytics' :
' [AppCenterReactNativeAnalytics registerWithInitiallyEnabled:false]; // Initialize AppCenter analytics';
return rnpmlink.ios.initInAppDelegate('#import <AppCenterReactNativeAnalytics/AppCenterReactNativeAnalytics.h>', code, /.*\[AppCenterReactNativeAnalytics register.*/g)
Expand Down
19 changes: 1 addition & 18 deletions appcenter-crashes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,8 @@
"appcenter": "1.3.0"
},
"rnpm": {
"params": [
{
"type": "list",
"name": "whenToSendCrashes",
"message": "For the Android app, should crashes be sent automatically or processed in JavaScript before being sent?",
"choices": [
{
"name": "Automatically",
"value": "ALWAYS_SEND"
},
{
"name": "Processed in JavaScript by user",
"value": "ASK_JAVASCRIPT"
}
]
}
],
"android": {
"packageInstance": "new AppCenterReactNativeCrashesPackage(MainApplication.this, ${whenToSendCrashes})"
"packageInstance": "new AppCenterReactNativeCrashesPackage(MainApplication.this, getResources().getString(R.string.appCenterCrashes_whenToSendCrashes))"
},
"commands": {
"prelink": "node node_modules/appcenter-crashes/scripts/prelink",
Expand Down
51 changes: 41 additions & 10 deletions appcenter-crashes/scripts/postlink.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,53 @@
const rnpmlink = require('appcenter-link-scripts');
const npmPackages = require('./../package.json');
const inquirer = require('inquirer');

return rnpmlink.ios.checkIfAppDelegateExists()
.then(() => rnpmlink.ios.initAppCenterConfig().catch((e) => {
console.log(`Could not create or update AppCenter config file (AppCenter-Config.plist). Error Reason - ${e.message}`);
return Promise.reject();
}))
.then(() => {
const prompt = npmPackages.rnpm.params[0];
prompt.message = prompt.message.replace(/Android/, 'iOS');
return rnpmlink.inquirer.prompt(prompt)
.catch((e) => {
console.log(`Could not determine when to send AppCenter crashes. Error Reason - ${e.message}`);
return Promise.reject();
});
return inquirer.prompt([{
type: 'list',
name: 'whenToSendCrashes',
message: 'For the Android app, should crashes be sent automatically or processed in JavaScript before being sent?',
choices: [
{
name: 'Automatically',
value: 'ALWAYS_SEND'
},
{
name: 'Processed in JavaScript by user',
value: 'ASK_JAVASCRIPT'
}]
}]).catch((e) => {
console.log(`Could not determine when to enable AppCenter crashes. Error Reason - ${e.message}`);
Copy link
Member

@dhei dhei Feb 28, 2018

Choose a reason for hiding this comment

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

The original log message Could not determine when to send AppCenter crashes. sounds better to me, it's more accurate and informative.

Copy link
Member Author

@guperrot guperrot Feb 28, 2018

Choose a reason for hiding this comment

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

Sounds like we didn't have the same message as analytics then, I copied from there.

return Promise.reject();
});
})
.then((androidAnswer) => {
rnpmlink.android.patchStrings('appCenterCrashes_whenToSendCrashes',
androidAnswer.whenToSendCrashes);
return inquirer.prompt([{
type: 'list',
name: 'whenToSendCrashes',
message: 'For the iOS app, should crashes be sent automatically or processed in JavaScript before being sent?',
choices: [
{
name: 'Automatically',
value: 'ALWAYS_SEND'
},
{
name: 'Processed in JavaScript by user',
value: 'ASK_JAVASCRIPT'
}]
}]).catch((e) => {
console.log(`Could not determine when to enable AppCenter crashes. Error Reason - ${e.message}`);
Copy link
Member

Choose a reason for hiding this comment

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

same as above comment.

return Promise.reject();
});
})
.then((answer) => {
const code = answer.whenToSendCrashes === 'ALWAYS_SEND' ?
.then((iosAnswer) => {
const code = iosAnswer.whenToSendCrashes === 'ALWAYS_SEND' ?
' [AppCenterReactNativeCrashes registerWithAutomaticProcessing]; // Initialize AppCenter crashes' :
' [AppCenterReactNativeCrashes register]; // Initialize AppCenter crashes';
return rnpmlink.ios.initInAppDelegate('#import <AppCenterReactNativeCrashes/AppCenterReactNativeCrashes.h>', code, /.*\[AppCenterReactNativeCrashes register.*/g)
Expand Down
15 changes: 15 additions & 0 deletions appcenter-link-scripts/src/android/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const fs = require('fs');
const path = require('path');

const inquirer = require('inquirer');
const debug = require('debug')('appcenter-link:android:index');
Expand Down Expand Up @@ -39,5 +40,19 @@ module.exports = {
console.log(`App Secret for Android written to ${file}`);
return file;
});
},

patchStrings(key, value) {
const stringsFile = path.join('android', 'app', 'src', 'main', 'res', 'values', 'strings.xml');
let stringsXml = fs.readFileSync(stringsFile, 'utf-8');
const pattern = new RegExp(`<string.*name="${key}".*>.*</string>`);
const newValue = `<string name="${key}" moduleConfig="true">${value}</string>`;
if (stringsXml.match(pattern)) {
stringsXml = stringsXml.replace(pattern, newValue);
}
else {
stringsXml = stringsXml.replace(`\n</resources>`, `\n ${newValue}\n</resources>`);
}
fs.writeFileSync(stringsFile, stringsXml);
}
};