本文整理汇总了TypeScript中promisify-node类的典型用法代码示例。如果您正苦于以下问题:TypeScript promisify-node类的具体用法?TypeScript promisify-node怎么用?TypeScript promisify-node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了promisify-node类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getRepos
/**
* Returns a Promise of a list of Polymer github repos to automatically
* cleanup / transform.
*/
async function getRepos(): Promise<GitHub.Repo[]> {
const per_page = 100;
const getFromOrg: (o: Object) => Promise<GitHub.Repo[]> =
promisify(github.repos.getFromOrg);
let progressLength = 2;
if (opts.repo.length) {
progressLength += opts.repo.length
}
const progressBar = standardProgressBar(
'Discovering repos in PolymerElements...', progressLength);
// First get the Polymer repo, then get all of the PolymerElements repos.
const repo: GitHub.Repo =
await promisify(github.repos.get)({user: 'Polymer', repo: 'polymer'});
progressBar.tick();
const repos = [repo];
if (opts.repo.length) {
// cleanup passes wants ContributionGuide around
repos.push(
await promisify(github.repos.get)(
{user: 'PolymerElements', repo: 'ContributionGuide'}));
progressBar.tick();
for (let repo of opts.repo) {
repos.push(await promisify(github.repos.get)(repo));
progressBar.tick();
}
} else {
let page = 0;
while (true) {
const resultsPage =
await getFromOrg({org: 'PolymerElements', per_page, page});
repos.push.apply(repos, resultsPage);
page++;
if (resultsPage.length < per_page) {
break;
}
}
repos.push(
await promisify(github.repos.get)(
{user: 'PolymerLabs', repo: 'promise-polyfill'}));
progressBar.tick();
}
// github pagination is... not entirely consistent, and
// sometimes gives us duplicate repos.
const repoIds = new Set<string>();
const dedupedRepos: GitHub.Repo[] = [];
for (const repo of repos) {
if (repoIds.has(repo.name)) {
continue;
}
repoIds.add(repo.name);
dedupedRepos.push(repo);
}
return dedupedRepos;
}
示例2: getRepos
/**
* Returns a Promise of a list of Polymer github repos to automatically
* cleanup / transform.
*/
async function getRepos(): Promise<GitHub.Repo[]> {
const per_page = 100;
const getFromOrg = promisify(github.repos.getFromOrg);
const getRepo = promisify(github.repos.get);
let progressLength = 2;
if (opts.repo.length) {
progressLength += opts.repo.length;
}
const progressBar = standardProgressBar(
'Discovering repos in PolymerElements...', progressLength);
const repos: GitHub.Repo[] = [];
// First get the repos outside PolymerElements, and those that are always
// needed.
const repoPromises = [
// getRepo({user: 'Polymer', repo: 'polymer'}),
// getRepo({user: 'PolymerLabs', repo: 'promise-polyfill'}),
// getRepo({user: 'PolymerElements', repo: 'ContributionGuide'})
];
if (opts.repo.length) {
for (const repo of opts.repo) {
repoPromises.push(getRepo(repo));
}
} else {
let page = 0;
while (true) {
const resultsPage =
await getFromOrg({org: 'PolymerElements', per_page, page});
repos.push.apply(repos, resultsPage);
page++;
if (resultsPage.length < per_page) {
break;
}
}
progressBar.tick();
}
repos.push(...await Promise.all(repoPromises));
progressBar.tick();
// github pagination is... not entirely consistent, and
// sometimes gives us duplicate repos.
const repoIds = new Set<string>();
const dedupedRepos: GitHub.Repo[] = [];
for (const repo of repos) {
if (repoIds.has(repo.name)) {
continue;
}
repoIds.add(repo.name);
dedupedRepos.push(repo);
}
return dedupedRepos;
};
示例3: detect
export async function detect(): Promise<{[browser: string]: wd.Capabilities}> {
const launcher = await promisify(launchpad.local)();
const browsers = await promisify(launcher.browsers)();
const results: {[browser: string]: wd.Capabilities} = {};
for (const browser of browsers) {
if (!LAUNCHPAD_TO_SELENIUM[browser.name]) continue;
const converter = LAUNCHPAD_TO_SELENIUM[browser.name];
results[browser.name] = converter(browser);
}
return results;
}
示例4: expandDirectory
async function expandDirectory(
baseDir: string, aPath: string): Promise<string[]> {
const stat = await promisify(fs.stat)(path.resolve(baseDir, aPath));
if (!stat.isDirectory()) {
return [aPath];
}
const files = await promisify(fs.readdir)(path.resolve(baseDir, aPath));
// We have an index; defer to that.
if (_.includes(files, 'index.html')) {
return [path.join(aPath, 'index.html')];
}
const children = await expandDirectories(path.join(baseDir, aPath), files);
return children.map((child) => path.join(aPath, child));
}
示例5: seleniumStart
async function seleniumStart(
wct: wct.Context,
opts: {args: string[], install: boolean}): Promise<number> {
const port = await promisify(freeport)();
// See below.
const log: string[] = [];
function onOutput(data: any) {
const message = data.toString();
log.push(message);
wct.emit('log:debug', message);
}
const config: selenium.StartOpts = SELENIUM_OVERRIDES || {};
config.seleniumArgs = ['-port', port.toString()].concat(opts.args);
// Bookkeeping once the process starts.
config.spawnCb = function(server: child_process.ChildProcess) {
// Make sure that we interrupt the selenium server ASAP.
cleankill.onInterrupt(function(done) {
server.kill();
done();
});
server.stdout.on('data', onOutput);
server.stderr.on('data', onOutput);
};
if (opts.install) {
try {
const options = SELENIUM_OVERRIDES || {};
options.logger = onOutput;
await promisify(selenium.install)(options);
} catch (error) {
log.forEach((line) => wct.emit('log:info', line));
throw error;
}
}
try {
await promisify(selenium.start)(config);
} catch (error) {
log.forEach((line) => wct.emit('log:info', line));
throw error;
}
wct.emit(
'log:info',
'Selenium server running on port', chalk.yellow(port.toString()));
return port;
}
示例6: run
async function run() {
// Load configuration
nconf.argv()
.env({ separator: "_" })
.file("user", { file: process.env.SMU_CONFIG || "/etc/smu.yml", format: nconfYaml })
.file("defaults", { file: join(__dirname, "../conf/defaults.yml"), format: nconfYaml });
const config = nconf.get(null);
// Initialize Hapi
const server = promisify(new hapi.Server());
server.connection(config.server);
// init server
try {
await server.register(plugins);
setupAuthentication(server, config.authentication);
setupCommands(server, config.commands);
await server.start();
} catch (err) {
server.log(["error"], "Error starting server: " + err);
process.exit(1);
}
server.log(["info"], `Server running at: ${server.info.uri}`);
}
示例7: detect
export let detect = async function detect(browserOptions: {[name: string]: string[]}): Promise<{[browser: string]: wd.Capabilities}> {
const launcher = await promisify(launchpad.local)();
const browsers = await promisify(launcher.browsers)();
const results: {[browser: string]: wd.Capabilities} = {};
for (const browser of browsers) {
if (!LAUNCHPAD_TO_SELENIUM[browser.name]) continue;
const converter = LAUNCHPAD_TO_SELENIUM[browser.name];
const convertedBrowser = converter(browser, browserOptions && browserOptions[browser.name]);
if (convertedBrowser) {
results[browser.name] = convertedBrowser;
}
}
return results;
};
示例8: unglob
/**
* Expands any glob expressions in `patterns`.
*
* @param {string} baseDir
* @param {!Array<string>} patterns
*/
async function unglob(baseDir: string, patterns: string[]): Promise<string[]> {
const strs: string[][] = [];
const pGlob: any = promisify(glob);
for (const pattern of patterns) {
strs.push(await pGlob(String(pattern), {cwd: baseDir, root: baseDir}));
}
return _.union(_.flatten(strs));
}
示例9: unglob
/**
* Expands any glob expressions in `patterns`.
*/
async function unglob(baseDir: string, patterns: string[]): Promise<string[]> {
const strs: string[][] = [];
const pGlob: any = promisify(glob);
for (const pattern of patterns) {
strs.push(await pGlob(String(pattern), {cwd: baseDir, root: baseDir}));
}
// for non-POSIX support, replacing path separators
return _.union(_.flatten(strs)).map((str) => str.replace(/\//g, path.sep));
}
示例10: promisify
export async function checkSeleniumEnvironment(): Promise<void> {
try {
await promisify(which)('java');
return;
} catch (error) { /* Handled below */ }
let message = 'java is not present on your PATH.';
if (process.platform === 'win32') {
message += `\n\n Please install it: https://java.com/download/\n\n`;
} else if (process.platform === 'linux') {
try {
await promisify(which)('apt-get');
message = message + '\n\n sudo apt-get install default-jre\n\n';
} catch (error) {
// There's not a clear default package for yum distros.
}
}
throw message;
}