• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript promise.denodeify函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中ember-cli/lib/ext/promise.denodeify函数的典型用法代码示例。如果您正苦于以下问题:TypeScript denodeify函数的具体用法?TypeScript denodeify怎么用?TypeScript denodeify使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了denodeify函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: beforeEach

import * as mockFs from 'mock-fs';
import { expect } from 'chai';
import * as ts from 'typescript';
import * as fs from 'fs';
import { InsertChange, RemoveChange } from '../../addon/ng2/utilities/change';
import * as Promise from 'ember-cli/lib/ext/promise';
import {
  findNodes,
  insertAfterLastOccurrence,
  addComponentToModule
} from '../../addon/ng2/utilities/ast-utils';

const readFile = Promise.denodeify(fs.readFile);

describe('ast-utils: findNodes', () => {
  const sourceFile = 'tmp/tmp.ts';

  beforeEach(() => {
    let mockDrive = {
      'tmp': {
        'tmp.ts': `import * as myTest from 'tests' \n` +
                  'hello.'
      }
    };
    mockFs(mockDrive);
  });

  afterEach(() => {
    mockFs.restore();
  });
开发者ID:AppasThirdLeftFoot,项目名称:angular-cli,代码行数:30,代码来源:ast-utils.spec.ts


示例2: function

  run: function(options, rawArgs) {
    var ui = this.ui;
    var root = this.project.root;
    var execOptions = {
      cwd: root
    };
    var projectName = this.project.pkg.name;

    let initialBranch;

    // declared here so that tests can stub exec
    const execPromise = Promise.denodeify(exec);

    var buildTask = new BuildTask({
      ui: this.ui,
      analytics: this.analytics,
      project: this.project
    });

    var buildOptions = {
      environment: options.environment,
      outputPath: 'dist/'
    };

    var createGithubRepoTask = new CreateGithubRepo({
      ui: this.ui,
      analytics: this.analytics,
      project: this.project
    });

    var createGithubRepoOptions = {
      projectName,
      ghUsername: options.ghUsername,
      ghToken: options.ghToken
    };

    return checkForPendingChanges()
      .then(build)
      .then(saveStartingBranchName)
      .then(createGitHubRepoIfNeeded)
      .then(checkoutGhPages)
      .then(copyFiles)
      .then(updateBaseHref)
      .then(addAndCommit)
      .then(returnStartingBranch)
      .then(pushToGitRepo)
      .then(printProjectUrl);

    function checkForPendingChanges() {
      return execPromise('git status --porcelain')
        .then(stdout => {
          if (/\w+/m.test(stdout)) {
            let msg = 'Uncommitted file changes found! Please commit all changes before deploying.';
            return Promise.reject(new SilentError(msg));
          }
        });
    }

    function build() {
      if (options.skipBuild) return Promise.resolve();
      return win.checkWindowsElevation(ui)
        .then(() => buildTask.run(buildOptions));
    }

    function saveStartingBranchName() {
      return execPromise('git rev-parse --abbrev-ref HEAD')
        .then((stdout) => initialBranch = stdout);
    }

    function createGitHubRepoIfNeeded() {
      return execPromise('git remote -v')
        .then(function(stdout) {
          if (!/origin\s+(https:\/\/|git@)github\.com/m.test(stdout)) {
            return createGithubRepoTask.run(createGithubRepoOptions);
          }
        });
    }

    function checkoutGhPages() {
      return execPromise(`git checkout ${options.branch}`)
        .catch(createGhPagesBranch)
    }

    function createGhPagesBranch() {
      return execPromise(`git checkout --orphan ${options.branch}`)
        .then(() => execPromise('git rm --cached -r .', execOptions))
        .then(() => execPromise('git add .gitignore', execOptions))
        .then(() => execPromise('git clean -f -d', execOptions))
        .then(() => execPromise(`git commit -m \"initial ${options.branch} commit\"`));
    }

    function copyFiles() {
      return fsReadDir('dist')
        .then((files) => Promise.all(files.map((file) => fsCopy(path.join('dist', file), path.join('.', file)))))
    }

    function updateBaseHref() {
      let indexHtml = path.join(root, 'index.html');
      return fsReadFile(indexHtml, 'utf8')
        .then((data) => data.replace(/<base href="\/">/g, `<base href="/${projectName}/>"`))
//.........这里部分代码省略.........
开发者ID:DrMabuse23,项目名称:angular-cli,代码行数:101,代码来源:github-pages-deploy.ts


示例3:

import * as Command from 'ember-cli/lib/models/command';
import * as SilentError from 'silent-error';
import { exec } from 'child_process';
import * as Promise from 'ember-cli/lib/ext/promise';
import * as chalk from 'chalk';
import * as fs from 'fs';
import * as fse from 'fs-extra';
import * as path from 'path';
import * as BuildTask from 'ember-cli/lib/tasks/build';
import * as win from 'ember-cli/lib/utilities/windows-admin';
import * as CreateGithubRepo from '../tasks/create-github-repo';

const fsReadFile = Promise.denodeify(fs.readFile);
const fsWriteFile = Promise.denodeify(fs.writeFile);
const fsReadDir = Promise.denodeify(fs.readdir);
const fsCopy = Promise.denodeify(fse.copy);

module.exports = Command.extend({
  name: 'github-pages:deploy',
  aliases: ['gh-pages:deploy'],
  description: 'Build the test app for production, commit it into a git branch, setup GitHub repo and push to it',
  works: 'insideProject',

  availableOptions: [
    {
      name: 'message',
      type: String,
      default: 'new gh-pages version',
      description: 'The commit message to include with the build, must be wrapped in quotes.'
    }, {
      name: 'environment',
开发者ID:DrMabuse23,项目名称:angular-cli,代码行数:31,代码来源:github-pages-deploy.ts


示例4:

import * as assign from 'lodash/assign';
import * as Command from 'ember-cli/lib/models/command';
import * as Promise from 'ember-cli/lib/ext/promise';
import * as SilentError from 'silent-error';
import * as PortFinder from 'portfinder';
import * as EOL from 'os';
import * as ServeWebpackTask from '../tasks/serve-webpack.ts';

PortFinder.basePort = 49152;

const getPort = Promise.denodeify(PortFinder.getPort);
const defaultPort = process.env.PORT || 4200;

export interface ServeTaskOptions {
  port?: number;
  host?: string;
  proxy?: string;
  insecureProxy?: boolean;
  watcher?: string;
  liveReload?: boolean;
  liveReloadHost?: string;
  liveReloadPort?: number;
  liveReloadBaseUrl?: string;
  liveReloadLiveCss?: boolean;
  target?: string;
  environment?: string;
  outputPath?: string;
  ssl?: boolean;
  sslKey?: string;
  sslCert?: string;
}
开发者ID:Alber70g,项目名称:angular-cli,代码行数:31,代码来源:serve.ts


示例5: function

  run: function(options, rawArgs) {
    var ui = this.ui;
    var root = this.project.root;
    var execOptions = {
      cwd: root
    };
    var projectName = this.project.pkg.name;

    let ghPagesBranch = 'gh-pages';
    let destinationBranch = options.userPage ? 'master' : ghPagesBranch;
    let initialBranch;

    // declared here so that tests can stub exec
    const execPromise = Promise.denodeify(exec);

    var buildTask = new BuildTask({
      ui: this.ui,
      analytics: this.analytics,
      project: this.project
    });

    var buildOptions = {
      environment: options.environment,
      outputPath: 'dist/'
    };

    var createGithubRepoTask = new CreateGithubRepo({
      ui: this.ui,
      analytics: this.analytics,
      project: this.project
    });

    var createGithubRepoOptions = {
      projectName,
      ghUsername: options.ghUsername,
      ghToken: options.ghToken
    };

    return checkForPendingChanges()
      .then(build)
      .then(saveStartingBranchName)
      .then(createGitHubRepoIfNeeded)
      .then(checkoutGhPages)
      .then(copyFiles)
      .then(updateBaseHref)
      .then(addAndCommit)
      .then(returnStartingBranch)
      .then(pushToGitRepo)
      .then(printProjectUrl)
      .catch(failGracefully);

    function checkForPendingChanges() {
      return execPromise('git status --porcelain')
        .then(stdout => {
          if (/\w+/m.test(stdout)) {
            let msg = 'Uncommitted file changes found! Please commit all changes before deploying.';
            return Promise.reject(new SilentError(msg));
          }
        });
    }

    function build() {
      if (options.skipBuild) return Promise.resolve();
      return win.checkWindowsElevation(ui)
        .then(() => buildTask.run(buildOptions));
    }

    function saveStartingBranchName() {
      return execPromise('git rev-parse --abbrev-ref HEAD')
        .then((stdout) => initialBranch = stdout.replace(/\s/g, ''));
    }

    function createGitHubRepoIfNeeded() {
      return execPromise('git remote -v')
        .then(function(stdout) {
          if (!/origin\s+(https:\/\/|git@)github\.com/m.test(stdout)) {
            return createGithubRepoTask.run(createGithubRepoOptions)
              .then(() => {
                // only push starting branch if it's not the destinationBranch
                // this happens commonly when using github user pages, since
                // they require the destination branch to be 'master'
                if (destinationBranch !== initialBranch) {
                  execPromise(`git push -u origin ${initialBranch}`);
                }
              });
          }
        });
    }

    function checkoutGhPages() {
      return execPromise(`git checkout ${ghPagesBranch}`)
        .catch(createGhPagesBranch)
    }

    function createGhPagesBranch() {
      return execPromise(`git checkout --orphan ${ghPagesBranch}`)
        .then(() => execPromise('git rm --cached -r .', execOptions))
        .then(() => execPromise('git add .gitignore', execOptions))
        .then(() => execPromise('git clean -f -d', execOptions))
        .then(() => execPromise(`git commit -m \"initial ${ghPagesBranch} commit\"`));
//.........这里部分代码省略.........
开发者ID:DevVersion,项目名称:angular-cli,代码行数:101,代码来源:github-pages-deploy.ts


示例6: function

  run: function(commandOptions) {
    var ui = this.ui;
    let promise;

    // declared here so that tests can stub exec
    const execPromise = Promise.denodeify(exec);

    if (/.+/.test(commandOptions.ghToken) && /\w+/.test(commandOptions.ghUsername)) {
      promise = Promise.resolve({
        ghToken: commandOptions.ghToken,
        ghUsername: commandOptions.ghUsername
      });
    } else {
      ui.writeLine("\nIn order to deploy this project via GitHub Pages, we must first create a repository for it.");
      ui.writeLine("It's safer to use a token than to use a password, so you will need to create one.\n");
      ui.writeLine("Go to the following page and click 'Generate new token'.");
      ui.writeLine("https://github.com/settings/tokens\n");
      ui.writeLine("Choose 'public_repo' as scope and then click 'Generate token'.\n");
      promise = ui.prompt([
        {
          name: 'ghToken',
          type: 'input',
          message: 'Please enter GitHub token you just created (used only once to create the repo):',
          validate: function(token) {
            return /.+/.test(token);
          }
        }, {
          name: 'ghUsername',
          type: 'input',
          message: 'and your GitHub user name:',
          validate: function(userName) {
            return /\w+/.test(userName);
          }
        }]);
    }

    return promise
      .then((answers) => {
      return new Promise(function(resolve, reject) {
        var postData = JSON.stringify({
          'name': commandOptions.projectName
        });

        var req = https.request({
          hostname: 'api.github.com',
          port: 443,
          path: '/user/repos',
          method: 'POST',
          headers: {
            'Authorization': `token ${answers.ghToken}`,
            'Content-Type': 'application/json',
            'Content-Length': postData.length,
            'User-Agent': 'angular-cli-github-pages'
          }
        });

        req.on('response', function(response) {
          if (response.statusCode === 201) {
            resolve(execPromise(`git remote add origin [email protected]:${answers.ghUsername}/${commandOptions.projectName}.git`))
          } else {
            reject(new SilentError(`Failed to create GitHub repo. Error: ${response.statusCode} ${response.statusMessage}`));
          }
        });

        req.write(postData);
        req.end();
      });
    });
  }
开发者ID:2blessed2bstressedbythedevilsmess,项目名称:angular-cli,代码行数:69,代码来源:create-github-repo.ts



注:本文中的ember-cli/lib/ext/promise.denodeify函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript promise.reject函数代码示例发布时间:2022-05-25
下一篇:
TypeScript promise.all函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap