Skip to main content

scaffer

Project description

Scaffer

Yet another scaffolding tool. This is the one that actually does what you want, honest. If you are not a reading type of person, see demo on YouTube.

Unlike many other scaffolding tools (like cookiecutter, angular schematics etc), this one:

  • Allows using working/compiling code as templates. That is, you only need to rename symbols in your live code and it will still compile and/or run. That way can modify and test templates naturally without having to remaster the template for publication.
  • Does not require you to create any configuration for your templates. Just place the files somewhere and use.
  • Allows using templates from your own repo/source tree.
  • Allows tree to contain as many templates as you want. E.g. with cookiecutter, you are stuck with one template per repo.
  • Is turing complete! You can add scaffer_init.py to your template, e.g to read values to template variables from external system (say, call git to get username, check directory name to get project name...)
  • Is not implemented in Node.

Logic

If you want to have template variable 'myvar', represent it by one of these in the templates:

ScfMyvar, scf-myvar, scf.myvar, scf_myvar, or uppercase equivalents. It should appear at word boundary at least once to be discovered. E.g. fooscfoeoevaroeuoeuoeu would not be discovered or replaced, to avoid triggering the logic in random strings that may have "scf" characters.

Example of file with all the supported templates, targeting variables "prj" and "bar":

ScfPrjHello vs ScfBarWorld in pascalcase.
Lower kebab scf-prj-hello scf-bar-world
Lower snake scf_prj_hello scf_bar_world
Lower dotted scf.prj.hello scf.bar.world
Lower flat scfprj scfbar
Upper dotted SCF.PRJ.HELLO SCF.BAR.world
Upper kebab SCF-PRJ-HELLO SCF-BAR-world
Upper snake SCF_PRJ_HELLO SCF_BAR_world
Upper flat SCFPRJ SCFBAR

Note that the "flat" variants (scfprj or SCFPRJ) can't contain a suffix for obvious reasons.

When scaffer sees these markers in your templates, it will ask for these and do a smart search-and-replace operation that does PascalCasing, kebab-casing, dot.separation and snake_casing based on what notation you used in the template.

The user will always give a kebab-cased variation when prompted. So if the user wants to emit MyClass, she just enters my-class when prompted. Scaffer will know how to emit the right compound word format at the replacement sites.

Template variables can also be in file and directory names, and behave as you would expect.

See https://github.com/vivainio/scaffer-templates for example templates.

Template discovery

  1. Place your files somewhere.
  2. In project root, or any parent directory, put scaffer.json that points to directories that contain your templates:
{
    "scaffer": ["my/templates", "some/other/templates"]
}

You can also add scaffer_template_urls and configure templates to be downloaded via HTTP. In this case template must be a zip file which is automatically downloaded and extracted by Scaffer.

{
    "scaffer": ["my/templates", "some/other/templates"],
    "scaffer_template_urls": {
        "template_1": "http://localhost/1.zip",
        "template_2": "http://localhost/2.zip"
    }
}

You can also put that "scaffer" key in your package.json if you don't want to pollute your tree with new files.

Installation

pip install scaffer

Usage:

usage: scaffer [-h] {barrel,gitignore,setup,g,add} ...

positional arguments:
  {barrel,gitignore,setup,g,add}
    barrel              Create index.tx for current directory
    gitignore           Create .gitignore file
    g                   Generate code from named or downloaded template
    add                 Add current directory as template root in user global
                        scaffer.json

$ scaffer g -h
usage: scaffer g [-h] [-v variable=value [variable=value ...]] [-f] [--dry]
                 [template]

positional arguments:
  template              Template to generate or a URL to template zip package

optional arguments:
  -h, --help            show this help message and exit
  -v variable=value [variable=value ...]
                        Give value to variable
  -f                    Overwrite files if needed
  --dry                 Dry run, do not create files

License

MIT.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scaffer-3.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

scaffer-3.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file scaffer-3.0.tar.gz.

File metadata

  • Download URL: scaffer-3.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for scaffer-3.0.tar.gz
Algorithm Hash digest
SHA256 c00fdf9ba5fb16687e50a7d412133e9ca7c88bad760983634c7fc2d6b7ab7864
MD5 3512ba565e62a6b3d4d046765ceed6ee
BLAKE2b-256 ec9366c0796f6d0a04bfdf796703fe7f5d203767baa97ecab253e8c415730279

See more details on using hashes here.

File details

Details for the file scaffer-3.0-py3-none-any.whl.

File metadata

  • Download URL: scaffer-3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.11

File hashes

Hashes for scaffer-3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b98e11380712d7304f30424cfab8836248bed5b7dc26636c0f7c0ce9651fccb5
MD5 0d2f3c7742eeeb08ecd65f8f1ff7ff4f
BLAKE2b-256 3cb5f025c5935802ce01bfcbec91a7a83f3cbba5f4190d1451f469a3cb318572

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page