* @param {string} alias filesystem path or skeleton url * @param {string} rootPath * @returns {Promise }
(alias, rootPath)
| 128 | * @returns {Promise<boolean>} |
| 129 | */ |
| 130 | async 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 | |
| 168 | exports.initSkeleton = initSkeleton; |
| 169 | exports.cleanURL = cleanURL; |
no test coverage detected
searching dependent graphs…