project_template 1.0.1 copy "project_template: ^1.0.1" to clipboard
project_template: ^1.0.1 copied to clipboard

outdated

Tool to generate project templates for any programming language or framework.

project_template #

pub package Null Safety Codecov CI GitHub Tag New Commits Last Commits Pull Requests Code size License

A tool to generate project templates and file trees for any programming language or framework.

Usage #

The package can be used as a command-line interface (CLI) or as a Dart library to be imported in other projects or other CLI tools.

CLI #

You can use the built-in command-line: project_template

To activate it globally:

 $> dart pub global activate project_template

Now you can use the CLI directly:

  $> project_template --help

CLI Commands #

prepare: #

Prepare a Template from a directory into a single file. The resulting file should be used by command create.

Prepare to a JSON file:

  $> project_template prepare -d example/template-example -r ".DS_Store$" -o /tmp/template-x.json

Prepare to a Zip file:

  $> project_template prepare -d example/template-example -r ".DS_Store$" -o /tmp/template-x.zip
  • -d: The Template directory/source.
    • Source types:
      • Directory: path/to/template-directory
      • Zip file: path/to/template-x.zip
      • Tar+gZip file: path/to/template-x.tar.gz
      • Tar file: path/to/template-x.tar
  • -r: A RegExp of a file path to ignore.
  • -o: The prepared Template output file (to be used by create command below).
    • Output File formats:
      • JSON file: path/to/template-x.json
      • YAML file: path/to/template-x.yaml
      • Zip file: path/to/template-x.zip
      • Tar+gZip file: path/to/template-x.tar.gz
      • Tar file: path/to/template-x.tar

info: #

Show information about a Template (files, variables and manifest):

  $> project_template info -t /tmp/template-x.json
  • -t: The template path.
    • Path types:
      • Directory: path/to/template-directory
      • Zip file: path/to/template-x.zip
      • Tar+gZip file: path/to/template-x.tar.gz
      • Tar file: path/to/template-x.tar

create: #

Create a file tree from a Template:

  $> project_template create -t /tmp/template-x.json -p project_name_dir=foo -p project_name=Foo -p "project_description=Foo project." -p homepage=http://foo.com -o /tmp/project-x
  • -t: The template path.
    • Path types:
      • Directory: path/to/template-directory
      • Zip file: path/to/template-x.zip
      • Tar+gZip file: path/to/template-x.tar.gz
      • Tar file: path/to/template-x.tar
  • -p: A template property/variable definition.
  • -o: The output directory, where the project (file tree) will be generated.

Library Usage #

Here's a simple example that loads a Template from a directory, resolves/builds it (with the variables definitions) and then saves it to a new directory.

import 'dart:io';

import 'package:project_template/src/project_template_storage_io.dart';

void main() async {

  var sourceDir = Directory('path/to/template-dir');
  
  // The template storage:
  var storage = StorageIO.directory(sourceDir)
    ..ignoreFiles.add('.DS_Store');

  // List files at storage:
  var files = storage.listFiles();

  // Load a Template using storage files:
  var template = await storage.loadTemplate();

  // Parse the Template files and identify the variables:
  var variables = template.parseTemplateVariables();

  // Return the Template manifest (`project_template.yaml`).
  var manifest = template.getManifest();

  // Define the variables to build a template: 
  var variables = {
    'project_name': 'Project X',
    'project_name_dir': 'project_x',
    'homepage': 'https://project-x.domain',
  };

  // Resolve/build the template:
  var templateResolved = template.resolve(variables);

  // Print all Template files as a YAML document:
  print(templateResolved.toYAMLEncoded());

  var saveDir = Directory('/path/to/workspace');
  
  // Save `templateResolved` files to `/path/to/workspace/project_x`:
  var storageSave = StorageIO.directory(saveDir);
  templateResolved.saveTo(storageSave, 'project_x');
  
}

See the example for more.

To use this library in your code, see the API documentation.

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Author #

Graciliano M. Passos: gmpassos@GitHub.

License #

Apache License - Version 2.0

3
likes
0
pub points
52%
popularity

Publisher

unverified uploader

Tool to generate project templates for any programming language or framework.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

archive, args, async_extension, collection, path, yaml, yaml_writer

More

Packages that depend on project_template