MCPcopy
hub / github.com/google/gts / installDefaultTemplate

Function installDefaultTemplate

src/init.ts:273–303  ·  view source on GitHub ↗
(
  options: Options,
)

Source from the content-addressed store, hash-verified

271}
272
273export async function installDefaultTemplate(
274 options: Options,
275): Promise<boolean> {
276 const cwd = process.cwd();
277 const sourceDirName = path.join(__dirname, '../template');
278 const targetDirName = path.join(cwd, 'src');
279
280 try {
281 fs.mkdirSync(targetDirName);
282 } catch (e) {
283 const err = e as Error & {code?: string};
284 if (err.code !== 'EEXIST') {
285 throw err;
286 }
287 // Else, continue and populate files into the existing directory.
288 }
289
290 // Only install the template if no ts files exist in target directory.
291 const files = fs.readdirSync(targetDirName);
292 const tsFiles = files.filter(file => file.toLowerCase().endsWith('.ts'));
293 if (tsFiles.length !== 0) {
294 options.logger.log(
295 'Target src directory already has ts files. ' +
296 'Template files not installed.',
297 );
298 return false;
299 }
300 await ncpp(sourceDirName, targetDirName);
301 options.logger.log('Default template installed.');
302 return true;
303}
304
305export async function init(options: Options): Promise<boolean> {
306 let generatedPackageJson = false;

Callers 1

initFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…