From 3ce3969edbd07da5f5740f97b4ae1db0ae585b7d Mon Sep 17 00:00:00 2001 From: filip131311 Date: Mon, 13 Jan 2025 16:18:30 +0100 Subject: [PATCH] cr --- packages/vscode-extension/package.json | 2 +- .../scripts/buildExtensionCode.mjs | 39 +++++++++---------- .../scripts/generateThirdPartyNotice.js | 17 +++----- .../install-sim-server-release-build.sh | 8 +--- 4 files changed, 27 insertions(+), 39 deletions(-) diff --git a/packages/vscode-extension/package.json b/packages/vscode-extension/package.json index e83ae987c..3908d9a31 100644 --- a/packages/vscode-extension/package.json +++ b/packages/vscode-extension/package.json @@ -470,7 +470,7 @@ "vscode:package": "vsce package", "vscode:prepublish": "npm run package", "build:extension-debug": "node scripts/buildExtensionCode.mjs debug", - "build:extension": "node scripts/buildExtensionCode.mjs prod", + "build:extension": "node scripts/buildExtensionCode.mjs production", "build:webview": "vite build --mode production && cp ./node_modules/@vscode/codicons/dist/codicon.* dist/.", "build:sim-server-debug": "bash ./scripts/build-sim-server-debug.sh dist", "build:sim-server": "bash ./scripts/install-sim-server-release-build.sh dist", diff --git a/packages/vscode-extension/scripts/buildExtensionCode.mjs b/packages/vscode-extension/scripts/buildExtensionCode.mjs index 79c1050e9..c0607a762 100755 --- a/packages/vscode-extension/scripts/buildExtensionCode.mjs +++ b/packages/vscode-extension/scripts/buildExtensionCode.mjs @@ -4,18 +4,23 @@ import fs from "fs"; const [mode] = process.argv.slice(2); +let buildConfig = { + entryPoints: ["./src/extension.ts"], + bundle: true, + outfile: "./dist/extension.js", + external: ["vscode"], + format: "cjs", + platform: "node", +}; + // build extension code if (mode === "debug") { - await esbuild.build({ - entryPoints: ["./src/extension.ts"], - bundle: true, - outfile: "./dist/extension.js", - external: ["vscode"], - format: "cjs", - platform: "node", + buildConfig = { + ...buildConfig, sourcemap: true, - }); -} else if (mode === "prod") { + }; +} +if (mode === "production") { const licensesDir = "dist/third-party-licenses"; // Ensure the license directory exists @@ -54,21 +59,15 @@ if (mode === "debug") { }, }; - await esbuild.build({ - entryPoints: ["./src/extension.ts"], - bundle: true, - outfile: "./dist/extension.js", + buildConfig = { + ...buildConfig, plugins: [esbuildPluginLicense(licensePluginConfiguration)], - external: ["vscode"], - format: "cjs", - platform: "node", minify: true, - }); -} else { - console.error("The `prod` or `debug` must be provided as an argument"); - process.exit(1); + }; } +await esbuild.build(buildConfig); + // add mapping to dist const sourceMapMappingsPath = "node_modules/source-map/lib/mappings.wasm"; const newSourceMapMappingsPath = "dist/mappings.wasm"; diff --git a/packages/vscode-extension/scripts/generateThirdPartyNotice.js b/packages/vscode-extension/scripts/generateThirdPartyNotice.js index 2f6515b8d..014a09b4c 100644 --- a/packages/vscode-extension/scripts/generateThirdPartyNotice.js +++ b/packages/vscode-extension/scripts/generateThirdPartyNotice.js @@ -5,17 +5,12 @@ const directoryPath = "dist/third-party-licenses"; const outputFile = "dist/THIRDPARTYNOTICE.json"; function readJsonFiles() { - return fs.promises - .readdir(directoryPath, { withFileTypes: true }) - .then((entries) => { - const filePromises = entries - .filter((entry) => entry.isFile() && entry.name.endsWith(".json")) - .map((entry) => fs.promises.readFile(path.join(directoryPath, entry.name), "utf8")); - return Promise.all(filePromises); - }) - .then((files) => { - return files.map((file) => JSON.parse(file)); - }); + return fs.promises.readdir(directoryPath, { withFileTypes: true }).then((entries) => { + const filePromises = entries + .filter((entry) => entry.isFile() && entry.name.endsWith(".json")) + .map((entry) => require(path.join("..", directoryPath, entry.name))); + return Promise.all(filePromises); + }); } function mergeLibraries(dataArrays) { diff --git a/packages/vscode-extension/scripts/install-sim-server-release-build.sh b/packages/vscode-extension/scripts/install-sim-server-release-build.sh index fce60c324..fd7e6bfd4 100755 --- a/packages/vscode-extension/scripts/install-sim-server-release-build.sh +++ b/packages/vscode-extension/scripts/install-sim-server-release-build.sh @@ -37,12 +37,7 @@ sim_server_tag=$(git -C ../simulator-server describe --tags) echo "Downloading simulator-server binaries for tag $sim_server_tag" echo "Removing existing simulator-server binaries if necessary..." -for file in "$output_dir"/simulator-server*; do - if [ -f "$file" ]; then - echo "Removing existing file $file" - rm -f "$file" - fi -done +rm -f $output_dir/simulator-server* # Download simulator-server binaries using gh CLI and place them in the output directory with correct file mode gh release download $sim_server_tag -R software-mansion-labs/simulator-server -p "simulator-server*" -D "$output_dir" @@ -57,7 +52,6 @@ else fi gh release download $sim_server_tag -R software-mansion-labs/simulator-server -p "THIRDPARTY.json" -D "$output_dir"/"third-party-licenses" -chmod +x "$output_dir"/"third-party-licenses" echo "Operation completed successfully."