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


TypeScript promise.denodeify函數代碼示例

本文整理匯總了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 git@github.com:${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;未經允許,請勿轉載。