From b974f2c47c96ef95bee940afc2742f563d571d07 Mon Sep 17 00:00:00 2001 From: Sergey Rubanov Date: Mon, 25 Sep 2023 23:53:16 +0200 Subject: [PATCH] exit on canceling create-vite operation --- index.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/index.js b/index.js index 91d0574..8e5ca37 100755 --- a/index.js +++ b/index.js @@ -46,32 +46,29 @@ const viteProcess = spawn(viteCreateCommand, [], { encoding: 'utf-8' }) -// TODO -// viteProcess.on('exit', (code) => { -// if (code !== 0) { -// process.stderr.write(`\nUnable to create vite project. Exit code ${code}\n`) -// process.exit(1) -// } -// }) - viteProcess.on('close', (code) => { const cwd = resolve(process.cwd(), projectName) + + try { execSync('ssc --version', { stdio: 'ignore' }) } catch { - process.stdout.write('Installing \'@socketsupply/socket\' locally (ssc not in PATH)\n') + process.stdout.write('Installing \'@socketsupply/socket\' locally (ssc not in PATH)\n\n') execSync('npm install @socketsupply/socket --save-dev') } - process.stdout.write('Installing dependencies\n') - - execSync('npm install', { - cwd, - stdio: 'inherit' - }) + try { + execSync('npm install', { + cwd, + stdio: 'inherit' + }) + } catch (error) { + // create-vite operation was cancelled + if (error.code === 'ENOENT') process.exit(0) + } process.stdout.write(`\nAdding the socket.ini file to the project\n`)