@thathoff/cordova-plugin-universal-links 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +84 -0
- package/LICENSE +22 -0
- package/README.md +908 -0
- package/docs/images/app-associated-domains.jpg +0 -0
- package/docs/images/app-id-team-prefix.jpg +0 -0
- package/docs/images/app-id.jpg +0 -0
- package/docs/images/branch-io-link-domain.jpg +0 -0
- package/docs/images/branch-io.jpg +0 -0
- package/docs/images/developer-console.jpg +0 -0
- package/hooks/afterPrepareHook.js +86 -0
- package/hooks/beforePluginInstallHook.js +55 -0
- package/hooks/iosBeforePrepareHook.js +74 -0
- package/hooks/lib/android/manifestWriter.js +320 -0
- package/hooks/lib/android/webSiteHook.js +162 -0
- package/hooks/lib/configXmlHelper.js +117 -0
- package/hooks/lib/configXmlParser.js +145 -0
- package/hooks/lib/ios/appleAppSiteAssociationFile.js +173 -0
- package/hooks/lib/ios/projectEntitlements.js +174 -0
- package/hooks/lib/ios/xcodePreferences.js +243 -0
- package/hooks/lib/xmlHelper.js +57 -0
- package/package.json +58 -0
- package/plugin.xml +106 -0
- package/src/android/com/nordnetab/cordova/ul/UniversalLinksPlugin.java +221 -0
- package/src/android/com/nordnetab/cordova/ul/js/JSAction.java +19 -0
- package/src/android/com/nordnetab/cordova/ul/model/JSMessage.java +193 -0
- package/src/android/com/nordnetab/cordova/ul/model/ULHost.java +85 -0
- package/src/android/com/nordnetab/cordova/ul/model/ULPath.java +43 -0
- package/src/android/com/nordnetab/cordova/ul/parser/ULConfigXmlParser.java +156 -0
- package/src/android/com/nordnetab/cordova/ul/parser/XmlTags.java +49 -0
- package/src/ios/AppDelegate+CULPlugin.h +17 -0
- package/src/ios/AppDelegate+CULPlugin.m +32 -0
- package/src/ios/CULPlugin.h +38 -0
- package/src/ios/CULPlugin.m +176 -0
- package/src/ios/JS/CDVInvokedUrlCommand+CULPlugin.h +21 -0
- package/src/ios/JS/CDVInvokedUrlCommand+CULPlugin.m +19 -0
- package/src/ios/JS/CDVPluginResult+CULPlugin.h +29 -0
- package/src/ios/JS/CDVPluginResult+CULPlugin.m +157 -0
- package/src/ios/Model/CULHost.h +63 -0
- package/src/ios/Model/CULHost.m +50 -0
- package/src/ios/Model/CULPath.h +36 -0
- package/src/ios/Model/CULPath.m +21 -0
- package/src/ios/Parser/JSON/CULConfigJsonParser.h +22 -0
- package/src/ios/Parser/JSON/CULConfigJsonParser.m +60 -0
- package/src/ios/Parser/XML/CULConfigXmlParser.h +22 -0
- package/src/ios/Parser/XML/CULConfigXmlParser.m +123 -0
- package/src/ios/Parser/XML/CULXmlTags.h +54 -0
- package/src/ios/Parser/XML/CULXmlTags.m +22 -0
- package/src/ios/Utils/NSBundle+CULPlugin.h +22 -0
- package/src/ios/Utils/NSBundle+CULPlugin.m +15 -0
- package/ul_web_hooks/android_web_hook_tpl.html +23 -0
- package/www/universal_links.js +56 -0
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Script creates entitlements file with the list of hosts, specified in config.xml.
|
|
3
|
+
File name is: ProjectName.entitlements
|
|
4
|
+
Location: ProjectName/
|
|
5
|
+
|
|
6
|
+
Script only generates content. File it self is included in the xcode project in another hook: xcodePreferences.js.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var path = require('path');
|
|
10
|
+
var fs = require('fs');
|
|
11
|
+
var plist = require('plist');
|
|
12
|
+
var mkpath = require('mkpath');
|
|
13
|
+
var ConfigXmlHelper = require('../configXmlHelper.js');
|
|
14
|
+
var ASSOCIATED_DOMAINS = 'com.apple.developer.associated-domains';
|
|
15
|
+
var context;
|
|
16
|
+
var projectRoot;
|
|
17
|
+
var projectName;
|
|
18
|
+
var entitlementsFilePath;
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
generateAssociatedDomainsEntitlements: generateEntitlements
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
// region Public API
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generate entitlements file content.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} cordovaContext - cordova context object
|
|
30
|
+
* @param {Object} pluginPreferences - plugin preferences from config.xml; already parsed
|
|
31
|
+
*/
|
|
32
|
+
function generateEntitlements(cordovaContext, pluginPreferences) {
|
|
33
|
+
context = cordovaContext;
|
|
34
|
+
|
|
35
|
+
var currentEntitlements = getEntitlementsFileContent();
|
|
36
|
+
var newEntitlements = injectPreferences(currentEntitlements, pluginPreferences);
|
|
37
|
+
|
|
38
|
+
saveContentToEntitlementsFile(newEntitlements);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// endregion
|
|
42
|
+
|
|
43
|
+
// region Work with entitlements file
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Save data to entitlements file.
|
|
47
|
+
*
|
|
48
|
+
* @param {Object} content - data to save; JSON object that will be transformed into xml
|
|
49
|
+
*/
|
|
50
|
+
function saveContentToEntitlementsFile(content) {
|
|
51
|
+
var plistContent = plist.build(content);
|
|
52
|
+
var filePath = pathToEntitlementsFile();
|
|
53
|
+
|
|
54
|
+
// ensure that file exists
|
|
55
|
+
mkpath.sync(path.dirname(filePath));
|
|
56
|
+
|
|
57
|
+
// save it's content
|
|
58
|
+
fs.writeFileSync(filePath, plistContent, 'utf8');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Read data from existing entitlements file. If none exist - default value is returned
|
|
63
|
+
*
|
|
64
|
+
* @return {String} entitlements file content
|
|
65
|
+
*/
|
|
66
|
+
function getEntitlementsFileContent() {
|
|
67
|
+
var pathToFile = pathToEntitlementsFile();
|
|
68
|
+
var content;
|
|
69
|
+
|
|
70
|
+
try {
|
|
71
|
+
content = fs.readFileSync(pathToFile, 'utf8');
|
|
72
|
+
} catch (err) {
|
|
73
|
+
return defaultEntitlementsFile();
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return plist.parse(content);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get content for an empty entitlements file.
|
|
81
|
+
*
|
|
82
|
+
* @return {String} default entitlements file content
|
|
83
|
+
*/
|
|
84
|
+
function defaultEntitlementsFile() {
|
|
85
|
+
return {};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Inject list of hosts into entitlements file.
|
|
90
|
+
*
|
|
91
|
+
* @param {Object} currentEntitlements - entitlements where to inject preferences
|
|
92
|
+
* @param {Object} pluginPreferences - list of hosts from config.xml
|
|
93
|
+
* @return {Object} new entitlements content
|
|
94
|
+
*/
|
|
95
|
+
function injectPreferences(currentEntitlements, pluginPreferences) {
|
|
96
|
+
var newEntitlements = currentEntitlements;
|
|
97
|
+
var content = generateAssociatedDomainsContent(pluginPreferences);
|
|
98
|
+
|
|
99
|
+
newEntitlements[ASSOCIATED_DOMAINS] = content;
|
|
100
|
+
|
|
101
|
+
return newEntitlements;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Generate content for associated-domains dictionary in the entitlements file.
|
|
106
|
+
*
|
|
107
|
+
* @param {Object} pluginPreferences - list of hosts from conig.xml
|
|
108
|
+
* @return {Object} associated-domains dictionary content
|
|
109
|
+
*/
|
|
110
|
+
function generateAssociatedDomainsContent(pluginPreferences) {
|
|
111
|
+
var domainsList = [];
|
|
112
|
+
|
|
113
|
+
// generate list of host links
|
|
114
|
+
pluginPreferences.hosts.forEach(function(host) {
|
|
115
|
+
var link = domainsListEntryForHost(host);
|
|
116
|
+
if (domainsList.indexOf(link) == -1) {
|
|
117
|
+
domainsList.push(link);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return domainsList;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Generate domain record for the given host.
|
|
126
|
+
*
|
|
127
|
+
* @param {Object} host - host entry
|
|
128
|
+
* @return {String} record
|
|
129
|
+
*/
|
|
130
|
+
function domainsListEntryForHost(host) {
|
|
131
|
+
return 'applinks:' + host.name;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// endregion
|
|
135
|
+
|
|
136
|
+
// region Path helper methods
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Path to entitlements file.
|
|
140
|
+
*
|
|
141
|
+
* @return {String} absolute path to entitlements file
|
|
142
|
+
*/
|
|
143
|
+
function pathToEntitlementsFile() {
|
|
144
|
+
if (entitlementsFilePath === undefined) {
|
|
145
|
+
entitlementsFilePath = path.join(getProjectRoot(), 'platforms', 'ios', getProjectName(), 'Resources', getProjectName() + '.entitlements');
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return entitlementsFilePath;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Projects root folder path.
|
|
153
|
+
*
|
|
154
|
+
* @return {String} absolute path to the projects root
|
|
155
|
+
*/
|
|
156
|
+
function getProjectRoot() {
|
|
157
|
+
return context.opts.projectRoot;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Name of the project from config.xml
|
|
162
|
+
*
|
|
163
|
+
* @return {String} project name
|
|
164
|
+
*/
|
|
165
|
+
function getProjectName() {
|
|
166
|
+
if (projectName === undefined) {
|
|
167
|
+
var configXmlHelper = new ConfigXmlHelper(context);
|
|
168
|
+
projectName = configXmlHelper.getProjectName();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return projectName;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// endregion
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Script activates support for Universal Links in the application by setting proper preferences in the xcode project file.
|
|
3
|
+
Which is:
|
|
4
|
+
- deployment target set to iOS 9.0
|
|
5
|
+
- .entitlements file added to project PBXGroup and PBXFileReferences section
|
|
6
|
+
- path to .entitlements file added to Code Sign Entitlements preference
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
var path = require('path');
|
|
10
|
+
var compare = require('node-version-compare');
|
|
11
|
+
var ConfigXmlHelper = require('../configXmlHelper.js');
|
|
12
|
+
const xcode = require('xcode');
|
|
13
|
+
const fileSystem = require('fs');
|
|
14
|
+
const glob = require('glob');
|
|
15
|
+
const shelljs = require('shelljs');
|
|
16
|
+
var IOS_DEPLOYMENT_TARGET = '8.0';
|
|
17
|
+
var COMMENT_KEY = /_comment$/;
|
|
18
|
+
var context;
|
|
19
|
+
|
|
20
|
+
module.exports = {
|
|
21
|
+
enableAssociativeDomainsCapability: enableAssociativeDomainsCapability
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// region Public API
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Activate associated domains capability for the application.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} cordovaContext - cordova context object
|
|
30
|
+
*/
|
|
31
|
+
function enableAssociativeDomainsCapability(cordovaContext) {
|
|
32
|
+
context = cordovaContext;
|
|
33
|
+
|
|
34
|
+
var projectFile = loadProjectFile();
|
|
35
|
+
|
|
36
|
+
// adjust preferences
|
|
37
|
+
activateAssociativeDomains(projectFile.xcode);
|
|
38
|
+
|
|
39
|
+
// add entitlements file to pbxfilereference
|
|
40
|
+
addPbxReference(projectFile.xcode);
|
|
41
|
+
|
|
42
|
+
// save changes
|
|
43
|
+
projectFile.write();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// endregion
|
|
47
|
+
|
|
48
|
+
// region Alter project file preferences
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Activate associated domains support in the xcode project file:
|
|
52
|
+
* - set deployment target to ios 9;
|
|
53
|
+
* - add .entitlements file to Code Sign Entitlements preference.
|
|
54
|
+
*
|
|
55
|
+
* @param {Object} xcodeProject - xcode project preferences; all changes are made in that instance
|
|
56
|
+
*/
|
|
57
|
+
function activateAssociativeDomains(xcodeProject) {
|
|
58
|
+
var configurations = nonComments(xcodeProject.pbxXCBuildConfigurationSection());
|
|
59
|
+
var entitlementsFilePath = pathToEntitlementsFile();
|
|
60
|
+
var config;
|
|
61
|
+
var buildSettings;
|
|
62
|
+
var deploymentTargetIsUpdated;
|
|
63
|
+
|
|
64
|
+
for (config in configurations) {
|
|
65
|
+
buildSettings = configurations[config].buildSettings;
|
|
66
|
+
buildSettings['CODE_SIGN_ENTITLEMENTS'] = '"' + entitlementsFilePath + '"';
|
|
67
|
+
|
|
68
|
+
// if deployment target is less then the required one - increase it
|
|
69
|
+
if (buildSettings['IPHONEOS_DEPLOYMENT_TARGET']) {
|
|
70
|
+
if (compare(buildSettings['IPHONEOS_DEPLOYMENT_TARGET'], IOS_DEPLOYMENT_TARGET) == -1) {
|
|
71
|
+
buildSettings['IPHONEOS_DEPLOYMENT_TARGET'] = IOS_DEPLOYMENT_TARGET;
|
|
72
|
+
deploymentTargetIsUpdated = true;
|
|
73
|
+
}
|
|
74
|
+
} else {
|
|
75
|
+
buildSettings['IPHONEOS_DEPLOYMENT_TARGET'] = IOS_DEPLOYMENT_TARGET;
|
|
76
|
+
deploymentTargetIsUpdated = true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (deploymentTargetIsUpdated) {
|
|
81
|
+
console.log('IOS project now has deployment target set as: ' + IOS_DEPLOYMENT_TARGET);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
console.log('IOS project Code Sign Entitlements now set to: ' + entitlementsFilePath);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// endregion
|
|
88
|
+
|
|
89
|
+
// region PBXReference methods
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Add .entitlemets file into the project.
|
|
93
|
+
*
|
|
94
|
+
* @param {Object} xcodeProject - xcode project preferences; all changes are made in that instance
|
|
95
|
+
*/
|
|
96
|
+
function addPbxReference(xcodeProject) {
|
|
97
|
+
var fileReferenceSection = nonComments(xcodeProject.pbxFileReferenceSection());
|
|
98
|
+
var entitlementsFileName = path.basename(pathToEntitlementsFile());
|
|
99
|
+
|
|
100
|
+
if (isPbxReferenceAlreadySet(fileReferenceSection, entitlementsFileName)) {
|
|
101
|
+
console.log('Entitlements file is in reference section.');
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
console.log('Entitlements file is not in references section, adding it');
|
|
106
|
+
xcodeProject.addResourceFile(entitlementsFileName);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Check if .entitlemets file reference already set.
|
|
111
|
+
*
|
|
112
|
+
* @param {Object} fileReferenceSection - PBXFileReference section
|
|
113
|
+
* @param {String} entitlementsRelativeFilePath - relative path to entitlements file
|
|
114
|
+
* @return true - if reference is set; otherwise - false
|
|
115
|
+
*/
|
|
116
|
+
function isPbxReferenceAlreadySet(fileReferenceSection, entitlementsRelativeFilePath) {
|
|
117
|
+
var isAlreadyInReferencesSection = false;
|
|
118
|
+
var uuid;
|
|
119
|
+
var fileRefEntry;
|
|
120
|
+
|
|
121
|
+
for (uuid in fileReferenceSection) {
|
|
122
|
+
fileRefEntry = fileReferenceSection[uuid];
|
|
123
|
+
if (fileRefEntry.path && fileRefEntry.path.indexOf(entitlementsRelativeFilePath) > -1) {
|
|
124
|
+
isAlreadyInReferencesSection = true;
|
|
125
|
+
break;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
return isAlreadyInReferencesSection;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// region Xcode project file helpers
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Load iOS project file from platform specific folder.
|
|
136
|
+
*
|
|
137
|
+
* @return {Object} projectFile - project file information
|
|
138
|
+
*/
|
|
139
|
+
function loadProjectFile() {
|
|
140
|
+
var platform_ios;
|
|
141
|
+
var projectFile;
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
// try pre-5.0 cordova structure
|
|
145
|
+
platform_ios = context.requireCordovaModule(
|
|
146
|
+
'cordova-lib/src/plugman/platforms',
|
|
147
|
+
).ios;
|
|
148
|
+
|
|
149
|
+
projectFile = platform_ios.parseProjectFile(iosPlatformPath());
|
|
150
|
+
} catch (e) {
|
|
151
|
+
try {
|
|
152
|
+
// let's try cordova 5.0 structure
|
|
153
|
+
platform_ios = context.requireCordovaModule('ios');
|
|
154
|
+
projectFile = platform_ios.parseProjectFile(iosPlatformPath());
|
|
155
|
+
} catch (e) {
|
|
156
|
+
// Then cordova 7.0
|
|
157
|
+
const project_files = glob.sync(
|
|
158
|
+
path.join(iosPlatformPath(), '*.xcodeproj', 'project.pbxproj'),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
if (project_files.length === 0) {
|
|
162
|
+
throw new Error(
|
|
163
|
+
'does not appear to be an xcode project (no xcode project file)',
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
const pbxPath = project_files[0];
|
|
168
|
+
|
|
169
|
+
const xcodeproj = xcode.project(pbxPath);
|
|
170
|
+
xcodeproj.parseSync();
|
|
171
|
+
|
|
172
|
+
projectFile = {
|
|
173
|
+
xcode: xcodeproj,
|
|
174
|
+
write() {
|
|
175
|
+
const fs = fileSystem;
|
|
176
|
+
|
|
177
|
+
const frameworks_file = path.join(
|
|
178
|
+
iosPlatformPath(),
|
|
179
|
+
'frameworks.json',
|
|
180
|
+
);
|
|
181
|
+
let frameworks = {};
|
|
182
|
+
try {
|
|
183
|
+
frameworks = context.requireCordovaModule(frameworks_file);
|
|
184
|
+
} catch (e) {}
|
|
185
|
+
|
|
186
|
+
fs.writeFileSync(pbxPath, xcodeproj.writeSync());
|
|
187
|
+
if (Object.keys(frameworks).length === 0) {
|
|
188
|
+
// If there is no framework references remain in the project, just remove this file
|
|
189
|
+
shelljs.rm('-rf', frameworks_file);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
fs.writeFileSync(
|
|
193
|
+
frameworks_file,
|
|
194
|
+
JSON.stringify(this.frameworks, null, 4),
|
|
195
|
+
);
|
|
196
|
+
},
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
return projectFile;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* Remove comments from the file.
|
|
206
|
+
*
|
|
207
|
+
* @param {Object} obj - file object
|
|
208
|
+
* @return {Object} file object without comments
|
|
209
|
+
*/
|
|
210
|
+
function nonComments(obj) {
|
|
211
|
+
var keys = Object.keys(obj);
|
|
212
|
+
var newObj = {};
|
|
213
|
+
|
|
214
|
+
for (var i = 0, len = keys.length; i < len; i++) {
|
|
215
|
+
if (!COMMENT_KEY.test(keys[i])) {
|
|
216
|
+
newObj[keys[i]] = obj[keys[i]];
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
return newObj;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// endregion
|
|
224
|
+
|
|
225
|
+
// region Path helpers
|
|
226
|
+
|
|
227
|
+
function iosPlatformPath() {
|
|
228
|
+
return path.join(projectRoot(), 'platforms', 'ios');
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function projectRoot() {
|
|
232
|
+
return context.opts.projectRoot;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function pathToEntitlementsFile() {
|
|
236
|
+
var configXmlHelper = new ConfigXmlHelper(context),
|
|
237
|
+
projectName = configXmlHelper.getProjectName(),
|
|
238
|
+
fileName = projectName + '.entitlements';
|
|
239
|
+
|
|
240
|
+
return path.join(projectName, 'Resources', fileName);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// endregion
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Small helper class to read/write from/to xml file.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var xml2js = require('xml2js');
|
|
7
|
+
|
|
8
|
+
module.exports = {
|
|
9
|
+
readXmlAsJson: readXmlAsJson,
|
|
10
|
+
writeJsonAsXml: writeJsonAsXml
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Read data from the xml file as JSON object.
|
|
15
|
+
*
|
|
16
|
+
* @param {String} filePath - absolute path to xml file
|
|
17
|
+
* @return {Object} JSON object with the contents of the xml file
|
|
18
|
+
*/
|
|
19
|
+
function readXmlAsJson(filePath) {
|
|
20
|
+
var xmlData;
|
|
21
|
+
var xmlParser;
|
|
22
|
+
var parsedData;
|
|
23
|
+
|
|
24
|
+
try {
|
|
25
|
+
xmlData = fs.readFileSync(filePath, 'utf8');
|
|
26
|
+
xmlParser = new xml2js.Parser();
|
|
27
|
+
xmlParser.parseString(xmlData, function(err, data) {
|
|
28
|
+
if (data) {
|
|
29
|
+
parsedData = data;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
} catch (err) {}
|
|
33
|
+
|
|
34
|
+
return parsedData;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Write JSON object as xml into the specified file.
|
|
39
|
+
*
|
|
40
|
+
* @param {Object} jsData - JSON object to write
|
|
41
|
+
* @param {String} filePath - path to the xml file where data should be saved
|
|
42
|
+
* @return {boolean} true - if data saved to file; false - otherwise
|
|
43
|
+
*/
|
|
44
|
+
function writeJsonAsXml(jsData, filePath, options) {
|
|
45
|
+
var xmlBuilder = new xml2js.Builder(options);
|
|
46
|
+
var changedXmlData = xmlBuilder.buildObject(jsData);
|
|
47
|
+
var isSaved = true;
|
|
48
|
+
|
|
49
|
+
try {
|
|
50
|
+
fs.writeFileSync(filePath, changedXmlData, 'utf8');
|
|
51
|
+
} catch (err) {
|
|
52
|
+
console.log(err);
|
|
53
|
+
isSaved = false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return isSaved;
|
|
57
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@thathoff/cordova-plugin-universal-links",
|
|
3
|
+
"version": "0.3.0",
|
|
4
|
+
"description": "Cordova plugin to add in your application support for Universal Links (iOS 9) and Deep Links (Android). Basically, open application through the link in the browser.",
|
|
5
|
+
"cordova": {
|
|
6
|
+
"id": "cordova-plugin-universal-links",
|
|
7
|
+
"platforms": [
|
|
8
|
+
"ios",
|
|
9
|
+
"android"
|
|
10
|
+
]
|
|
11
|
+
},
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/thathoff/cordova-plugin-universal-links.git"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"cordova",
|
|
18
|
+
"links",
|
|
19
|
+
"universal",
|
|
20
|
+
"deep links",
|
|
21
|
+
"universal links",
|
|
22
|
+
"ecosystem:cordova",
|
|
23
|
+
"cordova-ios",
|
|
24
|
+
"cordova-android",
|
|
25
|
+
"ios",
|
|
26
|
+
"android"
|
|
27
|
+
],
|
|
28
|
+
"engines": [
|
|
29
|
+
{
|
|
30
|
+
"name": "cordova-ios",
|
|
31
|
+
"version": ">=3.8"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"name": "cordova-android",
|
|
35
|
+
"version": ">=4"
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"mkpath": ">=1.0.0",
|
|
40
|
+
"xml2js": ">=0.4",
|
|
41
|
+
"rimraf": ">=2.4",
|
|
42
|
+
"node-version-compare": ">=1.0.1",
|
|
43
|
+
"plist": ">=1.2.0"
|
|
44
|
+
},
|
|
45
|
+
"author": "Nikolay Demyankov for Nordnet Bank AB",
|
|
46
|
+
"license": "MIT",
|
|
47
|
+
"bugs": {
|
|
48
|
+
"url": "https://github.com/eldadfux/cordova-plugin-universal-links/issues"
|
|
49
|
+
},
|
|
50
|
+
"homepage": "https://github.com/eldadfux/cordova-plugin-universal-links",
|
|
51
|
+
"main": "index.js",
|
|
52
|
+
"directories": {
|
|
53
|
+
"doc": "docs"
|
|
54
|
+
},
|
|
55
|
+
"scripts": {
|
|
56
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
57
|
+
}
|
|
58
|
+
}
|
package/plugin.xml
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
|
|
3
|
+
<plugin id="cordova-plugin-universal-links" version="0.3.0" xmlns="http://apache.org/cordova/ns/plugins/1.0">
|
|
4
|
+
|
|
5
|
+
<name>Universal Links Plugin</name>
|
|
6
|
+
<description>
|
|
7
|
+
Cordova plugin to add in your application support for Universal Links (iOS 9) and Deep Links (Android).
|
|
8
|
+
Basically, open application through the link in the browser.
|
|
9
|
+
</description>
|
|
10
|
+
<license>MIT</license>
|
|
11
|
+
<keywords>cordova,links,universal,deep</keywords>
|
|
12
|
+
|
|
13
|
+
<repo>https://github.com/eldadfux/cordova-plugin-universal-links</repo>
|
|
14
|
+
<issue>https://github.com/eldadfux/cordova-plugin-universal-links/issues</issue>
|
|
15
|
+
|
|
16
|
+
<engines>
|
|
17
|
+
<engine name="cordova-ios" version=">=3.8"></engine>
|
|
18
|
+
<engine name="cordova-android" version=">=4"></engine>
|
|
19
|
+
</engines>
|
|
20
|
+
|
|
21
|
+
<!-- JavaScrip Library Sources -->
|
|
22
|
+
<js-module name="universalLinks" src="www/universal_links.js">
|
|
23
|
+
<clobbers target="universalLinks"/>
|
|
24
|
+
</js-module>
|
|
25
|
+
|
|
26
|
+
<!-- Hooks -->
|
|
27
|
+
<hook src="hooks/afterPrepareHook.js" type="after_prepare"/>
|
|
28
|
+
<hook src="hooks/beforePluginInstallHook.js" type="before_plugin_install" />
|
|
29
|
+
|
|
30
|
+
<platform name="ios">
|
|
31
|
+
<hook src="hooks/iosBeforePrepareHook.js" type="before_prepare" />
|
|
32
|
+
|
|
33
|
+
<!-- Plugin inclusion in Cordova config.xml -->
|
|
34
|
+
<config-file parent="/*" target="config.xml">
|
|
35
|
+
<feature name="UniversalLinks">
|
|
36
|
+
<param name="ios-package" value="CULPlugin"/>
|
|
37
|
+
<param name="onload" value="true"/>
|
|
38
|
+
</feature>
|
|
39
|
+
</config-file>
|
|
40
|
+
|
|
41
|
+
<!-- Objective-C Sources -->
|
|
42
|
+
|
|
43
|
+
<source-file src="src/ios/CULPlugin.m"/>
|
|
44
|
+
<header-file src="src/ios/CULPlugin.h"/>
|
|
45
|
+
|
|
46
|
+
<source-file src="src/ios/AppDelegate+CULPlugin.m"/>
|
|
47
|
+
<header-file src="src/ios/AppDelegate+CULPlugin.h"/>
|
|
48
|
+
|
|
49
|
+
<!-- sources for JS folder -->
|
|
50
|
+
<source-file src="src/ios/JS/CDVPluginResult+CULPlugin.m" target-dir="JS/"/>
|
|
51
|
+
<header-file src="src/ios/JS/CDVPluginResult+CULPlugin.h" target-dir="JS/"/>
|
|
52
|
+
|
|
53
|
+
<source-file src="src/ios/JS/CDVInvokedUrlCommand+CULPlugin.m" target-dir="JS/"/>
|
|
54
|
+
<header-file src="src/ios/JS/CDVInvokedUrlCommand+CULPlugin.h" target-dir="JS/"/>
|
|
55
|
+
|
|
56
|
+
<!-- sources for Model folder -->
|
|
57
|
+
<source-file src="src/ios/Model/CULHost.m" target-dir="Model/"/>
|
|
58
|
+
<header-file src="src/ios/Model/CULHost.h" target-dir="Model/"/>
|
|
59
|
+
|
|
60
|
+
<source-file src="src/ios/Model/CULPath.m" target-dir="Model/"/>
|
|
61
|
+
<header-file src="src/ios/Model/CULPath.h" target-dir="Model/"/>
|
|
62
|
+
|
|
63
|
+
<!-- sources for XML Parser folder -->
|
|
64
|
+
<source-file src="src/ios/Parser/XML/CULXmlTags.m" target-dir="Parser/XML/"/>
|
|
65
|
+
<header-file src="src/ios/Parser/XML/CULXmlTags.h" target-dir="Parser/XML/"/>
|
|
66
|
+
|
|
67
|
+
<source-file src="src/ios/Parser/XML/CULConfigXmlParser.m" target-dir="Parser/XML/"/>
|
|
68
|
+
<header-file src="src/ios/Parser/XML/CULConfigXmlParser.h" target-dir="Parser/XML/"/>
|
|
69
|
+
|
|
70
|
+
<!-- sources for JSON Parser folder -->
|
|
71
|
+
<source-file src="src/ios/Parser/JSON/CULConfigJsonParser.m" target-dir="Parser/JSON/"/>
|
|
72
|
+
<header-file src="src/ios/Parser/JSON/CULConfigJsonParser.h" target-dir="Parser/JSON/"/>
|
|
73
|
+
|
|
74
|
+
<!-- sources for Utils folder -->
|
|
75
|
+
<source-file src="src/ios/Utils/NSBundle+CULPlugin.m" target-dir="Utils/"/>
|
|
76
|
+
<header-file src="src/ios/Utils/NSBundle+CULPlugin.h" target-dir="Utils/"/>
|
|
77
|
+
|
|
78
|
+
</platform>
|
|
79
|
+
|
|
80
|
+
<platform name="android">
|
|
81
|
+
<!-- Plugin inclusion in Cordova config.xml -->
|
|
82
|
+
<config-file parent="/*" target="res/xml/config.xml">
|
|
83
|
+
<feature name="UniversalLinks">
|
|
84
|
+
<param name="android-package" value="com.nordnetab.cordova.ul.UniversalLinksPlugin"/>
|
|
85
|
+
<param name="onload" value="true"/>
|
|
86
|
+
</feature>
|
|
87
|
+
</config-file>
|
|
88
|
+
|
|
89
|
+
<!-- Java Library Sources -->
|
|
90
|
+
<!-- sources for package: com.nordnetab.cordova.ul.js -->
|
|
91
|
+
<source-file src="src/android/com/nordnetab/cordova/ul/js/JSAction.java" target-dir="src/com/nordnetab/cordova/ul/js/"/>
|
|
92
|
+
|
|
93
|
+
<!-- sources for package: com.nordnetab.cordova.ul.model -->
|
|
94
|
+
<source-file src="src/android/com/nordnetab/cordova/ul/model/JSMessage.java" target-dir="src/com/nordnetab/cordova/ul/model/"/>
|
|
95
|
+
<source-file src="src/android/com/nordnetab/cordova/ul/model/ULHost.java" target-dir="src/com/nordnetab/cordova/ul/model/"/>
|
|
96
|
+
<source-file src="src/android/com/nordnetab/cordova/ul/model/ULPath.java" target-dir="src/com/nordnetab/cordova/ul/model/"/>
|
|
97
|
+
|
|
98
|
+
<!-- sources for package: com.nordnetab.cordova.ul.parser -->
|
|
99
|
+
<source-file src="src/android/com/nordnetab/cordova/ul/parser/ULConfigXmlParser.java" target-dir="src/com/nordnetab/cordova/ul/parser/"/>
|
|
100
|
+
<source-file src="src/android/com/nordnetab/cordova/ul/parser/XmlTags.java" target-dir="src/com/nordnetab/cordova/ul/parser/"/>
|
|
101
|
+
|
|
102
|
+
<!-- sources for package: com.nordnetab.cordova.ul -->
|
|
103
|
+
<source-file src="src/android/com/nordnetab/cordova/ul/UniversalLinksPlugin.java" target-dir="src/com/nordnetab/cordova/ul/"/>
|
|
104
|
+
|
|
105
|
+
</platform>
|
|
106
|
+
</plugin>
|