Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for user-specifiable name for cache directory #5

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

herber
Copy link

@herber herber commented Feb 23, 2018

Users should be able to choose the name of gittar's directory in ~/.

Instead of .gittar users can choose any name.

Example

gittar.fetch

gittar.fetch('lukeed/polka', { name: 'custom' }).then(console.log);
//=> ~/.custom/github/lukeed/polka/master.tar.gz

gittar.extract

gittar.extract('lukeed/polka#master', 'foo', { name: 'custom' });
// Searches in ~/.custom/ for the tarball
//=> contents: foo/polka-master/**

Copy link
Owner

@lukeed lukeed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, thanks~!!

Left some comments for you.

Do you mind sharing your use case for this? IMO, it'd be better to have everything shared from .gittar explicitly so that users don't end up with copies of the same tarball in different root locations.

Of course, this pkg isn't that popular to really make that a concern, but if that ever were the case, I'd be afraid of having something existing in multiple locations, when the underlying gittar can know for certain if it has it. Also, current approach allows for easy cleanup -- single directory to remove.

lib/index.js Outdated
function getTarFile(obj) {
return path.join(DIR, obj.site, obj.repo, `${obj.type}.tar.gz`);
function getTarFile(obj, name) {
return path.join(name !== undefined ? path.join(HOME, '.' + name) : DIR, obj.site, obj.repo, `${obj.type}.tar.gz`);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be:

function getTarFile(obj, name) {
  let dir = name ? path.join(HOME, `.${name}`) : DIR;
  return path.join(dir, obj.site, obj.repo, `${obj.type}.tar.gz`);
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easier to read IMO

lib/index.js Outdated
dest = path.resolve(dest || '.');
return new Promise((res, rej) => {
const ok = _ => res(dest);
opts = Object.assign({ strip:1 }, opts, { file, cwd:dest });
opts = Object.assign({ strip:1 }, opts, { file, cwd:dest, name: undefined });
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would have to be

opts = Object.assign({ strip:1, name:null }, opts, { file, cwd:dest });

Otherwise you're always overwriting a user-specified opts.name with name:undefined.

Used null here just for shorthand; that's not the problem in this case. :D

@herber
Copy link
Author

herber commented Feb 24, 2018

Thanks for the suggestions!

I added this feature, because some users might worry about the .gittar folder, instead of .my-app. They probably don't know .gittar, and would just delete the folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants