Skip to content

Commit

Permalink
Remove lodash dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Feb 3, 2017
1 parent f51fec4 commit 6303bf4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-release-cli",
"version": "0.1.1",
"version": "0.2.0",
"description": "A command-line tool for uploading release assets to a GitHub repository",
"homepage": "https://github.com/cheton/github-release-cli",
"author": "Cheton Wu <[email protected]>",
Expand Down Expand Up @@ -29,8 +29,7 @@
],
"dependencies": {
"commander": "^2.9.0",
"github": "^8.1.1",
"lodash": "^4.17.4"
"github": "^8.1.1"
},
"devDependencies": {
"babel-cli": "^6.22.2",
Expand Down
16 changes: 10 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint no-console: 0 */
/* eslint max-len: 0 */
import path from 'path';
import _ from 'lodash';
import GitHubApi from 'github';
import program from 'commander';
import pkg from '../package.json';
Expand Down Expand Up @@ -122,15 +121,15 @@ const main = async () => {
});
console.log('assets=%d', assets.length);

assets = _.filter(assets, (asset) => {
assets = assets.filter(asset => {
// Example:
// 'cnc-1.1.0-latest-08c256a-linux-x64.tar.gz'
// ["cnc-1.1.0-latest-08c256a-linux-x64.tar.gz", "cnc", "1.1.0-latest-08c256a", "linux", "x64", "tar.gz"]
const pattern = new RegExp(/([a-zA-Z0-9][a-zA-Z0-9\-]*)\-(\d+\.\d+\.\d+(?:\-[a-zA-Z0-9][a-zA-Z0-9\-]*)?)(?:\-(mac|win|linux|tinyweb))(?:(?:\-([a-zA-Z0-9_\-]+))?\.(.*))/);

return _.some(files, (file) => {
const r1 = asset.name.match(pattern);
const r2 = path.basename(file).match(pattern);
return files.some(file => {
let r1 = asset.name.match(pattern);
let r2 = path.basename(file).match(pattern);

if ((r1 === null) || (r2 === null)) {
console.error('Unable to match file: asset="%s", file="%s"', asset.name, path.basename(file));
Expand All @@ -148,7 +147,12 @@ const main = async () => {
r1[0] = r1[2] = undefined;
r2[0] = r2[2] = undefined;

return _.isEqual(_.compact(r1), _.compact(r2));
// compact
r1 = r1.filter(r => r !== undefined && r !== null);
r2 = r2.filter(r => r !== undefined && r !== null);

// compare two arrays
return (r1.length === r2.length) && r1.every((v, i) => v === r2[i]);
});
});

Expand Down

0 comments on commit 6303bf4

Please sign in to comment.