diff --git a/plugins/nextjs-plugin/esbuild.mjs b/plugins/nextjs-plugin/esbuild.mjs index 12f3ae9..55c6d9e 100644 --- a/plugins/nextjs-plugin/esbuild.mjs +++ b/plugins/nextjs-plugin/esbuild.mjs @@ -1,46 +1,5 @@ #!/usr/bin/env node -import esbuild from 'esbuild'; -import {existsSync, mkdirSync, readFileSync} from 'fs'; -import {join} from 'path'; - -const dist = join(process.cwd(), 'dist'); - -const createDistFolder = () => { - if (!existsSync(dist)) { - mkdirSync(dist); - } -}; - -// Skip peer dependencies -const peerDependencies = (packageJson) => { - const json = readFileSync(packageJson, 'utf8'); - const {peerDependencies} = JSON.parse(json); - return peerDependencies ?? {}; -}; - -const workspacePeerDependencies = peerDependencies(join(process.cwd(), 'package.json')); - -const buildEsm = () => { - esbuild - .build({ - entryPoints: ['src/index.ts'], - outfile: 'dist/index.mjs', - bundle: true, - minify: true, - format: 'esm', - platform: 'node', - banner: { - js: "import { createRequire as topLevelCreateRequire } from 'module';\n const require = topLevelCreateRequire(import.meta.url);" - }, - external: [...Object.keys(workspacePeerDependencies)] - }) - .catch(() => process.exit(1)); -}; - -export const build = () => { - createDistFolder(); - buildEsm(); -}; +import {build} from '../../scripts/esbuild.mjs'; build(); diff --git a/plugins/plugin-tools/esbuild.mjs b/plugins/plugin-tools/esbuild.mjs index 12f3ae9..55c6d9e 100644 --- a/plugins/plugin-tools/esbuild.mjs +++ b/plugins/plugin-tools/esbuild.mjs @@ -1,46 +1,5 @@ #!/usr/bin/env node -import esbuild from 'esbuild'; -import {existsSync, mkdirSync, readFileSync} from 'fs'; -import {join} from 'path'; - -const dist = join(process.cwd(), 'dist'); - -const createDistFolder = () => { - if (!existsSync(dist)) { - mkdirSync(dist); - } -}; - -// Skip peer dependencies -const peerDependencies = (packageJson) => { - const json = readFileSync(packageJson, 'utf8'); - const {peerDependencies} = JSON.parse(json); - return peerDependencies ?? {}; -}; - -const workspacePeerDependencies = peerDependencies(join(process.cwd(), 'package.json')); - -const buildEsm = () => { - esbuild - .build({ - entryPoints: ['src/index.ts'], - outfile: 'dist/index.mjs', - bundle: true, - minify: true, - format: 'esm', - platform: 'node', - banner: { - js: "import { createRequire as topLevelCreateRequire } from 'module';\n const require = topLevelCreateRequire(import.meta.url);" - }, - external: [...Object.keys(workspacePeerDependencies)] - }) - .catch(() => process.exit(1)); -}; - -export const build = () => { - createDistFolder(); - buildEsm(); -}; +import {build} from '../../scripts/esbuild.mjs'; build(); diff --git a/plugins/vite-plugin/esbuild.mjs b/plugins/vite-plugin/esbuild.mjs index 12f3ae9..55c6d9e 100644 --- a/plugins/vite-plugin/esbuild.mjs +++ b/plugins/vite-plugin/esbuild.mjs @@ -1,46 +1,5 @@ #!/usr/bin/env node -import esbuild from 'esbuild'; -import {existsSync, mkdirSync, readFileSync} from 'fs'; -import {join} from 'path'; - -const dist = join(process.cwd(), 'dist'); - -const createDistFolder = () => { - if (!existsSync(dist)) { - mkdirSync(dist); - } -}; - -// Skip peer dependencies -const peerDependencies = (packageJson) => { - const json = readFileSync(packageJson, 'utf8'); - const {peerDependencies} = JSON.parse(json); - return peerDependencies ?? {}; -}; - -const workspacePeerDependencies = peerDependencies(join(process.cwd(), 'package.json')); - -const buildEsm = () => { - esbuild - .build({ - entryPoints: ['src/index.ts'], - outfile: 'dist/index.mjs', - bundle: true, - minify: true, - format: 'esm', - platform: 'node', - banner: { - js: "import { createRequire as topLevelCreateRequire } from 'module';\n const require = topLevelCreateRequire(import.meta.url);" - }, - external: [...Object.keys(workspacePeerDependencies)] - }) - .catch(() => process.exit(1)); -}; - -export const build = () => { - createDistFolder(); - buildEsm(); -}; +import {build} from '../../scripts/esbuild.mjs'; build(); diff --git a/scripts/esbuild.mjs b/scripts/esbuild.mjs new file mode 100644 index 0000000..9feeeb1 --- /dev/null +++ b/scripts/esbuild.mjs @@ -0,0 +1,44 @@ +#!/usr/bin/env node + +import esbuild from 'esbuild'; +import {existsSync, mkdirSync, readFileSync} from 'fs'; +import {join} from 'path'; + +const dist = join(process.cwd(), 'dist'); + +const createDistFolder = () => { + if (!existsSync(dist)) { + mkdirSync(dist); + } +}; + +// Skip peer dependencies +const peerDependencies = (packageJson) => { + const json = readFileSync(packageJson, 'utf8'); + const {peerDependencies} = JSON.parse(json); + return peerDependencies ?? {}; +}; + +const workspacePeerDependencies = peerDependencies(join(process.cwd(), 'package.json')); + +const buildEsm = () => { + esbuild + .build({ + entryPoints: ['src/index.ts'], + outfile: 'dist/index.mjs', + bundle: true, + minify: true, + format: 'esm', + platform: 'node', + banner: { + js: "import { createRequire as topLevelCreateRequire } from 'module';\n const require = topLevelCreateRequire(import.meta.url);" + }, + external: [...Object.keys(workspacePeerDependencies)] + }) + .catch(() => process.exit(1)); +}; + +export const build = () => { + createDistFolder(); + buildEsm(); +};