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

Merge pre-existing package.json with file generated by Cloverfield #40

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

Conversation

halhenke
Copy link

Re issue #23

  • Tried to make it fit the pre-existing code structure as much as possible.
  • There is some "intelligence" to the merging from the package-merge package rather than a straight object merge - keywords field will be merged without duplicates etc. Might want to take a quick look at that package to see if its desired behaviour:

@ericelliott
Copy link
Contributor

Tests fail due to a missing package.

@halhenke
Copy link
Author

Yeah, seems the guy who maintains package-merge didnt declare lodash as a dependency.

Its passing on my machine seemingly because its a dependency of precommit-hook thats been spat into node_modules by npm 3 as far as i can tell.

Not sure what the best approach is - theres not a ton of functionality in that package but i thought it would be nice to have. Could fork it and make a PR and in the meantime use the fork or do a simpler
{ ...origPkg, ...genPkg} type merge?

@@ -54,6 +54,8 @@
"husky": "^0.10.1",
"isparta": "^3.0.4",
"nsp": "^1.1.0",
"package-merge": "^0.1.2",
"precommit-hook": "^3.0.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

oops, that was deleted previously

@nkbt
Copy link
Contributor

nkbt commented Nov 25, 2015

Hi, @halhenke can you please update PR so I can merge it? thanks 👌

@halhenke
Copy link
Author

OK for sure - sorry thought i already had - must be losing it... :-(

@@ -57,6 +58,7 @@
"husky": "^0.10.1",
"isparta": "^3.0.4",
"nsp": "^2.0.2",
"package-merge": "^0.1.2",
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this one is extra now.

Copy link
Author

Choose a reason for hiding this comment

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

Ah - i screwed up the rebase! will fix

@nkbt
Copy link
Contributor

nkbt commented Dec 14, 2015

Sorry, for the delay, @halhenke
I've just checked the new generation process. Package.json is merged respecting existing values. Other files not, though. Like README.md has new values, though package.json still has old ones.

I am not sure about intended behaviour here. I can suggest that when we merge package.json we can see which values have been changed and replace them accordingly in other files too. But not touching values that should not be changed.

Alternative (and much easier) solution could be - read package.json to get "suggested" values for the second run. Then either I just hit "Enter" and use those default ones - or enter new ones - does not matter. Replace all things as usual.

Honestly after playing with it a bit I'd rather go for the second solution.

Related to #44 by the way.

@ericelliott
Copy link
Contributor

👍

@halhenke
Copy link
Author

Hey sorry for delay in getting back to you Nik - busy few days,

Didn't realise we wanted to merge README also - was only thinking of package.json.

I also like the second idea - at least it makes people aware of whats happening. Will rework it and see if i can come up with something that deals with other files - think there could be some hard to deal with edge cases - but otherwise will go for the user prompt option.

Did you want me to try and work in suggestions from #44 also (i got the impression the other guy didnt want to)? Dont mind.

@nkbt
Copy link
Contributor

nkbt commented Dec 18, 2015

Awesome! #44 looks like duplicate to me then.

@halhenke
Copy link
Author

Cool! 👍

@ericelliott
Copy link
Contributor

What's going on with this?

@halhenke
Copy link
Author

halhenke commented Feb 9, 2016

Sorry, sort of got lost in Christmas stuff - have a couple of free days, will try to finish it off.

@ericelliott
Copy link
Contributor

Cool. Thanks!

…rom pre-existing package.json if available
- change big chain of if else statements into something a little more extensible
- move author/github stuff into separate file
@halhenke
Copy link
Author

OK this thing has been dragging on for a while (apologies) would love to wrap it up

Not entirely happy with what i've done (it feels a bit hack-ish) but wanted to check its the direction we wanted.

Anyway if a package.json file is found that exists:

  • grab author/email/github from package.json & use as defaults
  • read dependecies, devDependencies and scripts fields and add questions whether the user wants to merge them into the template package.json (could easily add other fields like peerDependencies if you like)

Feels a bit inelegant because its not using the same handlebars template/vars method to modify most fields - though we do now have author/email variables etc that will now be used in other templates also.

Could use more tests. Anyway just wanted to get any feedback/suggested changes when you guys have time.

@halhenke
Copy link
Author

halhenke commented Apr 2, 2016

Hey guys - just wanted to say - if this PR just missed the mark or isnt working out I wont be offended if you just want to kill it or anything. Its all pretty fuzzy for me at this point anyway.

@ericelliott
Copy link
Contributor

@nkbt Comments?

@nkbt
Copy link
Contributor

nkbt commented Apr 5, 2016

Wow, that looks cool, pretty much package.json-specific merging. I wish github sends emails on PR updated. I'll try it on couple of existing projects and let you know asap!

@ericelliott
Copy link
Contributor

@nkbt Any more thoughts?

const newPackagePath = path.join(process.cwd(), 'package.json');
const packageIndex = destinations.indexOf(newPackagePath);
const packageContents = JSON.parse(compiledFiles[packageIndex]);
const mergedPack = JSON.stringify(merge(packageContents, origPackage), null, 2);
Copy link
Contributor

Choose a reason for hiding this comment

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

I've tried it several times and tried to fix it too... No luck. With current implmentation no matter what I chose deps/devdeps/scrips are preserved and never updated. If I swap packageContents and origPackage - they always updated instead. Somehow those props from setPackageProps are just totally ignored =(

@halhenke
Copy link
Author

halhenke commented May 19, 2016

😞

I'll take a look at it either tonight or later this weekend.

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

3 participants