本文整理汇总了TypeScript中denodeify类的典型用法代码示例。如果您正苦于以下问题:TypeScript denodeify类的具体用法?TypeScript denodeify怎么用?TypeScript denodeify使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了denodeify类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: createTsSourceFile
export function createTsSourceFile(fileName: string): Promise<ts.SourceFile> {
const readFile = denodeify(fs.readFile);
return readFile(fileName, 'utf8')
.then((contents: string) => {
return ts.createSourceFile(fileName, contents, ts.ScriptTarget.ES6, true);
});
}
示例2: switch
.then(doc => {
switch (doc.type) {
case 'apib':
return denodeify(apib2swagger.convert)(doc.body).then(r => r['swagger'])
default:
return JSON.parse(doc.body)
}
})
示例3: function
run: function(commandOptions: any) {
const ui = this.ui;
let promise: Promise<any>;
// declared here so that tests can stub exec
const execPromise = denodeify(exec);
if (/.+/.test(commandOptions.ghToken) && /\w+/.test(commandOptions.ghUsername)) {
promise = Promise.resolve({
ghToken: commandOptions.ghToken,
ghUsername: commandOptions.ghUsername
});
} else {
ui.writeLine();
ui.writeLine(oneLine`
In order to deploy this project via GitHub Pages, we must first create a repository for it.
`);
ui.writeLine(oneLine`
It\'s safer to use a token than to use a password so you will need to create one
`);
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: oneLine`
Please enter GitHub token you just created
(used only once to create the repo):
`,
validate: function(token: string) {
return /.+/.test(token);
}
}, {
name: 'ghUsername',
type: 'input',
message: 'and your GitHub user name:',
validate: function(userName: string) {
return /\w+/.test(userName);
}
}]);
}
return promise
.then((answers) => {
return new Promise(function(resolve, reject) {
const postData = JSON.stringify({
'name': commandOptions.projectName
});
const 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: any) {
if (response.statusCode === 201) {
resolve(execPromise(oneLine`
git remote add origin
git@github.com:${answers.ghUsername}/${commandOptions.projectName}.git
`));
} else {
reject(new SilentError(oneLine`
Failed to create GitHub repo. Error: ${response.statusCode} ${response.statusMessage}
`));
}
});
req.write(postData);
req.end();
});
});
}
示例4: denodeify
import {Option} from '../../server/src/Option';
import * as denodeify from 'denodeify';
import {exec as execNode, ExecOptions} from 'child_process';
type Stdout = string;
type Stderr = string;
type ExecResult = [ Stdout, Stderr ];
export const exec: (command: string, options: ExecOptions) => Promise<ExecResult> = (
denodeify(execNode, (err, stdout, stderr) => [err, [stdout, stderr]])
);
export type StringDictionary<T> = { [key: string]: T };
export const getInStringDictionary = <T>(stringDictionary: StringDictionary<T>, key: number): T | undefined => stringDictionary[key]
export const getInArray = <T>(array: T[], index: number): T | undefined => array[index]
export const OptionHelpers = {
fromNullable<T>(t: T | null | undefined): Option<T> { return Option(t as T) },
arrayGet<T>(array: T[], index: number): Option<T> {
return OptionHelpers.fromNullable(getInArray(array, index))
},
stringMatch(str: string, matcher: RegExp): Option<RegExpMatchArray> {
return OptionHelpers.fromNullable(str.match(matcher))
},
}
export const stringify = (json: any) => JSON.stringify(json, null, ' ');
export const writePromise = (promise: Promise<string>): Promise<void> => (
promise.then(
output => { process.stdout.write(output) },
error => {
process.stderr.write(error.stack)
process.exit(1)
},
)
示例5: denodeify
"use strict";
import * as fs from 'fs-extra';
import * as denodeify from 'denodeify';
import {CompilableContent, ICompilableContent} from './CompilableContent';
import {error} from './Logger';
var fsreadfile = denodeify(fs.readFile);
/**
* Doc wraps up all occurances of markdown documents inside the styleguide.
*/
export class Doc extends CompilableContent {
load():Promise<ICompilableContent> {
return super.load()
.then((doc) => {
this.compiled = this.render();
return this;
})
.catch(e => {
error("Doc.load", e);
console.log(e.stack);
throw(e);
});
}
static create(path: string, name: string): ICompilableContent {
var doc:Doc = new Doc(path, name);
doc.renderer = this.renderer;
return doc;
示例6: denodeify
import {StructureReader} from './StructureReader';
import {StructureWriter} from './StructureWriter';
import {Node} from './Node';
import {ComponentList} from './ComponentList';
import {IRenderer, IRendererOptions} from './Renderer';
import {IPageConfig} from './Page';
import {LinkRegistry} from './LinkRegistry';
import {Doc} from './Doc';
import {Partial} from './Partial';
import {View} from './View';
import {MarkdownRenderer} from './MarkdownRenderer';
import {HandlebarsRenderer} from './HandlebarsRenderer';
var fsensuredir = denodeify(fs.ensureDir);
var fscopy = denodeify(fs.copy);
var outputfile = denodeify(fs.outputFile);
var flatten = (list) => list.reduce(
(a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);
interface IStyleguideOptions {
configPath?: string;
target?: string;
cwd?: string;
}
interface IAssetCopyConfig {
src?: string;
示例7: denodeify
import * as fs from 'fs-extra';
import * as path from 'path';
import * as slug from 'slug';
import * as denodeify from 'denodeify';
import {Doc} from './Doc';
import {View} from './View';
import {Styleguide} from './Styleguide';
import {IRenderer} from './Renderer';
import {IPageLayoutContext} from './PageLayout';
import {PlainComponentList, IRelatedComponentFiles} from './PlainComponentList';
import {ICompilableContent} from './CompilableContent';
import {warn, error} from './Logger';
var fsoutputfile = denodeify(fs.outputFile);
export interface IPageConfig {
id?: string;
label?: string;
slug?: string;
type?: string;
content?: any;
children?: Page[];
styleguide?: Styleguide;
mdRenderer?: IRenderer;
target?: string;
preflight?: string;
}
export interface IPageTemplateConfig {
示例8: read
import { assign } from 'lodash';
import * as _read from 'read';
import * as fs from 'fs';
import * as path from 'path';
import { WebApi, getBasicHandler } from 'vso-node-api/WebApi';
import { IGalleryApi, IQGalleryApi } from 'vso-node-api/GalleryApi';
import * as denodeify from 'denodeify';
const readFile = denodeify<string, string, string>(fs.readFile);
export function fatal<T>(message: any, ...args: any[]): Promise<T> {
if (message instanceof Error) {
if (/^cancell?ed$/i.test(message.message)) {
return;
}
message = message.message;
}
console.error('Error:', message, ...args);
process.exit(1);
return Promise.resolve<T>(null);
}
export function catchFatal<T>(promise: Promise<T>): Promise<T> {
return promise.catch<T>(fatal);
}
const __read = denodeify<_read.Options,string>(_read);
export function read(prompt: string, options: _read.Options = {}): Promise<string> {
return __read(assign({ prompt }, options));
示例9: require
import * as denodeify from 'denodeify';
const SilentError = require('silent-error');
const PortFinder = require('portfinder');
const getPort = denodeify<{host: string, port: number}, number>(PortFinder.getPort);
export function checkPort(port: number, host: string, basePort = 49152): Promise<number> {
PortFinder.basePort = basePort;
return getPort({ port, host })
.then(foundPort => {
// If the port isn't available and we weren't looking for any port, throw error.
if (port !== foundPort && port !== 0) {
throw new SilentError(
`Port ${port} is already in use. Use '--port' to specify a different port.`
);
}
// Otherwise, our found port is good.
return foundPort;
});
}
示例10: denodeify
"use strict";
import * as path from 'path';
import * as fs from 'fs-extra';
import * as denodeify from 'denodeify';
import {warn} from './Logger';
import {Config} from './Config';
import {Styleguide} from './Styleguide';
import {IComponentConfig} from './Component';
import {Component} from './Component';
import {Partial} from './Partial';
var fsstat = denodeify(fs.stat);
var fsreaddir = denodeify(fs.readdir);
/** options, that can be handed to nodes */
export interface INodeOptions {
namespace?: string;
styleguide?: Styleguide;
componentDocs?: string;
}
/**
* a Node represents a folder-node inside of the configured component paths.
* It may have a Component (1-to-1), but maybe it is just a container for
* child nodes, that are components.
*
* TODO: i guess nodes may also be pages
*/