-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathconvert.js
71 lines (68 loc) · 2.66 KB
/
convert.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
global.__base = __dirname + "/"
console.log(global.__base)
const path = require('path')
const fs = require("fs")
const fileExists = require('fs').existsSync
const glob = require('glob')
let routesDir = path.join(global.__base, '../oldPython/resources/schemas/*.json')
let files = glob.sync(routesDir)
this.routerFiles = files;
let i18nString = ''
let cdsString = `using { \n managed,\n sap,\n cuid\n} from '@sap/cds/common';\n\nnamespace star.wars;\n`
if (files.length !== 0) {
for (let file of files) {
console.log(`Reading ${file}`)
let importData = fs.readFileSync(file)
let schema = JSON.parse(importData)
i18nString += `# ${schema.title}\n`
i18nString += `${schema.title} = ${schema.description}\n`
cdsString += `entity ${schema.title} : cuid, managed {\n`
for (let property in schema.properties) {
switch (property) {
case 'created':
break
case 'edited':
break
default:
let dataType = 'String'
if(schema.properties[property].format){
if(schema.properties[property].format == 'date-time'){
dataType = `DateTime`
}
if(schema.properties[property].format == 'date'){
dataType = `Date`
}
}
if(schema.properties[property].type == 'integer'){
dataType = `Integer`
}
if(schema.properties[property].type == 'array'){
dataType = `Association to many Blank`
}
i18nString += `${property} = ${schema.properties[property].description} \n`
cdsString += `${property} : ${dataType};\n`
break
}
}
cdsString += `}\n\n`
cdsString += `annotate ${schema.title} with @(title : '{i18n>${schema.title}}') {\n`
for (let property in schema.properties) {
switch (property) {
case 'created':
break
case 'edited':
break
default:
cdsString += `${property} @title : '{i18n>${property}}';\n`
break
}
}
cdsString += `}\n\n`
}
fs.writeFile("./i18n.properties", i18nString, null, (err) => {
if (err) { console.err(err) }
})
fs.writeFile("./schema.cds", cdsString, null, (err) => {
if (err) { console.err(err) }
})
}