Skip to content

generate firestore.rules from multiple .rules files

License

Notifications You must be signed in to change notification settings

susiyaki/frules-gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Example 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't import.
    • it need to write .rules at pathname.
  • If refer to request context, hava to write in match /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.

CLI options

frules-gen options document

Author

@susiyaki_dev

License

MIT

About

generate firestore.rules from multiple .rules files

Resources

License

Stars

Watchers

Forks

Packages

No packages published