MCPcopy Create free account
hub / github.com/GooGee/Entity-Builder / writeFile

Function writeFile

src/Service/Generator/writeFile.ts:20–95  ·  view source on GitHub ↗
(
    file: LB.File,
    entity: LB.IdNameItem,
    module: LB.Module | undefined = undefined,
    ma: LB.ModuleAction | undefined = undefined,
    action: string,
    psr4: LB.StringMap,
    dbCopy: LB.DBData | undefined = undefined,
    DataMap: Record<string, any> = {},
)

Source from the content-addressed store, hash-verified

18import { callCode } from "./runCode"
19
20export default function writeFile(
21 file: LB.File,
22 entity: LB.IdNameItem,
23 module: LB.Module | undefined = undefined,
24 ma: LB.ModuleAction | undefined = undefined,
25 action: string,
26 psr4: LB.StringMap,
27 dbCopy: LB.DBData | undefined = undefined,
28 DataMap: Record<string, any> = {},
29) {
30 let cloneDB
31 if (dbCopy === undefined) {
32 cloneDB = exportDB().then((db) => cloneDeep(db))
33 } else {
34 cloneDB = Promise.resolve(dbCopy)
35 }
36
37 return cloneDB.then(function (db) {
38 const folder = "code" + APP_VERSION_NUMBER
39 return readFilezzInFolder(getDirectoryName(folder)).then(function (response) {
40 const fileMap = response.data.data
41 const treeMap = makeLinkedTreeMap(db.tables.Directory)
42 const treeHelper = makeTreeHelper(treeMap, psr4)
43 const ddd: LB.DataForScript = {
44 file,
45 entity,
46 module,
47 ma,
48 db,
49 dependencyzz: [],
50 fileMap,
51 getResponseContentColumnzz,
52 getTypeFormatColumnzz,
53 lodash,
54 makeChildzzMap,
55 makeIdItemMap,
56 makeIdNameMap,
57 tree: treeHelper,
58 treeMap,
59 action,
60 helper: {},
61 DataMap,
62 }
63
64 if (HelperCodeFileName in fileMap) {
65 callCode(fileMap[HelperCodeFileName], ddd)
66 }
67
68 const jsn = getCodeFileName(file, ScriptExtention)
69 if (jsn in fileMap) {
70 callCode(fileMap[jsn], ddd)
71 } else {
72 console.warn(jsn + " does not exist")
73 }
74
75 const tn = getCodeFileName(file, TemplateExtention)
76 if (tn in fileMap) {
77 nunjucks.configure({ autoescape: false })

Callers 2

FileButtonFunction · 0.85
createFileFunction · 0.85

Calls 10

exportDBFunction · 0.90
readFilezzInFolderFunction · 0.90
getDirectoryNameFunction · 0.90
callCodeFunction · 0.90
getCodeFileNameFunction · 0.90
putFileFunction · 0.90
refreshDiskFunction · 0.90
makeLinkedTreeMapFunction · 0.85
makeTreeHelperFunction · 0.85
deleteMethod · 0.65

Tested by

no test coverage detected