Skip to content

Commit

Permalink
refactor: use esm
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikobeats committed Jan 22, 2024
1 parent 8a57b85 commit 19c8a07
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 26 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@
"git-authors-cli": "latest",
"git-dirty": "latest",
"github-generate-release": "latest",
"got": "11",
"got": "latest",
"listr": "latest",
"lodash": "latest",
"meow": "9",
"nano-staged": "latest",
"p-all": "3",
"picocolors": "latest",
"prettier": "latest",
"pretty-bytes": "5",
"pretty-ms": "7",
"pretty-bytes": "latest",
"pretty-ms": "latest",
"puppeteer": "latest",
"simple-git-hooks": "latest",
"standard": "latest",
"standard-markdown": "latest",
"standard-version": "latest",
"unique-random-array": "2"
"unique-random-array": "latest"
},
"engines": {
"node": ">= 18"
Expand All @@ -67,11 +67,11 @@
"dist"
],
"scripts": {
"build": "node scripts/build.js dist https://cdn.microlink.io/",
"build": "node scripts/build.mjs dist https://cdn.microlink.io/",
"clean": "rm -rf node_modules",
"dev": "watchexec --exts js -- node scripts/build.js dist https://cdn.microlink.io/",
"dev": "watchexec --exts js -- node scripts/build.mjs dist https://cdn.microlink.io/",
"lint": "standard-markdown README.md && standard",
"postbuild": "node scripts/postbuild.js",
"postbuild": "node scripts/postbuild.mjs",
"postrelease": "npm run release:tags && npm run release:github",
"prerelease": "git-dirty && npm run update:check && npm test && git-authors-cli",
"pretest": "npm run lint",
Expand Down
10 changes: 5 additions & 5 deletions scripts/build.js → scripts/build.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict'

const { statSync, readdirSync } = require('fs')
const { writeFile } = require('fs/promises')
const prettyBytes = require('pretty-bytes')
const prettier = require('prettier')
const path = require('path')
import { statSync, readdirSync } from 'fs'
import { writeFile } from 'fs/promises'
import prettyBytes from 'pretty-bytes'
import prettier from 'prettier'
import path from 'path'

const IGNORE_FILES = ['.DS_Store', 'data', 'index.html']
const URLS = []
Expand Down
30 changes: 16 additions & 14 deletions scripts/postbuild.js → scripts/postbuild.mjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
'use strict'

const prettyMs = require('pretty-ms')
import createTimeSpan from '@kikobeats/time-span'
import { readFile } from 'fs/promises'
import prettyMs from 'pretty-ms'
import got from 'got'

const timeSpan = require('@kikobeats/time-span')({ format: prettyMs })
const URLS = await readFile(new URL('../urls.json', import.meta.url), 'utf8').then(JSON.parse)

const URLS = require('../urls.json')
const timeSpan = createTimeSpan({ format: prettyMs })

const {
CLOUDFLARE_MAX_FILES = 30,
Expand All @@ -21,7 +24,7 @@ const chunks = (array, size) =>
return result
}, [])

const cloudflare = require('got').extend({
const cloudflare = got.extend({
prefixUrl: `https://api.cloudflare.com/client/v4/zones/${CLOUDFLARE_ZONE_ID}/`,
throwHttpErrors: false,
responseType: 'json',
Expand All @@ -35,13 +38,12 @@ const cloudflare = require('got').extend({

const total = timeSpan()

;(async () => {
for (const files of chunks(URLS, CLOUDFLARE_MAX_FILES)) {
await cloudflare('purge_cache', {
method: 'POST',
body: JSON.stringify({ files })
})
process.stdout.write(' ' + total() + ' ')
}
process.stdout.write('✨\n')
})()
for (const files of chunks(URLS, CLOUDFLARE_MAX_FILES)) {
await cloudflare('purge_cache', {
method: 'POST',
body: JSON.stringify({ files })
})
process.stdout.write(' ' + total() + ' ')
}

process.stdout.write('✨\n')

1 comment on commit 19c8a07

@vercel
Copy link

@vercel vercel bot commented on 19c8a07 Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.