diff --git a/packages/create/index.js b/packages/create/index.js index a99f392e00..e523d29c72 100644 --- a/packages/create/index.js +++ b/packages/create/index.js @@ -53,6 +53,8 @@ function usage(error) { --packageManager=[yarn|npm] Select npm or yarn to install packages (default: npm if you ran npm/npx, yarn if you ran yarn create) --typescript Set up the workspace for TypeScript development + --workspaceDir Set a name for the directory containing the workspace + (default: workspace name) Run @bazel/create --help to see all options `); @@ -88,16 +90,17 @@ function main(argv, error = console.error, log = console.log) { log_verbose('Running with', process.argv); log_verbose('Environment', process.env); - const [wkspDir] = args['_']; - // TODO: user might want these to differ - const wkspName = wkspDir; + const [wkspName] = args['_']; + const wkspDir = args['workspaceDir'] || wkspName; if (!validateWorkspaceName(wkspName, error)) { return 1; } log(`Creating Bazel workspace ${wkspName}...`); - fs.mkdirSync(wkspDir); + if (!fs.existsSync(wkspDir)) { + fs.mkdirSync(wkspDir); + } fs.mkdirSync(path.join(wkspDir, 'tools')); function write(workspaceRelativePath, content) { diff --git a/packages/create/test.js b/packages/create/test.js index f8330f1eda..ba555c06ed 100644 --- a/packages/create/test.js +++ b/packages/create/test.js @@ -89,5 +89,13 @@ if (pkgContent.indexOf('"@bazel/typescript": "latest"') < 0) { fail('should install @bazel/typescript dependency', pkgContent); } +exitCode = main(['different_workspace_dir', '--workspaceDir=some-other-dir']) +if (exitCode != 0) fail('should be success'); +if (!fs.existsSync('some-other-dir')) fail('should create directory'); + +exitCode = main(['workspace_in_current_dir', '--workspaceDir=.']) +if (exitCode != 0) fail('should be success'); +if (!fs.existsSync('./WORKSPACE')) fail('should create WORKSPACE file in current directory'); + exitCode = main(['--help'], captureError); if (exitCode != 0) fail('should be success');