本文整理匯總了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();
});
}
});
});