-
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.
add seperate setConfig command and use yargs commands better
- Loading branch information
Showing
9 changed files
with
151 additions
and
51 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
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 |
---|---|---|
@@ -1,22 +1,4 @@ | ||
#!/usr/bin/env node | ||
const fs = require('fs'); | ||
const argv = require('yargs').argv; | ||
const { init } = require('../server/index') | ||
const yargs = require('yargs'); | ||
|
||
if (argv.goodReadsId && argv.goodReadsKey && argv.cookie) { | ||
const config = { | ||
GOODREADS_USER: argv.goodReadsId, | ||
GOODREADS_KEY: argv.goodReadsKey, | ||
COOKIE: argv.cookie | ||
} | ||
|
||
// add config vars to config file | ||
fs.writeFileSync(`${__dirname}/../config.js`, `module.exports = ${JSON.stringify(config)}`, err => { | ||
if (err) console.error(`error writing config file: ${error}`); | ||
else console.log('updated config with your options'); | ||
}) | ||
} | ||
|
||
//TODO error handling | ||
|
||
init(); | ||
yargs.commandDir('../server/commands').argv; |
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 |
---|---|---|
@@ -1 +1,5 @@ | ||
module.exports = { "GOODREADS_USER": "xxxxxxxxxxxxx", "GOODREADS_KEY": "xxxxxxxxxxxxxxxxxxxxxxx", "COOKIE": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } | ||
module.exports = { | ||
"GOODREADS_USER": "", | ||
"GOODREADS_KEY": "", | ||
"COOKIE": "" | ||
} |
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 |
---|---|---|
@@ -1,24 +1,76 @@ | ||
{ | ||
"name": "tsundoku", | ||
"version": "3.0.3", | ||
"description": "", | ||
"bin": "./bin/tsundoku.js", | ||
"author": "jennifer johnson", | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/jkerr321/tsundoku.git" | ||
}, | ||
"license": "MIT", | ||
"dependencies": { | ||
"async-sema": "^3.0.0", | ||
"cheerio": "^1.0.0-rc.2", | ||
"node-fetch": "^2.3.0", | ||
"nodemon": "^1.18.5", | ||
"xml-js": "^1.6.8", | ||
"yargs": "^13.2.2" | ||
}, | ||
"devDependencies": {}, | ||
"scripts": { | ||
"start": "node server/index.js" | ||
} | ||
"_from": "tsundoku", | ||
"_id": "[email protected]", | ||
"_inBundle": false, | ||
"_integrity": "sha512-/HxPrAfN+CR9jKNOgus9kMl2FrrA6RCEcDzyTW3U4lh543SCAicb1qMR0qCDxwFrsFOVvmHABZtBXQjGGyNI7w==", | ||
"_location": "/tsundoku", | ||
"_phantomChildren": { | ||
"decamelize": "1.2.0", | ||
"emoji-regex": "7.0.3", | ||
"is-stream": "1.1.0", | ||
"locate-path": "3.0.0", | ||
"mem": "4.3.0", | ||
"nice-try": "1.0.5", | ||
"npm-run-path": "2.0.2", | ||
"p-finally": "1.0.0", | ||
"path-key": "2.0.1", | ||
"pump": "3.0.0", | ||
"require-directory": "2.1.1", | ||
"set-blocking": "2.0.0", | ||
"shebang-command": "1.2.0", | ||
"signal-exit": "3.0.2", | ||
"strip-eof": "1.0.0", | ||
"which": "1.2.12", | ||
"wrap-ansi": "2.1.0" | ||
}, | ||
"_requested": { | ||
"type": "tag", | ||
"registry": true, | ||
"raw": "tsundoku", | ||
"name": "tsundoku", | ||
"escapedName": "tsundoku", | ||
"rawSpec": "", | ||
"saveSpec": null, | ||
"fetchSpec": "latest" | ||
}, | ||
"_requiredBy": [ | ||
"#USER", | ||
"/" | ||
], | ||
"_resolved": "https://registry.npmjs.org/tsundoku/-/tsundoku-3.1.0.tgz", | ||
"_shasum": "095f9afeeb7df643c69d8827430e9f29f5390832", | ||
"_spec": "tsundoku", | ||
"_where": "/Users/jenniferkerr/projects", | ||
"author": { | ||
"name": "jennifer johnson" | ||
}, | ||
"bin": { | ||
"tsundoku": "./bin/tsundoku.js" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/jkerr321/tsundoku/issues" | ||
}, | ||
"bundleDependencies": false, | ||
"dependencies": { | ||
"async-sema": "^3.0.0", | ||
"cheerio": "^1.0.0-rc.2", | ||
"node-fetch": "^2.3.0", | ||
"nodemon": "^1.18.5", | ||
"xml-js": "^1.6.8", | ||
"yargs": "^13.2.2" | ||
}, | ||
"deprecated": false, | ||
"description": "Tsundoku ========== A tool that outputs the books in your Goodreads `To Read` list in a csv file, along with their Amazon prices for different formats.", | ||
"devDependencies": {}, | ||
"homepage": "https://github.com/jkerr321/tsundoku#readme", | ||
"license": "MIT", | ||
"name": "tsundoku", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/jkerr321/tsundoku.git" | ||
}, | ||
"scripts": { | ||
"start": "node server/index.js" | ||
}, | ||
"version": "3.1.0" | ||
} |
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,9 @@ | ||
const { init } = require('../index'); | ||
|
||
exports.command = 'run'; | ||
|
||
exports.describe = 'get goodReads book list - you need to add your config details first'; | ||
|
||
exports.handler = (argv = {}) => { | ||
init(); | ||
} |
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,42 @@ | ||
|
||
const fs = require('fs'); | ||
const configFile = require('../../config'); | ||
|
||
exports.command = 'setConfig [goodReadsId] [goodReadsKey] [cookie]'; | ||
|
||
exports.describe = 'Search a file within a repository'; | ||
|
||
exports.builder = yargs => { | ||
return yargs | ||
.positional('goodReadsId', { | ||
type: 'string', | ||
describe: '8 character Good Reads user ID' | ||
}) | ||
.positional('goodReadsKey', { | ||
type: 'string', | ||
describe: 'good reads developer API key' | ||
}) | ||
.positional('cookie', { | ||
type: 'string', | ||
describe: 'Amazon cookie string' | ||
}) | ||
}; | ||
|
||
exports.handler = (argv = {}) => { | ||
const { goodReadsId, goodReadsKey, cookie } = argv; | ||
|
||
let configObj = {}; | ||
goodReadsId ? configObj.GOODREADS_USER = goodReadsId : configObj.GOODREADS_USER = configFile.GOODREADS_USER; | ||
goodReadsKey ? configObj.GOODREADS_KEY = goodReadsKey : configObj.GOODREADS_KEY = configFile.GOODREADS_KEY; | ||
cookie ? configObj.COOKIE = cookie : configObj.COOKIE = configFile.COOKIE; | ||
|
||
// add config vars to config file | ||
fs.writeFileSync(`${__dirname}/../../config.js`, `module.exports = ${JSON.stringify(configObj)}`, err => { | ||
if (err) console.error(`error writing config file: ${error}`); | ||
else { | ||
console.log('updated config with your options'); | ||
} | ||
}) | ||
|
||
console.log('** Success! Your config has been set **') | ||
} |
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
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
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