Skip to content

Commit

Permalink
feat(create): introduce --workspaceDir flag
Browse files Browse the repository at this point in the history
users now can set a different name for the directory to create a workspace in

the behaivior also changed, so it is possible to create a workspace e.g. in the current dir
  • Loading branch information
mgred authored and alexeagle committed Sep 27, 2022
1 parent fd2bf85 commit 3a28a02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
11 changes: 7 additions & 4 deletions packages/create/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
`);
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 8 additions & 0 deletions packages/create/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

0 comments on commit 3a28a02

Please sign in to comment.