Skip to content

Commit 6dc43cd

Browse files
authored
update
1 parent 3692d0c commit 6dc43cd

File tree

192 files changed

+3742
-3421
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

192 files changed

+3742
-3421
lines changed

build/frontend_renaming/config.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# config.yaml
2+
old_name: z2ui5
3+
new_name: zzzz2ui5
4+
source_paths:
5+
- ../../dist/src/05/01
6+
- ../../dist/src/05/02
7+
- ../../dist/src/05/03
8+
destination_path: ../../dist/src
9+
exclude_patterns:
10+
- wapa
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const yaml = require('js-yaml');
4+
5+
// Absolute path to the configuration file
6+
const configPath = path.join(__dirname, 'config.yaml');
7+
8+
// Read the configuration file
9+
const config = yaml.load(fs.readFileSync(configPath, 'utf8'));
10+
11+
// Function to recursively delete a directory
12+
function deleteFolderRecursive(folderPath) {
13+
if (fs.existsSync(folderPath)) {
14+
fs.readdirSync(folderPath).forEach(file => {
15+
const curPath = path.join(folderPath, file);
16+
if (fs.lstatSync(curPath).isDirectory()) {
17+
deleteFolderRecursive(curPath);
18+
} else {
19+
fs.unlinkSync(curPath);
20+
}
21+
});
22+
fs.rmdirSync(folderPath);
23+
}
24+
}
25+
26+
// Function to copy, rename, and replace content in files
27+
function copyAndRenameFiles(src, dest, callback) {
28+
// Check if the destination directory exists, otherwise create it
29+
if (!fs.existsSync(dest)) {
30+
fs.mkdirSync(dest, { recursive: true });
31+
}
32+
33+
// Read all files and directories in the source directory
34+
fs.readdir(src, (err, items) => {
35+
if (err) {
36+
console.error('Error reading directory:', err);
37+
return;
38+
}
39+
40+
let pending = items.length;
41+
if (!pending) return callback();
42+
43+
items.forEach(item => {
44+
const srcPath = path.join(src, item);
45+
const destPath = path.join(dest, item.replace(config.old_name, config.new_name));
46+
47+
// Check if the file should be excluded
48+
const shouldExclude = config.exclude_patterns.some(pattern => item.includes(pattern)) && !item.endsWith('wapa.xml');
49+
50+
// Check if it is a directory
51+
fs.stat(srcPath, (err, stats) => {
52+
if (err) {
53+
console.error('Error getting file information:', err);
54+
return;
55+
}
56+
57+
if (stats.isDirectory()) {
58+
// Recursively call for subdirectories
59+
copyAndRenameFiles(srcPath, destPath, () => {
60+
if (!--pending) callback();
61+
});
62+
} else {
63+
// Copy and rename file
64+
fs.copyFile(srcPath, destPath, err => {
65+
if (err) {
66+
console.error('Error copying file:', err);
67+
return;
68+
}
69+
70+
if (!shouldExclude || item.endsWith('wapa.xml')) {
71+
// Replace content (both lowercase and uppercase)
72+
fs.readFile(destPath, 'utf8', (err, data) => {
73+
if (err) {
74+
console.error('Error reading file:', err);
75+
return;
76+
}
77+
78+
const result = data
79+
.replace(new RegExp(config.old_name, 'g'), config.new_name)
80+
.replace(new RegExp(config.old_name.toUpperCase(), 'g'), config.new_name.toUpperCase());
81+
82+
// Save file in the destination directory
83+
fs.writeFile(destPath, result, 'utf8', err => {
84+
if (err) {
85+
console.error('Error writing file:', err);
86+
} else {
87+
console.log(`File copied and content replaced: ${srcPath} -> ${destPath}`);
88+
}
89+
if (!--pending) callback();
90+
});
91+
});
92+
} else {
93+
console.log(`File copied without replacing content: ${srcPath} -> ${destPath}`);
94+
if (!--pending) callback();
95+
}
96+
});
97+
}
98+
});
99+
});
100+
});
101+
}
102+
103+
// Function to replace the content of all files ending with manifest.json in the 02 folder
104+
function updateManifestJsonFiles(dest) {
105+
const targetDir = path.join(dest, '02');
106+
if (fs.existsSync(targetDir)) {
107+
fs.readdirSync(targetDir).forEach(file => {
108+
const curPath = path.join(targetDir, file);
109+
if (fs.lstatSync(curPath).isDirectory()) {
110+
updateManifestJsonFiles(curPath);
111+
} else if (file.endsWith('manifest.json')) {
112+
fs.readFile(curPath, 'utf8', (err, data) => {
113+
if (err) {
114+
console.error('Error reading manifest.json:', err);
115+
return;
116+
}
117+
118+
const result = data.replace(new RegExp(`"uri": "/sap/bc/${config.old_name}"`, 'g'), `"uri": "/sap/bc/${config.new_name}"`);
119+
120+
fs.writeFile(curPath, result, 'utf8', err => {
121+
if (err) {
122+
console.error('Error writing manifest.json:', err);
123+
} else {
124+
console.log(`manifest.json updated: ${curPath}`);
125+
}
126+
});
127+
});
128+
}
129+
});
130+
}
131+
}
132+
133+
// Clear the destination directory before copying
134+
const destDir = path.resolve(__dirname, config.destination_path);
135+
deleteFolderRecursive(destDir);
136+
fs.mkdirSync(destDir, { recursive: true });
137+
138+
// Execute the script for all specified source directories
139+
let pending = config.source_paths.length;
140+
config.source_paths.forEach(srcPath => {
141+
const srcDir = path.resolve(__dirname, srcPath);
142+
const destSubDir = path.join(destDir, path.basename(srcPath));
143+
copyAndRenameFiles(srcDir, destSubDir, () => {
144+
if (!--pending) {
145+
// Update all files ending with manifest.json in the 02 folder
146+
updateManifestJsonFiles(destDir);
147+
}
148+
});
149+
});
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const crypto = require('crypto');
4+
5+
const srcDirs = ['../../dist/src/05/01', '../../dist/src/05/02'];
6+
7+
// Function to generate a random hash
8+
function generateRandomHash() {
9+
return crypto.randomBytes(16).toString('hex');
10+
}
11+
12+
// Function to copy, rename, and delete the original file
13+
function copyRenameAndDeleteFile(srcDir, file) {
14+
const srcPath = path.join(srcDir, file);
15+
let newFileName;
16+
17+
if (file.includes('.smim')) {
18+
newFileName = generateRandomHash() + '.smim.xml';
19+
} else if (file.includes('.sicf')) {
20+
const parts = file.split(' ');
21+
const prefix = parts.slice(0, -1).join(' ').trim() + ' ';
22+
const hashLength = 48 - prefix.length - '.sicf.xml'.length;
23+
const hash = generateRandomHash().substring(0, hashLength);
24+
newFileName = prefix + hash + '.sicf.xml';
25+
} else {
26+
console.log(`File does not include '.smim' or '.sicf': ${file}`);
27+
return;
28+
}
29+
30+
const destPath = path.join(srcDir, newFileName);
31+
32+
console.log(`Copying ${file} to ${newFileName}`);
33+
34+
fs.copyFile(srcPath, destPath, err => {
35+
if (err) {
36+
console.error('Error copying file:', err);
37+
} else {
38+
console.log(`Copied and renamed ${file} to ${newFileName}`);
39+
40+
// Delete the original file
41+
fs.unlink(srcPath, err => {
42+
if (err) {
43+
console.error('Error deleting original file:', err);
44+
} else {
45+
console.log(`Deleted original file ${file}`);
46+
}
47+
});
48+
}
49+
});
50+
}
51+
52+
// Function to copy, rename, and delete files in the directory
53+
function copyRenameAndDeleteFiles(srcDir) {
54+
fs.readdir(srcDir, (err, files) => {
55+
if (err) {
56+
console.error('Error reading directory:', err);
57+
return;
58+
}
59+
60+
files.forEach(file => copyRenameAndDeleteFile(srcDir, file));
61+
});
62+
}
63+
64+
// Ensure the source directories exist and process files
65+
srcDirs.forEach(srcDir => {
66+
fs.access(srcDir, fs.constants.F_OK, err => {
67+
if (err) {
68+
console.error(`Source directory ${srcDir} does not exist:`, err);
69+
return;
70+
}
71+
72+
// Copy, rename, and delete files
73+
copyRenameAndDeleteFiles(srcDir);
74+
});
75+
});
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
const fs = require('fs');
2+
const path = require('path');
3+
const xml2js = require('xml2js');
4+
const yaml = require('js-yaml');
5+
6+
const xmlDirPath = '/workspaces/abap2UI5-renamed/dist/src/05/01/';
7+
const yamlFilePath = '/workspaces/abap2UI5-renamed/build/frontend_renaming/config.yaml';
8+
9+
console.log('Starting the script...');
10+
11+
// Read YAML file
12+
fs.readFile(yamlFilePath, 'utf8', (yamlErr, yamlData) => {
13+
if (yamlErr) {
14+
console.error('Error reading YAML file:', yamlErr);
15+
return;
16+
}
17+
console.log('YAML file read successfully.');
18+
19+
// Parse YAML
20+
let yamlContent;
21+
try {
22+
yamlContent = yaml.load(yamlData);
23+
console.log('YAML file parsed successfully.');
24+
} catch (parseYamlErr) {
25+
console.error('Error parsing YAML file:', parseYamlErr);
26+
return;
27+
}
28+
29+
// Extract dynamic value from YAML file
30+
const newName = yamlContent.new_name;
31+
console.log(`New name extracted from YAML file: ${newName}`);
32+
33+
// Dynamically set the JSON file path
34+
const jsonFilePath = `/workspaces/abap2UI5-renamed/dist/src/05/02/${newName}.wapa.manifest.json`;
35+
console.log(`JSON file path set to: ${jsonFilePath}`);
36+
37+
// Search for XML file in directory
38+
fs.readdir(xmlDirPath, (err, files) => {
39+
if (err) {
40+
console.error('Error reading directory:', err);
41+
return;
42+
}
43+
console.log('Directory read successfully.');
44+
45+
// Find XML file with the desired pattern
46+
const xmlFileName = files.find(file => file.startsWith(newName) && file.endsWith('.sicf.xml'));
47+
if (!xmlFileName) {
48+
console.error('No matching XML file found');
49+
return;
50+
}
51+
console.log(`XML file found: ${xmlFileName}`);
52+
53+
const xmlFilePath = path.join(xmlDirPath, xmlFileName);
54+
55+
// Read XML file
56+
fs.readFile(xmlFilePath, 'utf8', (err, xmlData) => {
57+
if (err) {
58+
console.error('Error reading XML file:', err);
59+
return;
60+
}
61+
console.log('XML file read successfully.');
62+
63+
// Parse XML
64+
xml2js.parseString(xmlData, (parseErr, result) => {
65+
if (parseErr) {
66+
console.error('Error parsing XML file:', parseErr);
67+
return;
68+
}
69+
console.log('XML file parsed successfully.');
70+
71+
// Extract URL from XML file
72+
const newUrl = result.abapGit?.['asx:abap']?.[0]?.['asx:values']?.[0]?.URL?.[0];
73+
if (!newUrl) {
74+
console.error('No URL found in XML file');
75+
return;
76+
}
77+
console.log(`URL extracted from XML file: ${newUrl}`);
78+
79+
// Read JSON file
80+
fs.readFile(jsonFilePath, 'utf8', (jsonErr, jsonData) => {
81+
if (jsonErr) {
82+
console.error('Error reading JSON file:', jsonErr);
83+
return;
84+
}
85+
console.log('JSON file read successfully.');
86+
87+
// Parse JSON
88+
let jsonContent;
89+
try {
90+
jsonContent = JSON.parse(jsonData);
91+
console.log('JSON file parsed successfully.');
92+
} catch (parseJsonErr) {
93+
console.error('Error parsing JSON file:', parseJsonErr);
94+
return;
95+
}
96+
97+
// Log the structure of the JSON file
98+
console.log('JSON file structure:', JSON.stringify(jsonContent, null, 4));
99+
100+
// Replace URL in JSON file
101+
if (jsonContent['sap.app'] && jsonContent['sap.app'].dataSources && jsonContent['sap.app'].dataSources.http && jsonContent['sap.app'].dataSources.http.uri) {
102+
console.log(`Old URL in JSON file: ${jsonContent['sap.app'].dataSources.http.uri}`);
103+
jsonContent['sap.app'].dataSources.http.uri = jsonContent['sap.app'].dataSources.http.uri.replace(yamlContent.old_name, newName);
104+
console.log(`New URL in JSON file: ${jsonContent['sap.app'].dataSources.http.uri}`);
105+
} else {
106+
console.error('No URI found in JSON file');
107+
}
108+
109+
// Save modified JSON file
110+
fs.writeFile(jsonFilePath, JSON.stringify(jsonContent, null, 4), 'utf8', (writeErr) => {
111+
if (writeErr) {
112+
console.error('Error writing JSON file:', writeErr);
113+
return;
114+
}
115+
console.log(`JSON file saved successfully. URL replaced with: ${jsonContent['sap.app'].dataSources.http.uri}`);
116+
});
117+
});
118+
});
119+
});
120+
});
121+
});

dist/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ This is my new abap2UI5 build.
1818

1919
### Timestamp
2020

21-
Created at: February 26, 2025 at 03:04:22 PM
21+
Created at: February 26, 2025 at 03:36:00 PM

0 commit comments

Comments
 (0)