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


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

本文整理匯總了TypeScript中fs-extra.pathExists函數的典型用法代碼示例。如果您正苦於以下問題:TypeScript pathExists函數的具體用法?TypeScript pathExists怎麽用?TypeScript pathExists使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了pathExists函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


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