Skip to content

Commit 1558001

Browse files
committed
Update README to recommend @bazel/create for quickstart
1 parent f33796d commit 1558001

2 files changed

Lines changed: 20 additions & 91 deletions

File tree

‎README.md‎

Lines changed: 10 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -19,91 +19,22 @@ https://bazelbuild.github.io/rules_nodejs/
1919

2020
## Quickstart
2121

22-
This is the most common workflow to get started.
22+
This is the fastest way to get started.
2323
See sections below for details and alternative methods.
2424

25-
1. Add dependencies
26-
27-
```sh
28-
$ yarn add -D @bazel/bazel @bazel/ibazel @bazel/buildifier
29-
```
30-
31-
or if you prefer `npm`,
32-
33-
```sh
34-
$ npm install --save-dev @bazel/bazel @bazel/ibazel @bazel/buildifier
35-
```
36-
37-
1. Create a file called `WORKSPACE` in the root of your repo, containing
38-
39-
```python
40-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
41-
http_archive(
42-
name = "build_bazel_rules_nodejs",
43-
sha256 = "abcf497e89cfc1d09132adfcd8c07526d026e162ae2cb681dcb896046417ce91",
44-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.30.1/rules_nodejs-0.30.1.tar.gz"],
45-
)
46-
47-
load("@build_bazel_rules_nodejs//:defs.bzl", "yarn_install")
48-
yarn_install(
49-
name = "npm",
50-
package_json = "//:package.json",
51-
yarn_lock = "//:yarn.lock",
52-
)
53-
54-
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
55-
install_bazel_dependencies()
56-
```
57-
58-
or if you used `npm`:
59-
60-
```python
61-
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
62-
http_archive(
63-
name = "build_bazel_rules_nodejs",
64-
sha256 = "abcf497e89cfc1d09132adfcd8c07526d026e162ae2cb681dcb896046417ce91",
65-
urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.30.1/rules_nodejs-0.30.1.tar.gz"],
66-
)
67-
68-
load("@build_bazel_rules_nodejs//:defs.bzl", "npm_install")
69-
npm_install(
70-
name = "npm",
71-
package_json = "//:package.json",
72-
package_lock_json = "//:package-lock.json",
73-
)
74-
75-
load("@npm//:install_bazel_dependencies.bzl", "install_bazel_dependencies")
76-
install_bazel_dependencies()
77-
```
78-
79-
1. Since Bazel manages a copy of the node_modules, we don't want it to discover configuration in your locally installed copy. Create a file `.bazelignore` in the root of your repo containing this line:
80-
81-
```
82-
node_modules
83-
```
84-
85-
1. Create a file `BUILD.bazel` in the root of your repo, next to the `package.json` file. It can be empty for now.
86-
87-
1. In your `package.json`, find the `"scripts"` section, or create one.
88-
89-
```json
90-
"scripts": {
91-
"build": "bazel build //...",
92-
"test": "ibazel test //..."
93-
}
94-
```
25+
```sh
26+
$ npm init @bazel
27+
```
9528

96-
1. Test that you can do an initial build. It will report that no targets were found yet.
29+
or if you prefer yarn,
9730

98-
```sh
99-
$ yarn build
100-
```
31+
```sh
32+
$ yarn create @bazel
33+
```
10134

102-
or
35+
> These commands are equivalent to `npx run @bazel/create` which downloads the latest version of the `@bazel/create` package from npm and runs the program contained.
10336
104-
```sh
105-
$ npm run build
106-
```
37+
See the output of the tool for command-line options and next steps.
10738

10839
## Adding Build Targets
10940

‎packages/create/index.js‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ function usage(error) {
4646
yarn create @bazel [workspace name] [options...]
4747
4848
Options:
49-
--packageManager=[yarn|npm] Select npm or yarn to install packages (default: npm)
49+
--packageManager=[yarn|npm] Select npm or yarn to install packages
50+
(default: npm if you ran npm/npx, yarn if you ran yarn create)
5051
--typescript Set up the workspace for TypeScript development
5152
5253
Run @bazel/create --help to see all options
@@ -191,17 +192,14 @@ install_bazel_dependencies()`);
191192

192193
log(`Successfully created new Bazel workspace at ${path.resolve(wkspDir)}`);
193194
// TODO: we should probably run the package manager install now
194-
if (pkgMgr === 'yarn') {
195-
log(`Now in that directory, you can run
196-
yarn install
197-
yarn build
198-
yarn test`);
199-
} else {
200-
log(`Now in that directory, you can run
201-
npm install
202-
npm run build
203-
npm test`);
204-
}
195+
196+
log(`Next steps:
197+
1. cd ${wkspDir}
198+
2. ${pkgMgr} install
199+
3. ${pkgMgr === 'yarn' ? 'yarn build' : 'npm run build'}
200+
Note that there is nothing to build, so this trivially succeeds.
201+
4. Add contents to the BUILD.bazel file or create a new BUILD.bazel in a subdirectory.
202+
`);
205203

206204
return 0;
207205
}

0 commit comments

Comments
 (0)