-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "build: refactor scripts to use Bun APIs (#339)"
This reverts commit 93f6056.
- Loading branch information
Showing
10 changed files
with
113 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
import { $ } from "bun"; | ||
|
||
import { buildLanguages } from "./build-languages"; | ||
import { buildStyles } from "./build-styles"; | ||
import { mkdir } from "./utils/fs"; | ||
|
||
(async () => { | ||
mkdir("www/data"); | ||
|
||
await $`rm -rf www/data; mkdir www/data`; | ||
await buildLanguages(); | ||
await buildStyles(); | ||
await buildLanguages(); | ||
await buildStyles(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,76 @@ | ||
import { $ } from "bun"; | ||
import fs from "node:fs"; | ||
import { mkdir, writeFile } from "./utils/fs"; | ||
|
||
console.time("package"); | ||
await $`rm -rf package; mkdir package`; | ||
await Bun.write("./package/package.json", Bun.file("./package.json")); | ||
await Bun.write("./package/README.md", Bun.file("./README.md")); | ||
await Bun.write("./package/LICENSE", Bun.file("./LICENSE")); | ||
async function npmPackage() { | ||
console.time("package"); | ||
|
||
// Copy source folder to package | ||
await $`cp -r ./src/ ./package`; | ||
mkdir("./package"); | ||
|
||
const pkgJson = await Bun.file("./package/package.json").json(); | ||
await Bun.write("./package/package.json", Bun.file("./package.json")); | ||
await Bun.write("./package/README.md", Bun.file("./README.md")); | ||
await Bun.write("./package/LICENSE", Bun.file("./LICENSE")); | ||
|
||
delete pkgJson.scripts; | ||
delete pkgJson.devDependencies; | ||
// Copy source folder to package | ||
mkdir("./package/src"); | ||
fs.cpSync("./src", "./package", { recursive: true }); | ||
fs.rmSync("./package/src", { recursive: true, force: true }); | ||
|
||
pkgJson.exports = { | ||
".": { | ||
types: "./index.d.ts", | ||
svelte: "./index.js", | ||
}, | ||
"./*.svelte": { | ||
types: "./*.svelte.d.ts", | ||
import: "./*.svelte", | ||
}, | ||
"./styles/*.css": { | ||
import: "./styles/*.css", | ||
}, | ||
"./styles": { | ||
types: "./styles/index.d.ts", | ||
import: "./styles/index.js", | ||
}, | ||
"./styles/*": { | ||
types: "./styles/*.d.ts", | ||
import: "./styles/*.js", | ||
}, | ||
"./styles/*.js": { | ||
types: "./styles/*.d.ts", | ||
import: "./styles/*.js", | ||
}, | ||
"./languages": { | ||
types: "./languages/index.d.ts", | ||
import: "./languages/index.js", | ||
}, | ||
"./languages/*": { | ||
types: "./languages/*.d.ts", | ||
import: "./languages/*.js", | ||
}, | ||
"./languages/*.js": { | ||
types: "./languages/*.d.ts", | ||
import: "./languages/*.js", | ||
}, | ||
"./package.json": "./package.json", | ||
}; | ||
const pkgJson = JSON.parse( | ||
fs.readFileSync("./package/package.json", "utf-8"), | ||
); | ||
|
||
// Svelte entry point is deprecated but we preserve it for backwards compatibility. | ||
pkgJson.svelte = "./index.js"; | ||
pkgJson.types = "./index.d.ts"; | ||
delete pkgJson.scripts; | ||
delete pkgJson.devDependencies; | ||
|
||
// Most modern bundlers know if standalone StyleSheets are used. | ||
// We specify it here to be sure so that it will not be mistakenly tree-shaken. | ||
pkgJson.sideEffects = ["src/styles/*.css"]; | ||
pkgJson.exports = { | ||
".": { | ||
types: "./index.d.ts", | ||
svelte: "./index.js", | ||
}, | ||
"./*.svelte": { | ||
types: "./*.svelte.d.ts", | ||
import: "./*.svelte", | ||
}, | ||
"./styles/*.css": { | ||
import: "./styles/*.css", | ||
}, | ||
"./styles": { | ||
types: "./styles/index.d.ts", | ||
import: "./styles/index.js", | ||
}, | ||
"./styles/*": { | ||
types: "./styles/*.d.ts", | ||
import: "./styles/*.js", | ||
}, | ||
"./styles/*.js": { | ||
types: "./styles/*.d.ts", | ||
import: "./styles/*.js", | ||
}, | ||
"./languages": { | ||
types: "./languages/index.d.ts", | ||
import: "./languages/index.js", | ||
}, | ||
"./languages/*": { | ||
types: "./languages/*.d.ts", | ||
import: "./languages/*.js", | ||
}, | ||
"./languages/*.js": { | ||
types: "./languages/*.d.ts", | ||
import: "./languages/*.js", | ||
}, | ||
"./package.json": "./package.json", | ||
}; | ||
|
||
await Bun.write("./package/package.json", JSON.stringify(pkgJson, null, 2)); | ||
console.timeEnd("package"); | ||
// Svelte entry point is deprecated but we preserve it for backwards compatibility. | ||
pkgJson.svelte = "./index.js"; | ||
pkgJson.types = "./index.d.ts"; | ||
|
||
// Most modern bundlers know if standalone StyleSheets are used. | ||
// We specify it here to be sure so that it will not be mistakenly tree-shaken. | ||
pkgJson.sideEffects = ["src/styles/*.css"]; | ||
|
||
await writeFile("./package/package.json", JSON.stringify(pkgJson, null, 2)); | ||
console.timeEnd("package"); | ||
} | ||
|
||
npmPackage(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
import { dependencies } from "../../package.json"; | ||
import fs from "node:fs"; | ||
|
||
const pkg = JSON.parse( | ||
fs.readFileSync(new URL("../../package.json", import.meta.url), "utf8"), | ||
); | ||
|
||
/** Creates header metadata for supported languages/styles */ | ||
export const createMarkdown = (type: "Languages" | "Styles", len: number) => | ||
` | ||
# Supported ${type} | ||
> ${len} ${type.toLowerCase()} exported from highlight.js@${ | ||
dependencies["highlight.js"] | ||
pkg.dependencies["highlight.js"] | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import fs from "node:fs"; | ||
import fsp from "node:fs/promises"; | ||
|
||
export const mkdir = (dir: string) => { | ||
if (fs.existsSync(dir)) { | ||
fs.rmSync(dir, { recursive: true }); | ||
} | ||
fs.mkdirSync(dir); | ||
}; | ||
export const readFile = fsp.readFile; | ||
export const writeFile = fsp.writeFile; | ||
export const copyFile = fsp.copyFile; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters