-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Rafael Grigorian
committed
May 7, 2019
0 parents
commit f5c51ac
Showing
13 changed files
with
2,234 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
/node_modules/ | ||
/dist/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "magerepo-cli", | ||
"version": "2.0.0", | ||
"description": "Cross-platform CLI tool to interact with the MageRepo API", | ||
"main": "src/index.js", | ||
"repository": "[email protected]:magerepo/magerepo-cli.git", | ||
"author": "Rafael Grigorian <[email protected]>", | ||
"license": "MIT", | ||
"private": true, | ||
"scripts": { | ||
"package": "pkg --out-path dist --config package.json src/index.js" | ||
}, | ||
"dependencies": { | ||
"axios": "^0.18.0", | ||
"chalk": "^2.4.2", | ||
"minimist": "^1.2.0", | ||
"shelljs": "^0.8.3", | ||
"strip-ansi": "^5.0.0", | ||
"targz": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"pkg": "^4.3.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
const path = require ("path") | ||
const fs = require ("fs") | ||
|
||
const HOME = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE | ||
const CONFIG_PATH = path.join ( HOME, ".magerepo" ) | ||
|
||
function load () { | ||
let credentials = { | ||
username: "", | ||
password: "" | ||
} | ||
try { | ||
if ( fs.existsSync ( CONFIG_PATH ) ) { | ||
let data = fs.readFileSync ( CONFIG_PATH ).toString () | ||
credentials = JSON.parse ( data ) | ||
} | ||
} | ||
catch ( error ) {} | ||
finally { | ||
return credentials | ||
} | ||
} | ||
|
||
function save ( username, password ) { | ||
let data = JSON.stringify ({ username, password }) | ||
fs.writeFileSync ( CONFIG_PATH, data ) | ||
} | ||
|
||
function remove () { | ||
if ( fs.existsSync ( CONFIG_PATH ) ) { | ||
fs.unlinkSync ( CONFIG_PATH ) | ||
return true | ||
} | ||
return false | ||
} | ||
|
||
module.exports = { | ||
load, | ||
save, | ||
remove | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const chalk = require ("chalk") | ||
const readline = require ("readline") | ||
const strip = require ("strip-ansi") | ||
const { save } = require ("../account") | ||
|
||
function auth ( context ) { | ||
let usernamePrompt = `${chalk.green ("Username")}: ` | ||
let passwordPrompt = `${chalk.green ("Password")}: ` | ||
if ( context.quiet ) { | ||
usernamePrompt = "" | ||
passwordPrompt = "" | ||
} | ||
else if ( context.unicode ) { | ||
usernamePrompt = strip ( usernamePrompt ) | ||
passwordPrompt = strip ( passwordPrompt ) | ||
} | ||
const rl = readline.createInterface ({ | ||
input: process.stdin, | ||
output: process.stdout | ||
}) | ||
rl.question ( usernamePrompt, username => { | ||
rl.question ( passwordPrompt, password => { | ||
save ( username, password ) | ||
context.log ("credentials saved to ~/.magerepo") | ||
rl.close () | ||
}) | ||
}) | ||
} | ||
|
||
module.exports = auth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const chalk = require ("chalk") | ||
|
||
function help ( context ) { | ||
context.log (`MageRepo is made possible by ${chalk.green.bold (">")}${chalk.white.bold ("jet")}${chalk.gray.bold ("rails")}${chalk.green.bold ("_")}`) | ||
context.log (``) | ||
context.log (`${chalk.bold ("usage")}:`) | ||
context.log (` magerepo [${chalk.yellow ("...flags")}] <${chalk.green ("command")}> [${chalk.blue ("...options")}]`) | ||
context.log (``) | ||
context.log (`${chalk.bold ("commands")}:`) | ||
context.log (` ${chalk.green ("release")} looking for release`) | ||
context.log (` ${chalk.green ("patch")} looking for patches`) | ||
context.log (` ${chalk.green ("auth")} Store magerepo credentials`) | ||
context.log (` ${chalk.green ("unauth")} Remove stored credentials`) | ||
context.log (``) | ||
context.log (`${chalk.bold ("flags")}:`) | ||
context.log (` ${chalk.yellow ("-h")}, ${chalk.yellow ("--help")} Display help menu`) | ||
context.log (` ${chalk.yellow ("-v")}, ${chalk.yellow ("--version")} Display version`) | ||
context.log (` ${chalk.yellow ("-q")}, ${chalk.yellow ("--quiet")} Do not display anything`) | ||
context.log (` ${chalk.yellow ("-u")}, ${chalk.yellow ("--unicode")} Only display unicode characters`) | ||
context.log (` ${chalk.yellow ("-c")}, ${chalk.yellow ("--clean")} Delete all archives before exiting`) | ||
context.log (``) | ||
context.log (`${chalk.bold ("options")}:`) | ||
context.log (` ${chalk.blue ("-e")}, ${chalk.blue ("--edition")} Specify edition [ce|ee]`) | ||
context.log (` ${chalk.blue ("-r")}, ${chalk.blue ("--release")} Specify release, i.e. 1.9.3.1`) | ||
context.log (` ${chalk.blue ("-p")}, ${chalk.blue ("--patch")} Specify patch name, i.e. supee-1000-v1`) | ||
context.log (` ${chalk.blue ("-d")}, ${chalk.blue ("--download")} [path] Download results, optionally specify path`) | ||
context.log (` ${chalk.blue ("-x")}, ${chalk.blue ("--extract")} [path] Extract, default extracted at download location`) | ||
context.log (``) | ||
context.log (`examples:`) | ||
context.log (` magerepo ${chalk.green ("auth")}`) | ||
context.log (` magerepo ${chalk.green ("unauth")}`) | ||
context.log (` magerepo ${chalk.green ("release")}`) | ||
context.log (` magerepo ${chalk.green ("release")} ${chalk.blue ("-e")} ce`) | ||
context.log (` magerepo ${chalk.green ("release")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} x`) | ||
context.log (` magerepo ${chalk.green ("release")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 2.x`) | ||
context.log (` magerepo ${chalk.green ("release")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 1.9.3.1`) | ||
context.log (` magerepo ${chalk.green ("release")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 1.x ${chalk.blue ("-d")} ${chalk.blue ("-x")}`) | ||
context.log (` magerepo ${chalk.green ("release")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 1.9.3.1 ${chalk.blue ("-d")} ${chalk.blue ("-x")} ${chalk.blue ("-c")}`) | ||
context.log (` magerepo ${chalk.green ("release")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 1.9.3.1 ${chalk.blue ("-d")} /var/www/html`) | ||
context.log (` magerepo ${chalk.green ("release")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 1.9.3.1 ${chalk.blue ("-d")} /var/www ${chalk.blue ("-x")} /var/www/html`) | ||
context.log (` magerepo ${chalk.green ("patch")}`) | ||
context.log (` magerepo ${chalk.green ("patch")} ${chalk.blue ("-e")} ce`) | ||
context.log (` magerepo ${chalk.green ("patch")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 1.9.3.1`) | ||
context.log (` magerepo ${chalk.green ("patch")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 1.9.3.1 ${chalk.blue ("-p")} supee-1000-v1`) | ||
context.log (` magerepo ${chalk.green ("patch")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 1.9.3.1 ${chalk.blue ("-d")}`) | ||
context.log (` magerepo ${chalk.green ("patch")} ${chalk.blue ("-e")} ce ${chalk.blue ("-r")} 1.9.3.1 ${chalk.blue ("-p")} supee-1000-v1 ${chalk.blue ("-d")}`) | ||
} | ||
|
||
module.exports = help |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
auth: require ("./auth"), | ||
help: require ("./help"), | ||
patch: require ("./patch"), | ||
release: require ("./release"), | ||
unauth: require ("./unauth") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
const chalk = require ("chalk") | ||
|
||
function metadata ( patches ) { | ||
if ( patches.length < 1 ) { | ||
return Promise.reject (`could not find patch(s)`) | ||
} | ||
this.log ( | ||
chalk.underline ( "File Size" ), | ||
chalk.underline ( "Date".padEnd ( 10, " " ) ), | ||
chalk.underline ( "Edition".padEnd ( 10, " " ) ), | ||
chalk.underline ( "Release".padEnd ( 10, " " ) ), | ||
chalk.underline ( "File Name".padEnd ( 19, " " ) ) | ||
) | ||
for ( let patch of patches ) { | ||
let filesize = patch.file_size_auto.split (" ") | ||
this.log ( | ||
filesize [ 0 ].padStart ( 6, " " ) + " " + filesize [ 1 ].padEnd( 2, " " ), | ||
patch.info_date.padEnd ( 10, " " ), | ||
patch.info_edition_short.padEnd ( 10, " " ), | ||
patch.info_release.padEnd ( 10, " " ), | ||
chalk.red.bold ( patch.file_name.padEnd ( 19, " " ) ) | ||
) | ||
} | ||
return Promise.resolve () | ||
} | ||
|
||
function download ( patches ) { | ||
if ( patches.length < 1 ) { | ||
return Promise.reject (`could not find patch(s)`) | ||
} | ||
return patches.reduce ( ( chain, patch ) => | ||
chain.then ( | ||
() => this.download ( | ||
patch.file_download_link.replace ( /^\/download\//m, "" ) | ||
) | ||
), | ||
Promise.resolve () | ||
) | ||
.catch ( error => | ||
Promise.reject ( | ||
`${error.response.statusText} (${error.response.status})` | ||
) | ||
) | ||
} | ||
|
||
function patch ( context ) { | ||
if ( context.downloadPath && context.edition && context.release && context.patch ) { | ||
return context.metadata (`patch/${context.edition}/${context.release}/${context.patch}`) | ||
.then ( download.bind ( context ) ) | ||
} | ||
else if ( context.downloadPath && context.edition && context.release ) { | ||
return context.metadata (`patch/${context.edition}/${context.release}`) | ||
.then ( download.bind ( context ) ) | ||
} | ||
else if ( context.edition && context.release && context.patch ) { | ||
return context.metadata (`patch/${context.edition}/${context.release}/${context.patch}`) | ||
.then ( metadata.bind ( context ) ) | ||
} | ||
else if ( context.edition && context.release ) { | ||
return context.metadata (`patch/${context.edition}/${context.release}`) | ||
.then ( metadata.bind ( context ) ) | ||
} | ||
else if ( context.edition ) { | ||
return context.metadata (`patch/${context.edition}`) | ||
.then ( metadata.bind ( context ) ) | ||
} | ||
else { | ||
return context.metadata (`patch`) | ||
.then ( metadata.bind ( context ) ) | ||
} | ||
} | ||
|
||
module.exports = patch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
const chalk = require ("chalk") | ||
const path = require ("path") | ||
|
||
function metadata ( releases ) { | ||
if ( releases.length < 1 ) { | ||
return Promise.reject (`could not find release(s)`) | ||
} | ||
this.log ( | ||
chalk.underline ( "File Size" ), | ||
chalk.underline ( "Date".padEnd ( 10, " " ) ), | ||
chalk.underline ( "File Name".padEnd ( 19, " " ) ) | ||
) | ||
for ( let release of releases ) { | ||
let filesize = release.file_size_auto.split (" ") | ||
this.log ( | ||
filesize [ 0 ].padStart ( 6, " " ) + " " + filesize [ 1 ].padEnd( 2, " " ), | ||
release.info_date.padEnd ( 10, " " ), | ||
chalk.red.bold ( release.file_name.padEnd ( 19, " " ) ) | ||
) | ||
} | ||
return Promise.resolve () | ||
} | ||
|
||
function download ( releases ) { | ||
if ( releases.length < 1 ) { | ||
return Promise.reject (`could not find release(s)`) | ||
} | ||
let release = releases.splice ( -1 ) [ 0 ] | ||
let link = release.file_download_link.replace ( /^\/download\//m, "" ) | ||
let filepath = path.join ( this.downloadPath, release.file_name ) | ||
return this.download ( link ) | ||
.then ( () => this.extractPath && this.extract ( filepath ) ) | ||
.then ( () => this.extractPath && this.clean && this.cleanup ( filepath ) ) | ||
.catch ( error => | ||
Promise.reject ( | ||
`${error.response.statusText} (${error.response.status})` | ||
) | ||
) | ||
} | ||
|
||
function release ( context ) { | ||
if ( context.downloadPath && context.edition && context.release ) { | ||
return context.metadata (`release/${context.edition}/${context.release}`) | ||
.then ( download.bind ( context ) ) | ||
} | ||
else if ( context.edition && context.release ) { | ||
return context.metadata (`release/${context.edition}/${context.release}`) | ||
.then ( metadata.bind ( context ) ) | ||
} | ||
else if ( context.edition ) { | ||
return context.metadata (`release/${context.edition}`) | ||
.then ( metadata.bind ( context ) ) | ||
} | ||
else { | ||
return context.metadata (`release`) | ||
.then ( metadata.bind ( context ) ) | ||
} | ||
} | ||
|
||
module.exports = release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const chalk = require ("chalk") | ||
const readline = require ("readline") | ||
const strip = require ("strip-ansi") | ||
const { remove } = require ("../account") | ||
|
||
function unauth ( context ) { | ||
if ( remove () ) { | ||
context.log ("credentials removed from ~/.magerepo") | ||
} | ||
else { | ||
context.log ("credentials do not exist in ~/.magerepo") | ||
} | ||
} | ||
|
||
module.exports = unauth |
Oops, something went wrong.