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

feat: add preview command #51

Merged
merged 1 commit into from
Aug 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 1 addition & 2 deletions src/cli/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { fileURLToPath } from "node:url";
import { execa } from "execa";
import type { ArgumentsCamelCase } from "yargs";

export type AstroOptions = "dev" | "build";
export type AstroOptions = "dev" | "build" | "preview";

const __dirname = dirname(fileURLToPath(import.meta.url));

Expand All @@ -18,7 +18,6 @@ export async function astro(

const astroDeckFolder = resolve(__dirname, "..", "..");

console.log(astroDeckFolder);
await execa("astro", [astroOptions, ...astroCommands.map(toString)], {
stdio: "inherit",
cwd: astroDeckFolder,
Expand Down
3 changes: 2 additions & 1 deletion src/cli/cmd/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import build from "./build.js";
import deck from "./deck.js";
import dev from "./dev.js";
import preview from "./preview.js";

export const command = [build, deck, dev];
export const command = [build, deck, dev, preview];
30 changes: 30 additions & 0 deletions src/cli/cmd/preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { dirname, resolve } from "node:path";
import { fileURLToPath } from "node:url";
import { cpSync } from "node:fs";
import type { CommandModule } from "yargs";

import { astro } from "../astro.js";

const command: CommandModule<{}, { dist: string }> = {
command: "preview [dist]",
describe: "Preview the deck in the browser",
builder: {
dist: {
describe: "The directory where the deck was built",
type: "string",
default: "dist",
},
},
handler: async (args) => {
const __dirname = dirname(fileURLToPath(import.meta.url));

const from = resolve(__dirname, "..", "..", "..", "dist");
const to = args.dist;

cpSync(from, to, { recursive: true });

await astro(args, "preview");
},
};

export default command;