Skip to content

Instantly share code, notes, and snippets.

@dfreedm
Created August 31, 2015 21:55
Show Gist options
  • Save dfreedm/8613b19327ea8929dd07 to your computer and use it in GitHub Desktop.
Save dfreedm/8613b19327ea8929dd07 to your computer and use it in GitHub Desktop.
Replace PolymerElement bower components with their github equivalents
#!/usr/bin/env node
/**
* @license
* Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
* This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
* The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
* The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
* Code distributed by Google as part of the polymer project is also
* subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
*/
var async = require('async');
var path = require('path');
var del = require('del');
var glob = require('glob');
var git = require('gift');
async.waterfall([
// find all the bower metadata
function(next) {
glob('bower_components/*/.bower.json', next);
},
// generate replacement objects for elements
function(files, next) {
var replacements = [];
files.forEach(function(file) {
try {
var json = require('./' + file);
var source = json._originalSource;
// only repos in PolymerElements
if (source.split('/')[0].toLowerCase() !== 'polymerelements') {
return;
}
// find the commit for the tag
var commit = json._resolution.commit;
// git repo
var repo = json._source.replace('git://', 'https://');
// folder in bower_comopnents
var folder = path.dirname(file);
replacements.push({
repo: repo,
commit: commit,
folder: folder
});
} catch(_) {
}
});
next(null, replacements);
},
function(replacements, next) {
async.each(replacements, function(rep, cb) {
console.log('swapping', rep.folder, 'with git version');
async.series([
// delete bower copy
function(n) {
del(rep.folder, n);
},
// clone git copy
function(n) {
git.clone(rep.repo, rep.folder, function(err, repo) {
if (err) return n(err);
// checkout tag
repo.checkout(rep.commit, n);
});
}
], cb);
}, next);
},
], function(err) {
if (err) {
console.log(err);
} else {
console.log('DONE');
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment