Skip to content

Instantly share code, notes, and snippets.

@isaacs
Last active April 8, 2018 02:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save isaacs/8142efc45eef5109e1d128588f08aebe to your computer and use it in GitHub Desktop.
Save isaacs/8142efc45eef5109e1d128588f08aebe to your computer and use it in GitHub Desktop.
$ tree x
x
└── y/
└── z/
└── .gitignore
2 directories, 1 file
$ tar cf x.tar x
$ tar tvf x.tar
drwxr-xr-x 0 isaacs staff 0 Aug 17 16:47 x/
drwxr-xr-x 0 isaacs staff 0 Aug 17 16:46 x/y/
drwxr-xr-x 0 isaacs staff 0 Aug 17 16:46 x/y/z/
-rw-r--r-- 0 isaacs staff 0 Aug 17 16:46 x/y/z/.gitignore
$ node rename.js
$ tree output/
output/
└── x/
└── y/
└── z/
└── .npmignore
3 directories, 1 file
'use strict'
const tar = require('./')
const file = 'x.tar'
const mkdirp = require('mkdirp')
const path = require('path')
const rimraf = require('rimraf')
rimraf.sync('output')
mkdirp.sync('output')
tar.x({
file: file,
cwd: 'output',
onentry: entry => {
if (path.basename(entry.path) === '.gitignore')
entry.path = path.dirname(entry.path) + '/.npmignore'
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment