Permalink
Browse files

Refactor

  • Loading branch information...
Kikobeats committed Jan 28, 2018
1 parent 4367988 commit e45236e7ccc7737ba4254be0c64b1fc0357f3ce8
@@ -0,0 +1,16 @@
'use strict'
const getUrlsFromHtml = require('html-urls')
const fromXML = require('xml-urls')
const got = require('got')
const { isXmlUrl } = fromXML
const fromHTML = async (url, { whitelist, ...opts }) => {
const { body: html } = await got(url, opts)
const urls = await getUrlsFromHtml({ url, html, whitelist })
return urls.map(({ normalizeUrl }) => normalizeUrl)
}
module.exports = async (url, opts) =>
isXmlUrl(url) ? fromXML(url, opts) : fromHTML(url, opts)
@@ -1,8 +1,8 @@
'use strict'
const chalk = require('chalk')
const theme = require('./theme')
const { description } = require('../package.json')
const theme = require('../view/theme')
const { description } = require('../../package.json')
const green = chalk.hex(theme.green)
@@ -12,16 +12,16 @@ module.exports = chalk.gray(`${chalk.gray(description)}
$ ${green('urlint')} url [<flags>]
Options
-i, --ignore Add an url to ignore
-w, --whitelist Add an url to ignore
-v, --version Output the version number
Examples
– Get all HTTP status from an URL
$ ${green('eslint')} https://kikobeats.com
$ ${green('urlint')} https://kikobeats.com
– Exclude a particular URL
$ ${green(
'eslint'
)} https://kikobeats.com --ignore https://www.linkedin.com/in/kikobeats'
'urlint'
)} https://kikobeats.com --whitelist https://www.linkedin.com/in/kikobeats'
`)
@@ -3,22 +3,26 @@
const { size } = require('lodash')
const urlint = require('urlint')
const path = require('path')
const componentPath = path.join(__dirname, './component.js')
const pkg = require('../package.json')
const mount = require('./mount')
const pkg = require('../../package.json')
const getUrls = require('./get-urls')
const view = require('../view')
require('update-notifier')({ pkg }).notify()
const cli = require('meow')(require('./help'), {
pkg,
description: false,
flags: {
ignore: {
alias: 'i',
whitelist: {
alias: 'w',
type: 'array',
default: []
},
concurrence: {
alias: 'c',
type: 'number',
default: 30
}
}
})
@@ -29,14 +33,16 @@ if (cli.input.length === 0) {
}
const [url] = cli.input
const { flags } = cli
const { ignore, ...opts } = flags
const whitelist = [].concat(ignore)
const opts = Object.assign({}, cli.flags, {
whitelist: [].concat(cli.flags.whitelist)
})
;(async () => {
const emitter = await urlint(url, Object.assign({ whitelist }, opts))
const urls = await getUrls(url, opts)
const emitter = await urlint(urls, opts)
console.log()
mount(componentPath, { emitter, ...opts })
view({ emitter, ...opts })
emitter.on('end', data => {
const exitCode = size(data) > 1 ? 1 : 0

This file was deleted.

Oops, something went wrong.
@@ -29,7 +29,7 @@ module.exports = class Counter extends Component {
addStatusCode (statusCode, payload) {
const status = this.state.count[statusCode]
const links = this.state.links[statusCode]
const linkItem = [payload.statusCode, payload.normalizeUrl]
const linkItem = [payload.statusCode, payload.url]
let nextCount
let nextLinks
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,9 @@
'use strict'
const path = require('path')
const componentPath = path.join(__dirname, './component.js')
const mount = require('./mount')
module.exports = props => mount(componentPath, props)
File renamed without changes.
File renamed without changes.
@@ -5,7 +5,7 @@
"version": "1.0.0",
"main": "index.js",
"bin": {
"urlint": "bin/index.js"
"urlint": "./bin/cli/index.js"
},
"author": {
"email": "josefrancisco.verdu@gmail.com",
@@ -33,12 +33,15 @@
],
"dependencies": {
"chalk": "~2.3.0",
"got": "~8.0.3",
"html-urls": "~1.0.3",
"import-jsx": "~1.3.0",
"ink": "~0.4.1",
"lodash": "~4.17.4",
"meow": "~4.0.0",
"update-notifier": "~2.3.0",
"urlint": "~1.0.2"
"urlint": "~1.0.3",
"xml-urls": "~1.0.1"
},
"devDependencies": {
"finepack": "latest",

0 comments on commit e45236e

Please sign in to comment.