{"action":"created","comment":{"url":"https://api.github.com/repos/PolymerLabs/tedium/pulls/comments/51515126","id":51515126,"diff_hunk":"@@ -0,0 +1,163 @@\n+/**\n+ * @license\n+ * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.\n+ * This code may only be used under the BSD style license found at\n+ * http://polymer.github.io/LICENSE.txt\n+ * The complete set of authors may be found at\n+ * http://polymer.github.io/AUTHORS.txt\n+ * The complete set of contributors may be found at\n+ * http://polymer.github.io/CONTRIBUTORS.txt\n+ * Code distributed by Google as part of the polymer project is also\n+ * subject to an additional IP rights grant found at\n+ * http://polymer.github.io/PATENTS.txt\n+ */\n+\n+'use strict';\n+\n+import * as fs from 'fs';\n+import * as path from 'path';\n+\n+import {register} from '../cleanup-pass';\n+import {ElementRepo} from '../element-repo.ts';\n+import {existsSync, makeCommit} from './util';\n+\n+const dependencyMap = {\n+  \"webcomponentsjs\": \"webcomponents.js\",\n+  \"web-component-tester\": \"web-component-tester\",\n+  \"polymer\": \"@polymer/polymer\",\n+  \"chartjs\": \"chart.js\",\n+  \"hydrolysis\": \"hydrolysis\",\n+  \"dom5\": \"dom5\",\n+  \"page\": \"page\",\n+  \"prism\": \"prismjs-package\",\n+  \"d3\": \"d3\",\n+  \"marked\": \"marked\",\n+  \"web-animations-js\": \"web-animations-js\",\n+  \"sw-toolbox\": \"sw-toolbox\",\n+  \"fetch\": \"whatwg-fetch\",\n+  // TODO: need to tedium the following separately with --repo\n+  \"promise-polyfill\": \"@polymer/promise-polyfill\",\n+  \"app-layout\": \"@polymer/app-layout\",\n+};\n+\n+function getNpmName(name: string, version: string) {\n+  version = version.toLowerCase();\n+  if (dependencyMap[name]) {\n+    return dependencyMap[name];\n+  }\n+  if (version.startsWith('polymerelements/')) {\n+    return `@polymer/${name}`;\n+  }\n+}\n+\n+function getPackageVersion(name: string) {\n+  if (name === 'polymer') {\n+    return '1.2.5-npm-test.1';\n+  } else {\n+    return '0.0.1';\n+  }\n+}\n+\n+function getDependencyVersion(name: string, version: string) {\n+  version = version.toLowerCase();\n+  if (name === 'polymer') {\n+    return '1.2.5-npm-test.1';\n+  } else if (version.startsWith('polymerelements/')) {\n+    return '^0.0.1';\n+  }\n+  return version.substring(version.indexOf('#') + 1);\n+}\n+\n+/**\n+ * Cleans up a number of common bower problems, like no \"main\" attribute,\n+ * \"main\" being an array rather than a string, etc.\n+ */\n+async function cleanupNpm(element: ElementRepo): Promise<void> {\n+  const writeJson = (filePath: string, config: Object) => {\n+    let fullPath = path.join(element.dir, filePath);\n+    fs.writeFileSync(fullPath, JSON.stringify(config, null, 2) + '\\n', 'utf8');\n+  };\n+\n+  const readJson = (filePath: string) => {\n+    let fullPath = path.join(element.dir, filePath);\n+    if (fs.existsSync(fullPath)) {\n+      return JSON.parse(fs.readFileSync(fullPath, 'utf8'));\n+    }\n+    return {};\n+  };\n+\n+  let bowerConfig: any = readJson('bower.json');\n+  let npmConfig: any = readJson('package.json');\n+\n+  if (!bowerConfig) {\n+    throw new Error('bower.json not found');\n+  }\n+\n+  if (bowerConfig['name'] !== 'polymer' && npmConfig['name']) {\n+    console.warn(`\\nunexpected existing package.json for ${element.repo}`);\n+    // throw new Error(`unexpected existing package.json for ${element.repo}`);\n+  }\n+\n+  const copyProperty = (name: string, bowerName?: string) =>\n+      npmConfig[name] = bowerConfig[bowerName || name] || npmConfig[name];\n+\n+  npmConfig['name'] = `@polymer/${bowerConfig['name']}`;\n+  npmConfig['version'] = getPackageVersion(bowerConfig['name']);\n+\n+  // properties that can be directly copied\n+  ['description', 'repository', 'ignore', 'keywords']\n+      .forEach((s, _) => copyProperty(s));\n+\n+  // authors => contributors\n+  // https://docs.npmjs.com/files/package.json#people-fields-author-contributors\n+  copyProperty('contributors', 'authors');\n+\n+  // make it public\n+  delete npmConfig['private'];\n+\n+  // https://docs.npmjs.com/files/package.json#license\n+  npmConfig['license'] = \"BSD-3-Clause\";\n+\n+  let npmDependencies = npmConfig['dependencies'] =\n+      npmConfig['dependencies'] || {};\n+  let bowerDependencies = bowerConfig['dependencies'] || {};\n+  let npmDevDependencies = npmConfig['devDependencies'] =\n+      npmConfig['devDependencies'] || {};\n+  let bowerDevDependencies = bowerConfig['devDependencies'] =","path":"cleanup-passes/npm.ts","position":126,"original_position":126,"commit_id":"45ab3d4ecac9011ba28343e530c7144a6b44aab8","original_commit_id":"45ab3d4ecac9011ba28343e530c7144a6b44aab8","user":{"login":"justinfagnani","id":522948,"avatar_url":"https://avatars.githubusercontent.com/u/522948?v=3","gravatar_id":"","url":"https://api.github.com/users/justinfagnani","html_url":"https://github.com/justinfagnani","followers_url":"https://api.github.com/users/justinfagnani/followers","following_url":"https://api.github.com/users/justinfagnani/following{/other_user}","gists_url":"https://api.github.com/users/justinfagnani/gists{/gist_id}","starred_url":"https://api.github.com/users/justinfagnani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinfagnani/subscriptions","organizations_url":"https://api.github.com/users/justinfagnani/orgs","repos_url":"https://api.github.com/users/justinfagnani/repos","events_url":"https://api.github.com/users/justinfagnani/events{/privacy}","received_events_url":"https://api.github.com/users/justinfagnani/received_events","type":"User","site_admin":false},"body":"done","created_at":"2016-02-02T02:35:01Z","updated_at":"2016-02-02T02:35:01Z","html_url":"https://github.com/PolymerLabs/tedium/pull/29#discussion_r51515126","pull_request_url":"https://api.github.com/repos/PolymerLabs/tedium/pulls/29","_links":{"self":{"href":"https://api.github.com/repos/PolymerLabs/tedium/pulls/comments/51515126"},"html":{"href":"https://github.com/PolymerLabs/tedium/pull/29#discussion_r51515126"},"pull_request":{"href":"https://api.github.com/repos/PolymerLabs/tedium/pulls/29"}}},"pull_request":{"url":"https://api.github.com/repos/PolymerLabs/tedium/pulls/29","id":57931456,"html_url":"https://github.com/PolymerLabs/tedium/pull/29","diff_url":"https://github.com/PolymerLabs/tedium/pull/29.diff","patch_url":"https://github.com/PolymerLabs/tedium/pull/29.patch","issue_url":"https://api.github.com/repos/PolymerLabs/tedium/issues/29","number":29,"state":"open","locked":false,"title":"Add npm/package.json pass","user":{"login":"justinfagnani","id":522948,"avatar_url":"https://avatars.githubusercontent.com/u/522948?v=3","gravatar_id":"","url":"https://api.github.com/users/justinfagnani","html_url":"https://github.com/justinfagnani","followers_url":"https://api.github.com/users/justinfagnani/followers","following_url":"https://api.github.com/users/justinfagnani/following{/other_user}","gists_url":"https://api.github.com/users/justinfagnani/gists{/gist_id}","starred_url":"https://api.github.com/users/justinfagnani/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justinfagnani/subscriptions","organizations_url":"https://api.github.com/users/justinfagnani/orgs","repos_url":"https://api.github.com/users/justinfagnani/repos","events_url":"https://api.github.com/users/justinfagnani/events{/privacy}","received_events_url":"https://api.github.com/users/justinfagnani/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-02-02T02:17:26Z","updated_at":"2016-02-02T02:35:01Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e1acb7fb3948fd4440b0832279d05d516c7c73ad","assignee":{"login":"rictic","id":1659,"avatar_url":"https://avatars.githubusercontent.com/u/1659?v=3","gravatar_id":"","url":"https://api.github.com/users/rictic","html_url":"https://github.com/rictic","followers_url":"https://api.github.com/users/rictic/followers","following_url":"https://api.github.com/users/rictic/following{/other_user}","gists_url":"https://api.github.com/users/rictic/gists{/gist_id}","starred_url":"https://api.github.com/users/rictic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rictic/subscriptions","organizations_url":"https://api.github.com/users/rictic/orgs","repos_url":"https://api.github.com/users/rictic/repos","events_url":"https://api.github.com/users/rictic/events{/privacy}","received_events_url":"https://api.github.com/users/rictic/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/PolymerLabs/tedium/pulls/29/commits","review_comments_url":"https://api.github.com/repos/PolymerLabs/tedium/pulls/29/comments","review_comment_url":"https://api.github.com/repos/PolymerLabs/tedium/pulls/comments{/number}","comments_url":"https://api.github.com/repos/PolymerLabs/tedium/issues/29/comments","statuses_url":"https://api.github.com/repos/PolymerLabs/tedium/statuses/45ab3d4ecac9011ba28343e530c7144a6b44aab8","head":{"label":"PolymerLabs:npm","ref":"npm","sha":"45ab3d4ecac9011ba28343e530c7144a6b44aab8","user":{"login":"PolymerLabs","id":5912903,"avatar_url":"https://avatars.githubusercontent.com/u/5912903?v=3","gravatar_id":"","url":"https://api.github.com/users/PolymerLabs","html_url":"https://github.com/PolymerLabs","followers_url":"https://api.github.com/users/PolymerLabs/followers","following_url":"https://api.github.com/users/PolymerLabs/following{/other_user}","gists_url":"https://api.github.com/users/PolymerLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/PolymerLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PolymerLabs/subscriptions","organizations_url":"https://api.github.com/users/PolymerLabs/orgs","repos_url":"https://api.github.com/users/PolymerLabs/repos","events_url":"https://api.github.com/users/PolymerLabs/events{/privacy}","received_events_url":"https://api.github.com/users/PolymerLabs/received_events","type":"Organization","site_admin":false},"repo":{"id":45142797,"name":"tedium","full_name":"PolymerLabs/tedium","owner":{"login":"PolymerLabs","id":5912903,"avatar_url":"https://avatars.githubusercontent.com/u/5912903?v=3","gravatar_id":"","url":"https://api.github.com/users/PolymerLabs","html_url":"https://github.com/PolymerLabs","followers_url":"https://api.github.com/users/PolymerLabs/followers","following_url":"https://api.github.com/users/PolymerLabs/following{/other_user}","gists_url":"https://api.github.com/users/PolymerLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/PolymerLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PolymerLabs/subscriptions","organizations_url":"https://api.github.com/users/PolymerLabs/orgs","repos_url":"https://api.github.com/users/PolymerLabs/repos","events_url":"https://api.github.com/users/PolymerLabs/events{/privacy}","received_events_url":"https://api.github.com/users/PolymerLabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PolymerLabs/tedium","description":"A bot for doing mass changes to github repos for the Polymer team","fork":false,"url":"https://api.github.com/repos/PolymerLabs/tedium","forks_url":"https://api.github.com/repos/PolymerLabs/tedium/forks","keys_url":"https://api.github.com/repos/PolymerLabs/tedium/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PolymerLabs/tedium/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PolymerLabs/tedium/teams","hooks_url":"https://api.github.com/repos/PolymerLabs/tedium/hooks","issue_events_url":"https://api.github.com/repos/PolymerLabs/tedium/issues/events{/number}","events_url":"https://api.github.com/repos/PolymerLabs/tedium/events","assignees_url":"https://api.github.com/repos/PolymerLabs/tedium/assignees{/user}","branches_url":"https://api.github.com/repos/PolymerLabs/tedium/branches{/branch}","tags_url":"https://api.github.com/repos/PolymerLabs/tedium/tags","blobs_url":"https://api.github.com/repos/PolymerLabs/tedium/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PolymerLabs/tedium/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PolymerLabs/tedium/git/refs{/sha}","trees_url":"https://api.github.com/repos/PolymerLabs/tedium/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PolymerLabs/tedium/statuses/{sha}","languages_url":"https://api.github.com/repos/PolymerLabs/tedium/languages","stargazers_url":"https://api.github.com/repos/PolymerLabs/tedium/stargazers","contributors_url":"https://api.github.com/repos/PolymerLabs/tedium/contributors","subscribers_url":"https://api.github.com/repos/PolymerLabs/tedium/subscribers","subscription_url":"https://api.github.com/repos/PolymerLabs/tedium/subscription","commits_url":"https://api.github.com/repos/PolymerLabs/tedium/commits{/sha}","git_commits_url":"https://api.github.com/repos/PolymerLabs/tedium/git/commits{/sha}","comments_url":"https://api.github.com/repos/PolymerLabs/tedium/comments{/number}","issue_comment_url":"https://api.github.com/repos/PolymerLabs/tedium/issues/comments{/number}","contents_url":"https://api.github.com/repos/PolymerLabs/tedium/contents/{+path}","compare_url":"https://api.github.com/repos/PolymerLabs/tedium/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PolymerLabs/tedium/merges","archive_url":"https://api.github.com/repos/PolymerLabs/tedium/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PolymerLabs/tedium/downloads","issues_url":"https://api.github.com/repos/PolymerLabs/tedium/issues{/number}","pulls_url":"https://api.github.com/repos/PolymerLabs/tedium/pulls{/number}","milestones_url":"https://api.github.com/repos/PolymerLabs/tedium/milestones{/number}","notifications_url":"https://api.github.com/repos/PolymerLabs/tedium/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PolymerLabs/tedium/labels{/name}","releases_url":"https://api.github.com/repos/PolymerLabs/tedium/releases{/id}","deployments_url":"https://api.github.com/repos/PolymerLabs/tedium/deployments","created_at":"2015-10-28T21:25:30Z","updated_at":"2016-01-11T22:33:10Z","pushed_at":"2016-02-02T02:17:27Z","git_url":"git://github.com/PolymerLabs/tedium.git","ssh_url":"git@github.com:PolymerLabs/tedium.git","clone_url":"https://github.com/PolymerLabs/tedium.git","svn_url":"https://github.com/PolymerLabs/tedium","homepage":null,"size":106,"stargazers_count":7,"watchers_count":7,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":6,"forks":1,"open_issues":6,"watchers":7,"default_branch":"master"}},"base":{"label":"PolymerLabs:master","ref":"master","sha":"58374841aeb5f5ca0584b163fa299049615a1dfd","user":{"login":"PolymerLabs","id":5912903,"avatar_url":"https://avatars.githubusercontent.com/u/5912903?v=3","gravatar_id":"","url":"https://api.github.com/users/PolymerLabs","html_url":"https://github.com/PolymerLabs","followers_url":"https://api.github.com/users/PolymerLabs/followers","following_url":"https://api.github.com/users/PolymerLabs/following{/other_user}","gists_url":"https://api.github.com/users/PolymerLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/PolymerLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PolymerLabs/subscriptions","organizations_url":"https://api.github.com/users/PolymerLabs/orgs","repos_url":"https://api.github.com/users/PolymerLabs/repos","events_url":"https://api.github.com/users/PolymerLabs/events{/privacy}","received_events_url":"https://api.github.com/users/PolymerLabs/received_events","type":"Organization","site_admin":false},"repo":{"id":45142797,"name":"tedium","full_name":"PolymerLabs/tedium","owner":{"login":"PolymerLabs","id":5912903,"avatar_url":"https://avatars.githubusercontent.com/u/5912903?v=3","gravatar_id":"","url":"https://api.github.com/users/PolymerLabs","html_url":"https://github.com/PolymerLabs","followers_url":"https://api.github.com/users/PolymerLabs/followers","following_url":"https://api.github.com/users/PolymerLabs/following{/other_user}","gists_url":"https://api.github.com/users/PolymerLabs/gists{/gist_id}","starred_url":"https://api.github.com/users/PolymerLabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/PolymerLabs/subscriptions","organizations_url":"https://api.github.com/users/PolymerLabs/orgs","repos_url":"https://api.github.com/users/PolymerLabs/repos","events_url":"https://api.github.com/users/PolymerLabs/events{/privacy}","received_events_url":"https://api.github.com/users/PolymerLabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/PolymerLabs/tedium","description":"A bot for doing mass changes to github repos for the Polymer team","fork":false,"url":"https://api.github.com/repos/PolymerLabs/tedium","forks_url":"https://api.github.com/repos/PolymerLabs/tedium/forks","keys_url":"https://api.github.com/repos/PolymerLabs/tedium/keys{/key_id}","collaborators_url":"https://api.github.com/repos/PolymerLabs/tedium/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/PolymerLabs/tedium/teams","hooks_url":"https://api.github.com/repos/PolymerLabs/tedium/hooks","issue_events_url":"https://api.github.com/repos/PolymerLabs/tedium/issues/events{/number}","events_url":"https://api.github.com/repos/PolymerLabs/tedium/events","assignees_url":"https://api.github.com/repos/PolymerLabs/tedium/assignees{/user}","branches_url":"https://api.github.com/repos/PolymerLabs/tedium/branches{/branch}","tags_url":"https://api.github.com/repos/PolymerLabs/tedium/tags","blobs_url":"https://api.github.com/repos/PolymerLabs/tedium/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/PolymerLabs/tedium/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/PolymerLabs/tedium/git/refs{/sha}","trees_url":"https://api.github.com/repos/PolymerLabs/tedium/git/trees{/sha}","statuses_url":"https://api.github.com/repos/PolymerLabs/tedium/statuses/{sha}","languages_url":"https://api.github.com/repos/PolymerLabs/tedium/languages","stargazers_url":"https://api.github.com/repos/PolymerLabs/tedium/stargazers","contributors_url":"https://api.github.com/repos/PolymerLabs/tedium/contributors","subscribers_url":"https://api.github.com/repos/PolymerLabs/tedium/subscribers","subscription_url":"https://api.github.com/repos/PolymerLabs/tedium/subscription","commits_url":"https://api.github.com/repos/PolymerLabs/tedium/commits{/sha}","git_commits_url":"https://api.github.com/repos/PolymerLabs/tedium/git/commits{/sha}","comments_url":"https://api.github.com/repos/PolymerLabs/tedium/comments{/number}","issue_comment_url":"https://api.github.com/repos/PolymerLabs/tedium/issues/comments{/number}","contents_url":"https://api.github.com/repos/PolymerLabs/tedium/contents/{+path}","compare_url":"https://api.github.com/repos/PolymerLabs/tedium/compare/{base}...{head}","merges_url":"https://api.github.com/repos/PolymerLabs/tedium/merges","archive_url":"https://api.github.com/repos/PolymerLabs/tedium/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/PolymerLabs/tedium/downloads","issues_url":"https://api.github.com/repos/PolymerLabs/tedium/issues{/number}","pulls_url":"https://api.github.com/repos/PolymerLabs/tedium/pulls{/number}","milestones_url":"https://api.github.com/repos/PolymerLabs/tedium/milestones{/number}","notifications_url":"https://api.github.com/repos/PolymerLabs/tedium/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/PolymerLabs/tedium/labels{/name}","releases_url":"https://api.github.com/repos/PolymerLabs/tedium/releases{/id}","deployments_url":"https://api.github.com/repos/PolymerLabs/tedium/deployments","created_at":"2015-10-28T21:25:30Z","updated_at":"2016-01-11T22:33:10Z","pushed_at":"2016-02-02T02:17:27Z","git_url":"git://github.com/PolymerLabs/tedium.git","ssh_url":"git@github.com:PolymerLabs/tedium.git","clone_url":"https://github.com/PolymerLabs/tedium.git","svn_url":"https://github.com/PolymerLabs/tedium","homepage":null,"size":106,"stargazers_count":7,"watchers_count":7,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":6,"forks":1,"open_issues":6,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/PolymerLabs/tedium/pulls/29"},"html":{"href":"https://github.com/PolymerLabs/tedium/pull/29"},"issue":{"href":"https://api.github.com/repos/PolymerLabs/tedium/issues/29"},"comments":{"href":"https://api.github.com/repos/PolymerLabs/tedium/issues/29/comments"},"review_comments":{"href":"https://api.github.com/repos/PolymerLabs/tedium/pulls/29/comments"},"review_comment":{"href":"https://api.github.com/repos/PolymerLabs/tedium/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/PolymerLabs/tedium/pulls/29/commits"},"statuses":{"href":"https://api.github.com/repos/PolymerLabs/tedium/statuses/45ab3d4ecac9011ba28343e530c7144a6b44aab8"}}}}