create-mastra 0.15.0 → 0.15.1-alpha.0
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/CHANGELOG.md +6 -0
- package/dist/index.js +58 -32
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# create-mastra
|
|
2
2
|
|
|
3
|
+
## 0.15.1-alpha.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Improve the overall flow of the `create-mastra` CLI by first asking all questions and then creating the project structure. If you skip entering an API key during the wizard, the `your-api-key` placeholder will now be added to an `.env.example` file instead of `.env`. ([#8603](https://github.com/mastra-ai/mastra/pull/8603))
|
|
8
|
+
|
|
3
9
|
## 0.15.0
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -2042,14 +2042,12 @@ var getAPIKey = async (provider) => {
|
|
|
2042
2042
|
return key;
|
|
2043
2043
|
}
|
|
2044
2044
|
};
|
|
2045
|
-
var writeAPIKey = async ({
|
|
2046
|
-
|
|
2047
|
-
apiKey = "your-api-key"
|
|
2048
|
-
}) => {
|
|
2045
|
+
var writeAPIKey = async ({ provider, apiKey }) => {
|
|
2046
|
+
const envFileName = apiKey ? ".env" : ".env.example";
|
|
2049
2047
|
const key = await getAPIKey(provider);
|
|
2050
2048
|
const escapedKey = shellQuote.quote([key]);
|
|
2051
|
-
const escapedApiKey = shellQuote.quote([apiKey]);
|
|
2052
|
-
await exec2(`echo ${escapedKey}=${escapedApiKey} >>
|
|
2049
|
+
const escapedApiKey = shellQuote.quote([apiKey ? apiKey : "your-api-key"]);
|
|
2050
|
+
await exec2(`echo ${escapedKey}=${escapedApiKey} >> ${envFileName}`);
|
|
2053
2051
|
};
|
|
2054
2052
|
var createMastraDir = async (directory) => {
|
|
2055
2053
|
let dir = directory.trim().split("/").filter((item) => item !== "");
|
|
@@ -2070,8 +2068,19 @@ var writeCodeSample = async (dirPath, component, llmProvider, importComponents)
|
|
|
2070
2068
|
throw err;
|
|
2071
2069
|
}
|
|
2072
2070
|
};
|
|
2073
|
-
var
|
|
2074
|
-
|
|
2071
|
+
var LLM_PROVIDERS = [
|
|
2072
|
+
{ value: "openai", label: "OpenAI", hint: "recommended" },
|
|
2073
|
+
{ value: "anthropic", label: "Anthropic" },
|
|
2074
|
+
{ value: "groq", label: "Groq" },
|
|
2075
|
+
{ value: "google", label: "Google" },
|
|
2076
|
+
{ value: "cerebras", label: "Cerebras" },
|
|
2077
|
+
{ value: "mistral", label: "Mistral" }
|
|
2078
|
+
];
|
|
2079
|
+
var interactivePrompt = async (args2 = {}) => {
|
|
2080
|
+
const { skip = {}, options: { showBanner = true } = {} } = args2;
|
|
2081
|
+
if (showBanner) {
|
|
2082
|
+
Ie(color2.inverse(" Mastra Init "));
|
|
2083
|
+
}
|
|
2075
2084
|
const mastraProject = await Ce(
|
|
2076
2085
|
{
|
|
2077
2086
|
directory: () => he({
|
|
@@ -2079,20 +2088,15 @@ var interactivePrompt = async () => {
|
|
|
2079
2088
|
placeholder: "src/",
|
|
2080
2089
|
defaultValue: "src/"
|
|
2081
2090
|
}),
|
|
2082
|
-
llmProvider: () => ve({
|
|
2083
|
-
message: "Select default provider:",
|
|
2084
|
-
options:
|
|
2085
|
-
{ value: "openai", label: "OpenAI", hint: "recommended" },
|
|
2086
|
-
{ value: "anthropic", label: "Anthropic" },
|
|
2087
|
-
{ value: "groq", label: "Groq" },
|
|
2088
|
-
{ value: "google", label: "Google" },
|
|
2089
|
-
{ value: "cerebras", label: "Cerebras" },
|
|
2090
|
-
{ value: "mistral", label: "Mistral" }
|
|
2091
|
-
]
|
|
2091
|
+
llmProvider: () => skip?.llmProvider ? void 0 : ve({
|
|
2092
|
+
message: "Select a default provider:",
|
|
2093
|
+
options: LLM_PROVIDERS
|
|
2092
2094
|
}),
|
|
2093
2095
|
llmApiKey: async ({ results: { llmProvider } }) => {
|
|
2096
|
+
if (skip?.llmApiKey) return void 0;
|
|
2097
|
+
const llmName = LLM_PROVIDERS.find((p6) => p6.value === llmProvider)?.label || "provider";
|
|
2094
2098
|
const keyChoice = await ve({
|
|
2095
|
-
message: `Enter your ${
|
|
2099
|
+
message: `Enter your ${llmName} API key?`,
|
|
2096
2100
|
options: [
|
|
2097
2101
|
{ value: "skip", label: "Skip for now", hint: "default" },
|
|
2098
2102
|
{ value: "enter", label: "Enter API key" }
|
|
@@ -2102,7 +2106,10 @@ var interactivePrompt = async () => {
|
|
|
2102
2106
|
if (keyChoice === "enter") {
|
|
2103
2107
|
return he({
|
|
2104
2108
|
message: "Enter your API key:",
|
|
2105
|
-
placeholder: "sk-..."
|
|
2109
|
+
placeholder: "sk-...",
|
|
2110
|
+
validate: (value) => {
|
|
2111
|
+
if (value.length === 0) return "API key cannot be empty";
|
|
2112
|
+
}
|
|
2106
2113
|
});
|
|
2107
2114
|
}
|
|
2108
2115
|
return void 0;
|
|
@@ -2112,7 +2119,7 @@ var interactivePrompt = async () => {
|
|
|
2112
2119
|
const cursorIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`cursor`);
|
|
2113
2120
|
const vscodeIsAlreadyInstalled = await globalMCPIsAlreadyInstalled(`vscode`);
|
|
2114
2121
|
const editor = await ve({
|
|
2115
|
-
message: `Make your
|
|
2122
|
+
message: `Make your IDE into a Mastra expert? (Installs Mastra's MCP server)`,
|
|
2116
2123
|
options: [
|
|
2117
2124
|
{ value: "skip", label: "Skip for now", hint: "default" },
|
|
2118
2125
|
{
|
|
@@ -2324,18 +2331,34 @@ async function installMastraDependency(pm, dependency, versionTag, isDev, timeou
|
|
|
2324
2331
|
var createMastraProject = async ({
|
|
2325
2332
|
projectName: name,
|
|
2326
2333
|
createVersionTag,
|
|
2327
|
-
timeout
|
|
2334
|
+
timeout,
|
|
2335
|
+
llmProvider,
|
|
2336
|
+
llmApiKey,
|
|
2337
|
+
needsInteractive
|
|
2328
2338
|
}) => {
|
|
2329
2339
|
Ie(color2.inverse(" Mastra Create "));
|
|
2330
2340
|
const projectName = name ?? await he({
|
|
2331
2341
|
message: "What do you want to name your project?",
|
|
2332
2342
|
placeholder: "my-mastra-app",
|
|
2333
|
-
defaultValue: "my-mastra-app"
|
|
2343
|
+
defaultValue: "my-mastra-app",
|
|
2344
|
+
validate: (value) => {
|
|
2345
|
+
if (value.length === 0) return "Project name cannot be empty";
|
|
2346
|
+
if (fs4__default__default.existsSync(value)) {
|
|
2347
|
+
return `A directory named "${value}" already exists. Please choose a different name.`;
|
|
2348
|
+
}
|
|
2349
|
+
}
|
|
2334
2350
|
});
|
|
2335
2351
|
if (pD(projectName)) {
|
|
2336
2352
|
xe("Operation cancelled");
|
|
2337
2353
|
process.exit(0);
|
|
2338
2354
|
}
|
|
2355
|
+
let result;
|
|
2356
|
+
if (needsInteractive) {
|
|
2357
|
+
result = await interactivePrompt({
|
|
2358
|
+
options: { showBanner: false },
|
|
2359
|
+
skip: { llmProvider: llmProvider !== void 0, llmApiKey: llmApiKey !== void 0 }
|
|
2360
|
+
});
|
|
2361
|
+
}
|
|
2339
2362
|
const s2 = Y();
|
|
2340
2363
|
try {
|
|
2341
2364
|
s2.start("Creating project");
|
|
@@ -2396,15 +2419,15 @@ var createMastraProject = async ({
|
|
|
2396
2419
|
);
|
|
2397
2420
|
}
|
|
2398
2421
|
s2.stop(`${pm} dependencies installed`);
|
|
2399
|
-
s2.start("Installing
|
|
2422
|
+
s2.start("Installing Mastra CLI");
|
|
2400
2423
|
const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
|
|
2401
2424
|
try {
|
|
2402
2425
|
await installMastraDependency(pm, "mastra", versionTag, true, timeout);
|
|
2403
2426
|
} catch (error) {
|
|
2404
2427
|
throw new Error(`Failed to install Mastra CLI: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2405
2428
|
}
|
|
2406
|
-
s2.stop("
|
|
2407
|
-
s2.start("Installing dependencies");
|
|
2429
|
+
s2.stop("Mastra CLI installed");
|
|
2430
|
+
s2.start("Installing Mastra dependencies");
|
|
2408
2431
|
try {
|
|
2409
2432
|
await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
|
|
2410
2433
|
await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
|
|
@@ -2431,7 +2454,7 @@ var createMastraProject = async ({
|
|
|
2431
2454
|
s2.stop(".gitignore added");
|
|
2432
2455
|
Se("Project created successfully");
|
|
2433
2456
|
console.info("");
|
|
2434
|
-
return { projectName };
|
|
2457
|
+
return { projectName, result };
|
|
2435
2458
|
} catch (error) {
|
|
2436
2459
|
s2.stop();
|
|
2437
2460
|
const errorMessage = error instanceof Error ? error.message : "An unexpected error occurred";
|
|
@@ -2444,14 +2467,17 @@ var create = async (args2) => {
|
|
|
2444
2467
|
await createFromTemplate({ ...args2, injectedAnalytics: args2.analytics });
|
|
2445
2468
|
return;
|
|
2446
2469
|
}
|
|
2447
|
-
const
|
|
2470
|
+
const needsInteractive = args2.components === void 0 || args2.llmProvider === void 0 || args2.addExample === void 0;
|
|
2471
|
+
const { projectName, result } = await createMastraProject({
|
|
2448
2472
|
projectName: args2?.projectName,
|
|
2449
2473
|
createVersionTag: args2?.createVersionTag,
|
|
2450
|
-
timeout: args2?.timeout
|
|
2474
|
+
timeout: args2?.timeout,
|
|
2475
|
+
llmProvider: args2?.llmProvider,
|
|
2476
|
+
llmApiKey: args2?.llmApiKey,
|
|
2477
|
+
needsInteractive
|
|
2451
2478
|
});
|
|
2452
2479
|
const directory = args2.directory || "src/";
|
|
2453
|
-
if (
|
|
2454
|
-
const result = await interactivePrompt();
|
|
2480
|
+
if (needsInteractive && result) {
|
|
2455
2481
|
await init({
|
|
2456
2482
|
...result,
|
|
2457
2483
|
llmApiKey: result?.llmApiKey,
|
|
@@ -2701,7 +2727,7 @@ program.name("create-mastra").description("Create a new Mastra project").argumen
|
|
|
2701
2727
|
components: args.components ? args.components.split(",") : [],
|
|
2702
2728
|
llmProvider: args.llm,
|
|
2703
2729
|
addExample: args.example,
|
|
2704
|
-
llmApiKey: args
|
|
2730
|
+
llmApiKey: args.llmApiKey,
|
|
2705
2731
|
createVersionTag,
|
|
2706
2732
|
timeout,
|
|
2707
2733
|
projectName,
|