MCPcopy
hub / github.com/loopbackio/loopback-next / updateFileHeaders

Function updateFileHeaders

packages/cli/generators/copyright/header.js:197–247  ·  view source on GitHub ↗

* Update file headers for the given project * @param {string} projectRoot - Root directory of a package or a lerna monorepo * @param {object} options - Options

(projectRoot, options = {})

Source from the content-addressed store, hash-verified

195 * @param {object} options - Options
196 */
197async function updateFileHeaders(projectRoot, options = {}) {
198 debug('Starting project root: %s', projectRoot);
199 options = {
200 dryRun: false,
201 gitOnly: true,
202 ...options,
203 };
204
205 const {content: rootPkg} = await pkgJson.load(projectRoot);
206 if ('workspaces' in rootPkg) {
207 const workspaces = await mapWorkspaces({cwd: projectRoot, pkg: rootPkg});
208 const packages = Array.from(workspaces, ([name, location]) => ({
209 name,
210 location,
211 }));
212
213 // Update file headers for each package
214 const visited = [];
215 for (const p of packages) {
216 visited.push(p.location);
217 const pkgOptions = {...options};
218 // Set default copyright owner and id so that package-level settings
219 // take precedence
220 pkgOptions.defaultCopyrightIdentifer = options.copyrightIdentifer;
221 pkgOptions.defaultCopyrightOwner = options.copyrightOwner;
222 pkgOptions.defaultLicense = options.license;
223 delete pkgOptions.copyrightOwner;
224 delete pkgOptions.copyrightIdentifer;
225 delete pkgOptions.license;
226 await updateFileHeaders(p.location, pkgOptions);
227 }
228
229 // Now handle the root level package
230 // Exclude files that have been processed
231 const filter = f => {
232 const included = !visited.some(dir => {
233 dir = path.relative(projectRoot, dir);
234 // glob return files with `/`
235 return f.startsWith(path.join(dir, '/').replace(/\\/g, '/'));
236 });
237 if (included) {
238 debug('File %s is included for monorepo package', f);
239 }
240 return included;
241 };
242 const pkgOptions = {filter, ...options};
243 await updateFileHeadersForSinglePackage(projectRoot, pkgOptions);
244 } else {
245 await updateFileHeadersForSinglePackage(projectRoot, options);
246 }
247}
248
249/**
250 * Update file headers for the given project

Callers 2

updateHeadersMethod · 0.85
header.jsFile · 0.85

Calls 2

loadMethod · 0.65

Tested by

no test coverage detected