From 5dc857c3f9736828b2d541e8d0429775288f8d97 Mon Sep 17 00:00:00 2001 From: Kiko Beats Date: Mon, 22 Jan 2024 16:05:11 +0100 Subject: [PATCH] refactor: use esm --- package.json | 14 ++++++------- scripts/{build.js => build.mjs} | 10 +++++----- scripts/{postbuild.js => postbuild.mjs} | 26 ++++++++++++------------- 3 files changed, 25 insertions(+), 25 deletions(-) rename scripts/{build.js => build.mjs} (97%) rename scripts/{postbuild.js => postbuild.mjs} (67%) diff --git a/package.json b/package.json index 9e8c21b4..3d74dfc7 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,7 @@ "git-authors-cli": "latest", "git-dirty": "latest", "github-generate-release": "latest", - "got": "11", + "got": "latest", "listr": "latest", "lodash": "latest", "meow": "9", @@ -51,14 +51,14 @@ "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" @@ -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", diff --git a/scripts/build.js b/scripts/build.mjs similarity index 97% rename from scripts/build.js rename to scripts/build.mjs index d5cd9dc6..cc182beb 100644 --- a/scripts/build.js +++ b/scripts/build.mjs @@ -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 = [] diff --git a/scripts/postbuild.js b/scripts/postbuild.mjs similarity index 67% rename from scripts/postbuild.js rename to scripts/postbuild.mjs index d3751c67..3a9508f8 100644 --- a/scripts/postbuild.js +++ b/scripts/postbuild.mjs @@ -1,11 +1,12 @@ 'use strict' -const prettyMs = require('pretty-ms') - -const timeSpan = require('@kikobeats/time-span')({ format: prettyMs }) +import prettyMs from 'pretty-ms' +import createTimeSpan from '@kikobeats/time-span' const URLS = require('../urls.json') +const timeSpan = createTimeSpan({ format: prettyMs }) + const { CLOUDFLARE_MAX_FILES = 30, CLOUDFLARE_AUTH_EMAIL, @@ -35,13 +36,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')