Skip to content
Snippets Groups Projects
Commit 79b9fb1d authored by Ramesh Kumar's avatar Ramesh Kumar
Browse files

TMSS-1587: Script files moved to application root folder

parent af5346af
No related branches found
No related tags found
1 merge request!773TMSS-1587: Updated mock data to get observation_strategy_template and...
//const fs = require('fs').promises;
const fs = require('fs');
const path = require('path');
if (fs.existsSync("build/schemas")) {
fs.rm("build/schemas", { recursive: true, force: true }, (err) => {
if (err) {
throw err;
}
console.log("Deleted build/schemas");
});
}
if (fs.existsSync("public/schemas")) {
fs.rm("public/schemas", { recursive: true, force: true }, (err) => {
if (err) {
throw err;
}
console.log("Deleted public/schemas");
});
}
\ No newline at end of file
...@@ -75,8 +75,8 @@ ...@@ -75,8 +75,8 @@
"build": "react-scripts build", "build": "react-scripts build",
"test": "react-scripts test", "test": "react-scripts test",
"eject": "react-scripts eject", "eject": "react-scripts eject",
"prepareTemplateSchemas": "node scripts/prepareTemplateSchemas.js", "prepareTemplateSchemas": "node prepareTemplateSchemas.js",
"cleanTemplateSchemas": "node scripts/cleanTemplateSchemas.js" "cleanTemplateSchemas": "node cleanTemplateSchemas.js"
}, },
"proxy": "http://127.0.0.1:8008/", "proxy": "http://127.0.0.1:8008/",
"eslintConfig": { "eslintConfig": {
......
//const fs = require('fs').promises;
const fs = require('fs');
const path = require('path');
const replace = require('replace-in-file');
async function getTemplateFiles(dir) {
let files = await fs.promises.readdir(dir);
files = await Promise.all(files.map(async file => {
const filePath = path.join(dir, file);
const stats = await fs.promises.stat(filePath);
if (stats.isDirectory()) return getTemplateFiles(filePath);
else if(stats.isFile()) return filePath;
}));
return files.reduce((all, folderContents) => all.concat(folderContents), []);
}
// Get and Copy all template files from backend source to frontend app folders and format as required
getTemplateFiles('../../backend/src/tmss/tmssapp/schemas').then(async(backEndFiles) => {
console.log(backEndFiles);
// Copy backend template json files to public/schemas folder in frontend app
for (let file of backEndFiles) {
if (file.indexOf(".json") <=0) { continue; }
let folderName = file.substring(file.indexOf("schemas\\")+8, file.lastIndexOf("\\"));
let fileName = file.substring(file.lastIndexOf("\\")+1);
const data = fs.readFileSync(file, 'utf8')
console.log(data)
if (!fs.existsSync("public/schemas/" + folderName)) {
fs.mkdirSync("public/schemas/" + folderName, { recursive: true });
}
fs.writeFileSync("public/schemas/" + folderName + "/" + fileName, data);
}
// Get all template files from public/schema folder and format as required
getTemplateFiles('public/schemas').then(async(files) => {
//console.log(files);
// Replace the host and port address of template apis to localhost
const hostReplaceOptions = {
//files: 'schemas/scheduling_constraints_template/constraints-1.json',
files: files,
from: /http:\/\/127.0.0.1:8000\/api/g,
to: 'http://localhost:3000',
};
console.log(await replace(hostReplaceOptions));
// Replace db_id with file extension
const fileReplaceOptions = {
files: files,
from: /\/1\/#/g,
to: '-1.json#',
};
console.log(await replace(fileReplaceOptions));
/*const fileReplaceOptions1 = {
files: files,
from: /\/1#/g,
to: '-1.json#',
};
console.log(await replace(fileReplaceOptions1));
const fileReplaceOptions2 = {
files: files,
from: /.json#\/definitions/g,
to: '.json#/schema/definitions',
};
console.log(await replace(fileReplaceOptions2));*/
for (let file of files) {
if (file.indexOf(".json") <=0) { continue; }
console.log(file);
let folderName = file.substring(file.indexOf("schemas\\")+8, file.lastIndexOf("\\"));
// Replae folder name
let folderRef = folderName.replace(/_/g,"");
let folderRefRegex = new RegExp(folderRef, "g");
const folderReplaceOptions = {
files: files,
from: folderRefRegex,
to: folderName,
};
console.log(await replace(folderReplaceOptions));
// Copy templates to build folder so that it can be referred by the test suites
const data = fs.readFileSync(file, 'utf8')
console.log(data)
if (!fs.existsSync("build/schemas/" + folderName)) {
fs.mkdirSync("build/schemas/" + folderName, { recursive: true });
}
fs.writeFileSync(file.replace("public","build"), data);
// Update the json files in public/schemas folder to contain only the schema object
const jsonData = JSON.parse(data);
if (jsonData["schema"]) {
fs.writeFileSync(file, JSON.stringify(jsonData["schema"]));
}
}
});
});
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment