Permalink
Browse files

WIP

  • Loading branch information...
Kikobeats committed Jan 27, 2018
0 parents commit 119221aefdf781c9b707b8a068a757c10cd51c1e
Showing with 447 additions and 0 deletions.
  1. +21 −0 .bumpedrc
  2. +22 −0 .editorconfig
  3. +1 −0 .gitattributes
  4. +34 −0 .gitignore
  5. +4 −0 .npmrc
  6. +5 −0 .travis.yml
  7. +21 −0 LICENSE
  8. +25 −0 README.md
  9. +117 −0 bin/component.js
  10. +12 −0 bin/constants.js
  11. +27 −0 bin/help.js
  12. +13 −0 bin/help.txt
  13. +8 −0 bin/helpers.js
  14. +45 −0 bin/index.js
  15. +6 −0 bin/mount.js
  16. +8 −0 bin/theme.js
  17. +78 −0 package.json
@@ -0,0 +1,21 @@
files:
- package.json
plugins:
prerelease:
Linting config files:
plugin: bumped-finepack
postrelease:
Generating CHANGELOG file:
plugin: bumped-changelog
Committing new version:
plugin: bumped-terminal
command: 'git add CHANGELOG.md package.json && git commit -m "Release $newVersion"'
Detecting problems before publish:
plugin: bumped-terminal
command: 'git-dirty && npm test'
Publishing tag to GitHub:
plugin: bumped-terminal
command: 'git tag $newVersion && git push && git push --tags'
Publishing to NPM:
plugin: bumped-terminal
command: npm publish
@@ -0,0 +1,22 @@
# http://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
max_line_length = 100
indent_brace_style = 1TBS
spaces_around_operators = true
quote_type = auto
[package.json]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
@@ -0,0 +1 @@
* text=auto
@@ -0,0 +1,34 @@
############################
# npm
############################
node_modules
npm-debug.log
.node_history
yarn.lock
package-lock.json
############################
# tmp, editor & OS files
############################
.tmp
*.swo
*.swp
*.swn
*.swm
.DS_Store
*#
*~
.idea
*sublime*
nbproject
############################
# Tests
############################
testApp
coverage
.nyc_output
############################
# Other
############################
4 .npmrc
@@ -0,0 +1,4 @@
unsafe-perm=true
save-prefix=~
shrinkwrap=false
save=false
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "node"
- "lts/*"
after_success: npm run coveralls
21 LICENSE
@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright © 2018 Kiko Beats <josefrancisco.verdu@gmail.com> (kikobeats.com)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@@ -0,0 +1,25 @@
# urlint-cli
![Last version](https://img.shields.io/github/tag/Kikobeats/urlint-cli.svg?style=flat-square)
[![Build Status](https://img.shields.io/travis/Kikobeats/urlint-cli/master.svg?style=flat-square)](https://travis-ci.org/Kikobeats/urlint-cli)
[![Coverage Status](https://img.shields.io/coveralls/Kikobeats/urlint-cli.svg?style=flat-square)](https://coveralls.io/github/Kikobeats/urlint-cli)
[![Dependency status](https://img.shields.io/david/Kikobeats/urlint-cli.svg?style=flat-square)](https://david-dm.org/Kikobeats/urlint-cli)
[![Dev Dependencies Status](https://img.shields.io/david/dev/Kikobeats/urlint-cli.svg?style=flat-square)](https://david-dm.org/Kikobeats/urlint-cli#info=devDependencies)
[![NPM Status](https://img.shields.io/npm/dm/urlint-cli.svg?style=flat-square)](https://www.npmjs.org/package/urlint-cli)
[![Donate](https://img.shields.io/badge/donate-paypal-blue.svg?style=flat-square)](https://paypal.me/Kikobeats)
> Lint an URL from your CLI.
## Install
```bash
$ npm install urlint-cli --global
```
## License
**urlint-cli** © [Kiko Beats](https://kikobeats.com), released under the [MIT](https://github.com/Kikobeats/urlint-cli/blob/master/LICENSE.md) License.<br>
Authored and maintained by Kiko Beats with help from [contributors](https://github.com/Kikobeats/urlint-cli/contributors).
> [kikobeats.com](https://kikobeats.com) · GitHub [@Kiko Beats](https://github.com/Kikobeats) · Twitter [@Kikobeats](https://twitter.com/Kikobeats)
@@ -0,0 +1,117 @@
'use strict'
/* eslint no-unused-vars: ["error", { "varsIgnorePattern": "h" }] */
const { h, Indent, Component, Text } = require('ink')
const { reduce, map } = require('lodash')
const chalk = require('chalk')
const os = require('os')
const { getStatusColor } = require('./helpers')
module.exports = class Counter extends Component {
constructor (props) {
super(props)
this.state = {
count: {},
links: {}
}
const { emitter } = props
emitter.on('*', (eventName, data) => {
if (eventName !== 'end') this.addStatusCode(eventName, data)
else this.setState({ end: true })
})
}
addStatusCode (statusCode, payload) {
const status = this.state.count[statusCode]
const links = this.state.links[statusCode]
const linkItem = [payload.statusCode, payload.normalizeUrl]
let nextCount
let nextLinks
if (status === undefined) {
nextCount = { [statusCode]: 1 }
} else {
nextCount = { [statusCode]: status + 1 }
}
if (links === undefined) {
nextLinks = { [statusCode]: [linkItem] }
} else {
nextLinks = { [statusCode]: links.concat([linkItem]) }
}
this.setState({
count: { ...this.state.count, ...nextCount },
links: { ...this.state.links, ...nextLinks }
})
}
printStatusCode (statusCode, count) {
return (
<Indent size={1}>
<Text hex={getStatusColor(statusCode)}>
· {statusCode} {count}
</Text>
</Indent>
)
}
printUrl (statusCode, url) {
const prettyStatusCode = chalk.hex(getStatusColor(statusCode))(statusCode)
const prettyUrl = chalk.gray(url)
return ` ${prettyStatusCode} ${prettyUrl}`
}
renderStatusCode (status) {
return map(status, (count, stat) => (
<div>{this.printStatusCode(stat, count)}</div>
))
}
renderLinks (status, links) {
const total = reduce(status, (acc, count) => acc + count, 0)
const details = map(status, (count, stat) => {
const urls = map(links[stat], ([statusCode, url]) =>
this.printUrl(statusCode, url)
).join(os.EOL)
return (
<span>
<div>{this.printStatusCode(stat, count)}</div>
<div>
{urls}
<div />
</div>
</span>
)
})
return (
<span>
<div>{details}</div>
<span>
<Indent size={3}>{chalk.gray(`Total ${total}`)}</Indent>
</span>
</span>
)
}
render () {
return (
<span>
{!this.state.end
? this.renderStatusCode(this.state.count)
: this.props.minimal
? this.renderStatusCode(this.state.count)
: this.renderLinks(this.state.count, this.state.links)}
</span>
)
}
}
@@ -0,0 +1,12 @@
const { red, green, yellow, blue, magenta } = require('./theme')
module.exports = {
STATUS_COLORS: {
'2': green,
'3': blue,
'4': yellow,
'5': red,
'9': red
},
STATUS_COLORS_FALLBACK: magenta
}
@@ -0,0 +1,27 @@
'use strict'
const chalk = require('chalk')
const theme = require('./theme')
const { description } = require('../package.json')
const green = chalk.hex(theme.green)
module.exports = chalk.gray(`${chalk.gray(description)}
Usage
$ ${green('urlint')} url [<flags>]
Options
-i, --ignore Add an url to ignore
-v, --version Output the version number
Examples
– Get all HTTP status from an URL
$ ${green('eslint')} https://kikobeats.com
– Exclude a particular URL
$ ${green(
'eslint'
)} https://kikobeats.com --ignore https://www.linkedin.com/in/kikobeats'
`)
@@ -0,0 +1,13 @@
Usage
$ urlint-cli <command>[options]
Commands
--file Read the file
Options
--wait Wait for the app to exit
Examples
$ npm-url # Open the current package if you are over package.json path.
$ npm-url json-future
$ npm-url json-future -- 'google chrome' --incognito
@@ -0,0 +1,8 @@
'use strict'
const { STATUS_COLORS, STATUS_COLORS_FALLBACK } = require('./constants')
const getStatusColor = status =>
STATUS_COLORS[status.toString().charAt(0)] || STATUS_COLORS_FALLBACK
module.exports = { getStatusColor }
@@ -0,0 +1,45 @@
#!/usr/bin/env node
'use strict'
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')
require('update-notifier')({ pkg }).notify()
const cli = require('meow')(require('./help'), {
pkg,
description: false,
flags: {
ignore: {
alias: 'i',
type: 'array',
default: []
}
}
})
if (cli.input.length === 0) {
cli.showHelp()
process.exit()
}
const [url] = cli.input
const { flags } = cli
const { ignore, ...opts } = flags
const whitelist = [].concat(ignore)
;(async () => {
const emitter = await urlint(url, Object.assign({ whitelist }, opts))
console.log()
mount(componentPath, { emitter, ...opts })
emitter.on('end', data => {
const exitCode = size(data) > 1 ? 1 : 0
setTimeout(process.exit, 300, exitCode)
})
})()
@@ -0,0 +1,6 @@
'use strict'
const importJsx = require('import-jsx')
const { h, render } = require('ink')
module.exports = (component, props) => render(h(importJsx(component), props))
@@ -0,0 +1,8 @@
module.exports = {
red: '#ff5c57',
green: '#5af78e',
yellow: '#f3f99d',
blue: '#57c7ff',
magenta: '#ff6ac1',
cyan: '#9aedfe'
}
Oops, something went wrong.

0 comments on commit 119221a

Please sign in to comment.