1
mirror of https://github.com/jakejarvis/jakejarvis.git synced 2025-12-01 07:43:50 -05:00

nicer and centered BigText, remove fs-extra, updated readmes

This commit is contained in:
2021-11-21 11:17:10 -05:00
parent 9d1447c801
commit 3f418d3602
11 changed files with 122 additions and 153 deletions

View File

@@ -1,5 +1,5 @@
const path = require("path");
const fs = require("fs-extra");
const fs = require("fs").promises;
const babel = require("@babel/core");
const ncc = require("@vercel/ncc");
const prettyBytes = require("pretty-bytes");
@@ -10,11 +10,11 @@ const prettyBytes = require("pretty-bytes");
const distDir = path.join(__dirname, "dist");
// remove anything leftover from previous builds
fs.removeSync(tempDir);
fs.removeSync(distDir);
await fs.rm(tempDir, { recursive: true, force: true });
await fs.rm(distDir, { recursive: true, force: true });
// run code through babel
const { code: babelCode } = babel.transformFileSync(path.join(__dirname, "index.js"), {
const { code: babelCode } = await babel.transformFileAsync(path.join(__dirname, "index.js"), {
presets: [
[
"@babel/preset-react",
@@ -26,7 +26,8 @@ const prettyBytes = require("pretty-bytes");
});
// save babelified code to a file -- unfortunately, we can't pipe this code directly to ncc below
fs.outputFileSync(path.join(tempDir, "babel.js"), babelCode);
await fs.mkdir(tempDir);
await fs.writeFile(path.join(tempDir, "babel.js"), babelCode);
// compile for distribution with ncc
const { code, assets } = await ncc(path.join(tempDir, "babel.js"), {
@@ -37,16 +38,17 @@ const prettyBytes = require("pretty-bytes");
});
// write final build to ./dist and make executable
fs.outputFileSync(path.join(distDir, "index.js"), code);
fs.outputFileSync(path.join(distDir, "xdg-open"), assets["xdg-open"].source); // TODO: external script from 'open' module
fs.chmodSync(path.join(distDir, "index.js"), 0o775);
fs.chmodSync(path.join(distDir, "xdg-open"), 0o775);
await fs.mkdir(distDir);
await fs.writeFile(path.join(distDir, "index.js"), code);
await fs.writeFile(path.join(distDir, "xdg-open"), assets["xdg-open"].source); // TODO: external script from 'open' module
await fs.chmod(path.join(distDir, "index.js"), 0o775);
await fs.chmod(path.join(distDir, "xdg-open"), 0o775);
// quick logging of resulting filesize
console.log("✅ Success!");
console.log(`dist/index.js\t${prettyBytes(fs.statSync(path.join(distDir, "index.js")).size)}`);
console.log(`dist/xdg-open\t${prettyBytes(fs.statSync(path.join(distDir, "xdg-open")).size)}`);
console.log(`dist/index.js\t${prettyBytes((await fs.stat(path.join(distDir, "index.js"))).size)}`);
console.log(`dist/xdg-open\t${prettyBytes((await fs.stat(path.join(distDir, "xdg-open"))).size)}`);
// clean up temp files
fs.removeSync(tempDir);
await fs.rm(tempDir, { recursive: true, force: true });
})();