Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 120 additions & 0 deletions fileUpdate.js
Original file line number Diff line number Diff line change
@@ -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 with your legacy CMS:'
});

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();
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
"api": "cd ./api && npm run dev",
"upload": "cd ./upload-api && npm start",
"ui": "cd ./ui && npm start",
"start": "node index.js"
"setup:file": "npm i && node fileUpdate.js",
"create:env": "node index.js",
"setup:mac": "bash setup.sh"
},
"repository": {
"type": "git",
Expand All @@ -36,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"
}
}
}
95 changes: 95 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#!/bin/bash

# Get the script's directory (ensures correct paths)
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$SCRIPT_DIR" || exit 1

# 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

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

# 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
echo "Setting up CLI repo..."
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

# 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

echo "Updating config file..."
npm run setup:file

# Start services in new terminals
echo "Starting services in new terminals..."

if [[ "$OSTYPE" == "darwin"* ]]; then
# 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
# 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!"