create-prisma 0.4.2-pr.34.111.1 → 0.4.2-pr.34.112.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/cli.mjs +1 -1
- package/dist/{create-Co1kBCus.mjs → create-D7XYRH3T.mjs} +93 -123
- package/dist/index.mjs +2 -2
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1707,6 +1707,8 @@ async function executeCreateAddonSetupContext(params) {
|
|
|
1707
1707
|
//#endregion
|
|
1708
1708
|
//#region src/tasks/deploy-to-compute.ts
|
|
1709
1709
|
const PRISMA_CLI_PACKAGE = "@prisma/cli@latest";
|
|
1710
|
+
const COMPUTE_DEPLOY_BRANCH = "main";
|
|
1711
|
+
const COMPUTE_ENV_ROLE = "production";
|
|
1710
1712
|
const DEPLOY_OPTIONS_BY_TEMPLATE = {
|
|
1711
1713
|
hono: {
|
|
1712
1714
|
framework: "hono",
|
|
@@ -1755,85 +1757,6 @@ async function ensurePrismaCliAvailable(packageManager) {
|
|
|
1755
1757
|
return false;
|
|
1756
1758
|
}
|
|
1757
1759
|
}
|
|
1758
|
-
async function fetchProjects(packageManager) {
|
|
1759
|
-
const { stdout } = await runPrismaCli(packageManager, [
|
|
1760
|
-
"project",
|
|
1761
|
-
"list",
|
|
1762
|
-
"--json"
|
|
1763
|
-
], { stdio: "pipe" });
|
|
1764
|
-
const parsed = parseProjectListJson(stdout);
|
|
1765
|
-
if (!parsed) throw new Error("Failed to list Prisma projects: invalid command output");
|
|
1766
|
-
if (!parsed.ok) throw new Error(getJsonErrorMessage(parsed.error, "Failed to list Prisma projects"));
|
|
1767
|
-
return parsed.result.items.map((project) => ({
|
|
1768
|
-
id: project.id,
|
|
1769
|
-
name: project.name
|
|
1770
|
-
}));
|
|
1771
|
-
}
|
|
1772
|
-
function parseProjectListJson(stdout) {
|
|
1773
|
-
if (typeof stdout !== "string" || stdout.trim().length === 0) return null;
|
|
1774
|
-
try {
|
|
1775
|
-
return JSON.parse(stdout);
|
|
1776
|
-
} catch {
|
|
1777
|
-
return null;
|
|
1778
|
-
}
|
|
1779
|
-
}
|
|
1780
|
-
async function promptForNewProjectName(defaultProjectName) {
|
|
1781
|
-
const projectNameInput = await text({
|
|
1782
|
-
message: "Prisma project name",
|
|
1783
|
-
placeholder: defaultProjectName,
|
|
1784
|
-
initialValue: defaultProjectName,
|
|
1785
|
-
validate: (value) => {
|
|
1786
|
-
if (!value || value.trim().length === 0) return "Project name is required";
|
|
1787
|
-
}
|
|
1788
|
-
});
|
|
1789
|
-
if (isCancel(projectNameInput)) {
|
|
1790
|
-
cancel("Operation cancelled.");
|
|
1791
|
-
return;
|
|
1792
|
-
}
|
|
1793
|
-
return projectNameInput.trim();
|
|
1794
|
-
}
|
|
1795
|
-
async function promptForNewProjectTarget(defaultProjectName) {
|
|
1796
|
-
const projectName = await promptForNewProjectName(defaultProjectName);
|
|
1797
|
-
return projectName ? { createProjectName: projectName } : void 0;
|
|
1798
|
-
}
|
|
1799
|
-
async function collectProjectTarget(options) {
|
|
1800
|
-
const projects = await fetchProjects(options.packageManager);
|
|
1801
|
-
if (projects.length === 1) {
|
|
1802
|
-
const only = projects[0];
|
|
1803
|
-
const shouldUseExistingProject = await confirm({
|
|
1804
|
-
message: `Use Prisma project ${only.name}?`,
|
|
1805
|
-
initialValue: true
|
|
1806
|
-
});
|
|
1807
|
-
if (isCancel(shouldUseExistingProject)) {
|
|
1808
|
-
cancel("Operation cancelled.");
|
|
1809
|
-
return;
|
|
1810
|
-
}
|
|
1811
|
-
return shouldUseExistingProject ? { projectRef: only.id } : promptForNewProjectTarget(options.defaultProjectName);
|
|
1812
|
-
}
|
|
1813
|
-
if (projects.length > 1) {
|
|
1814
|
-
const selection = await select({
|
|
1815
|
-
message: "Select Prisma project",
|
|
1816
|
-
options: [{
|
|
1817
|
-
value: { type: "create" },
|
|
1818
|
-
label: "Create new project"
|
|
1819
|
-
}, ...projects.slice().sort((a, b) => a.name.localeCompare(b.name)).map((project) => ({
|
|
1820
|
-
value: {
|
|
1821
|
-
type: "existing",
|
|
1822
|
-
project
|
|
1823
|
-
},
|
|
1824
|
-
label: project.name,
|
|
1825
|
-
hint: project.id
|
|
1826
|
-
}))]
|
|
1827
|
-
});
|
|
1828
|
-
if (isCancel(selection)) {
|
|
1829
|
-
cancel("Operation cancelled.");
|
|
1830
|
-
return;
|
|
1831
|
-
}
|
|
1832
|
-
return selection.type === "create" ? promptForNewProjectTarget(options.defaultProjectName) : { projectRef: selection.project.id };
|
|
1833
|
-
}
|
|
1834
|
-
log.info("No Prisma projects found.");
|
|
1835
|
-
return promptForNewProjectTarget(options.defaultProjectName);
|
|
1836
|
-
}
|
|
1837
1760
|
async function collectComputeDeployContext(input, options) {
|
|
1838
1761
|
if (!isComputeDeployableTemplate(options.template)) return null;
|
|
1839
1762
|
if (input.deploy === false) return null;
|
|
@@ -1866,43 +1789,15 @@ async function collectComputeDeployContext(input, options) {
|
|
|
1866
1789
|
return null;
|
|
1867
1790
|
}
|
|
1868
1791
|
}
|
|
1869
|
-
let projectTarget;
|
|
1870
|
-
try {
|
|
1871
|
-
projectTarget = await collectProjectTarget({
|
|
1872
|
-
packageManager: options.packageManager,
|
|
1873
|
-
defaultProjectName: options.defaultServiceName
|
|
1874
|
-
});
|
|
1875
|
-
} catch (error) {
|
|
1876
|
-
log.warn(`Could not list Prisma projects${error instanceof Error ? `: ${redactSecrets(error.message)}` : "."}`);
|
|
1877
|
-
if (input.deploy === true) throw createExplicitDeployError("could not list Prisma projects", error);
|
|
1878
|
-
return null;
|
|
1879
|
-
}
|
|
1880
|
-
if (!projectTarget) {
|
|
1881
|
-
if (input.deploy === true) throw createExplicitDeployError("no Prisma project was selected or created");
|
|
1882
|
-
return null;
|
|
1883
|
-
}
|
|
1884
|
-
const appNameInput = await text({
|
|
1885
|
-
message: "App name",
|
|
1886
|
-
placeholder: options.defaultServiceName,
|
|
1887
|
-
initialValue: options.defaultServiceName,
|
|
1888
|
-
validate: (value) => {
|
|
1889
|
-
if (!value || value.trim().length === 0) return "App name is required";
|
|
1890
|
-
}
|
|
1891
|
-
});
|
|
1892
|
-
if (isCancel(appNameInput)) {
|
|
1893
|
-
cancel("Operation cancelled.");
|
|
1894
|
-
return;
|
|
1895
|
-
}
|
|
1896
1792
|
const deployOptions = DEPLOY_OPTIONS_BY_TEMPLATE[options.template];
|
|
1897
1793
|
if (!deployOptions) {
|
|
1898
1794
|
if (input.deploy === true) throw createExplicitDeployError(`${options.template} is not supported by prisma app deploy yet`);
|
|
1899
1795
|
return null;
|
|
1900
1796
|
}
|
|
1901
1797
|
return {
|
|
1902
|
-
...projectTarget,
|
|
1903
1798
|
template: options.template,
|
|
1904
1799
|
packageManager: options.packageManager,
|
|
1905
|
-
|
|
1800
|
+
createProjectName: options.defaultServiceName,
|
|
1906
1801
|
framework: deployOptions.framework,
|
|
1907
1802
|
httpPort: deployOptions.httpPort
|
|
1908
1803
|
};
|
|
@@ -1911,6 +1806,15 @@ function redactSecrets(message) {
|
|
|
1911
1806
|
return message.replace(/(['"])([A-Z0-9_]*(?:DATABASE_URL|DIRECT_URL|TOKEN|SECRET|PASSWORD|API_KEY|PRIVATE_KEY|ACCESS_KEY)[A-Z0-9_]*=)(.*?)\1/g, "$1$2<redacted>$1").replace(/\b([A-Z0-9_]*(?:DATABASE_URL|DIRECT_URL|TOKEN|SECRET|PASSWORD|API_KEY|PRIVATE_KEY|ACCESS_KEY)[A-Z0-9_]*=)[^\s]+/g, "$1<redacted>");
|
|
1912
1807
|
}
|
|
1913
1808
|
function parseDeployJson(stdout) {
|
|
1809
|
+
return parsePrismaCliJson(stdout);
|
|
1810
|
+
}
|
|
1811
|
+
function parseProjectCreateJson(stdout) {
|
|
1812
|
+
return parsePrismaCliJson(stdout);
|
|
1813
|
+
}
|
|
1814
|
+
function parseProjectEnvJson(stdout) {
|
|
1815
|
+
return parsePrismaCliJson(stdout);
|
|
1816
|
+
}
|
|
1817
|
+
function parsePrismaCliJson(stdout) {
|
|
1914
1818
|
if (typeof stdout !== "string" || stdout.trim().length === 0) return null;
|
|
1915
1819
|
try {
|
|
1916
1820
|
return JSON.parse(stdout);
|
|
@@ -1942,29 +1846,95 @@ function toComputeDeployResult(data) {
|
|
|
1942
1846
|
branchName: data.result.branch.name
|
|
1943
1847
|
};
|
|
1944
1848
|
}
|
|
1849
|
+
async function createComputeProjectForDeploy(params) {
|
|
1850
|
+
const { stdout, exitCode } = await runPrismaCli(params.context.packageManager, [
|
|
1851
|
+
"project",
|
|
1852
|
+
"create",
|
|
1853
|
+
params.context.createProjectName,
|
|
1854
|
+
"--json",
|
|
1855
|
+
"--yes"
|
|
1856
|
+
], {
|
|
1857
|
+
cwd: params.projectDir,
|
|
1858
|
+
reject: false,
|
|
1859
|
+
stdio: [
|
|
1860
|
+
"ignore",
|
|
1861
|
+
"pipe",
|
|
1862
|
+
"pipe"
|
|
1863
|
+
]
|
|
1864
|
+
});
|
|
1865
|
+
const parsed = parseProjectCreateJson(stdout);
|
|
1866
|
+
if (!parsed) throw new Error("Could not parse prisma project create output.");
|
|
1867
|
+
if (exitCode !== 0 || !parsed.ok) throw createDeployError(parsed.ok ? "Prisma project create failed." : getJsonErrorMessage(parsed.error, "Prisma project create failed."));
|
|
1868
|
+
return parsed.result.project.id;
|
|
1869
|
+
}
|
|
1870
|
+
async function writeComputeEnvironmentVariables(params) {
|
|
1871
|
+
for (const [key, value] of Object.entries(params.envVars ?? {})) {
|
|
1872
|
+
const commonArgs = [
|
|
1873
|
+
`${key}=${value}`,
|
|
1874
|
+
"--project",
|
|
1875
|
+
params.projectRef,
|
|
1876
|
+
"--role",
|
|
1877
|
+
COMPUTE_ENV_ROLE,
|
|
1878
|
+
"--json",
|
|
1879
|
+
"--yes"
|
|
1880
|
+
];
|
|
1881
|
+
if ((await runProjectEnvCommand(params.context, params.projectDir, ["add", ...commonArgs])).ok) continue;
|
|
1882
|
+
const updateResult = await runProjectEnvCommand(params.context, params.projectDir, ["update", ...commonArgs]);
|
|
1883
|
+
if (!updateResult.ok) throw createDeployError(getJsonErrorMessage(updateResult.error, `Failed to configure ${key} for Prisma Compute.`));
|
|
1884
|
+
}
|
|
1885
|
+
}
|
|
1886
|
+
async function runProjectEnvCommand(context, projectDir, args) {
|
|
1887
|
+
const { stdout, exitCode } = await runPrismaCli(context.packageManager, [
|
|
1888
|
+
"project",
|
|
1889
|
+
"env",
|
|
1890
|
+
...args
|
|
1891
|
+
], {
|
|
1892
|
+
cwd: projectDir,
|
|
1893
|
+
reject: false,
|
|
1894
|
+
stdio: [
|
|
1895
|
+
"ignore",
|
|
1896
|
+
"pipe",
|
|
1897
|
+
"pipe"
|
|
1898
|
+
]
|
|
1899
|
+
});
|
|
1900
|
+
const parsed = parseProjectEnvJson(stdout);
|
|
1901
|
+
if (!parsed) throw new Error("Could not parse prisma project env output.");
|
|
1902
|
+
if (exitCode !== 0 && parsed.ok) return {
|
|
1903
|
+
ok: false,
|
|
1904
|
+
error: { message: "Prisma project env command failed." }
|
|
1905
|
+
};
|
|
1906
|
+
return parsed;
|
|
1907
|
+
}
|
|
1945
1908
|
async function executeComputeDeployContext(params) {
|
|
1909
|
+
const deploySpinner = spinner();
|
|
1910
|
+
deploySpinner.start("Deploying to Prisma Compute...");
|
|
1911
|
+
const envVars = params.envVars ?? {};
|
|
1912
|
+
const shouldPreconfigureEnvVars = Object.keys(envVars).length > 0;
|
|
1946
1913
|
const args = [
|
|
1947
1914
|
"app",
|
|
1948
1915
|
"deploy",
|
|
1949
1916
|
"--json",
|
|
1950
1917
|
"--yes",
|
|
1951
|
-
"--app",
|
|
1952
|
-
params.context.appName,
|
|
1953
1918
|
"--framework",
|
|
1954
|
-
params.context.framework
|
|
1919
|
+
params.context.framework,
|
|
1920
|
+
"--branch",
|
|
1921
|
+
COMPUTE_DEPLOY_BRANCH
|
|
1955
1922
|
];
|
|
1956
|
-
if (params.context.projectRef) args.push("--project", params.context.projectRef);
|
|
1957
|
-
else if (params.context.createProjectName) args.push("--create-project", params.context.createProjectName);
|
|
1958
|
-
else return {
|
|
1959
|
-
ok: false,
|
|
1960
|
-
cancelled: false,
|
|
1961
|
-
error: /* @__PURE__ */ new Error("Deploy target is missing a Prisma project.")
|
|
1962
|
-
};
|
|
1963
|
-
if (params.context.httpPort) args.push("--http-port", String(params.context.httpPort));
|
|
1964
|
-
for (const [key, value] of Object.entries(params.envVars ?? {})) args.push("--env", `${key}=${value}`);
|
|
1965
|
-
const deploySpinner = spinner();
|
|
1966
|
-
deploySpinner.start("Deploying to Prisma Compute...");
|
|
1967
1923
|
try {
|
|
1924
|
+
if (shouldPreconfigureEnvVars) {
|
|
1925
|
+
const projectRef = await createComputeProjectForDeploy({
|
|
1926
|
+
context: params.context,
|
|
1927
|
+
projectDir: params.projectDir
|
|
1928
|
+
});
|
|
1929
|
+
await writeComputeEnvironmentVariables({
|
|
1930
|
+
context: params.context,
|
|
1931
|
+
projectDir: params.projectDir,
|
|
1932
|
+
projectRef,
|
|
1933
|
+
envVars
|
|
1934
|
+
});
|
|
1935
|
+
args.push("--project", projectRef);
|
|
1936
|
+
} else args.push("--create-project", params.context.createProjectName);
|
|
1937
|
+
if (params.context.httpPort) args.push("--http-port", String(params.context.httpPort));
|
|
1968
1938
|
const { stdout, exitCode } = await runPrismaCli(params.context.packageManager, args, {
|
|
1969
1939
|
cwd: params.projectDir,
|
|
1970
1940
|
reject: false,
|
|
@@ -2054,7 +2024,7 @@ async function getAnonymousId() {
|
|
|
2054
2024
|
}
|
|
2055
2025
|
function getCommonProperties() {
|
|
2056
2026
|
return {
|
|
2057
|
-
"cli-version": "0.4.2-pr.34.
|
|
2027
|
+
"cli-version": "0.4.2-pr.34.112.1",
|
|
2058
2028
|
"node-version": process.version,
|
|
2059
2029
|
platform: process.platform,
|
|
2060
2030
|
arch: process.arch
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { a as DatabaseUrlSchema, i as DatabaseProviderSchema, n as CreateCommandInputSchema, o as PackageManagerSchema, r as CreateTemplateSchema, s as SchemaPresetSchema, t as runCreateCommand } from "./create-
|
|
2
|
+
import { a as DatabaseUrlSchema, i as DatabaseProviderSchema, n as CreateCommandInputSchema, o as PackageManagerSchema, r as CreateTemplateSchema, s as SchemaPresetSchema, t as runCreateCommand } from "./create-D7XYRH3T.mjs";
|
|
3
3
|
import { os } from "@orpc/server";
|
|
4
4
|
import { createCli } from "trpc-cli";
|
|
5
5
|
|
|
6
6
|
//#region src/index.ts
|
|
7
|
-
const CLI_VERSION = "0.4.2-pr.34.
|
|
7
|
+
const CLI_VERSION = "0.4.2-pr.34.112.1";
|
|
8
8
|
const router = os.router({ create: os.meta({
|
|
9
9
|
description: "Create a new project with Prisma setup",
|
|
10
10
|
default: true,
|
package/package.json
CHANGED