Skip to content

Commit

Permalink
Add prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Rowno committed Dec 6, 2017
1 parent 792888b commit 74b3f1e
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 50 deletions.
24 changes: 12 additions & 12 deletions lib/__tests__/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ function formatUrls(urls) {
test('should extract urls from sitemap file', () => {
const sitemapPath = path.join(__dirname, 'fixtures/sitemap.xml')

return execa(CLI, [sitemapPath], {input: '', stripEof: false}).then(result => {
expect(result.stdout).toBe(formatUrls([
'http://example.com/',
'http://example.com/test/'
]))
expect(result.stderr).toBe('')
})
return execa(CLI, [sitemapPath], { input: '', stripEof: false }).then(
result => {
expect(result.stdout).toBe(
formatUrls(['http://example.com/', 'http://example.com/test/'])
)
expect(result.stderr).toBe('')
}
)
})

test('should extract urls from stdin', () => {
Expand All @@ -35,11 +36,10 @@ test('should extract urls from stdin', () => {
</urlset>
`

return execa(CLI, [], {input: stdin, stripEof: false}).then(result => {
expect(result.stdout).toBe(formatUrls([
'http://example.com/',
'http://example.com/test/'
]))
return execa(CLI, [], { input: stdin, stripEof: false }).then(result => {
expect(result.stdout).toBe(
formatUrls(['http://example.com/', 'http://example.com/test/'])
)
expect(result.stderr).toBe('')
})
})
5 changes: 1 addition & 4 deletions lib/__tests__/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ describe('#extractUrls', () => {
</urlset>
`)

expect(urls).toEqual([
'http://example.com/',
'http://example.com/test/'
])
expect(urls).toEqual(['http://example.com/', 'http://example.com/test/'])
})

test('should not include duplicate urls', () => {
Expand Down
33 changes: 18 additions & 15 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const meow = require('meow')
const stdin = require('get-stdin')
const sitemapUrls = require('../')

const cli = meow(`
const cli = meow(
`
Usage: sitemap-urls <path> [<options>]
Path:
Expand All @@ -18,39 +19,41 @@ Path:
Options:
-h, --help Show this help text.
-v, --version Print sitemap-urls' version.
`, {
flags: {
help: {
type: 'boolean',
alias: 'h'
},
version: {
type: 'boolean',
alias: 'v'
`,
{
flags: {
help: {
type: 'boolean',
alias: 'h'
},
version: {
type: 'boolean',
alias: 'v'
}
}
}
})
)

stdin().then(stdinSitemap => {
let filepath
let sitemap

// Require stdin or file
// Require stdin or file
if (!stdinSitemap && !cli.input[0]) {
cli.showHelp()
}

// Try reading file if no stdin
// Try reading file if no stdin
if (stdinSitemap) {
sitemap = stdinSitemap
} else {
filepath = path.resolve(cli.input[0])
if (!fs.existsSync(filepath) || !fs.statSync(filepath).isFile()) {
console.error('File doesn\'t exist:', filepath)
console.error("File doesn't exist:", filepath)
process.exit(1)
}

sitemap = fs.readFileSync(filepath, {encoding: 'utf8'})
sitemap = fs.readFileSync(filepath, { encoding: 'utf8' })
}

const urls = sitemapUrls.extractUrls(sitemap)
Expand Down
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const cheerio = require('cheerio')

function extractUrls(xml) {
const urls = []
const $ = cheerio.load(xml, {xmlMode: true})
const $ = cheerio.load(xml, { xmlMode: true })

$('loc').each(function () {
$('loc').each(function() {
const url = $(this).text()

if (urls.indexOf(url) < 0) {
Expand Down
28 changes: 12 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
"version": "2.0.0",
"description": "Extract URLs from an XML sitemap.",
"author": "Roland Warmerdam (https://roland.codes)",
"keywords": [
"sitemap",
"url",
"parse",
"extract"
],
"keywords": ["sitemap", "url", "parse", "extract"],
"repository": "Rowno/sitemap-urls",
"license": "MIT",
"main": "lib/index.js",
Expand All @@ -28,31 +23,32 @@
"meow": "^4.0.0"
},
"devDependencies": {
"eslint-config-prettier": "^2.9.0",
"execa": "^0.8.0",
"husky": "^0.14.3",
"jest": "^21.2.1",
"lint-staged": "^6.0.0",
"prettier": "^1.9.1",
"xo": "^0.18.2"
},
"files": [
"lib"
],
"files": ["lib"],
"xo": {
"space": true,
"semicolon": false,
"extends": ["prettier"],
"overrides": [
{
"files": "**/__tests__/**/*.js",
"envs": [
"jest"
]
"envs": ["jest"]
}
]
},
"prettier": {
"semi": false,
"singleQuote": true
},
"lint-staged": {
"*.js": [
"xo --fix",
"git add"
]
"*.js": ["xo --fix", "prettier --write", "git add"],
"*.json": ["prettier --write", "git add"]
}
}
12 changes: 11 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,12 @@ escope@^3.6.0:
esrecurse "^4.1.0"
estraverse "^4.1.1"

eslint-config-prettier@^2.9.0:
version "2.9.0"
resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-2.9.0.tgz#5ecd65174d486c22dff389fe036febf502d468a3"
dependencies:
get-stdin "^5.0.1"

eslint-config-xo@^0.18.0:
version "0.18.2"
resolved "https://registry.yarnpkg.com/eslint-config-xo/-/eslint-config-xo-0.18.2.tgz#0a157120875619929e735ffd6b185c41e8a187af"
Expand Down Expand Up @@ -1407,7 +1413,7 @@ get-stdin@^4.0.1:
version "4.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe"

get-stdin@^5.0.0:
get-stdin@^5.0.0, get-stdin@^5.0.1:
version "5.0.1"
resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-5.0.1.tgz#122e161591e21ff4c52530305693f20e6393a398"

Expand Down Expand Up @@ -3062,6 +3068,10 @@ preserve@^0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"

prettier@^1.9.1:
version "1.9.1"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.9.1.tgz#41638a0d47c1efbd1b7d5a742aaa5548eab86d70"

pretty-format@^21.2.1:
version "21.2.1"
resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-21.2.1.tgz#ae5407f3cf21066cd011aa1ba5fce7b6a2eddb36"
Expand Down

0 comments on commit 74b3f1e

Please sign in to comment.