From 3b3ee523b65a69c69aa2091cd6da4ba4568ec15f Mon Sep 17 00:00:00 2001 From: umeshmore45 Date: Thu, 27 Mar 2025 18:09:02 +0530 Subject: [PATCH 1/5] setup added --- setup.sh | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 setup.sh diff --git a/setup.sh b/setup.sh new file mode 100644 index 000000000..6aa7b008e --- /dev/null +++ b/setup.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Get the script's directory (ensures correct paths) +SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" +cd "$SCRIPT_DIR" + +# Install NVM +echo "Installing NVM..." +curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash + +# Load NVM +export NVM_DIR="$HOME/.nvm" +[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + +# Install and use Node.js 21 +echo "Installing and using Node.js 21..." +nvm install 21 +nvm use 21 + +Setup CLI first +echo "Setting up CLI repo..." +cd "$SCRIPT_DIR/cli" && npm run setup-repo +cd "$SCRIPT_DIR" + +# Open new terminals for other services +echo "Starting services in new terminals..." + +# macOS (Using AppleScript) +if [[ "$OSTYPE" == "darwin"* ]]; then + osascript -e "tell application \"Terminal\" to do script \"cd '$SCRIPT_DIR/api' && npm i && npm run dev\"" + osascript -e "tell application \"Terminal\" to do script \"cd '$SCRIPT_DIR/upload-api' && npm i && npm run start\"" + osascript -e "tell application \"Terminal\" to do script \"cd '$SCRIPT_DIR/ui' && npm i && npm run start\"" + +# Linux (Using GNOME Terminal) +elif [[ "$OSTYPE" == "linux-gnu"* ]]; then + gnome-terminal -- bash -c "cd '$SCRIPT_DIR/api' && npm run dev; exec bash" + gnome-terminal -- bash -c "cd '$SCRIPT_DIR/upload-api' && npm run start; exec bash" + gnome-terminal -- bash -c "cd '$SCRIPT_DIR/ui' && npm run start; exec bash" +fi + +echo "All services started!" From 92304bfb729235613dd7407caa88aac830f21d40 Mon Sep 17 00:00:00 2001 From: umeshmore45 Date: Thu, 27 Mar 2025 18:21:10 +0530 Subject: [PATCH 2/5] setup added --- package.json | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 305fec691..6e335a957 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "api": "cd ./api && npm run dev", "upload": "cd ./upload-api && npm start", "ui": "cd ./ui && npm start", - "start": "node index.js" + "start": "node index.js", + "setup:mac": "bash setup.sh" }, "repository": { "type": "git", @@ -37,4 +38,4 @@ "pattern": "^(feature|bugfix|hotfix)/[a-z0-9-]{5,30}$", "errorMsg": "Please add valid branch name!" } -} +} \ No newline at end of file From 07f4f969cde54d09268c508cac5f9deff478d474 Mon Sep 17 00:00:00 2001 From: umeshmore45 Date: Fri, 28 Mar 2025 02:43:46 +0530 Subject: [PATCH 3/5] resloved the issue --- package.json | 2 +- setup.sh | 99 +++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 76 insertions(+), 25 deletions(-) mode change 100644 => 100755 setup.sh diff --git a/package.json b/package.json index 6e335a957..23d60e2cf 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "api": "cd ./api && npm run dev", "upload": "cd ./upload-api && npm start", "ui": "cd ./ui && npm start", - "start": "node index.js", + "create:env": "node index.js", "setup:mac": "bash setup.sh" }, "repository": { diff --git a/setup.sh b/setup.sh old mode 100644 new mode 100755 index 6aa7b008e..aa554185d --- a/setup.sh +++ b/setup.sh @@ -2,40 +2,91 @@ # Get the script's directory (ensures correct paths) SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" -cd "$SCRIPT_DIR" +cd "$SCRIPT_DIR" || exit 1 -# Install NVM -echo "Installing NVM..." -curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash +# Install NVM if not installed +if ! command -v nvm &> /dev/null; then + echo "Installing NVM..." + curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash -# Load NVM -export NVM_DIR="$HOME/.nvm" -[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" + [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" +else + export NVM_DIR="$HOME/.nvm" + [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" +fi -# Install and use Node.js 21 -echo "Installing and using Node.js 21..." -nvm install 21 +# Ensure Node.js 21 is installed and used +NODE_VERSION=$(node -v 2>/dev/null) +if [[ "$NODE_VERSION" != v21.* ]]; then + echo "Installing and using Node.js 21..." + nvm install 21 +fi nvm use 21 -Setup CLI first +Setup CLI echo "Setting up CLI repo..." -cd "$SCRIPT_DIR/cli" && npm run setup-repo -cd "$SCRIPT_DIR" +cd "$SCRIPT_DIR/cli" || exit 1 + +# Check if current user can write to node_modules +if [ -w node_modules ] || [ ! -d node_modules ]; then + npm run setup-repo --force +else + echo "Permission issue detected. Trying with sudo..." + sudo npm run setup-repo --force +fi -# Open new terminals for other services +# Return to script root +cd "$SCRIPT_DIR" || exit 1 + +# Fix npm cache permissions +echo "Fixing npm cache permissions..." +sudo chown -R $(id -u):$(id -g) "$HOME/.npm" + +# Start With Env File +echo "Creating .env file..." +npm run create:env + +# Start services in new terminals echo "Starting services in new terminals..." -# macOS (Using AppleScript) if [[ "$OSTYPE" == "darwin"* ]]; then - osascript -e "tell application \"Terminal\" to do script \"cd '$SCRIPT_DIR/api' && npm i && npm run dev\"" - osascript -e "tell application \"Terminal\" to do script \"cd '$SCRIPT_DIR/upload-api' && npm i && npm run start\"" - osascript -e "tell application \"Terminal\" to do script \"cd '$SCRIPT_DIR/ui' && npm i && npm run start\"" - -# Linux (Using GNOME Terminal) + # macOS + osascript -e "tell application \"Terminal\" to do script \" + source \$HOME/.nvm/nvm.sh && nvm use 21 && + cd '$SCRIPT_DIR/api' && + echo 'Cleaning API dependencies...' && + rm -rf node_modules package-lock.json && + npm install && + npm run dev + \"" + osascript -e "tell application \"Terminal\" to do script \" + source \$HOME/.nvm/nvm.sh && nvm use 21 && + cd '$SCRIPT_DIR/upload-api' && + echo 'Cleaning upload-api dependencies...' && + rm -rf node_modules package-lock.json && + rm -rf migration-sitecore/node_modules migration-sitecore/package-lock.json && + npm install && + npm run start + \"" + osascript -e "tell application \"Terminal\" to do script \" + source \$HOME/.nvm/nvm.sh && nvm use 21 && + cd '$SCRIPT_DIR/ui' && + echo 'Cleaning UI dependencies...' && + rm -rf node_modules package-lock.json && + npm install && + npm run start + \"" + elif [[ "$OSTYPE" == "linux-gnu"* ]]; then - gnome-terminal -- bash -c "cd '$SCRIPT_DIR/api' && npm run dev; exec bash" - gnome-terminal -- bash -c "cd '$SCRIPT_DIR/upload-api' && npm run start; exec bash" - gnome-terminal -- bash -c "cd '$SCRIPT_DIR/ui' && npm run start; exec bash" + # Linux (GNOME Terminal) + gnome-terminal -- bash -c "source $HOME/.nvm/nvm.sh && nvm use 21 && cd '$SCRIPT_DIR/api' && npm install && npm run dev; exec bash" + gnome-terminal -- bash -c "source $HOME/.nvm/nvm.sh && nvm use 21 && cd '$SCRIPT_DIR/upload-api' && npm install && npm run start; exec bash" + gnome-terminal -- bash -c "source $HOME/.nvm/nvm.sh && nvm use 21 && cd '$SCRIPT_DIR/ui' && npm install && npm run start; exec bash" +else + echo "Unsupported OS: $OSTYPE" + exit 1 fi -echo "All services started!" +echo "All services started!" \ No newline at end of file From caad4ff2338efaca7af278534ae76687f35b631c Mon Sep 17 00:00:00 2001 From: umeshmore45 Date: Tue, 1 Apr 2025 01:57:59 +0530 Subject: [PATCH 4/5] added file uploade --- fileUpdate.js | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 4 ++ setup.sh | 3 ++ 3 files changed, 127 insertions(+) create mode 100644 fileUpdate.js diff --git a/fileUpdate.js b/fileUpdate.js new file mode 100644 index 000000000..c665e356a --- /dev/null +++ b/fileUpdate.js @@ -0,0 +1,120 @@ +const fs = require('fs'); +const path = require('path'); +const { cliux, messageHandler } = require('@contentstack/cli-utilities'); +const isEmpty = (value) => value === null || value === undefined || + (typeof value === 'object' && Object.keys(value).length === 0) || + (typeof value === 'string' && value.trim().length === 0);; +const config = { + plan: { + dropdown: { optionLimit: 100 } + }, + cmsType: null, + isLocalPath: true, + awsData: { + awsRegion: 'us-east-2', + awsAccessKeyId: '', + awsSecretAccessKey: '', + awsSessionToken: '', + bucketName: 'migartion-test', + buketKey: 'project/package 45.zip' + }, + localPath: null +}; + +const configFilePath = path.resolve(path?.join?.('upload-api', 'src', 'config', 'index.ts')); + +const ensureDirectoryExists = (filePath) => { + const dir = path.dirname(filePath); + if (!fs.existsSync(dir)) { + fs.mkdirSync(dir, { recursive: true }); + console.log('📂 Created missing directory:', dir); + } +}; + +const inquireRequireFieldValidation = (input) => { + if (isEmpty(input)) { + return messageHandler.parse('Please enter the path'); + } + if (!fs.existsSync(input)) { + return messageHandler.parse('The specified path does not exist. Please enter a valid path.'); + } + return true; +}; + +const typeSwitcher = async (type) => { + switch (type) { + case 'Aws S3': { + const awsData = { + awsRegion: await cliux.inquire({ + type: 'input', + message: 'Enter AWS Region', + name: 'awsRegion', + validate: inquireRequireFieldValidation + }), + awsAccessKeyId: await cliux.inquire({ + type: 'input', + message: 'Enter AWS Access Key Id', + name: 'awsAccessKeyId', + validate: inquireRequireFieldValidation + }), + awsSecretAccessKey: await cliux.inquire({ + type: 'input', + message: 'Enter AWS Secret Access Key', + name: 'awsSecretAccessKey', + validate: inquireRequireFieldValidation + }), + }; + const isSessionToken = await cliux.inquire({ + choices: ['yes', 'no'], + type: 'list', + name: 'isSessionToken', + message: 'Do you have a Session Token?' + }); + if (isSessionToken === 'yes') { + awsData.awsSessionToken = await cliux.inquire({ + type: 'input', + message: 'Enter AWS Session Token', + name: 'awsSessionToken', + validate: inquireRequireFieldValidation + }); + } + return awsData; + } + case 'Locale Path': { + return await cliux.inquire({ + type: 'input', + message: 'Enter file path', + name: 'filePath', + validate: inquireRequireFieldValidation + }); + } + default: + console.log('⚠️ Invalid type provided'); + return; + } +}; + +const XMLMigration = async () => { + const typeOfcms = await cliux.inquire({ + choices: ['sitecore', 'contentful'], + type: 'list', + name: 'value', + message: 'Choose the option to proceed' + }); + + const data = await typeSwitcher('Locale Path'); + if (typeof typeOfcms === 'string') { + config.cmsType = typeOfcms; + } else { + console.log('⚠️ Error: Expected a string for typeOfcms but got an object.'); + } + if (typeof data === 'string') { + config.localPath = data; + } else { + console.log('⚠️ Error: Expected a string for localPath but got an object.'); + } + ensureDirectoryExists(configFilePath); + fs.writeFileSync(configFilePath, `export default ${JSON.stringify(config, null, 2)};`, 'utf8'); +}; + +XMLMigration(); diff --git a/package.json b/package.json index 23d60e2cf..f58d5feaa 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "api": "cd ./api && npm run dev", "upload": "cd ./upload-api && npm start", "ui": "cd ./ui && npm start", + "setup:file": "npm i && node fileUpdate.js", "create:env": "node index.js", "setup:mac": "bash setup.sh" }, @@ -37,5 +38,8 @@ "validate-branch-name": { "pattern": "^(feature|bugfix|hotfix)/[a-z0-9-]{5,30}$", "errorMsg": "Please add valid branch name!" + }, + "dependencies": { + "@contentstack/cli-utilities": "^1.8.4" } } \ No newline at end of file diff --git a/setup.sh b/setup.sh index aa554185d..fb877e1b3 100755 --- a/setup.sh +++ b/setup.sh @@ -48,6 +48,9 @@ sudo chown -R $(id -u):$(id -g) "$HOME/.npm" echo "Creating .env file..." npm run create:env +echo "Updating config file..." +npm run setup:file + # Start services in new terminals echo "Starting services in new terminals..." From fe1375f0481c8e54712531a605c90bd4f408b27e Mon Sep 17 00:00:00 2001 From: umeshmore45 Date: Tue, 1 Apr 2025 02:12:07 +0530 Subject: [PATCH 5/5] added file uploade --- fileUpdate.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fileUpdate.js b/fileUpdate.js index c665e356a..8753a34a7 100644 --- a/fileUpdate.js +++ b/fileUpdate.js @@ -99,7 +99,7 @@ const XMLMigration = async () => { choices: ['sitecore', 'contentful'], type: 'list', name: 'value', - message: 'Choose the option to proceed' + message: 'Choose the option to proceed with your legacy CMS:' }); const data = await typeSwitcher('Locale Path');