Skip to content

Commit 3a28a02

Browse files
mgredalexeagle
authored andcommitted
feat(create): introduce --workspaceDir flag
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
1 parent fd2bf85 commit 3a28a02

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

‎packages/create/index.js‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ function usage(error) {
5353
--packageManager=[yarn|npm] Select npm or yarn to install packages
5454
(default: npm if you ran npm/npx, yarn if you ran yarn create)
5555
--typescript Set up the workspace for TypeScript development
56+
--workspaceDir Set a name for the directory containing the workspace
57+
(default: workspace name)
5658
5759
Run @bazel/create --help to see all options
5860
`);
@@ -88,16 +90,17 @@ function main(argv, error = console.error, log = console.log) {
8890
log_verbose('Running with',process.argv);
8991
log_verbose('Environment',process.env);
9092

91-
const[wkspDir]=args['_'];
92-
// TODO: user might want these to differ
93-
constwkspName=wkspDir;
93+
const[wkspName]=args['_'];
94+
constwkspDir=args['workspaceDir']||wkspName;
9495

9596
if(!validateWorkspaceName(wkspName,error)){
9697
return1;
9798
}
9899

99100
log(`Creating Bazel workspace ${wkspName}...`);
100-
fs.mkdirSync(wkspDir);
101+
if(!fs.existsSync(wkspDir)){
102+
fs.mkdirSync(wkspDir);
103+
}
101104
fs.mkdirSync(path.join(wkspDir,'tools'));
102105

103106
functionwrite(workspaceRelativePath,content){

‎packages/create/test.js‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,5 +89,13 @@ if (pkgContent.indexOf('"@bazel/typescript": "latest"') < 0) {
8989
fail('should install @bazel/typescript dependency',pkgContent);
9090
}
9191

92+
exitCode=main(['different_workspace_dir','--workspaceDir=some-other-dir'])
93+
if(exitCode!=0)fail('should be success');
94+
if(!fs.existsSync('some-other-dir'))fail('should create directory');
95+
96+
exitCode=main(['workspace_in_current_dir','--workspaceDir=.'])
97+
if(exitCode!=0)fail('should be success');
98+
if(!fs.existsSync('./WORKSPACE'))fail('should create WORKSPACE file in current directory');
99+
92100
exitCode=main(['--help'],captureError);
93101
if(exitCode!=0)fail('should be success');

0 commit comments

Comments
 (0)