Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: WP-2469 apply cli magic to unpublished templates
  • Loading branch information
deloreyj committed Oct 9, 2025
commit 0c0fcbebe0fd42a961fe7bbff96427292ab250dd
6 changes: 4 additions & 2 deletions astro-blog-starter-template/wrangler.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
{
"name": "astro-blog-starter-template",
"compatibility_date": "2025-04-01",
"compatibility_flags": ["nodejs_compat"],
"compatibility_date": "2025-10-08",
"compatibility_flags": [
"nodejs_compat"
],
"main": "./dist/_worker.js/index.js",
"assets": {
"directory": "./dist",
Expand Down
2 changes: 1 addition & 1 deletion chanfana-openapi-template/wrangler.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"compatibility_date": "2025-04-01",
"compatibility_date": "2025-10-08",
"main": "src/index.ts",
"name": "chanfana-openapi-template",
"upload_source_maps": true,
Expand Down
4 changes: 2 additions & 2 deletions cli/src/deployLiveDemos.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import "zx/globals";
import subprocess from "node:child_process";
import { getTemplates } from "./util";
import { getPublishedTemplates } from "./util";

export type DeployLiveDemosConfig = {
templateDirectory: string;
Expand Down Expand Up @@ -29,7 +29,7 @@ function runCommand(command: string, cwd: string) {
export default async function deployLiveDemos({
templateDirectory,
}: DeployLiveDemosConfig) {
const templates = getTemplates(templateDirectory);
const templates = getPublishedTemplates(templateDirectory);
await Promise.all(
templates.map(({ path: templatePath }) => {
runCommand("npm install", templatePath);
Expand Down
24 changes: 14 additions & 10 deletions cli/src/lint.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import fs from "node:fs";
import path from "node:path";
import {
getTemplates,
getAllTemplates,
readJson,
readJsonC,
readToml,
Expand All @@ -19,7 +19,7 @@ export type LintConfig = {
const integrationsPlatCategories = ["starter", "storage", "ai"];

export function lint(config: LintConfig) {
const templates = getTemplates(config.templateDirectory);
const templates = getAllTemplates(config.templateDirectory);
const results = templates.flatMap((template) =>
lintTemplate(template, config.fix),
);
Expand All @@ -42,7 +42,7 @@ const CHECKS = {
"package.json": [lintPackageJson],
".gitignore": [lintGitIgnore],
};
const TARGET_COMPATIBILITY_DATE = "2025-04-01";
const TARGET_COMPATIBILITY_DATE = "2025-10-08";
const DASH_CONTENT_START_MARKER = "<!-- dash-content-start -->";
const DASH_CONTENT_END_MARKER = "<!-- dash-content-end -->";

Expand Down Expand Up @@ -290,6 +290,7 @@ function lintPackageJson(
icon_urls?: string[];
preview_image_url?: string;
preview_icon_url?: string;
publish?: boolean;
};
};

Expand Down Expand Up @@ -323,13 +324,16 @@ function lintPackageJson(
);
});
}
// Ensure a preview image URL is set
if (!pkg.cloudflare.preview_image_url) {
problems.push('"cloudflare.preview_image_url" must be defined');
}
// Ensure preview_icon_url is set
if (!pkg.cloudflare.preview_icon_url) {
problems.push('"cloudflare.preview_icon_url" must be defined');
// Only require preview URLs for published templates
if (pkg.cloudflare.publish === true) {
// Ensure a preview image URL is set
if (!pkg.cloudflare.preview_image_url) {
problems.push('"cloudflare.preview_image_url" must be defined');
}
// Ensure preview_icon_url is set
if (!pkg.cloudflare.preview_icon_url) {
problems.push('"cloudflare.preview_icon_url" must be defined');
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions cli/src/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { z } from "zod";
import { createHash } from "node:crypto";
import path from "node:path";
import MarkdownError from "./MarkdownError";
import { getTemplates } from "./util";
import { getAllTemplates } from "./util";

export type NpmLockfilesConfig = {
templateDirectory: string;
Expand All @@ -19,7 +19,7 @@ export async function generateNpmLockfiles({
}: NpmLockfilesConfig): Promise<void> {
const repoRoot = path.resolve(templateDirectory);
const config = await new TemplatesConfig(repoRoot).load();
const templates = getTemplates(templateDirectory);
const templates = getAllTemplates(templateDirectory);

for (const { name } of templates) {
echo(chalk.blue(`Updating template: ${chalk.grey(name)}`));
Expand Down Expand Up @@ -58,7 +58,7 @@ export async function lintNpmLockfiles({
}: NpmLockfilesConfig): Promise<void> {
const repoRoot = path.resolve(templateDirectory);
const config = await new TemplatesConfig(repoRoot).load();
const templates = getTemplates(templateDirectory);
const templates = getAllTemplates(templateDirectory);

const errors: string[] = [];
for (const { name } of templates) {
Expand Down
4 changes: 2 additions & 2 deletions cli/src/upload.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
collectTemplateFiles,
fetchWithRetries,
getTemplates,
getPublishedTemplates,
handleCloudflareResponse,
SeedRepo,
} from "./util";
Expand All @@ -20,7 +20,7 @@ export type UploadConfig = {
};

export async function upload(config: UploadConfig) {
const templates = getTemplates(config.templateDirectory);
const templates = getPublishedTemplates(config.templateDirectory);
const formData = templates.reduce((body, template) => {
const files = collectTemplateFiles(template.path, !!config.seedRepo);
console.info(`Uploading ${template.path}:`);
Expand Down
19 changes: 16 additions & 3 deletions cli/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ export const ALLOWED_DIRECTORIES = [
"test-results",
];

export function getTemplates(templateDirectory: string): Template[] {
export function getAllTemplates(templateDirectory: string): Template[] {
if (path.basename(templateDirectory).endsWith(TEMPLATE_DIRECTORY_SUFFIX)) {
// If the specified path is a template directory, just return that.
const templatePath = templateDirectory;
const packageJsonPath = path.join(templatePath, "package.json");

if (!isDashTemplate(packageJsonPath)) {
if (!fs.existsSync(packageJsonPath)) {
return [];
}

Expand Down Expand Up @@ -81,20 +81,33 @@ export function getTemplates(templateDirectory: string): Template[] {
.filter((name) =>
fs.statSync(path.join(templateDirectory, name)).isDirectory(),
)
.filter((name) => name.endsWith(TEMPLATE_DIRECTORY_SUFFIX))
.filter((name) => {
const packageJsonPath = path.join(
templateDirectory,
name,
"package.json",
);
return isDashTemplate(packageJsonPath);
return fs.existsSync(packageJsonPath);
})
.map((name) => ({
name,
path: path.join(templateDirectory, name),
}));
}

export function getPublishedTemplates(templateDirectory: string): Template[] {
return getAllTemplates(templateDirectory).filter((template) => {
const packageJsonPath = path.join(template.path, "package.json");
return isDashTemplate(packageJsonPath);
});
}

// Deprecated: Use getAllTemplates() or getPublishedTemplates() instead
export function getTemplates(templateDirectory: string): Template[] {
return getPublishedTemplates(templateDirectory);
}

export function collectTemplateFiles(
templatePath: string,
onlySeedRepoFiles?: boolean,
Expand Down
4 changes: 2 additions & 2 deletions cli/src/validateD2CButtons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "node:fs";
import path from "node:path";
import { getTemplates } from "./util";
import { getAllTemplates } from "./util";
import MarkdownError from "./MarkdownError";

export type ValidateD2CButtonsConfig = {
Expand All @@ -10,7 +10,7 @@ export type ValidateD2CButtonsConfig = {
export async function validateD2CButtons({
templateDirectory,
}: ValidateD2CButtonsConfig) {
const templates = getTemplates(templateDirectory);
const templates = getAllTemplates(templateDirectory);
const successes: string[] = [];
const errors: string[] = [];
let numBadStatuses = 0;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/validateLiveDemoLinks.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTemplates } from "./util";
import { getPublishedTemplates } from "./util";
import MarkdownError from "./MarkdownError";

export type ValidateLiveDemoLinksConfig = {
Expand All @@ -8,7 +8,7 @@ export type ValidateLiveDemoLinksConfig = {
export async function validateLiveDemoLinks({
templateDirectory,
}: ValidateLiveDemoLinksConfig) {
const templates = getTemplates(templateDirectory);
const templates = getPublishedTemplates(templateDirectory);
const successes: string[] = [];
const errors: string[] = [];
let numBadStatuses = 0;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/validateVersionPrivatePackageJson.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fs from "node:fs";
import path from "node:path";
import { getTemplates } from "./util";
import { getAllTemplates } from "./util";
import MarkdownError from "./MarkdownError";

export type ValidateVersionPrivatePackageJsonConfig = {
Expand All @@ -10,7 +10,7 @@ export type ValidateVersionPrivatePackageJsonConfig = {
export async function validateVersionPrivatePackageJson({
templateDirectory,
}: ValidateVersionPrivatePackageJsonConfig) {
const templates = getTemplates(templateDirectory);
const templates = getAllTemplates(templateDirectory);
const successes: string[] = [];
const errors: string[] = [];
let numBadStatuses = 0;
Expand Down
Loading
Loading