Skip to content
This repository has been archived by the owner on Jun 1, 2020. It is now read-only.

Add GitHub auto-updater #33

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add GitHub auto-updater #33

wants to merge 1 commit into from

Conversation

jman294
Copy link

@jman294 jman294 commented Apr 27, 2018

The git updater without cloning individual repositories.

@jman294 jman294 mentioned this pull request Apr 27, 2018
Copy link
Contributor

@PeterDaveHello PeterDaveHello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jman294 thanks for the PR, please squash the commits into a single one first, thanks!

updaters/git.js Outdated
@@ -15,6 +15,7 @@ var isThere = require('is-there');

var update = function(library, callback) {
var target = library.autoupdate.target;
console.log(target)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should git auto-update be touched here?

Copy link
Contributor

@PeterDaveHello PeterDaveHello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set the user-agent in a single place?

var update = function(library, callback) {
async.series([
function(next) {
rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/tags',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's give + spaces between and after it

function(next) {
rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/tags',
headers: {
'User-Agent': 'cdnjs'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say CDNJS GitHub auto-updater

var basePath = library.autoupdate.basePath || "";
var allFiles = [];

rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/git/trees/'+fullData.tree+'?recursive=1',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's give + spaces between and after it


rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/git/trees/'+fullData.tree+'?recursive=1',
headers: {
'User-Agent': 'cdnjs'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say CDNJS GitHub auto-updater

fs.writeFileSync(libraryPath, JSON.stringify(libraryJSON, undefined, 2) + '\n');
}
async.each(allFiles, function(file, callback) {
//var fileName = path.relative(path.join(localTarget, file.basePath), file._);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be removed?

@jman294
Copy link
Author

jman294 commented Apr 27, 2018

Sorry for somewhat unprofessional style, squashed all commits into one (I believe).

.gitignore Outdated
@@ -1,3 +1,5 @@
node_modules
tmp
git_repo_local_cache/

*.swp
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't update .gitignore in this PR, it's not related. I also suggest to include it in your personal global gitignore list, like:
https://github.com/PeterDaveHello/Unitial/blob/master/gitignore_global#L2
https://github.com/PeterDaveHello/Unitial/blob/master/gitconfig#L72

};

var githubRepo = function (url) {
return url.slice(url.indexOf('/', 10)+1, url.indexOf('.git'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing spaces for +

Copy link
Author

@jman294 jman294 Apr 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are there any other stylistic changes required? I am happy to make all changes, I just am not aware of your style guidelines. Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should copy this one here: https://github.com/cdnjs/cdnjs/blob/master/.jscsrc
We have an issue with it: #12
Thanks for asking!

.then(function (jsonString) {
var filesJson = JSON.parse(jsonString);
_.each(library.autoupdate.fileMap, function(mapGroup) {
var cBasePath = mapGroup.basePath || "", files = [];
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use single quotes here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I bet you're right!

rp({
uri:'https://raw.githubusercontent.com/'
+ githubRepo(library.autoupdate.target) + '/'
+ file.tree + '/' + file.basePath + '/' + fileName,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could change this to path.normalize(path.join(file.tree, file.basePath, fileName)),

This is a path for a website, but I think the benefit still applies.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good!

@PeterDaveHello
Copy link
Contributor

Hi @jman294! I've added Travis CI to help check coding style issues, hope it'll help us save time on style issues, please take a look, thank you! 😄

Download correct tarballs

Add file retrieval functionality

Fix up github updater

Delete .cdnjs.js.swp

Delete .git.js.swp

Delete .autoupdate.js.swp

Fixed up style

Issue 27 GitHub Updater

Add space after +

Github Updater

Fix style
@jman294
Copy link
Author

jman294 commented May 1, 2018

Is there anything that needs to happen for this pull request to complete? I have tested the updater to the best of my ability.

Copy link
Contributor

@PeterDaveHello PeterDaveHello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to invite @extend1994 & @sufuf3 join the review and test here.

@PeterDaveHello PeterDaveHello changed the title Github Updater Add GitHub Updater May 3, 2018
@PeterDaveHello PeterDaveHello changed the title Add GitHub Updater Add GitHub auto-updater May 3, 2018
@extend1994
Copy link

Review in progress, might need some more time.

Copy link

@extend1994 extend1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this PR can't be used to get the assets in the release page which #27 hopes to achieve?
The used GitHub API in this PR is to get files in a Git repository, #27 wants us to use https://developer.github.com/v3/repos/releases/#releases in my view.

});

var needed = _.filter(versions, function (version) {
var tagName = versions[0].version;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version.version[0] should be the one to retrieve a tag name :)

var needed = _.filter(versions, function (version) {
var tagName = versions[0].version;
if ((tagName === 'v' || tagName === 'V' || tagName === 'r') &&
version.length > 1 && !isNaN(version[1])) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here we want to check version length and numberic version, so it would be version.version.length > 1 && !isNaN(version.version[1])according to your version object.

_.each(mapGroup.files, function (cRule) {
var newFiles = [];
for (var file of filesJson.tree) {
if (file.path.indexOf(cBasePath) === 0) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add && file.type !== "tree" here in order to prevent directory match like what option nodir: true can do in glob library.

if (minimatch(file.path, cRule, {
nodir: true,
realpath: true
})) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove nodir and realpath option, they are only for glob lib and there has no effect in minimatch lib.
Then the code block here can be simpler:

if (minimatch(file.path, cRule)) {
  newFiles.push({ path: file.path, tree: fullData.tree });
}

rp({
uri: 'https://raw.githubusercontent.com/'
+ githubRepo(library.autoupdate.target) + '/'
+ path.normalize(path.join(file.tree, file.basePath, fileName)),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path.normalize(path.join(file.tree, fileName) is enough, fileName has included basePath.

var fileName = file._;
var fileTarget = path.normalize(
path.join(__dirname, '../../cdnjs', 'ajax',
'libs', library.name, tag, fileName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileName here should be path.relative(file.basePath, fileName);,
I suppose a better way is to replace it with a local and meaningful variable
(instead of using path.relative(file.basePath, fileName); directly)
e.g. Add

var localFileName = path.relative(file.basePath, file._);

under fileName declaration. And use it to replace fileName.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants