From df98c7006205a567151c6f03faa647b171e4485d Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Wed, 4 Mar 2020 18:40:50 +0100 Subject: [PATCH 1/5] fix: init with directory option set to . --- packages/cli/src/commands/init/init.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 183ef4035..9f06ad988 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -224,7 +224,7 @@ export default (async function initialize( */ const version: string = minimist(process.argv).version || DEFAULT_VERSION; - const directoryName = path.relative(root, options.directory || projectName); + const directoryName = path.resolve(root, options.directory || projectName); try { await createProject(projectName, directoryName, version, options); From 49efee1a37d04363f1e5e9d1b55855a73a1f2cd1 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Wed, 4 Mar 2020 21:05:10 +0100 Subject: [PATCH 2/5] Remove initializing to pre-existing directory --- packages/cli/src/commands/init/init.ts | 39 ++++++++------------------ 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 9f06ad988..c59ea8818 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -42,37 +42,21 @@ interface TemplateOptions { projectTitle?: string; } -function doesDirectoryExist(dir: string) { - return fs.existsSync(dir); +function doesDirectoryExist(path: string) { + return fs.existsSync(path); } -async function setProjectDirectory(directory: string) { - const directoryExists = doesDirectoryExist(directory); - if (directoryExists) { - const {shouldReplaceprojectDirectory} = await inquirer.prompt([ - { - type: 'confirm', - name: 'shouldReplaceprojectDirectory', - message: `Directory "${directory}" already exists, do you want to replace it?`, - default: false, - }, - ]); - - if (!shouldReplaceprojectDirectory) { - throw new DirectoryAlreadyExistsError(directory); - } - - fs.emptyDirSync(directory); +async function setProjectDirectory(projectPath: string) { + if (doesDirectoryExist(projectPath)) { + throw new DirectoryAlreadyExistsError(projectPath); } try { - mkdirp.sync(directory); - process.chdir(directory); + mkdirp.sync(projectPath); + process.chdir(projectPath); } catch (error) { throw new CLIError( - `Error occurred while trying to ${ - directoryExists ? 'replace' : 'create' - } project directory.`, + `Error occurred while trying to create project directory.`, error, ); } @@ -224,13 +208,12 @@ export default (async function initialize( */ const version: string = minimist(process.argv).version || DEFAULT_VERSION; - const directoryName = path.resolve(root, options.directory || projectName); + const projectPath = path.resolve(root, options.directory || projectName); try { - await createProject(projectName, directoryName, version, options); + await createProject(projectName, projectPath, version, options); - const projectFolder = path.join(root, directoryName); - printRunInstructions(projectFolder, projectName); + printRunInstructions(projectPath, projectName); } catch (e) { logger.error(e.message); } From ff7f23e70004ee9b359fc71c0c0dc2acaeaeec7c Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Wed, 4 Mar 2020 21:15:12 +0100 Subject: [PATCH 3/5] Remove lint errors --- packages/cli/src/commands/init/init.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index c59ea8818..b740c28c2 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -4,8 +4,6 @@ import fs from 'fs-extra'; import minimist from 'minimist'; import ora from 'ora'; import semver from 'semver'; -// @ts-ignore untyped -import inquirer from 'inquirer'; import mkdirp from 'mkdirp'; import {validateProjectName} from './validate'; import DirectoryAlreadyExistsError from './errors/DirectoryAlreadyExistsError'; @@ -42,8 +40,8 @@ interface TemplateOptions { projectTitle?: string; } -function doesDirectoryExist(path: string) { - return fs.existsSync(path); +function doesDirectoryExist(dir: string) { + return fs.existsSync(dir); } async function setProjectDirectory(projectPath: string) { @@ -56,7 +54,7 @@ async function setProjectDirectory(projectPath: string) { process.chdir(projectPath); } catch (error) { throw new CLIError( - `Error occurred while trying to create project directory.`, + 'Error occurred while trying to create project directory.', error, ); } From 06b8d6b25c61cb1ed6a99865daa3a4af783a01f6 Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Wed, 4 Mar 2020 21:26:44 +0100 Subject: [PATCH 4/5] Bring back relative names --- packages/cli/src/commands/init/init.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index b740c28c2..2721b7ac1 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -206,12 +206,13 @@ export default (async function initialize( */ const version: string = minimist(process.argv).version || DEFAULT_VERSION; - const projectPath = path.resolve(root, options.directory || projectName); + const directoryName = path.relative(root, options.directory || projectName); try { - await createProject(projectName, projectPath, version, options); + await createProject(projectName, directoryName, version, options); - printRunInstructions(projectPath, projectName); + const projectFolder = path.join(root, directoryName); + printRunInstructions(projectFolder, projectName); } catch (e) { logger.error(e.message); } From 0ffa3c230611322e457335a68655d6dafd73247a Mon Sep 17 00:00:00 2001 From: Kacper Wiszczuk Date: Wed, 4 Mar 2020 21:28:07 +0100 Subject: [PATCH 5/5] Consistent names everywhere --- packages/cli/src/commands/init/init.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/cli/src/commands/init/init.ts b/packages/cli/src/commands/init/init.ts index 2721b7ac1..7d5df4c6e 100644 --- a/packages/cli/src/commands/init/init.ts +++ b/packages/cli/src/commands/init/init.ts @@ -44,14 +44,14 @@ function doesDirectoryExist(dir: string) { return fs.existsSync(dir); } -async function setProjectDirectory(projectPath: string) { - if (doesDirectoryExist(projectPath)) { - throw new DirectoryAlreadyExistsError(projectPath); +async function setProjectDirectory(directory: string) { + if (doesDirectoryExist(directory)) { + throw new DirectoryAlreadyExistsError(directory); } try { - mkdirp.sync(projectPath); - process.chdir(projectPath); + mkdirp.sync(directory); + process.chdir(directory); } catch (error) { throw new CLIError( 'Error occurred while trying to create project directory.',