Skip to content

Commit dabd561

Browse files
authored
makes tar extraction depth configurable
defaults to 3 for consistency, but makes template depth (in repo) configurable 1 is root of project repo, as the case may be
1 parent 912910c commit dabd561

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ const getTar = ({
3030
user,
3131
repo,
3232
path = '',
33-
name
33+
name,
34+
depth = 3
3435
}) => {
3536
const url = `https://codeload.github.com/${user}/${repo}/tar.gz/master`
36-
const cmd = `curl ${url} | tar -xz -C ${name} --strip=3 ${repo}-master/${path}`
37+
const cmd = `curl ${url} | tar -xz -C ${name} --strip=${depth} ${repo}-master/${path}`
3738
exec(cmd, { stdio: 'inherit' })
3839
}
3940

@@ -51,14 +52,16 @@ const create = async (opts = {}) => {
5152
const dirname = path.resolve(opts.name)
5253
const name = path.basename(dirname)
5354
const [ user, repo, ...paths ] = opts.template.split('/')
55+
const depth = opts.templateDepth
5456

5557
fs.ensureDirSync(name)
5658

5759
getTar(Object.assign({}, opts, {
5860
name,
5961
user,
6062
repo,
61-
path: paths.join('/')
63+
path: paths.join('/'),
64+
depth
6265
}))
6366

6467
const templatePkg = require(

0 commit comments

Comments
 (0)