本文整理汇总了TypeScript中Q.nfcall函数的典型用法代码示例。如果您正苦于以下问题:TypeScript nfcall函数的具体用法?TypeScript nfcall怎么用?TypeScript nfcall使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了nfcall函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
return Q.nfcall<fs.Stats>(fs.stat, p).then((stats: fs.Stats) => {
if (stats.isDirectory()) {
return Q.nfcall<string[]>(fs.readdir, p).then((childPaths: string[]) => {
let result = Q<void>(void 0);
childPaths.forEach(childPath =>
result = result.then<void>(() => this.removePathRecursivelyAsync(path.join(p, childPath))));
return result;
}).then(() =>
Q.nfcall<void>(fs.rmdir, p));
} else {
/* file */
return Q.nfcall<void>(fs.unlink, p);
}
});
示例2: runTest
function runTest(testFileName: string) {
const testFilePath = path.resolve(__dirname, '..', 'fixtures', testFileName);
logger.info({testFilePath: testFilePath}, 'Running test file');
return q.nfcall(tmp.file.bind(tmp), {postfix: '.js'})
.spread(function(jsOutputFilePath: string) {
logger.info({jsOutputFilePath: jsOutputFilePath, lsc: lsc}, 'Compiling to js output');
return lsc(testFilePath, jsOutputFilePath)
.then(function() {
const command = `node ${jsOutputFilePath}`;
logger.info({command: command}, 'Spawning node on generated js');
return q.nfcall(child_process.exec.bind(child_process), command);
})
.fail(function(err: any) {
logger.error(err, 'lsc failed');
throw err;
});
}).spread(function(stdout: Buffer, stderr: Buffer) {
if (stderr.length) {
throw new Error(stderr.toString());
}
logger.info({stdout: stdout.toString()}, 'Nodejs spawn complete');
return stdout.toString();
});
}
示例3: getHistoryModel
export function getHistoryModel(
options,
basePath = remote.app.getPath('userData')
) {
let buffer: any[] = []
let promise = q()
const fileName = basePath + '/' + options.file
const history = {
push(item) {
promise = promise.then(() => {
buffer.splice(0, 0, item)
if (buffer.length > options.max) {
buffer = buffer.slice(0, options.min)
}
return q.nfcall(
writeFile,
fileName,
buffer.map(obj => JSON.stringify(obj)).join(',')
)
})
return promise
},
list: () => buffer,
}
return q.nfcall(readFile, fileName).then(
content => {
buffer = JSON.parse('[' + content + ']')
return history
},
() => history
)
}
示例4: file
Q.all([Q.nfcall(fs.exists, jsconfigPath), Q.nfcall(fs.exists, tsconfigPath)]).spread((jsExists: boolean, tsExists: boolean) => {
if (!jsExists && !tsExists) {
Q.nfcall(fs.writeFile, jsconfigPath, "{}").then(() => {
// Any open file must be reloaded to enable intellisense on them, so inform the user
vscode.window.showInformationMessage("A 'jsconfig.json' file was created to enable IntelliSense. You may need to reload your open JS file(s).");
});
}
});
示例5:
.then(function(exists: boolean) {
if (!exists) {
return Q.nfcall(child_process.exec, `npm install --prefix ${typeScriptNextDest} typescript@next`)
.then(() => { return true; });
}
return isRestartRequired;
});
示例6: findFilesByExtension
public findFilesByExtension(folder: string, extension: string): Q.Promise<string[]> {
return Q.nfcall(fs.readdir, folder).then((files: string[]) => {
const extFiles = files.filter((file: string) => path.extname(file) === `.${extension}`);
if (extFiles.length === 0) {
throw new Error(`Unable to find any ${extension} files.`);
}
return extFiles;
});
}
示例7: exists
/**
* Helper (asynchronous) function to check if a file or directory exists
*/
public exists(filename: string): Q.Promise<boolean> {
return Q.nfcall(fs.stat, filename)
.then(function() {
return Q.resolve(true);
})
.catch(function(err) {
return Q.resolve(false);
});
}
示例8:
promise = promise.then(() => {
buffer.splice(0, 0, item)
if (buffer.length > options.max) {
buffer = buffer.slice(0, options.min)
}
return q.nfcall(
writeFile,
fileName,
buffer.map(obj => JSON.stringify(obj)).join(',')
)
})
示例9: getBundleIdentifier
public static getBundleIdentifier(projectRoot: string): Q.Promise<string> {
return Q.nfcall(fs.readdir, path.join(projectRoot, 'platforms', 'ios')).then((files: string[]) => {
let xcodeprojfiles = files.filter((file: string) => /\.xcodeproj$/.test(file));
if (xcodeprojfiles.length === 0) {
throw new Error('Unable to find xcodeproj file');
}
let xcodeprojfile = xcodeprojfiles[0];
let projectName = /^(.*)\.xcodeproj/.exec(xcodeprojfile)[1];
let plist = pl.parseFileSync(path.join(projectRoot, 'platforms', 'ios', projectName, projectName + '-Info.plist'));
return plist.CFBundleIdentifier;
});
}
示例10: ensureNuGetDownloads
async function ensureNuGetDownloads(): Promise<void> {
if (!fs.existsSync(tempDir)) {
await Q.nfcall(fs.mkdir, tempDir);
}
for (let i of nuGetVersions) {
if (!fs.existsSync(i.filePath)) {
// tslint:disable-next-line
console.log(`Downloading ${i.url} to ${i.filePath}`);
await download(i.url, i.filePath);
}
}
}