From b061a2592ada29721dc1ce9e0c73c0233b665be1 Mon Sep 17 00:00:00 2001 From: Neta London Date: Wed, 14 Aug 2024 14:12:16 +0300 Subject: [PATCH] Make build script windows friendly --- components/package.json | 2 +- extension/package.json | 5 +- extension/views/hdl/package.json | 2 +- package-lock.json | 111 +++++++++++++++++++++++++++++++ package.json | 14 ++-- web/package.json | 4 +- web/scripts/predeploy.js | 27 ++++++++ web/scripts/predeploy.sh | 9 --- 8 files changed, 155 insertions(+), 19 deletions(-) create mode 100644 web/scripts/predeploy.js delete mode 100755 web/scripts/predeploy.sh diff --git a/components/package.json b/components/package.json index f2bd410a6..268baf33c 100644 --- a/components/package.json +++ b/components/package.json @@ -47,7 +47,7 @@ }, "scripts": { "build": "tsc", - "postbuild": "rm -rf build/public && cp -r src/public/ build/public/", + "postbuild": "shx rm -rf build/public && shx cp -r src/public/ build/public/", "test": "react-scripts test" }, "jest": { diff --git a/extension/package.json b/extension/package.json index ac114cf9d..5cccb2e92 100644 --- a/extension/package.json +++ b/extension/package.json @@ -11,7 +11,7 @@ }, "homepage": "https://davidsouther.github.io/nand2tetris", "scripts": { - "prebuild": "mkdir -p out/views/hdl ; cd .. ; npm run build -w extension/views/hdl", + "prebuild": "shx mkdir -p out/views/hdl && cd .. && npm run build -w extension/views/hdl", "build": "npx esbuild ./src/extension.ts --bundle --outfile=out/main.js --external:vscode --format=cjs --platform=node --sourcemap", "watch": "npm run build -- --watch", "vscode:prepublish": "npm run build", @@ -255,5 +255,8 @@ "dependencies": { "gh-pages": "6.1.1", "react-scripts": "5.0.1" + }, + "optionalDependencies": { + "esbuild-windows-64": "^0.15.18" } } diff --git a/extension/views/hdl/package.json b/extension/views/hdl/package.json index f5f3e58ce..2aed4c910 100644 --- a/extension/views/hdl/package.json +++ b/extension/views/hdl/package.json @@ -26,7 +26,7 @@ "scripts": { "start": "react-scripts start", "build": "node ./scripts/build-react-no-split.js", - "postbuild": "cp ./build/styles.css ./build/static/js/main.js ./build/static/js/main.js.map ./build/static/js/main.js.LICENSE.txt ../../out/views/hdl", + "postbuild": "shx cp ./build/styles.css ./build/static/js/main.js ./build/static/js/main.js.map ./build/static/js/main.js.LICENSE.txt ../../out/views/hdl", "test": "react-scripts test", "eject": "react-scripts eject" }, diff --git a/package-lock.json b/package-lock.json index df5be8dfb..dabf28306 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18,6 +18,10 @@ "simulator", "web" ], + "devDependencies": { + "cross-env": "^7.0.3", + "shx": "^0.3.4" + }, "engines": { "node": ">=16", "npm": ">=7" @@ -291,6 +295,9 @@ }, "engines": { "vscode": "^1.61.0" + }, + "optionalDependencies": { + "esbuild-windows-64": "^0.15.18" } }, "extension/node_modules/@types/node": { @@ -7761,6 +7768,24 @@ "optional": true, "peer": true }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "license": "MIT", @@ -8989,6 +9014,21 @@ "node": ">=12" } }, + "node_modules/esbuild-windows-64": { + "version": "0.15.18", + "resolved": "https://registry.npmjs.org/esbuild-windows-64/-/esbuild-windows-64-0.15.18.tgz", + "integrity": "sha512-qinug1iTTaIIrCorAUjR0fcBk24fjzEedFYhhispP8Oc7SFvs+XeW3YpAKiKp8dRpizl4YYAhxMjlftAMJiaUw==", + "cpu": [ + "x64" + ], + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=12" + } + }, "node_modules/escalade": { "version": "3.1.2", "license": "MIT", @@ -11454,6 +11494,15 @@ "node": ">= 0.4" } }, + "node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "dev": true, + "engines": { + "node": ">= 0.10" + } + }, "node_modules/ipaddr.js": { "version": "2.2.0", "license": "MIT", @@ -20321,6 +20370,35 @@ "node": ">=8.10.0" } }, + "node_modules/rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "dev": true, + "dependencies": { + "resolve": "^1.1.6" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/rechoir/node_modules/resolve": { + "version": "1.22.8", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.22.8.tgz", + "integrity": "sha512-oKWePCxqpd6FlLvGV1VU0x7bkPmmCNolxzjMf4NczoDnQcIWrAF+cPtZn5i6n+RfD2d9i0tzpKnG6Yk168yIyw==", + "dev": true, + "dependencies": { + "is-core-module": "^2.13.0", + "path-parse": "^1.0.7", + "supports-preserve-symlinks-flag": "^1.0.0" + }, + "bin": { + "resolve": "bin/resolve" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/recursive-readdir": { "version": "2.2.3", "license": "MIT", @@ -21393,12 +21471,45 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "dev": true, + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, "node_modules/shellwords": { "version": "0.1.1", "license": "MIT", "optional": true, "peer": true }, + "node_modules/shx": { + "version": "0.3.4", + "resolved": "https://registry.npmjs.org/shx/-/shx-0.3.4.tgz", + "integrity": "sha512-N6A9MLVqjxZYcVn8hLmtneQWIJtp8IKzMP4eMnx+nqkvXoqinUPCbUFLp2UcWTEIUONhlk0ewxr/jaVGlc+J+g==", + "dev": true, + "dependencies": { + "minimist": "^1.2.3", + "shelljs": "^0.8.5" + }, + "bin": { + "shx": "lib/cli.js" + }, + "engines": { + "node": ">=6" + } + }, "node_modules/side-channel": { "version": "1.0.6", "license": "MIT", diff --git a/package.json b/package.json index 7cb70ff9e..17d1fe757 100644 --- a/package.json +++ b/package.json @@ -15,10 +15,10 @@ "scripts": { "precli": "npm run build -w cli", "cli": "node cli", - "ci": "CI=true npm run check && CI=true npm run test", + "ci": "cross-env CI=true npm run check && cross-env CI=true npm run test", "precheck": "npm -w web run extract && npm -w web run lingui", "check": "npm run check:format && npm run check:types && npm run check:lint", - "clean": "rm -rf **/node_modules **/tsconfig.tsbuildinfo **/build", + "clean": "shx rm -rf **/node_modules **/tsconfig.tsbuildinfo **/build", "format": "prettier --write cli/src components/src extension/src projects/src runner/src simulator/src web/src web/public", "fix": "eslint --fix cli/src components/src extension/src projects/src runner/src simulator/src web/src web/public", "check:format": "prettier --ignore-unknown --check cli/src components/src extension/src projects/src runner/src simulator/src web/src web/public", @@ -26,10 +26,10 @@ "precheck:types": "npm run build -w projects && npm run build -w runner && npm run build -w simulator && npm run build -w components", "check:types": "tsc --build tsconfig.json", "prebuild": "npm run check", - "build": "CI=true npm run build -w projects && CI=true npm run build -w runner && CI=true npm run build -w simulator && CI=true npm run build -w cli && CI=true npm run build -w components && CI=true npm run build -w web && CI=true npm run build -w extension", - "build:extension": "CI=true npm run build -w extension", + "build": "cross-env CI=true npm run build -w projects && cross-env CI=true npm run build -w runner && cross-env CI=true npm run build -w simulator && cross-env CI=true npm run build -w cli && cross-env CI=true npm run build -w components && cross-env CI=true npm run build -w web && cross-env CI=true npm run build -w extension", + "build:extension": "cross-env CI=true npm run build -w extension", "pretest": "npm run build", - "test": "CI=true npm test -w simulator && CI=true npm test -w components && CI=true npm test -w web", + "test": "cross-env CI=true npm test -w simulator && cross-env CI=true npm test -w components && cross-env CI=true npm test -w web", "web": "npm run start -w web", "start": "npm run web", "preinstall-cli": "npm run build -w projects && npm run build -w runner && npm run build -w simulator && npm run build -w cli", @@ -48,5 +48,9 @@ "engines": { "node": ">=16", "npm": ">=7" + }, + "devDependencies": { + "cross-env": "^7.0.3", + "shx": "^0.3.4" } } diff --git a/web/package.json b/web/package.json index 1c636fe52..edcbbbe28 100644 --- a/web/package.json +++ b/web/package.json @@ -52,9 +52,9 @@ "analyze": "source-map-explorer 'build/static/js/*.js'", "preanalyze": "npm run map-build", "start": "react-scripts start", - "build": "GENERATE_SOURCEMAP=false react-scripts build", + "build": "cross-env GENERATE_SOURCEMAP=false react-scripts build", "map-build": "react-scripts build", - "postbuild": "./scripts/predeploy.sh", + "postbuild": "node ./scripts/predeploy.js", "preserve-pwa": "npm run build ; ln -s build web-ide", "serve-pwa": "python3 -m http.server", "test": "react-scripts test", diff --git a/web/scripts/predeploy.js b/web/scripts/predeploy.js new file mode 100644 index 000000000..995425632 --- /dev/null +++ b/web/scripts/predeploy.js @@ -0,0 +1,27 @@ +const fs = require("fs-extra"); +const path = require("path"); + +const scriptDir = path.dirname(__filename); +const buildDir = path.resolve(scriptDir, "..", "build"); + +fs.ensureDirSync(buildDir); +process.chdir(buildDir); + +const folders = [ + "chip", + "cpu", + "asm", + "vm", + "compiler", + "bitmap", + "guide", + "util", + "about", +]; + +for (const folder of folders) { + fs.ensureDirSync(folder); + fs.copyFileSync("index.html", path.join(folder, "index.html")); +} + +console.log("Predeploy tasks completed."); diff --git a/web/scripts/predeploy.sh b/web/scripts/predeploy.sh deleted file mode 100755 index 619e2c555..000000000 --- a/web/scripts/predeploy.sh +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/bash - -cd "$(dirname "$(readlink -f "$0")")/.." -cd build - -for F in chip cpu asm vm compiler bitmap guide util about; do - mkdir $F - cp index.html $F/index.html -done