Skip to content

Commit

Permalink
Only warnThemePackage on not restart(astrolicious#75)
Browse files Browse the repository at this point in the history
and add notice to use `'private': true` suppress these warnings
  • Loading branch information
Yuhanawa committed Dec 7, 2024
1 parent 86dfc0e commit 6c82311
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 34 deletions.
4 changes: 2 additions & 2 deletions package/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export default function <ThemeName extends string, Schema extends z.ZodTypeAny>(
if (existsSync(seedEntrypoint)) extendDb({ seedEntrypoint });
},
"astro:config:setup": (params) => {
const { config, logger, injectRoute, addMiddleware } = params;
const { config, logger, isRestart, injectRoute, addMiddleware } = params;

const projectRoot = resolveDirectory("./", config.root);

Expand Down Expand Up @@ -169,7 +169,7 @@ export default function <ThemeName extends string, Schema extends z.ZodTypeAny>(
}
`;

if (logLevel) {
if (logLevel && !isRestart) {
// Warn about issues with theme's `package.json`
warnThemePackage(themePackage, logger);
}
Expand Down
74 changes: 42 additions & 32 deletions package/src/utils/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,47 +40,57 @@ export function warnThemePackage(pkg: PackageJSON, logger: HookParameters<"astro

// If package is not private, warn theme author about issues with package
if (!isPrivate) {
let hasIssues = false;
const warn = (condition: boolean, message: string) => {
if (condition) {
hasIssues = true;
if (message.includes("\\n")) for (const m of `${message}\n`.split("\\n")) logger.warn(m);
else logger.warn(`${message}\n`);
}
};

// Warn theme author if `astro-integration` keyword does not exist inside 'package.json'
if (!keywords.includes("astro-integration")) {
logger.warn(
`Add the 'astro-integration' keyword to your theme's 'package.json'!\tAstro uses this value to support the command 'astro add ${name}'\n\n\t"keywords": [ "astro-integration" ],\n`,
);
}
warn(
!keywords.includes("astro-integration"),
`Add the 'astro-integration' keyword to your theme's 'package.json'!\\nAstro uses this value to support the command 'astro add ${name}'\n\n\t"keywords": [ "astro-integration" ]`,
);

// Warn theme author if no 'description' property exists inside 'package.json'
if (!description) {
logger.warn(
`Add a 'description' to your theme's 'package.json'!\tAstro uses this value to populate the integrations page https://astro.build/integrations/\n\n\t"description": "My awesome Astro theme!",\n`,
);
}
warn(
!description,
`Add a 'description' to your theme's 'package.json'!\\nAstro uses this value to populate the integrations page https://astro.build/integrations/\n\n\t"description": "My awesome Astro theme!"`,
);


// Warn theme author if no 'homepage' property exists inside 'package.json'
if (!homepage) {
logger.warn(
`Add a 'homepage' to your theme's 'package.json'!\tAstro uses this value to populate the integrations page https://astro.build/integrations/\n\n\t"homepage": "https://github.com/UserName/theme-playground",\n`,
);
}
warn(
!homepage,
`Add a 'homepage' to your theme's 'package.json'!\\nAstro uses this value to populate the integrations page https://astro.build/integrations/\n\n\t"homepage": "https://github.com/UserName/theme-playground"`,
);


// Warn theme author if no 'repository' property exists inside 'package.json'
if (!repository) {
logger.warn(
`Add a 'repository' to your theme's 'package.json'!\tAstro uses this value to populate the integrations page https://astro.build/integrations/\n\n\t"repository": ${JSON.stringify(
{
type: "git",
url: `https://github.com/UserName/${name}`,
directory: "package",
},
null,
4,
).replace(/\n/g, "\n\t")},\n`,
);
}
warn(
!repository,
`Add a 'repository' to your theme's 'package.json'!\\nAstro uses this value to populate the integrations page https://astro.build/integrations/\n\n\t"repository": ${JSON.stringify(
{
type: "git",
url: `https://github.com/UserName/${name}`,
directory: "package",
}, null, 4,
).replaceAll("\n", "\n\t")}`,
);


// Warn theme author if package does not have a README
if (!existsSync(resolveFilepath(pkg.path, "README.md", false))) {
logger.warn(
`Add a 'README.md' to the root of your theme's package!\tNPM uses this file to populate the package page https://www.npmjs.com/package/${name}\n`,
);
warn(
!existsSync(resolveFilepath(pkg.path, "README.md", false)),
`Add a 'README.md' to the root of your theme's package!\\nNPM uses this file to populate the package page https://www.npmjs.com/package/${name} `,
);

if (hasIssues) {
logger.warn("These warnings in order to notice for people who are preparing to submit theme to the Astro integration page, ");
logger.warn("If you don't want to submit your theme, you can set `'private': true` inside the `package.json` to suppress these warnings.");
}
}
}

0 comments on commit 6c82311

Please sign in to comment.