Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notify on schema push if no schema files are found #507

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/commands/schema/push.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//@ts-check

import path from "path";

import { container } from "../../cli.mjs";
import { yargsWithCommonQueryOptions } from "../../lib/command-helpers.mjs";
import { getSecret } from "../../lib/fauna-client.mjs";
Expand All @@ -13,10 +15,16 @@ async function doPush(argv) {

const isStagedPush = !argv.active;
const secret = await getSecret();
const fslFiles = await gatherFSL(argv.dir);
const hasLocalSchema = fslFiles.length > 0;
const absoluteDirPath = path.resolve(argv.dir);
const fsl = reformatFSL(fslFiles);

const fsl = reformatFSL(await gatherFSL(argv.dir));

if (!argv.input) {
if (!hasLocalSchema) {
logger.stdout(
`No schema files (*.fsl) found in '${absoluteDirPath}'. Use '--dir' to specify a different directory, or create new .fsl files in this location.`,
);
} else if (!argv.input) {
const params = new URLSearchParams({
force: "true",
staged: argv.active ? "false" : "true",
Expand Down
12 changes: 12 additions & 0 deletions test/schema/push.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ describe("schema push", function () {
gatherFSL.resolves(fsl);
});

it("notifies the user when no schema files are found", async function () {
gatherFSL.resolves([]);

await run(`schema push --secret "secret"`, container);

expect(logger.stdout).to.have.been.calledWith(
sinon.match(
/^No schema files \(\*\.fsl\) found in '.*'\. Use '--dir' to specify a different directory, or create new \.fsl files in this location\.$/,
),
);
});

it("can push a schema without user input", async function () {
await run(`schema push --secret "secret" --no-input`, container);

Expand Down
Loading