├── .gitignore ├── .travis.yml ├── lib ├── .DS_Store └── package.js ├── test ├── .DS_Store ├── fixtures │ ├── package.json │ └── package.html └── test_package.js ├── .jshintrc ├── .editorconfig ├── index.js ├── .jscs.json ├── README.md ├── package.json └── gulpfile.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | temp/ 3 | coverage/ 4 | npm-debug.log 5 | .DS_Store 6 | .idea 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '0.10' 4 | after_script: 5 | - npm run coveralls 6 | -------------------------------------------------------------------------------- /lib/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stefanbuck/github-linker-core/ef0d9ab06ed5edbf74f5cd31905d04aa79f45fbc/lib/.DS_Store -------------------------------------------------------------------------------- /test/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stefanbuck/github-linker-core/ef0d9ab06ed5edbf74f5cd31905d04aa79f45fbc/test/.DS_Store -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "curly": true, 3 | "eqeqeq": true, 4 | "immed": true, 5 | "latedef": true, 6 | "newcap": true, 7 | "noarg": true, 8 | "sub": true, 9 | "undef": true, 10 | "unused": true, 11 | "boss": true, 12 | "eqnull": true, 13 | "node": true, 14 | "globals": { 15 | "describe" : false, 16 | "it" : false, 17 | "before" : false, 18 | "beforeEach" : false, 19 | "after" : false, 20 | "afterEach" : false 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | 8 | [*] 9 | 10 | # Change these settings to your own preference 11 | indent_style = space 12 | indent_size = 2 13 | 14 | # We recommend you to keep these unchanged 15 | end_of_line = lf 16 | charset = utf-8 17 | trim_trailing_whitespace = true 18 | insert_final_newline = true 19 | 20 | [*.md] 21 | trim_trailing_whitespace = false 22 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* 2 | * github-linker-core 3 | * https://github.com/stefanbuck/github-linker 4 | * 5 | * Copyright (c) 2014 Stefan Buck 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | 'use strict'; 10 | 11 | var _ = require('lodash'); 12 | var pkg = require('./lib/package'); 13 | 14 | var getType = function(url) { 15 | 16 | var urlContains = function(indicator) { 17 | return url.indexOf(indicator) === url.length - indicator.length; 18 | }; 19 | var lookup = { 20 | '/package.json': 'npm', 21 | '/bower.json': 'bower', 22 | '.js': 'js', 23 | '.coffee': 'coffee' 24 | }; 25 | 26 | return _.find(lookup, function(type, urlFragment) { 27 | return urlContains(urlFragment); 28 | }); 29 | }; 30 | 31 | module.exports = function($, url, cb) { 32 | 33 | var type = getType(url); 34 | 35 | pkg($, type, cb); 36 | }; 37 | -------------------------------------------------------------------------------- /.jscs.json: -------------------------------------------------------------------------------- 1 | { 2 | "requireCurlyBraces": ["if", "else", "for", "while", "do", "try", "catch"], 3 | "requireSpaceAfterKeywords": ["if", "else", "for", "while", "do", "switch", "return", "try", "catch"], 4 | "disallowSpaceBeforeBinaryOperators": [",", ":"], 5 | "disallowSpaceAfterBinaryOperators": ["!"], 6 | "requireSpaceBeforeBinaryOperators": ["?", "+", "-", "/", "*", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 7 | "requireSpaceAfterBinaryOperators": ["?", "+", "/", "*", ":", "=", "==", "===", "!=", "!==", ">", ">=", "<", "<="], 8 | "disallowImplicitTypeConversion": ["string"], 9 | "disallowKeywords": ["with"], 10 | "disallowMultipleLineBreaks": true, 11 | "disallowKeywordsOnNewLine": ["else"], 12 | "disallowTrailingWhitespace": true, 13 | "requireLineFeedAtFileEnd": true, 14 | "validateJSDoc": { 15 | "checkParamNames": true, 16 | "requireParamTypes": true 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # github-linker-core 2 | [![NPM version][npm-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency Status][daviddm-url]][daviddm-image] [![Coverage Status][coveralls-image]][coveralls-url] 3 | 4 | | The [GitHub-Linker](https://github.com/stefanbuck/github-linker) core 5 | 6 | 7 | ## License 8 | 9 | Copyright (c) 2014 Stefan Buck. Licensed under the MIT license. 10 | 11 | 12 | 13 | [npm-url]: https://npmjs.org/package/github-linker-core 14 | [npm-image]: https://badge.fury.io/js/github-linker-core.svg 15 | [travis-url]: https://travis-ci.org/stefanbuck/github-linker-core 16 | [travis-image]: https://travis-ci.org/stefanbuck/github-linker-core.svg?branch=master 17 | [daviddm-url]: https://david-dm.org/stefanbuck/github-linker-core.svg?theme=shields.io 18 | [daviddm-image]: https://david-dm.org/stefanbuck/github-linker-core 19 | [coveralls-url]: https://coveralls.io/r/stefanbuck/github-linker-core 20 | [coveralls-image]: https://coveralls.io/repos/stefanbuck/github-linker-core/badge.png 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "github-linker-core", 3 | "description": "The GitHub Linker core", 4 | "version": "0.0.1", 5 | "homepage": "https://github.com/stefanbuck/github-linker", 6 | "bugs": "https://github.com/stefanbuck/github-linker-core/issues", 7 | "license": "MIT", 8 | "main": "index.js", 9 | "author": { 10 | "name": "Stefan Buck", 11 | "email": "dev@stefanbuck.com", 12 | "url": "http://stefanbuck.com" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/stefanbuck/github-linker-core" 17 | }, 18 | "keywords": [], 19 | "dependencies": { 20 | "debug": "1.0.4", 21 | "jquery": "^2.1.1", 22 | "lodash": "2.4.1" 23 | }, 24 | "devDependencies": { 25 | "coveralls": "^2.10.0", 26 | "gulp": "^3.6.2", 27 | "gulp-bump": "^0.1.8", 28 | "gulp-istanbul": "^0.2.0", 29 | "gulp-jscs": "^0.4.2", 30 | "gulp-jshint": "^1.5.5", 31 | "gulp-load-plugins": "^0.5.1", 32 | "gulp-mocha": "^0.4.1", 33 | "gulp-plumber": "^0.6.2", 34 | "gulp-util": "2.2.16", 35 | "jshint-stylish": "^0.2.0", 36 | "should": "^3.3.1", 37 | "jsdom": "^1.0.0-pre.3" 38 | }, 39 | "scripts": { 40 | "coveralls": "gulp test && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", 41 | "test": "gulp test" 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /test/fixtures/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "playground-repo", 3 | "description": "My personal playground", 4 | "version": "0.0.1", 5 | "homepage": "https://github.com/stefanbuck/playground-repo", 6 | "bugs": "https://github.com/stefanbuck/playground-repo/issues", 7 | "license": "MIT", 8 | "main": "index.js", 9 | "author": { 10 | "name": "Stefan Buck", 11 | "email": "dev@stefanbuck.com", 12 | "url": "http://stefanbuck.com" 13 | }, 14 | "repository": { 15 | "type": "git", 16 | "url": "https://github.com/stefanbuck/playground-repo" 17 | }, 18 | "keywords": [], 19 | "dependencies": { 20 | "lodash": "2.4.1", 21 | "request": "^2.40.0", 22 | "modernizr": "Modernizr/Modernizr", 23 | "backbone": "jashkenas/backbone#master", 24 | "jquery": "jquery/jquery#1.x-master", 25 | "unknown-package-name": "latest" 26 | }, 27 | "devDependencies": { 28 | "chai": "^1.9.1", 29 | "gulp": "^3.6.2" 30 | }, 31 | "optionalDependencies": { 32 | "should": "^3.3.1" 33 | }, 34 | "peerDependencies": { 35 | "yo": ">=1.0.0" 36 | }, 37 | "scripts": { 38 | "coveralls": "gulp test && cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js", 39 | "test": "gulp test" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var gulp = require('gulp'); 4 | var plugins = require('gulp-load-plugins')(); 5 | 6 | var paths = { 7 | lint: ['./gulpfile.js', './lib/**/*.js', '!./lib/dictionary/*.js'], 8 | watch: ['./gulpfile.js', './lib/**', './test/**/*.js', '!test/{temp,temp/**}', '!./lib/dictionary/*.js'], 9 | tests: ['./test/**/*.js', '!test/{temp,temp/**}'], 10 | source: ['./lib/*.js'] 11 | }; 12 | 13 | gulp.task('lint', function () { 14 | return gulp.src(paths.lint) 15 | .pipe(plugins.jshint('.jshintrc')) 16 | .pipe(plugins.jscs()) 17 | .pipe(plugins.jshint.reporter('jshint-stylish')); 18 | }); 19 | 20 | gulp.task('istanbul', function (cb) { 21 | gulp.src(paths.source) 22 | .pipe(plugins.istanbul()) // Covering files 23 | .on('finish', function () { 24 | gulp.src(paths.tests) 25 | .pipe(plugins.plumber()) 26 | .pipe(plugins.mocha()) 27 | .pipe(plugins.istanbul.writeReports()) // Creating the reports after tests runned 28 | .on('finish', function() { 29 | process.chdir(__dirname); 30 | cb(); 31 | }); 32 | }); 33 | }); 34 | 35 | gulp.task('bump', ['test'], function () { 36 | var bumpType = plugins.util.env.type || 'patch'; // major.minor.patch 37 | 38 | return gulp.src(['./package.json']) 39 | .pipe(plugins.bump({ type: bumpType })) 40 | .pipe(gulp.dest('./')); 41 | }); 42 | 43 | gulp.task('watch', ['test'], function () { 44 | gulp.watch(paths.watch, ['test']); 45 | }); 46 | 47 | gulp.task('test', ['lint', 'istanbul']); 48 | 49 | gulp.task('release', ['bump']); 50 | 51 | gulp.task('default', ['test']); 52 | -------------------------------------------------------------------------------- /lib/package.js: -------------------------------------------------------------------------------- 1 | /* 2 | * github-linker-core 3 | * https://github.com/stefanbuck/github-linker 4 | * 5 | * Copyright (c) 2014 Stefan Buck 6 | * Licensed under the MIT license. 7 | */ 8 | 9 | 'use strict'; 10 | 11 | var $ = null; 12 | 13 | var stripQuotes = function(jqElement) { 14 | return jqElement.html().replace(/"/g, ''); 15 | }; 16 | 17 | var getPackageNodes = function() { 18 | 19 | var $root, $row, $name, $version, name, version, targetURL; 20 | var types = ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']; 21 | var result = []; 22 | 23 | types.forEach(function(selector) { 24 | $root = $('.nt:contains(\'' + selector + '\')'); 25 | 26 | if (!$root || $root.length === 0) { 27 | return; 28 | } 29 | 30 | $row = $root.closest('tr').next(); 31 | 32 | while ($row) { 33 | $name = $row.find('.nt'); 34 | $version = $row.find('.s2'); 35 | 36 | if (!$name.length || !$version.length) { 37 | return; 38 | } 39 | 40 | name = stripQuotes($name); 41 | version = stripQuotes($version); 42 | 43 | if (version.split('/').length === 2) { 44 | version = version.replace('#', '/tree/'); 45 | targetURL = 'https://github.com/' + version; 46 | } 47 | 48 | result.push({ 49 | el: $name, 50 | version: version, 51 | name: name, 52 | url: targetURL 53 | }); 54 | 55 | $row = $row.next(); 56 | } 57 | }); 58 | 59 | return result; 60 | }; 61 | 62 | module.exports = function(_$, _type, cb) { 63 | $ = _$; 64 | 65 | var result = getPackageNodes(); 66 | 67 | cb(null, result); 68 | }; 69 | -------------------------------------------------------------------------------- /test/test_package.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var githubLinkerCore = require('../'); 4 | var fs = require('fs'); 5 | var path = require('path'); 6 | var assert = require('should'); 7 | var _ = require('lodash'); 8 | var env = require('jsdom').env; 9 | 10 | describe('githubLinkerCore', function() { 11 | 12 | var $, result; 13 | 14 | beforeEach(function(done) { 15 | var file = path.resolve(__dirname, 'fixtures/package.html'); 16 | var html = fs.readFileSync(file, 'utf-8'); 17 | 18 | $ = result = null; 19 | 20 | env(html, function(err, window) { 21 | if (err) { 22 | return done(err); 23 | } 24 | $ = require('jquery')(window); 25 | 26 | var url = 'https://github.com/stefanbuck/playground-repo/blob/master/package.json'; 27 | githubLinkerCore($, url, function(err, _result) { 28 | if (err) { 29 | throw err; 30 | } 31 | result = _result; 32 | done(); 33 | }); 34 | }); 35 | }); 36 | 37 | it('found dependencies', function() { 38 | 39 | // TODO Evaluate why this doesn't work 40 | // result.should.have.length(10); 41 | 42 | result.length.should.equal(10); 43 | }); 44 | 45 | it('check order', function() { 46 | var pkgNames = ['lodash', 'request', 'modernizr', 'backbone', 'jquery', 'unknown-package-name', 'chai', 'gulp', 'yo', 'should']; 47 | _.each(result, function(item, index) { 48 | item.name.should.equal( pkgNames[index] ); 49 | }); 50 | }); 51 | 52 | it('url Modernizr/Modernizr', function() { 53 | var item = _.findWhere(result, { 54 | name: 'modernizr' 55 | }); 56 | 57 | (item.url === null).should.equal(false); 58 | item.url.should.equal('https://github.com/Modernizr/Modernizr'); 59 | }); 60 | 61 | it('url jashkenas/backbone#master', function() { 62 | var item = _.findWhere(result, { 63 | name: 'backbone' 64 | }); 65 | 66 | (item.url === null).should.equal(false); 67 | item.url.should.equal('https://github.com/jashkenas/backbone/tree/master'); 68 | }); 69 | 70 | it('url jquery/jquery#1.x-master', function() { 71 | var item = _.findWhere(result, { 72 | name: 'jquery' 73 | }); 74 | 75 | (item.url === null).should.equal(false); 76 | item.url.should.equal('https://github.com/jquery/jquery/tree/1.x-master'); 77 | }); 78 | 79 | }); 80 | -------------------------------------------------------------------------------- /test/fixtures/package.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 | 9 |