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
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ services:
- CONTAINER_PATH=${CONTAINER_PATH}
- CMS_DATA_PATH=${CMS_DATA_PATH}
- AEM_TEMPLATES_DIR=${AEM_TEMPLATES_DIR:-templates}
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- migration-network
security_opt:
Expand All @@ -39,6 +41,16 @@ services:
- CMS_DATA_PATH=${CMS_DATA_PATH}
- NODE_BACKEND_API=${NODE_BACKEND_API:-http://migration-api:5001}
- AEM_TEMPLATES_DIR=${AEM_TEMPLATES_DIR:-templates}
- CMS_LOCAL_PATH=${CMS_LOCAL_PATH:-}
- MYSQL_HOST=${MYSQL_HOST:-}
- MYSQL_USER=${MYSQL_USER:-}
- MYSQL_PASSWORD=${MYSQL_PASSWORD:-}
- MYSQL_DATABASE=${MYSQL_DATABASE:-}
- MYSQL_PORT=${MYSQL_PORT:-3306}
- DRUPAL_ASSETS_BASE_URL=${DRUPAL_ASSETS_BASE_URL:-}
- DRUPAL_ASSETS_PUBLIC_PATH=${DRUPAL_ASSETS_PUBLIC_PATH:-}
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- migration-network
security_opt:
Expand Down
173 changes: 93 additions & 80 deletions fileUpdate.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
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: '',
bucketKey: ''
},
localPath: null
};

const configFilePath = path.resolve(path?.join?.('upload-api', 'src', 'config', 'index.ts'));
const envFilePath = path.resolve(path.join('upload-api', '.env'));

const ensureDirectoryExists = (filePath) => {
const dir = path.dirname(filePath);
Expand All @@ -31,6 +16,31 @@ const ensureDirectoryExists = (filePath) => {
}
};

const readEnvFile = () => {
const vars = {};
if (fs.existsSync(envFilePath)) {
const content = fs.readFileSync(envFilePath, 'utf8');
for (const line of content.split('\n')) {
const trimmed = line.trim();
if (trimmed && !trimmed.startsWith('#')) {
const eqIndex = trimmed.indexOf('=');
if (eqIndex > 0) {
vars[trimmed.substring(0, eqIndex)] = trimmed.substring(eqIndex + 1);
}
}
}
}
return vars;
};

const writeEnvFile = (newVars) => {
ensureDirectoryExists(envFilePath);
const existing = readEnvFile();
const merged = { ...existing, ...newVars };
const lines = Object.entries(merged).map(([k, v]) => `${k}=${v}`);
fs.writeFileSync(envFilePath, lines.join('\n') + '\n', 'utf8');
};

const inquireRequireFieldValidation = (input) => {
if (isEmpty(input)) {
return messageHandler.parse('Please enter the path');
Expand All @@ -41,80 +51,83 @@ const inquireRequireFieldValidation = (input) => {
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', 'wordpress', 'aem'],
choices: ['sitecore', 'contentful', 'wordpress', 'aem', 'drupal'],
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 {
if (typeof typeOfcms !== 'string') {
console.log('⚠️ Error: Expected a string for typeOfcms but got an object.');
return;
}
if (typeof data === 'string') {
config.localPath = data;

const envVars = { CMS_TYPE: typeOfcms };

if (typeOfcms === 'drupal') {
console.log('\nDrupal uses a MySQL database connection. Please provide your database details:');

envVars.MYSQL_HOST = await cliux.inquire({
type: 'input',
message: 'Enter MySQL Host',
name: 'mysqlHost',
validate: (input) => isEmpty(input) ? 'Please enter the MySQL host' : true
});
envVars.MYSQL_USER = await cliux.inquire({
type: 'input',
message: 'Enter MySQL User',
name: 'mysqlUser',
validate: (input) => isEmpty(input) ? 'Please enter the MySQL user' : true
});
envVars.MYSQL_PASSWORD = await cliux.inquire({
type: 'password',
message: 'Enter MySQL Password (can be empty)',
name: 'mysqlPassword'
});
envVars.MYSQL_DATABASE = await cliux.inquire({
type: 'input',
message: 'Enter MySQL Database Name',
name: 'mysqlDatabase',
validate: (input) => isEmpty(input) ? 'Please enter the MySQL database name' : true
});
const portInput = await cliux.inquire({
type: 'input',
message: 'Enter MySQL Port [3306]',
name: 'mysqlPort'
});
envVars.MYSQL_PORT = portInput || '3306';

envVars.DRUPAL_ASSETS_BASE_URL = await cliux.inquire({
type: 'input',
message: 'Enter Drupal Assets Base URL (e.g. https://example.com)',
name: 'assetsBaseUrl'
});
envVars.DRUPAL_ASSETS_PUBLIC_PATH = await cliux.inquire({
type: 'input',
message: 'Enter Drupal Assets Public Path (e.g. sites/default/files)',
name: 'assetsPublicPath'
});

envVars.CMS_LOCAL_PATH = 'sql';
} else {
console.log('⚠️ Error: Expected a string for localPath but got an object.');
const localPath = await cliux.inquire({
type: 'input',
message: 'Enter file path',
name: 'filePath',
validate: inquireRequireFieldValidation
});
if (typeof localPath === 'string') {
envVars.CMS_LOCAL_PATH = localPath;
} else {
console.log('⚠️ Error: Expected a string for localPath but got an object.');
return;
}
}
ensureDirectoryExists(configFilePath);
fs.writeFileSync(configFilePath, `export default ${JSON.stringify(config, null, 2)};`, 'utf8');

writeEnvFile(envVars);
console.log(`✅ Configuration written to ${envFilePath}`);
};

XMLMigration();
Loading
Loading