From 5e7c6a3786cddc0b3c5457f9fe4ef47212960c9c Mon Sep 17 00:00:00 2001 From: kylee Date: Wed, 5 Apr 2023 17:47:33 +0900 Subject: [PATCH] [fix] add exit code --- src/bin/playcanvas-cli.ts | 32 +++++++++++++++++++------------- src/scripts/donwload.ts | 9 ++++++--- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/bin/playcanvas-cli.ts b/src/bin/playcanvas-cli.ts index 86a2cac..9e671fa 100644 --- a/src/bin/playcanvas-cli.ts +++ b/src/bin/playcanvas-cli.ts @@ -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( @@ -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(); diff --git a/src/scripts/donwload.ts b/src/scripts/donwload.ts index a73f6a4..3faff8a 100644 --- a/src/scripts/donwload.ts +++ b/src/scripts/donwload.ts @@ -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 => { const { data } = await playcanvas.getJob(jobId); const { download_url } = data; @@ -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; @@ -58,7 +60,7 @@ export const download = async () => { const { data } = await axios({ url: download_url, method: "GET", - responseType: "stream" + responseType: "stream", }); await data @@ -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" ***');