From 9ec25b419ab874e96215bb9cdf48a33684a2b6ea Mon Sep 17 00:00:00 2001 From: Hoon Kim <40356749+hoonsubin@users.noreply.github.com> Date: Sat, 31 Oct 2020 23:03:25 -0700 Subject: [PATCH] fixed self copy bug (#8) * fixed self copy bug * bump version --- package.json | 2 +- src/cli/deploy.ts | 9 +++++++-- src/cli/index.ts | 4 ++-- src/models/glitchGit.ts | 14 +++++++++----- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/package.json b/package.json index 3c5dc4c..4d4f486 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "glitch-deploy-tool", - "version": "0.1.2-alpha", + "version": "0.1.3-alpha", "description": "CLI tool for deploying files to Glitch.com", "keywords": [ "glitch.com", diff --git a/src/cli/deploy.ts b/src/cli/deploy.ts index c1b84f2..128f587 100644 --- a/src/cli/deploy.ts +++ b/src/cli/deploy.ts @@ -3,9 +3,14 @@ import { GlitchGit, GlitchProject } from '../models'; export const importFromFolder = async (repoUrl: string, targetPath?: string, debugMessage?: boolean) => { const glitchRepo = new GlitchGit(repoUrl, debugMessage); - await glitchRepo.publishFilesToGlitch(targetPath); + try { + await glitchRepo.publishFilesToGlitch(targetPath); + } catch (e) { + glitchRepo.cleanGitInstance(); + throw e; + } - console.log('successfully imported projects from ' + targetPath); + console.log('successfully imported projects from ' + targetPath || process.cwd()); }; export const importFromGithub = async (token: string, projId: string, repo: string, path?: string) => { diff --git a/src/cli/index.ts b/src/cli/index.ts index 3dc0816..5cd7442 100644 --- a/src/cli/index.ts +++ b/src/cli/index.ts @@ -133,8 +133,8 @@ const checkToolMode = () => { // print the tool version if (opts.version) { - //todo: dynamically parse the version - console.log(`glitch-deploy-tool version 0.1.1-alpha`); + //todo: dynamically parse the app version without importing package.json (due to tsc folder structure) + console.log(`glitch-deploy-tool version 0.1.3-alpha`); process.exit(0); } diff --git a/src/models/glitchGit.ts b/src/models/glitchGit.ts index 7d195fb..6e962b9 100644 --- a/src/models/glitchGit.ts +++ b/src/models/glitchGit.ts @@ -59,15 +59,19 @@ export default class GlitchRepo { await this._pushChangesToRemote(); this._writeLog('cleaning up...'); - this._cleanGitInstance(); - // remove the local repo - rimraf.sync(this._glitchRepoDir); + this.cleanGitInstance(); this._writeLog('done'); } - private _cleanGitInstance() { + public cleanGitInstance() { + if (!this._glitchRepoDir) { + throw new Error('Glitch project is not cloned to the local machine yet'); + } + this._gitInst = this._gitInst.clearQueue(); + // remove the local repo + rimraf.sync(this._glitchRepoDir); } private async _cloneRepo() { @@ -106,7 +110,7 @@ export default class GlitchRepo { this._writeLog(`cloning everything inside ${folderToCopy} to Glitch`); // move the new contents to Glitch - Helpers.copyFolderContent(folderToCopy, this._glitchRepoDir, ['.git']); + Helpers.copyFolderContent(folderToCopy, this._glitchRepoDir, ['.git', REPO_FOLDER]); } private async _pushChangesToRemote() {