scaff 1.0.2 copy "scaff: ^1.0.2" to clipboard
scaff: ^1.0.2 copied to clipboard

outdated

scaff (scaffold generator) is a simple command-line utility for generating Dart and Flutter components from template files.

pub-scaff #

Introduction #

Scaffold Generator for Dart and Flutter.

scaff is a simple command-line utility for generating Dart and Flutter components from template files. It is a very tedious job to keep replicating the boilerplate codes every time you try to add a new component in your app. Using scaff, you can generate dart or flutter components from the custom-defined templates. You can even add template schemes to the component directories and files for easy and flexible scaffolding.

scaff uses 'Mustache templating library' for defining and processing the template files.

Installation #

$ pub global activate scaff

Usage Example #

Let us create a simple component. First of all, we need to create a working directory and it should contain a scaff.setup.json file. The scaff.setup.json file should contain all the template variables used in that working directory. Add the other subdirectories and template files into the working directory.

All template files should have a .tpl extension. The files and directories name may contain template variables as well.

Template variable examples: {{var1}}, {{className}}Base, {{fileName}}_store

The example template directory structure:

component_templates
│   └── general_store_architecture
│       ├── scaff.setup.json
│       └── {{componentName}}
│           ├── {{componentName}}.tpl
│           └── {{componentName}}_store.tpl
  1. Create a new directory in the project root
$ mkdir -p component_templates
$ cd component_templates/general_store_architecture
  1. Create the component directory
$ mkdir {{componentName}}
$ cd {{componentName}}
  1. Create the component template file
$ touch {{componentName}}.tpl
  1. Add the code to {{componentName}}.tpl file
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import '../../data/mobx/{{componentName}}_store.dart';

class {{className}}Screen extends StatelessWidget {
  {{className}}Screen({
    Key key,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final {{componentName}} = Provider.of<{{className}}Store>(context);

    return Scaffold(
      body: Center(
        child: Column(),
      ),
    );
  }
}
  1. Create the store template file
$ touch {{componentName}}_store.tpl
  1. Add the code to {{componentName}}_store.tpl file
import 'package:mobx/mobx.dart';

abstract class {{className}}StoreBase with Store {
  @observable
  bool dummyValue = false;
}
  1. Create the scaff.setup.json file
$ cd ..
$ touch scaff.setup.json
  1. Add all the template variables used in the working directory to scaff.setup.json file as
{
	"variables": ["componentName", "className"]
}
  1. cd into general_store_architecture folder.
$ pwd # it should be pointing to =>  /path/component_templates/general_store_architecture
  1. Run scaff globally
$ pub global run scaff
  1. You will be prompted to:
- Enter source directory (/path/component_templates/general_store_architecture) »
- Enter destination directory (/path/component_templates/general_store_architecture/__component__) »
- Enter 'componentName' variable value » login
- Enter 'className' variable value » Login
  1. The destination directory will have the newly generated component. The destination directory structure:
└── login
    ├── login.dart
    └── login_store.dart

Building from Source #

Requirements: Dart and Git

Clone #

$ git clone --depth 1 --single-branch --branch master https://github.com/ganeshrvel/pub-scaff.git

$ cd pub-scaff

Contribute #

  • Fork the repo and create your branch from master.
  • Ensure that the changes pass linting.
  • Update the documentation if needed.
  • Make sure your code lints.
  • Issue a pull request!

When you submit code changes, your submissions are understood to be under the same MIT License that covers the project. Feel free to contact the maintainers if that's a concern.

Buy me a coffee #

Help me keep the app FREE and open for all. Paypal me: paypal.me/ganeshrvel

Contacts #

Please feel free to contact me at ganeshrvel@outlook.com

More repos #

License #

scaff | Scaffold Generator for Dart and Flutter. MIT License.

Copyright © 2018-Present Ganesh Rathinavel

6
likes
0
pub points
0%
popularity

Publisher

verified publisherganeshrvel.com

scaff (scaffold generator) is a simple command-line utility for generating Dart and Flutter components from template files.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

meta, mustache, path, prompts

More

Packages that depend on scaff