本文整理汇总了TypeScript中bluebird.Promise类的典型用法代码示例。如果您正苦于以下问题:TypeScript Promise类的具体用法?TypeScript Promise怎么用?TypeScript Promise使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Promise类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: require
import { spawn } from "child_process"
import * as path from "path"
import { Promise as BluebirdPromise } from "bluebird"
import * as fs from "fs-extra-p"
import { Platform } from "out/metadata";
// we set NODE_PATH in this file, so, we cannot use 'out/awaiter' path here
//noinspection JSUnusedLocalSymbols
const __awaiter = require("../../../out/awaiter")
const downloadElectron: (options: any) => Promise<any> = BluebirdPromise.promisify(require("electron-download"))
const packager = require("../../../out/packager")
const rootDir = path.join(__dirname, "..", "..", "..")
const testPackageDir = path.join(require("os").tmpdir(), "electron_builder_published")
const testNodeModules = path.join(testPackageDir, "node_modules")
const electronVersion = "0.37.7"
BluebirdPromise.all([
deleteOldElectronVersion(),
downloadAllRequiredElectronVersions(),
fs.outputFile(path.join(testPackageDir, "package.json"), `{
"private": true,
"version": "1.0.0",
"name": "test",
"dependencies": {
"electron-builder": "file:${path.posix.join(__dirname.replace(/\\/g, "/"), "..", "..")}"
}
}`)
.then(() => copyDependencies())
示例2: assertThat
packed: () => {
assertThat(platformPackager.effectiveDistOptions.loadingGif).equal(loadingGifPath)
assertThat(platformPackager.effectiveDistOptions.certificateFile).equal("secretFile")
return BluebirdPromise.resolve(null)
},
示例3: build
async build(arch: Arch) {
const packager = this.packager
const iconPath = await packager.iconPath
const guid = this.nsisOptions.guid || await BluebirdPromise.promisify(uuid5)({namespace: ELECTRON_BUILDER_NS_UUID, name: packager.info.appId})
const version = this.packager.metadata.version
const productName = packager.appName
const defines: any = {
PRODUCT_NAME: productName,
APP_ID: packager.info.appId,
APP_DESCRIPTION: smarten(packager.metadata.description),
APP_BUILD_DIR: this.appOutDir,
VERSION: version,
MUI_ICON: iconPath,
MUI_UNICON: iconPath,
COMPANY_NAME: packager.metadata.author.name,
APP_EXECUTABLE_FILENAME: `${packager.appName}.exe`,
UNINSTALL_FILENAME: `Uninstall ${productName}.exe`,
MULTIUSER_INSTALLMODE_INSTDIR: guid,
MULTIUSER_INSTALLMODE_INSTALL_REGISTRY_KEY: guid,
MULTIUSER_INSTALLMODE_UNINSTALL_REGISTRY_KEY: guid,
MULTIUSER_INSTALLMODE_DEFAULT_REGISTRY_VALUENAME: "UninstallString",
MULTIUSER_INSTALLMODE_INSTDIR_REGISTRY_VALUENAME: "InstallLocation",
}
if (this.nsisOptions.perMachine === true) {
defines.MULTIUSER_INSTALLMODE_DEFAULT_ALLUSERS = null
}
else {
defines.MULTIUSER_INSTALLMODE_DEFAULT_CURRENTUSER = null
}
if (this.nsisOptions.allowElevation !== false) {
defines.MULTIUSER_INSTALLMODE_ALLOW_ELEVATION = null
}
const archSuffix = getArchSuffix(arch)
const installerPath = path.join(this.outDir, `${this.packager.appName} Setup ${version}${archSuffix}.exe`)
const commands: any = {
FileBufSize: "64",
Name: `"${productName}"`,
OutFile: `"${installerPath}"`,
Unicode: "true",
}
if (packager.devMetadata.build.compression !== "store") {
commands.SetCompressor = "/SOLID lzma"
// default is 8: test app installer size 37.2 vs 36 if dict size 64
commands.SetCompressorDictSize = "64"
}
else {
commands.SetCompress = "off"
}
const oneClick = this.nsisOptions.oneClick !== false
log(`Building ${oneClick ? "one-click " : ""}NSIS installer using nsis ${NSIS_VERSION}`)
if (oneClick) {
defines.ONE_CLICK = null
commands.AutoCloseWindow = "true"
}
debug(defines)
debug(commands)
const args: Array<string> = []
for (let name of Object.keys(defines)) {
const value = defines[name]
if (value == null) {
args.push(`-D${name}`)
}
else {
args.push(`-D${name}=${value}`)
}
}
for (let name of Object.keys(commands)) {
args.push(`-X${name} ${commands[name]}`)
}
args.push(path.join(__dirname, "..", "..", "templates", "nsis", "installer.nsi"))
const binDir = process.platform === "darwin" ? "osx" : (process.platform === "win32" ? "Bin" : "linux")
const nsisPath = await this.nsisPath
// we use NSIS_CONFIG_CONST_DATA_PATH=no to build makensis on Linux, but in any case it doesn't use stubs as OS X/Windows version, so, we explicitly set NSISDIR
await exec(path.join(nsisPath, binDir, process.platform === "win32" ? "makensis.exe" : "makensis"), args, {
env: Object.assign({}, process.env, {NSISDIR: nsisPath})
})
await packager.sign(installerPath)
this.packager.dispatchArtifactCreated(installerPath, `${this.packager.metadata.name}-Setup-${version}${archSuffix}.exe`)
}
示例4: doSign
protected doSign(opts: SignOptions): Promise<any> {
this.signOptions = opts
return BluebirdPromise.resolve(null)
}
示例5: writeFile
tempDirCreated: projectDir => BluebirdPromise.all([
writeFile(path.join(projectDir, "build", "osx.entitlements"), ""),
writeFile(path.join(projectDir, "build", "osx.inherit.entitlements"), ""),
]),
示例6: require
import { AppMetadata, InfoRetriever, ProjectMetadataProvider, Metadata } from "./repositoryInfo"
import EventEmitter = NodeJS.EventEmitter
import { tsAwaiter } from "./awaiter"
import { Promise as BluebirdPromise } from "bluebird"
import * as path from "path"
import packager = require("electron-packager-tf")
const __awaiter = tsAwaiter
Array.isArray(__awaiter)
const pack = BluebirdPromise.promisify(packager)
export interface DevMetadata extends Metadata {
build: DevBuildMetadata
directories?: MetadataDirectories
}
export interface MetadataDirectories {
buildResources?: string
}
export interface DevBuildMetadata {
osx: appdmg.Specification
win: any,
linux: any
}
export interface PackagerOptions {
arch?: string
示例7: assertThat
packed: () => {
assertThat(platformPackager.effectiveDistOptions.loadingGif).isEqualTo(loadingGifPath)
assertThat(platformPackager.signOptions.cert).isEqualTo("secretFile")
assertThat(platformPackager.signOptions.password).isEqualTo("pass")
return BluebirdPromise.resolve(null)
},
示例8: resolve
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fooArrProm = fooArrProm.each((item: Foo): Bar => bar);
fooArrProm = fooArrProm.each((item: Foo, index: number) => index ? bar : null);
fooArrProm = fooArrProm.each((item: Foo, index: number, arrayLength: number): Bar => bar);
fooArrProm = fooArrProm.each((item: Foo, index: number, arrayLength: number): Bluebird<Bar> => barProm);
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
fooProm = new Bluebird.Promise<Foo>((resolve, reject) => {
resolve(foo);
});
fooProm = Bluebird.Promise.try<Foo>(() => {
return foo;
});
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
function getMaybePromise(): Foo|Bluebird<Foo> {
return foo;
}
fooProm = Bluebird.try(() => {
return getMaybePromise();
});
fooProm = Bluebird.try<Foo>(() => {
return getMaybePromise();
});
fooProm = Bluebird.try(() => {
示例9: _download
import { Socket } from "net"
import { IncomingMessage, ClientRequest } from "http"
import * as https from "https"
import { createWriteStream, ensureDir } from "fs-extra-p"
import { parse as parseUrl } from "url"
import { Promise as BluebirdPromise } from "bluebird"
import * as path from "path"
const maxRedirects = 10
export const download = BluebirdPromise.promisify(_download)
function _download(url: string, destination: string, callback: (error: Error) => void): void {
doDownload(url, destination, 0, callback)
}
export function addTimeOutHandler(request: ClientRequest, callback: (error: Error) => void) {
request.on("socket", function (socket: Socket) {
socket.setTimeout(60 * 1000, () => {
callback(new Error("Request timed out"))
request.abort()
})
})
}
function doDownload(url: string, destination: string, redirectCount: number, callback: (error: Error) => void) {
const ensureDirPromise = ensureDir(path.dirname(destination))
const parsedUrl = parseUrl(url)
// user-agent must be specified, otherwise some host can return 401 unauthorised
const request = https.request({
示例10: packageInDistributableFormat
async packageInDistributableFormat(outDir: string, appOutDir: string, arch: string): Promise<any> {
let iconUrl = this.devMetadata.build.iconUrl
if (!iconUrl) {
if (this.customBuildOptions != null) {
iconUrl = this.customBuildOptions.iconUrl
}
if (!iconUrl) {
if (this.info.repositoryInfo != null) {
const info = await this.info.repositoryInfo.getInfo(this)
if (info != null) {
iconUrl = `https://raw.githubusercontent.com/${info.user}/${info.project}/master/${this.relativeBuildResourcesDirname}/icon.ico`
}
}
if (!iconUrl) {
throw new Error("iconUrl is not specified, please see https://github.com/electron-userland/electron-builder#in-short")
}
}
}
const certificateFile = await this.certFilePromise
const version = this.metadata.version
const installerOutDir = WinPackager.computeDistOut(outDir, arch)
const archSuffix = arch === "x64" ? "" : ("-" + arch)
const options = Object.assign({
name: this.metadata.name,
productName: this.appName,
exe: this.appName + ".exe",
title: this.appName,
appDirectory: appOutDir,
outputDirectory: installerOutDir,
version: version,
description: this.metadata.description,
authors: this.metadata.author.name,
iconUrl: iconUrl,
setupIcon: path.join(this.buildResourcesDir, "icon.ico"),
certificateFile: certificateFile,
certificatePassword: this.options.cscKeyPassword,
fixUpPaths: false,
usePackageJson: false,
noMsi: true,
}, this.customBuildOptions)
try {
await require("electron-winstaller-fixed").createWindowsInstaller(options)
}
catch (e) {
if (!e.message.includes("Unable to set icon")) {
throw e
}
else {
let fileInfo: Stats
try {
fileInfo = await stat(options.setupIcon)
}
catch (e) {
throw new Error("Please specify correct setupIcon, file " + options.setupIcon + " not found")
}
if (fileInfo.isDirectory()) {
throw new Error("Please specify correct setupIcon, " + options.setupIcon + " is a directory")
}
}
}
const releasesFile = path.join(installerOutDir, "RELEASES")
const nupkgPathOriginal = this.metadata.name + "-" + version + "-full.nupkg"
const nupkgPathWithArch = this.metadata.name + "-" + version + archSuffix + "-full.nupkg"
async function changeFileNameInTheReleasesFile(): Promise<void> {
const data = (await readFile(releasesFile, "utf8")).replace(new RegExp(" " + nupkgPathOriginal + " ", "g"), " " + nupkgPathWithArch + " ")
await writeFile(releasesFile, data)
}
const promises: Array<Promise<any>> = [
rename(path.join(installerOutDir, "Setup.exe"), path.join(installerOutDir, `${this.appName}Setup-${version}${archSuffix}.exe`))
.then(it => this.dispatchArtifactCreated(it, `${this.metadata.name}Setup-${version}${archSuffix}.exe`)),
]
if (archSuffix === "") {
this.dispatchArtifactCreated(path.join(installerOutDir, nupkgPathOriginal))
this.dispatchArtifactCreated(path.join(installerOutDir, "RELEASES"))
}
else {
promises.push(
rename(path.join(installerOutDir, nupkgPathOriginal), path.join(installerOutDir, nupkgPathWithArch))
.then(it => this.dispatchArtifactCreated(it))
)
promises.push(
changeFileNameInTheReleasesFile()
.then(() => copy(releasesFile, path.join(installerOutDir, "RELEASES-ia32")))
.then(it => this.dispatchArtifactCreated(it))
)
}
await BluebirdPromise.all(promises)
}