當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Q.denodeify函數代碼示例

本文整理匯總了TypeScript中Q.denodeify函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript denodeify函數的具體用法?TypeScript denodeify怎麽用?TypeScript denodeify使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了denodeify函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: viewDynamic

export function viewDynamic(
    viewName: string,
    viewData: any,
    layoutName?: string ) : Q.Promise< relaxjs.Embodiment > {
  var log = _log.child( { func: 'internals.viewDynamic'} );
  var laterAct = Q.defer< relaxjs.Embodiment >();
  var readFile = Q.denodeify(fs.readFile);
  var templateFilename = './views/'+viewName+'._';
  if ( viewName === 'site') {
    templateFilename = `${__dirname}/../views/${viewName}._`;
  }
  if ( layoutName ) {
    var layoutFilename = './views/'+layoutName+'._';
    log.info('Reading template %s in layout %s',templateFilename, layoutFilename );
    Q.all( [ readFile( templateFilename,  { 'encoding':'utf8'} ),
             readFile( layoutFilename,    { 'encoding':'utf8'} ) ])
    .spread( (content: string, outerContent : string) => {
      try {
        log.info('Compile composite view %s in %s',templateFilename,layoutFilename);
        var innerContent = new Buffer( _.template(content)(viewData), 'utf-8' );
        var fullContent = new Buffer( _.template(outerContent)( { page: innerContent, name: viewData.Name, data: viewData.data }), 'utf-8');
        laterAct.resolve( new relaxjs.Embodiment( 'text/html', 200, fullContent ));
      }
      catch( err ) {
        log.error( err );
        laterAct.reject( emitCompileViewError(content,err, templateFilename +' in '+ layoutFilename) );
      }
    })
    .catch( (err : Error ) => {
      log.error( err );
      laterAct.reject( emitCompileViewError('N/A',err, templateFilename +' in '+ layoutFilename ) );
    });
  }
  else {
    log.info('Reading template %s',templateFilename);
    readFile( templateFilename,  { 'encoding':'utf8'} )
    .then( ( content:string ) => {
      try {
        log.info( 'Compiling view %s', templateFilename );
        var fullContent = new Buffer( _.template(content)(viewData) , 'utf-8') ;
        laterAct.resolve( new relaxjs.Embodiment( 'text/html', 200, fullContent ));
      }
      catch( err ) {
        log.error( err );
        laterAct.reject( emitCompileViewError(content,err, templateFilename ) );
      }
    })
    .catch( ( err : Error ) => {
      log.error( err );
      laterAct.reject( emitCompileViewError('N/A',err, templateFilename ) );
    });
  }
  return laterAct.promise;
}
開發者ID:micurs,項目名稱:relaxjs,代碼行數:54,代碼來源:internals.ts

示例2: cleanup

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for details.

'use strict';

import * as child_process from 'child_process';
import * as fs from 'fs';
import * as net from 'net';
import * as path from 'path';
import * as pl from 'plist-with-patches';
import * as Q from 'q';

let promiseExec = Q.denodeify(child_process.exec);

export class CordovaIosDeviceLauncher {
    private static nativeDebuggerProxyInstance: child_process.ChildProcess;
    private static webDebuggerProxyInstance: child_process.ChildProcess;

    public static cleanup(): void {
        if (CordovaIosDeviceLauncher.nativeDebuggerProxyInstance) {
            CordovaIosDeviceLauncher.nativeDebuggerProxyInstance.kill('SIGHUP');
            CordovaIosDeviceLauncher.nativeDebuggerProxyInstance = null;
        }
        if (CordovaIosDeviceLauncher.webDebuggerProxyInstance) {
            CordovaIosDeviceLauncher.webDebuggerProxyInstance.kill();
            CordovaIosDeviceLauncher.webDebuggerProxyInstance = null;
        }
    }

    public static getBundleIdentifier(projectRoot: string): Q.Promise<string> {
        return Q.nfcall(fs.readdir, path.join(projectRoot, 'platforms', 'ios')).then((files: string[]) => {
開發者ID:Paradox-Cascade,項目名稱:vscode-cordova,代碼行數:31,代碼來源:cordovaIosDeviceLauncher.ts

示例3: require

const _ = require('lodash')
const FS  = require('fs')
const Q  = require('q')
const glob = require('glob')
const sass = require('node-sass')

let globSearch = Q.denodeify(glob)
let sassRender = Q.nbind(sass.render, sass)
let writeFile = Q.denodeify(FS.writeFile)
let sassDefaults = {
  includePaths: [
  ],
  indentedSyntax: true
}

globSearch('src/**/*.scss')
  .then((files) => {
    var result = Q()
    files.forEach((srcFile) => {
      result = result
        .then(() => {
          let dstFile = srcFile.replace(/\.scss$/i, '.css')
          return buildSassFile(srcFile, dstFile)
        })
    })
    return result
  })
  .then(() => {
    console.log('Compiled CSS files.')
  })
  .catch((err) => {
開發者ID:ng-cookbook,項目名稱:angular2-redux-complex-ui,代碼行數:31,代碼來源:build-css.ts

示例4:

import * as Q from 'q';
import * as _ from 'lodash';

// key generation parameters
const pbkdf2SaltLen = 64;
const pbkdf2Iterations = 6911;
const pbkdf2KeyLen = 192 / 8;
const pbkdf2Digest = 'sha256';

// see https://tools.ietf.org/html/rfc5084
// console.log((<any>crypto).getCiphers());
const cipherAlgorithm = 'aes-192-gcm';
const cipherIvLen = 12;

// promised variants
const randomBytes = Q.denodeify<Buffer>(crypto.randomBytes);
const pbkdf2 = Q.denodeify<Buffer>(crypto.pbkdf2);

/**
 * encrypted object data.
 *
 * @internal Not part of public API, exported for library use only.
 */
export interface EncryptedJson<T> {
  salt: string;
  iv: string;
  tag?: string;
  value: string;
}

/**
開發者ID:relution-io,項目名稱:relution-sdk,代碼行數:31,代碼來源:cipher.ts


注:本文中的Q.denodeify函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。