Skip to content

Commit

Permalink
restructuring and adding lots of dev tooling
Browse files Browse the repository at this point in the history
  • Loading branch information
machellerogden committed Feb 22, 2017
1 parent bf4e694 commit 0ad5c46
Show file tree
Hide file tree
Showing 20 changed files with 190 additions and 81 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage
94 changes: 94 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"browser": true,
"node": true,
"es6": true,
"mocha": true
},
"globals": {
"googletag": true,
"navigator": true,
"$": true,
"_": true,
"browser": true,
"element": true,
"by": true,
"angular": true,
"sinon": true,
"ConfigBootstrapper": true,
"configBootstrapper": true,
"Ignition": true,
"ignition": true,
"$LAB": true,
"s_clven": true,
"s_gi": true,
"s_account": true,
"trackLink": true,
"gigya": true,
"optimizely": true,
"module": true,
"inject": true,
"STATIC_REPLACEMENT_STRING": true
},
"extends": "eslint:recommended",
"rules": {
"no-mixed-requires": 0,
"wrap-iife": [2, "any"],
"camelcase": 2,
"curly": 0,
"eqeqeq": 0,
"no-extend-native": 1,
"no-native-reassign": 2,
"guard-for-in": 2,
"func-style": [1, "declaration"],
"no-lonely-if": 0,
"no-mixed-spaces-and-tabs": 2,
"no-use-before-define": 0,
"no-unused-vars" : 0,
"no-undefined" : 0,
"no-undef" : 1,
"strict": 0,
"new-cap": 2,
"no-caller": 1,
"no-empty": 0,
"no-new": 0,
"quotes": 0,
"no-trailing-spaces": 1,
"comma-dangle": 0,
"no-underscore-dangle": 0,
"no-console": 0,
"no-debugger": 1,
"no-eq-null": 0,
"no-eval": 1,
"space-infix-ops": 1,
"block-scoped-var": 1,
"dot-notation": 0,
"complexity": 0,
"no-iterator": 1,
"no-loop-func": 1,
"no-multi-str": 1,
"no-proto": 1,
"no-script-url": 1,
"no-shadow": 0,
"no-shadow-restricted-names": 1,
"no-dupe-keys": 2,
"eol-last": 0,
"key-spacing": 0,
"keyword-spacing": 1,
"brace-style": [1, "1tbs", {
"allowSingleLine": true
}],
"semi": [2, "always"],
"no-process-exit": 0,
"no-unused-expressions": 0,
"no-case-declarations": 2,
"no-extra-semi": 1,
"no-unsafe-finally": 2,
"require-yield": 2,
"no-inner-declarations": 0
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
sources/.cache.json
npm-debug.log
coverage
3 changes: 1 addition & 2 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ function cli(options) {
if (options.refresh) {
return refresh();
} else {
const searchFilter = (v) => (new RegExp(searchTerm)).test(v);
const sourceDataPromise = lib.getSourceData();
const pathsPromise = sourceDataPromise.then(lib.getPaths).filter(searchFilter);
const pathsPromise = sourceDataPromise.then(lib.getPaths).filter((v) => (new RegExp(searchTerm)).test(v));
if (options.completions) {
return pathsPromise.map((repoPath) => _.tail(repoPath.split(path.sep)).join(path.sep))
.each(_.ary(console.log, 1));
Expand Down
4 changes: 2 additions & 2 deletions dotfiles/cli.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
function bitcar_cli() {
local root="${BITCAR_ROOT_DIR:-"$HOME/bitcar-repos"}"
[ -z "$1" ] && cd "$root" && return
local workspace_dir="${BITCAR_WORKSPACE_DIR:-"$HOME/bitcar-repos"}"
[ -z "$1" ] && cd "$workspace_dir" && return
local target="$HOME/.bitcar/.bitcar_target"
bitcar "$@" && if [ -f "$target" ]; then cd "$(cat "$target")" && rm "$target"; fi
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const inquirer = require('inquirer');
module.exports = bitbucketSourcePromise;

function bitbucketSourcePromise(config) {
const bitbucketConfig = _.find(config.sources, { type: 'bitbucket-server' });
const bitbucketConfig = _.find(config.drivers, { type: 'bitbucket-server' });
if (bitbucketConfig && bitbucketConfig.host) {
return inquirer.prompt([
{
Expand Down
28 changes: 12 additions & 16 deletions sources/github.com/index.js → drivers/github/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,16 @@ const Promise = require('bluebird');
module.exports = githubSourcePromise;

function parseLinkHeader(header) {
if (header.length === 0) {
throw new Error("input must not be of zero length");
}
var parts = header.split(',');
var links = {};
for(var i=0; i<parts.length; i++) {
var section = parts[i].split(';');
if (section.length !== 2) {
throw new Error("section could not be split on ';'");
}
var url = section[0].replace(/<(.*)>/, '$1').trim();
var name = section[1].replace(/rel="(.*)"/, '$1').trim();
links[name] = url;
}
if (header.length === 0) throw new Error("input must not be of zero length");
const parts = header.split(',');
const links = _.reduce(parts, (acc, part) => {
const section = part.split(';');
if (section.length !== 2) throw new Error("section could not be split on ';'");
const url = section[0].replace(/<(.*)>/, '$1').trim();
const name = section[1].replace(/rel="(.*)"/, '$1').trim();
acc[name] = url;
return acc;
}, {});
return links;
}

Expand All @@ -41,7 +37,7 @@ function getOwnRepos(config) {
}
}
return all;
});
}).catch();
}
return getPage([], reqUrl);
}
Expand All @@ -66,7 +62,7 @@ function getReposFromUsernames(config) {
}

function githubSourcePromise(config) {
const githubConfig = _.find(config.sources, { type: 'github' });
const githubConfig = _.find(config.drivers, { type: 'github' });
let resultPromises = [];
if (githubConfig && githubConfig.accessToken) {
resultPromises.push(getOwnRepos(githubConfig));
Expand Down
2 changes: 1 addition & 1 deletion sources/index.js → drivers/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
'use strict';
exports['bitbucket-server'] = require('./bitbucket-server');
exports['github.com'] = require('./github.com');
exports['github'] = require('./github');
15 changes: 7 additions & 8 deletions lib/getSourceData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const fs = require('./fs');
const path = require('path');
const _ = require('lodash');
const Promise = require('bluebird');
const rootDir = require('./rootDir');
const workspaceDir = require('./workspaceDir');
const rc = require('rc')('bitcar', {});

module.exports = getSourceData;
Expand All @@ -14,18 +14,17 @@ function getSourceData(forceRefresh = false) {
return Promise.resolve(fs.readJSON(CACHE_PATH));
} else {
const config = fs.readJSON(path.normalize(process.env.HOME + '/.bitcar/config'));
const sources = require('../sources');
const drivers = require('../drivers');
console.log('Loading cache...');
return Promise.props(_.mapValues(sources, source => source(rc)))
const selected = _.pick(drivers, _.map(config.drivers, (v) => v.type));
return Promise.props(_.mapValues(selected, (driver) => driver(rc)))
.then((sourceData) => {
sourceData = _.mapValues(sourceData, _.flow(_.flattenDeep, _.compact));
sourceData = _.mapValues(sourceData, (entries) => _.uniqBy(entries, 'name'));
sourceData = _.mapKeys(sourceData, (v, k) => {
return _.find(rc.drivers, { type: k }).host;
});
return new Promise((resolve, reject) => {
let bitbucketConfig = _.find(rc.sources, { type: 'bitbucket-server' });
if (bitbucketConfig) {
sourceData[bitbucketConfig.host] = sourceData['bitbucket-server'];
delete sourceData['bitbucket-server'];
}
fs.writeJSON(CACHE_PATH, sourceData, null, 4);
fs.commit((err) => {
if (err) return reject(err);
Expand Down
4 changes: 2 additions & 2 deletions lib/getSourceResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const path = require('path');
const _ = require('lodash');
const Promise = require('bluebird');
const rootDir = require('./rootDir');
const workspaceDir = require('./workspaceDir');
const getSourceData = require('./getSourceData');

module.exports = getSourceResult;
Expand All @@ -13,7 +13,7 @@ function getSourceResult(repoDir) {
const repoName = repoParts.join(path.sep);
return getSourceData().then((sourceData) => {
const sourceResult = _.find(sourceData[sourceName], { name: repoName });
sourceResult.repoDir = path.join(rootDir, repoDir);
sourceResult.repoDir = path.join(workspaceDir, repoDir);
return sourceResult;
});
}
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ exports.getSourceData = require('./getSourceData');
exports.getSourceResult = require('./getSourceResult');
exports.maybeClone = require('./maybeClone');
exports.openInBrowser = require('./openInBrowser');
exports.rootDir = require('./rootDir');
exports.workspaceDir = require('./workspaceDir');
exports.setTarget = require('./setTarget');
4 changes: 2 additions & 2 deletions lib/maybeClone.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
const fs = require('fs');
const path = require('path');
const Promise = require('bluebird');
const rootDir = require('./rootDir');
const git = require('simple-git')(rootDir)
const workspaceDir = require('./workspaceDir');
const git = require('simple-git')(workspaceDir)
.outputHandler(function (command, stdout, stderr) {
stdout.pipe(process.stdout);
stderr.pipe(process.stderr);
Expand Down
2 changes: 1 addition & 1 deletion lib/openInBrowser.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
const path = require('path');
const _ = require('lodash');
const Promise = require('bluebird');
const rootDir = require('./rootDir');
const workspaceDir = require('./workspaceDir');
const open = require('open');

module.exports = openInBrowser;
Expand Down
12 changes: 0 additions & 12 deletions lib/rootDir.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/setTarget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';
const fs = require('./fs');
const rootDir = require('./rootDir');
const workspaceDir = require('./workspaceDir');
const path = require('path');

module.exports = setTarget;
Expand Down
12 changes: 12 additions & 0 deletions lib/workspaceDir.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';
const path = require('path');
const fs = require('fs');
const envWorkspaceDir = process.env.BITCAR_WORKSPACE_DIR;
const defaultWorkspaceDir = `${process.env.HOME}/bitcar-repos`;
const workspaceDir = (envWorkspaceDir) ? path.normalize(envWorkspaceDir) : path.normalize(defaultWorkspaceDir);

if (!fs.existsSync(workspaceDir)) {
fs.mkdirSync(workspaceDir);
}

module.exports = workspaceDir;
19 changes: 17 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
"bitcar": "index.js"
},
"scripts": {
"test": "./node_modules/.bin/mocha \"test/**/*.js\""
"lint": "./node_modules/.bin/eslint .",
"test": "./node_modules/.bin/mocha \"test/**/*.js\"",
"changelog": "./node_modules/.bin/github-changes -o carsdotcom -r bitcar",
"generate-and-stage-changelog": "npm run changelog && git add -A",
"coverage": "rm -rf coverage && node node_modules/.bin/istanbul cover -x \"test/**/*.js\" --dir=\"coverage\" --root=\"./\" node_modules/.bin/_mocha -- \"test/**/*.js\"",
"check-coverage": "npm run coverage && ./node_modules/.bin/istanbul check-coverage --root=\"./coverage\" --statement 85 --function 85 --branch 85"
},
"contributors": [
{
Expand All @@ -37,9 +42,19 @@
},
"devDependencies": {
"chai": "^3.5.0",
"eslint": "^3.16.0",
"github-changes": "^1.0.4",
"istanbul": "^0.4.5",
"joi": "^10.2.2",
"mocha": "^3.2.0",
"pre-commit": "^1.2.2",
"sinon": "^1.17.7",
"sinon-chai": "^2.8.0"
}
},
"pre-commit": [
"lint",
"test",
"check-coverage",
"generate-and-stage-changelog"
]
}
Loading

0 comments on commit 0ad5c46

Please sign in to comment.