Permalink
Browse files

Add load config from file

Closes #40
  • Loading branch information...
Kikobeats committed Jun 26, 2018
1 parent 0837525 commit 5b52b63a0fa89ec7fa4b750803d871bfcdeae8dc
Showing with 30 additions and 22 deletions.
  1. +2 −1 bin/cli/extract-urls.js
  2. +11 −11 bin/cli/get-url.js
  3. +14 −8 bin/cli/index.js
  4. +3 −2 package.json
@@ -9,11 +9,12 @@ const got = require('got')
const { isXmlUrl } = fromXML
const fromHTML = async (url, { selector, ...opts }) => {
// TODO: Add prerender support
const { body: rawHtml } = await got(url, opts)
const $ = cheerio.load(rawHtml)
const html = selector ? $(selector).html() : rawHtml
const urls = await getUrlsFromHtml({ url, html, ...opts })
return map(urls, 'normalizeUrl')
return map(urls, 'normalizedUrl')
}
module.exports = (url, opts) => {
@@ -1,18 +1,18 @@
'use strict'
const normalizeUrl = require('normalize-url')
const normalizedUrl = require('normalize-url')
const reachableUrl = require('reachable-url')
const { first } = require('lodash')
const getUrl = cli =>
first(cli.input) ||
process.env.DEPLOY_URL ||
process.env.DEPLOY_PRIME_URL ||
process.env.URL
const getUrl = input =>
normalizedUrl(
input ||
process.env.DEPLOY_URL ||
process.env.DEPLOY_PRIME_URL ||
process.env.URL
)
module.exports = async cli => {
const targetUrl = getUrl(cli)
const normalizedUrl = normalizeUrl(targetUrl)
const { url } = await reachableUrl(normalizedUrl)
module.exports = async input => {
const targetUrl = getUrl(input)
const { url } = await reachableUrl(targetUrl)
return url
}
@@ -2,7 +2,9 @@
'use strict'
const { size, concat, isEmpty } = require('lodash')
const cosmiconfig = require('cosmiconfig')('urlint')
const { first, size, concat, isEmpty } = require('lodash')
const { ci } = require('ci-env')
const urlint = require('@urlint/core')
@@ -22,8 +24,7 @@ const cli = require('meow')(require('./help'), {
flags: {
whitelist: {
alias: 'w',
type: 'array',
default: false
type: 'array'
},
concurrence: {
alias: 'c',
@@ -67,16 +68,21 @@ const cli = require('meow')(require('./help'), {
}
})
;(async () => {
const { config } = (await cosmiconfig.search()) || {}
const input = config.url || first(cli.input)
try {
if (isEmpty(cli.input)) {
if (isEmpty(input)) {
cli.showHelp()
await build.exit({ buildCode: 1, exitCode: 0 })
}
const url = await getUrl(cli)
const opts = Object.assign({}, cli.flags, {
whitelist: cli.flags.whitelist && concat(cli.flags.whitelist)
})
const flags = { ...config, ...cli.flags }
const url = await getUrl(input)
const opts = {
...flags,
whitelist: flags.whitelist && concat(flags.whitelist)
}
await build.start()
const urls = await extractUrls(url, opts)
@@ -37,9 +37,10 @@
"cheerio": "~1.0.0-rc.2",
"ci-env": "~1.6.1",
"clean-stack": "~1.3.0",
"cosmiconfig": "~5.0.5",
"github-build": "~1.2.0",
"got": "~8.3.1",
"html-urls": "~1.0.8",
"html-urls": "~2.0.0",
"lodash": "~4.17.10",
"meow": "~5.0.0",
"neat-log": "~2.4.0",
@@ -48,7 +49,7 @@
"pretty-ms": "~3.2.0",
"reachable-url": "~1.0.1",
"update-notifier": "~2.5.0",
"xml-urls": "~1.0.1"
"xml-urls": "~1.0.2"
},
"devDependencies": {
"ava": "latest",

0 comments on commit 5b52b63

Please sign in to comment.