-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: make build script more generic
- Loading branch information
Showing
2 changed files
with
48 additions
and
27 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
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, | ||
|
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 |
---|---|---|
|
@@ -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 |