create-avalon 0.1.10 → 0.1.11
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/cli.js +108 -73
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1192,7 +1192,7 @@ async function collectProjectConfig(initialName) {
|
|
|
1192
1192
|
|
|
1193
1193
|
// src/scaffold.ts
|
|
1194
1194
|
import { mkdir, writeFile } from "node:fs/promises";
|
|
1195
|
-
import { join } from "node:path";
|
|
1195
|
+
import { join, dirname } from "node:path";
|
|
1196
1196
|
|
|
1197
1197
|
// src/types.ts
|
|
1198
1198
|
var INTEGRATION_PACKAGES = {
|
|
@@ -1254,6 +1254,8 @@ function generatePackageJson(config) {
|
|
|
1254
1254
|
devDependencies["tailwindcss"] = "latest";
|
|
1255
1255
|
devDependencies["@tailwindcss/vite"] = "latest";
|
|
1256
1256
|
dependencies["@shadcn/ui"] = "latest";
|
|
1257
|
+
dependencies["tailwind-merge"] = "^3.5.0";
|
|
1258
|
+
dependencies["clsx"] = "^2.1.1";
|
|
1257
1259
|
break;
|
|
1258
1260
|
}
|
|
1259
1261
|
const pkg = {
|
|
@@ -1282,7 +1284,10 @@ function generateTsConfig() {
|
|
|
1282
1284
|
esModuleInterop: true,
|
|
1283
1285
|
skipLibCheck: true,
|
|
1284
1286
|
allowArbitraryExtensions: true,
|
|
1287
|
+
allowImportingTsExtensions: true,
|
|
1288
|
+
noEmit: true,
|
|
1285
1289
|
jsx: "react-jsx",
|
|
1290
|
+
types: ["@useavalon/avalon/types"],
|
|
1286
1291
|
paths: {
|
|
1287
1292
|
"@shared/*": ["./app/shared/*"],
|
|
1288
1293
|
"@modules/*": ["./app/modules/*"]
|
|
@@ -1296,6 +1301,7 @@ function generateTsConfig() {
|
|
|
1296
1301
|
// src/templates/vite-config.ts
|
|
1297
1302
|
function generateViteConfig(config) {
|
|
1298
1303
|
const imports = [
|
|
1304
|
+
`import { resolve } from 'node:path';`,
|
|
1299
1305
|
`import { defineConfig, type UserConfig } from 'vite';`,
|
|
1300
1306
|
`import { avalon } from '@useavalon/avalon';`
|
|
1301
1307
|
];
|
|
@@ -1348,6 +1354,14 @@ function generateViteConfig(config) {
|
|
|
1348
1354
|
`),
|
|
1349
1355
|
` ],`,
|
|
1350
1356
|
``,
|
|
1357
|
+
` resolve: {`,
|
|
1358
|
+
` alias: {`,
|
|
1359
|
+
` '@shared': resolve(__dirname, 'app/shared'),`,
|
|
1360
|
+
` '@modules': resolve(__dirname, 'app/modules'),`,
|
|
1361
|
+
` '@': resolve(__dirname, 'app'),`,
|
|
1362
|
+
` },`,
|
|
1363
|
+
` },`,
|
|
1364
|
+
``,
|
|
1351
1365
|
` server: {`,
|
|
1352
1366
|
` port: 3000,`,
|
|
1353
1367
|
` },`,
|
|
@@ -1453,91 +1467,32 @@ export default async function HomePage() {
|
|
|
1453
1467
|
}
|
|
1454
1468
|
|
|
1455
1469
|
// src/templates/middleware.ts
|
|
1456
|
-
function generateSampleMiddleware(
|
|
1457
|
-
|
|
1458
|
-
case "h3":
|
|
1459
|
-
return generateH3Middleware();
|
|
1460
|
-
case "hono":
|
|
1461
|
-
return generateHonoMiddleware();
|
|
1462
|
-
case "elysia":
|
|
1463
|
-
return generateElysiaMiddleware();
|
|
1464
|
-
}
|
|
1465
|
-
}
|
|
1466
|
-
function generateH3Middleware() {
|
|
1467
|
-
return `import { defineHandler } from 'nitro/h3';
|
|
1470
|
+
function generateSampleMiddleware(_config) {
|
|
1471
|
+
return `import { defineHandler } from 'nitro';
|
|
1468
1472
|
|
|
1469
1473
|
export default defineHandler((event) => {
|
|
1470
1474
|
console.log(\`[\${new Date().toISOString()}] \${event.method} \${event.path}\`);
|
|
1471
1475
|
});
|
|
1472
1476
|
`;
|
|
1473
1477
|
}
|
|
1474
|
-
function generateHonoMiddleware() {
|
|
1475
|
-
return `import { Hono } from 'hono';
|
|
1476
|
-
|
|
1477
|
-
const app = new Hono();
|
|
1478
|
-
|
|
1479
|
-
app.use('*', async (c, next) => {
|
|
1480
|
-
console.log(\`[\${new Date().toISOString()}] \${c.req.method} \${c.req.path}\`);
|
|
1481
|
-
await next();
|
|
1482
|
-
});
|
|
1483
|
-
|
|
1484
|
-
export default app;
|
|
1485
|
-
`;
|
|
1486
|
-
}
|
|
1487
|
-
function generateElysiaMiddleware() {
|
|
1488
|
-
return `import { Elysia } from 'elysia';
|
|
1489
|
-
|
|
1490
|
-
export default new Elysia()
|
|
1491
|
-
.onBeforeHandle(({ request }) => {
|
|
1492
|
-
console.log(\`[\${new Date().toISOString()}] \${request.method} \${new URL(request.url).pathname}\`);
|
|
1493
|
-
});
|
|
1494
|
-
`;
|
|
1495
|
-
}
|
|
1496
1478
|
|
|
1497
1479
|
// src/templates/api-routes.ts
|
|
1498
|
-
function generateHelloRoute(
|
|
1499
|
-
|
|
1500
|
-
case "h3":
|
|
1501
|
-
return generateH3Route();
|
|
1502
|
-
case "hono":
|
|
1503
|
-
return generateHonoRoute();
|
|
1504
|
-
case "elysia":
|
|
1505
|
-
return generateElysiaRoute();
|
|
1506
|
-
}
|
|
1507
|
-
}
|
|
1508
|
-
function generateH3Route() {
|
|
1509
|
-
return `import { defineHandler } from 'nitro/h3';
|
|
1480
|
+
function generateHelloRoute(_config) {
|
|
1481
|
+
return `import { defineHandler } from 'nitro';
|
|
1510
1482
|
|
|
1511
1483
|
export default defineHandler(() => {
|
|
1512
|
-
return { message: 'Hello from Avalon!' };
|
|
1484
|
+
return Response.json({ message: 'Hello from Avalon!' });
|
|
1513
1485
|
});
|
|
1514
1486
|
`;
|
|
1515
1487
|
}
|
|
1516
|
-
function generateHonoRoute() {
|
|
1517
|
-
return `import { Hono } from 'hono';
|
|
1518
|
-
|
|
1519
|
-
const app = new Hono();
|
|
1520
|
-
|
|
1521
|
-
app.get('/', (c) => {
|
|
1522
|
-
return c.json({ message: 'Hello from Avalon!' });
|
|
1523
|
-
});
|
|
1524
|
-
|
|
1525
|
-
export default app;
|
|
1526
|
-
`;
|
|
1527
|
-
}
|
|
1528
|
-
function generateElysiaRoute() {
|
|
1529
|
-
return `import { Elysia } from 'elysia';
|
|
1530
|
-
|
|
1531
|
-
export default new Elysia()
|
|
1532
|
-
.get('/', () => ({ message: 'Hello from Avalon!' }));
|
|
1533
|
-
`;
|
|
1534
|
-
}
|
|
1535
1488
|
|
|
1536
1489
|
// src/templates/styling.ts
|
|
1537
1490
|
function generateStylingFiles(config) {
|
|
1538
1491
|
const files = new Map;
|
|
1539
1492
|
files.set("app/shared/styles/main.css", generateMainCss(config));
|
|
1540
|
-
|
|
1493
|
+
if (config.styling === "css-modules") {
|
|
1494
|
+
files.set("app/shared/styles/reset.css", generateResetCss());
|
|
1495
|
+
}
|
|
1541
1496
|
switch (config.styling) {
|
|
1542
1497
|
case "css-modules":
|
|
1543
1498
|
files.set("app/shared/styles/tokens.css", generateTokensCss());
|
|
@@ -1547,19 +1502,21 @@ function generateStylingFiles(config) {
|
|
|
1547
1502
|
break;
|
|
1548
1503
|
case "tailwind":
|
|
1549
1504
|
files.set("tailwind.config.js", generateTailwindConfig());
|
|
1550
|
-
files.set("app/shared/styles/global.css", generateTailwindGlobalCss());
|
|
1505
|
+
files.set("app/shared/styles/global.css", generateTailwindGlobalCss(config));
|
|
1551
1506
|
break;
|
|
1552
1507
|
case "shadcn":
|
|
1553
1508
|
files.set("tailwind.config.js", generateTailwindConfig());
|
|
1554
|
-
files.set("app/shared/styles/global.css", generateTailwindGlobalCss());
|
|
1509
|
+
files.set("app/shared/styles/global.css", generateTailwindGlobalCss(config));
|
|
1555
1510
|
files.set("components.json", generateShadcnComponentsJson(config));
|
|
1511
|
+
files.set("app/shared/utils/cn.ts", generateCnUtil());
|
|
1556
1512
|
break;
|
|
1557
1513
|
}
|
|
1558
1514
|
return files;
|
|
1559
1515
|
}
|
|
1560
1516
|
function generateMainCss(config) {
|
|
1561
|
-
const imports = [
|
|
1517
|
+
const imports = [];
|
|
1562
1518
|
if (config.styling === "css-modules") {
|
|
1519
|
+
imports.push(`@import './reset.css';`);
|
|
1563
1520
|
imports.push(`@import './tokens.css';`);
|
|
1564
1521
|
} else {
|
|
1565
1522
|
imports.push(`@import './global.css';`);
|
|
@@ -1667,8 +1624,47 @@ export default {
|
|
|
1667
1624
|
};
|
|
1668
1625
|
`;
|
|
1669
1626
|
}
|
|
1670
|
-
function generateTailwindGlobalCss() {
|
|
1671
|
-
|
|
1627
|
+
function generateTailwindGlobalCss(config) {
|
|
1628
|
+
const lines = [`@import "tailwindcss";`];
|
|
1629
|
+
if (config.styling === "shadcn") {
|
|
1630
|
+
lines.push("");
|
|
1631
|
+
lines.push(`@theme inline {
|
|
1632
|
+
--color-background: oklch(1 0 0);
|
|
1633
|
+
--color-foreground: oklch(0.145 0 0);
|
|
1634
|
+
--color-card: oklch(1 0 0);
|
|
1635
|
+
--color-card-foreground: oklch(0.145 0 0);
|
|
1636
|
+
--color-popover: oklch(1 0 0);
|
|
1637
|
+
--color-popover-foreground: oklch(0.145 0 0);
|
|
1638
|
+
--color-primary: oklch(0.205 0 0);
|
|
1639
|
+
--color-primary-foreground: oklch(0.985 0 0);
|
|
1640
|
+
--color-secondary: oklch(0.97 0 0);
|
|
1641
|
+
--color-secondary-foreground: oklch(0.205 0 0);
|
|
1642
|
+
--color-muted: oklch(0.97 0 0);
|
|
1643
|
+
--color-muted-foreground: oklch(0.556 0 0);
|
|
1644
|
+
--color-accent: oklch(0.97 0 0);
|
|
1645
|
+
--color-accent-foreground: oklch(0.205 0 0);
|
|
1646
|
+
--color-destructive: oklch(0.577 0.245 27.325);
|
|
1647
|
+
--color-destructive-foreground: oklch(0.577 0.245 27.325);
|
|
1648
|
+
--color-border: oklch(0.922 0 0);
|
|
1649
|
+
--color-input: oklch(0.922 0 0);
|
|
1650
|
+
--color-ring: oklch(0.708 0 0);
|
|
1651
|
+
--radius-sm: 0.25rem;
|
|
1652
|
+
--radius-md: 0.375rem;
|
|
1653
|
+
--radius-lg: 0.5rem;
|
|
1654
|
+
--radius-xl: 0.75rem;
|
|
1655
|
+
}`);
|
|
1656
|
+
}
|
|
1657
|
+
return lines.join(`
|
|
1658
|
+
`) + `
|
|
1659
|
+
`;
|
|
1660
|
+
}
|
|
1661
|
+
function generateCnUtil() {
|
|
1662
|
+
return `import { clsx, type ClassValue } from 'clsx';
|
|
1663
|
+
import { twMerge } from 'tailwind-merge';
|
|
1664
|
+
|
|
1665
|
+
export function cn(...inputs: ClassValue[]) {
|
|
1666
|
+
return twMerge(clsx(inputs));
|
|
1667
|
+
}
|
|
1672
1668
|
`;
|
|
1673
1669
|
}
|
|
1674
1670
|
function generateShadcnComponentsJson(config) {
|
|
@@ -1695,6 +1691,39 @@ function getFaviconBuffer() {
|
|
|
1695
1691
|
}
|
|
1696
1692
|
|
|
1697
1693
|
// src/scaffold.ts
|
|
1694
|
+
function generateHonoServerEntry() {
|
|
1695
|
+
return `import { Hono } from 'hono';
|
|
1696
|
+
|
|
1697
|
+
const app = new Hono();
|
|
1698
|
+
|
|
1699
|
+
// Add your Hono middleware and routes here.
|
|
1700
|
+
// This file is the Nitro server entry using the web fetch interface.
|
|
1701
|
+
// Route files in routes/ still use defineHandler from 'nitro'.
|
|
1702
|
+
|
|
1703
|
+
app.use('*', async (c, next) => {
|
|
1704
|
+
console.log(\`[\${new Date().toISOString()}] \${c.req.method} \${c.req.path}\`);
|
|
1705
|
+
await next();
|
|
1706
|
+
});
|
|
1707
|
+
|
|
1708
|
+
export default app;
|
|
1709
|
+
`;
|
|
1710
|
+
}
|
|
1711
|
+
function generateElysiaServerEntry() {
|
|
1712
|
+
return `import { Elysia } from 'elysia';
|
|
1713
|
+
|
|
1714
|
+
const app = new Elysia();
|
|
1715
|
+
|
|
1716
|
+
// Add your Elysia middleware and routes here.
|
|
1717
|
+
// This file is the Nitro server entry using the web fetch interface.
|
|
1718
|
+
// Route files in routes/ still use defineHandler from 'nitro'.
|
|
1719
|
+
|
|
1720
|
+
app.onBeforeHandle(({ request }) => {
|
|
1721
|
+
console.log(\`[\${new Date().toISOString()}] \${request.method} \${new URL(request.url).pathname}\`);
|
|
1722
|
+
});
|
|
1723
|
+
|
|
1724
|
+
export default app;
|
|
1725
|
+
`;
|
|
1726
|
+
}
|
|
1698
1727
|
async function scaffoldProject(config, targetDir) {
|
|
1699
1728
|
await mkdir(targetDir, { recursive: true });
|
|
1700
1729
|
for (const dir of BASE_DIRS) {
|
|
@@ -1708,8 +1737,14 @@ async function scaffoldProject(config, targetDir) {
|
|
|
1708
1737
|
await writeFile(join(targetDir, "app/modules/home/pages/index.tsx"), generateHomePage(config));
|
|
1709
1738
|
await writeFile(join(targetDir, "middleware/01.logger.ts"), generateSampleMiddleware(config));
|
|
1710
1739
|
await writeFile(join(targetDir, "routes/api/hello.ts"), generateHelloRoute(config));
|
|
1740
|
+
if (config.middleware === "hono") {
|
|
1741
|
+
await writeFile(join(targetDir, "server.ts"), generateHonoServerEntry());
|
|
1742
|
+
} else if (config.middleware === "elysia") {
|
|
1743
|
+
await writeFile(join(targetDir, "server.ts"), generateElysiaServerEntry());
|
|
1744
|
+
}
|
|
1711
1745
|
const stylingFiles = generateStylingFiles(config);
|
|
1712
1746
|
for (const [filePath, content] of stylingFiles) {
|
|
1747
|
+
await mkdir(join(targetDir, dirname(filePath)), { recursive: true });
|
|
1713
1748
|
await writeFile(join(targetDir, filePath), content);
|
|
1714
1749
|
}
|
|
1715
1750
|
await writeFile(join(targetDir, "public/favicon.ico"), getFaviconBuffer());
|