frules-gen
v1.0.7
Published
A CLI to generate firestore.rules from multiple .rules files
Downloads
2
Maintainers
Readme
frules-gen
A CLI to generate firestore.rules file from multiple files.
Description
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. :)
Requirement
- NodeJs
Features
- Compile mode: Combine multiple rule files.
- Watching mode: Combine multiple rule files automatically.
Installation
yarn add -D frules-gen
Usage
Run following command or set scripts in package.json
.
yarn frules-gen // Compile mode
yarn frules-gen -w // Watching mode
Syntax of code
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;
}
Rules
- 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.