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
|
||||
|
||||
const fs = require('fs-extra')
|
||||
const yargs = require('yargs')
|
||||
const { basename, extname, join } = require('path')
|
||||
const { getLatestId, getComic } = require('../lib/xkcd')
|
||||
const { homePage, comicPage } = require('../lib/html')
|
||||
const { pad, progress } = require('../lib/helpers')
|
||||
import fs from 'fs-extra'
|
||||
import yargs from 'yargs'
|
||||
import * as url from 'url'
|
||||
import { hideBin } from 'yargs/helpers'
|
||||
import { basename, extname, join } from 'path'
|
||||
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.')
|
||||
.scriptName('xkcd-clone')
|
||||
.option('dir', {
|
||||
|
@ -31,8 +33,8 @@ async function write ({ data, img }, dir, latest) {
|
|||
await fs.outputFile(join(dir, 'index.html'), comicPage(data, latest, hasImage))
|
||||
|
||||
if (hasImage) {
|
||||
await fs.outputFile(join(dir, basename(data.img)), img)
|
||||
await fs.outputFile(join(dir, `image${extname(data.img)}`), img)
|
||||
await fs.outputFile(join(dir, basename(data.img)), Buffer.from(img))
|
||||
await fs.outputFile(join(dir, `image${extname(data.img)}`), Buffer.from(img))
|
||||
}
|
||||
} catch (err) {
|
||||
await fs.remove(dir)
|
||||
|
@ -118,11 +120,13 @@ async function run () {
|
|||
progress('📦 Some comics fetched\n')
|
||||
}
|
||||
|
||||
const currDirectory = url.fileURLToPath(new URL('.', import.meta.url))
|
||||
|
||||
added = added.sort((a, b) => a.num - b.num)
|
||||
await fs.remove(join(argv.dir, 'latest'))
|
||||
await fs.copy(join(argv.dir, latest.toString()), 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(__dirname, '../node_modules/tachyons-columns/css/tachyons-columns.min.css'), join(argv.dir, 'tachyons-columns.css'))
|
||||
await fs.copy(join(argv.dir, pad(latest, 4)), join(argv.dir, 'latest'))
|
||||
await fs.copyFile(join(currDirectory, '../node_modules/tachyons/css/tachyons.min.css'), join(argv.dir, 'tachyons.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))
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
const progress = (str) => {
|
||||
export const progress = (str) => {
|
||||
if (process.stdout.isTTY) {
|
||||
process.stdout.clearLine()
|
||||
process.stdout.cursorTo(0)
|
||||
|
@ -8,7 +8,7 @@ const progress = (str) => {
|
|||
}
|
||||
}
|
||||
|
||||
const pad = (str, max) => {
|
||||
export const pad = (str, max) => {
|
||||
str = str.toString()
|
||||
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)
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
progress,
|
||||
escapeHtml,
|
||||
pad
|
||||
}
|
||||
|
|
13
lib/html.js
13
lib/html.js
|
@ -1,5 +1,5 @@
|
|||
const { basename } = require('path')
|
||||
const { pad, escapeHtml } = require('./helpers')
|
||||
import { basename } from 'path'
|
||||
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>'
|
||||
|
||||
|
@ -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'
|
||||
}
|
||||
|
||||
const comicPage = ({ alt, title, transcript, num, img }, latest) => `<html>
|
||||
export const comicPage = ({ alt, title, transcript, num, img }, latest) => `<html>
|
||||
<head>
|
||||
<title>${num} - ${title}</title>
|
||||
<meta charset=utf-8>
|
||||
|
@ -33,7 +33,7 @@ const comicPage = ({ alt, title, transcript, num, img }, latest) => `<html>
|
|||
</body>
|
||||
</html>`
|
||||
|
||||
const homePage = (list) => `<html>
|
||||
export const homePage = (list) => `<html>
|
||||
<head>
|
||||
<title>XKCD</title>
|
||||
<meta charset=utf-8>
|
||||
|
@ -71,8 +71,3 @@ const homePage = (list) => `<html>
|
|||
${credits}
|
||||
</body>
|
||||
</html>`
|
||||
|
||||
module.exports = {
|
||||
comicPage,
|
||||
homePage
|
||||
}
|
||||
|
|
15
lib/xkcd.js
15
lib/xkcd.js
|
@ -1,7 +1,7 @@
|
|||
const fetch = require('node-fetch')
|
||||
const path = require('path')
|
||||
import fetch from 'node-fetch'
|
||||
import path from 'path'
|
||||
|
||||
async function getLatestId () {
|
||||
export async function getLatestId () {
|
||||
const raw = await fetch('https://xkcd.com/info.0.json')
|
||||
const data = await raw.json()
|
||||
return data.num
|
||||
|
@ -20,10 +20,10 @@ async function getImage (url) {
|
|||
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 data = await raw.json()
|
||||
let img = null
|
||||
|
@ -36,8 +36,3 @@ async function getComic (id) {
|
|||
|
||||
return { data, img }
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getLatestId,
|
||||
getComic
|
||||
}
|
||||
|
|
|
@ -3,16 +3,17 @@
|
|||
"version": "1.2.1",
|
||||
"description": "Clone xkcd comics.",
|
||||
"main": "./lib/index.js",
|
||||
"type": "module",
|
||||
"bin": {
|
||||
"xkcd-clone": "./bin/index.js"
|
||||
},
|
||||
"license": "MIT",
|
||||
"author": "Henrique Dias <hacdias@gmail.com>",
|
||||
"dependencies": {
|
||||
"fs-extra": "^9.0.1",
|
||||
"node-fetch": "^2.6.1",
|
||||
"fs-extra": "^10.1.0",
|
||||
"node-fetch": "^3.2.10",
|
||||
"tachyons": "^4.12.0",
|
||||
"tachyons-columns": "^1.0.5",
|
||||
"yargs": "^17.0.0"
|
||||
"yargs": "^17.5.1"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user