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

TMSS-1587: Added script to copy, format template schemas for test and delete after test

parent e66b3631
No related branches found
No related tags found
1 merge request!773TMSS-1587: Updated mock data to get observation_strategy_template and...
......@@ -23,3 +23,4 @@ SAS/OTB/jRSP/configure.in
venv
SAS/TMSS/frontend/tmss_webapp/node_modules/
SAS/TMSS/frontend/tmss_webapp/debug.log
*.bak
......@@ -382,10 +382,12 @@ unit_test_TMSS_Frontend:
- PACKAGE=SCU
- echo "Testing $PACKAGE..."
- cd build/gnucxx11_opt/SAS/TMSS/frontend/tmss_webapp
- npm run prepareTemplateSchemas
- nohup npm start &
- cd build/gnucxx11_opt/SAS/TMSS/frontend/tmss_webapp/build
- npm test a
- npx kill-port 3000
- npm run cleanTemplateSchemas
interruptible: true
needs:
- build_SCU
......
This diff is collapsed.
......@@ -61,6 +61,7 @@
"react-websocket": "^2.1.0",
"reactstrap": "^8.5.1",
"redux": "^4.1.0",
"replace-in-file": "^6.3.2",
"shortcut-buttons-flatpickr": "^0.3.1",
"styled-components": "^5.1.1",
"suneditor": "^2.36.5",
......@@ -73,7 +74,9 @@
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
"eject": "react-scripts eject",
"prepareTemplateSchemas": "node scripts/prepareTemplateSchemas.js",
"cleanTemplateSchemas": "node scripts/cleanTemplateSchemas.js"
},
"proxy": "http://127.0.0.1:8008/",
"eslintConfig": {
......
{
"$id": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#",
"$schema": "http://json-schema.org/draft-06/schema#",
"definitions": {
"timedelta": {
"default": 0,
"description": "A time duration or delta expressed in seconds",
"type": "number"
},
"timestamp": {
"description": "A timestamp defined in UTC",
"format": "date-time",
"pattern": "\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\d(\\.\\d+)?Z?",
"type": "string"
},
"timewindow": {
"additionalProperties": false,
"description": "A timewindow interval: [from, to)",
"properties": {
"from": {
"$ref": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#/definitions/timestamp"
},
"to": {
"$ref": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#/definitions/timestamp"
}
},
"required": [
"from",
"to"
],
"type": "object"
}
},
"description": "This schema defines datetime objects like timestamp and timewindow.",
"title": "datetime",
"type": "object",
"version": 1
}
\ No newline at end of file
{
"description": "This schema defines the scheduling constraints for a scheduling unit",
"name": "constraints",
"purpose": "technical_commissioning",
"schema": {
"$id": "http://localhost:3000/schemas/scheduling_constraints_template/constraints/1#",
"$schema": "http://json-schema.org/draft-06/schema#",
"default": {},
"definitions": {
"distance_on_sky": {
"maximum": 3.142,
"minimum": 0,
"type": "number"
},
"elevation": {
"maximum": 1.571,
"minimum": 0,
"type": "number"
}
},
"description": "This schema defines the scheduling constraints for a scheduling unit",
"properties": {
"daily": {
"additionalProperties": false,
"default": {},
"properties": {
"avoid_twilight": {
"default": false,
"description": "Do not run during sunrise or sunset",
"type": "boolean"
},
"require_day": {
"default": false,
"description": "Must run in daylight",
"type": "boolean"
},
"require_night": {
"default": false,
"description": "Must run at night",
"type": "boolean"
}
},
"type": "object"
},
"scheduler": {
"default": "dynamic",
"description": "Schedule either at the fixed_time 'time.at' moment, of dynamically taking all time constraints into consideration.",
"enum": [
"fixed_time",
"dynamic"
],
"name": "Scheduler",
"type": "string"
},
"sky": {
"additionalProperties": false,
"default": {},
"properties": {
"min_distance": {
"additionalProperties": false,
"default": {},
"properties": {
"jupiter": {
"$ref": "#/definitions/distance_on_sky",
"default": 0.5
},
"moon": {
"$ref": "#/definitions/distance_on_sky",
"default": 0.5
},
"sun": {
"$ref": "#/definitions/distance_on_sky",
"default": 0.5
}
},
"type": "object"
},
"min_elevation": {
"additionalProperties": false,
"default": {},
"properties": {
"calibrator": {
"$ref": "#/definitions/elevation",
"default": 0.5,
"description": "Minimum elevation for all calibrator sources"
},
"target": {
"$ref": "#/definitions/elevation",
"default": 0.5,
"description": "Minimum elevation for all target sources"
}
},
"type": "object"
},
"transit_offset": {
"additionalProperties": false,
"default": {},
"description": "Offset window to LST centering",
"properties": {
"from": {
"$ref": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#/definitions/timedelta",
"default": -7200,
"maximum": 86400,
"minimum": -86400
},
"to": {
"$ref": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#/definitions/timedelta",
"default": 7200,
"maximum": 86400,
"minimum": -86400
}
},
"required": [
"from",
"to"
],
"type": "object"
}
},
"type": "object"
},
"time": {
"additionalProperties": false,
"default": {},
"properties": {
"after": {
"$ref": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#/definitions/timestamp",
"description": "Start after this moment"
},
"at": {
"$ref": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#/definitions/timestamp",
"description": "Start at the specified date/time. Overrules dynamic scheduler priority. To be used only if really needed. Requires 'scheduler' to be set to 'fixed_time'."
},
"before": {
"$ref": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#/definitions/timestamp",
"description": "End before this moment"
},
"between": {
"default": [],
"description": "Run within one of these time windows",
"items": {
"$ref": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#/definitions/timewindow"
},
"minItems": 0,
"type": "array",
"uniqueItems": true
},
"not_between": {
"default": [],
"description": "Do NOT run within any of these time windows",
"items": {
"$ref": "http://localhost:3000/schemas/common_schema_template/datetime-1.json#/definitions/timewindow"
},
"minItems": 0,
"type": "array",
"uniqueItems": true
}
},
"type": "object"
}
},
"required": [
"scheduler"
],
"title": "constraints",
"type": "object",
"version": 1
},
"state": "active",
"version": 1
}
\ No newline at end of file
//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
//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