create-mastra 0.2.8 → 0.2.9-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 +30 -51
- package/dist/index.js.map +1 -1
- package/dist/templates/dev.entry.js +6 -4
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1744,6 +1744,21 @@ var execWithTimeout = async (command, timeoutMs) => {
|
|
|
1744
1744
|
throw error;
|
|
1745
1745
|
}
|
|
1746
1746
|
};
|
|
1747
|
+
async function installMastraDependency(pm, dependency, versionTag, isDev, timeout) {
|
|
1748
|
+
let installCommand = getPackageManagerInstallCommand(pm);
|
|
1749
|
+
if (isDev) {
|
|
1750
|
+
installCommand = `${installCommand} --save-dev`;
|
|
1751
|
+
}
|
|
1752
|
+
try {
|
|
1753
|
+
await execWithTimeout(`${pm} ${installCommand} ${dependency}${versionTag}`, timeout);
|
|
1754
|
+
} catch (err) {
|
|
1755
|
+
console.log("err", err);
|
|
1756
|
+
if (versionTag === "@latest") {
|
|
1757
|
+
throw err;
|
|
1758
|
+
}
|
|
1759
|
+
await execWithTimeout(`${pm} ${installCommand} ${dependency}@latest`, timeout);
|
|
1760
|
+
}
|
|
1761
|
+
}
|
|
1747
1762
|
var createMastraProject = async ({
|
|
1748
1763
|
projectName: name,
|
|
1749
1764
|
createVersionTag,
|
|
@@ -1780,12 +1795,13 @@ var createMastraProject = async ({
|
|
|
1780
1795
|
await exec3(`npm pkg set type="module"`);
|
|
1781
1796
|
const depsService = new DepsService();
|
|
1782
1797
|
await depsService.addScriptsToPackageJson({
|
|
1783
|
-
dev: "mastra dev"
|
|
1798
|
+
dev: "mastra dev",
|
|
1799
|
+
build: "mastra build"
|
|
1784
1800
|
});
|
|
1785
1801
|
s2.stop("Project created");
|
|
1786
1802
|
s2.start(`Installing ${pm} dependencies`);
|
|
1787
1803
|
await exec3(`${pm} ${installCommand} zod`);
|
|
1788
|
-
await exec3(`${pm} ${installCommand} typescript
|
|
1804
|
+
await exec3(`${pm} ${installCommand} typescript @types/node --save-dev`);
|
|
1789
1805
|
await exec3(`echo '{
|
|
1790
1806
|
"compilerOptions": {
|
|
1791
1807
|
"target": "ES2022",
|
|
@@ -1795,24 +1811,20 @@ var createMastraProject = async ({
|
|
|
1795
1811
|
"forceConsistentCasingInFileNames": true,
|
|
1796
1812
|
"strict": true,
|
|
1797
1813
|
"skipLibCheck": true,
|
|
1814
|
+
"noEmit": true,
|
|
1798
1815
|
"outDir": "dist"
|
|
1799
1816
|
},
|
|
1800
1817
|
"include": [
|
|
1801
1818
|
"src/**/*"
|
|
1802
|
-
],
|
|
1803
|
-
"exclude": [
|
|
1804
|
-
"node_modules",
|
|
1805
|
-
"dist",
|
|
1806
|
-
".mastra"
|
|
1807
1819
|
]
|
|
1808
1820
|
}' > tsconfig.json`);
|
|
1809
1821
|
s2.stop(`${pm} dependencies installed`);
|
|
1810
1822
|
s2.start("Installing mastra");
|
|
1811
1823
|
const versionTag = createVersionTag ? `@${createVersionTag}` : "@latest";
|
|
1812
|
-
await
|
|
1824
|
+
await installMastraDependency(pm, "mastra", versionTag, true, timeout);
|
|
1813
1825
|
s2.stop("mastra installed");
|
|
1814
1826
|
s2.start("Installing @mastra/core");
|
|
1815
|
-
await
|
|
1827
|
+
await installMastraDependency(pm, "@mastra/core", versionTag, false, timeout);
|
|
1816
1828
|
s2.stop("@mastra/core installed");
|
|
1817
1829
|
s2.start("Adding .gitignore");
|
|
1818
1830
|
await exec3(`echo output.txt >> .gitignore`);
|
|
@@ -1870,48 +1882,14 @@ async function getPackageVersion() {
|
|
|
1870
1882
|
const content = await fsExtra.readJSON(pkgJsonPath);
|
|
1871
1883
|
return content.version;
|
|
1872
1884
|
}
|
|
1873
|
-
async function tryReadPackageJson(paths) {
|
|
1874
|
-
let lastError;
|
|
1875
|
-
for (const path2 of paths) {
|
|
1876
|
-
try {
|
|
1877
|
-
const content = await fsExtra.readJSON(path2);
|
|
1878
|
-
if (content.name === "create-mastra") {
|
|
1879
|
-
return content;
|
|
1880
|
-
}
|
|
1881
|
-
} catch (err) {
|
|
1882
|
-
lastError = err;
|
|
1883
|
-
continue;
|
|
1884
|
-
}
|
|
1885
|
-
}
|
|
1886
|
-
throw lastError || new Error("Could not find create-mastra package.json in any of the expected locations");
|
|
1887
|
-
}
|
|
1888
1885
|
async function getCreateVersionTag() {
|
|
1889
1886
|
try {
|
|
1890
|
-
const
|
|
1891
|
-
const
|
|
1892
|
-
const
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
path.join(binDir, "..", "..", "..", "package.json"),
|
|
1897
|
-
path.join(binDir, "..", "..", "..", "..", "package.json"),
|
|
1898
|
-
// Standard node_modules paths
|
|
1899
|
-
path.join(binDir, "..", "create-mastra", "package.json"),
|
|
1900
|
-
path.join(binDir, "..", "..", "create-mastra", "package.json"),
|
|
1901
|
-
path.join(binDir, "..", "..", "..", "create-mastra", "package.json"),
|
|
1902
|
-
path.join(binDir, "..", "..", "..", "..", "create-mastra", "package.json"),
|
|
1903
|
-
// pnpm specific paths (.pnpm directory)
|
|
1904
|
-
path.join(binDir, "..", ".pnpm", "create-mastra@*", "node_modules", "create-mastra", "package.json"),
|
|
1905
|
-
path.join(binDir, "..", "..", ".pnpm", "create-mastra@*", "node_modules", "create-mastra", "package.json"),
|
|
1906
|
-
// pnpm dlx specific path
|
|
1907
|
-
path.join(binDir, "..", "..", "package.json"),
|
|
1908
|
-
path.join(binDir, "..", "..", "node_modules", "create-mastra", "package.json")
|
|
1909
|
-
];
|
|
1910
|
-
const content = await tryReadPackageJson(possiblePaths);
|
|
1911
|
-
if (content.version?.includes("-")) {
|
|
1912
|
-
const tag = content.version.split("-")[1].split(".")[0];
|
|
1913
|
-
return tag;
|
|
1914
|
-
}
|
|
1887
|
+
const pkgPath = fileURLToPath(import.meta.resolve("create-mastra/package.json"));
|
|
1888
|
+
const json = await fsExtra.readJSON(pkgPath);
|
|
1889
|
+
const { stdout } = await execa("npm", ["dist-tag", "create-mastra"]);
|
|
1890
|
+
const tagLine = stdout.split("\n").find((distLine) => distLine.includes(`: ${json.version}`));
|
|
1891
|
+
const tag = tagLine ? tagLine.split(":")[0].trim() : "latest";
|
|
1892
|
+
return tag;
|
|
1915
1893
|
} catch {
|
|
1916
1894
|
console.error('We could not resolve the create-mastra version tag, falling back to "latest"');
|
|
1917
1895
|
}
|
|
@@ -1935,7 +1913,7 @@ program.version(`${version}`, "-v, --version").description(`create-mastra ${vers
|
|
|
1935
1913
|
} catch {
|
|
1936
1914
|
}
|
|
1937
1915
|
});
|
|
1938
|
-
program.name("create-mastra").description("Create a new Mastra project").option("--default", "Quick start with defaults(src, OpenAI, no examples)").option("-c, --components <components>", "Comma-separated list of components (agents, tools, workflows)").option("-l, --llm <model-provider>", "Default model provider (openai, anthropic, groq, google, or cerebras)").option("-k, --llm-api-key <api-key>", "API key for the model provider").option("-e, --example", "Include example code").option("-t, --timeout [timeout]", "Configurable timeout for package installation, defaults to 60000 ms").action(async (args) => {
|
|
1916
|
+
program.name("create-mastra").description("Create a new Mastra project").argument("[project-name]", "Directory name of the project").option("--default", "Quick start with defaults(src, OpenAI, no examples)").option("-c, --components <components>", "Comma-separated list of components (agents, tools, workflows)").option("-l, --llm <model-provider>", "Default model provider (openai, anthropic, groq, google, or cerebras)").option("-k, --llm-api-key <api-key>", "API key for the model provider").option("-e, --example", "Include example code").option("-t, --timeout [timeout]", "Configurable timeout for package installation, defaults to 60000 ms").action(async (projectName, args) => {
|
|
1939
1917
|
const timeout = args?.timeout ? args?.timeout === true ? 6e4 : parseInt(args?.timeout, 10) : void 0;
|
|
1940
1918
|
if (args.default) {
|
|
1941
1919
|
await create({
|
|
@@ -1953,7 +1931,8 @@ program.name("create-mastra").description("Create a new Mastra project").option(
|
|
|
1953
1931
|
addExample: args.example,
|
|
1954
1932
|
llmApiKey: args["llm-api-key"],
|
|
1955
1933
|
createVersionTag,
|
|
1956
|
-
timeout
|
|
1934
|
+
timeout,
|
|
1935
|
+
projectName
|
|
1957
1936
|
});
|
|
1958
1937
|
});
|
|
1959
1938
|
program.parse(process.argv);
|