Skip to content

Commit 0812d54

Browse files
committed
Merge branch 'dev' of github.com:contentstack/migration-v2-node-server into feature/dropdown-field-choices
2 parents 25a2f80 + 83db088 commit 0812d54

File tree

13 files changed

+307
-85
lines changed

13 files changed

+307
-85
lines changed

fileUpdate.js

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const { cliux, messageHandler } = require('@contentstack/cli-utilities');
4+
const isEmpty = (value) => value === null || value === undefined ||
5+
(typeof value === 'object' && Object.keys(value).length === 0) ||
6+
(typeof value === 'string' && value.trim().length === 0);
7+
const config = {
8+
plan: {
9+
dropdown: { optionLimit: 100 }
10+
},
11+
cmsType: null,
12+
isLocalPath: true,
13+
awsData: {
14+
awsRegion: 'us-east-2',
15+
awsAccessKeyId: '',
16+
awsSecretAccessKey: '',
17+
awsSessionToken: '',
18+
bucketName: '',
19+
bucketKey: ''
20+
},
21+
localPath: null
22+
};
23+
24+
const configFilePath = path.resolve(path?.join?.('upload-api', 'src', 'config', 'index.ts'));
25+
26+
const ensureDirectoryExists = (filePath) => {
27+
const dir = path.dirname(filePath);
28+
if (!fs.existsSync(dir)) {
29+
fs.mkdirSync(dir, { recursive: true });
30+
console.log('📂 Created missing directory:', dir);
31+
}
32+
};
33+
34+
const inquireRequireFieldValidation = (input) => {
35+
if (isEmpty(input)) {
36+
return messageHandler.parse('Please enter the path');
37+
}
38+
if (!fs.existsSync(input)) {
39+
return messageHandler.parse('The specified path does not exist. Please enter a valid path.');
40+
}
41+
return true;
42+
};
43+
44+
const typeSwitcher = async (type) => {
45+
switch (type) {
46+
case 'Aws S3': {
47+
const awsData = {
48+
awsRegion: await cliux.inquire({
49+
type: 'input',
50+
message: 'Enter AWS Region',
51+
name: 'awsRegion',
52+
validate: inquireRequireFieldValidation
53+
}),
54+
awsAccessKeyId: await cliux.inquire({
55+
type: 'input',
56+
message: 'Enter AWS Access Key Id',
57+
name: 'awsAccessKeyId',
58+
validate: inquireRequireFieldValidation
59+
}),
60+
awsSecretAccessKey: await cliux.inquire({
61+
type: 'input',
62+
message: 'Enter AWS Secret Access Key',
63+
name: 'awsSecretAccessKey',
64+
validate: inquireRequireFieldValidation
65+
}),
66+
};
67+
const isSessionToken = await cliux.inquire({
68+
choices: ['yes', 'no'],
69+
type: 'list',
70+
name: 'isSessionToken',
71+
message: 'Do you have a Session Token?'
72+
});
73+
if (isSessionToken === 'yes') {
74+
awsData.awsSessionToken = await cliux.inquire({
75+
type: 'input',
76+
message: 'Enter AWS Session Token',
77+
name: 'awsSessionToken',
78+
validate: inquireRequireFieldValidation
79+
});
80+
}
81+
return awsData;
82+
}
83+
case 'Locale Path': {
84+
return await cliux.inquire({
85+
type: 'input',
86+
message: 'Enter file path',
87+
name: 'filePath',
88+
validate: inquireRequireFieldValidation
89+
});
90+
}
91+
default:
92+
console.log('⚠️ Invalid type provided');
93+
return;
94+
}
95+
};
96+
97+
const XMLMigration = async () => {
98+
const typeOfcms = await cliux.inquire({
99+
choices: ['sitecore', 'contentful'],
100+
type: 'list',
101+
name: 'value',
102+
message: 'Choose the option to proceed with your legacy CMS:'
103+
});
104+
105+
const data = await typeSwitcher('Locale Path');
106+
if (typeof typeOfcms === 'string') {
107+
config.cmsType = typeOfcms;
108+
} else {
109+
console.log('⚠️ Error: Expected a string for typeOfcms but got an object.');
110+
}
111+
if (typeof data === 'string') {
112+
config.localPath = data;
113+
} else {
114+
console.log('⚠️ Error: Expected a string for localPath but got an object.');
115+
}
116+
ensureDirectoryExists(configFilePath);
117+
fs.writeFileSync(configFilePath, `export default ${JSON.stringify(config, null, 2)};`, 'utf8');
118+
};
119+
120+
XMLMigration();

package.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
"api": "cd ./api && npm run dev",
1010
"upload": "cd ./upload-api && npm start",
1111
"ui": "cd ./ui && npm start",
12-
"start": "node index.js"
12+
"setup:file": "npm i && node fileUpdate.js",
13+
"create:env": "node index.js",
14+
"setup:mac": "bash setup.sh"
1315
},
1416
"repository": {
1517
"type": "git",
@@ -36,5 +38,8 @@
3638
"validate-branch-name": {
3739
"pattern": "^(feature|bugfix|hotfix)/[a-z0-9-]{5,30}$",
3840
"errorMsg": "Please add valid branch name!"
41+
},
42+
"dependencies": {
43+
"@contentstack/cli-utilities": "^1.8.4"
3944
}
40-
}
45+
}

setup.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/bash
2+
3+
# Get the script's directory (ensures correct paths)
4+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
5+
cd "$SCRIPT_DIR" || exit 1
6+
7+
# Install NVM if not installed
8+
if ! command -v nvm &> /dev/null; then
9+
echo "Installing NVM..."
10+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.4/install.sh | bash
11+
12+
export NVM_DIR="$HOME/.nvm"
13+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
14+
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
15+
else
16+
export NVM_DIR="$HOME/.nvm"
17+
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
18+
fi
19+
20+
# Ensure Node.js 21 is installed and used
21+
NODE_VERSION=$(node -v 2>/dev/null)
22+
if [[ "$NODE_VERSION" != v21.* ]]; then
23+
echo "Installing and using Node.js 21..."
24+
nvm install 21
25+
fi
26+
nvm use 21
27+
28+
Setup CLI
29+
echo "Setting up CLI repo..."
30+
cd "$SCRIPT_DIR/cli" || exit 1
31+
32+
# Check if current user can write to node_modules
33+
if [ -w node_modules ] || [ ! -d node_modules ]; then
34+
npm run setup-repo --force
35+
else
36+
echo "Permission issue detected. Trying with sudo..."
37+
sudo npm run setup-repo --force
38+
fi
39+
40+
# Return to script root
41+
cd "$SCRIPT_DIR" || exit 1
42+
43+
# Fix npm cache permissions
44+
echo "Fixing npm cache permissions..."
45+
sudo chown -R $(id -u):$(id -g) "$HOME/.npm"
46+
47+
# Start With Env File
48+
echo "Creating .env file..."
49+
npm run create:env
50+
51+
echo "Updating config file..."
52+
npm run setup:file
53+
54+
# Start services in new terminals
55+
echo "Starting services in new terminals..."
56+
57+
if [[ "$OSTYPE" == "darwin"* ]]; then
58+
# macOS
59+
osascript -e "tell application \"Terminal\" to do script \"
60+
source \$HOME/.nvm/nvm.sh && nvm use 21 &&
61+
cd '$SCRIPT_DIR/api' &&
62+
echo 'Cleaning API dependencies...' &&
63+
rm -rf node_modules package-lock.json &&
64+
npm install &&
65+
npm run dev
66+
\""
67+
osascript -e "tell application \"Terminal\" to do script \"
68+
source \$HOME/.nvm/nvm.sh && nvm use 21 &&
69+
cd '$SCRIPT_DIR/upload-api' &&
70+
echo 'Cleaning upload-api dependencies...' &&
71+
rm -rf node_modules package-lock.json &&
72+
rm -rf migration-sitecore/node_modules migration-sitecore/package-lock.json &&
73+
npm install &&
74+
npm run start
75+
\""
76+
osascript -e "tell application \"Terminal\" to do script \"
77+
source \$HOME/.nvm/nvm.sh && nvm use 21 &&
78+
cd '$SCRIPT_DIR/ui' &&
79+
echo 'Cleaning UI dependencies...' &&
80+
rm -rf node_modules package-lock.json &&
81+
npm install &&
82+
npm run start
83+
\""
84+
85+
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
86+
# Linux (GNOME Terminal)
87+
gnome-terminal -- bash -c "source $HOME/.nvm/nvm.sh && nvm use 21 && cd '$SCRIPT_DIR/api' && npm install && npm run dev; exec bash"
88+
gnome-terminal -- bash -c "source $HOME/.nvm/nvm.sh && nvm use 21 && cd '$SCRIPT_DIR/upload-api' && npm install && npm run start; exec bash"
89+
gnome-terminal -- bash -c "source $HOME/.nvm/nvm.sh && nvm use 21 && cd '$SCRIPT_DIR/ui' && npm install && npm run start; exec bash"
90+
else
91+
echo "Unsupported OS: $OSTYPE"
92+
exit 1
93+
fi
94+
95+
echo "All services started!"

ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@types/react": "^18.2.28",
1313
"@types/react-dom": "^18.2.13",
1414
"@types/react-redux": "^7.1.33",
15-
"axios": "^1.8.2",
15+
"axios": "^1.8.3",
1616
"bootstrap": "5.1.3",
1717
"chokidar": "^3.6.0",
1818
"final-form": "^4.20.10",

ui/src/components/DestinationStack/Actions/LoadLanguageMapper.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ const LanguageMapper = () => {
522522
type="Secondary"
523523
/>
524524
<Button
525-
className="ml-10 mt-10 mb-10"
525+
className="mt-10"
526526
buttonType="secondary"
527527
aria-label="add language"
528528
version={'v2'}

ui/src/components/DestinationStack/Actions/LoadStacks.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { RootState } from '../../../store';
1515
import { updateNewMigrationData } from '../../../store/slice/migrationDataSlice';
1616

1717
// Interface
18-
import { DEFAULT_DROPDOWN, IDropDown, INewMigration } from '../../../context/app/app.interface';
18+
import { IDropDown, INewMigration } from '../../../context/app/app.interface';
1919
import { StackResponse } from '../../../services/api/service.interface';
2020
import { Stack } from '../../../components/Common/AddStack/addStack.interface';
2121

ui/src/components/DestinationStack/Actions/tableHeader.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,19 @@ const TableHeader = ({ cms }: { cms: string }) => {
99
htmlFor="Content Types"
1010
className="contentTypeRows__label field-color field-label"
1111
version="v2"
12-
requiredText="(destination language)"
12+
requiredText="(destination)"
1313
>
1414
Contentstack
1515
</FieldLabel>
1616

17-
<div style={{ marginLeft: '15px' }}>
1817
<FieldLabel
1918
htmlFor="Fields"
20-
className="contentTypeRows__label field-color field-label"
21-
requiredText="(source language)"
19+
className="contentTypeRows__label field-color field-label ml-20"
20+
requiredText="(source)"
2221
version="v2"
2322
>
2423
{cms}
2524
</FieldLabel>
26-
</div>
2725
</div>
2826
);
2927
};

ui/src/components/DestinationStack/DestinationStack.scss

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,10 @@
4545
border-radius: 4px;
4646
}
4747
.destination-stack-container {
48-
padding-left: 25px !important;
49-
padding-top: 26px;
50-
padding-right: 30px;
51-
48+
height: 100%;
5249
overflow-y: auto;
5350
overflow-x: hidden;
54-
max-height: 65vh;
51+
padding: 25px;
5552
.migration-vertical-stepper {
5653
padding: 24px 30px;
5754
border: 1px solid $color-brand-secondary-lightest;
@@ -207,6 +204,7 @@
207204
//padding-bottom: 50px;
208205
}
209206
.language-mapper {
207+
border-top: 1px solid $color-brand-secondary-lightest;
210208
margin-top: 16px;
211209

212210
.table-content-section {
@@ -220,6 +218,7 @@
220218
}
221219
.field-content__content {
222220
height: auto !important;
221+
margin-left: 0;
223222
max-height: unset !important;
224223
overflow: visible !important;
225224
z-index: 9999;
@@ -229,7 +228,8 @@
229228
padding: 10px 20px;
230229
}
231230
.field-label {
232-
padding: 10px 0;
231+
padding: 15px 0 0;
232+
width: 290px;
233233
}
234234
}
235235

@@ -253,9 +253,9 @@
253253
//width: 120px;
254254
}
255255
.lang-container {
256-
margin-bottom: 30px;
257-
margin-left: 10px;
258-
margin-top: 10px;
256+
// margin-bottom: 30px;
257+
// margin-left: 10px;
258+
// margin-top: 10px;
259259
display: flex;
260260
}
261261
.info-tag {

ui/src/context/app/app.interface.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export interface FileDetails {
5656
bucketName?: string;
5757
buketKey?: string;
5858
};
59+
filePath?: string | undefined;
5960
}
6061
export interface IFile {
6162
id?: string;

0 commit comments

Comments
 (0)