export function createTarTask()

in packages/just-scripts/src/tasks/tarTask.ts [62:95]


export function createTarTask(options: CreateOptions = { file: 'archive.tar.gz' }): TaskFunction {
  const resolvedTar = resolve('tar-fs');

  // Inject default options
  options = { cwd: process.cwd(), gzip: true, ...options };

  // Validate whether tar-fs is installed
  if (!resolvedTar) {
    logger.error('Please make sure to have "tar-fs" as a dependency in your package.json');
    throw new Error('Required dependency "tar-fs" is not installed!');
  }

  const tar = require(resolvedTar);

  const { entries, file, cwd, ...restOptions } = options;

  return function archive(done) {
    let tarStream = tar.pack(cwd, {
      entries,
      finalize: true,
      finish: () => {
        done();
      },
      ...restOptions,
    });

    if (options.gzip) {
      const gzip = typeof options.gzip === 'boolean' ? createGzip() : createGzip(options.gzip as any);
      tarStream = tarStream.pipe(gzip);
    }

    tarStream.pipe(createWriteStream(options.file));
  };
}