mirror of
https://github.com/samsonjs/mit-license.git
synced 2026-04-27 15:07:42 +00:00
refactor: Use reliable packages
Signed-off-by: Richie Bendall <richiebendall@gmail.com>
This commit is contained in:
parent
fe248a03af
commit
6688cdf96d
11 changed files with 97 additions and 102 deletions
|
|
@ -1 +0,0 @@
|
||||||
module.exports = require('@remy/eslint')('node');
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html id="home" lang="en">
|
<html id="home" lang="en">
|
||||||
<%- include('components/header') %>
|
<%- include('components/header') %>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<article>
|
<article>
|
||||||
<%- gravatar %>
|
<%- gravatar %>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html id="home" lang="en">
|
<html id="home" lang="en">
|
||||||
<%- include('components/header') %>
|
<%- include('components/header') %>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<article>
|
<article>
|
||||||
<%- gravatar %>
|
<%- gravatar %>
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
<footer>
|
<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>
|
</footer>
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,8 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
<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.">
|
<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
|
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
|
link to if you're like me and keep forgetting to include the
|
||||||
|
|
@ -27,9 +28,7 @@ For more options see the README in the github hosted project.
|
||||||
Hope you find this useful too!
|
Hope you find this useful too!
|
||||||
|
|
||||||
- @rem
|
- @rem
|
||||||
|
|
||||||
-->
|
-->
|
||||||
<!-- for HTML5 el styling -->
|
|
||||||
<script>
|
<script>
|
||||||
document.createElement('article');
|
document.createElement('article');
|
||||||
document.createElement('footer');
|
document.createElement('footer');
|
||||||
|
|
|
||||||
24
package.json
24
package.json
|
|
@ -1,5 +1,4 @@
|
||||||
{
|
{
|
||||||
"author": "Remy Sharp <remy@leftlogic.com> (http://remysharp.com/)",
|
|
||||||
"name": "mit-licence",
|
"name": "mit-licence",
|
||||||
"description": "Hosted MIT License with details controlled through this repo",
|
"description": "Hosted MIT License with details controlled through this repo",
|
||||||
"private": true,
|
"private": true,
|
||||||
|
|
@ -12,12 +11,7 @@
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": ">=10"
|
"node": ">=10"
|
||||||
},
|
},
|
||||||
"husky": {
|
"author": "Remy Sharp <remy@leftlogic.com> (http://remysharp.com/)",
|
||||||
"hooks": {
|
|
||||||
"pre-commit": "npm run lint",
|
|
||||||
"pre-push": "npm test"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "node .",
|
"start": "node .",
|
||||||
"dev": "nodemon .",
|
"dev": "nodemon .",
|
||||||
|
|
@ -30,28 +24,38 @@
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"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",
|
"btoa": "^1.2.1",
|
||||||
"ejs": "^3.0.1",
|
"ejs": "^3.0.1",
|
||||||
|
"escape-html": "^1.0.3",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"express-minify": "^1.0.0",
|
"express-minify": "^1.0.0",
|
||||||
"fs-extra": "^8.1.0",
|
"fs-extra": "^8.1.0",
|
||||||
"lodash": "^4.17.15",
|
"html-text": "^1.0.1",
|
||||||
"md5": "^2.2.1",
|
"md5": "^2.2.1",
|
||||||
"postcss-middleware": "^1.1.4",
|
"postcss-middleware": "^1.1.4",
|
||||||
"postcss-preset-env": "^6.7.0",
|
"postcss-preset-env": "^6.7.0",
|
||||||
"serve-favicon": "^2.5.0",
|
"serve-favicon": "^2.5.0",
|
||||||
"temp-dir": "^2.0.0",
|
"temp-dir": "^2.0.0",
|
||||||
|
"unescape-html": "^1.1.0",
|
||||||
"yn": "^4.0.0"
|
"yn": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"css": "^2.2.4",
|
"css": "^2.2.4",
|
||||||
"has-flag": "^4.0.0",
|
"has-flag": "^4.0.0",
|
||||||
"husky": "^4.0.7",
|
"husky": "^4.2.1",
|
||||||
"nodemon": "^2.0.2",
|
"nodemon": "^2.0.2",
|
||||||
"standard": "^14.3.1"
|
"standard": "^14.3.1"
|
||||||
},
|
},
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"postcss-middleware/vinyl-fs/glob-stream/micromatch/braces": "^3.0.2"
|
"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 md5 = require('md5')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const { stripTags, escapeTags, unescapeTags } = require('./utils')
|
const escapeTags = require('escape-html')
|
||||||
const _ = require('lodash')
|
const unescapeTags = require('unescape-html')
|
||||||
|
const stripTags = require('html-text')
|
||||||
|
const is = require('@sindresorhus/is')
|
||||||
|
|
||||||
function getCopyrightHTML (user, plain) {
|
function getCopyrightHTML (user, plain) {
|
||||||
let html = ''
|
let html = ''
|
||||||
|
|
||||||
const name = _.isString(user)
|
const name = is.string(user)
|
||||||
? user
|
? user
|
||||||
: plain
|
: plain
|
||||||
? user.name || user.copyright
|
? user.name || user.copyright
|
||||||
|
|
@ -34,9 +36,9 @@ module.exports = (req, res) => {
|
||||||
|
|
||||||
// No error and valid
|
// No error and valid
|
||||||
if (user.copyright) {
|
if (user.copyright) {
|
||||||
if (_.isString(user.copyright)) {
|
if (is.string(user.copyright)) {
|
||||||
name = getCopyrightHTML(user, options.format !== 'html')
|
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']
|
// Supports: ['Remy Sharp', 'Richie Bendall']
|
||||||
name = user.copyright
|
name = user.copyright
|
||||||
.map(v => (options.format !== 'html' ? v : escapeTags(v)))
|
.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(
|
gravatar = `<img id="gravatar" alt="Profile image" src="https://www.gravatar.com/avatar/${md5(
|
||||||
user.email.trim().toLowerCase()
|
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
|
// Supports multi-user format
|
||||||
gravatar = `<img id="gravatar" alt="Profile image" src="https://www.gravatar.com/avatar/${md5(
|
gravatar = `<img id="gravatar" alt="Profile image" src="https://www.gravatar.com/avatar/${md5(
|
||||||
user.copyright[0].email.trim().toLowerCase()
|
user.copyright[0].email.trim().toLowerCase()
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ const fs = require('fs-extra')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const btoa = require('btoa')
|
const btoa = require('btoa')
|
||||||
const { version } = require(path.join(__dirname, '..', 'package.json'))
|
const { version } = require(path.join(__dirname, '..', 'package.json'))
|
||||||
const _ = require('lodash')
|
const size = require('any-size')
|
||||||
const github = require('@octokit/rest')({
|
const github = require('@octokit/rest')({
|
||||||
// GitHub personal access token
|
// GitHub personal access token
|
||||||
auth: process.env.github_token,
|
auth: process.env.github_token,
|
||||||
|
|
@ -10,14 +10,15 @@ const github = require('@octokit/rest')({
|
||||||
userAgent: `mit-license v${version}`
|
userAgent: `mit-license v${version}`
|
||||||
})
|
})
|
||||||
const yn = require('yn')
|
const yn = require('yn')
|
||||||
|
const is = require('@sindresorhus/is')
|
||||||
|
|
||||||
const { validDomainId } = require('./utils')
|
const { validDomainId } = require('./utils')
|
||||||
|
|
||||||
function getUserData ({ query, body }) {
|
function getUserData ({ query, body }) {
|
||||||
// If query parameters provided
|
// If query parameters provided
|
||||||
if (_.size(query) > 0) return query
|
if (size(query) > 0) return query
|
||||||
// If the data parsed as {'{data: "value"}': ''}
|
// 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
|
// Fallback
|
||||||
return body
|
return body
|
||||||
}
|
}
|
||||||
|
|
@ -38,7 +39,7 @@ module.exports = async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Extract the name from the URL
|
// Extract the name from the URL
|
||||||
const id = _.first(params)
|
const id = params[0]
|
||||||
|
|
||||||
if (!validDomainId(id)) {
|
if (!validDomainId(id)) {
|
||||||
// Return a vague error intentionally
|
// Return a vague error intentionally
|
||||||
|
|
@ -65,7 +66,7 @@ module.exports = async (req, res) => {
|
||||||
if (userData.gravatar) {
|
if (userData.gravatar) {
|
||||||
// Parse the string version of a boolean or similar
|
// Parse the string version of a boolean or similar
|
||||||
userData.gravatar = yn(userData.gravatar, { lenient: true })
|
userData.gravatar = yn(userData.gravatar, { lenient: true })
|
||||||
if (_.isUndefined(userData.gravatar)) {
|
if (is.undefined(userData.gravatar)) {
|
||||||
res
|
res
|
||||||
.status(400)
|
.status(400)
|
||||||
.send(
|
.send(
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,3 @@
|
||||||
const _ = require('lodash')
|
|
||||||
|
|
||||||
const tags = {
|
|
||||||
'<': '<',
|
|
||||||
'>': '>',
|
|
||||||
'&': '&'
|
|
||||||
}
|
|
||||||
const untags = _.invert(tags)
|
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
escapeTags: str => (str || '').replace(/[<>&]/g, m => tags[m]),
|
|
||||||
unescapeTags: str =>
|
|
||||||
(str || '').replace(/(<|>|&)/g, m => untags[m]),
|
|
||||||
stripTags: str => (str || '').replace(/<(?:.|\n)*?>/gm, ''),
|
|
||||||
validDomainId: str => /^[\w-_]+$/.test(str)
|
validDomainId: str => /^[\w-_]+$/.test(str)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ const express = require('express')
|
||||||
const minify = require('express-minify')
|
const minify = require('express-minify')
|
||||||
const favicon = require('serve-favicon')
|
const favicon = require('serve-favicon')
|
||||||
const postcssMiddleware = require('postcss-middleware')
|
const postcssMiddleware = require('postcss-middleware')
|
||||||
const tmpdir = require('temp-dir')
|
const tempdir = require('temp-dir')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
|
|
@ -19,7 +19,7 @@ var PORT = process.env.PORT || 8080
|
||||||
const app = express()
|
const app = express()
|
||||||
app.use(
|
app.use(
|
||||||
minify({
|
minify({
|
||||||
cache: tmpdir
|
cache: tempdir
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
app.use(favicon(path.join(__dirname, 'favicon.ico')))
|
app.use(favicon(path.join(__dirname, 'favicon.ico')))
|
||||||
|
|
|
||||||
BIN
yarn.lock
BIN
yarn.lock
Binary file not shown.
Loading…
Reference in a new issue