From 65a6a72643fc96cb146c065f8dbde44a794ef87d Mon Sep 17 00:00:00 2001 From: Baptiste Grimaud Date: Fri, 7 Feb 2025 16:35:28 +0100 Subject: [PATCH 1/2] build: move deploy script into JS library --- .../tests/jahia-module/yarn.lock | 14 ++++++++-- javascript-modules-engine/yarn.lock | 14 ++++++++-- javascript-modules-library/package.json | 8 ++++-- .../src/bin/jahia-deploy.mjs | 27 +++++++++++++++++++ javascript-modules-library/tsconfig.json | 3 ++- javascript-modules-library/yarn.lock | 10 +++++++ 6 files changed, 69 insertions(+), 7 deletions(-) create mode 100644 javascript-modules-library/src/bin/jahia-deploy.mjs diff --git a/javascript-modules-engine/tests/jahia-module/yarn.lock b/javascript-modules-engine/tests/jahia-module/yarn.lock index f3914908..5098655c 100644 --- a/javascript-modules-engine/tests/jahia-module/yarn.lock +++ b/javascript-modules-engine/tests/jahia-module/yarn.lock @@ -1703,8 +1703,9 @@ __metadata: "@jahia/javascript-modules-library@file:../../../javascript-modules-library/dist::locator=%40jahia%2Fnpm-module-example%40workspace%3A.": version: 0.4.0-SNAPSHOT - resolution: "@jahia/javascript-modules-library@file:../../../javascript-modules-library/dist#../../../javascript-modules-library/dist::hash=9e300c&locator=%40jahia%2Fnpm-module-example%40workspace%3A." + resolution: "@jahia/javascript-modules-library@file:../../../javascript-modules-library/dist#../../../javascript-modules-library/dist::hash=3d895a&locator=%40jahia%2Fnpm-module-example%40workspace%3A." dependencies: + dotenv: "npm:^16.4.7" graphql: "npm:^16.0.1" graphql-tag: "npm:^2.12.6" prop-types: "npm:^15.8.1" @@ -1725,7 +1726,9 @@ __metadata: optional: true styled-jsx: optional: true - checksum: 10/9cc7e6803a50ed8418b64983574889bb5d760f4acb39aab6c9f4c61b26c7d9563e97acaea31d34d144c54b58325cc01e3cb344ddd9fae9c24f6881aa03892454 + bin: + jahia-deploy: bin/jahia-deploy.mjs + checksum: 10/0f5553384f866e1374095fb25df8089cf2286730fb793fcfaa3b2fd9d5ad854ed54319f34f334c3f28f3cbb5c53fb69e3a66eee34905727cdc5d9c1b369d9529 languageName: node linkType: hard @@ -3515,6 +3518,13 @@ __metadata: languageName: node linkType: hard +"dotenv@npm:^16.4.7": + version: 16.4.7 + resolution: "dotenv@npm:16.4.7" + checksum: 10/f13bfe97db88f0df4ec505eeffb8925ec51f2d56a3d0b6d916964d8b4af494e6fb1633ba5d09089b552e77ab2a25de58d70259b2c5ed45ec148221835fc99a0c + languageName: node + linkType: hard + "dotenv@npm:^8.2.0": version: 8.6.0 resolution: "dotenv@npm:8.6.0" diff --git a/javascript-modules-engine/yarn.lock b/javascript-modules-engine/yarn.lock index 77b1fd83..6e0a98f0 100644 --- a/javascript-modules-engine/yarn.lock +++ b/javascript-modules-engine/yarn.lock @@ -1277,8 +1277,9 @@ __metadata: "@jahia/javascript-modules-library@file:../javascript-modules-library/dist::locator=javascript-modules-engine%40workspace%3A.": version: 0.4.0-SNAPSHOT - resolution: "@jahia/javascript-modules-library@file:../javascript-modules-library/dist#../javascript-modules-library/dist::hash=2a2152&locator=javascript-modules-engine%40workspace%3A." + resolution: "@jahia/javascript-modules-library@file:../javascript-modules-library/dist#../javascript-modules-library/dist::hash=e5271e&locator=javascript-modules-engine%40workspace%3A." dependencies: + dotenv: "npm:^16.4.7" graphql: "npm:^16.0.1" graphql-tag: "npm:^2.12.6" prop-types: "npm:^15.8.1" @@ -1299,7 +1300,9 @@ __metadata: optional: true styled-jsx: optional: true - checksum: 10c0/5899a54137b102251184b691c8c72f0f168685da4f0da676e5369a143ccb2d9a21f012fbed50bafa1e032dde1b67a722a1e1525e69c4970be0eefd99b0b9a85c + bin: + jahia-deploy: bin/jahia-deploy.mjs + checksum: 10c0/241e3ca0bcc8c289f01548277263d023fe6c81215eed3464e47223ae434257ceb9e338fdbc24ca081bbe7504c5fa15c6c4b0324dbaefa673b7631039ca9abfb4 languageName: node linkType: hard @@ -2533,6 +2536,13 @@ __metadata: languageName: node linkType: hard +"dotenv@npm:^16.4.7": + version: 16.4.7 + resolution: "dotenv@npm:16.4.7" + checksum: 10c0/be9f597e36a8daf834452daa1f4cc30e5375a5968f98f46d89b16b983c567398a330580c88395069a77473943c06b877d1ca25b4afafcdd6d4adb549e8293462 + languageName: node + linkType: hard + "duplexer@npm:^0.1.2": version: 0.1.2 resolution: "duplexer@npm:0.1.2" diff --git a/javascript-modules-library/package.json b/javascript-modules-library/package.json index 70273a32..f80e88e2 100644 --- a/javascript-modules-library/package.json +++ b/javascript-modules-library/package.json @@ -7,20 +7,24 @@ "license": "MIT", "scripts": { "types:copy": "mkdir -p dist/types && ncp target/types dist/types", - "build:development": "run types:copy && tsc && node generate-index", + "build:development": "run types:copy && tsc && node generate-index.js", "build:production": "run build:development && run minify", "build": "run build:production", - "minify": "node minify", + "minify": "node minify.js", "doc": "typedoc", "clean": "rm -rf dist", "lint": "eslint --ext js,jsx,json,ts src/", "lint:fix": "eslint --ext js,jsx,json,ts --fix src/", "prepack": "echo 'Please run 'mvn package' to create the tgz so the Maven version can be injected in the package.json' && exit 1" }, + "bin": { + "jahia-deploy": "bin/jahia-deploy.mjs" + }, "files": [ "dist" ], "dependencies": { + "dotenv": "^16.4.7", "graphql": "^16.0.1", "graphql-tag": "^2.12.6", "prop-types": "^15.8.1" diff --git a/javascript-modules-library/src/bin/jahia-deploy.mjs b/javascript-modules-library/src/bin/jahia-deploy.mjs new file mode 100644 index 00000000..9bc26119 --- /dev/null +++ b/javascript-modules-library/src/bin/jahia-deploy.mjs @@ -0,0 +1,27 @@ +import dotenv from 'dotenv'; +import {execSync} from 'child_process'; +import path from 'path'; + +dotenv.config(); + +const deployMethod = process.env.JAHIA_DEPLOY_METHOD; + +const packageFilePath = path.resolve('dist/package.tgz'); + +if (deployMethod === 'curl') { + console.log('Deploying URL curl to Jahia bundles REST API...'); + console.log( + execSync( + `curl -s --user ${process.env.JAHIA_USER} --form bundle=@${packageFilePath} --form start=true ${process.env.JAHIA_HOST}/modules/api/bundles`, + {encoding: 'utf8'} + ) + ); +} else { + console.log('Deploying using Docker copy...'); + console.log( + execSync( + `docker cp ${packageFilePath} ${process.env.JAHIA_DOCKER_NAME}:/var/jahia/modules`, + {encoding: 'utf8'} + ) + ); +} diff --git a/javascript-modules-library/tsconfig.json b/javascript-modules-library/tsconfig.json index fe3218b1..ff8213f8 100644 --- a/javascript-modules-library/tsconfig.json +++ b/javascript-modules-library/tsconfig.json @@ -26,7 +26,8 @@ }, }, "include": [ - "src/**/*.js", + "src/**/*.js", + "src/**/*.mjs" ], "exclude": [ "node_modules", diff --git a/javascript-modules-library/yarn.lock b/javascript-modules-library/yarn.lock index 051a5d7e..6776d641 100644 --- a/javascript-modules-library/yarn.lock +++ b/javascript-modules-library/yarn.lock @@ -1654,6 +1654,7 @@ __metadata: "@typescript-eslint/parser": "npm:^4.29.3" babel-loader: "npm:^9.1.3" babel-plugin-transform-react-jsx: "npm:^6.24.1" + dotenv: "npm:^16.4.7" eslint: "npm:^7.32.0" eslint-plugin-cypress: "npm:^2.11.3" eslint-plugin-jest: "npm:^27.2.1" @@ -1688,6 +1689,8 @@ __metadata: optional: true styled-jsx: optional: true + bin: + jahia-deploy: bin/jahia-deploy.mjs languageName: unknown linkType: soft @@ -2828,6 +2831,13 @@ __metadata: languageName: node linkType: hard +"dotenv@npm:^16.4.7": + version: 16.4.7 + resolution: "dotenv@npm:16.4.7" + checksum: 10c0/be9f597e36a8daf834452daa1f4cc30e5375a5968f98f46d89b16b983c567398a330580c88395069a77473943c06b877d1ca25b4afafcdd6d4adb549e8293462 + languageName: node + linkType: hard + "eastasianwidth@npm:^0.2.0": version: 0.2.0 resolution: "eastasianwidth@npm:0.2.0" From 19c34169e7f5d6fcd89d7ce180a17289e9b56b87 Mon Sep 17 00:00:00 2001 From: Baptiste Grimaud Date: Fri, 7 Feb 2025 16:59:45 +0100 Subject: [PATCH 2/2] cleanup --- javascript-modules-engine/tests/jahia-module/yarn.lock | 4 ++-- javascript-modules-engine/yarn.lock | 4 ++-- javascript-modules-library/package.json | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/javascript-modules-engine/tests/jahia-module/yarn.lock b/javascript-modules-engine/tests/jahia-module/yarn.lock index 5098655c..0dc89508 100644 --- a/javascript-modules-engine/tests/jahia-module/yarn.lock +++ b/javascript-modules-engine/tests/jahia-module/yarn.lock @@ -1703,7 +1703,7 @@ __metadata: "@jahia/javascript-modules-library@file:../../../javascript-modules-library/dist::locator=%40jahia%2Fnpm-module-example%40workspace%3A.": version: 0.4.0-SNAPSHOT - resolution: "@jahia/javascript-modules-library@file:../../../javascript-modules-library/dist#../../../javascript-modules-library/dist::hash=3d895a&locator=%40jahia%2Fnpm-module-example%40workspace%3A." + resolution: "@jahia/javascript-modules-library@file:../../../javascript-modules-library/dist#../../../javascript-modules-library/dist::hash=f5e20b&locator=%40jahia%2Fnpm-module-example%40workspace%3A." dependencies: dotenv: "npm:^16.4.7" graphql: "npm:^16.0.1" @@ -1728,7 +1728,7 @@ __metadata: optional: true bin: jahia-deploy: bin/jahia-deploy.mjs - checksum: 10/0f5553384f866e1374095fb25df8089cf2286730fb793fcfaa3b2fd9d5ad854ed54319f34f334c3f28f3cbb5c53fb69e3a66eee34905727cdc5d9c1b369d9529 + checksum: 10/a4ec52b065a544a4b0d5753b8304bfbc51ed792e2dfcbb480d9a85c344dbbb6ccb0bf5bd497fde0d45b9f8ce36fd9a5223cc3dc648b1f4b063056088cee1b0f4 languageName: node linkType: hard diff --git a/javascript-modules-engine/yarn.lock b/javascript-modules-engine/yarn.lock index 6e0a98f0..a2696fcf 100644 --- a/javascript-modules-engine/yarn.lock +++ b/javascript-modules-engine/yarn.lock @@ -1277,7 +1277,7 @@ __metadata: "@jahia/javascript-modules-library@file:../javascript-modules-library/dist::locator=javascript-modules-engine%40workspace%3A.": version: 0.4.0-SNAPSHOT - resolution: "@jahia/javascript-modules-library@file:../javascript-modules-library/dist#../javascript-modules-library/dist::hash=e5271e&locator=javascript-modules-engine%40workspace%3A." + resolution: "@jahia/javascript-modules-library@file:../javascript-modules-library/dist#../javascript-modules-library/dist::hash=3d703a&locator=javascript-modules-engine%40workspace%3A." dependencies: dotenv: "npm:^16.4.7" graphql: "npm:^16.0.1" @@ -1302,7 +1302,7 @@ __metadata: optional: true bin: jahia-deploy: bin/jahia-deploy.mjs - checksum: 10c0/241e3ca0bcc8c289f01548277263d023fe6c81215eed3464e47223ae434257ceb9e338fdbc24ca081bbe7504c5fa15c6c4b0324dbaefa673b7631039ca9abfb4 + checksum: 10c0/afe30647aa916a2053d36eb6c8ae5143315f7a0e929017e1fa445a2ccf5e97a52f5d23739cfea0104f7ca2821a668e4ee687f594087ed8bd442493f2b21ffb6b languageName: node linkType: hard diff --git a/javascript-modules-library/package.json b/javascript-modules-library/package.json index f80e88e2..1edc1e8f 100644 --- a/javascript-modules-library/package.json +++ b/javascript-modules-library/package.json @@ -7,10 +7,10 @@ "license": "MIT", "scripts": { "types:copy": "mkdir -p dist/types && ncp target/types dist/types", - "build:development": "run types:copy && tsc && node generate-index.js", + "build:development": "run types:copy && tsc && node generate-index", "build:production": "run build:development && run minify", "build": "run build:production", - "minify": "node minify.js", + "minify": "node minify", "doc": "typedoc", "clean": "rm -rf dist", "lint": "eslint --ext js,jsx,json,ts src/",