Skip to content
Permalink
Browse files

refactor: Use reliable packages

Signed-off-by: Richie Bendall <richiebendall@gmail.com>
  • Loading branch information
Richienb committed Jan 31, 2020
1 parent fe248a0 commit 6688cdf96d7cd99195512c9e060f0abf5375b976
Showing with 362 additions and 187 deletions.
  1. +0 −1 .eslintrc.js
  2. +17 −16 licenses/ISC.ejs
  3. +22 −21 licenses/MIT.ejs
  4. +2 −1 licenses/components/footer.ejs
  5. +26 −27 licenses/components/header.ejs
  6. +14 −10 package.json
  7. +8 −6 routes/get.js
  8. +6 −5 routes/post.js
  9. +0 −13 routes/utils.js
  10. +2 −2 server.js
  11. +265 −85 yarn.lock

This file was deleted.

@@ -1,26 +1,27 @@
<!DOCTYPE html>
<html id="home" lang="en">
<%- include('components/header') %>

<body>
<article>
<%- gravatar %>
<h1>The ISC License (ISC)</h1>
<article>
<%- gravatar %>
<h1>The ISC License (ISC)</h1>

<p>Copyright © <%- info %></p>
<p>Copyright © <%- info %></p>

<p>Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.</p>
<p>Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.</p>

<p>THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</p>
</article>
<%- include('components/footer') %>
<p>THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.</p>
</article>
<%- include('components/footer') %>
</body>

</html>
@@ -1,32 +1,33 @@
<!DOCTYPE html>
<html id="home" lang="en">
<%- include('components/header') %>

<body>
<article>
<%- gravatar %>
<h1>The MIT License (MIT)</h1>
<article>
<%- gravatar %>
<h1>The MIT License (MIT)</h1>

<p>Copyright © <%- info %></p>
<p>Copyright © <%- info %></p>

<p>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:</p>
<p>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:</p>

<p>The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.</p>
<p>The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.</p>

<p>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.</p>
</article>
<%- include('components/footer') %>
<p>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.</p>
</article>
<%- include('components/footer') %>
</body>

</html>
@@ -1,3 +1,4 @@
<footer>
<p><a target="_blank" rel="noopener" href="https://github.com/remy/mit-license">Fork this project to create your own MIT license that you can always link to.</a></p>
<p><a target="_blank" rel="noopener" href="https://github.com/remy/mit-license">Fork this project to create your own
MIT license that you can always link to.</a></p>
</footer>
@@ -1,38 +1,37 @@
<head>
<title>MIT License</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description" content="The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology. As a permissive license, it puts only very limited restriction on reuse and has, therefore, an excellent license compatibility.">
<!--
Welcome fellow open source developer. This project is here for you to
link to if you're like me and keep forgetting to include the
MIT-license.txt file.
<title>MIT License</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="description"
content="The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology. As a permissive license, it puts only very limited restriction on reuse and has, therefore, an excellent license compatibility.">
<!--
Welcome fellow open source developer. This project is here for you to
link to if you're like me and keep forgetting to include the
MIT-license.txt file.
Fork this project and send a pull request on:
Fork this project and send a pull request on:
https://github.com/remy/mit-license
https://github.com/remy/mit-license
By adding a new JSON file to the users directory, it will yield an
MIT License on a CNAME, for example:
By adding a new JSON file to the users directory, it will yield an
MIT License on a CNAME, for example:
{ "copyright": "Remy Sharp, https://remysharp.com" }
{ "copyright": "Remy Sharp, https://remysharp.com" }
Means visiting https://rem.mit-license.org/ shows "Remy Sharp" as the
copyright holder. Namespaces will be on a first come first serve basis,
and I'm open to folk joining the GitHub project.
Means visiting https://rem.mit-license.org/ shows "Remy Sharp" as the
copyright holder. Namespaces will be on a first come first serve basis,
and I'm open to folk joining the GitHub project.
For more options see the README in the github hosted project.
For more options see the README in the github hosted project.
Hope you find this useful too!
- @rem
Hope you find this useful too!
- @rem
-->
<!-- for HTML5 el styling -->
<script>
document.createElement('article');
document.createElement('footer');
</script>
<link rel="stylesheet" href="/themes/<%= theme %>.css">
<script>
document.createElement('article');
document.createElement('footer');
</script>
<link rel="stylesheet" href="/themes/<%= theme %>.css">
</head>
@@ -1,5 +1,4 @@
{
"author": "Remy Sharp <remy@leftlogic.com> (http://remysharp.com/)",
"name": "mit-licence",
"description": "Hosted MIT License with details controlled through this repo",
"private": true,
@@ -12,12 +11,7 @@
"engines": {
"node": ">=10"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint",
"pre-push": "npm test"
}
},
"author": "Remy Sharp <remy@leftlogic.com> (http://remysharp.com/)",
"scripts": {
"start": "node .",
"dev": "nodemon .",
@@ -30,28 +24,38 @@
},
"license": "MIT",
"dependencies": {
"@octokit/rest": "^16.36.0",
"@octokit/rest": "^16.41.0",
"@sindresorhus/is": "^2.0.0",
"any-size": "^1.0.0",
"btoa": "^1.2.1",
"ejs": "^3.0.1",
"escape-html": "^1.0.3",
"express": "^4.17.1",
"express-minify": "^1.0.0",
"fs-extra": "^8.1.0",
"lodash": "^4.17.15",
"html-text": "^1.0.1",
"md5": "^2.2.1",
"postcss-middleware": "^1.1.4",
"postcss-preset-env": "^6.7.0",
"serve-favicon": "^2.5.0",
"temp-dir": "^2.0.0",
"unescape-html": "^1.1.0",
"yn": "^4.0.0"
},
"devDependencies": {
"css": "^2.2.4",
"has-flag": "^4.0.0",
"husky": "^4.0.7",
"husky": "^4.2.1",
"nodemon": "^2.0.2",
"standard": "^14.3.1"
},
"resolutions": {
"postcss-middleware/vinyl-fs/glob-stream/micromatch/braces": "^3.0.2"
},
"husky": {
"hooks": {
"pre-commit": "npm run lint",
"pre-push": "npm test"
}
}
}
@@ -1,12 +1,14 @@
const md5 = require('md5')
const path = require('path')
const { stripTags, escapeTags, unescapeTags } = require('./utils')
const _ = require('lodash')
const escapeTags = require('escape-html')
const unescapeTags = require('unescape-html')
const stripTags = require('html-text')
const is = require('@sindresorhus/is')

function getCopyrightHTML (user, plain) {
let html = ''

const name = _.isString(user)
const name = is.string(user)
? user
: plain
? user.name || user.copyright
@@ -34,9 +36,9 @@ module.exports = (req, res) => {

// No error and valid
if (user.copyright) {
if (_.isString(user.copyright)) {
if (is.string(user.copyright)) {
name = getCopyrightHTML(user, options.format !== 'html')
} else if (_.isArray(user.copyright) && user.copyright.every(val => _.isString(val))) {
} else if (is.array(user.copyright) && user.copyright.every(val => is.string(val))) {
// Supports: ['Remy Sharp', 'Richie Bendall']
name = user.copyright
.map(v => (options.format !== 'html' ? v : escapeTags(v)))
@@ -51,7 +53,7 @@ module.exports = (req, res) => {
gravatar = `<img id="gravatar" alt="Profile image" src="https://www.gravatar.com/avatar/${md5(
user.email.trim().toLowerCase()
)}" />`
} else if (_.isObject(user.copyright[0]) && user.gravatar) {
} else if (is.object(user.copyright[0]) && user.gravatar) {
// Supports multi-user format
gravatar = `<img id="gravatar" alt="Profile image" src="https://www.gravatar.com/avatar/${md5(
user.copyright[0].email.trim().toLowerCase()
@@ -2,22 +2,23 @@ const fs = require('fs-extra')
const path = require('path')
const btoa = require('btoa')
const { version } = require(path.join(__dirname, '..', 'package.json'))
const _ = require('lodash')
const size = require('any-size')
const github = require('@octokit/rest')({
// GitHub personal access token
auth: process.env.github_token,
// User agent with version from package.json
userAgent: `mit-license v${version}`
})
const yn = require('yn')
const is = require('@sindresorhus/is')

const { validDomainId } = require('./utils')

function getUserData ({ query, body }) {
// If query parameters provided
if (_.size(query) > 0) return query
if (size(query) > 0) return query
// If the data parsed as {'{data: "value"}': ''}
if (_.size(body) === 1 && !_.first(_.values(body))) return JSON.parse(_.first(_.keys(body)))
if (size(body) === 1 && !Object.values(body)[0]) return JSON.parse(Object.keys(body)[0])
// Fallback
return body
}
@@ -38,7 +39,7 @@ module.exports = async (req, res) => {
}

// Extract the name from the URL
const id = _.first(params)
const id = params[0]

if (!validDomainId(id)) {
// Return a vague error intentionally
@@ -65,7 +66,7 @@ module.exports = async (req, res) => {
if (userData.gravatar) {
// Parse the string version of a boolean or similar
userData.gravatar = yn(userData.gravatar, { lenient: true })
if (_.isUndefined(userData.gravatar)) {
if (is.undefined(userData.gravatar)) {
res
.status(400)
.send(
@@ -1,16 +1,3 @@
const _ = require('lodash')

const tags = {
'<': '&lt;',
'>': '&gt;',
'&': '&amp;'
}
const untags = _.invert(tags)

module.exports = {
escapeTags: str => (str || '').replace(/[<>&]/g, m => tags[m]),
unescapeTags: str =>
(str || '').replace(/(&lt;|&gt;|&amp;)/g, m => untags[m]),
stripTags: str => (str || '').replace(/<(?:.|\n)*?>/gm, ''),
validDomainId: str => /^[\w-_]+$/.test(str)
}
@@ -9,7 +9,7 @@ const express = require('express')
const minify = require('express-minify')
const favicon = require('serve-favicon')
const postcssMiddleware = require('postcss-middleware')
const tmpdir = require('temp-dir')
const tempdir = require('temp-dir')
const path = require('path')

// Server
@@ -19,7 +19,7 @@ var PORT = process.env.PORT || 8080
const app = express()
app.use(
minify({
cache: tmpdir
cache: tempdir
})
)
app.use(favicon(path.join(__dirname, 'favicon.ico')))

0 comments on commit 6688cdf

Please sign in to comment.
You can’t perform that action at this time.