Skip to content

Commit

Permalink
Merge pull request #13 from kylee001/master
Browse files Browse the repository at this point in the history
[fix] add exit code
  • Loading branch information
yushimatenjin authored Apr 6, 2023
2 parents cadc177 + 5e7c6a3 commit 7c8be53
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
32 changes: 19 additions & 13 deletions src/bin/playcanvas-cli.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
#!/usr/bin/env node
import { create, init, download, upload, sw, archive } from "../scripts/commands";
import {
archive,
create,
download,
init,
sw,
upload,
} from "../scripts/commands";
import meow from "meow";

const cli = meow(
Expand Down Expand Up @@ -28,41 +35,40 @@ const cli = meow(
flags: {
accessToken: {
type: "string",
alias: "t"
alias: "t",
},
projectId: {
type: "string",
alias: "p"
alias: "p",
},
scenes: {
type: "string",
alias: "s"
alias: "s",
},
branchId: {
type: "string",
alias: "b"
alias: "b",
},
projectName: {
type: "string",
alias: "n"
alias: "n",
},
remotePath: {
type: "string",
alias: "r"
alias: "r",
},
url: {
type: "string",
alias: "u"
alias: "u",
},
name: {
type: "string"
}
}
}
type: "string",
},
},
},
);

const script = cli.input[0];

switch (script) {
case "create": {
create();
Expand Down
9 changes: 6 additions & 3 deletions src/scripts/donwload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import axios from "axios";
import extract from "extract-zip";
import path from "path";
import ProgressBar from "progress";
import meow from "meow";
const error = meow("error", {});

const getDownloadUrl = async (
jobId: number,
count: number,
playcanvas: PlayCanvas
playcanvas: PlayCanvas,
): Promise<string | null> => {
const { data } = await playcanvas.getJob(jobId);
const { download_url } = data;
Expand All @@ -28,7 +30,7 @@ export const download = async () => {
const options = fs.readJSONSync("./playcanvas.json");
const progress = new ProgressBar("downloading [:bar] :percent :etas", {
complete: "≶",
total: 50
total: 50,
});
const { accessToken, scenes, projectId, branchId, projectName } = options;

Expand Down Expand Up @@ -58,7 +60,7 @@ export const download = async () => {
const { data } = await axios({
url: download_url,
method: "GET",
responseType: "stream"
responseType: "stream",
});

await data
Expand All @@ -74,6 +76,7 @@ export const download = async () => {
} catch (e) {
console.log(e);
console.log("Download failed.");
error.showHelp(2);
}
} else {
console.log('*** Please run "playcanvas-cli init" ***');
Expand Down

0 comments on commit 7c8be53

Please sign in to comment.