Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Node CI

on: [push, pull_request]

jobs:
test:
name: NodeJS ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
node-version: [18.x, 20.x, 22.x]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}

- name: Environment Information
run: |
node --version
npm --version

- name: npm install & test
run: npm it
env:
CI: true

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
24 changes: 11 additions & 13 deletions hooks/afterPrepareHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ It will inject required preferences in the platform-specific projects, based on
data you have specified in the projects config.xml file.
*/

var configParser = require('./lib/configXmlParser.js');
const path = require('node:path');

var androidManifestWriter = require('./lib/android/manifestWriter.js');
var androidWebHook = require('./lib/android/webSiteHook.js');
var iosProjectEntitlements = require('./lib/ios/projectEntitlements.js');
var iosAppSiteAssociationFile = require('./lib/ios/appleAppSiteAssociationFile.js');
var ANDROID = 'android';
var IOS = 'ios';
const ExtendedConfigParser = require('./lib/ExtendedConfigParser.js');
const { CONFIG_FILE_NAME, PLATFORM_ANDROID, PLATFORM_IOS } = require('./lib/constants.js')

module.exports = function(ctx) {
run(ctx);
Expand All @@ -23,32 +24,30 @@ module.exports = function(ctx) {
* @param {Object} cordovaContext - cordova context object
*/
function run(cordovaContext) {
var pluginPreferences = configParser.readPreferences(cordovaContext);
const configFilePath = path.join(cordovaContext.opts.projectRoot, CONFIG_FILE_NAME);
const configFile = new ExtendedConfigParser(configFilePath);
const pluginPreferences = configFile.getUniversalLinks();
var platformsList = cordovaContext.opts.platforms;

// if no preferences are found - exit
if (pluginPreferences == null) {
if (!pluginPreferences) {
return;
}

// if no host is defined - exit
if (pluginPreferences.hosts == null || pluginPreferences.hosts.length == 0) {
if (pluginPreferences.hosts === null || pluginPreferences.hosts.length === 0) {
console.warn('No host is specified in the config.xml. Universal Links plugin is not going to work.');
return;
}

platformsList.forEach(function(platform) {
switch (platform) {
case ANDROID:
{
case PLATFORM_ANDROID:
activateUniversalLinksInAndroid(cordovaContext, pluginPreferences);
break;
}
case IOS:
{
case PLATFORM_IOS:
activateUniversalLinksInIos(cordovaContext, pluginPreferences);
break;
}
}
});
}
Expand All @@ -74,7 +73,6 @@ function activateUniversalLinksInAndroid(cordovaContext, pluginPreferences) {
* @param {Object} pluginPreferences - plugin preferences from the config.xml file. Basically, content from <universal-links> tag.
*/
function activateUniversalLinksInIos(cordovaContext, pluginPreferences) {

// generate entitlements file
iosProjectEntitlements.generateAssociatedDomainsEntitlements(cordovaContext, pluginPreferences);

Expand Down
55 changes: 0 additions & 55 deletions hooks/beforePluginInstallHook.js

This file was deleted.

74 changes: 0 additions & 74 deletions hooks/iosBeforePrepareHook.js

This file was deleted.

67 changes: 67 additions & 0 deletions hooks/lib/ExtendedConfigParser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const { ConfigParser } = require('cordova-common');

const { DEFAULT_SCHEME, PLATFORM_ANDROID, PLATFORM_IOS } = require('./constants.js')

class ExtendedConfigParser extends ConfigParser {
getPackageName (platform) {
let packageName;

switch (platform) {
case PLATFORM_ANDROID:
packageName = this.android_packageName();
break;
case PLATFORM_IOS:
packageName = this.ios_CFBundleIdentifier();
break;
}

if (packageName === undefined || packageName.length == 0) {
packageName = this.packageName();
}

return packageName;
}

/**
* Returns the privacy manifest node, if available.
* Otherwise `null` is returned.
*/
getUniversalLinks () {
const universalLinks = this.doc.find('./universal-links');

if (!universalLinks) {
console.warn('<universal-links> tag is not set in the config.xml. Universal Links plugin is not going to work.');
return;
}

const iosTeamIdEl = universalLinks.find('./ios-team-id');
const iosTeamId = iosTeamIdEl && iosTeamIdEl.attrib.value || null;

const hosts = universalLinks.findall('./host').map(host => ({
scheme: host.attrib.scheme || DEFAULT_SCHEME,
name: host.attrib.name || '',
paths: extractPathUrlsFromHost(host)
}));

return { hosts, iosTeamId }
}
}

function extractPathUrlsFromHost(host) {
const paths = host.findall('./path');

if (paths.length === 0) {
return ['*'];
}

const urls = paths.map(path => path.attrib.url)
.filter(path => !!path);

if (urls.includes('*')) {
return ['*'];
}

return urls;
}

module.exports = ExtendedConfigParser;
4 changes: 2 additions & 2 deletions hooks/lib/android/manifestWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
Class injects plugin preferences into AndroidManifest.xml file.
*/

var path = require('path');
var path = require('node:path');
var xmlHelper = require('../xmlHelper.js');
var fs = require('fs');
var fs = require('node:fs');

module.exports = {
writePreferences: writePreferences
Expand Down
19 changes: 11 additions & 8 deletions hooks/lib/android/webSiteHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ More documentation on that can be found here:
https://developer.android.com/training/app-indexing/enabling-app-indexing.html
*/

var fs = require('fs');
var path = require('path');
var mkpath = require('mkpath');
var ConfigXmlHelper = require('../configXmlHelper.js');
var fs = require('node:fs');
var path = require('node:path');
var WEB_HOOK_FILE_PATH = path.join('ul_web_hooks', 'android', 'android_web_hook.html');
var WEB_HOOK_TPL_FILE_PATH = path.join('plugins', 'cordova-universal-links-plugin', 'ul_web_hooks', 'android_web_hook_tpl.html');
var WEB_HOOK_TPL_FILE_PATH = path.join('plugins/@gedysintraware/cordova-universal-links-plugin/ul_web_hooks/android_web_hook_tpl.html');
var LINK_PLACEHOLDER = '[__LINKS__]';
var LINK_TEMPLATE = '<link rel="alternate" href="android-app://<package_name>/<scheme>/<host><path>" />';

const ExtendedConfigParser = require('../ExtendedConfigParser.js');
const { CONFIG_FILE_NAME, PLATFORM_ANDROID } = require('../constants.js');

module.exports = {
generate: generateWebHook
};
Expand All @@ -30,8 +31,10 @@ module.exports = {
*/
function generateWebHook(cordovaContext, pluginPreferences) {
var projectRoot = cordovaContext.opts.projectRoot;
var configXmlHelper = new ConfigXmlHelper(cordovaContext);
var packageName = configXmlHelper.getPackageName('android');

const configFilePath = path.join(projectRoot, CONFIG_FILE_NAME);
const configFile = new ExtendedConfigParser(configFilePath);
var packageName = configFile.getPackageName(PLATFORM_ANDROID);
var template = readTemplate(projectRoot);

// if template was not found - exit
Expand Down Expand Up @@ -153,7 +156,7 @@ function saveWebHook(projectRoot, hookContent) {
*/
function createDirectoryIfNeeded(dir) {
try {
mkpath.sync(dir);
fs.mkdirSync(dir, { recursive: true });
} catch (err) {
console.log(err);
}
Expand Down
Loading