How to use the @ionic/utils-fs.readdirSafe function in @ionic/utils-fs

To help you get started, we’ve selected a few @ionic/utils-fs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ionic-team / ionic-cli / packages / ionic / src / commands / monitoring / syncmaps.ts View on Github external
sourcemapsExist = await pathExists(sourcemapsDir);

    if (sourcemapsExist) {
      this.env.log.msg(`Using existing sourcemaps in ${strong(prettyPath(sourcemapsDir))}`);
    } else { // TODO: this is hard-coded for ionic-angular, make it work for all project types
      throw new FatalException(
        `Cannot find directory: ${strong(prettyPath(sourcemapsDir))}.\n` +
        `Make sure you have the latest ${strong('@ionic/app-scripts')}. Then, re-run this command.`
      );
    }

    let count = 0;
    const tasks = this.createTaskChain();
    const syncTask = tasks.next('Syncing sourcemaps');

    const sourcemapFiles = (await readdirSafe(sourcemapsDir)).filter(f => f.endsWith('.js.map'));
    debug(`Found ${sourcemapFiles.length} sourcemap files: ${sourcemapFiles.map(f => strong(f)).join(', ')}`);

    await Promise.all(sourcemapFiles.map(async f => {
      await this.syncSourcemap(path.resolve(sourcemapsDir, f), snapshotId, appVersion, commitHash, appflowId, token);
      count += 1;
      syncTask.msg = `Syncing sourcemaps: ${strong(`${count} / ${sourcemapFiles.length}`)}`;
    }));

    syncTask.msg = `Syncing sourcemaps: ${strong(`${sourcemapFiles.length} / ${sourcemapFiles.length}`)}`;
    tasks.end();

    const details = columnar([
      ['App ID', strong(appflowId)],
      ['Version', strong(appVersion)],
      ['Package ID', strong(cordovaInfo.id)],
      ['Snapshot ID', snapshotId ? strong(snapshotId) : weak('not set')],
github ionic-team / ionic-cli / packages / ionic / src / lib / integrations / cordova / resources.ts View on Github external
export async function getSourceImages(projectDir: string, buildPlatforms: string[], resourceTypes: string[]): Promise {
  const resourceDir = path.resolve(projectDir, 'resources'); // TODO: hard-coded

  const srcDirList = buildPlatforms
    .map(platform => ({ platform, path: path.resolve(resourceDir, platform) }))
    .concat({ platform: 'global', path: resourceDir });

  const sourceImages: SourceImage[] = [];

  for (const srcImgDir of srcDirList) {
    const srcImageDirContents = await readdirSafe(srcImgDir.path);

    for (const srcImage of srcImageDirContents) {
      const ext = path.extname(srcImage);
      const resType = path.basename(srcImage, ext);

      if (SUPPORTED_SOURCE_EXTENSIONS.includes(ext) && resourceTypes.includes(resType)) {
        sourceImages.push({
          ext,
          resType,
          platform: srcImgDir.platform,
          path: path.join(srcImgDir.path, srcImage),
          vector: false,
          height: 0,
          width: 0,
        });
      }
github ionic-team / ionic-cli / packages / ionic / src / lib / integrations / cordova / index.ts View on Github external
this.e.log.info(`Downloading integration ${input(this.name)}`);
    const tmpdir = path.resolve(os.tmpdir(), `ionic-integration-${this.name}`);

    // TODO: etag

    if (await pathExists(tmpdir)) {
      await remove(tmpdir);
    }

    await mkdirp(tmpdir);

    const ws = tar.extract({ cwd: tmpdir });
    const { req } = await createRequest('GET', this.archiveUrl, this.e.config.getHTTPConfig());
    await download(req, ws, {});

    const contents = await readdirSafe(tmpdir);
    const blacklist: string[] = [];

    debug(`Integration files downloaded to ${strong(tmpdir)} (files: ${contents.map(f => strong(f)).join(', ')})`);

    for (const f of contents) {
      const projectf = path.resolve(this.e.project.directory, f);

      try {
        const stats = await stat(projectf);
        const overwrite = await conflictHandler(projectf, stats);

        if (!overwrite) {
          blacklist.push(f);
        }
      } catch (e) {
        if (e.code !== 'ENOENT') {
github ionic-team / ionic-cli / packages / ionic / src / lib / integrations / cordova / project.ts View on Github external
export async function getPlatforms(projectDir: string): Promise {
  const platformsDir = path.resolve(projectDir, 'platforms');
  const contents = await readdirSafe(platformsDir);
  const platforms = await filter(contents, async file => {
    const stat = await statSafe(path.join(platformsDir, file));
    return !file.startsWith('.') && typeof stat !== 'undefined' && stat.isDirectory();
  });

  return platforms;
}