當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript fs-extra.exists函數代碼示例

本文整理匯總了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 });
            }
        });
    });
開發者ID:eamodio,項目名稱:omnisharp-vscode,代碼行數:29,代碼來源:assets.ts

示例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}`);
  }
}
開發者ID:ghoullier,項目名稱:codesandbox-cli,代碼行數:14,代碼來源:index.ts

示例3: resolve

 return new Promise<any>(resolve => {
     fs.exists(file, yes => {
         if (yes) {
             return fs.unlink(file, () => resolve());
         }
         resolve();
     });
 });
開發者ID:lzfernandes,項目名稱:pythonVSCode,代碼行數:8,代碼來源:extension.lint.test.ts

示例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) || '';
}
開發者ID:ghoullier,項目名稱:codesandbox-cli,代碼行數:14,代碼來源:index.ts

示例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);
}
開發者ID:ghoullier,項目名稱:codesandbox-cli,代碼行數:15,代碼來源:index.ts

示例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...`));
     }
   });
 });
開發者ID:3L4CKD4RK,項目名稱:angular-cli,代碼行數:9,代碼來源:fs.ts

示例7: resolve

 fs.exists(generator.launchJsonPath, exists => {
     if (exists) {
         resolve(true);
     }
     else {
         fs.exists(generator.tasksJsonPath, exists => {
             resolve(exists);
         });
     }
 });
開發者ID:eamodio,項目名稱:omnisharp-vscode,代碼行數:10,代碼來源:assets.ts

示例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();
                });
            }
        });
    });
開發者ID:rlugojr,項目名稱:omnisharp-vscode,代碼行數:14,代碼來源:assets.ts


注:本文中的fs-extra.exists函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。