本文整理汇总了TypeScript中plist.parse函数的典型用法代码示例。如果您正苦于以下问题:TypeScript parse函数的具体用法?TypeScript parse怎么用?TypeScript parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了parse函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getBundleIdentifier
function getBundleIdentifier(plistFilePath: string): string {
let plistData: any;
try {
plistData = bplistParser.parseFileSync(plistFilePath)[0];
} catch (err) {
let content = fs.readFileSync(plistFilePath).toString();
plistData = plist.parse(content);
}
return plistData && plistData.CFBundleIdentifier;
}
示例2: parse
private parse(sourceLanguage: SupportedLanguage, documentText: string): any {
switch (sourceLanguage) {
case "xml":
case "tmlanguage":
return plist.parse(documentText);
case "json":
case "json-tmlanguage":
return JSON.parse(documentText);
case "yaml":
case "yaml-tmlanguage":
return YAML.parse(documentText);
default:
return undefined;
}
}
示例3: checkMacResult
async function checkMacResult(packager: Packager, packagerOptions: PackagerOptions, checkOptions: AssertPackOptions, packedAppDir: string) {
const appInfo = packager.appInfo
const info = parsePlist(await readFile(path.join(packedAppDir, "Contents", "Info.plist"), "utf8"))
expect(info).toMatchObject({
CFBundleVersion: info.CFBundleVersion === "50" ? "50" : `${appInfo.version}.${(process.env.TRAVIS_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM)}`
})
// checked manually, remove to avoid mismatch on CI server (where TRAVIS_BUILD_NUMBER is defined and different on each test run)
delete info.AsarIntegrity
delete info.CFBundleVersion
delete info.BuildMachineOSBuild
delete info.NSHumanReadableCopyright
delete info.DTXcode
delete info.DTXcodeBuild
delete info.DTSDKBuild
delete info.DTSDKName
delete info.DTCompiler
if (info.NSAppTransportSecurity != null) {
delete info.NSAppTransportSecurity.NSAllowsArbitraryLoads
}
// test value
if (info.LSMinimumSystemVersion !== "10.12.0") {
delete info.LSMinimumSystemVersion
}
expect(info).toMatchSnapshot()
const checksumData = info.AsarIntegrity
if (checksumData != null) {
const data = JSON.parse(checksumData)
const checksums = data.checksums
for (const name of Object.keys(checksums)) {
checksums[name] = "hash"
}
info.AsarIntegrity = JSON.stringify(data)
}
if (checkOptions.checkMacApp != null) {
await checkOptions.checkMacApp(packedAppDir, info)
}
if (packagerOptions.config != null && (packagerOptions.config as Configuration).cscLink != null) {
const result = await exec("codesign", ["--verify", packedAppDir])
expect(result).not.toMatch(/is not signed at all/)
}
}
示例4: Error
}).spread<string>(function(stdout: string, stderr: string): string {
// First find the path of the app on the device
const filename: string = stdout.trim();
if (!/^\/tmp\/[0-9]+\.ideviceinstaller$/.test(filename)) {
throw new Error("WrongInstalledAppsFile");
}
const list: any[] = pl.parse(fs.readFileSync(filename, 'utf8'));
fs.unlink(filename);
for (let i: number = 0; i < list.length; ++i) {
if (list[i].CFBundleIdentifier === packageId) {
return list[i].Path;
}
}
throw new Error("PackageNotInstalled");
}).then(function(path: string): Q.Promise<net.Socket> {
示例5: checkOsXResult
async function checkOsXResult(packager: Packager, artifacts: Array<string>) {
const productName = getProductName(packager.metadata)
const packedAppDir = path.join(path.dirname(artifacts[0]), (productName || packager.metadata.name) + ".app")
const info = parsePlist(await readText(path.join(packedAppDir, "Contents", "Info.plist")))
assertThat(info).has.properties({
CFBundleDisplayName: productName,
CFBundleIdentifier: "your.id",
LSApplicationCategoryType: "your.app.category.type",
CFBundleVersion: "1.0.0" + "." + (process.env.TRAVIS_BUILD_NUMBER || process.env.CIRCLE_BUILD_NUM)
})
const result = await exec("codesign", ["--verify", packedAppDir])
assertThat(result[0].toString()).not.match(/is not signed at all/)
assertThat(artifacts.map(it => path.basename((it))).sort()).deepEqual([
"TestApp-1.0.0-mac.zip",
"TestApp-1.0.0.dmg"
].sort())
}
示例6: _readThemeFile
private _readThemeFile(fullPath: string): SyntaxTheme {
const fileContents = fs.readFileSync(fullPath, "utf8");
const tmThemeContents = plist.parse(fileContents);
const foreground = this._readTextStyleValue(tmThemeContents, "settings.0.settings.foreground", "");
const background = this._readTextStyleValue(tmThemeContents, "settings.0.settings.background", "");
const cursor = this._readTextStyleValue(tmThemeContents, "settings.0.settings.caret", "");
const invisibles = this._readTextStyleValue(tmThemeContents, "settings.0.settings.invisibles", "");
const lineHighlight = this._readTextStyleValue(tmThemeContents, "settings.0.settings.lineHighlight", "");
const selection = this._readTextStyleValue(tmThemeContents, "settings.0.settings.selection", "");
return {
foreground,
invisibles,
background,
cursor,
lineHighlight,
selection,
syntaxTokenRule: this._readTokenRules(tmThemeContents)
};
}
示例7:
<data>QWxpY2U=</data>
</dict>
<dict>
<key>id</key>
<integer>456</integer>
<key>name</key>
<string>Bob</string>
<key>birthday</key>
<date>2000-12-31T23:59:59Z</date>
<key>data</key>
<data>Qm9i</data>
</dict>
</array>
</plist>`;
const plistValue1 = plist.parse(plistString);
if (plistValue1 instanceof Array) {
for (const elem of plistValue1) {
if (instanceOfPerson(elem)) {
console.log(`id: ${elem.id}`);
console.log(`name: ${elem.name}`);
console.log(`birthday: ${elem.birthday.toDateString()}`);
console.log(`data: ${elem.data.toString()}`);
}
}
}
// parsing a plist from filename
const plistValue2 = plist.parse(
fs.readFileSync("plist/sample.plist", "utf8"));
console.log(plistValue2);
示例8: createApp
export async function createApp(opts: ElectronPackagerOptions, appOutDir: string, initializeApp: () => Promise<any>) {
const appInfo = opts.appInfo
const appFilename = appInfo.productFilename
const contentsPath = path.join(appOutDir, "Electron.app", "Contents")
const frameworksPath = path.join(contentsPath, "Frameworks")
const appPlistFilename = path.join(contentsPath, "Info.plist")
const helperPlistFilename = path.join(frameworksPath, "Electron Helper.app", "Contents", "Info.plist")
const helperEHPlistFilename = path.join(frameworksPath, "Electron Helper EH.app", "Contents", "Info.plist")
const helperNPPlistFilename = path.join(frameworksPath, "Electron Helper NP.app", "Contents", "Info.plist")
const result = await BluebirdPromise.all<any | n>([
initializeApp(),
BluebirdPromise.map<any | null>([appPlistFilename, helperPlistFilename, helperEHPlistFilename, helperNPPlistFilename, opts["extend-info"]], it => it == null ? it : readFile(it, "utf8"))
])
const fileContents: Array<string> = result[1]!
const appPlist = parsePlist(fileContents[0])
const helperPlist = parsePlist(fileContents[1])
const helperEHPlist = parsePlist(fileContents[2])
const helperNPPlist = parsePlist(fileContents[3])
// If an extend-info file was supplied, copy its contents in first
if (fileContents[4] != null) {
Object.assign(appPlist, parsePlist(fileContents[4]))
}
// Now set fields based on explicit options
const appBundleIdentifier = filterCFBundleIdentifier(appInfo.id)
const helperBundleIdentifier = filterCFBundleIdentifier(opts["helper-bundle-id"] || `${appBundleIdentifier}.helper`)
const buildVersion = appInfo.buildVersion
const appCategoryType = opts["app-category-type"]
const humanReadableCopyright = appInfo.copyright
appPlist.CFBundleDisplayName = appInfo.productName
appPlist.CFBundleIdentifier = appBundleIdentifier
appPlist.CFBundleName = appInfo.productName
helperPlist.CFBundleDisplayName = `${appInfo.productName} Helper`
helperPlist.CFBundleIdentifier = helperBundleIdentifier
appPlist.CFBundleExecutable = appFilename
helperPlist.CFBundleName = appInfo.productName
helperPlist.CFBundleExecutable = `${appFilename} Helper`
helperEHPlist.CFBundleDisplayName = `${appFilename} Helper EH`
helperEHPlist.CFBundleIdentifier = `${helperBundleIdentifier}.EH`
helperEHPlist.CFBundleName = `${appInfo.productName} Helper EH`
helperEHPlist.CFBundleExecutable = `${appFilename} Helper EH`
helperNPPlist.CFBundleDisplayName = `${appInfo.productName} Helper NP`
helperNPPlist.CFBundleIdentifier = `${helperBundleIdentifier}.NP`
helperNPPlist.CFBundleName = `${appInfo.productName} Helper NP`
helperNPPlist.CFBundleExecutable = `${appFilename} Helper NP`
if (appInfo.version != null) {
appPlist.CFBundleShortVersionString = appPlist.CFBundleVersion = appInfo.version
}
if (buildVersion != null) {
appPlist.CFBundleVersion = buildVersion
}
if (opts.protocols && opts.protocols.length) {
appPlist.CFBundleURLTypes = opts.protocols.map(function (protocol: any) {
return {
CFBundleURLName: protocol.name,
CFBundleURLSchemes: [].concat(protocol.schemes)
}
})
}
if (appCategoryType) {
appPlist.LSApplicationCategoryType = appCategoryType
}
if (humanReadableCopyright) {
appPlist.NSHumanReadableCopyright = humanReadableCopyright
}
const promises: Array<BluebirdPromise<any | n>> = [
writeFile(appPlistFilename, buildPlist(appPlist)),
writeFile(helperPlistFilename, buildPlist(helperPlist)),
writeFile(helperEHPlistFilename, buildPlist(helperEHPlist)),
writeFile(helperNPPlistFilename, buildPlist(helperNPPlist)),
doRename(path.join(contentsPath, "MacOS"), "Electron", appPlist.CFBundleExecutable)
]
if (opts.icon != null) {
promises.push(copy(opts.icon, path.join(contentsPath, "Resources", appPlist.CFBundleIconFile)))
}
await BluebirdPromise.all(promises)
await moveHelpers(frameworksPath, appFilename)
await rename(path.dirname(contentsPath), path.join(appOutDir, `${appFilename}.app`))
}
示例9: require
import path = require('path');
import fs = require('fs-extra');
import tl = require('vsts-task-lib/task');
var plist = require('plist');
import {recursiveProcessing} from './common/expandJObject';
try {
var source = tl.getPathInput("PlistSource");
var variablePrefix = tl.getInput("VariablePrefix");
var isSecret = tl.getBoolInput("MarkAsSecret");
var content = fs.readFileSync(source, { encoding: 'utf8' });
var jObject = plist.parse(content);
recursiveProcessing(jObject, variablePrefix, isSecret);
tl.setResult(tl.TaskResult.Succeeded, "Variables loaded");
} catch (err) {
console.error(String(err));
tl.setResult(tl.TaskResult.Failed, String(err));
}
示例10: createMacApp
export async function createMacApp(packager: PlatformPackager<any>, appOutDir: string, asarIntegrity: AsarIntegrity | null) {
const appInfo = packager.appInfo
const appFilename = appInfo.productFilename
const contentsPath = path.join(appOutDir, packager.electronDistMacOsAppName, "Contents")
const frameworksPath = path.join(contentsPath, "Frameworks")
const appPlistFilename = path.join(contentsPath, "Info.plist")
const helperPlistFilename = path.join(frameworksPath, `${packager.electronDistMacOsExecutableName} Helper.app`, "Contents", "Info.plist")
const helperEHPlistFilename = path.join(frameworksPath, `${packager.electronDistMacOsExecutableName} Helper EH.app`, "Contents", "Info.plist")
const helperNPPlistFilename = path.join(frameworksPath, `${packager.electronDistMacOsExecutableName} Helper NP.app`, "Contents", "Info.plist")
const buildMetadata = packager.config!
const fileContents: Array<string> = await BluebirdPromise.map([appPlistFilename, helperPlistFilename, helperEHPlistFilename, helperNPPlistFilename, (buildMetadata as any)["extend-info"]], it => it == null ? it : readFile(it, "utf8"))
const appPlist = parsePlist(fileContents[0])
const helperPlist = parsePlist(fileContents[1])
const helperEHPlist = parsePlist(fileContents[2])
const helperNPPlist = parsePlist(fileContents[3])
// If an extend-info file was supplied, copy its contents in first
if (fileContents[4] != null) {
Object.assign(appPlist, parsePlist(fileContents[4]))
}
const macOptions = buildMetadata.mac || {}
if (macOptions.extendInfo != null) {
Object.assign(appPlist, macOptions.extendInfo)
}
const appBundleIdentifier = filterCFBundleIdentifier(appInfo.id)
const oldHelperBundleId = (buildMetadata as any)["helper-bundle-id"]
if (oldHelperBundleId != null) {
log.warn("build.helper-bundle-id is deprecated, please set as build.mac.helperBundleId")
}
const helperBundleIdentifier = filterCFBundleIdentifier(packager.platformSpecificBuildOptions.helperBundleId || oldHelperBundleId || `${appBundleIdentifier}.helper`)
const icon = await packager.getIconPath()
const oldIcon = appPlist.CFBundleIconFile
if (icon != null) {
appPlist.CFBundleIconFile = `${appFilename}.icns`
}
appPlist.CFBundleDisplayName = appInfo.productName
appPlist.CFBundleIdentifier = appBundleIdentifier
appPlist.CFBundleName = appInfo.productName
// https://github.com/electron-userland/electron-builder/issues/1278
appPlist.CFBundleExecutable = !appFilename.endsWith(" Helper") ? appFilename : appFilename.substring(0, appFilename.length - " Helper".length)
helperPlist.CFBundleExecutable = `${appFilename} Helper`
helperEHPlist.CFBundleExecutable = `${appFilename} Helper EH`
helperNPPlist.CFBundleExecutable = `${appFilename} Helper NP`
helperPlist.CFBundleDisplayName = `${appInfo.productName} Helper`
helperEHPlist.CFBundleDisplayName = `${appInfo.productName} Helper EH`
helperNPPlist.CFBundleDisplayName = `${appInfo.productName} Helper NP`
helperPlist.CFBundleIdentifier = helperBundleIdentifier
helperEHPlist.CFBundleIdentifier = `${helperBundleIdentifier}.EH`
helperNPPlist.CFBundleIdentifier = `${helperBundleIdentifier}.NP`
appPlist.CFBundleShortVersionString = macOptions.bundleShortVersion || appInfo.version
appPlist.CFBundleVersion = appInfo.buildVersion
const protocols = asArray(buildMetadata.protocols).concat(asArray(packager.platformSpecificBuildOptions.protocols))
if (protocols.length > 0) {
appPlist.CFBundleURLTypes = protocols.map(protocol => {
const schemes = asArray(protocol.schemes)
if (schemes.length === 0) {
throw new Error(`Protocol "${protocol.name}": must be at least one scheme specified`)
}
return {
CFBundleURLName: protocol.name,
CFBundleTypeRole: protocol.role || "Editor",
CFBundleURLSchemes: schemes.slice()
}
})
}
const resourcesPath = path.join(contentsPath, "Resources")
const fileAssociations = packager.fileAssociations
if (fileAssociations.length > 0) {
appPlist.CFBundleDocumentTypes = await BluebirdPromise.map(fileAssociations, async fileAssociation => {
const extensions = asArray(fileAssociation.ext).map(normalizeExt)
const customIcon = await packager.getResource(getPlatformIconFileName(fileAssociation.icon, true), `${extensions[0]}.icns`)
let iconFile = appPlist.CFBundleIconFile
if (customIcon != null) {
iconFile = path.basename(customIcon)
await copyOrLinkFile(customIcon, path.join(resourcesPath, iconFile))
}
const result = {
CFBundleTypeExtensions: extensions,
CFBundleTypeName: fileAssociation.name || extensions[0],
CFBundleTypeRole: fileAssociation.role || "Editor",
CFBundleTypeIconFile: iconFile
} as any
//.........这里部分代码省略.........