From d8efffb53d8ff7a37249f30398737ef8a1459b08 Mon Sep 17 00:00:00 2001 From: campionfellin Date: Tue, 29 May 2018 18:25:57 -0700 Subject: [PATCH] Clasp clone now exits with error if .clasp.json already exists Created test for this Changed logError to exit with status 1 Signed-off-by: campionfellin --- index.ts | 6 +++++- src/utils.ts | 1 + tests/test.ts | 9 +++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index c613c848..f41bacb8 100755 --- a/index.ts +++ b/index.ts @@ -291,6 +291,10 @@ commander .command('clone [scriptId] [versionNumber]') .description('Clone a project') .action(async (scriptId: string, versionNumber?: number) => { + await checkIfOnline(); + if (fs.existsSync(DOT.PROJECT.PATH)) { + logError(null, ERROR.FOLDER_EXISTS); + } else { if (!scriptId) { getAPICredentials(async () => { const drive = google.drive({version: 'v3', auth: oauth2Client}) as Drive; @@ -325,11 +329,11 @@ commander } }); } else { - await checkIfOnline(); spinner.setSpinnerTitle(LOG.CLONING); saveProjectId(scriptId); fetchProject(scriptId, '', versionNumber); } + } }); /** diff --git a/src/utils.ts b/src/utils.ts index 7e3b216c..3b6dd843 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -134,6 +134,7 @@ export const logError = (err: any, description = '') => { } if (description) console.error(description); } + process.exit(1); }; /** diff --git a/tests/test.ts b/tests/test.ts index 8de3ceec..9ef333f1 100644 --- a/tests/test.ts +++ b/tests/test.ts @@ -71,6 +71,7 @@ describe.skip('Test clasp create function', () => { describe.skip('Test clasp clone <scriptId> function', () => { it('should clone an existing project correctly', () => { const settings = JSON.parse(fs.readFileSync('.clasp.json', 'utf8')); + fs.removeSync('.clasp.json'); const result = spawnSync( 'clasp', ['clone', settings.scriptId], { encoding: 'utf8' }, ); @@ -173,6 +174,14 @@ describe.skip('Test clasp clone function', () => { expect(result.stdout).to.contain('Clone which script?'); expect(result.status).to.equal(0); }); + it('should give an error if .clasp.json already exists', () => { + fs.writeFileSync('.clasp.json', ''); + const result = spawnSync( + 'clasp', ['clone'], { encoding: 'utf8' }, + ); + expect(result.stderr).to.contain('Project file (.clasp.json) already exists.'); + expect(result.status).to.equal(1); + }); }); describe.skip('Test clasp deployments function', () => {