-
-
Notifications
You must be signed in to change notification settings - Fork 14
Add GitHub auto-updater #33
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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) |
There was a problem hiding this comment.
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?
There was a problem hiding this 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?
updaters/github.js
Outdated
var update = function(library, callback) { | ||
async.series([ | ||
function(next) { | ||
rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/tags', |
There was a problem hiding this comment.
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
updaters/github.js
Outdated
function(next) { | ||
rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/tags', | ||
headers: { | ||
'User-Agent': 'cdnjs' |
There was a problem hiding this comment.
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
updaters/github.js
Outdated
var basePath = library.autoupdate.basePath || ""; | ||
var allFiles = []; | ||
|
||
rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/git/trees/'+fullData.tree+'?recursive=1', |
There was a problem hiding this comment.
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
updaters/github.js
Outdated
|
||
rp({uri:'https://api.github.com/repos/'+githubRepo(library.autoupdate.target)+'/git/trees/'+fullData.tree+'?recursive=1', | ||
headers: { | ||
'User-Agent': 'cdnjs' |
There was a problem hiding this comment.
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
updaters/github.js
Outdated
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._); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be removed?
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 |
There was a problem hiding this comment.
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
updaters/github.js
Outdated
}; | ||
|
||
var githubRepo = function (url) { | ||
return url.slice(url.indexOf('/', 10)+1, url.indexOf('.git')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing spaces for +
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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!
updaters/github.js
Outdated
.then(function (jsonString) { | ||
var filesJson = JSON.parse(jsonString); | ||
_.each(library.autoupdate.fileMap, function(mapGroup) { | ||
var cBasePath = mapGroup.basePath || "", files = []; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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!
updaters/github.js
Outdated
rp({ | ||
uri:'https://raw.githubusercontent.com/' | ||
+ githubRepo(library.autoupdate.target) + '/' | ||
+ file.tree + '/' + file.basePath + '/' + fileName, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
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
Is there anything that needs to happen for this pull request to complete? I have tested the updater to the best of my ability. |
There was a problem hiding this 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.
Review in progress, might need some more time. |
There was a problem hiding this 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; |
There was a problem hiding this comment.
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])) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 | ||
})) { |
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
.
The git updater without cloning individual repositories.