@sap-ux/project-integrity 0.1.16 → 0.1.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fiori-project/index.js +67 -2
- package/package.json +2 -2
|
@@ -12,6 +12,8 @@ const fs_1 = require("fs");
|
|
|
12
12
|
const path_1 = require("path");
|
|
13
13
|
const project_access_1 = require("@sap-ux/project-access");
|
|
14
14
|
const integrity_1 = require("../integrity");
|
|
15
|
+
const hash_1 = require("../integrity/hash");
|
|
16
|
+
const persistence_1 = require("../integrity/persistence");
|
|
15
17
|
exports.fioriIntegrityDataPath = (0, path_1.join)('.fiori-ai/ai-integrity.json');
|
|
16
18
|
/**
|
|
17
19
|
* Get the list of files to protect the integrity of.
|
|
@@ -37,6 +39,24 @@ async function getFileList(projectRoot) {
|
|
|
37
39
|
}
|
|
38
40
|
return fileList;
|
|
39
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Retrieves the Core Schema Notation (CSN) content for a given project root.
|
|
44
|
+
*
|
|
45
|
+
* This function generates a JSON string containing the namespace and definitions
|
|
46
|
+
* from the CSN model of the specified project root.
|
|
47
|
+
*
|
|
48
|
+
* @param projectRoot - The root directory of the project.
|
|
49
|
+
* @returns A promise that resolves to a JSON string containing the CSN content,
|
|
50
|
+
* including the namespace and structured clone of the definitions.
|
|
51
|
+
*/
|
|
52
|
+
async function getCsnContent(projectRoot) {
|
|
53
|
+
const modelFiles = { srv: (0, path_1.join)('srv', 'service.cds'), db: (0, path_1.join)('db', 'schema.cds') };
|
|
54
|
+
const pathSelection = new Set(Object.keys(modelFiles));
|
|
55
|
+
const result = await (0, project_access_1.getCapModelAndServices)({ projectRoot, pathSelection });
|
|
56
|
+
const csn = result.model;
|
|
57
|
+
const data = { namespace: csn.namespace, definitions: structuredClone(csn.definitions) };
|
|
58
|
+
return JSON.stringify(data);
|
|
59
|
+
}
|
|
40
60
|
/**
|
|
41
61
|
* Returns additional string content, like the CAP environment.
|
|
42
62
|
* This content will be stored in the integrity data.
|
|
@@ -46,7 +66,8 @@ async function getFileList(projectRoot) {
|
|
|
46
66
|
*/
|
|
47
67
|
async function getAdditionalStringContent(projectRoot) {
|
|
48
68
|
const capCustomPaths = await (0, project_access_1.getCapCustomPaths)(projectRoot);
|
|
49
|
-
|
|
69
|
+
const cnsContent = await getCsnContent(projectRoot);
|
|
70
|
+
return { capPaths: JSON.stringify(capCustomPaths), csn: cnsContent };
|
|
50
71
|
}
|
|
51
72
|
/**
|
|
52
73
|
* Initialize a Fiori project for integrity protection.
|
|
@@ -68,7 +89,51 @@ async function initFioriProject(projectRoot) {
|
|
|
68
89
|
async function checkFioriProjectIntegrity(projectRoot) {
|
|
69
90
|
const integrityFilePath = (0, path_1.join)(projectRoot, exports.fioriIntegrityDataPath);
|
|
70
91
|
const additionalStringContent = await getAdditionalStringContent(projectRoot);
|
|
71
|
-
|
|
92
|
+
const checkResult = await (0, integrity_1.checkProjectIntegrity)(integrityFilePath, additionalStringContent);
|
|
93
|
+
const integrityData = await (0, persistence_1.readIntegrityData)(integrityFilePath);
|
|
94
|
+
/**
|
|
95
|
+
* 1. if csn integrity is the same, but file integrity is different, then is compatible changes (e.g empty spaces, new lines or comments). Add them to equal files, update integrity and remove cds files from different files,
|
|
96
|
+
* 2. if csn integrity is different, but file integrity is same, then CDS compiler might have produced different CSN. Remove csnPath from different content and add it to equal content. Update integrity.
|
|
97
|
+
* 3. if csn integrity is different and file integrity is different, then it is un-compatible changes. Report them.
|
|
98
|
+
*/
|
|
99
|
+
const csnDiff = checkResult.additionalStringContent?.differentContent.some((content) => content.key === 'csn');
|
|
100
|
+
const fileDiff = checkResult.files.differentFiles.some((file) => file.filePath.endsWith('.cds'));
|
|
101
|
+
if (csnDiff === false && fileDiff === true) {
|
|
102
|
+
// case 1
|
|
103
|
+
checkResult.files.equalFiles.push(...checkResult.files.differentFiles.map((file) => file.filePath));
|
|
104
|
+
// also update integrity.json file
|
|
105
|
+
const cdsDiffFiles = checkResult.files.differentFiles.filter((file) => file.filePath.endsWith('.cds'));
|
|
106
|
+
const diffFileIntegrity = await (0, hash_1.getFileIntegrity)(cdsDiffFiles.map((file) => file.filePath));
|
|
107
|
+
const fileIntegrity = integrityData.fileIntegrity.map((file) => {
|
|
108
|
+
const diffFile = diffFileIntegrity.find((diff) => diff.filePath === file.filePath);
|
|
109
|
+
if (diffFile) {
|
|
110
|
+
return { ...file, hash: diffFile.hash, content: diffFile.content };
|
|
111
|
+
}
|
|
112
|
+
return file;
|
|
113
|
+
});
|
|
114
|
+
await (0, persistence_1.writeIntegrityData)(integrityFilePath, {
|
|
115
|
+
enabled: integrityData.enabled,
|
|
116
|
+
fileIntegrity,
|
|
117
|
+
contentIntegrity: integrityData.contentIntegrity
|
|
118
|
+
});
|
|
119
|
+
// remove cds files from different files
|
|
120
|
+
checkResult.files.differentFiles = checkResult.files.differentFiles.filter((file) => !file.filePath.endsWith('.cds'));
|
|
121
|
+
}
|
|
122
|
+
if (csnDiff === true && fileDiff === false) {
|
|
123
|
+
// case 2
|
|
124
|
+
const csnIndex = checkResult.additionalStringContent.differentContent.findIndex((content) => content.key === 'csn');
|
|
125
|
+
const [csnContent] = checkResult.additionalStringContent.differentContent.splice(csnIndex, 1);
|
|
126
|
+
checkResult.additionalStringContent.equalContent.push(csnContent.key);
|
|
127
|
+
// update csn content
|
|
128
|
+
const contentIntegrity = (0, hash_1.getContentIntegrity)(additionalStringContent);
|
|
129
|
+
await (0, persistence_1.writeIntegrityData)(integrityFilePath, {
|
|
130
|
+
enabled: integrityData.enabled,
|
|
131
|
+
fileIntegrity: integrityData.fileIntegrity,
|
|
132
|
+
contentIntegrity
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
// case 3 or return checkResult of case 1 or 2
|
|
136
|
+
return checkResult;
|
|
72
137
|
}
|
|
73
138
|
/**
|
|
74
139
|
* Updates the integrity data of a Fiori project.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sap-ux/project-integrity",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.18",
|
|
4
4
|
"description": "Library to check the integrity of projects",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"lz-string": "1.5.0",
|
|
27
|
-
"@sap-ux/project-access": "1.29.
|
|
27
|
+
"@sap-ux/project-access": "1.29.19"
|
|
28
28
|
},
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "tsc --build",
|