( options: Options, )
| 271 | } |
| 272 | |
| 273 | export 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 | |
| 305 | export async function init(options: Options): Promise<boolean> { |
| 306 | let generatedPackageJson = false; |
no outgoing calls
no test coverage detected
searching dependent graphs…