fs-extra#readlink TypeScript Examples

The following examples show how to use fs-extra#readlink. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.ts    From cli with MIT License 5 votes vote down vote up
private async makeZip(sourceDirection: string, targetFileName: string) {
    let ignore = [];
    if (this.core.service?.experimentalFeatures?.removeUselessFiles) {
      this.core.cli.log(' - Experimental Feature RemoveUselessFiles');
      ignore = uselessFilesMatch;
    }
    const globbyMatched = ['**'];
    const npmClient = this.getNPMClient();
    if (npmClient?.startsWith('pnpm')) {
      globbyMatched.push('**/.pnpm/**');
    }
    const fileList = await globby(globbyMatched, {
      onlyFiles: false,
      followSymbolicLinks: false,
      cwd: sourceDirection,
      ignore,
    });
    const zip = new JSZip();
    const isWindows = platform() === 'win32';
    for (const fileName of fileList) {
      const absPath = join(sourceDirection, fileName);
      const stats = await lstat(absPath);
      if (stats.isDirectory()) {
        zip.folder(fileName);
      } else if (stats.isSymbolicLink()) {
        let link = await readlink(absPath);
        if (isWindows) {
          link = relative(dirname(absPath), link).replace(/\\/g, '/');
        }
        zip.file(fileName, link, {
          binary: false,
          createFolders: true,
          unixPermissions: stats.mode,
        });
      } else if (stats.isFile()) {
        const fileData = await readFile(absPath);
        zip.file(fileName, fileData, {
          binary: true,
          createFolders: true,
          unixPermissions: stats.mode,
        });
      }
    }
    await new Promise((res, rej) => {
      zip
        .generateNodeStream({
          platform: 'UNIX',
          compression: 'DEFLATE',
          compressionOptions: {
            level: 6,
          },
        })
        .pipe(createWriteStream(targetFileName))
        .once('finish', res)
        .once('error', rej);
    });
  }