{"action":"created","comment":{"url":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/comments/46033165","id":46033165,"diff_hunk":"@@ -0,0 +1,24 @@\n+import merge from 'lodash.merge';\n+import fs from 'fs';\n+import path from 'path';\n+\n+export const getPackage = () => {\n+  let origPackage;\n+  try {\n+    origPackage = JSON.parse(fs.readFileSync(path.join(process.cwd(), 'package.json'), 'utf-8'));\n+  } catch (e) {\n+    origPackage = false;\n+  }\n+  return origPackage;\n+};\n+\n+export const mergePackages = (origPackage, destinations) => compiledFiles => {\n+  if (origPackage) {\n+    const newPackagePath = path.join(process.cwd(), 'package.json');\n+    const packageIndex = destinations.indexOf(newPackagePath);\n+    const packageContents = JSON.parse(compiledFiles[packageIndex]);\n+    const mergedPack = JSON.stringify(merge(origPackage, packageContents), null, 2);","path":"lib/mergePack.js","position":20,"original_position":20,"commit_id":"c1d4b76070b9cfa7f537df6c90e1b9ce4dc3c16b","original_commit_id":"c1d4b76070b9cfa7f537df6c90e1b9ce4dc3c16b","user":{"login":"nkbt","id":175264,"avatar_url":"https://avatars.githubusercontent.com/u/175264?v=3","gravatar_id":"","url":"https://api.github.com/users/nkbt","html_url":"https://github.com/nkbt","followers_url":"https://api.github.com/users/nkbt/followers","following_url":"https://api.github.com/users/nkbt/following{/other_user}","gists_url":"https://api.github.com/users/nkbt/gists{/gist_id}","starred_url":"https://api.github.com/users/nkbt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nkbt/subscriptions","organizations_url":"https://api.github.com/users/nkbt/orgs","repos_url":"https://api.github.com/users/nkbt/repos","events_url":"https://api.github.com/users/nkbt/events{/privacy}","received_events_url":"https://api.github.com/users/nkbt/received_events","type":"User","site_admin":false},"body":"I am not quite sure but I reckon it should be the other way around. package from template should not override fields in already existing package. Only add missing ones.\r\n\r\nI mean if I used this template and later changed how my lib is tested, I'd prefer to keep it as it is. But if there are new scripts added, it would be nice to add them to my lib too.\r\n\r\n@ericelliott  what is your idea on merging package.json?","created_at":"2015-11-27T10:12:05Z","updated_at":"2015-11-27T10:12:05Z","html_url":"https://github.com/cloverfield-tools/cf-package/pull/40#discussion_r46033165","pull_request_url":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/40","_links":{"self":{"href":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/comments/46033165"},"html":{"href":"https://github.com/cloverfield-tools/cf-package/pull/40#discussion_r46033165"},"pull_request":{"href":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/40"}}},"pull_request":{"url":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/40","id":48609496,"html_url":"https://github.com/cloverfield-tools/cf-package/pull/40","diff_url":"https://github.com/cloverfield-tools/cf-package/pull/40.diff","patch_url":"https://github.com/cloverfield-tools/cf-package/pull/40.patch","issue_url":"https://api.github.com/repos/cloverfield-tools/cf-package/issues/40","number":40,"state":"open","locked":false,"title":"Merge pre-existing package.json with file generated by Cloverfield","user":{"login":"halhenke","id":1448377,"avatar_url":"https://avatars.githubusercontent.com/u/1448377?v=3","gravatar_id":"","url":"https://api.github.com/users/halhenke","html_url":"https://github.com/halhenke","followers_url":"https://api.github.com/users/halhenke/followers","following_url":"https://api.github.com/users/halhenke/following{/other_user}","gists_url":"https://api.github.com/users/halhenke/gists{/gist_id}","starred_url":"https://api.github.com/users/halhenke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halhenke/subscriptions","organizations_url":"https://api.github.com/users/halhenke/orgs","repos_url":"https://api.github.com/users/halhenke/repos","events_url":"https://api.github.com/users/halhenke/events{/privacy}","received_events_url":"https://api.github.com/users/halhenke/received_events","type":"User","site_admin":false},"body":"Re issue #23 \r\n\r\n- Tried to make it fit the pre-existing code structure as much as possible.\r\n- 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: \r\n  - https://github.com/izaakschroeder/package-merge/blob/master/lib/merge.js","created_at":"2015-10-23T17:52:02Z","updated_at":"2015-11-27T10:12:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"d2cffb05b2aaad1f48230bdb3f7d2f842403e934","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/40/commits","review_comments_url":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/40/comments","review_comment_url":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/comments{/number}","comments_url":"https://api.github.com/repos/cloverfield-tools/cf-package/issues/40/comments","statuses_url":"https://api.github.com/repos/cloverfield-tools/cf-package/statuses/c1d4b76070b9cfa7f537df6c90e1b9ce4dc3c16b","head":{"label":"halhenke:feaure/package-check","ref":"feaure/package-check","sha":"c1d4b76070b9cfa7f537df6c90e1b9ce4dc3c16b","user":{"login":"halhenke","id":1448377,"avatar_url":"https://avatars.githubusercontent.com/u/1448377?v=3","gravatar_id":"","url":"https://api.github.com/users/halhenke","html_url":"https://github.com/halhenke","followers_url":"https://api.github.com/users/halhenke/followers","following_url":"https://api.github.com/users/halhenke/following{/other_user}","gists_url":"https://api.github.com/users/halhenke/gists{/gist_id}","starred_url":"https://api.github.com/users/halhenke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halhenke/subscriptions","organizations_url":"https://api.github.com/users/halhenke/orgs","repos_url":"https://api.github.com/users/halhenke/repos","events_url":"https://api.github.com/users/halhenke/events{/privacy}","received_events_url":"https://api.github.com/users/halhenke/received_events","type":"User","site_admin":false},"repo":{"id":42948510,"name":"cf-package","full_name":"halhenke/cf-package","owner":{"login":"halhenke","id":1448377,"avatar_url":"https://avatars.githubusercontent.com/u/1448377?v=3","gravatar_id":"","url":"https://api.github.com/users/halhenke","html_url":"https://github.com/halhenke","followers_url":"https://api.github.com/users/halhenke/followers","following_url":"https://api.github.com/users/halhenke/following{/other_user}","gists_url":"https://api.github.com/users/halhenke/gists{/gist_id}","starred_url":"https://api.github.com/users/halhenke/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/halhenke/subscriptions","organizations_url":"https://api.github.com/users/halhenke/orgs","repos_url":"https://api.github.com/users/halhenke/repos","events_url":"https://api.github.com/users/halhenke/events{/privacy}","received_events_url":"https://api.github.com/users/halhenke/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/halhenke/cf-package","description":"Cloverfield Package Scaffold","fork":true,"url":"https://api.github.com/repos/halhenke/cf-package","forks_url":"https://api.github.com/repos/halhenke/cf-package/forks","keys_url":"https://api.github.com/repos/halhenke/cf-package/keys{/key_id}","collaborators_url":"https://api.github.com/repos/halhenke/cf-package/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/halhenke/cf-package/teams","hooks_url":"https://api.github.com/repos/halhenke/cf-package/hooks","issue_events_url":"https://api.github.com/repos/halhenke/cf-package/issues/events{/number}","events_url":"https://api.github.com/repos/halhenke/cf-package/events","assignees_url":"https://api.github.com/repos/halhenke/cf-package/assignees{/user}","branches_url":"https://api.github.com/repos/halhenke/cf-package/branches{/branch}","tags_url":"https://api.github.com/repos/halhenke/cf-package/tags","blobs_url":"https://api.github.com/repos/halhenke/cf-package/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/halhenke/cf-package/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/halhenke/cf-package/git/refs{/sha}","trees_url":"https://api.github.com/repos/halhenke/cf-package/git/trees{/sha}","statuses_url":"https://api.github.com/repos/halhenke/cf-package/statuses/{sha}","languages_url":"https://api.github.com/repos/halhenke/cf-package/languages","stargazers_url":"https://api.github.com/repos/halhenke/cf-package/stargazers","contributors_url":"https://api.github.com/repos/halhenke/cf-package/contributors","subscribers_url":"https://api.github.com/repos/halhenke/cf-package/subscribers","subscription_url":"https://api.github.com/repos/halhenke/cf-package/subscription","commits_url":"https://api.github.com/repos/halhenke/cf-package/commits{/sha}","git_commits_url":"https://api.github.com/repos/halhenke/cf-package/git/commits{/sha}","comments_url":"https://api.github.com/repos/halhenke/cf-package/comments{/number}","issue_comment_url":"https://api.github.com/repos/halhenke/cf-package/issues/comments{/number}","contents_url":"https://api.github.com/repos/halhenke/cf-package/contents/{+path}","compare_url":"https://api.github.com/repos/halhenke/cf-package/compare/{base}...{head}","merges_url":"https://api.github.com/repos/halhenke/cf-package/merges","archive_url":"https://api.github.com/repos/halhenke/cf-package/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/halhenke/cf-package/downloads","issues_url":"https://api.github.com/repos/halhenke/cf-package/issues{/number}","pulls_url":"https://api.github.com/repos/halhenke/cf-package/pulls{/number}","milestones_url":"https://api.github.com/repos/halhenke/cf-package/milestones{/number}","notifications_url":"https://api.github.com/repos/halhenke/cf-package/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/halhenke/cf-package/labels{/name}","releases_url":"https://api.github.com/repos/halhenke/cf-package/releases{/id}","created_at":"2015-09-22T17:10:58Z","updated_at":"2015-09-22T17:10:59Z","pushed_at":"2015-11-26T03:00:07Z","git_url":"git://github.com/halhenke/cf-package.git","ssh_url":"git@github.com:halhenke/cf-package.git","clone_url":"https://github.com/halhenke/cf-package.git","svn_url":"https://github.com/halhenke/cf-package","homepage":null,"size":48,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"cloverfield-tools:master","ref":"master","sha":"8bb6699585c6b5d878f685bebfa64fb403263720","user":{"login":"cloverfield-tools","id":13182545,"avatar_url":"https://avatars.githubusercontent.com/u/13182545?v=3","gravatar_id":"","url":"https://api.github.com/users/cloverfield-tools","html_url":"https://github.com/cloverfield-tools","followers_url":"https://api.github.com/users/cloverfield-tools/followers","following_url":"https://api.github.com/users/cloverfield-tools/following{/other_user}","gists_url":"https://api.github.com/users/cloverfield-tools/gists{/gist_id}","starred_url":"https://api.github.com/users/cloverfield-tools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloverfield-tools/subscriptions","organizations_url":"https://api.github.com/users/cloverfield-tools/orgs","repos_url":"https://api.github.com/users/cloverfield-tools/repos","events_url":"https://api.github.com/users/cloverfield-tools/events{/privacy}","received_events_url":"https://api.github.com/users/cloverfield-tools/received_events","type":"Organization","site_admin":false},"repo":{"id":38615463,"name":"cf-package","full_name":"cloverfield-tools/cf-package","owner":{"login":"cloverfield-tools","id":13182545,"avatar_url":"https://avatars.githubusercontent.com/u/13182545?v=3","gravatar_id":"","url":"https://api.github.com/users/cloverfield-tools","html_url":"https://github.com/cloverfield-tools","followers_url":"https://api.github.com/users/cloverfield-tools/followers","following_url":"https://api.github.com/users/cloverfield-tools/following{/other_user}","gists_url":"https://api.github.com/users/cloverfield-tools/gists{/gist_id}","starred_url":"https://api.github.com/users/cloverfield-tools/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cloverfield-tools/subscriptions","organizations_url":"https://api.github.com/users/cloverfield-tools/orgs","repos_url":"https://api.github.com/users/cloverfield-tools/repos","events_url":"https://api.github.com/users/cloverfield-tools/events{/privacy}","received_events_url":"https://api.github.com/users/cloverfield-tools/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/cloverfield-tools/cf-package","description":"Cloverfield Package Scaffold","fork":false,"url":"https://api.github.com/repos/cloverfield-tools/cf-package","forks_url":"https://api.github.com/repos/cloverfield-tools/cf-package/forks","keys_url":"https://api.github.com/repos/cloverfield-tools/cf-package/keys{/key_id}","collaborators_url":"https://api.github.com/repos/cloverfield-tools/cf-package/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/cloverfield-tools/cf-package/teams","hooks_url":"https://api.github.com/repos/cloverfield-tools/cf-package/hooks","issue_events_url":"https://api.github.com/repos/cloverfield-tools/cf-package/issues/events{/number}","events_url":"https://api.github.com/repos/cloverfield-tools/cf-package/events","assignees_url":"https://api.github.com/repos/cloverfield-tools/cf-package/assignees{/user}","branches_url":"https://api.github.com/repos/cloverfield-tools/cf-package/branches{/branch}","tags_url":"https://api.github.com/repos/cloverfield-tools/cf-package/tags","blobs_url":"https://api.github.com/repos/cloverfield-tools/cf-package/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/cloverfield-tools/cf-package/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/cloverfield-tools/cf-package/git/refs{/sha}","trees_url":"https://api.github.com/repos/cloverfield-tools/cf-package/git/trees{/sha}","statuses_url":"https://api.github.com/repos/cloverfield-tools/cf-package/statuses/{sha}","languages_url":"https://api.github.com/repos/cloverfield-tools/cf-package/languages","stargazers_url":"https://api.github.com/repos/cloverfield-tools/cf-package/stargazers","contributors_url":"https://api.github.com/repos/cloverfield-tools/cf-package/contributors","subscribers_url":"https://api.github.com/repos/cloverfield-tools/cf-package/subscribers","subscription_url":"https://api.github.com/repos/cloverfield-tools/cf-package/subscription","commits_url":"https://api.github.com/repos/cloverfield-tools/cf-package/commits{/sha}","git_commits_url":"https://api.github.com/repos/cloverfield-tools/cf-package/git/commits{/sha}","comments_url":"https://api.github.com/repos/cloverfield-tools/cf-package/comments{/number}","issue_comment_url":"https://api.github.com/repos/cloverfield-tools/cf-package/issues/comments{/number}","contents_url":"https://api.github.com/repos/cloverfield-tools/cf-package/contents/{+path}","compare_url":"https://api.github.com/repos/cloverfield-tools/cf-package/compare/{base}...{head}","merges_url":"https://api.github.com/repos/cloverfield-tools/cf-package/merges","archive_url":"https://api.github.com/repos/cloverfield-tools/cf-package/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/cloverfield-tools/cf-package/downloads","issues_url":"https://api.github.com/repos/cloverfield-tools/cf-package/issues{/number}","pulls_url":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls{/number}","milestones_url":"https://api.github.com/repos/cloverfield-tools/cf-package/milestones{/number}","notifications_url":"https://api.github.com/repos/cloverfield-tools/cf-package/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/cloverfield-tools/cf-package/labels{/name}","releases_url":"https://api.github.com/repos/cloverfield-tools/cf-package/releases{/id}","created_at":"2015-07-06T11:45:50Z","updated_at":"2015-11-26T08:20:32Z","pushed_at":"2015-11-26T03:00:07Z","git_url":"git://github.com/cloverfield-tools/cf-package.git","ssh_url":"git@github.com:cloverfield-tools/cf-package.git","clone_url":"https://github.com/cloverfield-tools/cf-package.git","svn_url":"https://github.com/cloverfield-tools/cf-package","homepage":null,"size":48,"stargazers_count":42,"watchers_count":42,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":12,"mirror_url":null,"open_issues_count":6,"forks":12,"open_issues":6,"watchers":42,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/40"},"html":{"href":"https://github.com/cloverfield-tools/cf-package/pull/40"},"issue":{"href":"https://api.github.com/repos/cloverfield-tools/cf-package/issues/40"},"comments":{"href":"https://api.github.com/repos/cloverfield-tools/cf-package/issues/40/comments"},"review_comments":{"href":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/40/comments"},"review_comment":{"href":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/cloverfield-tools/cf-package/pulls/40/commits"},"statuses":{"href":"https://api.github.com/repos/cloverfield-tools/cf-package/statuses/c1d4b76070b9cfa7f537df6c90e1b9ce4dc3c16b"}}}}