MCPcopy
hub / github.com/QwikDev/qwik / mergeIntegrationDir

Function mergeIntegrationDir

packages/qwik/src/cli/add/update-files.ts:7–60  ·  view source on GitHub ↗
(
  fileUpdates: FsUpdates,
  opts: UpdateAppOptions,
  srcDir: string,
  destDir: string,
  alwaysInRoot?: string[]
)

Source from the content-addressed store, hash-verified

5import { getPackageManager } from '../utils/utils';
6
7export async function mergeIntegrationDir(
8 fileUpdates: FsUpdates,
9 opts: UpdateAppOptions,
10 srcDir: string,
11 destDir: string,
12 alwaysInRoot?: string[]
13) {
14 const items = await fs.promises.readdir(srcDir);
15 await Promise.all(
16 items.map(async (itemName) => {
17 const destName = itemName === 'gitignore' ? '.gitignore' : itemName;
18 const ext = extname(destName);
19 const srcChildPath = join(srcDir, itemName);
20
21 const destRootPath = join(destDir, destName);
22
23 const s = await fs.promises.stat(srcChildPath);
24
25 if (s.isDirectory()) {
26 await mergeIntegrationDir(fileUpdates, opts, srcChildPath, destRootPath, alwaysInRoot);
27 } else if (s.isFile()) {
28 const finalDestPath = getFinalDestPath(opts, destRootPath, destDir, destName, alwaysInRoot);
29
30 if (destName === 'package.json') {
31 await mergePackageJsons(fileUpdates, srcChildPath, destRootPath);
32 } else if (destDir.endsWith('.vscode') && destName === 'settings.json') {
33 await mergeVSCodeSettings(fileUpdates, srcChildPath, finalDestPath);
34 } else if (destName === 'README.md') {
35 await mergeReadmes(fileUpdates, srcChildPath, finalDestPath);
36 } else if (
37 destName === '.gitignore' ||
38 destName === '.prettierignore' ||
39 destName === '.eslintignore'
40 ) {
41 await mergeIgnoresFile(fileUpdates, srcChildPath, destRootPath);
42 } else if (ext === '.css') {
43 await mergeCss(fileUpdates, srcChildPath, finalDestPath, opts);
44 } else if (fs.existsSync(finalDestPath)) {
45 fileUpdates.files.push({
46 path: finalDestPath,
47 content: await fs.promises.readFile(srcChildPath),
48 type: 'overwrite',
49 });
50 } else {
51 fileUpdates.files.push({
52 path: finalDestPath,
53 content: await fs.promises.readFile(srcChildPath),
54 type: 'create',
55 });
56 }
57 }
58 })
59 );
60}
61
62function getFinalDestPath(
63 opts: UpdateAppOptions,

Callers 2

updateAppFunction · 0.90

Calls 8

extnameFunction · 0.85
joinFunction · 0.85
getFinalDestPathFunction · 0.85
mergePackageJsonsFunction · 0.85
mergeVSCodeSettingsFunction · 0.85
mergeReadmesFunction · 0.85
mergeIgnoresFileFunction · 0.85
mergeCssFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…