chore: upgrade dependencies
This commit is contained in:
parent
98476c51bc
commit
60859a0a48
28
bin/index.js
28
bin/index.js
|
@ -1,13 +1,15 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
const fs = require('fs-extra')
|
import fs from 'fs-extra'
|
||||||
const yargs = require('yargs')
|
import yargs from 'yargs'
|
||||||
const { basename, extname, join } = require('path')
|
import * as url from 'url'
|
||||||
const { getLatestId, getComic } = require('../lib/xkcd')
|
import { hideBin } from 'yargs/helpers'
|
||||||
const { homePage, comicPage } = require('../lib/html')
|
import { basename, extname, join } from 'path'
|
||||||
const { pad, progress } = require('../lib/helpers')
|
import { getLatestId, getComic } from '../lib/xkcd.js'
|
||||||
|
import { homePage, comicPage } from '../lib/html.js'
|
||||||
|
import { pad, progress } from '../lib/helpers.js'
|
||||||
|
|
||||||
const argv = yargs
|
const argv = yargs(hideBin(process.argv))
|
||||||
.usage('$0', 'Clones XKCD comics. By default it only downloads the missing comics.')
|
.usage('$0', 'Clones XKCD comics. By default it only downloads the missing comics.')
|
||||||
.scriptName('xkcd-clone')
|
.scriptName('xkcd-clone')
|
||||||
.option('dir', {
|
.option('dir', {
|
||||||
|
@ -31,8 +33,8 @@ async function write ({ data, img }, dir, latest) {
|
||||||
await fs.outputFile(join(dir, 'index.html'), comicPage(data, latest, hasImage))
|
await fs.outputFile(join(dir, 'index.html'), comicPage(data, latest, hasImage))
|
||||||
|
|
||||||
if (hasImage) {
|
if (hasImage) {
|
||||||
await fs.outputFile(join(dir, basename(data.img)), img)
|
await fs.outputFile(join(dir, basename(data.img)), Buffer.from(img))
|
||||||
await fs.outputFile(join(dir, `image${extname(data.img)}`), img)
|
await fs.outputFile(join(dir, `image${extname(data.img)}`), Buffer.from(img))
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await fs.remove(dir)
|
await fs.remove(dir)
|
||||||
|
@ -118,11 +120,13 @@ async function run () {
|
||||||
progress('📦 Some comics fetched\n')
|
progress('📦 Some comics fetched\n')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const currDirectory = url.fileURLToPath(new URL('.', import.meta.url))
|
||||||
|
|
||||||
added = added.sort((a, b) => a.num - b.num)
|
added = added.sort((a, b) => a.num - b.num)
|
||||||
await fs.remove(join(argv.dir, 'latest'))
|
await fs.remove(join(argv.dir, 'latest'))
|
||||||
await fs.copy(join(argv.dir, latest.toString()), join(argv.dir, 'latest'))
|
await fs.copy(join(argv.dir, pad(latest, 4)), join(argv.dir, 'latest'))
|
||||||
await fs.copyFile(join(__dirname, '../node_modules/tachyons/css/tachyons.min.css'), join(argv.dir, 'tachyons.css'))
|
await fs.copyFile(join(currDirectory, '../node_modules/tachyons/css/tachyons.min.css'), join(argv.dir, 'tachyons.css'))
|
||||||
await fs.copyFile(join(__dirname, '../node_modules/tachyons-columns/css/tachyons-columns.min.css'), join(argv.dir, 'tachyons-columns.css'))
|
await fs.copyFile(join(currDirectory, '../node_modules/tachyons-columns/css/tachyons-columns.min.css'), join(argv.dir, 'tachyons-columns.css'))
|
||||||
await fs.outputFile(join(argv.dir, 'index.html'), homePage(added))
|
await fs.outputFile(join(argv.dir, 'index.html'), homePage(added))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const progress = (str) => {
|
export const progress = (str) => {
|
||||||
if (process.stdout.isTTY) {
|
if (process.stdout.isTTY) {
|
||||||
process.stdout.clearLine()
|
process.stdout.clearLine()
|
||||||
process.stdout.cursorTo(0)
|
process.stdout.cursorTo(0)
|
||||||
|
@ -8,7 +8,7 @@ const progress = (str) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const pad = (str, max) => {
|
export const pad = (str, max) => {
|
||||||
str = str.toString()
|
str = str.toString()
|
||||||
return str.length < max ? pad('0' + str, max) : str
|
return str.length < max ? pad('0' + str, max) : str
|
||||||
}
|
}
|
||||||
|
@ -19,12 +19,6 @@ const tagsToReplace = {
|
||||||
'>': '>'
|
'>': '>'
|
||||||
}
|
}
|
||||||
|
|
||||||
const escapeHtml = (html) => {
|
export const escapeHtml = (html) => {
|
||||||
html.replace(/[&<>]/g, tag => tagsToReplace[tag] || tag)
|
html.replace(/[&<>]/g, tag => tagsToReplace[tag] || tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
progress,
|
|
||||||
escapeHtml,
|
|
||||||
pad
|
|
||||||
}
|
|
||||||
|
|
13
lib/html.js
13
lib/html.js
|
@ -1,5 +1,5 @@
|
||||||
const { basename } = require('path')
|
import { basename } from 'path'
|
||||||
const { pad, escapeHtml } = require('./helpers')
|
import { pad, escapeHtml } from './helpers.js'
|
||||||
|
|
||||||
const credits = '<p class="mv4 tc f6 small-caps">This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License.<br>Originally from <a target="_blank" class="blue hover-dark-blue no-underline" href="https://xkcd.com/">xkcd.com</a>.</p>'
|
const credits = '<p class="mv4 tc f6 small-caps">This work is licensed under a Creative Commons Attribution-NonCommercial 2.5 License.<br>Originally from <a target="_blank" class="blue hover-dark-blue no-underline" href="https://xkcd.com/">xkcd.com</a>.</p>'
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ const classes = {
|
||||||
btn: 'dib navy mh2 pa2 bg-light-blue hover-bg-lightest-blue br2 ba bw1 b--navy no-underline'
|
btn: 'dib navy mh2 pa2 bg-light-blue hover-bg-lightest-blue br2 ba bw1 b--navy no-underline'
|
||||||
}
|
}
|
||||||
|
|
||||||
const comicPage = ({ alt, title, transcript, num, img }, latest) => `<html>
|
export const comicPage = ({ alt, title, transcript, num, img }, latest) => `<html>
|
||||||
<head>
|
<head>
|
||||||
<title>${num} - ${title}</title>
|
<title>${num} - ${title}</title>
|
||||||
<meta charset=utf-8>
|
<meta charset=utf-8>
|
||||||
|
@ -33,7 +33,7 @@ const comicPage = ({ alt, title, transcript, num, img }, latest) => `<html>
|
||||||
</body>
|
</body>
|
||||||
</html>`
|
</html>`
|
||||||
|
|
||||||
const homePage = (list) => `<html>
|
export const homePage = (list) => `<html>
|
||||||
<head>
|
<head>
|
||||||
<title>XKCD</title>
|
<title>XKCD</title>
|
||||||
<meta charset=utf-8>
|
<meta charset=utf-8>
|
||||||
|
@ -71,8 +71,3 @@ const homePage = (list) => `<html>
|
||||||
${credits}
|
${credits}
|
||||||
</body>
|
</body>
|
||||||
</html>`
|
</html>`
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
comicPage,
|
|
||||||
homePage
|
|
||||||
}
|
|
||||||
|
|
15
lib/xkcd.js
15
lib/xkcd.js
|
@ -1,7 +1,7 @@
|
||||||
const fetch = require('node-fetch')
|
import fetch from 'node-fetch'
|
||||||
const path = require('path')
|
import path from 'path'
|
||||||
|
|
||||||
async function getLatestId () {
|
export async function getLatestId () {
|
||||||
const raw = await fetch('https://xkcd.com/info.0.json')
|
const raw = await fetch('https://xkcd.com/info.0.json')
|
||||||
const data = await raw.json()
|
const data = await raw.json()
|
||||||
return data.num
|
return data.num
|
||||||
|
@ -20,10 +20,10 @@ async function getImage (url) {
|
||||||
throw new Error('bad image request')
|
throw new Error('bad image request')
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.buffer()
|
return res.arrayBuffer()
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getComic (id) {
|
export async function getComic (id) {
|
||||||
const raw = await fetch(`https://xkcd.com/${id}/info.0.json`)
|
const raw = await fetch(`https://xkcd.com/${id}/info.0.json`)
|
||||||
const data = await raw.json()
|
const data = await raw.json()
|
||||||
let img = null
|
let img = null
|
||||||
|
@ -36,8 +36,3 @@ async function getComic (id) {
|
||||||
|
|
||||||
return { data, img }
|
return { data, img }
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
getLatestId,
|
|
||||||
getComic
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,16 +3,17 @@
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
"description": "Clone xkcd comics.",
|
"description": "Clone xkcd comics.",
|
||||||
"main": "./lib/index.js",
|
"main": "./lib/index.js",
|
||||||
|
"type": "module",
|
||||||
"bin": {
|
"bin": {
|
||||||
"xkcd-clone": "./bin/index.js"
|
"xkcd-clone": "./bin/index.js"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"author": "Henrique Dias <hacdias@gmail.com>",
|
"author": "Henrique Dias <hacdias@gmail.com>",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fs-extra": "^9.0.1",
|
"fs-extra": "^10.1.0",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^3.2.10",
|
||||||
"tachyons": "^4.12.0",
|
"tachyons": "^4.12.0",
|
||||||
"tachyons-columns": "^1.0.5",
|
"tachyons-columns": "^1.0.5",
|
||||||
"yargs": "^17.0.0"
|
"yargs": "^17.5.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user