本文整理汇总了TypeScript中fs-extra.exists函数的典型用法代码示例。如果您正苦于以下问题:TypeScript exists函数的具体用法?TypeScript exists怎么用?TypeScript exists使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了exists函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: reject
return new Promise<Operations>((resolve, reject) => {
fs.exists(tasksJsonPath, exists => {
if (exists) {
fs.readFile(tasksJsonPath, (err, buffer) => {
if (err) {
return reject(err);
}
const text = buffer.toString();
let tasksConfiguration: tasks.TaskConfiguration;
try {
tasksConfiguration = tolerantParse(text);
}
catch (error) {
vscode.window.showErrorMessage(`Failed to parse tasks.json file`);
return resolve({ updateTasksJson: false });
}
let buildTasks = getBuildTasks(tasksConfiguration);
resolve({ updateTasksJson: buildTasks.length === 0 });
});
}
else {
resolve({ addTasksJson: true });
}
});
});
示例2: validateExistance
/**
* Validates the existence of the specified file
*
* @param {string} projectPath Path to project
* @param {string} checkPath Absolute path to file to check
*/
async function validateExistance(projectPath: string, checkPath: string) {
const fileExists = await fs.exists(checkPath);
if (!fileExists) {
const friendlyPath = checkPath.replace(projectPath, './');
throw new Error(`The project doesn't contain a ${friendlyPath}`);
}
}
示例3: resolve
return new Promise<any>(resolve => {
fs.exists(file, yes => {
if (yes) {
return fs.unlink(file, () => resolve());
}
resolve();
});
});
示例4: getIndexHTML
/**
* Return public/index.html contents
*
* @param {string} projectPath
*/
async function getIndexHTML(projectPath: string) {
const indexHTMLPath = path.join(projectPath, 'public', 'index.html');
const fileExists = await fs.exists(indexHTMLPath);
if (!fileExists) {
return '';
}
return fs.readFileSync(indexHTMLPath) || '';
}
示例5: getPackageJSON
/**
* Return package.json object
*
* @param {string} projectPath
* @returns
*/
async function getPackageJSON(projectPath: string) {
const packageJSONPath = path.join(projectPath, 'package.json');
const fileExists = await fs.exists(packageJSONPath);
if (!fileExists) {
throw new Error(`The project doesn't have a package.json.`);
}
return fs.readJson(packageJSONPath);
}
示例6: Promise
return new Promise((resolve, reject) => {
fs.exists(fileName, (exist) => {
if (exist) {
resolve();
} else {
reject(new Error(`File ${fileName} was expected to exist but not found...`));
}
});
});
示例7: resolve
fs.exists(generator.launchJsonPath, exists => {
if (exists) {
resolve(true);
}
else {
fs.exists(generator.tasksJsonPath, exists => {
resolve(exists);
});
}
});
示例8: reject
return new Promise<void>((resolve, reject) => {
fs.exists(path, exists => {
if (exists) {
// TODO: Should we check after unlinking to see if the file still exists?
fs.unlink(path, err => {
if (err) {
return reject(err);
}
resolve();
});
}
});
});