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 () => {