WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit f445ff7

Browse files
authored
fix: WP-2469 apply cli magic to unpublished templates (#799)
1 parent e19d9af commit f445ff7

File tree

68 files changed

+5728
-2055
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+5728
-2055
lines changed

astro-blog-starter-template/worker-configuration.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable */
22
// Generated by Wrangler by running `wrangler types` (hash: 187132f48ddf0f604882ba8213fe386f)
3-
// Runtime types generated with [email protected] 2025-04-01 nodejs_compat
3+
// Runtime types generated with [email protected] 2025-10-08 nodejs_compat
44
declare namespace Cloudflare {
55
interface Env {
66
ASSETS: Fetcher;
@@ -374,6 +374,8 @@ declare abstract class Navigator {
374374
sendBeacon(url: string, body?: (ReadableStream | string | (ArrayBuffer | ArrayBufferView) | Blob | FormData | URLSearchParams | URLSearchParams)): boolean;
375375
readonly userAgent: string;
376376
readonly hardwareConcurrency: number;
377+
readonly language: string;
378+
readonly languages: string[];
377379
}
378380
/**
379381
* The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
@@ -2217,6 +2219,7 @@ declare class URLPattern {
22172219
get pathname(): string;
22182220
get search(): string;
22192221
get hash(): string;
2222+
get hasRegExpGroups(): boolean;
22202223
test(input?: (string | URLPatternInit), baseURL?: string): boolean;
22212224
exec(input?: (string | URLPatternInit), baseURL?: string): URLPatternResult | null;
22222225
}

astro-blog-starter-template/wrangler.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "astro-blog-starter-template",
3-
"compatibility_date": "2025-04-01",
3+
"compatibility_date": "2025-10-08",
44
"compatibility_flags": ["nodejs_compat"],
55
"main": "./dist/_worker.js/index.js",
66
"assets": {

chanfana-openapi-template/worker-configuration.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* eslint-disable */
22
// Generated by Wrangler by running `wrangler types` (hash: 751a7ef0204e37564547937fa13c0dba)
3-
// Runtime types generated with [email protected] 2025-04-01
3+
// Runtime types generated with [email protected] 2025-10-08
44
declare namespace Cloudflare {
55
interface Env {
66
DB: D1Database;
@@ -374,6 +374,8 @@ declare abstract class Navigator {
374374
sendBeacon(url: string, body?: (ReadableStream | string | (ArrayBuffer | ArrayBufferView) | Blob | FormData | URLSearchParams | URLSearchParams)): boolean;
375375
readonly userAgent: string;
376376
readonly hardwareConcurrency: number;
377+
readonly language: string;
378+
readonly languages: string[];
377379
}
378380
/**
379381
* The Workers runtime supports a subset of the Performance API, used to measure timing and performance,
@@ -2217,6 +2219,7 @@ declare class URLPattern {
22172219
get pathname(): string;
22182220
get search(): string;
22192221
get hash(): string;
2222+
get hasRegExpGroups(): boolean;
22202223
test(input?: (string | URLPatternInit), baseURL?: string): boolean;
22212224
exec(input?: (string | URLPatternInit), baseURL?: string): URLPatternResult | null;
22222225
}

chanfana-openapi-template/wrangler.jsonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"compatibility_date": "2025-04-01",
2+
"compatibility_date": "2025-10-08",
33
"main": "src/index.ts",
44
"name": "chanfana-openapi-template",
55
"upload_source_maps": true,

cli/src/deployLiveDemos.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "zx/globals";
22
import subprocess from "node:child_process";
3-
import { getTemplates } from "./util";
3+
import { getPublishedTemplates } from "./util";
44

55
export type DeployLiveDemosConfig = {
66
templateDirectory: string;
@@ -29,7 +29,7 @@ function runCommand(command: string, cwd: string) {
2929
export default async function deployLiveDemos({
3030
templateDirectory,
3131
}: DeployLiveDemosConfig) {
32-
const templates = getTemplates(templateDirectory);
32+
const templates = getPublishedTemplates(templateDirectory);
3333
await Promise.all(
3434
templates.map(({ path: templatePath }) => {
3535
runCommand("npm install", templatePath);

cli/src/lint.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import fs from "node:fs";
22
import path from "node:path";
33
import {
4-
getTemplates,
4+
getAllTemplates,
55
readJson,
66
readJsonC,
77
readToml,
@@ -19,7 +19,7 @@ export type LintConfig = {
1919
const integrationsPlatCategories = ["starter", "storage", "ai"];
2020

2121
export function lint(config: LintConfig) {
22-
const templates = getTemplates(config.templateDirectory);
22+
const templates = getAllTemplates(config.templateDirectory);
2323
const results = templates.flatMap((template) =>
2424
lintTemplate(template, config.fix),
2525
);
@@ -42,7 +42,7 @@ const CHECKS = {
4242
"package.json": [lintPackageJson],
4343
".gitignore": [lintGitIgnore],
4444
};
45-
const TARGET_COMPATIBILITY_DATE = "2025-04-01";
45+
const TARGET_COMPATIBILITY_DATE = "2025-10-08";
4646
const DASH_CONTENT_START_MARKER = "<!-- dash-content-start -->";
4747
const DASH_CONTENT_END_MARKER = "<!-- dash-content-end -->";
4848

@@ -290,6 +290,7 @@ function lintPackageJson(
290290
icon_urls?: string[];
291291
preview_image_url?: string;
292292
preview_icon_url?: string;
293+
publish?: boolean;
293294
};
294295
};
295296

@@ -323,13 +324,16 @@ function lintPackageJson(
323324
);
324325
});
325326
}
326-
// Ensure a preview image URL is set
327-
if (!pkg.cloudflare.preview_image_url) {
328-
problems.push('"cloudflare.preview_image_url" must be defined');
329-
}
330-
// Ensure preview_icon_url is set
331-
if (!pkg.cloudflare.preview_icon_url) {
332-
problems.push('"cloudflare.preview_icon_url" must be defined');
327+
// Only require preview URLs for published templates
328+
if (pkg.cloudflare.publish === true) {
329+
// Ensure a preview image URL is set
330+
if (!pkg.cloudflare.preview_image_url) {
331+
problems.push('"cloudflare.preview_image_url" must be defined');
332+
}
333+
// Ensure preview_icon_url is set
334+
if (!pkg.cloudflare.preview_icon_url) {
335+
problems.push('"cloudflare.preview_icon_url" must be defined');
336+
}
333337
}
334338
}
335339

cli/src/npm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { z } from "zod";
33
import { createHash } from "node:crypto";
44
import path from "node:path";
55
import MarkdownError from "./MarkdownError";
6-
import { getTemplates } from "./util";
6+
import { getAllTemplates } from "./util";
77

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

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

6363
const errors: string[] = [];
6464
for (const { name } of templates) {

cli/src/upload.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {
22
collectTemplateFiles,
33
fetchWithRetries,
4-
getTemplates,
4+
getPublishedTemplates,
55
handleCloudflareResponse,
66
SeedRepo,
77
} from "./util";
@@ -20,7 +20,7 @@ export type UploadConfig = {
2020
};
2121

2222
export async function upload(config: UploadConfig) {
23-
const templates = getTemplates(config.templateDirectory);
23+
const templates = getPublishedTemplates(config.templateDirectory);
2424
const formData = templates.reduce((body, template) => {
2525
const files = collectTemplateFiles(template.path, !!config.seedRepo);
2626
console.info(`Uploading ${template.path}:`);

cli/src/util.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ export const ALLOWED_DIRECTORIES = [
4141
"test-results",
4242
];
4343

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

50-
if (!isDashTemplate(packageJsonPath)) {
50+
if (!fs.existsSync(packageJsonPath)) {
5151
return [];
5252
}
5353

@@ -81,20 +81,33 @@ export function getTemplates(templateDirectory: string): Template[] {
8181
.filter((name) =>
8282
fs.statSync(path.join(templateDirectory, name)).isDirectory(),
8383
)
84+
.filter((name) => name.endsWith(TEMPLATE_DIRECTORY_SUFFIX))
8485
.filter((name) => {
8586
const packageJsonPath = path.join(
8687
templateDirectory,
8788
name,
8889
"package.json",
8990
);
90-
return isDashTemplate(packageJsonPath);
91+
return fs.existsSync(packageJsonPath);
9192
})
9293
.map((name) => ({
9394
name,
9495
path: path.join(templateDirectory, name),
9596
}));
9697
}
9798

99+
export function getPublishedTemplates(templateDirectory: string): Template[] {
100+
return getAllTemplates(templateDirectory).filter((template) => {
101+
const packageJsonPath = path.join(template.path, "package.json");
102+
return isDashTemplate(packageJsonPath);
103+
});
104+
}
105+
106+
// Deprecated: Use getAllTemplates() or getPublishedTemplates() instead
107+
export function getTemplates(templateDirectory: string): Template[] {
108+
return getPublishedTemplates(templateDirectory);
109+
}
110+
98111
export function collectTemplateFiles(
99112
templatePath: string,
100113
onlySeedRepoFiles?: boolean,

cli/src/validateD2CButtons.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import fs from "node:fs";
22
import path from "node:path";
3-
import { getTemplates } from "./util";
3+
import { getAllTemplates } from "./util";
44
import MarkdownError from "./MarkdownError";
55

66
export type ValidateD2CButtonsConfig = {
@@ -10,7 +10,7 @@ export type ValidateD2CButtonsConfig = {
1010
export async function validateD2CButtons({
1111
templateDirectory,
1212
}: ValidateD2CButtonsConfig) {
13-
const templates = getTemplates(templateDirectory);
13+
const templates = getAllTemplates(templateDirectory);
1414
const successes: string[] = [];
1515
const errors: string[] = [];
1616
let numBadStatuses = 0;

0 commit comments

Comments
 (0)