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

feat: MIT License by default and (attempt to) automatically set author name #244

Merged
merged 5 commits into from
Oct 16, 2019

Conversation

audiolion
Copy link
Contributor

@audiolion audiolion commented Oct 15, 2019

Adds an additional prompt to the CLI, somewhat unavoidable, we need the package author name to place in the LICENSE file. That said, we can double up and use the author name provided to place inside the package.json's author field as well.

image

Closes #241

If you have other ideas about how to approach this problem @sw-yx @jaredpalmer let me know.

Some other ideas I had:

  • Try and parse the user's git config for email / name, still need the CLI though because what if their git config is wrong, doesn't exist, etc. This could be useful to provide a sensible default for the name to make the create flow easier
  • tsdx config cli option that creates and stores a config object somewhere on the file system and uses those fields as defaults. It just seems like this is flaky though, unless it was part of the users dotfiles where they carried them between systems.

@audiolion audiolion force-pushed the feature/mit-license branch 3 times, most recently from 3bb5e4f to 8c68336 Compare October 15, 2019 12:48
@jaredpalmer
Copy link
Owner

I thought about this last night. I really want to limit the choice presented to the user. I really do not want people to have to think.

Some ideas:

  • Can we pull out the author info from npm config or git config?
  • We could create a ~/.tsdx file in the user's home directory with this information, so subsequent runs don't need to pull it out and we can skip the question (even with npx)
  • If we had our own tsdx publish we could get this info on the first run. This command would just be a thin wrapper around np. When it's run for the first time, it would prompt the user for whatever is missing in package.json. It could also maybe even check at the scripts.build against the presence of main, module, umd fields too.

@orta
Copy link
Contributor

orta commented Oct 15, 2019

We got pretty far with a mix of keychain and git for CocoaPods

@audiolion
Copy link
Contributor Author

Can we pull out the author info from npm config or git config?

I could update this PR to follow what @orta suggested and if I find anything to just use that, otherwise we prompt them for the information. I get the philosophy you are going for, and the user can always change the name in the license/package.json afterwards if they want something else.

Adds an additional option to the CLI, somewhat unavoidable, we need the package author name to place in the LICENSE file. That said, we can double up and use the author name provided to place inside the package.json's author field as well.
@audiolion audiolion force-pushed the feature/mit-license branch from 72e28df to f1fc1d6 Compare October 15, 2019 15:34
@audiolion
Copy link
Contributor Author

Ok I updated the PR to parse the users global git config and search for their name from that, if not found it prompts. I would like to add npm config as well but I didn't see any existing tools for parsing npm config. I also could add the stuff cocoapods was doing, but I would need to be running shelljs exec commands for that, I am not sure if I should be going down that road or not?

@jaredpalmer
Copy link
Owner

I am cool with adding shelljs.

@jaredpalmer
Copy link
Owner

go for it.

… or git config

We give npm first preference, if we do not find it there we try git.
If we still do not have a name we try for their email instead on npm first then on git.

Finally if we still dont have a name we prompt the user for the name.
@audiolion
Copy link
Contributor Author

Ok switched to shelljs and dropped parse-git-config, as it was just another point of failure.

@jaredpalmer
Copy link
Owner

@orta does this look good to you?

@orta
Copy link
Contributor

orta commented Oct 15, 2019

Could be worth setting the username in the npm config after asking for the user (so it only happens once) but other than that, looks good to me?

@jaredpalmer
Copy link
Owner

@audiolion I agree. npm-config set or something if IIRC

@audiolion
Copy link
Contributor Author

groovy, done.

image

.exec('git config --global user.name', { silent: true })
.stdout.trim();
if (author) {
setAuthorName(author);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

if they did not have an author with npm but do have a user name in git, we set their npm author name to it.

@jaredpalmer jaredpalmer merged commit 0f965a6 into jaredpalmer:master Oct 16, 2019
@audiolion audiolion deleted the feature/mit-license branch October 17, 2019 14:05
@agilgur5 agilgur5 changed the title feat: MIT License by default feat: MIT License by default and (attempt to) automatically set author name Mar 17, 2020
@agilgur5
Copy link
Collaborator

Hmmm... the set / get author name capabilities added here seem appropriate to split out into a separate package that other libraries could use too

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.

No license in templates, add ability to generate licenses
5 participants