test: improve test coverage; multiple internal refactors ()

This commit is contained in:
Joshua Chen 2022-03-14 21:53:57 +08:00 committed by GitHub
parent 12a7305238
commit ad88f5cc87
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
78 changed files with 1613 additions and 1149 deletions
packages/create-docusaurus/src

View file

@ -37,10 +37,7 @@ async function findPackageManagerFromLockFile(): Promise<
SupportedPackageManager | undefined
> {
for (const packageManager of PackageManagersList) {
const lockFilePath = path.resolve(
process.cwd(),
SupportedPackageManagers[packageManager],
);
const lockFilePath = path.resolve(SupportedPackageManagers[packageManager]);
if (await fs.pathExists(lockFilePath)) {
return packageManager;
}
@ -152,7 +149,7 @@ async function copyTemplate(
template: string,
dest: string,
) {
await fs.copy(path.resolve(templatesDir, 'shared'), dest);
await fs.copy(path.join(templatesDir, 'shared'), dest);
// TypeScript variants will copy duplicate resources like CSS & config from
// base template
@ -211,7 +208,7 @@ export default async function init(
const templates = await readTemplates(templatesDir);
const hasTS = (templateName: string) =>
fs.pathExists(
path.resolve(templatesDir, `${templateName}${TypeScriptTemplateSuffix}`),
path.join(templatesDir, `${templateName}${TypeScriptTemplateSuffix}`),
);
let name = siteName;
@ -297,7 +294,7 @@ export default async function init(
name: 'templateDir',
validate: async (dir?: string) => {
if (dir) {
const fullDir = path.resolve(process.cwd(), dir);
const fullDir = path.resolve(dir);
if (await fs.pathExists(fullDir)) {
return true;
}
@ -351,8 +348,8 @@ export default async function init(
logger.error`Copying Docusaurus template name=${template} failed!`;
throw err;
}
} else if (await fs.pathExists(path.resolve(process.cwd(), template))) {
const templateDir = path.resolve(process.cwd(), template);
} else if (await fs.pathExists(path.resolve(template))) {
const templateDir = path.resolve(template);
try {
await fs.copy(templateDir, dest);
} catch (err) {