diff --git a/app/data/organizations.js b/app/data/organizations.js index 70633d9..11799ab 100644 --- a/app/data/organizations.js +++ b/app/data/organizations.js @@ -1,3 +1,4 @@ +// This file is going to be replaced in production builds. export default { coala: { name: 'coala association e.V.', diff --git a/lib/.eslintrc.js b/lib/.eslintrc.js new file mode 100644 index 0000000..104718c --- /dev/null +++ b/lib/.eslintrc.js @@ -0,0 +1,6 @@ +module.exports = { + env: { + node: true, + browser: false + } +}; diff --git a/lib/gsoc-org/index.js b/lib/gsoc-org/index.js new file mode 100644 index 0000000..e1088cd --- /dev/null +++ b/lib/gsoc-org/index.js @@ -0,0 +1,28 @@ +/* eslint-env node */ +'use strict'; + +const path = require('path'); +const wikidataGsocOrg = require('./wikidataGsocOrg'); + +module.exports = { + name: 'gsoc-org', + preBuild: function () { + const fetch = this.project.require('node-fetch'); + const fs = this.project.require('fs-extra'); + if(this.app.env == 'production') { + const orgPath = path.join(this.app.project.root, 'app', + 'data', 'organizations.js'); + + return wikidataGsocOrg(fetch).then((data) =>{ + const orgDefinition = "export default " + JSON.stringify(data); + fs.writeFile(orgPath, orgDefinition); + }); + + } else { + return true; + } + }, + isDevelopingAddon() { + return true; + } +}; diff --git a/lib/gsoc-org/package-lock.json b/lib/gsoc-org/package-lock.json new file mode 100644 index 0000000..2f20e59 --- /dev/null +++ b/lib/gsoc-org/package-lock.json @@ -0,0 +1,83 @@ +{ + "name": "gsoc-org", + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "biskviit": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/biskviit/-/biskviit-1.0.1.tgz", + "integrity": "sha1-A3oM1LcbnjMf2QoRIt4X3EnkIKc=", + "requires": { + "psl": "^1.1.7" + } + }, + "encoding": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", + "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", + "requires": { + "iconv-lite": "~0.4.13" + } + }, + "fetch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/fetch/-/fetch-1.1.0.tgz", + "integrity": "sha1-CoJ58Gvjf58Ou1Z1YKMKSA2lmi4=", + "requires": { + "biskviit": "1.0.1", + "encoding": "0.1.12" + } + }, + "fs-extra": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-6.0.1.tgz", + "integrity": "sha512-GnyIkKhhzXZUWFCaJzvyDLEEgDkPfb4/TPvJCJVuS8MWZgoSsErf++QpiAlDnKFcqhRlm+tIOcencCjyJE6ZCA==", + "requires": { + "graceful-fs": "^4.1.2", + "jsonfile": "^4.0.0", + "universalify": "^0.1.0" + } + }, + "graceful-fs": { + "version": "4.1.11", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.1.11.tgz", + "integrity": "sha1-Dovf5NHduIVNZOBOp8AOKgJuVlg=" + }, + "iconv-lite": { + "version": "0.4.23", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.23.tgz", + "integrity": "sha512-neyTUVFtahjf0mB3dZT77u+8O0QB89jFdnBkd5P1JgYPbPaia3gXXOVL2fq8VyU2gMMD7SaN7QukTB/pmXYvDA==", + "requires": { + "safer-buffer": ">= 2.1.2 < 3" + } + }, + "jsonfile": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz", + "integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=", + "requires": { + "graceful-fs": "^4.1.6" + } + }, + "node-fetch": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.1.2.tgz", + "integrity": "sha1-q4hOjn5X44qUR1POxwb3iNF2i7U=" + }, + "psl": { + "version": "1.1.27", + "resolved": "https://registry.npmjs.org/psl/-/psl-1.1.27.tgz", + "integrity": "sha512-J8tJX5tAeEp9tQTI2w2aMZ6V1INuU4JmNaNPRuHAqjjVq3ZJ+jV3+tcT3ncgTnBxvwJy740IB/WZrxFus2VdMA==" + }, + "safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==" + }, + "universalify": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/universalify/-/universalify-0.1.1.tgz", + "integrity": "sha1-+nG63UQ3r0wUiEHjs7Fl+enlkLc=" + } + } +} diff --git a/lib/gsoc-org/package.json b/lib/gsoc-org/package.json new file mode 100644 index 0000000..0a1dee6 --- /dev/null +++ b/lib/gsoc-org/package.json @@ -0,0 +1,11 @@ +{ + "name": "gsoc-org", + "keywords": [ + "ember-addon" + ], + "dependencies": { + "fetch": "^1.1.0", + "fs-extra": "^6.0.1", + "node-fetch": "^2.1.2" + } +} diff --git a/lib/gsoc-org/wikidataGsocOrg.js b/lib/gsoc-org/wikidataGsocOrg.js new file mode 100644 index 0000000..b46fedc --- /dev/null +++ b/lib/gsoc-org/wikidataGsocOrg.js @@ -0,0 +1,35 @@ +const ENDPOINT = "https://query.wikidata.org/sparql?format=json&query="; +const QUERY = ` +SELECT DISTINCT ?orgLabel ?githubUsername +WHERE { + ?org wdt:P1344 wd:Q54276825. + ?org wdt:P2037 ?githubUsername + SERVICE wikibase:label { bd:serviceParam wikibase:language "id,en". } +} ORDER BY ?orgLabel +` + +module.exports = function(fetch) { + const toJson = (res) => { + return res.json(); + }; + const format = (json) => { + const mapToCompatibleOrg = (item) => { + return { + name: item['orgLabel']['value'], + trackers: [ + { + type: 'github', + identifier: item['githubUsername']['value'] + } + ] + } + } + const toObject = (object, item) => { + return Object.assign(object, { [item['name']]: item}); + } + return json['results']['bindings'] + .map(mapToCompatibleOrg) + .reduce(toObject, {}); + }; + return fetch(ENDPOINT + encodeURIComponent(QUERY)).then(toJson).then(format); +} \ No newline at end of file diff --git a/lib/gsoc-org/yarn.lock b/lib/gsoc-org/yarn.lock new file mode 100644 index 0000000..e9f13e8 --- /dev/null +++ b/lib/gsoc-org/yarn.lock @@ -0,0 +1,58 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +biskviit@1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/biskviit/-/biskviit-1.0.1.tgz#037a0cd4b71b9e331fd90a1122de17dc49e420a7" + dependencies: + psl "^1.1.7" + +encoding@0.1.12: + version "0.1.12" + resolved "https://registry.yarnpkg.com/encoding/-/encoding-0.1.12.tgz#538b66f3ee62cd1ab51ec323829d1f9480c74beb" + dependencies: + iconv-lite "~0.4.13" + +fetch@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/fetch/-/fetch-1.1.0.tgz#0a8279f06be37f9f0ebb567560a30a480da59a2e" + dependencies: + biskviit "1.0.1" + encoding "0.1.12" + +fs-extra@^6.0.1: + version "6.0.1" + resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-6.0.1.tgz#8abc128f7946e310135ddc93b98bddb410e7a34b" + dependencies: + graceful-fs "^4.1.2" + jsonfile "^4.0.0" + universalify "^0.1.0" + +graceful-fs@^4.1.2, graceful-fs@^4.1.6: + version "4.1.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" + +iconv-lite@~0.4.13: + version "0.4.23" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.23.tgz#297871f63be507adcfbfca715d0cd0eed84e9a63" + dependencies: + safer-buffer ">= 2.1.2 < 3" + +jsonfile@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" + optionalDependencies: + graceful-fs "^4.1.6" + +psl@^1.1.7: + version "1.1.27" + resolved "https://registry.yarnpkg.com/psl/-/psl-1.1.27.tgz#2b2c77019db86855170d903532400bf71ee085b6" + +"safer-buffer@>= 2.1.2 < 3": + version "2.1.2" + resolved "https://registry.yarnpkg.com/safer-buffer/-/safer-buffer-2.1.2.tgz#44fa161b0187b9549dd84bb91802f9bd8385cd6a" + +universalify@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/universalify/-/universalify-0.1.1.tgz#fa71badd4437af4c148841e3b3b165f9e9e590b7" diff --git a/package.json b/package.json index 76c2af9..098d61a 100644 --- a/package.json +++ b/package.json @@ -64,5 +64,10 @@ "linkifyjs": "^2.1.6", "minimatch": "^3.0.3", "moment": "^2.22.1" + }, + "ember-addon": { + "paths": [ + "lib/gsoc-org" + ] } }