Skip to content

Commit

Permalink
Refactor; add build pipeline
Browse files Browse the repository at this point in the history
* Differentiate between platform specific code and core code
* Add gulp to build platform bundles
* Use fork of github-api
* Use babel + webpack to compile code
  • Loading branch information
Clay Reimann committed Dec 11, 2015
1 parent 6503337 commit ed75c0b
Show file tree
Hide file tree
Showing 15 changed files with 400 additions and 209 deletions.
4 changes: 4 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"presets": ["es2015"],
"plugins": ["transform-strict-mode"]
}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bower_components/
build/
node_modules/
bower_components/
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
72 changes: 0 additions & 72 deletions chrome.js

This file was deleted.

105 changes: 105 additions & 0 deletions gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/**
* Clay Reimann, 2015
* See LICENSE.txt for details
*/
'use strict';

import gulp from 'gulp';
import webpack from 'webpack-stream';

import del from 'del';
import sequence from 'run-sequence';

const VENDOR_ASSETS = [
'bower_components/bootstrap/dist/css/bootstrap.min.css',
'bower_components/jquery/dist/jquery.min.js',
'bower_components/bootstrap/dist/js/bootstrap.min.js'
]

const PLATFORMS = [
'chrome'
];

gulp.task('build', PLATFORMS.map((p) => `build:${p}`));

PLATFORMS.forEach((platform) => {
gulp.task(`build:${platform}`, function(done) {
sequence(
`${platform}:clean`,
`${platform}:move-assets`,
`${platform}:move-vendor`,
`${platform}:compile`,
`${platform}:zip-extension`,
done);
});
});

////////////////////////////
// Build Chrome extension //
////////////////////////////
gulp.task('chrome:clean', function(done) {
del('build/chrome/**').then(() => {
done()
});
});

gulp.task('chrome:move-assets', function() {
return gulp.src([
'platform/chrome/manifest.json',
'platform/chrome/options/options.html',
'assets/**'
])
.pipe(gulp.dest('build/chrome'))
;
});

gulp.task('chrome:move-vendor', function() {
return gulp.src(VENDOR_ASSETS)
.pipe(gulp.dest('build/chrome/vendor'))
})

var WEBPACK_CONFIG = {
entry: {
chrome: './platform/chrome/chrome.js',
options: './platform/chrome/options/options.js'
},
output: {
filename: '[name].min.js'
},
resolve: {
extensions: ['', '.js']
},
externals: {
chrome: 'chrome'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel',
query: {
presets: ['es2015']
}
}
]
},
plugins: [
// new webpack.webpack.optimize.UglifyJsPlugin()
],
devtool: 'source-map',
stats: {
colors: 'true'
}
};
gulp.task('chrome:compile', function(done) {
return gulp.src(['platform/chrome/chrome.js', 'platform/chrome/options/options.html'])
.pipe(webpack(WEBPACK_CONFIG))
.pipe(gulp.dest('build/chrome'))
;
});

gulp.task('chrome:zip-extension', function(done) {
// do stuff
done();
})
110 changes: 110 additions & 0 deletions lib/search-service.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**
* Clay Reimann, 2015
* See LICENSE.txt for details
*/

import Github from 'github-api';

class SuggestionService {
/**
* Constructs a new SuggestionService
*
* @param {array} githubDescriptors - an array of objects that describe the github instances to be searched
* the objects should be of the format
* {
* url: the github url
* auth: {oauth, basic} to describe the service type
* token: required when auth == oauth
* username: required when auth == basic
* password: required when auth == basic
* }
*/
constructor(githubDescriptors) {
this.__githubs = {};
githubDescriptors.forEach((descriptor) => {
let opts = {
apiUrl: descriptor.url,
auth: descriptor.auth
};
if (descriptor.auth === 'oauth') {
opts.token = descriptor.token;
} else {
opts.username = descriptor.username;
opts.password = descriptor.password;
}
this.__githubs[descriptor.url] = new Github(opts);
});

this.__repos = [];
}

isLoaded() {
return this.__repos.length > 0;
}

addRepository(githubUrl, repository) {
let isAdded = this.__repos.reduce((found, r) => {
return found || (r.githubUrl === githubUrl && r.name === repository.full_name);
}, false);

if (!isAdded) {
this.__repos.push({
githubUrl,
name: repository.full_name,
url: repository.html_url
});
}
}

addRepositories(githubUrl, list) {
if (!list) {
return;
}

list.forEach((repository) => {
this.addRepository(githubUrl, repository);
});
}

queryGithubsForRepositories() {
this.__repos = [];
Object.keys(this.__githubs).forEach((githubUrl) => {
let github = this.__githubs[githubUrl];
let user = github.getUser();

user.repos((err, repoList) => {
this.addRepositories(githubUrl, repoList);
})

user.orgs((err, orgs) => {
if (!orgs) {
return;
}

orgs.forEach((org) => {
user.orgRepos(org.login, (err, repoList) => {
console.log(`got repos for ${org.login}`);
this.addRepositories(githubUrl, repoList);
})
})
})
})
}

getRepositoriesMatching(text) {
return this.__repos.filter(function(repo) {
return repo.name.search(new RegExp(text, 'i')) !== -1;
}).sort(function(a, b) {
return a.name.toLowerCase() < b.name.toLowerCase() ? -1 : 1;
});
}

getUrlForRepo(repoFullName) {
return this.__repos.reduce(function(found, repo) {
return found || (repo.name === repoFullName ? repo.url : found);
}, undefined);
}

}

module.exports = SuggestionService;
15 changes: 14 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,18 @@
"productivity"
],
"author": "Clay Reimann",
"license": "ISC"
"license": "ISC",
"devDependencies": {
"babel-core": "^6.3.15",
"babel-loader": "^6.2.0",
"babel-plugin-transform-strict-mode": "^6.3.13",
"babel-preset-es2015": "^6.3.13",
"gulp": "^3.9.0",
"run-sequence": "^1.1.5",
"webpack-stream": "^2.3.0"
},
"dependencies": {
"del": "^2.2.0",
"github-api": "github:clayreimann/github#add-webpack"
}
}
Loading

0 comments on commit ed75c0b

Please sign in to comment.