• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript fs-extra.pathExists函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中fs-extra.pathExists函数的典型用法代码示例。如果您正苦于以下问题:TypeScript pathExists函数的具体用法?TypeScript pathExists怎么用?TypeScript pathExists使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了pathExists函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: _setupLibraries

  async _setupLibraries () {
    const libraries = this.opts.json.libraries
    const librariesPath = []
    for (const library of libraries) {
      if (library['natives']) continue
      if (!library.path) {
        if (library['downloads']) {
          library.path = library['downloads']['artifact']['path']
        } else {
          library.path = JavaLibraryHelper.getPath(library.name)
        }
      }
      const path = npath.join(this._libraryPath, library.path)
      if (!await fs.pathExists(path)) {
        this.emit('missing', library)
        this._missingLibrary.push(library)
      }

      librariesPath.push(path)
    }
    const jar = this.opts.json.jar || this.opts.json.id
    let filePath: string
    if (this.opts.json.inheritsFrom) {
      filePath = npath.join(this.versionPath, `../${this.opts.json.inheritsFrom}/${jar}.jar`)
    } else {
      filePath = npath.join(this.versionPath, `${jar}.jar`)
    }
    if (!await fs.pathExists(filePath)) throw new Error('cannot find jar')
    librariesPath.push(filePath)

    this._arguments.push('-cp')
    this._arguments.push(`${librariesPath.join(npath.delimiter)}`)
    return librariesPath.join(';')
  }
开发者ID:bangbang93,项目名称:BMCLJS,代码行数:34,代码来源:launcher.ts


示例2: prepareDiffFile

async function prepareDiffFile(
  rs: RepositorySession,
  file: DiffFile
): Promise<string> {
  if (file.sha === "UNSTAGED") {
    // use file in the repository directly
    return path.join(rs.repoPath, file.path);
  }

  let absPath: string;
  if (file.sha === "STAGED") {
    const fileName = path.basename(file.path);
    const tempFileName = `STAGED-${randomName(6)}-${fileName}`;
    // TODO: check file name conflict
    absPath = path.join(rs.tempdir, tempFileName);
  } else {
    // TODO: shorten path
    absPath = path.join(rs.tempdir, file.sha, file.path);
    const parentDir = path.dirname(absPath);
    if (!(await fs.pathExists(parentDir))) {
      await fs.mkdirs(parentDir);
    }
  }
  if (await fs.pathExists(absPath)) {
    return absPath;
  }
  await git.saveTo(rs.repoPath, file.path, file.sha, absPath);
  return absPath;
}
开发者ID:wonderful-panda,项目名称:inazuma,代码行数:29,代码来源:actions.ts


示例3: found

(async () => {
  const dirsToCheck = [];

  for (const subDir of await fs.readdir(PACKAGES_DIR)) {
    for (const packageDir of await fs.readdir(path.resolve(PACKAGES_DIR, subDir))) {
      dirsToCheck.push(path.resolve(PACKAGES_DIR, subDir, packageDir));
    }
  }

  let bad = false;
  for (const dir of dirsToCheck) {
    const pj = await fs.readJson(path.resolve(dir, 'package.json'));
    if (pj.name === '@electron-forge/cli') continue;
    if (!await fs.pathExists(path.resolve(dir, pj.main))) {
      console.error(`${`[${pj.name}]`.cyan}:`,  `Main entry not found (${pj.main})`.red);
      bad = true;
    }
    if (!pj.typings || !await fs.pathExists(path.resolve(dir, pj.typings))) {
      console.error(`${`[${pj.name}]`.cyan}:`, `Typings entry not found (${pj.typings})`.red);
      bad = true;
    }
  }

  if (bad) {
    process.exit(1);
  }
})().catch(console.error);
开发者ID:balloonzzq,项目名称:electron-forge,代码行数:27,代码来源:test-dist.ts


示例4: async

 const migrateV6Plugins = async () => {
   if (!await fs.pathExists(pluginsDir)) return
   process.stderr.write('heroku: migrating plugins\n')
   try {
     const p = path.join(pluginsDir, 'user.json')
     if (await fs.pathExists(p)) {
       const {manifest} = await fs.readJSON(p)
       for (let plugin of Object.keys(manifest.plugins)) {
         process.stderr.write(`heroku-cli: migrating ${plugin}\n`)
         await exec('heroku', ['plugins:install', plugin])
       }
     }
   } catch (err) {
     this.warn(err)
   }
   try {
     const p = path.join(pluginsDir, 'link.json')
     if (await fs.pathExists(p)) {
       const {manifest} = await fs.readJSON(path.join(pluginsDir, 'link.json'))
       for (let {root} of Object.values(manifest.plugins) as any) {
         process.stderr.write(`heroku-cli: migrating ${root}\n`)
         await exec('heroku', ['plugins:link', root])
       }
     }
   } catch (err) {
     this.warn(err)
   }
   await fs.remove(pluginsDir)
   process.stderr.write('heroku: done migrating plugins\n')
 }
开发者ID:jimmyurl,项目名称:cli,代码行数:30,代码来源:plugin-migrate.ts


示例5: it

    it('can package to outDir without errors', async () => {
      const outDir = `${dir}/foo`;

      expect(await fs.pathExists(outDir)).to.equal(false);

      await forge.package({ dir, outDir });

      expect(await fs.pathExists(outDir)).to.equal(true);
    });
开发者ID:balloonzzq,项目名称:electron-forge,代码行数:9,代码来源:api_spec_slow.ts


示例6: it

      it('should do nothing when disabled', async () => {
        p.config.enabled = false;
        const fn = p.getHook('packageAfterExtract')!;

        await fn(null, tmpDir, null, process.platform, process.arch);

        expect(await fs.pathExists(tmpDir)).to.equal(true);
        expect(await fs.pathExists(path.resolve(tmpDir, 'touch'))).to.equal(true);
      });
开发者ID:balloonzzq,项目名称:electron-forge,代码行数:9,代码来源:LocalElectronPlugin_spec.ts


示例7: withTempDirectory

 await withTempDirectory(async dir => {
   const testFile = path.resolve(dir, 'test.txt');
   expect(await fs.pathExists(testFile)).toEqual(false);
   await downloader.download(
     'https://github.com/electron/electron/releases/download/v2.0.18/SHASUMS256.txt',
     testFile,
   );
   expect(await fs.pathExists(testFile)).toEqual(true);
   expect(await fs.readFile(testFile, 'utf8')).toMatchSnapshot();
 });
开发者ID:electron-userland,项目名称:electron-download,代码行数:10,代码来源:GotDownloader.spec.ts


示例8: chapterAsync

export async function chapterAsync(request: express.Request, response: express.Response) {
  // Initialize the downloaded chapter.
  let chapterPath = shared.path.normal(request.params.providerName, request.params.seriesTitle, request.params.chapterName + shared.extension.cbz);
  let chapterExists = await fs.pathExists(chapterPath);
  if (chapterExists) return process(response, chapterPath);
  
  // Initialize the deleted chapter.
  let deletedChapterPath = shared.path.normal(request.params.providerName, request.params.seriesTitle, request.params.chapterName + shared.extension.del);
  let deletedChapterExists = await fs.pathExists(deletedChapterPath);
  if (deletedChapterExists) return process(response, deletedChapterPath);
  response.sendStatus(404);
}
开发者ID:Deathspike,项目名称:mangarack,代码行数:12,代码来源:chapter.ts


示例9: generatePackageJson

/**
 * Generate a super minimal package.json from an existing bower.json, and adds
 * `node_modules` to `.gitignore` if needed. Does nothing if there's already a
 * package.json.
 */
async function generatePackageJson(element: ElementRepo): Promise<void> {
  const npmConfigPath = path.join(element.dir, 'package.json');
  if (await fse.pathExists(npmConfigPath)) {
    console.log(`${element.ghRepo.name} already has a package.json, skipping.`);
    return;
  }

  const bowerConfigPath = path.join(element.dir, 'bower.json');
  if (!await fse.pathExists(bowerConfigPath)) {
    throw new Error(`${element.ghRepo.name} has no bower.json.`);
  }
  const bowerConfig: BowerConfig = await fse.readJson(bowerConfigPath);

  const npmConfig: NpmConfig = {
    // This is the style of name we're using for the 3.0 elements on NPM. Might
    // as well be consistent, even though this is a 2.0 package.json.
    name: `@polymer/${bowerConfig.name}`,

    // Make sure we don't accidentally publish this repo.
    private: true,

    // Note that we exclude version because the bower version might not be well
    // maintained, plus it won't get updated here going forward if we do more
    // releases.

    // npm warns if any of these fields aren't set.
    description: bowerConfig.description,
    repository: bowerConfig.repository,
    license: 'BSD-3-Clause'
  };

  // Since we're an NPM package now, we might get some dependencies installed,
  // which we don't want to commit.
  const gitIgnorePath = path.join(element.dir, '.gitignore');
  let gitIgnore = '';
  if (await fse.pathExists(gitIgnorePath)) {
    gitIgnore = (await fse.readFile(gitIgnorePath)).toString();
  }
  if (!gitIgnore.includes('node_modules')) {
    if (!gitIgnore.endsWith('\n')) {
      gitIgnore += '\n';
    }
    gitIgnore += 'node_modules\n';
    await fse.writeFile(gitIgnorePath, gitIgnore);
  }

  await fse.writeJson(npmConfigPath, npmConfig, {spaces: 2});

  await makeCommit(
      element,
      ['package.json', '.gitignore'],
      'Generate minimal package.json from bower.json');
}
开发者ID:TimvdLippe,项目名称:tedium,代码行数:58,代码来源:package-json.ts


示例10: it

    it('creates a merge commit', async () => {
      const repo = await setupConflictedRepo()
      const filePath = path.join(repo.path, 'foo')

      const inMerge = await FSE.pathExists(
        path.join(repo.path, '.git', 'MERGE_HEAD')
      )
      expect(inMerge).to.equal(true)

      await FSE.writeFile(filePath, 'b1b2')

      const status = await getStatusOrThrow(repo)
      const files = status.workingDirectory.files

      expect(files.length).to.equal(1)
      expect(files[0].path).to.equal('foo')
      expect(files[0].status).to.equal(AppFileStatus.Conflicted)

      const selection = files[0].selection.withSelectAll()
      const selectedFile = files[0].withSelection(selection)
      await createCommit(repo, 'Merge commit!', [selectedFile])

      const commits = await getCommits(repo, 'HEAD', 5)
      expect(commits[0].parentSHAs.length).to.equal(2)
    })
开发者ID:soslanashkhotov,项目名称:desktop,代码行数:25,代码来源:commit-test.ts


示例11:

export async function readJsonIfExists<T>(filepath: string):
    Promise<T|undefined> {
  if (await fse.pathExists(filepath)) {
    return await fse.readJSON(filepath) as T;
  }
  return undefined;
}
开发者ID:,项目名称:,代码行数:7,代码来源:


示例12: findGitBash

async function findGitBash(): Promise<string | null> {
  const registryPath = enumerateValues(
    HKEY.HKEY_LOCAL_MACHINE,
    'SOFTWARE\\GitForWindows'
  )

  if (registryPath.length === 0) {
    return null
  }

  const installPathEntry = registryPath.find(e => e.name === 'InstallPath')
  if (installPathEntry && installPathEntry.type === RegistryValueType.REG_SZ) {
    const path = Path.join(installPathEntry.data, 'git-bash.exe')

    if (await pathExists(path)) {
      return path
    } else {
      log.debug(
        `[Git Bash] registry entry found but does not exist at '${path}'`
      )
    }
  }

  return null
}
开发者ID:ghmoore,项目名称:desktop,代码行数:25,代码来源:win32.ts


示例13: getBabelAst

async function getBabelAst(path: string, options: FableSplitterOptions, info: CompilationInfo) {
    let ast: Babel.types.Node | null = null;
    if (FSHARP_EXT.test(path)) {
        // return Babel AST from F# file
        const fableMsg = JSON.stringify(Object.assign({}, options.fable, { path, rootDir: process.cwd() }));
        const response = await fableUtils.client.send(options.port as number, fableMsg);
        const babelAst = JSON.parse(response);
        if (babelAst.error) {
            throw new Error(babelAst.error);
        } else if (path.endsWith(".fsproj")) {
            info.projectFiles = babelAst.sourceFiles;
        }
        addLogs(babelAst.logs, info);
        ast = babelAst;
    } else {
        // return Babel AST from JS file
        path = JAVASCRIPT_EXT.test(path) ? path : path + ".js";
        if (await fs.pathExists(path)) {
            ast = await getBabelAstFromJsFile(path, info);
        } else {
            console.log(`fable: Skip missing JS file: ${path}`);
        }
    }
    return ast;
}
开发者ID:TheAngryByrd,项目名称:Fable,代码行数:25,代码来源:index.ts


示例14: it

      it('should create dry run hash JSON files', async () => {
        expect(makeStub.callCount).to.equal(2);
        const dryRunFolder = path.resolve(dir, 'out', 'publish-dry-run');
        expect(await fs.pathExists(dryRunFolder)).to.equal(true);

        const hashFolders = await fs.readdir(dryRunFolder);
        expect(hashFolders).to.have.length(2, 'Should contain two hashes (two publishes)');
        for (const hashFolderName of hashFolders) {
          const hashFolder = path.resolve(dryRunFolder, hashFolderName);
          const makes = await fs.readdir(hashFolder);
          expect(makes).to.have.length(3, 'Should contain the results of three makes');
          for (const makeJson of makes) {
            const jsonPath = path.resolve(hashFolder, makeJson);
            const contents = await fs.readFile(jsonPath, 'utf8');
            expect(() => JSON.parse(contents), 'Should be valid JSON').to.not.throw();
            const data = JSON.parse(contents);
            expect(data).to.have.property('artifacts');
            expect(data).to.have.property('platform');
            expect(data).to.have.property('arch');
            expect(data).to.have.property('packageJSON');

            // Make the artifacts for later
            for (const artifactPath of data.artifacts) {
              await fs.mkdirp(path.dirname(path.resolve(dir, artifactPath)));
              await fs.writeFile(path.resolve(dir, artifactPath), artifactPath);
            }
          }
        }
      });
开发者ID:balloonzzq,项目名称:electron-forge,代码行数:29,代码来源:publish_spec.ts


示例15: test

  test('should allow module data to be deleted', async () => {
    // Write some module data, then delete it and check that all files have been deleted
    await Promise.all([
      persist.module('CS1010S', {} as any),
      persist.semesterData(1, 'CS1010S', {} as any),
      persist.semesterData(2, 'CS1010S', {} as any),
      persist.timetable(1, 'CS1010S', {} as any),
      persist.timetable(2, 'CS1010S', {} as any),
    ]);

    await persist.deleteModule('CS1010S');

    await expect(fs.pathExists('2018-2019/modules/CS1010S.json')).resolves.toEqual(false);
    await expect(fs.pathExists('2018-2019/semesters/1/CS1010S')).resolves.toEqual(false);
    await expect(fs.pathExists('2018-2019/semesters/2/CS1010S')).resolves.toEqual(false);
  });
开发者ID:nusmodifications,项目名称:nusmods,代码行数:16,代码来源:io.test.ts


示例16: async

// FIXME: If we want getElectronVersion to be overridable by plugins
//        and / or forge config then we need to be able to resolve
//        the dir without calling getElectronVersion
export default async (dir: string) => {
  let mDir = dir;
  let prevDir;
  while (prevDir !== mDir) {
    prevDir = mDir;
    const testPath = path.resolve(mDir, 'package.json');
    d('searching for project in:', mDir);
    if (await fs.pathExists(testPath)) {
      const packageJSON = await readRawPackageJson(mDir);

      // TODO: Move this check to inside the forge config resolver and use
      //       mutatedPackageJson reader
      const electronVersion = getElectronVersion(packageJSON);
      if (electronVersion) {
        if (!/[0-9]/.test(electronVersion[0])) {
          throw `You must depend on an EXACT version of electron not a range (${electronVersion})`;
        }
      } else {
        throw 'You must depend on "electron" in your devDependencies';
      }

      if (packageJSON.config && packageJSON.config.forge) {
        d('electron-forge compatible package.json found in', testPath);
        return mDir;
      }
    }
    mDir = path.dirname(mDir);
  }
  return null;
};
开发者ID:balloonzzq,项目名称:electron-forge,代码行数:33,代码来源:resolve-dir.ts


示例17: findPowerShellCore

async function findPowerShellCore(): Promise<string | null> {
  const powerShellCore = enumerateValues(
    HKEY.HKEY_LOCAL_MACHINE,
    'Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\pwsh.exe'
  )

  if (powerShellCore.length === 0) {
    return null
  }

  const first = powerShellCore[0]
  if (first.type === RegistryValueType.REG_SZ) {
    const path = first.data

    if (await pathExists(path)) {
      return path
    } else {
      log.debug(
        `[PowerShellCore] registry entry found but does not exist at '${path}'`
      )
    }
  }

  return null
}
开发者ID:ghmoore,项目名称:desktop,代码行数:25,代码来源:win32.ts


示例18: seriesAsync

export async function seriesAsync(request: express.Request, response: express.Response) {
  let metaSeriesPath = shared.path.normal(request.params.providerName, request.params.seriesTitle + shared.extension.json);
  let metaSeriesExists = await fs.pathExists(metaSeriesPath);
  if (metaSeriesExists) {
    let seriesPath = shared.path.normal(request.params.providerName, request.params.seriesTitle);
    let seriesExists = await fs.pathExists(seriesPath);
    let metaSeries = await fs.readJson(metaSeriesPath) as shared.IMetaSeries;
    let series = metaSeries as shared.IApiSeries;
    if (seriesExists) {
      let fileNames = await fs.readdir(seriesPath);
      let seriesChapters = [] as shared.IApiSeriesChapter[];
      let seriesChapterFileNames = {} as {[fileName: string]: number};
      for (let metaSeriesChapter of metaSeries.chapters) {
        let chapterName = sanitizeFilename(metaSeriesChapter.name) + shared.extension.cbz;
        let scanResult = scan(metaSeriesChapter.name);
        seriesChapterFileNames[chapterName] = seriesChapters.push({
          available: true,
          downloaded: fileNames.indexOf(chapterName) !== -1,
          name: metaSeriesChapter.name,
          number: scanResult.number,
          title: metaSeriesChapter.title,
          volume: scanResult.volume
        });
      }
      for (let fileName of fileNames) {
        let fileExtension = path.extname(fileName);
        if (!seriesChapterFileNames[fileName] && (fileExtension === shared.extension.cbz || fileExtension === shared.extension.del)) {
          let chapterName = fileName.substr(0, fileName.length - fileExtension.length);
          let scanResult = scan(chapterName);
          seriesChapters.push({
            available: false,
            downloaded: true,
            name: chapterName,
            number: scanResult.number,
            volume: scanResult.volume
          });
        }
      }
      series.chapters = seriesChapters.sort(orderVolumeAndNumber);
      response.send(series);
    } else {
      response.send(series);
    }
  } else {
    response.sendStatus(404);
  }
}
开发者ID:Deathspike,项目名称:mangarack,代码行数:47,代码来源:series.ts


示例19: async

const copyPublicFolder = async (dest: string): Promise<void> => {
  if (await fs.pathExists(paths.appPublic)) {
    await fs.copySync(paths.appPublic, paths.distPublic(dest), {
      dereference: true,
      filter: file => file !== paths.indexHtml,
    })
  }
}
开发者ID:leslieSie,项目名称:docz,代码行数:8,代码来源:build.ts


示例20: createSeriesAsync

export async function createSeriesAsync(series: mio.IScraperSeries) {
  let metaProviderPath = shared.path.normal(series.providerName + shared.extension.json);
  let metaProviderExists = await fs.pathExists(metaProviderPath);
  let metaProvider = metaProviderExists ? await fs.readJson(metaProviderPath) as shared.IMetaProvider : {};
  metaProvider[series.url] = series.title;
  await mio.commands.updateSeriesAsync(series);
  await fs.writeJson(metaProviderPath, metaProvider, {spaces: 2});
}
开发者ID:Deathspike,项目名称:mangarack,代码行数:8,代码来源:create.ts



注:本文中的fs-extra.pathExists函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript fs-extra.pathExistsSync函数代码示例发布时间:2022-05-25
下一篇:
TypeScript fs-extra.outputJson函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap