create-avalon 0.1.7 → 0.1.9
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 +54 -55
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -76,10 +76,41 @@ var require_src = __commonJS((exports, module) => {
|
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
// src/cli.ts
|
|
79
|
+
import { basename, resolve } from "node:path";
|
|
80
|
+
import { createRequire } from "node:module";
|
|
81
|
+
|
|
82
|
+
// src/cli-utils.ts
|
|
79
83
|
import { parseArgs } from "node:util";
|
|
80
84
|
import { existsSync, readdirSync } from "node:fs";
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
function validateDirectory(dir) {
|
|
86
|
+
if (!existsSync(dir)) {
|
|
87
|
+
return { valid: true };
|
|
88
|
+
}
|
|
89
|
+
const entries = readdirSync(dir);
|
|
90
|
+
if (entries.length === 0) {
|
|
91
|
+
return { valid: true };
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
valid: false,
|
|
95
|
+
error: `Directory "${dir}" already exists and is not empty.`
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
function parseCliArgs(argv) {
|
|
99
|
+
const { values, positionals } = parseArgs({
|
|
100
|
+
args: argv,
|
|
101
|
+
options: {
|
|
102
|
+
help: { type: "boolean", default: false, short: "h" },
|
|
103
|
+
version: { type: "boolean", default: false, short: "v" }
|
|
104
|
+
},
|
|
105
|
+
strict: true,
|
|
106
|
+
allowPositionals: true
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
projectName: positionals[0] ?? undefined,
|
|
110
|
+
help: values.help ?? false,
|
|
111
|
+
version: values.version ?? false
|
|
112
|
+
};
|
|
113
|
+
}
|
|
83
114
|
|
|
84
115
|
// ../../node_modules/.bun/@clack+core@1.1.0/node_modules/@clack/core/dist/index.mjs
|
|
85
116
|
import { styleText as D } from "node:util";
|
|
@@ -1082,7 +1113,7 @@ async function collectProjectConfig(initialName) {
|
|
|
1082
1113
|
const nameResult = await Zt({
|
|
1083
1114
|
message: "What is your project name?",
|
|
1084
1115
|
placeholder: "my-avalon-app",
|
|
1085
|
-
validate(value) {
|
|
1116
|
+
validate(value = "") {
|
|
1086
1117
|
if (!value.trim())
|
|
1087
1118
|
return "Project name is required.";
|
|
1088
1119
|
}
|
|
@@ -1094,8 +1125,9 @@ async function collectProjectConfig(initialName) {
|
|
|
1094
1125
|
projectName = nameResult;
|
|
1095
1126
|
}
|
|
1096
1127
|
const integrationsResult = await Lt2({
|
|
1097
|
-
message: "Which
|
|
1128
|
+
message: "Which integrations would you like to include? (use space to toggle, enter to confirm)",
|
|
1098
1129
|
options: [
|
|
1130
|
+
{ value: "preact", label: "preact", hint: "Preact 10" },
|
|
1099
1131
|
{ value: "react", label: "react", hint: "React 19" },
|
|
1100
1132
|
{ value: "vue", label: "vue", hint: "Vue 3" },
|
|
1101
1133
|
{ value: "svelte", label: "svelte", hint: "Svelte 5" },
|
|
@@ -1158,8 +1190,8 @@ import { mkdir, writeFile } from "node:fs/promises";
|
|
|
1158
1190
|
import { join } from "node:path";
|
|
1159
1191
|
|
|
1160
1192
|
// src/types.ts
|
|
1161
|
-
var DEFAULT_INTEGRATION_PACKAGE = "@useavalon/preact";
|
|
1162
1193
|
var INTEGRATION_PACKAGES = {
|
|
1194
|
+
preact: "@useavalon/preact",
|
|
1163
1195
|
react: "@useavalon/react",
|
|
1164
1196
|
vue: "@useavalon/vue",
|
|
1165
1197
|
svelte: "@useavalon/svelte",
|
|
@@ -1183,8 +1215,7 @@ var BASE_DIRS = [
|
|
|
1183
1215
|
// src/templates/package-json.ts
|
|
1184
1216
|
function generatePackageJson(config) {
|
|
1185
1217
|
const dependencies = {
|
|
1186
|
-
"@useavalon/avalon": "latest"
|
|
1187
|
-
[DEFAULT_INTEGRATION_PACKAGE]: "latest"
|
|
1218
|
+
"@useavalon/avalon": "latest"
|
|
1188
1219
|
};
|
|
1189
1220
|
for (const integration of config.integrations) {
|
|
1190
1221
|
dependencies[INTEGRATION_PACKAGES[integration]] = "latest";
|
|
@@ -1268,8 +1299,7 @@ function generateViteConfig(config) {
|
|
|
1268
1299
|
if (hasAgentOptimization) {
|
|
1269
1300
|
imports.push(`import { agentOptimization } from '@useavalon/agent-optimization';`);
|
|
1270
1301
|
}
|
|
1271
|
-
const
|
|
1272
|
-
const integrationsList = allIntegrations.map((i) => `'${i}'`).join(", ");
|
|
1302
|
+
const integrationsList = config.integrations.map((i) => `'${i}'`).join(", ");
|
|
1273
1303
|
const pluginEntries = [];
|
|
1274
1304
|
if (hasAgentOptimization) {
|
|
1275
1305
|
pluginEntries.push(` agentOptimization({
|
|
@@ -1696,11 +1726,11 @@ var STYLING_LABELS = {
|
|
|
1696
1726
|
tailwind: "Tailwind CSS",
|
|
1697
1727
|
shadcn: "shadcn"
|
|
1698
1728
|
};
|
|
1699
|
-
function formatSummary(config) {
|
|
1700
|
-
const
|
|
1701
|
-
const integrations = allIntegrations.join(", ");
|
|
1729
|
+
function formatSummary(config, scaffoldedInPlace = false) {
|
|
1730
|
+
const integrations = config.integrations.length > 0 ? config.integrations.join(", ") : "none";
|
|
1702
1731
|
const styling = STYLING_LABELS[config.styling] ?? config.styling;
|
|
1703
1732
|
const plugins = config.plugins.length > 0 ? config.plugins.join(", ") : "none";
|
|
1733
|
+
const nextSteps = scaffoldedInPlace ? [" bun install", " bun run dev"] : [` cd ${config.projectName}`, " bun install", " bun run dev"];
|
|
1704
1734
|
return [
|
|
1705
1735
|
"",
|
|
1706
1736
|
` Project: ${config.projectName}`,
|
|
@@ -1710,47 +1740,16 @@ function formatSummary(config) {
|
|
|
1710
1740
|
` Middleware: ${config.middleware}`,
|
|
1711
1741
|
"",
|
|
1712
1742
|
" Next steps:",
|
|
1713
|
-
|
|
1714
|
-
" bun install",
|
|
1715
|
-
" bun run dev",
|
|
1743
|
+
...nextSteps,
|
|
1716
1744
|
""
|
|
1717
1745
|
].join(`
|
|
1718
1746
|
`);
|
|
1719
1747
|
}
|
|
1720
|
-
function printSummary(config) {
|
|
1721
|
-
console.log(formatSummary(config));
|
|
1748
|
+
function printSummary(config, scaffoldedInPlace = false) {
|
|
1749
|
+
console.log(formatSummary(config, scaffoldedInPlace));
|
|
1722
1750
|
}
|
|
1723
1751
|
|
|
1724
1752
|
// src/cli.ts
|
|
1725
|
-
function validateDirectory(dir) {
|
|
1726
|
-
if (!existsSync(dir)) {
|
|
1727
|
-
return { valid: true };
|
|
1728
|
-
}
|
|
1729
|
-
const entries = readdirSync(dir);
|
|
1730
|
-
if (entries.length === 0) {
|
|
1731
|
-
return { valid: true };
|
|
1732
|
-
}
|
|
1733
|
-
return {
|
|
1734
|
-
valid: false,
|
|
1735
|
-
error: `Directory "${dir}" already exists and is not empty.`
|
|
1736
|
-
};
|
|
1737
|
-
}
|
|
1738
|
-
function parseCliArgs(argv) {
|
|
1739
|
-
const { values, positionals } = parseArgs({
|
|
1740
|
-
args: argv,
|
|
1741
|
-
options: {
|
|
1742
|
-
help: { type: "boolean", default: false, short: "h" },
|
|
1743
|
-
version: { type: "boolean", default: false, short: "v" }
|
|
1744
|
-
},
|
|
1745
|
-
strict: true,
|
|
1746
|
-
allowPositionals: true
|
|
1747
|
-
});
|
|
1748
|
-
return {
|
|
1749
|
-
projectName: positionals[0] ?? undefined,
|
|
1750
|
-
help: values.help ?? false,
|
|
1751
|
-
version: values.version ?? false
|
|
1752
|
-
};
|
|
1753
|
-
}
|
|
1754
1753
|
async function main() {
|
|
1755
1754
|
const args = parseCliArgs(process.argv.slice(2));
|
|
1756
1755
|
if (args.version) {
|
|
@@ -1767,7 +1766,7 @@ Options:
|
|
|
1767
1766
|
-h, --help Show help`);
|
|
1768
1767
|
process.exit(0);
|
|
1769
1768
|
}
|
|
1770
|
-
if (args.projectName) {
|
|
1769
|
+
if (args.projectName && args.projectName !== ".") {
|
|
1771
1770
|
const dirResult = validateDirectory(resolve(args.projectName));
|
|
1772
1771
|
if (!dirResult.valid) {
|
|
1773
1772
|
console.error(dirResult.error);
|
|
@@ -1775,20 +1774,20 @@ Options:
|
|
|
1775
1774
|
}
|
|
1776
1775
|
}
|
|
1777
1776
|
const config = await collectProjectConfig(args.projectName);
|
|
1778
|
-
if (!args.projectName) {
|
|
1777
|
+
if (!args.projectName && config.projectName !== ".") {
|
|
1779
1778
|
const dirResult = validateDirectory(resolve(config.projectName));
|
|
1780
1779
|
if (!dirResult.valid) {
|
|
1781
1780
|
console.error(dirResult.error);
|
|
1782
1781
|
process.exit(1);
|
|
1783
1782
|
}
|
|
1784
1783
|
}
|
|
1785
|
-
|
|
1786
|
-
|
|
1784
|
+
const targetDir = resolve(config.projectName);
|
|
1785
|
+
const scaffoldedInPlace = config.projectName === ".";
|
|
1786
|
+
if (scaffoldedInPlace) {
|
|
1787
|
+
config.projectName = basename(targetDir);
|
|
1788
|
+
}
|
|
1789
|
+
await scaffoldProject(config, targetDir);
|
|
1790
|
+
printSummary(config, scaffoldedInPlace);
|
|
1787
1791
|
process.exit(0);
|
|
1788
1792
|
}
|
|
1789
1793
|
main();
|
|
1790
|
-
export {
|
|
1791
|
-
validateDirectory,
|
|
1792
|
-
parseCliArgs,
|
|
1793
|
-
main
|
|
1794
|
-
};
|