A CLI to generate firestore.rules file from multiple files.
This CLI enable to organize directory structure and avoid fat firestore.rules
file.
This CLI has a watching mode so you could edit rules comfortable. :)
- NodeJs
- Compile mode: Combine multiple rule files.
- Watching mode: Combine multiple rule files automatically.
yarn add -D frules-gen
Run following command or set scripts in package.json
.
yarn frules-gen // Compile mode
yarn frules-gen -w // Watching mode
index.rules
service cloud.firestore {
match /databases/{database}/documents {
// helpers: Define helpers what often using.
include "helpers/isAuthenticated.rules"; // isAuthenticated function is able to call in `documents`.
// documents: Difine documents per domain and import here.
include "documents/users/index.rules";
}
helpers/isAuthenticated.rules
function isAuthenticated() {
return request.auth != null;
}
- When import file, write
include "<pathname>";
where you want to output code.- it must be
include
, dosen'timport
. - it need to write
.rules
at pathname.
- it must be
- If refer to
request
context, hava to write inmatch /databases/{database}/documents
. - Are there same include pathes, thier are each output same things so
firestore.rules
will be fat. In this case, you should change import file position to above position.