Skip to content

Commit

Permalink
chore: make build script more generic
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Dec 2, 2024
1 parent b642817 commit e8a3cee
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
9 changes: 9 additions & 0 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
{
"name": "prettier-plugin-vitepress",
"version": "0.0.5",
"description": "a prettier plugin to format vue in markdown syntax used in vitepress",
"keywords": ["prettier", "vitepress", "vue", "markdown"],
"repository": {
"type": "git",
"url": "git+https://github.com/brc-dd/prettier-plugin-vitepress.git"
},
"funding": "https://github.com/sponsors/brc-dd",
"license": "MIT",
"author": "Divyansh Singh <[email protected]> (https://github.com/brc-dd)",
"exports": "./src/index.ts",
"compilerOptions": {
"noFallthroughCasesInSwitch": true,
Expand Down
66 changes: 39 additions & 27 deletions scripts/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,59 @@ import * as esbuild from 'esbuild'
import tsid from 'unplugin-isolated-decl/esbuild'
import denoJson from '../deno.json' with { type: 'json' }

const pick = [
'name',
'version',
'description',
'keywords',
'repository',
'funding',
'license',
'author',
] as const

const peerDeps = ['prettier'] as const
const minify = Deno.env.get('CI') === 'true'
const exports = typeof denoJson.exports === 'string' ? { '.': denoJson.exports } : denoJson.exports

await emptyDir('dist')

await esbuild.build({
plugins: [
tsid(),
...denoPlugins(),
],
entryPoints: [denoJson.exports],
const res = await esbuild.build({
plugins: [tsid(), ...denoPlugins()],
entryPoints: Object.values(exports),
outdir: 'dist',
bundle: true,
format: 'esm',
platform: 'neutral',
target: 'es2022',
external: ['prettier'],
minify: !!Deno.env.get('CI'),
metafile: true,
minify,
})

const outputs = Object.fromEntries(
Object.entries(res.metafile.outputs).flatMap(([key, value]) =>
value.entryPoint ? [['./' + value.entryPoint, key.replace('dist/', './')]] : []
),
)

await Deno.writeTextFile(
'dist/package.json',
JSON.stringify({
name: denoJson.name,
version: denoJson.version,
description: 'a prettier plugin to format vue in markdown syntax used in vitepress',
keywords: ['prettier', 'vitepress', 'vue', 'markdown'],
repository: {
type: 'git',
url: 'git+https://github.com/brc-dd/prettier-plugin-vitepress.git',
},
funding: 'https://github.com/sponsors/brc-dd',
license: 'MIT',
author: 'Divyansh Singh <[email protected]> (https://github.com/brc-dd)',
sideEffects: false,
type: 'module',
main: 'index.js',
peerDependencies: {
prettier: denoJson.imports.prettier.split('@')[1],
JSON.stringify(
{
...Object.fromEntries(pick.map((key) => [key, denoJson[key]])),
type: 'module',
exports: Object.fromEntries(
Object.entries(exports).map(([key, value]) => [key, outputs[value]]),
),
peerDependencies: Object.fromEntries(
peerDeps.map((dep) => [dep, denoJson.imports[dep].split('@')[1]]),
),
},
}),
null,
minify ? 0 : 2,
),
)

await Deno.copyFile('LICENSE.md', 'dist/LICENSE.md')
await Deno.copyFile('README.md', 'dist/README.md')

// TODO: make it more generic

0 comments on commit e8a3cee

Please sign in to comment.