MCPcopy Create free account
hub / github.com/SAP/ui5-project / readWorkspaceConfigFile

Function readWorkspaceConfigFile

lib/graph/helpers/createWorkspace.js:71–133  ·  view source on GitHub ↗
(filePath)

Source from the content-addressed store, hash-verified

69}
70
71async function readWorkspaceConfigFile(filePath) {
72 const {
73 default: fs
74 } = await import("graceful-fs");
75 const {promisify} = await import("node:util");
76 const readFile = promisify(fs.readFile);
77 const jsyaml = await import("js-yaml");
78
79 let fileContent;
80 try {
81 fileContent = await readFile(filePath, {encoding: "utf8"});
82 } catch (err) {
83 throw new Error(
84 `Failed to load workspace configuration from path ${filePath}: ${err.message}`, {
85 cause: err
86 });
87 }
88 let configs;
89 try {
90 configs = jsyaml.loadAll(fileContent, undefined, {
91 filename: filePath,
92 });
93 } catch (err) {
94 throw new Error(`Failed to parse workspace configuration at ${filePath}\nError: ${err.message}`);
95 }
96
97 if (!configs || !configs.length) {
98 // No configs found => exit here
99 log.verbose(`Found empty workspace configuration file at ${filePath}`);
100 return configs;
101 }
102
103 // Validate found configurations with schema
104 // Validation is done again in the Workspace class. But here we can reference the YAML file
105 // which adds helpful information like the line number
106 const validationResults = await Promise.all(
107 configs.map(async (config, documentIndex) => {
108 // Catch validation errors to ensure proper order of rejections within Promise.all
109 try {
110 await validateWorkspace({
111 config,
112 yaml: {
113 path: filePath,
114 source: fileContent,
115 documentIndex
116 }
117 });
118 } catch (error) {
119 return error;
120 }
121 })
122 );
123
124 const validationErrors = validationResults.filter(($) => $);
125
126 if (validationErrors.length > 0) {
127 // Throw any validation errors
128 // For now just throw the error of the first invalid document

Callers 1

createWorkspaceFunction · 0.85

Calls 1

validateWorkspaceFunction · 0.90

Tested by

no test coverage detected