|
| 1 | +import { argv, parallel, series, task, tscTask } from "just-scripts"; |
| 2 | +import { |
| 3 | + BundleTaskParameters, |
| 4 | + CopyTaskParameters, |
| 5 | + bundleTask, |
| 6 | + cleanTask, |
| 7 | + cleanCollateralTask, |
| 8 | + copyTask, |
| 9 | + coreLint, |
| 10 | + mcaddonTask, |
| 11 | + setupEnvironment, |
| 12 | + ZipTaskParameters, |
| 13 | + STANDARD_CLEAN_PATHS, |
| 14 | + DEFAULT_CLEAN_DIRECTORIES, |
| 15 | + getOrThrowFromProcess, |
| 16 | + watchTask, |
| 17 | +} from "@minecraft/core-build-tasks"; |
| 18 | +import path from "path"; |
| 19 | + |
| 20 | +// Setup env variables |
| 21 | +setupEnvironment(path.resolve(__dirname, ".env")); |
| 22 | +const projectName = getOrThrowFromProcess("PROJECT_NAME"); |
| 23 | + |
| 24 | +// You can use `npm run build:production` to build a "production" build that strips out statements labelled with "dev:". |
| 25 | +const isProduction = argv()['production']; |
| 26 | + |
| 27 | +const bundleTaskOptions: BundleTaskParameters = { |
| 28 | + entryPoint: path.join(__dirname, "./scripts/main.ts"), |
| 29 | + external: ["@minecraft/server", "@minecraft/server-ui"], |
| 30 | + outfile: path.resolve(__dirname, "./dist/scripts/main.js"), |
| 31 | + minifyWhitespace: false, |
| 32 | + sourcemap: true, |
| 33 | + outputSourcemapPath: path.resolve(__dirname, "./dist/debug"), |
| 34 | + dropLabels: isProduction ? ['dev'] : undefined |
| 35 | +}; |
| 36 | + |
| 37 | +const copyTaskOptions: CopyTaskParameters = { |
| 38 | + copyToBehaviorPacks: [`./behavior_packs/${projectName}`], |
| 39 | + copyToScripts: ["./dist/scripts"], |
| 40 | + copyToResourcePacks: [`./resource_packs/${projectName}`], |
| 41 | +}; |
| 42 | + |
| 43 | +const mcaddonTaskOptions: ZipTaskParameters = { |
| 44 | + ...copyTaskOptions, |
| 45 | + outputFile: `./dist/packages/${projectName}.mcaddon`, |
| 46 | +}; |
| 47 | + |
| 48 | +// Lint |
| 49 | +task("lint", coreLint(["scripts/**/*.ts"], argv().fix)); |
| 50 | + |
| 51 | +// Build |
| 52 | +task("typescript", tscTask()); |
| 53 | +task("bundle", bundleTask(bundleTaskOptions)); |
| 54 | +task("build", series("typescript", "bundle")); |
| 55 | + |
| 56 | +// Clean |
| 57 | +task("clean-local", cleanTask(DEFAULT_CLEAN_DIRECTORIES)); |
| 58 | +task("clean-collateral", cleanCollateralTask(STANDARD_CLEAN_PATHS)); |
| 59 | +task("clean", parallel("clean-local", "clean-collateral")); |
| 60 | + |
| 61 | +// Package |
| 62 | +task("copyArtifacts", copyTask(copyTaskOptions)); |
| 63 | +task("package", series("clean-collateral", "copyArtifacts")); |
| 64 | + |
| 65 | +// Local Deploy used for deploying local changes directly to output via the bundler. It does a full build and package first just in case. |
| 66 | +task( |
| 67 | + "local-deploy", |
| 68 | + watchTask( |
| 69 | + ["scripts/**/*.ts", "behavior_packs/**/*.{json,lang,png}", "resource_packs/**/*.{json,lang,png}"], |
| 70 | + series("clean-local", "build", "package") |
| 71 | + ) |
| 72 | +); |
| 73 | + |
| 74 | +// Mcaddon |
| 75 | +task("createMcaddonFile", mcaddonTask(mcaddonTaskOptions)); |
| 76 | +task("mcaddon", series("clean-local", "build", "createMcaddonFile")); |
0 commit comments