Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
this.simDeviceTypes[id] = deviceType;
} catch (e) {
// squelch
}
}
}
// runtimes
const runtimesDir = path.join(dir, 'Runtimes');
if (isDir(runtimesDir)) {
// regex to extract the version from the runtime name
const runtimeNameRegExp = /\s(\d+(?:\.\d+(?:\.\d+)?)?)$/;
for (const name of fs.readdirSync(runtimesDir)) {
try {
let info = plist.readFileSync(path.join(runtimesDir, name, 'Contents/Info.plist'));
const runtime = {
name: info.CFBundleName,
version: null
};
const id = info.CFBundleIdentifier;
const m = info.CFBundleName.match(runtimeNameRegExp);
if (m) {
runtime.version = m[1];
}
try {
info = plist.readFileSync(path.join(runtimesDir, name, 'Contents/Resources/profile.plist'));
if (!runtime.version || info.defaultVersionString.startsWith(runtime.version)) {
runtime.version = info.defaultVersionString;
}
} catch (e) {
// device types
const deviceTypesDir = path.join(dir, 'DeviceTypes');
if (isDir(deviceTypesDir)) {
for (const name of fs.readdirSync(deviceTypesDir)) {
try {
let info = plist.readFileSync(path.join(deviceTypesDir, name, 'Contents/Info.plist'));
const deviceType = {
name: info.CFBundleName,
model: 'unknown',
supportsWatch: false
};
const id = info.CFBundleIdentifier;
try {
info = plist.readFileSync(path.join(deviceTypesDir, name, 'Contents/Resources/profile.plist'));
if (info.modelIdentifier) {
deviceType.model = info.modelIdentifier;
}
} catch (e) {
// squelch
}
try {
info = plist.readFileSync(path.join(deviceTypesDir, name, 'Contents/Resources/capabilities.plist'));
deviceType.supportsWatch = !!info.capabilities['watch-companion'];
} catch (e) {
// squelch
}
this.simDeviceTypes[id] = deviceType;
} catch (e) {
model: 'unknown',
supportsWatch: false
};
const id = info.CFBundleIdentifier;
try {
info = plist.readFileSync(path.join(deviceTypesDir, name, 'Contents/Resources/profile.plist'));
if (info.modelIdentifier) {
deviceType.model = info.modelIdentifier;
}
} catch (e) {
// squelch
}
try {
info = plist.readFileSync(path.join(deviceTypesDir, name, 'Contents/Resources/capabilities.plist'));
deviceType.supportsWatch = !!info.capabilities['watch-companion'];
} catch (e) {
// squelch
}
this.simDeviceTypes[id] = deviceType;
} catch (e) {
// squelch
}
}
}
// runtimes
const runtimesDir = path.join(dir, 'Runtimes');
if (isDir(runtimesDir)) {
// regex to extract the version from the runtime name
unzipper.on('extract', function() {
var path = glob.sync(output.path + '/Payload/*/')[0];
data.metadata = plist.readFileSync(path + 'Info.plist');
async.parallel([
async.apply(provisioning, path + 'embedded.mobileprovision'),
async.apply(entitlements, path)
], function(error, results){
if(error){
return cleanUp(error);
}
data.provisioning = results[0];
// Hard to serialize and it looks messy in output
delete data.provisioning.DeveloperCertificates;
data.entitlements = results[1];
return [];
}
const nameRegExp = new RegExp(`^${sdkTypeName}(.*).sdk$`);
const results = new Set();
for (const name of fs.readdirSync(dir)) {
const m = name.match(nameRegExp);
const subdir = m && path.join(dir, name);
if (!m || !isDir(subdir)) {
continue;
}
let ver = m[1] || null;
try {
const plistFile = path.join(subdir, 'System/Library/CoreServices/SystemVersion.plist');
const info = plist.readFileSync(plistFile);
if (info.ProductVersion) {
ver = info.ProductVersion;
}
} catch (e) {
// squelch
}
results.add(ver);
}
return Array.from(results).sort(version.rcompare);
}
function getExecutable (appdir) {
if (!appdir) {
throw new Error('No application directory is provided');
}
const plistPath = path.join(appdir, 'Info.plist');
try {
const plistData = plist.readFileSync(plistPath);
const cfBundleExecutable = plistData['CFBundleExecutable'];
if (cfBundleExecutable) {
return cfBundleExecutable;
}
} catch (e) {
// do nothing
}
const exename = path.basename(appdir);
const dotap = exename.indexOf('.app');
return (dotap === -1) ? exename : exename.substring(0, dotap);
}
import fs from 'fs';
import path from 'path';
import plist from 'simple-plist';
import { Characteristic, Formats, Units } from "../Characteristic";
/**
* This module is intended to be run from the command line. It is a script that extracts Apple's Service
* and Characteristic UUIDs and structures from Apple's own HomeKit Accessory Simulator app.
*/
// assumed location of the plist we need (might want to make this a command-line argument at some point)
var plistPath = '/Applications/HomeKit Accessory Simulator.app/Contents/Frameworks/HAPAccessoryKit.framework/Versions/A/Resources/default.metadata.plist';
var metadata = plist.readFileSync(plistPath);
// begin writing the output file
var outputPath = path.join(__dirname, '..', '..', '..', 'src', 'lib', 'gen', 'HomeKitTypes.generated.ts');
var output = fs.createWriteStream(outputPath);
output.write("// THIS FILE IS AUTO-GENERATED - DO NOT MODIFY\n");
output.write("\n");
// output.write("var inherits = require('util').inherits;\n");
output.write("import {\n");
output.write(" Characteristic,\n");
output.write(" CharacteristicProps,\n");
output.write(" Formats,\n");
output.write(" Perms,\n");
output.write(" Units,\n");
output.write("} from '../Characteristic';\n");
output.write("import { Service } from '../Service';\n");
function getExecutable (appdir, exename) {
if (appdir) {
const plistPath = path.join(appdir, 'Info.plist');
try {
const plistData = plist.readFileSync(plistPath);
const cfBundleExecutable = plistData['CFBundleExecutable'];
if (cfBundleExecutable) {
return cfBundleExecutable;
}
} catch (e) {
// do nothing
}
}
return exename;
}
file.target = opt ? opt.target : undefined;
file.uuid = this.generateUuid();
this.addToPbxBuildFileSection(file);
this.addToPbxSourcesBuildPhase(file);
file.models = [];
var currentVersionName;
var modelFiles = fs.readdirSync(file.path);
for (var index in modelFiles) {
var modelFileName = modelFiles[index];
var modelFilePath = path.join(filePath, modelFileName);
if (modelFileName == '.xccurrentversion') {
currentVersionName = plist.readFileSync(modelFilePath)._XCCurrentVersionName;
continue;
}
var modelFile = new pbxFile(modelFilePath);
modelFile.fileRef = this.generateUuid();
this.addToPbxFileReferenceSection(modelFile);
file.models.push(modelFile);
if (currentVersionName && currentVersionName === modelFileName) {
file.currentModel = modelFile;
}
}
if (!file.currentModel) {
file.target = opt ? opt.target : undefined;
file.uuid = this.generateUuid();
this.addToPbxBuildFileSection(file);
this.addToPbxSourcesBuildPhase(file);
file.models = [];
var currentVersionName;
var modelFiles = fs.readdirSync(file.path);
for (var index in modelFiles) {
var modelFileName = modelFiles[index];
var modelFilePath = path.join(filePath, modelFileName);
if (modelFileName == '.xccurrentversion') {
currentVersionName = plist.readFileSync(modelFilePath)._XCCurrentVersionName;
continue;
}
var modelFile = new pbxFile(modelFilePath);
modelFile.fileRef = this.generateUuid();
this.addToPbxFileReferenceSection(modelFile);
file.models.push(modelFile);
if (currentVersionName && currentVersionName === modelFileName) {
file.currentModel = modelFile;
}
}
if (!file.currentModel) {