Skip to content

Commit

Permalink
allow no data source
Browse files Browse the repository at this point in the history
  • Loading branch information
eluce2 committed Jan 6, 2025
1 parent 0d0938d commit 0b7bf78
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .changeset/large-beans-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@proofgeist/kit": patch
---

Allow setup without any data sources
60 changes: 46 additions & 14 deletions cli/src/cli/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,28 +199,62 @@ export const runInit = async (name?: string, opts?: CliFlags) => {
// e.g. dir/@mono/app returns ["@mono/app", "dir/app"]
const [scopedAppName, appDir] = parseNameAndPath(projectName);

const dataSource = abortIfCancel(
await p.select({
message: "Do you want to connect to a FileMaker Database now?",
options: [
{
value: "filemaker",
label: "Yes",
hint: "Requires OttoFMS and Admin Server credentials",
},
// { value: "supabase", label: "Supabase" },
{
value: "later",
label: "No",
hint: "You'll be able to add a new data source later",
},
],
})
);

const projectDir = await createBareProject({
projectName: appDir,
scopedAppName,
packages: usePackages,
noInstall: cliOptions.noInstall,
appRouter: cliOptions.appRouter,
});

// later will split this flow to ask for which kind of data souce, but for now it's just FM
await promptForFileMakerDataSource({
projectDir,
name: "filemaker",
adminApiKey: cliOptions.adminApiKey,
dataApiKey: cliOptions.dataApiKey,
server: cliOptions.server,
fileName: cliOptions.fileName,
layoutName: cliOptions.layoutName,
schemaName: cliOptions.schemaName,
});
setImportAlias(projectDir, "@/");

if (state.appType === "webviewer") {
await promptForFileMakerDataSource({
projectDir,
name: "filemaker",
adminApiKey: cliOptions.adminApiKey,
dataApiKey: cliOptions.dataApiKey,
server: cliOptions.server,
fileName: cliOptions.fileName,
layoutName: cliOptions.layoutName,
schemaName: cliOptions.schemaName,
});
await installFmAddon({ addonName: "wv" });
} else if (state.appType === "browser") {
if (dataSource === "filemaker") {
// later will split this flow to ask for which kind of data souce, but for now it's just FM
await promptForFileMakerDataSource({
projectDir,
name: "filemaker",
adminApiKey: cliOptions.adminApiKey,
dataApiKey: cliOptions.dataApiKey,
server: cliOptions.server,
fileName: cliOptions.fileName,
layoutName: cliOptions.layoutName,
schemaName: cliOptions.schemaName,
});
} else if (dataSource === "supabase") {
// TODO: add supabase
}
}

await askForAuth({ projectDir });
Expand Down Expand Up @@ -250,8 +284,6 @@ export const runInit = async (name?: string, opts?: CliFlags) => {
spaces: 2,
});

setImportAlias(projectDir, "@/");

if (!cliOptions.noInstall) {
await installDependencies({ projectDir });
await runCodegenCommand({ projectDir });
Expand Down
43 changes: 27 additions & 16 deletions cli/src/generators/fmdapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,24 +103,35 @@ export async function runCodegenCommand({
projectDir: string;
}) {
const settings = getSettings();
if (settings.dataSources.length === 0) {
console.log("no data sources found, skipping typegen");
return;
}
const pkgManager = getUserPkgManager();
const { failed } = await execa(
pkgManager === "npm"
? "npx"
: pkgManager === "pnpm"
? "pnpx"
: pkgManager === "bun"
? "bunx"
: pkgManager,
["@proofgeist/fmdapi", `--env-path=${settings.envFile}`],
{
cwd: projectDir,
stderr: "inherit",
stdout: "inherit",
}

const hasFileMakerDataSources = settings.dataSources.some(
(ds) => ds.type === "fm"
);
if (failed) {
throw new Error("Failed to run codegen command");

if (hasFileMakerDataSources) {
const { failed } = await execa(
pkgManager === "npm"
? "npx"
: pkgManager === "pnpm"
? "pnpx"
: pkgManager === "bun"
? "bunx"
: pkgManager,
["@proofgeist/fmdapi", `--env-path=${settings.envFile}`],
{
cwd: projectDir,
stderr: "inherit",
stdout: "inherit",
}
);
if (failed) {
throw new Error("Failed to run codegen command");
}
}
}

Expand Down

0 comments on commit 0b7bf78

Please sign in to comment.