Implemented serve and copy-link development features

This commit is contained in:
Sun Knudsen 2022-02-17 13:32:26 -05:00
parent 48a50320a8
commit 3dcffe7cef
No known key found for this signature in database
GPG Key ID: 02C43AD072D57783
7 changed files with 1214 additions and 4 deletions

2
.env.sample Normal file
View File

@ -0,0 +1,2 @@
PORT=8080
LOCALHOST_PROXY=

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
.env
*.code-workspace
/node_modules

9
.vscode/tasks.json vendored
View File

@ -1,6 +1,15 @@
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "Copy link",
"command": "node ./tasks/copy-link.js \"${selectedText}\"",
"presentation": {
"reveal": "silent"
},
"problemMatcher": []
},
{
"type": "shell",
"label": "Insert YouTube player",

16
index.js Normal file
View File

@ -0,0 +1,16 @@
"use strict"
import express from "express"
const app = express()
app.use(
express.static(".", {
dotfiles: "ignore",
index: false,
})
)
const server = app.listen(process.env.PORT ?? 8080, () => {
console.info(`Server listening on port ${server.address().port}`)
})

1164
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"serve": "node index.js",
"ncu": "ncu --target minor --upgrade"
},
"author": "Sun Knudsen <hello@sunknudsen.com>",
@ -20,7 +21,11 @@
},
"homepage": "https://github.com/sunknudsen/privacy-guides#readme",
"devDependencies": {
"@types/express": "^4.17.13",
"@types/fs-extra": "^9.0.13",
"clipboardy": "^3.0.0",
"dotenv": "^16.0.0",
"express": "^4.17.2",
"fs-extra": "^10.0.0",
"npm-check-updates": "^12.3.0",
"readdirp": "^3.6.0",

21
tasks/copy-link.js Normal file
View File

@ -0,0 +1,21 @@
"use strict"
import "dotenv/config"
import clipboard from "clipboardy"
if (process.argv.length !== 3 || !process.argv[2].match(/http(s)?:\/\//)) {
console.info("Usage: node copy-link.js selectedText")
process.exit(1)
}
var text = process.argv[2]
if (process.env.LOCALHOST_PROXY) {
text = text.replace(
"https://raw.githubusercontent.com/sunknudsen/privacy-guides/master",
process.env.LOCALHOST_PROXY
)
}
clipboard.write(text)