Skip to content

Commit cb86aea

Browse files
committed
add plugin build script
1 parent 690bf5b commit cb86aea

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

buildTsPlugin.mjs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//@ts-check
2+
import { ensureDir } from 'fs-extra'
3+
import { build } from 'esbuild'
4+
import { join, resolve } from 'path'
5+
import { writePackageJsonFile } from 'typed-jsonfile'
6+
7+
export const buildTsPlugin = async (/** @type {string} */ outDir, /** @type {string} */ name, /** @type {string} */ entrypoint) => {
8+
outDir = resolve(outDir)
9+
entrypoint = resolve(entrypoint)
10+
await ensureDir(outDir)
11+
await writePackageJsonFile(
12+
{ dir: outDir },
13+
{
14+
name,
15+
// TODO
16+
version: '0.0.0',
17+
main: 'index.js',
18+
},
19+
)
20+
await build({
21+
bundle: true,
22+
platform: 'node',
23+
treeShaking: true,
24+
format: 'cjs',
25+
entryPoints: [entrypoint],
26+
outfile: join(outDir, 'index.js'),
27+
})
28+
}
29+
30+
const name = 'my-typescript-plugin-2'
31+
buildTsPlugin(`out/node_modules/${name}`, name, 'typescript-2/src/index.ts')

0 commit comments

Comments
 (0)