Add GitHub auto-updater#33
Conversation
PeterDaveHello
left a comment
There was a problem hiding this comment.
@jman294 thanks for the PR, please squash the commits into a single one first, thanks!
|
|
||
| var update = function(library, callback) { | ||
| var target = library.autoupdate.target; | ||
| console.log(target) |
There was a problem hiding this comment.
Should git auto-update be touched here?
PeterDaveHello
left a comment
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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' |
There was a problem hiding this comment.
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._); |
|
Sorry for somewhat unprofessional style, squashed all commits into one (I believe). |
| tmp | ||
| git_repo_local_cache/ | ||
|
|
||
| *.swp |
There was a problem hiding this comment.
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')) |
There was a problem hiding this comment.
missing spaces for +
There was a problem hiding this comment.
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.
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 = []; |
There was a problem hiding this comment.
I bet you're right!
| rp({ | ||
| uri:'https://raw.githubusercontent.com/' | ||
| + githubRepo(library.autoupdate.target) + '/' | ||
| + file.tree + '/' + file.basePath + '/' + fileName, |
There was a problem hiding this comment.
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.
|
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.
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.
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.
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.
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.
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.
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.
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.
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.