diff --git a/.github/workflows/jsweet.yml b/.github/workflows/jsweet.yml index 376d409d0..506bcfc2f 100644 --- a/.github/workflows/jsweet.yml +++ b/.github/workflows/jsweet.yml @@ -85,8 +85,8 @@ jobs: - name: Build with Gradle and JSweet run: | pwd - chmod +x gradlew cicd/jsweet-legacy-code.bash - cicd/jsweet-legacy-code.bash + chmod +x gradlew cicd/online.bash + cicd/online.bash jsweet - name: Archive Generated JS uses: actions/upload-artifact@v3 diff --git a/.github/workflows/online.yml b/.github/workflows/online.yml index afbdf81ef..15e400983 100644 --- a/.github/workflows/online.yml +++ b/.github/workflows/online.yml @@ -93,8 +93,8 @@ jobs: node-version: ${{ matrix.node-version }} - name: Build with Gradle and Yarn run: | - chmod +x gradlew cicd/build-online.bash - cicd/build-online.bash + chmod +x gradlew cicd/online.bash + cicd/online.bash prod - name: Configure SSH run: | diff --git a/cicd/build-online.bash b/cicd/build-online.bash deleted file mode 100755 index 0ddffd783..000000000 --- a/cicd/build-online.bash +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/bash - -banner() { - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%% '$1 - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' -} - -REVISION=${BUILD_NUMBER:-'DEV'} - -if [ "$1" != 'quick' ]; then - cicd/jsweet-legacy-code.bash || exit $? -fi - -cd online - -banner 'Marshalling core and desktop resources' -# Remove the detritus of earlier builds (& dev server) -rm -rf serve/modules || exit $? -rm -rf serve/app/classic/resources || exit $? -# Marshall the resources from core and desktop -mkdir -p serve/app/classic/resources/com/vzome/core/exporters || exit $? -cp -R ../desktop/src/main/resources/* serve/app/classic/resources || exit $? -cp -R ../core/src/main/resources/com/vzome/core/exporters/* serve/app/classic/resources/com/vzome/core/exporters || exit $? - -if [ "$1" == 'quick' ]; then - exit 0; -fi - -banner 'Generating src/revision.js' -echo "export const REVISION=\"${REVISION}\";" > src/revision.js -echo "export const importLegacy = async () => import( './worker/legacy/dynamic.js' );" >> src/revision.js -echo "export const importZomic = async () => import( './worker/legacy/zomic/index.js' );" >> src/revision.js -# index exporter resources -( cd serve/app/classic/resources - echo 'export const resourceIndex = [' - find com/vzome/core/exporters -type f -exec echo " \"{}\"", \; - echo ' ];' ) >> src/revision.js - -banner 'Preparing the distribution folder with NPM' -yarn install || exit $? -rm -rf dist || exit $? -yarn run build || exit $? - -cd dist - -banner 'Creating the online.tgz archive' - cp -R ../serve/app/* app && \ - rm -rf app/test* && \ - echo 'Header always set Access-Control-Allow-Origin "*"' > modules/.htaccess && \ - echo ${REVISION} > modules/revision.txt && \ - tar czvf online.tgz app modules - -banner 'finished building the vZome Online apps and web component' - diff --git a/cicd/jsweet-legacy-code.bash b/cicd/jsweet-legacy-code.bash index 1099497cb..170413287 100755 --- a/cicd/jsweet-legacy-code.bash +++ b/cicd/jsweet-legacy-code.bash @@ -1,24 +1,18 @@ #!/bin/bash -banner() { - echo '' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%% '$1 - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '' -} +if [ -z ${REVISION+x} ]; then + echo "This script is not meant to run as a top-level entry point. Use online.bash." + exit 1 +fi -# This is designed to run from the main repo as a working directory. -# From the command line there, run "cicd/jsweet-legacy-code.bash". +verifyJava - -rm -rf online/node_modules online/.jsweet +# removing online/node_modules/@types because the JSweet TSC doesn't like Three.d.ts +rm -rf online/.jsweet online/jsweetOut online/node_modules/@types banner 'Transpiling core Java sources with JSweet' ###################################### -./gradlew --continue -p online coreClean core &> core-errors.txt # ignore the exit code, it always fails +./gradlew --continue --info -p online coreClean core &> core-errors.txt # ignore the exit code, it always fails cat core-errors.txt grep -q 'transpilation failed with 33 error(s) and 0 warning(s)' core-errors.txt \ @@ -26,10 +20,6 @@ grep -q 'transpilation failed with 33 error(s) and 0 warning(s)' core-errors.txt || { banner 'UNEXPECTED CHANGE IN JSWEET CORE ERRORS'; exit 1; } -LEGACY=online/src/worker/legacy -CANDIES_IN=online/jsweetOut/core/candies -CANDIES_OUT="$LEGACY/candies" - banner 'Patching up the j4ts bundle as an ES6 module' ###################################### # also, working around https://github.com/cincheo/jsweet/issues/740, diff --git a/cicd/online.bash b/cicd/online.bash new file mode 100755 index 000000000..9ce74168d --- /dev/null +++ b/cicd/online.bash @@ -0,0 +1,192 @@ +#!/bin/bash + +REVISION=${BUILD_NUMBER:-'DEV'} + +LEGACY=online/src/worker/legacy +CANDIES_IN=online/jsweetOut/core/candies +CANDIES_OUT="$LEGACY/candies" + +banner() { + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%% '$1 + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' + echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' +} + +verifyJava(){ + JAVA_VER=$(java -version 2>&1 | head -1 | cut -d'"' -f2 | sed '/^1\./s///' | cut -d'.' -f1) + echo "detected Java $JAVA_VER" + if [ "$JAVA_VER" -ne 11 ]; then + echo "This script requires JAVA_HOME to point at a Java 11 JDK." + exit 1 + fi +} + +clean() { + rm -rf jsweet-branches || exit $? + cd online + + rm -rf src/worker/legacy/candies || exit $? + rm -rf src/worker/legacy/core-java.js || exit $? + + rm -rf .jsweet || exit $? + rm -rf jsweetOut || exit $? + rm -rf dist || exit $? + rm -rf node_modules || exit $? + rm -rf serve/modules || exit $? + rm -rf serve/app/classic/resources || exit $? +} + +marshallResources() { + banner 'Marshalling core and desktop resources' + # Remove the detritus of earlier builds (& dev server) + rm -rf serve/modules || exit $? + rm -rf serve/app/classic/resources || exit $? + # Marshall the resources from core and desktop + mkdir -p serve/app/classic/resources/com/vzome/core/exporters || exit $? + cp -R ../desktop/src/main/resources/* serve/app/classic/resources || exit $? + cp -R ../core/src/main/resources/com/vzome/core/exporters/* serve/app/classic/resources/com/vzome/core/exporters || exit $? +} + +generateRevisionJs() { + banner 'Generating src/revision.js' + if [ -z ${1+x} ]; then + echo "export const REVISION=\"${REVISION}\";" > src/revision.js + echo "export const importLegacy = async () => import( './worker/legacy/dynamic.js' );" >> src/revision.js + echo "export const importZomic = async () => import( './worker/legacy/zomic/index.js' );" >> src/revision.js + else + echo "export const REVISION=\"${1}\";" > src/revision.js + echo "export const importLegacy = async () => import( 'https://www.vzome.com/modules/vzome-legacy.js' );" >> src/revision.js + echo "export const importZomic = async () => import( 'https://www.vzome.com/modules/vzome-zomic.js' );" >> src/revision.js + fi + + # index exporter resources + ( cd serve/app/classic/resources + echo 'export const resourceIndex = [' + find com/vzome/core/exporters -type f -exec echo " \"{}\"", \; + echo ' ];' ) >> src/revision.js +} + +installJsDependencies(){ + banner 'Preparing the distribution folder with Yarn' + yarn install || exit $? +} + +buildForProduction() { + installJsDependencies || exit $? + + rm -rf dist || exit $? + yarn run build || exit $? + + cd dist + + banner 'Creating the online.tgz archive' + cp -R ../serve/app/* app && \ + rm -rf app/test* && \ + echo 'Header always set Access-Control-Allow-Origin "*"' > modules/.htaccess && \ + echo ${REVISION} > modules/revision.txt && \ + tar czvf online.tgz app modules +} + +prepareJSweet(){ + source cicd/prepare-jsweet.bash || exit $? +} + +jsweet(){ + source cicd/jsweet-legacy-code.bash || exit $? +} + +devJava(){ + jsweet || exit $? + + cd online + + marshallResources || exit $? + + generateRevisionJs || exit $? + + installJsDependencies || exit $? + + yarn run dev +} + +devJs(){ + cd online + + marshallResources || exit $? + + generateRevisionJs || exit $? + + installJsDependencies || exit $? + + yarn run dev +} + +devQuick(){ + cd online + + marshallResources || exit $? + + generateRevisionJs 'QUICKSTART' || exit $? + + installJsDependencies || exit $? + + yarn run nolegacy +} + +productionBuild(){ + jsweet || exit $? + + cd online + + marshallResources || exit $? + + generateRevisionJs || exit $? + + buildForProduction || exit $? + + banner 'finished building the vZome Online apps and web component' +} + + +case $1 in + + quickstart) + devQuick + ;; + + dev) + devJs + ;; + + prepareJSweet) + prepareJSweet + ;; + + jsweet) + jsweet + ;; + + java) + devJava + ;; + + prod) + productionBuild + ;; + + clean) + clean + ;; + + *) + banner 'no command (quickstart|dev|java|prod) provided' + ;; +esac + + diff --git a/online/prepare-jsweet.sh b/cicd/prepare-jsweet.bash similarity index 63% rename from online/prepare-jsweet.sh rename to cicd/prepare-jsweet.bash index b161a5e5e..b5e757c83 100755 --- a/online/prepare-jsweet.sh +++ b/cicd/prepare-jsweet.bash @@ -1,18 +1,16 @@ #!/bin/bash -cd .. +if [ -z ${REVISION+x} ]; then + echo "This script is not meant to run as a top-level entry point." + exit 1 +fi + +verifyJava + rm -rf jsweet-branches mkdir jsweet-branches cd jsweet-branches -banner() { - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%% '$1 - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' - echo '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' -} - clone() { banner "git clone vorth/$1" git clone -b $2 https://github.com/vorth/$1 || exit $? @@ -20,12 +18,9 @@ clone() { clone jsweet develop clone jsweet-maven-plugin master -clone j4ts update-jsweet +clone j4ts master clone jsweet-gradle-plugin update-jsweet -banner 'setting java 11 home' -export JAVA_HOME=`/usr/libexec/java_home -v 11` || exit $? - banner 'building JSweet' cd jsweet/transpiler/ || exit $? mvn clean install -Dmaven.test.skip=true -DskipJavadoc=true -DskipSigning=true || exit $? diff --git a/online/README.md b/online/README.md index 1185f8392..c8beda2ec 100644 --- a/online/README.md +++ b/online/README.md @@ -18,22 +18,17 @@ or loading an existing design for editing. ## Prerequisites -You'll need [Node.js](https://nodejs.org/en). That includes `npm`, but I prefer [Yarn](https://yarnpkg.com/getting-started/install). +You'll need [Node.js](https://nodejs.org/en) and [Yarn](https://yarnpkg.com/getting-started/install); +the `online.bash` script uses `yarn` explicitly. ## Quick Start This quick-start workflow bypasses building the legacy code, downloading it from `vzome.com` instead. -Simply execute this command line in this directory (`online`): +Simply execute this command line in root directory (the parent of the directory containing this file): ```bash -yarn && ../cicd/build-online.bash quick && yarn quick +cicd/online.bash quickstart ``` -or, if you prefer `npm`: -```bash -npm install && ../cicd/build-online.bash quick && npm run quick -``` -...then visit one of the URLs indicated in the output banner to try an app. - -For subsequent builds, all you need is `yarn quick` or `npm run quick`. +...then visit the URL indicated in the output banner to try the apps and test pages. ## Legacy Code Dev Workflow @@ -55,16 +50,12 @@ upstream projects but not yet merged, or merged but no release has been published, since the JSweet maintainers have largely moved on to other projects. -For the steps below, I find it convenient to keep two terminal windows open, -since I often I need to iterate the steps. -I'll call these the *main shell* and the *online shell*. -In the main shell, the working directory should be the root folder for the +For these steps, the working directory should be the root folder for the Git repository; this is the parent of the `online` folder. -In the online shell, it should be the `online` subfolder. -First, in the online shell, execute this script: +First, execute this script: ``` -./prepare-jsweet.sh +cicd/online.bash prepareJSweet ``` This will create a `jsweet-branches` folder as a sibling of `online`, check out the four branches listed above, and build them in sequence. @@ -74,23 +65,28 @@ local Maven cache. Since this steps is not touching any code in this repository, you should not need to repeat it unless you set up another machine to work on vZome Online. -Next, from the main shell run: +Next, run: ``` -cicd/build-online.bash +cicd/online.bash java ``` You'll need to do this whenever the Java source code has changed, since it does the JSweet transpile. You'll see a number of errors during the transpilation, but that is expected. The script checks for the expected number of errors, and fails if there are more errors or fewer. -Now, in the online shell do -``` -yarn && yarn dev -``` -This is a dev server, which means it will detect file changes and update the live server. +This command also starts a dev server, which means it will detect file changes and update the live server. You can leave this running for hours or days as you do your development. However, it is not set up for hot module reloading, so you'll need to refresh your browser pages manually. Finally, copy `vscode-launch-template.json` as `.vscode/launch.json` (relative to the main folder). -This gives you several launch profiles. Using the VS Code debugging view, launch the `online` profile. This will start a dedicated Chrome window running vZome Online, with the ability to set breakpoints in the `online` source code in VS Code. Note that this only starts the client-side Chrome. You must have the dev server started also, per the prior paragraph. +This gives you several launch profiles. Using the VS Code debugging view, launch the `TEST` profile. This will start a dedicated Chrome window running vZome Online, with the ability to set breakpoints in the `online` source code in VS Code. Note that this only starts the client-side Chrome. You must have the dev server started also, per the prior paragraph. + +If you cancel the running dev server, and want to test Javascript-only changes, +you can simply run: +``` +cicd/online.bash dev +``` +This is only appropriate if you have not touched any Java code. +This is my most common workflow step, as I'm usually working on Javascript code, not Java code. +Like the `java` subcommand, it leaves a dev server running. ## Testing the Web Component diff --git a/online/package.json b/online/package.json index 06770dde1..826c7bb4f 100644 --- a/online/package.json +++ b/online/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "build": "node scripts/prod-build.mjs", - "quick": "node scripts/test-app.mjs quick", + "nolegacy": "node scripts/test-app.mjs nolegacy", "dev": "node scripts/test-app.mjs", "https": "node scripts/test-https.mjs" }, diff --git a/online/scripts/test-app.mjs b/online/scripts/test-app.mjs index b5932142e..0ddd3def6 100644 --- a/online/scripts/test-app.mjs +++ b/online/scripts/test-app.mjs @@ -13,25 +13,20 @@ const commonConfig = { const port = 8532; -if ( argv .includes( 'quick' ) ) { +if ( argv .includes( 'nolegacy' ) ) { // Avoid bundling any of the legacy code; the 'vzome-legacy' dynamic bundle will be missing from runtime delete commonConfig.entryPoints[ 'vzome-legacy' ]; commonConfig.external = [ './legacy/*.js' ]; - - writeFileSync( 'src/revision.js', 'export const REVISION="QUICKSTART"; export const resourceIndex = []; export const importLegacy = async () => import( "https://www.vzome.com/modules/vzome-legacy.js" ); export const importZomic = async () => import( "https://www.vzome.com/modules/vzome-zomic.js" );' ); - - console.log( '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' ); - console.log( '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' ); - console.log( '' ); - console.log( ` Visit http://localhost:${port}/app/59icosahedra` ); - console.log( ` or http://localhost:${port}/app/classic` ); - console.log( ` or http://localhost:${port}/app/browser` ); - console.log( ' or any other vZome app on the same port.' ); - console.log( '' ); - console.log( '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' ); - console.log( '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' ); } +console.log( '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' ); +console.log( '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' ); +console.log( '' ); +console.log( ` Visit http://localhost:${port}/app/test/` ); +console.log( '' ); +console.log( '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' ); +console.log( '%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%' ); + let ctx = await esbuild.context( commonConfig ); ctx.serve( { servedir: 'serve', port } ); diff --git a/online/src/app/classic/dialogs/sharing.jsx b/online/src/app/classic/dialogs/sharing.jsx index d7e5be71a..4200183b8 100644 --- a/online/src/app/classic/dialogs/sharing.jsx +++ b/online/src/app/classic/dialogs/sharing.jsx @@ -24,7 +24,7 @@ import { Tooltip } from '../../framework/tooltip.jsx' import { useViewer } from "../../../viewer/context/viewer.jsx"; import { useEditor } from '../../framework/context/editor.jsx'; import { resumeMenuKeyEvents, suspendMenuKeyEvents } from '../context/commands.jsx'; -import { getUserRepos } from "../../../worker/legacy/gitcommit.js"; +import { getUserRepos } from "../../../both-contexts.js"; const AUTHENTICATING = 0; const CHOOSING_REPO = 1; diff --git a/online/src/both-contexts.js b/online/src/both-contexts.js new file mode 100644 index 000000000..b5d574791 --- /dev/null +++ b/online/src/both-contexts.js @@ -0,0 +1,8 @@ + +import { commitToGitHub, getUserRepos } from './worker/legacy/gitcommit.js'; +import { assemblePartsList } from './worker/legacy/partslist.js'; +import { normalizePreview } from './worker/legacy/preview.js'; // does not actually use any legacy module code + +export { + commitToGitHub, getUserRepos, assemblePartsList, normalizePreview, +} \ No newline at end of file diff --git a/online/src/worker/vzome-worker-static.js b/online/src/worker/vzome-worker-static.js index 7d3f00e4d..8556218e9 100644 --- a/online/src/worker/vzome-worker-static.js +++ b/online/src/worker/vzome-worker-static.js @@ -1,8 +1,6 @@ import { resourceIndex, importLegacy, importZomic } from '../revision.js'; -import { commitToGitHub } from './legacy/gitcommit.js'; -import { assemblePartsList } from './legacy/partslist.js'; -import { normalizePreview } from './legacy/preview.js'; // does not actually use any legacy module code +import { commitToGitHub, assemblePartsList, normalizePreview } from '../both-contexts.js'; // const uniqueId = Math.random();