-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_app_schemes.js
35 lines (33 loc) · 1.09 KB
/
get_app_schemes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const getMacApps = require("get-mac-apps");
const parser = require('plist');
const fs = require('fs');
const path = require('path');
getMacApps
.getApps()
.then(apps => {
const presudoList = apps.map((app, index) => {
const appConfigPath = path.join(app.path, 'Contents/info.plist');
let schemes = [];
if (fs.existsSync(appConfigPath)) {
try {
const fileContent = fs.readFileSync(appConfigPath, {encoding: 'utf-8'});
const pXml = parser.parse(fileContent);
if (pXml.CFBundleURLTypes) {
pXml.CFBundleURLTypes.forEach(scheme => {
if (scheme.CFBundleURLSchemes) {
schemes = [...schemes, ...scheme.CFBundleURLSchemes]
}
});
}
} catch (e) {
console.log(app._name)
}
}
return {
schemes,
name: app._name,
}
}).filter(app => app.schemes.length);
fs.writeFileSync(path.join(__dirname, './src/appSchemes.js'), `export const sList = ${JSON.stringify(presudoList)}`);
})
.catch(error => console.log(error.message));