Skip to content

Commit

Permalink
📦 update package.json and create bin
Browse files Browse the repository at this point in the history
  • Loading branch information
edkf committed Nov 9, 2017
1 parent a6112a7 commit dcdc81b
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 44 deletions.
85 changes: 45 additions & 40 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,48 +11,53 @@ const parseBadge = require('./src/parseBadge.js')

// Start the code here

setTitle('📰 dncli - CLI to browse designernews.co')
const dncli = () => {

scrapeIt(
process.argv[2] ? `https://www.designernews.co/badges/${process.argv[2]}` : 'https://www.designernews.co'
, {
stories: {
listItem: '.montana-list-item',
data: {
id: {
attr: 'data-story-id'
},
upvotes: '.upvoted-number',
title: {
selector: '.montana-item-title',
attr: 'alt'
},
url: {
selector: '.montana-item-title',
attr: 'href'
},
timeAgo: '.list-story-time-ago',
from: '.montana-item-meta span a'
setTitle('📰 dncli - CLI to browse designernews.co')

scrapeIt(
process.argv[2] ? `https://www.designernews.co/badges/${process.argv[2]}` : 'https://www.designernews.co'
, {
stories: {
listItem: '.montana-list-item',
data: {
id: {
attr: 'data-story-id'
},
upvotes: '.upvoted-number',
title: {
selector: '.montana-item-title',
attr: 'alt'
},
url: {
selector: '.montana-item-title',
attr: 'href'
},
timeAgo: '.list-story-time-ago',
from: '.montana-item-meta span a'
}
}
}
}).then(data => {
const storiesQuestions = {
type: 'list',
name: 'selectedStorie',
message: 'Select a story to read',
pageSize: 30,
choices: data.stories.map(item => {
return {
name: `${chalk.green('â–´')} ${chalk.gray(`${ ('0' + Number(item.upvotes)).slice(-2)} |`)} ${item.title} ${chalk.gray(`- by ${item.from} (${item.timeAgo})`)}`,
value: item.id
}).then(data => {
const storiesQuestions = {
type: 'list',
name: 'selectedStorie',
message: 'Select a story to read',
pageSize: 30,
choices: data.stories.map(item => {
return {
name: `${chalk.green('â–´')} ${chalk.gray(`${ ('0' + Number(item.upvotes)).slice(-2)} |`)} ${item.title} ${chalk.gray(`- by ${item.from} (${item.timeAgo})`)}`,
value: item.id
}
})
}
inquirer.prompt([storiesQuestions]).then(function (answer) {
for (let i = 0; i < data.stories.length; i++) {
if (data.stories[i].id === answer.selectedStorie) {
openurl.open(data.stories[i].url.includes('http') ? data.stories[i].url : 'https://www.designernews.co' + data.stories[i].url)
}
}
})
}
inquirer.prompt([storiesQuestions]).then(function (answer) {
for (let i = 0; i < data.stories.length; i++) {
if (data.stories[i].id === answer.selectedStorie) {
openurl.open(data.stories[i].url.includes('http') ? data.stories[i].url : 'https://www.designernews.co' + data.stories[i].url)
}
}
})
})
}

exports.dncli = dncli
5 changes: 5 additions & 0 deletions bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

var app = require('./app.js')

app.dncli()
24 changes: 20 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
{
"name": "dncli",
"version": "0.0.1",
"description": "",
"description": "CLI to browse designernews.co",
"license": "MIT",
"bin": {
"dncli": "bin.js"
},
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "nodemon app.js"
},
"author": "",
"license": "ISC",
"author": {
"name": "Edgard Kozlowski",
"email": "[email protected]",
"url": "edkf.com.br"
},
"keywords": [
"cli",
"dn",
"designer",
"news",
"feed",
"rss",
"reader",
"app"
],
"dependencies": {
"chalk": "^2.3.0",
"inquirer": "^3.3.0",
Expand Down

0 comments on commit dcdc81b

Please sign in to comment.