-
-
Save JanTristanH/5982098b30ad8aae2eb9b33e161cfed4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this script removes the @(restrict ..) from apipos-service.cds temporarily | |
const fs = require('fs'); | |
const searchStr = ' @\(restrict' | |
const fileName = '../srv/apip-service.cds' | |
let fileContent = fs.readFileSync(__dirname + '/' + fileName, 'utf8'); | |
fs.writeFileSync(__dirname + '/tmp-unmodified-api-service.cds', fileContent) | |
function findClosingBracketMatchIndex (str, pos) { | |
let openBracketCount = 0; | |
let givenBracketPosition = -1; | |
let index = -1; | |
for (let i = 0; i < str.length; i++) { | |
let char = str[i]; | |
if (char === '(') { | |
openBracketCount++; | |
if (i === pos) { | |
givenBracketPosition = openBracketCount; | |
} | |
} else if (char === ')') { | |
if (openBracketCount === givenBracketPosition) { | |
index = i; | |
break; | |
} | |
openBracketCount--; | |
} | |
} | |
return index; | |
} | |
function insert(str, index, value) { | |
return str.substr(0, index) + value + str.substr(index); | |
} | |
while(fileContent.indexOf(searchStr) > 0){ | |
let i = fileContent.indexOf(searchStr); | |
//insert */ after matching closing bracket | |
fileContent = insert(fileContent, findClosingBracketMatchIndex(fileContent, i + 2) + 1, '*/') | |
//insert /* at opening restrict | |
//add 1 to keep space before @ | |
fileContent = insert(fileContent, i + 1, '/*') | |
} | |
//console.log(fileContent); | |
fs.writeFileSync(__dirname + '/' + fileName, fileContent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// this script writes back the removed requires | |
const fs = require('fs'); | |
const fileName = '../srv/api-service.cds' | |
let fileContent = fs.readFileSync(__dirname + '/tmp-unmodified-api-service.cds', 'utf8'); | |
fs.writeFileSync(__dirname + '/' + fileName, fileContent) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment