Build dist/tests

This commit is contained in:
Adria Navarro 2023-09-05 16:44:02 +02:00
parent 7ff6714ff8
commit 5a4d032b0d
2 changed files with 28 additions and 24 deletions

View File

@ -1,18 +1,21 @@
#!/usr/bin/node
const coreBuild = require("../../../scripts/build")
coreBuild("./src/plugin/index.ts", "./dist/plugins.js")
coreBuild("./src/index.ts", "./dist/index.js")
const esbuild = require("esbuild")
const glob = require("glob")
const inputFiles = [
...glob.sync("./src/**/*.[tj]s", { nodir: true }),
...glob.sync("./tests/**/*.[tj]s", { nodir: true }),
]
const inputFiles = glob.sync("./tests/**/*.[tj]s", { nodir: true })
const outputDir = "./dist/tests"
esbuild
.build({
entryPoints: inputFiles,
outdir: outputDir,
const path = require("path")
for (const file of inputFiles) {
coreBuild(file, `./${path.join("dist", file.replace(/\.ts$/, ".js"))}`, {
skipMeta: true,
bundle: false,
forcedFormat: "cjs",
})
.catch(() => process.exit(1))
}

View File

@ -15,7 +15,7 @@ const { nodeExternalsPlugin } = require("esbuild-node-externals")
var argv = require("minimist")(process.argv.slice(2))
function runBuild(entry, outfile) {
function runBuild(entry, outfile, opts = { skipMeta: false, bundle: true }) {
const isDev = process.env.NODE_ENV !== "production"
const tsconfig = argv["p"] || `tsconfig.build.json`
const tsconfigPathPluginContent = JSON.parse(
@ -36,12 +36,16 @@ function runBuild(entry, outfile) {
]
}
const metafile = !opts.skipMeta
const { bundle } = opts
const sharedConfig = {
entryPoints: [entry],
bundle: true,
bundle,
minify: !isDev,
sourcemap: isDev,
tsconfig,
format: opts?.forcedFormat,
plugins: [
TsconfigPathsPlugin({ tsconfig: tsconfigPathPluginContent }),
nodeExternalsPlugin(),
@ -50,15 +54,10 @@ function runBuild(entry, outfile) {
loader: {
".svelte": "copy",
},
metafile: true,
external: [
"deasync",
"mock-aws-s3",
"nock",
"pino",
"koa-pino-logger",
"bull",
],
metafile,
external: bundle
? ["deasync", "mock-aws-s3", "nock", "pino", "koa-pino-logger", "bull"]
: undefined,
}
build({
@ -77,10 +76,12 @@ function runBuild(entry, outfile) {
)
})
fs.writeFileSync(
`dist/${path.basename(outfile)}.meta.json`,
JSON.stringify(result.metafile)
)
if (metafile) {
fs.writeFileSync(
`dist/${path.basename(outfile)}.meta.json`,
JSON.stringify(result.metafile)
)
}
})
}