Ein Projekt das es ermöglicht Beerpong über das Internet von zwei unabhängigen positionen aus zu spielen. Entstehung im Rahmen einer Praktikumsaufgabe im Fach Interaktion.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

release.js 2.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. 'use strict';
  2. var GITHUB_CLIENT_ID = '2031dbe958e741775201';
  3. var GITHUB_CLIENT_SECRET = 'd509a1e5e89248ce5d4211cb06995edcd979667d';
  4. var SCOPE = 'public_repo';
  5. var fs = require('fs');
  6. var qs = require('querystring');
  7. var crypto = require('crypto');
  8. var express = require('express');
  9. var opener = require('opener');
  10. var github = require('github-basic');
  11. var pr = require('pull-request');
  12. var readdirp = require('lsr').sync;
  13. // todo: check that the version is a new un-released version
  14. // todo: check the user has commit access to the github repo
  15. // todo: check the user is an owner in npm
  16. // todo: check History.md has been updated
  17. var version = require('./package.json').version;
  18. var compiledWebsite = require('./docs/stop.js');
  19. function getToken(gotToken) {
  20. try {
  21. var settings = JSON.parse(fs.readFileSync(__dirname + '/.release.json', 'utf8'));
  22. return gotToken(settings.token);
  23. } catch (ex) {
  24. // use server to initialize config
  25. }
  26. var app = express();
  27. var state = crypto.randomBytes(8).toString('hex');
  28. var server = null;
  29. app.get('/', function (req, res, next) {
  30. if (req.query.code) return next();
  31. res.redirect('https://github.com/login/oauth/authorize?client_id=' + GITHUB_CLIENT_ID
  32. + '&scope=' + SCOPE
  33. + '&redirect_uri=http://localhost:1337/'
  34. + '&state=' + state);
  35. });
  36. app.get('/', function (req, res, next) {
  37. var code = req.query.code;
  38. var u = 'https://github.com/login/oauth/access_token'
  39. + '?client_id=' + GITHUB_CLIENT_ID
  40. + '&client_secret=' + GITHUB_CLIENT_SECRET
  41. + '&code=' + code
  42. + '&state=' + state;
  43. github.buffer('GET', u, {}, {}, function (err, response) {
  44. if (err) return next(err);
  45. req.token = qs.parse(response.body);
  46. next();
  47. });
  48. });
  49. app.get('/', function (req, res, next) {
  50. res.send('got token, return to terminal');
  51. server.close();
  52. fs.writeFileSync(__dirname + '/.release.json', JSON.stringify({token: req.token}));
  53. gotToken(req.token);
  54. });
  55. server = app.listen(1337);
  56. server.setTimeout(3000);
  57. opener('http://localhost:1337');
  58. }
  59. getToken(function (token) {
  60. compiledWebsite.then(function () {
  61. var fileUpdates = readdirp(__dirname + '/docs/out').filter(function (info) {
  62. return info.isFile();
  63. }).map(function (info) {
  64. return {
  65. path: info.path.replace(/^\.\//, ''),
  66. content: fs.readFileSync(info.fullPath)
  67. };
  68. });
  69. return pr.commit('visionmedia', 'jade', {
  70. branch: 'gh-pages',
  71. message: 'Update website for ' + version,
  72. updates: fileUpdates
  73. }, {auth: {type: 'oauth', token: token.access_token}});
  74. }).then(function () {
  75. // todo: release the new npm package, set the tag and commit etc.
  76. }).done();
  77. });