MCPcopy
hub / github.com/brunch/brunch / initSkeleton

Function initSkeleton

lib/init-skeleton.js:130–166  ·  view source on GitHub ↗

* @param {string} alias filesystem path or skeleton url * @param {string} rootPath * @returns {Promise }

(alias, rootPath)

Source from the content-addressed store, hash-verified

128 * @returns {Promise<boolean>}
129 */
130async function initSkeleton(alias, rootPath) {
131 if (!alias) {
132 alias = process.env.BRUNCH_INIT_SKELETON || 'https://github.com/brunch/dead-simple';
133 }
134 const cwd = process.cwd();
135 rootPath = sysPath.resolve(rootPath || cwd);
136
137 if (alias == null || alias === '.' && rootPath === cwd) {
138 return printErrorBanner();
139 }
140
141 if (await exists(sysPath.join(rootPath, 'package.json'))) {
142 const error = new Error(`Directory "${rootPath}" is already an npm project`);
143 error.code = 'ALREADY_NPM_PROJECT';
144 throw error;
145 }
146
147 // Copy skeleton from file system. Returns Promise.
148 const skeleton = skeletons.urlFor(alias) || alias;
149 const skeletonExists = await exists(skeleton);
150 const rPath = skeletonExists ? skeleton : await clone(skeleton);
151 await fs.promises.mkdir(rootPath, {recursive: true, mode: rwxrxrx});
152
153 const relative = sysPath.relative(cwd, rootPath);
154 logger.info(`Copying local skeleton to "${relative}"...`);
155 const timer = Date.now();
156 await ncp(rPath, rootPath, {
157 filter: path => !/^\.(git|hg)$/.test(sysPath.basename(path))
158 });
159
160 const difference = Date.now() - timer;
161 if (difference > 30) {
162 logger.info('Created skeleton directory layout');
163 }
164 await installDeps(rootPath, {logger});
165 return true;
166};
167
168exports.initSkeleton = initSkeleton;
169exports.cleanURL = cleanURL;

Callers 1

createFunction · 0.85

Calls 3

printErrorBannerFunction · 0.85
existsFunction · 0.85
cloneFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…