MCPcopy Create free account
hub / github.com/UI5/webcomponents / getScripts

Method getScripts

packages/tools/bin/ui5nps.js:128–174  ·  view source on GitHub ↗

* Loads and validates package-scripts file * @returns {Object} Object containing scripts and environment variables

()

Source from the content-addressed store, hash-verified

126 * @returns {Object} Object containing scripts and environment variables
127 */
128 getScripts() {
129 let packageScriptPath;
130
131 for (const scriptName of SCRIPT_NAMES) {
132 const filePath = path.join(process.cwd(), scriptName);
133 if (fs.existsSync(filePath)) {
134 packageScriptPath = filePath;
135 break;
136 }
137 }
138
139 // Package-script file should be in the current working directory
140 if (!packageScriptPath) {
141 console.error("No package-scripts.js/cjs/mjs file found in the current directory.");
142 process.exit(1);
143 }
144
145 const packageScript = require(packageScriptPath);
146 let scripts;
147 let envs;
148
149 if (packageScript.__esModule) {
150 scripts = packageScript.default.scripts;
151 } else {
152 scripts = packageScript.scripts;
153 }
154
155 // Package-script should provide default export with scripts object
156 if (!scripts || typeof scripts !== "object") {
157 console.error("No valid 'scripts' object found in package-scripts file.");
158 process.exit(1);
159 }
160
161 envs = JSON.parse(JSON.stringify(scripts.__ui5envs || {}));
162
163 Object.entries(envs).forEach(([key, value]) => {
164 envs[key] = String(value);
165 });
166
167 // Package-script should provide default export with scripts object
168 if (envs && typeof envs !== "object") {
169 console.error("No valid 'envs' object found in package-scripts file.");
170 process.exit(1);
171 }
172
173 return { scripts, envs };
174 }
175
176 /**
177 * Executes a command or command object (with parallel/sequential support)

Callers 1

constructorMethod · 0.95

Calls 1

parseMethod · 0.45

Tested by

no test coverage detected