Skip to content

Commit

Permalink
cli: --leopard-url option
Browse files Browse the repository at this point in the history
  • Loading branch information
towerofnix committed Jul 1, 2024
1 parent e493317 commit b763a27
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ program
.addOption(new Option("-it, --input-type <type>", "The type of input file").choices(["sb3"]))
.requiredOption("-o, --output <path>", "The path to the output project")
.addOption(new Option("-ot, --output-type <type>", "The type of output file").choices(["leopard", "leopard-zip"]))
.addOption(new Option("-t, --trace", "Show a detailed error trace"));
.addOption(new Option("-t, --trace", "Show a detailed error trace"))
.addOption(
new Option("--leopard-url <url>", "The URL to use for Leopard").default("https://unpkg.com/leopard@^1/dist/")
);

program.parse();

Expand All @@ -27,6 +30,7 @@ const options: {
output: string;
outputType: "leopard" | "leopard-zip";
trace: boolean | undefined;
leopardUrl: string;
} = program.opts();

let { input, inputType, output, outputType } = options;
Expand Down Expand Up @@ -164,7 +168,24 @@ async function run() {
);

function toLeopard() {
return project.toLeopard();
const { leopardUrl: leopardURL } = options;

let fileJS = "index.esm.js";
let fileCSS = "index.min.css";

let leopardJSURL, leopardCSSURL;

try {
leopardJSURL = String(new URL(fileJS, leopardURL));
leopardCSSURL = String(new URL(fileCSS, leopardURL));
} catch {
throw new Error(`Provided leopard-url isn't a valid URL base`);
}

return project.toLeopard({
leopardJSURL,
leopardCSSURL
});
}

switch (outputType) {
Expand Down

0 comments on commit b763a27

Please sign in to comment.