create-mastra 0.10.4 → 0.10.5-alpha.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 +95 -56
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -415,8 +415,8 @@ function requireQuote () {
|
|
|
415
415
|
if (s && typeof s === 'object') {
|
|
416
416
|
return s.op.replace(/(.)/g, '\\$1');
|
|
417
417
|
}
|
|
418
|
-
if ((/["\s]/).test(s) && !(/'/).test(s)) {
|
|
419
|
-
return "'" + s.replace(/(['
|
|
418
|
+
if ((/["\s\\]/).test(s) && !(/'/).test(s)) {
|
|
419
|
+
return "'" + s.replace(/(['])/g, '\\$1') + "'";
|
|
420
420
|
}
|
|
421
421
|
if ((/["'\s]/).test(s)) {
|
|
422
422
|
return '"' + s.replace(/(["\\$`!])/g, '\\$1') + '"';
|
|
@@ -2123,7 +2123,6 @@ var execWithTimeout = async (command, timeoutMs) => {
|
|
|
2123
2123
|
throw error;
|
|
2124
2124
|
}
|
|
2125
2125
|
} catch (error) {
|
|
2126
|
-
console.error(error);
|
|
2127
2126
|
throw error;
|
|
2128
2127
|
}
|
|
2129
2128
|
};
|
|
@@ -2135,11 +2134,18 @@ async function installMastraDependency(pm, dependency, versionTag, isDev, timeou
|
|
|
2135
2134
|
try {
|
|
2136
2135
|
await execWithTimeout(`${pm} ${installCommand} ${dependency}${versionTag}`, timeout);
|
|
2137
2136
|
} catch (err) {
|
|
2138
|
-
console.log("err", err);
|
|
2139
2137
|
if (versionTag === "@latest") {
|
|
2140
|
-
throw
|
|
2138
|
+
throw new Error(
|
|
2139
|
+
`Failed to install ${dependency}@latest: ${err instanceof Error ? err.message : "Unknown error"}`
|
|
2140
|
+
);
|
|
2141
|
+
}
|
|
2142
|
+
try {
|
|
2143
|
+
await execWithTimeout(`${pm} ${installCommand} ${dependency}@latest`, timeout);
|
|
2144
|
+
} catch (fallbackErr) {
|
|
2145
|
+
throw new Error(
|
|
2146
|
+
`Failed to install ${dependency} (tried ${versionTag} and @latest): ${fallbackErr instanceof Error ? fallbackErr.message : "Unknown error"}`
|
|
2147
|
+
);
|
|
2141
2148
|
}
|
|
2142
|
-
await execWithTimeout(`${pm} ${installCommand} ${dependency}@latest`, timeout);
|
|
2143
2149
|
}
|
|
2144
2150
|
}
|
|
2145
2151
|
var createMastraProject = async ({
|
|
@@ -2158,36 +2164,44 @@ var createMastraProject = async ({
|
|
|
2158
2164
|
process.exit(0);
|
|
2159
2165
|
}
|
|
2160
2166
|
const s2 = _();
|
|
2161
|
-
s2.start("Creating project");
|
|
2162
2167
|
try {
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
+
s2.start("Creating project");
|
|
2169
|
+
try {
|
|
2170
|
+
await fs4.mkdir(projectName);
|
|
2171
|
+
} catch (error) {
|
|
2172
|
+
if (error instanceof Error && "code" in error && error.code === "EEXIST") {
|
|
2173
|
+
s2.stop(`A directory named "${projectName}" already exists. Please choose a different name.`);
|
|
2174
|
+
process.exit(1);
|
|
2175
|
+
}
|
|
2176
|
+
throw new Error(
|
|
2177
|
+
`Failed to create project directory: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2168
2178
|
);
|
|
2169
|
-
process.exit(1);
|
|
2170
2179
|
}
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2180
|
+
process.chdir(projectName);
|
|
2181
|
+
const pm = getPackageManager();
|
|
2182
|
+
const installCommand = getPackageManagerInstallCommand(pm);
|
|
2183
|
+
s2.message("Initializing project structure");
|
|
2184
|
+
try {
|
|
2185
|
+
await exec3(`npm init -y`);
|
|
2186
|
+
await exec3(`npm pkg set type="module"`);
|
|
2187
|
+
await exec3(`npm pkg set engines.node=">=20.9.0"`);
|
|
2188
|
+
const depsService = new DepsService();
|
|
2189
|
+
await depsService.addScriptsToPackageJson({
|
|
2190
|
+
dev: "mastra dev",
|
|
2191
|
+
build: "mastra build",
|
|
2192
|
+
start: "mastra start"
|
|
2193
|
+
});
|
|
2194
|
+
} catch (error) {
|
|
2195
|
+
throw new Error(
|
|
2196
|
+
`Failed to initialize project structure: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2197
|
+
);
|
|
2198
|
+
}
|
|
2199
|
+
s2.stop("Project structure created");
|
|
2200
|
+
s2.start(`Installing ${pm} dependencies`);
|
|
2201
|
+
try {
|
|
2202
|
+
await exec3(`${pm} ${installCommand} zod`);
|
|
2203
|
+
await exec3(`${pm} ${installCommand} typescript @types/node --save-dev`);
|
|
2204
|
+
await exec3(`echo '{
|
|
2191
2205
|
"compilerOptions": {
|
|
2192
2206
|
"target": "ES2022",
|
|
2193
2207
|
"module": "ES2022",
|
|
@@ -2203,29 +2217,54 @@ var createMastraProject = async ({
|
|
|
2203
2217
|
"src/**/*"
|
|
2204
2218
|
]
|
|
2205
2219
|
}' > tsconfig.json`);
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2220
|
+
} catch (error) {
|
|
2221
|
+
throw new Error(
|
|
2222
|
+
`Failed to install basic dependencies: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2223
|
+
);
|
|
2224
|
+
}
|
|
2225
|
+
s2.stop(`${pm} dependencies installed`);
|
|
2226
|
+
s2.start("Installing mastra");
|
|
2227
|
+
const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
|
|
2228
|
+
try {
|
|
2229
|
+
await installMastraDependency(pm, "mastra", versionTag, true, timeout);
|
|
2230
|
+
} catch (error) {
|
|
2231
|
+
throw new Error(`Failed to install Mastra CLI: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2232
|
+
}
|
|
2233
|
+
s2.stop("mastra installed");
|
|
2234
|
+
s2.start("Installing dependencies");
|
|
2235
|
+
try {
|
|
2236
|
+
await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
|
|
2237
|
+
await installMastraDependency(pm, "@mastra/libsql", versionTag, false, timeout);
|
|
2238
|
+
await installMastraDependency(pm, "@mastra/memory", versionTag, false, timeout);
|
|
2239
|
+
} catch (error) {
|
|
2240
|
+
throw new Error(
|
|
2241
|
+
`Failed to install Mastra dependencies: ${error instanceof Error ? error.message : "Unknown error"}`
|
|
2242
|
+
);
|
|
2243
|
+
}
|
|
2244
|
+
s2.stop("Mastra dependencies installed");
|
|
2245
|
+
s2.start("Adding .gitignore");
|
|
2246
|
+
try {
|
|
2247
|
+
await exec3(`echo output.txt >> .gitignore`);
|
|
2248
|
+
await exec3(`echo node_modules >> .gitignore`);
|
|
2249
|
+
await exec3(`echo dist >> .gitignore`);
|
|
2250
|
+
await exec3(`echo .mastra >> .gitignore`);
|
|
2251
|
+
await exec3(`echo .env.development >> .gitignore`);
|
|
2252
|
+
await exec3(`echo .env >> .gitignore`);
|
|
2253
|
+
await exec3(`echo *.db >> .gitignore`);
|
|
2254
|
+
await exec3(`echo *.db-* >> .gitignore`);
|
|
2255
|
+
} catch (error) {
|
|
2256
|
+
throw new Error(`Failed to create .gitignore: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
2257
|
+
}
|
|
2258
|
+
s2.stop(".gitignore added");
|
|
2259
|
+
ge("Project created successfully");
|
|
2260
|
+
console.log("");
|
|
2261
|
+
return { projectName };
|
|
2262
|
+
} catch (error) {
|
|
2263
|
+
s2.stop();
|
|
2264
|
+
const errorMessage = error instanceof Error ? error.message : "An unexpected error occurred";
|
|
2265
|
+
he(`Project creation failed: ${errorMessage}`);
|
|
2266
|
+
process.exit(1);
|
|
2267
|
+
}
|
|
2229
2268
|
};
|
|
2230
2269
|
var create = async (args2) => {
|
|
2231
2270
|
const { projectName } = await createMastraProject({
|