@thorprovider/create-thor-app 3.1.0 → 3.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +60 -13
- package/package.json +1 -1
- package/templates/default/ai-validator.json +131 -0
package/dist/index.js
CHANGED
|
@@ -65,11 +65,11 @@ function createCopyFilter(sourceRoot) {
|
|
|
65
65
|
// src/create-app.ts
|
|
66
66
|
import {
|
|
67
67
|
cpSync,
|
|
68
|
-
existsSync as
|
|
68
|
+
existsSync as existsSync9,
|
|
69
69
|
mkdirSync as mkdirSync3,
|
|
70
70
|
rmSync
|
|
71
71
|
} from "fs";
|
|
72
|
-
import { join as
|
|
72
|
+
import { join as join9, relative as relative2 } from "path";
|
|
73
73
|
|
|
74
74
|
// src/helpers/logger.ts
|
|
75
75
|
var c = {
|
|
@@ -1231,18 +1231,47 @@ async function linkVercel(name, targetDir, githubRepo) {
|
|
|
1231
1231
|
}
|
|
1232
1232
|
}
|
|
1233
1233
|
|
|
1234
|
+
// src/helpers/ai-validator.ts
|
|
1235
|
+
import { existsSync as existsSync8, readFileSync as readFileSync6, writeFileSync as writeFileSync6 } from "fs";
|
|
1236
|
+
import { join as join8 } from "path";
|
|
1237
|
+
function verifyValidatorConfig(targetDir) {
|
|
1238
|
+
const validatorPath = join8(targetDir, "ai-validator.json");
|
|
1239
|
+
if (!existsSync8(validatorPath)) {
|
|
1240
|
+
log(` \u26A0\uFE0F ai-validator.json not found at ${validatorPath}`, c.yellow);
|
|
1241
|
+
return false;
|
|
1242
|
+
}
|
|
1243
|
+
try {
|
|
1244
|
+
const content = readFileSync6(validatorPath, "utf-8");
|
|
1245
|
+
const config = JSON.parse(content);
|
|
1246
|
+
if (!config.version || !config.maxRetries || !config.retryModelId) {
|
|
1247
|
+
log(" \u26A0\uFE0F ai-validator.json is missing required fields", c.yellow);
|
|
1248
|
+
return false;
|
|
1249
|
+
}
|
|
1250
|
+
if (!Array.isArray(config.architecturalRules)) {
|
|
1251
|
+
log(" \u26A0\uFE0F ai-validator.json architecturalRules must be an array", c.yellow);
|
|
1252
|
+
return false;
|
|
1253
|
+
}
|
|
1254
|
+
log(" \u2713 ai-validator.json verified", c.green);
|
|
1255
|
+
return true;
|
|
1256
|
+
} catch (err) {
|
|
1257
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
1258
|
+
log(` \u26A0\uFE0F Failed to parse ai-validator.json: ${message}`, c.yellow);
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1234
1263
|
// src/create-app.ts
|
|
1235
1264
|
function bundleRegionsScript(monorepoRoot, targetDir) {
|
|
1236
1265
|
if (!monorepoRoot) return;
|
|
1237
|
-
const regionsScriptSrc =
|
|
1266
|
+
const regionsScriptSrc = join9(
|
|
1238
1267
|
monorepoRoot,
|
|
1239
1268
|
"scripts",
|
|
1240
1269
|
"generate-regions-config.ts"
|
|
1241
1270
|
);
|
|
1242
|
-
if (
|
|
1243
|
-
const scriptsDir =
|
|
1271
|
+
if (existsSync9(regionsScriptSrc)) {
|
|
1272
|
+
const scriptsDir = join9(targetDir, "scripts");
|
|
1244
1273
|
mkdirSync3(scriptsDir, { recursive: true });
|
|
1245
|
-
cpSync(regionsScriptSrc,
|
|
1274
|
+
cpSync(regionsScriptSrc, join9(scriptsDir, "generate-regions-config.ts"));
|
|
1246
1275
|
log(" \u2713 Bundled generate-regions-config.ts", c.green);
|
|
1247
1276
|
}
|
|
1248
1277
|
}
|
|
@@ -1257,6 +1286,7 @@ async function createApp(opts) {
|
|
|
1257
1286
|
skipRemote,
|
|
1258
1287
|
skipVercel,
|
|
1259
1288
|
noContext,
|
|
1289
|
+
noValidator,
|
|
1260
1290
|
commerceProvider,
|
|
1261
1291
|
commerceApiUrl,
|
|
1262
1292
|
commerceApiKey,
|
|
@@ -1268,7 +1298,7 @@ async function createApp(opts) {
|
|
|
1268
1298
|
loadRootEnv(monorepoRoot);
|
|
1269
1299
|
}
|
|
1270
1300
|
const templatePath = resolveTemplatePath(mode, monorepoRoot);
|
|
1271
|
-
if (!
|
|
1301
|
+
if (!existsSync9(templatePath)) {
|
|
1272
1302
|
log(`
|
|
1273
1303
|
\u274C Template not found: ${templatePath}`, c.red);
|
|
1274
1304
|
if (mode === "standalone") {
|
|
@@ -1285,7 +1315,7 @@ async function createApp(opts) {
|
|
|
1285
1315
|
log(` Target : ${c.cyan}${outputDir}${c.reset}`);
|
|
1286
1316
|
log(` Package : ${c.cyan}@thorprovider/${name}${c.reset}
|
|
1287
1317
|
`);
|
|
1288
|
-
if (
|
|
1318
|
+
if (existsSync9(outputDir)) {
|
|
1289
1319
|
log(`\u274C Directory already exists: ${outputDir}`, c.red);
|
|
1290
1320
|
log(
|
|
1291
1321
|
" Choose a different name or delete the existing directory.",
|
|
@@ -1316,8 +1346,8 @@ async function createApp(opts) {
|
|
|
1316
1346
|
log(" \u2713 Files copied", c.green);
|
|
1317
1347
|
log("\u{1F9F9} Removing build artifacts...", c.cyan);
|
|
1318
1348
|
for (const p of REMOVE_AFTER_COPY) {
|
|
1319
|
-
const fullPath =
|
|
1320
|
-
if (
|
|
1349
|
+
const fullPath = join9(outputDir, p);
|
|
1350
|
+
if (existsSync9(fullPath)) {
|
|
1321
1351
|
rmSync(fullPath, { recursive: true, force: true });
|
|
1322
1352
|
log(` \u2713 Removed ${p}`, c.gray);
|
|
1323
1353
|
}
|
|
@@ -1347,10 +1377,26 @@ async function createApp(opts) {
|
|
|
1347
1377
|
}
|
|
1348
1378
|
if (!noContext) {
|
|
1349
1379
|
log("\u{1F4C1} Generating .agents/ directory...", c.cyan);
|
|
1350
|
-
const contextSourceDir = mode === "monorepo" && monorepoRoot ?
|
|
1380
|
+
const contextSourceDir = mode === "monorepo" && monorepoRoot ? join9(monorepoRoot, "packages", "core") : outputDir;
|
|
1351
1381
|
generateAgentsDir(name, outputDir, contextSourceDir);
|
|
1352
1382
|
log(" \u2713 .agents/ generated (AGENTS.md + context/ + skills/)", c.green);
|
|
1353
1383
|
}
|
|
1384
|
+
if (!noValidator) {
|
|
1385
|
+
log("\u2705 Verifying ai-validator.json (V0 Stop Hooks)...", c.cyan);
|
|
1386
|
+
const validatorOk = verifyValidatorConfig(outputDir);
|
|
1387
|
+
if (!validatorOk) {
|
|
1388
|
+
log(
|
|
1389
|
+
" \u26A0\uFE0F ai-validator.json not found or invalid. V0 Stop Hooks validation will be skipped.",
|
|
1390
|
+
c.yellow
|
|
1391
|
+
);
|
|
1392
|
+
log(
|
|
1393
|
+
" To enable validation, ensure ai-validator.json exists in the project root.",
|
|
1394
|
+
c.yellow
|
|
1395
|
+
);
|
|
1396
|
+
}
|
|
1397
|
+
} else {
|
|
1398
|
+
log("\u23ED\uFE0F Skipping ai-validator.json (--no-validator)", c.gray);
|
|
1399
|
+
}
|
|
1354
1400
|
if (!skipInstall) {
|
|
1355
1401
|
installDependencies(outputDir);
|
|
1356
1402
|
}
|
|
@@ -1446,7 +1492,7 @@ ${step++}. Configure your backend:`, c.cyan);
|
|
|
1446
1492
|
const vis = process.env.GITHUB_REPO_VISIBILITY === "public" ? "--public" : "--private";
|
|
1447
1493
|
const org = process.env.GITHUB_ORG;
|
|
1448
1494
|
const repoName = org ? `${org}/${name}` : name;
|
|
1449
|
-
const githubHint = monorepoRoot ? `once GITHUB_TOKEN is in ${relative2(monorepoRoot,
|
|
1495
|
+
const githubHint = monorepoRoot ? `once GITHUB_TOKEN is in ${relative2(monorepoRoot, join9(monorepoRoot, ".env"))}` : "once GITHUB_TOKEN is set";
|
|
1450
1496
|
log(
|
|
1451
1497
|
`
|
|
1452
1498
|
${step++}. Push to GitHub (${githubHint}):`,
|
|
@@ -1515,7 +1561,7 @@ if (nodeMajor < NODE_MIN_MAJOR || nodeMajor === NODE_MIN_MAJOR && nodeMinor < NO
|
|
|
1515
1561
|
);
|
|
1516
1562
|
process.exit(1);
|
|
1517
1563
|
}
|
|
1518
|
-
program.name("create-thor-app").description("Create a new Thor Commerce application").argument("[name]", "Project name (kebab-case)").option("--name <name>", "Project name (alternative to positional arg)").option("-o, --output <dir>", "Output directory (default: ./<name>)").option("--skip-git", "Skip git init").option("--skip-install", "Skip yarn install").option("--skip-remote", "Skip GitHub remote repo creation").option("--skip-vercel", "Skip Vercel project linking").option("--no-context", "Skip .agents/ directory generation").option("--commerce-provider <provider>", "Commerce backend provider (e.g., medusa, shopify)").option("--commerce-api-url <url>", "Commerce backend API URL").option("--commerce-api-key <key>", "Commerce publishable API key").option("--preset <preset>", "Visual preset for site.config.ts (e.g., electro, minimal)").option("--site-url <url>", "Public site URL for site.config.ts").option("--generate-regions", "Run region generation from backend after install (requires --commerce-api-url and --commerce-api-key)").action(async (positionalName, opts) => {
|
|
1564
|
+
program.name("create-thor-app").description("Create a new Thor Commerce application").argument("[name]", "Project name (kebab-case)").option("--name <name>", "Project name (alternative to positional arg)").option("-o, --output <dir>", "Output directory (default: ./<name>)").option("--skip-git", "Skip git init").option("--skip-install", "Skip yarn install").option("--skip-remote", "Skip GitHub remote repo creation").option("--skip-vercel", "Skip Vercel project linking").option("--no-context", "Skip .agents/ directory generation").option("--no-validator", "Skip ai-validator.json injection (V0 Stop Hooks)").option("--commerce-provider <provider>", "Commerce backend provider (e.g., medusa, shopify)").option("--commerce-api-url <url>", "Commerce backend API URL").option("--commerce-api-key <key>", "Commerce publishable API key").option("--preset <preset>", "Visual preset for site.config.ts (e.g., electro, minimal)").option("--site-url <url>", "Public site URL for site.config.ts").option("--generate-regions", "Run region generation from backend after install (requires --commerce-api-url and --commerce-api-key)").action(async (positionalName, opts) => {
|
|
1519
1565
|
let rawName = positionalName || opts.name || "";
|
|
1520
1566
|
if (!rawName) {
|
|
1521
1567
|
rawName = await promptForName();
|
|
@@ -1544,6 +1590,7 @@ program.name("create-thor-app").description("Create a new Thor Commerce applicat
|
|
|
1544
1590
|
skipRemote: !!opts.skipRemote,
|
|
1545
1591
|
skipVercel: !!opts.skipVercel,
|
|
1546
1592
|
noContext: !!opts.noContext,
|
|
1593
|
+
noValidator: !!opts.noValidator,
|
|
1547
1594
|
commerceProvider: opts.commerceProvider,
|
|
1548
1595
|
commerceApiUrl: opts.commerceApiUrl,
|
|
1549
1596
|
commerceApiKey: opts.commerceApiKey,
|
package/package.json
CHANGED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": "1.0.0",
|
|
3
|
+
"description": "V0 Stop Hooks validation criteria for Thor Commerce projects",
|
|
4
|
+
"maxRetries": 2,
|
|
5
|
+
"retryModelId": "v0-1.5-sm",
|
|
6
|
+
"architecturalRules": [
|
|
7
|
+
{
|
|
8
|
+
"id": "no-console-in-api",
|
|
9
|
+
"filePattern": "app/api/**/*.ts",
|
|
10
|
+
"pattern": "console\\.",
|
|
11
|
+
"description": "Console statements not allowed in API routes (use logger instead)"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
"id": "no-console-in-lib",
|
|
15
|
+
"filePattern": "lib/**/*.ts",
|
|
16
|
+
"pattern": "console\\.",
|
|
17
|
+
"description": "Console statements not allowed in lib (use logger instead)"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"id": "logger-import-in-api",
|
|
21
|
+
"filePattern": "app/api/**/*.ts",
|
|
22
|
+
"pattern": "import.*logger.*from.*@/lib/logger",
|
|
23
|
+
"description": "API routes must import logger from @/lib/logger",
|
|
24
|
+
"required": false
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"id": "no-raw-sql",
|
|
28
|
+
"filePattern": "lib/**/*.ts",
|
|
29
|
+
"pattern": "sql`|sql\\(|raw\\(",
|
|
30
|
+
"description": "Raw SQL not allowed (use Drizzle ORM instead)"
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
"id": "no-moment-js",
|
|
34
|
+
"filePattern": "**/*.ts",
|
|
35
|
+
"pattern": "from\\s+['\"]moment['\"]|import.*moment",
|
|
36
|
+
"description": "moment.js not allowed (use native Date or date-fns)"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
"id": "no-manual-classname",
|
|
40
|
+
"filePattern": "components/**/*.tsx",
|
|
41
|
+
"pattern": "className=\\{`.*\\$\\{.*\\}`\\}|className=\\{.*\\+.*\\}",
|
|
42
|
+
"description": "Use cn() utility instead of manual string concatenation for classNames"
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
"id": "use-drizzle-orm",
|
|
46
|
+
"filePattern": "lib/db/**/*.ts",
|
|
47
|
+
"pattern": "query\\(|execute\\(|raw\\(",
|
|
48
|
+
"description": "Database operations must use Drizzle ORM (no raw queries)"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"id": "auth-ownership-check",
|
|
52
|
+
"filePattern": "app/api/**/*.ts",
|
|
53
|
+
"pattern": "getChatOwnership|getProjectOwnership|getUserId",
|
|
54
|
+
"description": "API routes accessing user data must verify ownership",
|
|
55
|
+
"required": false
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
"id": "no-hardcoded-secrets",
|
|
59
|
+
"filePattern": "**/*.ts",
|
|
60
|
+
"pattern": "AUTH_SECRET|V0_API_KEY|GITHUB_TOKEN|DATABASE_URL",
|
|
61
|
+
"description": "Secrets must not be hardcoded (use environment variables)"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"id": "use-server-actions",
|
|
65
|
+
"filePattern": "app/**/*.ts",
|
|
66
|
+
"pattern": "fetch\\(.*process\\.env\\.",
|
|
67
|
+
"description": "Server-side API calls should use server actions, not client-side fetch with env vars"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"id": "no-client-env-vars",
|
|
71
|
+
"filePattern": "components/**/*.tsx",
|
|
72
|
+
"pattern": "process\\.env\\.[A-Z_]*(?!NEXT_PUBLIC)",
|
|
73
|
+
"description": "Client components cannot access non-NEXT_PUBLIC env vars"
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
"id": "use-cn-utility",
|
|
77
|
+
"filePattern": "components/**/*.tsx",
|
|
78
|
+
"pattern": "className=\\{.*\\+.*\\}",
|
|
79
|
+
"description": "Use cn() utility for dynamic classNames instead of string concatenation"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
"id": "no-inline-styles",
|
|
83
|
+
"filePattern": "components/**/*.tsx",
|
|
84
|
+
"pattern": "style=\\{\\{",
|
|
85
|
+
"description": "Use Tailwind CSS classes instead of inline styles"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
"id": "proper-error-handling",
|
|
89
|
+
"filePattern": "app/api/**/*.ts",
|
|
90
|
+
"pattern": "catch\\s*\\(\\s*\\)",
|
|
91
|
+
"description": "Error handlers must capture and log errors (not empty catch blocks)"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
"id": "use-zod-validation",
|
|
95
|
+
"filePattern": "app/api/**/*.ts",
|
|
96
|
+
"pattern": "JSON\\.parse|typeof.*===.*string",
|
|
97
|
+
"description": "Use Zod for request validation instead of manual type checking"
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
"id": "no-any-type",
|
|
101
|
+
"filePattern": "**/*.ts",
|
|
102
|
+
"pattern": ":\\s*any(?![a-zA-Z])",
|
|
103
|
+
"description": "Avoid 'any' type (use proper TypeScript types)"
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
"id": "use-next-image",
|
|
107
|
+
"filePattern": "components/**/*.tsx",
|
|
108
|
+
"pattern": "<img\\s",
|
|
109
|
+
"description": "Use next/image Image component instead of <img> tag"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"id": "use-next-link",
|
|
113
|
+
"filePattern": "components/**/*.tsx",
|
|
114
|
+
"pattern": "<a\\s+href",
|
|
115
|
+
"description": "Use next/link Link component instead of <a> tag"
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
"id": "proper-async-await",
|
|
119
|
+
"filePattern": "app/api/**/*.ts",
|
|
120
|
+
"pattern": "\\.then\\(|Promise\\.all\\(",
|
|
121
|
+
"description": "Use async/await instead of .then() chains",
|
|
122
|
+
"required": false
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
"id": "no-var-declaration",
|
|
126
|
+
"filePattern": "**/*.ts",
|
|
127
|
+
"pattern": "\\bvar\\s+",
|
|
128
|
+
"description": "Use const/let instead of var"
|
|
129
|
+
}
|
|
130
|
+
]
|
|
131
|
+
}
|