MCPcopy Create free account
hub / github.com/BuilderIO/mitosis / copy

Function copy

packages/starter/script.cjs:72–111  ·  view source on GitHub ↗
(src, dest)

Source from the content-addressed store, hash-verified

70 * @param {string} dest
71 */
72 const copy = (src, dest) => {
73 fs.mkdirSync(dest, { recursive: true });
74 fs.readdirSync(src).forEach((entry) => {
75 if (entry === 'node_modules') return;
76 if (entry === 'package-lock.json') return;
77
78 // ignore folders meant for excluded targets
79 const isTargetSpecificFolder =
80 src.endsWith('/library/packages') || src.endsWith('/test-apps');
81 if (isTargetSpecificFolder && !targets.some((target) => entry === target)) {
82 return;
83 }
84
85 const srcPath = path.join(src, entry);
86 const destPath = path.join(dest, entry);
87
88 // update mitosis.config.cjs
89 if (entry === 'mitosis.config.cjs') {
90 try {
91 const newConfig = updateMitosisConfig(srcPath);
92
93 fs.writeFileSync(destPath, newConfig);
94 } catch (error) {
95 p.note('Error processing `mitosis.config.cjs`. Copying as-is.');
96 console.error(error);
97 fs.copyFileSync(srcPath, destPath);
98 }
99 return;
100 }
101
102 if (fs.lstatSync(srcPath).isDirectory()) {
103 copy(srcPath, destPath);
104 } else {
105 const fileContents = fs.readFileSync(srcPath, 'utf8');
106 // update all files to have correct package names
107 const updatedFileContents = fileContents.replace(/@template/g, '@' + projectName);
108 fs.writeFileSync(destPath, updatedFileContents);
109 }
110 });
111 };
112
113 copy(templateFolder, outputFolder);
114

Callers 1

mainFunction · 0.85

Calls 1

updateMitosisConfigFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…