-
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.
build: refactor scripts to use Bun APIs
- Loading branch information
Showing
10 changed files
with
78 additions
and
113 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,10 +1,8 @@ | ||
import { $ } from "bun"; | ||
|
||
import { buildLanguages } from "./build-languages"; | ||
import { buildStyles } from "./build-styles"; | ||
import { mkdir } from "./utils/fs"; | ||
|
||
(async () => { | ||
mkdir("www/data"); | ||
|
||
await buildLanguages(); | ||
await buildStyles(); | ||
})(); | ||
await $`rm -rf www/data; mkdir www/data`; | ||
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,76 +1,65 @@ | ||
import fs from "node:fs"; | ||
import { mkdir, writeFile } from "./utils/fs"; | ||
import { $ } from "bun"; | ||
|
||
async function npmPackage() { | ||
console.time("package"); | ||
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")); | ||
|
||
mkdir("./package"); | ||
// Copy source folder to package | ||
await $`cp -r ./src/ ./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")); | ||
const pkgJson = await Bun.file("./package/package.json").json(); | ||
|
||
// Copy source folder to package | ||
mkdir("./package/src"); | ||
fs.cpSync("./src", "./package", { recursive: true }); | ||
fs.rmSync("./package/src", { recursive: true, force: true }); | ||
delete pkgJson.scripts; | ||
delete pkgJson.devDependencies; | ||
|
||
const pkgJson = JSON.parse( | ||
fs.readFileSync("./package/package.json", "utf-8"), | ||
); | ||
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", | ||
}; | ||
|
||
delete pkgJson.scripts; | ||
delete pkgJson.devDependencies; | ||
// Svelte entry point is deprecated but we preserve it for backwards compatibility. | ||
pkgJson.svelte = "./index.js"; | ||
pkgJson.types = "./index.d.ts"; | ||
|
||
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", | ||
}; | ||
// 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"]; | ||
|
||
// 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(); | ||
await Bun.write("./package/package.json", JSON.stringify(pkgJson, null, 2)); | ||
console.timeEnd("package"); |
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,15 +1,11 @@ | ||
import fs from "node:fs"; | ||
|
||
const pkg = JSON.parse( | ||
fs.readFileSync(new URL("../../package.json", import.meta.url), "utf8"), | ||
); | ||
import { dependencies } from "../../package.json"; | ||
|
||
/** Creates header metadata for supported languages/styles */ | ||
export const createMarkdown = (type: "Languages" | "Styles", len: number) => | ||
` | ||
# Supported ${type} | ||
> ${len} ${type.toLowerCase()} exported from highlight.js@${ | ||
pkg.dependencies["highlight.js"] | ||
dependencies["highlight.js"] | ||
} | ||
`; |
This file was deleted.
Oops, something went wrong.
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