Skip to content

Commit

Permalink
Move core out of packages folder
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbuck committed May 2, 2016
1 parent b0b0dbf commit 4363b55
Show file tree
Hide file tree
Showing 26 changed files with 111 additions and 106 deletions.
2 changes: 2 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ module.exports = function(config) {
basePath: '',
frameworks: ['mocha', 'browserify', 'fixture', 'phantomjs-shim'],
files: [
'lib/**/*.js',
'packages/**/*.js',
'packages/*/fixtures/**/*.html',
],
exclude: [],
preprocessors: {
'lib/**/*.js': ['browserify'],
'packages/**/*.js': ['browserify'],
'packages/*/fixtures/**/*.html': ['html2js'],
},
Expand Down
5 changes: 5 additions & 0 deletions lib/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import 'babel-polyfill';
import OctoLinker from './octo-linker.js';

const octoLinker = new OctoLinker();
octoLinker.init();
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import $ from 'jquery';
import tryLoad from '../packages/try-load';
import resolverAPI from './resolver/resolver-api.js';
import relativeFile from './resolver/relative-file.js';
import javascriptFile from './resolver/javascript-file.js';
import gitUrl from './resolver/git-url.js';
import githubShorthand from './resolver/github-shorthand.js';
import javascriptUniversal from './resolver/javascript-universal.js';
import tryLoad from '../try-load';

const CLASS_NAME = 'octo-linker-link';
const LINK_SELECTOR = `.${CLASS_NAME}`;
Expand Down
7 changes: 7 additions & 0 deletions lib/debug-mode.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function (enable = false) {
if (!enable) {
return;
}

document.body.classList.add('octo-linker-debug');
}
45 changes: 45 additions & 0 deletions lib/octo-linker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import injection from 'github-injection';
import BlobReader from '../packages/blob-reader';
import clickHandler from './click-handler';
import getPluginsForBlobType from './plugin-manager.js';
import debugMode from './debug-mode.js';

function initialize(self) {
debugMode(true);
clickHandler();

self._blobReader = new BlobReader();
}

function run(self) {
if (!self._blobReader.hasBlobs()) {
return false;
}

console.time('total');

self._blobReader.read();

self._blobReader.forEach((blob) => {
const pluginsForType = getPluginsForBlobType(blob.type);
if (!pluginsForType) {
return;
}

pluginsForType.forEach((plugin) => {
plugin.parseBlob(blob);
});
});

console.timeEnd('total');
}

export default class OctoLinkerCore {
constructor() {
initialize(this);
}

init() {
injection(window, run.bind(null, this));
}
}
34 changes: 34 additions & 0 deletions lib/plugin-manager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import LinkResolver from './plugins/link-resolver';
import ManifestNPM from './plugins/manifest-npm';
import ManifestGemfile from './plugins/manifest-gemfile';

const plugins = [
LinkResolver,
ManifestNPM,
ManifestGemfile,
];

function generateCache() {
const list = new Map();

plugins.forEach((PluginClass) => {
const pluginInstance = new PluginClass();

pluginInstance.blobTypes().forEach((type) => {
const caller = list.get(type) || [];
caller.push(pluginInstance);

if (!list.has(type)) {
list.set(type, caller);
}
});
});

return list;
}

const cache = generateCache();

export default function (pluginName) {
return cache.get(pluginName);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { REQUIRE, REQUIRE_RESOLVE, IMPORT } from '../helper-grammar-regex-collection/index.js';
import replaceKeywords from '../helper-replace-keywords';
import { REQUIRE, REQUIRE_RESOLVE, IMPORT } from '../../../packages/helper-grammar-regex-collection/index.js';
import wrapKeyword from '../../wrap-keyword';

export default class LiveResolver {

Expand All @@ -12,7 +12,7 @@ export default class LiveResolver {

parseBlob(blob) {
[REQUIRE, REQUIRE_RESOLVE, IMPORT].forEach((regex) => {
replaceKeywords(blob.el, regex, {
wrapKeyword(blob.el, regex, {
resolver: 'javascriptUniversal',
target: '$1',
path: blob.path,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { basename } from 'path';
import replaceKeywords from '../helper-replace-keywords';
import { GEM } from '../helper-grammar-regex-collection/index.js';
import { GEM } from '../../../packages/helper-grammar-regex-collection/index.js';
import wrapKeyword from '../../wrap-keyword';

export default class GemManifest {

Expand All @@ -16,7 +16,7 @@ export default class GemManifest {
return;
}

replaceKeywords(blob.el, GEM, {
wrapKeyword(blob.el, GEM, {
resolver: 'resolverAPI',
target: '$1',
type: 'rubygems',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import replaceKeywords from '../helper-replace-keywords';
import escapeRegexString from 'escape-regex-string';
import semver from 'semver';
import escapeRegexString from 'escape-regex-string';
import wrapKeyword from '../../wrap-keyword';

function regexBuilder(key, value) {
const regexKey = escapeRegexString(key);
Expand All @@ -18,7 +18,7 @@ function linker(blob, result) {

const isSemver = isValidSemver(value);

replaceKeywords(blob.el, regex, {
wrapKeyword(blob.el, regex, {
resolver: isSemver ? 'resolverAPI' : 'gitUrl|githubShorthand',
target: isSemver ? '$1' : '$2',
type: 'npm',
Expand All @@ -29,7 +29,7 @@ function mainLinker(blob, result) {
const [key, value] = result;
const regex = regexBuilder(key, value);

replaceKeywords(blob.el, regex, {
wrapKeyword(blob.el, regex, {
resolver: 'javascriptFile',
path: blob.path,
target: '$2',
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function ({ type, target }) {
}

return {
url: `https://githublinker.herokuapp.com/redirect?url=${target}`,
url: `https://githublinker.herokuapp.com/ping?url=${target}`,
method: 'GET',
};
}
File renamed without changes.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"engines": {
"node": ">=4.0.0"
},
"main": "lib/app.js",
"scripts": {
"bootstrap": "./scripts/bootstrap",
"lint": "./scripts/lint",
Expand Down
86 changes: 0 additions & 86 deletions packages/core/index.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/plugin-link-resolver/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e
NPM_BIN="$(npm bin)";
cd "$(dirname "$0")/.."

"$NPM_BIN/browserify" ./packages/core/index.js -t babelify --outfile ./chrome/app.js
"$NPM_BIN/browserify" ./lib/app.js -t babelify --outfile ./chrome/app.js
2 changes: 1 addition & 1 deletion scripts/watch-build
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ set -e
NPM_BIN="$(npm bin)";
cd "$(dirname "$0")/.."

"$NPM_BIN/watchify" ./packages/core/index.js -t babelify --outfile ./chrome/app.js
"$NPM_BIN/watchify" ./lib/app.js -t babelify --outfile ./chrome/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'assert';
import sinon from 'sinon';
import $ from 'jquery';
import clickHandler, { registerHandler } from './index.js';
import clickHandler, { registerHandler } from '../lib/click-hanlder';

describe.skip('helper-click-handler', () => {
const sandbox = sinon.sandbox.create();
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import assert from 'assert';
import $ from 'jquery';
import insertLink from './index.js';
import wrapKeyword from '../lib/wrap-keyword.js';

describe('helper-replace-keywords', () => {
function helper(html, options = { value: '$1' }, regex = /foo ("\w+")/, replaceIndex = '$1') {
const el = document.createElement('div');
el.innerHTML = html;

insertLink(el, regex, options, replaceIndex);
wrapKeyword(el, regex, options, replaceIndex);

return el;
}
Expand Down

0 comments on commit 4363b55

Please sign in to comment.