From c73e2d11ba93309b2e93f7ad96aabb46cbd2b1d6 Mon Sep 17 00:00:00 2001 From: barduinor Date: Mon, 18 Sep 2023 16:52:35 -0400 Subject: [PATCH] updated classic release to use the new bulk deploy to CI/CD and merge to public --- package.json | 4 ++-- src/DeployBulk.js | 31 +++++++++++++++++++++---------- src/scripts/release.js | 11 +++++++---- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/package.json b/package.json index 59ff76b..3f67f3c 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,8 @@ "prebuild:all": "yarn prebuild", "convert": "node -e 'require(\"./src/scripts/convert.js\").convert()'", "convert:all": "node -e 'require(\"./src/scripts/convert.js\").convertAll()'", - "x_prerelease": "yarn build", - "x_prerelease:all": "yarn build:all", + "prerelease": "yarn build:all", + "prerelease:all": "yarn build:all", "release": "node -e 'require(\"./src/scripts/release.js\").release()'", "release:all": "node -e 'require(\"./src/scripts/release.js\").releaseAll()'", "build": "yarn convert", diff --git a/src/DeployBulk.js b/src/DeployBulk.js index 6208d87..fd91bed 100644 --- a/src/DeployBulk.js +++ b/src/DeployBulk.js @@ -1,12 +1,13 @@ // const pmConvert = require('./PostmanCovertions') const pmAPI = require('./postmanAPI') -const deployColectionHead = async (localCollection, remoteCollectionID) => { +const deployColectionHead = async (privateRemoteCollectionID, localCollection) => { const collectionHead = { ...localCollection } collectionHead.item = [] - const msg = `\nDeploying collection head ${collectionHead.info.name} to ${remoteCollectionID}` - await new pmAPI.Collection(remoteCollectionID) - .update(collectionHead) + const msg = `\nDeploying collection head ${collectionHead.info.name} to ${privateRemoteCollectionID}` + console.log(msg + '...') + await new pmAPI.Collection(privateRemoteCollectionID) + .update({ collection: collectionHead }) .then(() => { console.log(msg, '-> OK\n') }) .catch((error) => { console.log(msg, '-> FAIL') @@ -14,10 +15,20 @@ const deployColectionHead = async (localCollection, remoteCollectionID) => { }) } -const deployColectionFull = async (localCollection, remoteCollectionID) => { - const msg = `\nDeploying full collection ${localCollection.info.name} to ${remoteCollectionID}` - await new pmAPI.Collection(remoteCollectionID) - .update(localCollection) +const deployColectionFull = async (privateRemoteCollectionId, localCollection, publicRemoteCollectionId) => { + let msg = `\nDeploying full collection ${localCollection.info.name} to ${privateRemoteCollectionId}` + console.log(msg + '...') + await new pmAPI.Collection(privateRemoteCollectionId) + .update({ collection: localCollection }) + .then(() => { console.log(msg, '-> OK\n') }) + .catch((error) => { + console.log(msg, '-> FAIL') + handlePostmanAPIError(error) + }) + + msg = 'Merging to public collection' + console.log('\n' + msg + '...') + await new pmAPI.Collection(privateRemoteCollectionId).merge(publicRemoteCollectionId) .then(() => { console.log(msg, '-> OK\n') }) .catch((error) => { console.log(msg, '-> FAIL') @@ -40,8 +51,8 @@ const handlePostmanAPIError = (error) => { console.log('CAUSE:', error.cause) } } - const { method, url, data } = error.config - console.log('REQUEST DETAILS', { method, url, data }) + // const { method, url, data } = error.config + // console.log('REQUEST DETAILS', { method, url, data }) process.exit(1) } diff --git a/src/scripts/release.js b/src/scripts/release.js index 340a3b2..7fa2f72 100644 --- a/src/scripts/release.js +++ b/src/scripts/release.js @@ -1,15 +1,18 @@ require('dotenv').config() const fs = require('fs') -const oldDeploy = require('../OldDeployBulk') +// const oldDeploy = require('../OldDeployBulk') +const deployBulk = require('../DeployBulk') const OUTPUT_FOLDER = './compiled' const release = async (locale = process.argv[1]) => { const collection = JSON.parse(fs.readFileSync(`${OUTPUT_FOLDER}/collection.${locale}.json`).toString()) - // const privateRemoteCollectionID = process.env[`PRIVATE_${locale.toUpperCase()}_POSTMAN_COLLECTION_ID`] - const publicRemoteCollectionID = process.env[`PUBLIC_${locale.toUpperCase()}_POSTMAN_COLLECTION_ID`] + const privateRemoteCollectionId = process.env[`PRIVATE_${locale.toUpperCase()}_POSTMAN_COLLECTION_ID`] + const publicRemoteCollectionId = process.env[`PUBLIC_${locale.toUpperCase()}_POSTMAN_COLLECTION_ID`] - oldDeploy.oldDeployBulk(publicRemoteCollectionID, collection, publicRemoteCollectionID) + // oldDeploy.oldDeployBulk(publicRemoteCollectionID, collection, publicRemoteCollectionID) + await deployBulk.deployColectionHead(privateRemoteCollectionId, collection) + await deployBulk.deployColectionFull(privateRemoteCollectionId, collection, publicRemoteCollectionId) } const releaseAll = async () => {