async function readPackage(ctx) { const pkgFile = normalize(`${ctx.cwd}/package.json`); return readJson(ctx, pkgFile); }
const getTempName = async function() { const tempDir = tmpdir() const tempDirA = await pRealpath(tempDir) const id = String(Math.random()).replace('.', '') const tempName = normalize(`${tempDirA}/netlify-build-${id}`) return tempName }
/** * Get the absolute path * * @param templatePath The path to check. * @returns `true` if the path is a local path, otherwise `false`. */ function getAbsolutePath(templatePath) { return path.isAbsolute(templatePath) ? templatePath : path.normalize(path.join(process.cwd(), templatePath)) }
// The current directory is `buildDir`. Most constants are inside this `buildDir`. // Instead of passing absolute paths, we pass paths relative to `buildDir`, so // that logs are less verbose. const normalizePath = function(path, buildDir, key) { if (path === undefined || !CONSTANT_PATHS.includes(key)) { return path } const pathA = normalize(path) if (pathA.startsWith(buildDir) && pathA !== buildDir) { return relative(buildDir, pathA) } return pathA }
// The `repositoryRoot` flag can be overriden, but defaults to the fixture // directory const getRepositoryRootFlag = function({ fixtureName, copyRoot: { cwd } = {}, copyRootDir, repositoryRoot }) { if (fixtureName === '') { return {} } if (copyRootDir === undefined) { return { repositoryRoot: normalize(repositoryRoot) } } if (cwd) { return { cwd: normalize(copyRootDir) } } return { repositoryRoot: normalize(copyRootDir) } }
getTemplatePath(templatePath) { return path.isAbsolute(templatePath) ? templatePath : path.normalize(path.join(process.cwd(), templatePath)) }
getTemplatePath(templatePath) { return path.isAbsolute(templatePath) ? templatePath : path.normalize(path.join(process.cwd(), templatePath)) }