Giter Club home page Giter Club logo

mason's Introduction

mason logo

mason coverage License: MIT Powered by Mason


A collection of packages that enable developers to create and consume reusable templates called bricks.

Mason Demo

Packages

Package Pub
mason pub package
mason_api pub package
mason_cli pub package
mason_logger pub package

Quick Start

# ๐ŸŽฏ Activate from https://pub.dev
dart pub global activate mason_cli

# ๐Ÿš€ Initialize mason
mason init

# ๐Ÿ“ฆ Install your first brick
mason add hello

# ๐Ÿงฑ Use your first brick
mason make hello

Documentation

View the full documentation here.

Video Tutorials

Package of the Week by Flutter Observable Flutter: Building a Mason brick by Flutter
mason (Package of the Week) Observable Flutter: Building a Mason brick
Meet Mason: Flutter Vikings 2022 by Flutter Community Felix Angelov Demos Mason by Very Good Ventures
Meet Mason: Intro to Templating and Custom Code Generation Mason Video Tutorial

Badge

Add a markdown badge to indicate your project is powered by mason โ†’ Powered by Mason

[![Powered by Mason](https://img.shields.io/endpoint?url=https%3A%2F%2Ftinyurl.com%2Fmason-badge)](https://github.com/felangel/mason)

mason's People

Contributors

abitofevrything avatar alestiago avatar chyiiiiiiiiiiii avatar dependabot[bot] avatar felangel avatar hugo-pcl avatar jksevend avatar luckey-elijah avatar lukemoody01 avatar lukepighetti avatar marcossevilla avatar marcotas avatar mauriciomunozsc avatar mohamedabdallah-14 avatar mrgnhnt96 avatar mrverdant13 avatar olexale avatar renancaraujo avatar rohan20 avatar slovnicki avatar tenhobi avatar tomwyr avatar wolfenrain avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mason's Issues

feat: mason should show what template `config.json` that is required to make a brick

Description
While going through the bricks/todos I went through and using the install command mason i --source path todos
and then to make it mason make todos

โžœ mason make todos
โžœ mason make todos
todos: 3
Unhandled exception:
type 'Null' is not a subtype of type 'Object'
#0      Renderer.pop (package:mustache_template/src/renderer.dart:46:26)
#1      Renderer._renderWithValue (package:mustache_template/src/renderer.dart:185:5)
#2      Renderer._renderInvSection (package:mustache_template/src/renderer.dart:160:9)
#3      Renderer.visitSection (package:mustache_template/src/renderer.dart:111:7)
#4      SectionNode.accept (package:mustache_template/src/node.dart:66:43)
#5      SectionNode.visitChildren.<anonymous closure> (package:mustache_template/src/node.dart:70:37)
#6      List.forEach (dart:core-patch/growable_array.dart:403:8)
#7      SectionNode.visitChildren (package:mustache_template/src/node.dart:70:14)
#8      Renderer._renderWithValue (package:mustache_template/src/renderer.dart:184:10)
#9      Renderer._renderSection (package:mustache_template/src/renderer.dart:144:7)
#10     Renderer.visitSection (package:mustache_template/src/renderer.dart:113:7)
#11     SectionNode.accept (package:mustache_template/src/node.dart:66:43)
#12     Renderer.render.<anonymous closure> (package:mustache_template/src/renderer.dart:52:30)
#13     List.forEach (dart:core-patch/growable_array.dart:403:8)
#14     Renderer.render (package:mustache_template/src/renderer.dart:52:13)
#15     Template.render (package:mustache_template/src/template.dart:42:14)
#16     Template.renderString (package:mustache_template/src/template.dart:34:5)
#17     TemplateX.render (package:mason/src/render.dart:71:21)
#18     TemplateFile._createContent (package:mason/src/generator.dart:385:12)
#19     TemplateFile.runSubstitution (package:mason/src/generator.dart:364:27)
#20     Generator.generate.<anonymous closure> (package:mason/src/generator.dart:157:34)
#21     Generator.generate.<anonymous closure> (package:mason/src/generator.dart:150:47)
#22     Future.forEach.<anonymous closure> (dart:async/future.dart:495:26)
#23     Future.doWhile.<anonymous closure> (dart:async/future.dart:535:26)
#24     _RootZone.runUnaryGuarded (dart:async/zone.dart:1546:10)
#25     _RootZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1585:26)
#26     Future.doWhile (dart:async/future.dart:551:18)
#27     Future.forEach (dart:async/future.dart:493:12)
#28     Generator.generate (package:mason/src/generator.dart:150:18)
#29     _MakeCommand.run (package:mason/src/commands/make.dart:109:41)
<asynchronous suspension>
#30     CommandRunner.runCommand (package:args/command_runner.dart:196:13)
<asynchronous suspension>
#31     MasonCommandRunner.run (package:mason/src/command_runner.dart:39:14)
<asynchronous suspension>
#32     main (file:///Users/whiteknife/.pub-cache/hosted/pub.dartlang.org/mason-0.0.1-dev.44/bin/mason.dart:5:23)
<asynchronous suspension>
At this point, the user doesn't know what are all the arguments that are required not even arguments but objects. It will be great if there is some way to get to know this beforehand like a `template.json`. Something like `mason template todos` will output something similar to the following JSON so that the user can directly use it as `config.json` and don't have to go through all the options while reading the code.
{
  "todos": [
    {
      "todo": String
      "done": boolean
    }
  ]
}

Requirements

  • Template output
  • Template to config.json
  • Checklist of requirements to be fulfilled

Additional Context

  • I would love to work on this feature

Screenshots:

Screenshot 2021-07-20 at 3 42 22 AM

Screenshot 2021-07-20 at 3 42 10 AM

Screenshot 2021-07-20 at 3 41 47 AM

refactor: create mason_cli

I'm using mason to ship templates with my cli. The APIs I'm using in the cli are MasonBundle.fromJson, MasonGenerator.fromBundle and MasonGenerator.generate.

There are dependencies in the current mason package that might cause unnecessary conflicts. Unnecessary because they aren't required for mason to generate templates, but only for the cli part of the package:

dependencies:
  args: ^2.1.0
  http: ^0.13.3
  pub_updater: ^0.2.1
  universal_io: ^2.0.4

mason should be split into two packages:

  • One for the cli part (with /bin directory)
  • One for the tempalte/generation part with minimal dependencies

This split allows the CLI to use and ship the latest dependencies while allowing wide dependency ranges for packages which use mason as dependency.

While it sounds like a duplicate of #91, I think this split alone is easier to achieve and it fixes a realworld problem.

fix: Crashes when no argument to 'new' is provided

Description
When the user tries to create a new brick without providing the name, the tool crashes.

Steps To Reproduce

  1. Open a mason project
  2. Type exactly mason new
  3. Profit

Expected Behavior
Should prompt the help menu the same way as mason make

Logs

$ mason new
Unhandled exception:
Bad state: No element
#0      ListMixin.first (dart:collection/list.dart:99:22)
#1      NewCommand.run (package:mason/src/commands/new.dart:37:34)
#2      CommandRunner.runCommand (package:args/command_runner.dart:197:27)
#3      MasonCommandRunner.runCommand (package:mason/src/command_runner.dart:64:18)
#4      MasonCommandRunner.run (package:mason/src/command_runner.dart:39:20)
#5      main (file:///home/ascenio/.pub-cache/hosted/pub.dartlang.org/mason-0.0.1-dev.27/bin/mason.dart:5:50)
#6      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:281:32)
#7      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

fix: OS Error: The system cannot find the path specified ( When brick installed globally )

Description
When I install a brick globally from GitHub and try to use it I get this error.

FileSystemException: Directory listing failed, path = 'C:\Users\user\AppData\Local\Mason\Cache\git\useful_bricks_83a860a417bba07e93659860bfb3e3e93cb1b5b204e555e8fcca581839f895bb\bricks\freezed\__brick__\*' (OS Error: The system cannot find the path specified.
, errno = 3)

Os: Windows-10

Steps To Reproduce

  1. Push a brick to GitHub
  2. Install the brick globally from GitHub
  3. Try to run mason make brick_name

fix: mason install --source path /pathofbrick not working.

Description
mason install --source path /pathofbrick not working.

Steps To Reproduce

  1. mason init
  2. mason get
  3. mason make /pathtobrick
  4. mason install --source path /pathtobrick

Expected Behavior
The brick is globally installed and accessible from terminal.

Screenshots
Screenshot 2021-06-26 at 11 45 16 AM

Additional Context
mason make is working fine and I could generate project as per my template. but I couldn't globally install it by following the documentation.

proposal: support custom scripts

Proposal - Custom Script Support

Background

As a developer who creates/maintains bricks, it's fairly common to want to execute some code either before or after generation. Currently, the only way to achieve this is to use mason as a dependency and build a custom CLI that performs the pre/post generation tasks manually (very_good_cli is a great example of this).

Problem

The above limitation forces developers to write a lot of additional code and create wrappers on top of mason just to execute custom code before or after the generation process. If mason could support this natively, that would drastically improve the developer experience and reduce the amount of effort needed apply custom scripts. It would also improve the experience of the consumer because a brick could handle performing time-consuming tasks automatically on behalf of the user (see more in Use Cases).

Example Use Cases

If mason supported custom script execution before and/or after generation it would allow brick maintainers to support things like:

  • pre generation input validation
  • pre generation dynamic variable creation (things like UUIDs or timestamps)
  • post generation dependency installation (flutter packages get)
  • post generation formatting/fixes (dart fix --apply)

Real World Examples:

Proposed Usage

Bricks can include an optional hooks directory with an optional pre_gen and post_gen script (Dart).

For example:

.
โ”œโ”€โ”€ __brick__
โ”‚   โ””โ”€โ”€ GREETINGS.md
โ”œโ”€โ”€ brick.yaml
โ””โ”€โ”€ hooks
    โ””โ”€โ”€ post_gen.dart

where brick.yaml looks like:

name: greeting
description: A Simple Greeting Template
vars:
  - name

Mason would handle bundling the scripts as part of the brick and can execute the scripts at their respective times. In addition, the hooks themselves can contain templated variables. For example, in the post_gen.dart script above we could have the following code

import 'dart:io';

void main() {
  print('hello {{name}}!');
  print(Directory.current.path);
}

The result of running mason make greeting --name would be:

$ mason make greeting --name Dash
โœ“ Made brick greeting (0.0s)
โœ“ Generated 1 file:
  /Users/dash/mason/example/GREETINGS.md (new)
hello Dash!
/Users/dash/mason/example

Note that the script was able to access template variables and the working directory of the script was the directory in which the code is generated.

Open Questions

Some open questions regarding the above proposal are:

  1. Should the custom scripts be executed by the mason cli or should the custom scripts also be executed automatically when a brick is generated programmatically via MasonGenerator.fromBundle(...)?
  2. Should a developer be able to disable custom script execution when using mason via the cli?
  3. Should mason be able to support external custom scripts?
  4. Are there any other hooks (besides pre_gen and post_gen) that would be valuable to support?
  5. Should custom dart scripts have access to a Logger instance?

Additional Context

  • Original feature request: #114

feat: Add Append to conflict resolution

Description

I would like to have the ability to append to a file that already exits, for example, I have a brick that adds function to a repository right now the work around that I generate temp file and move the function to the correct file then delete the temp file

Requirements

  • Add Append options to conflict

feat: add command to remove a brick

Hi @felangel I'm starting to use mason and I like it!
what I haven't noticed in the documentation is a command to remove bricks.
I do not know if there is any reason why it could not be implemented but I see it convenient because so far removing a brick is manual.
Thanks for mason and good morning.

fix: Install bricks from a git repository

Description

Installing from a git repository is not finding any bricks.

Steps To Reproduce

mason i https://github.com/PoloLacoste/mason_bricks

Expected Behavior

I was expecting mason to install all the bricks described by the mason.yaml file inside the repository.

Result

brick not found at url https://github.com/PoloLacoste/mason_bricks

feat: mason list could tell whether brick is local or global

Description

  • Current situation
mason list   
hello - An example hello brick.
groovin_core - An opinionated Flutter app template by GroovinChip

*suggestion

mason list   
local   hello - An example hello brick.
global groovin_core - An opinionated Flutter app template by GroovinChip

Requirements

  • tell whether brick is local or global

feat: Expose the template render engine to be used programatically

Description

When used as a package dependency, there is no way (at least I didn't find any ๐Ÿ˜… ) to use the template engine of mason programatically. Unless we import source files from mason (like I did here)

Would be cool if mason could expose that file, so we could also use its cool template engine programatically.

fix: Every command runs twice

Description
On executing any mason command the command is executed twice simultaneously.

Steps To Reproduce

  1. On windows install mason globally
  2. Open cmd/powershell
  3. run mason --version
  4. See the version is printed twice

Expected Behavior
The version should only be printed once.

Screenshots
image

Additional Context

fix: Can't import template from git on Windows

Description
After filling up mason.yaml im getting an error

FileSystemException: Exists failed, path = 'C:\Users\bbkk9\AppData\Local\Mason\Cache\git\[email protected]:Fasuh/mason_template.git' (OS Error: The filename, directory name, or volume label syntax is incorrect. , errno = 123)
the same conficuration works on MacOS

Steps To Reproduce

rather self explanatory

Expected Behavior
I would expect Mason to import my templates from git.

fix: Unable to sign in to GitHub for mason get

Description
when using a commant mason get the package is asking me to provide username and password, but as for now logging in to github with a password is disabled and we are getting an error.

Steps To Reproduce

  1. add mason bricks to the private repo
  2. run mason get on a clean install
  3. try to log in to your GitHub account

Expected Behavior
i am unsure what should happen in this case, maybe provide steps to add an auth key

refactor: Create backend and frontend for mason generator for better modularity and future enhancements

Create backend and frontend for mason generator for better modularity and future enhancements

The following is a little bit of brain-storming around updating mason's architecture given that mason may eventually implement mustache partials (basically include filesโ€”see #90) and output transformers at some point.

The mason generator APIs would likely benefit from an additional layer of abstraction. Code could be refactored into a front end layer and a backend layer, each with their own responsibilities:

Frontend:

  • Dispatch broad, abstract commands from the generator API to the relevant subsystems.
  • Handles the abstract notion of files, bricks, and bundles to perform file access, template rendering, and output generation.
  • Communicate with the backend to fetch/read/write across the file system/network/inter-process-communication/callbacks/etc as needed without being tied to any particular implementation.

This frontend is not to meant to be confused with the part of mason that handles CLI inputโ€”the CLI code could be a platform-specific front end for the front end, and would simply call into this code to perform requests, making it just another mason client. ๐Ÿ˜›

Backend:

  • Dispatch requests from the front end for fetching files, reading directories, writing files, creating directories, scanning directory contents, etc to one or more adapters which conform to a common input/output interface to perform these functions in the specified environment.

Depending on how much modularity is desired, mason could potentially be split into several subsystems or packages:

  • mason_cli โ€” responsible for collecting console input and dispatching to mason engine.
  • mason_generator โ€” contains the front end and back end.
  • mason_environment โ€” a single interface which is consumed by the mason_generator for all filesystem-type operations.
  • One package for each environment interface implementation. These could take on the form of the following, if desired: mason_github, mason_filesystem, mason_filesystem_windows, mason_streams, etc.

Requirements

  • There is no drop in test coverage.

feat: improved support for partials

Description

As a developer I'd like to be able to use partials with mason templates.

For example if we have a brick which consists of greeting.md

Hello {{name}}!

{{> include.md}}

Goodbye!

Where include.md looks like:

Cats

Running mason make greeting --name Felix should generate:

Hello Felix!

Cats

Goodbye!

fix: `mason help make` doesn't show command line args in help description

Description

Running mason help make doesn't list the args that the make command takes. This is probably a small, unfortunate side effect of the intended behavior with bricks being subcommands. Instead, it outputs the following in a project without any bricks:

Generate code using an existing brick template.

Usage: mason make <subcommand> [arguments]
-h, --help    Print this usage information.

Run "mason help" to see global options.

Steps To Reproduce
mason help make

Expected Behavior
The following:

Generate code using an existing brick template.

Usage: mason make [arguments]
-h, --help           Print this usage information.
-c, --config-path    Path to config json file containing variables.
-o, --output-dir     Directory where to output the generated code.
                     (defaults to ".")

Run "mason help" to see global options.

Additional Context

The problem seems to reside with the structure of the subcommands here:

class _MakeCommand extends MasonCommand {
_MakeCommand(this._brick, {Logger? logger}) : super(logger: logger) {
argParser
..addOption(
'config-path',
abbr: 'c',
help: 'Path to config json file containing variables.',
)
..addOption(
'output-dir',
abbr: 'o',
help: 'Directory where to output the generated code.',
defaultsTo: '.',
);
for (final arg in _brick.vars) {
argParser.addOption(arg);
}
}

Because subcommands are only defined for bricks that have been found earlier, it is omitting the flags from the command altogether which is preventing the args package from generating accurate help:

class MakeCommand extends MasonCommand {
/// {@macro make_command}
MakeCommand({Logger? logger}) : super(logger: logger) {
try {
for (final brick in bricks) {
addSubcommand(_MakeCommand(brick, logger: logger));
}
} catch (e) {
_exception = e;
}
}

I would have submitted a pull request, but I wasn't sure how to do this as this without breaking the flags for each brick subcommand. If you'd like help, feel free to point me in the right direction and I'll see what I can do. ๐Ÿ˜…

feat: show correct msg when there is no mason.yam.

Description

  • Clearly describe what you are looking to add. The more context the better.
  1. there is no mason.yaml, and no use mason add -g
  2. mason add show a bad err message.
# output
mason add '/Users/huangzheng/very_good_cli/example/vscode_dart_extension/bricks/groovin_core' 
brick not found at path /Users/huangzheng/very_good_cli/example/vscode_dart_extension/bricks/groovin_core

  1. ref code
final bricksJson = isGlobal ? globalBricksJson : localBricksJson;
    if (bricksJson == null) {
      throw UsageException('brick not found at path $location', usage);
...
Directory? get __entryPoint {
    try {
      return entryPoint;
    } catch (_) {} // <<<<<<<<<<<<<
    return null;  // <<<<<<<<<<<<<
  }
...
Directory get entryPoint {
    if (_entryPoint != null) return _entryPoint!;
    final nearestMasonYaml = MasonYaml.findNearest(cwd);
    if (nearestMasonYaml == null ||
        nearestMasonYaml.parent.path == BricksJson.globalDir.path) {
      throw const MasonYamlNotFoundException();
    }
    return _entryPoint = nearestMasonYaml.parent;
  }

Requirements

  • show mason.yaml not found rather than brick not found
  • or show use -g to add to global path
  • if there is no brick, it would still be ok.

fix: Lambdas on windows do not work

Description
On Windows I can't use lambdas in file names

Steps To Reproduce

Follow the steps in this blog post to create a custom widget brick https://verygood.ventures/blog/code-generation-with-mason

Expected Behavior

Should work fine but seems I can't create a file on Windows that has a slash in the name ๐Ÿคทโ€โ™‚๏ธ๐Ÿ˜ข

Maybe use double hashtags to close the lambda?

like this: {{#snakeCase}}{{name}}{{##snakeCase}}.dart
instead of this right now: {{#snakeCase}}{{name}}{{/snakeCase}}.dart
?
Screenshots
image

When making the brick it gives this error
image

fix: null check operator used on a null value

Description

When generating a project from a config.json file, the mason generator fails with this output:

Null check operator used on a null value
#0      TemplateFile.runSubstitution (package:mason/src/generator.dart:329:60)
#1      Generator.generate.<anonymous closure> (package:mason/src/generator.dart:157:34)
#2      Generator.generate.<anonymous closure> (package:mason/src/generator.dart:150:47)
#3      Future.forEach.<anonymous closure> (dart:async/future.dart:495:26)
#4      Future.doWhile.<anonymous closure> (dart:async/future.dart:535:26)
#5      _RootZone.runUnaryGuarded (dart:async/zone.dart:1620:10)
#6      _RootZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1659:26)
<asynchronous suspension>
#7      _RootZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart)
<asynchronous suspension>

Expected Behavior

Should generate correctly with config.json file specified.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional Context
Add any other context about the problem here.

fix: command duplication (mason 0.0.1-dev.47)

Description
Mason duplicates every command on the Windows machine.
But I have to notice that it works fine despite that issue.

Steps To Reproduce

  1. Have Windows (I haven't tried on MacOS)
  2. Have the latest mason installed
  3. Execute commands as shown on the screenshot

Expected Behavior

PS C:\Apps\mason_bricks> mason init
โœ“ Initialized (0.0ms)
โœ“ Generated 3 file(s):
  C:\Apps\mason_bricks\mason.yaml (new)
  C:\Apps\mason_bricks\bricks/hello/brick.yaml (new)        
  C:\Apps\mason_bricks\bricks/hello/__brick__/HELLO.md (new)
PS C:\Apps\mason_bricks> mason get
โœ“ getting bricks (0.0ms)
PS C:\Apps\mason_bricks> mason list
hello - An example hello brick.
PS C:\Apps\mason_bricks> mason make hello
name: Eli
โœ“ Made brick hello (1.7ms)
โœ“ Generated 1 file(s):
  c:\apps\mason_bricks\HELLO.md (new)
PS C:\Apps\mason_bricks> 

Screenshots
image

Unclosed tag in file name

Description
A clear and concise description of what the bug is.

When I create a new file {{#snakeCase}}{{name}}{{/snakeCase}}.dart, vscode will create a new folder named {{#snakeCase}}{{name}}{{ and contains a file named snakeCase}}.dart.

If I open Finder to create the file, create it, go back to vscode, the file name reads {{#snakeCase}}{{name}}{{:snakeCase}}.dart.

Is there a setting that I missed? Do I need change a setting in my IDE to allow "/" in file names?

Steps To Reproduce

  1. create a new file and paste "{{#snakeCase}}{{name}}{{/snakeCase}}.dart" for the name

This is the error that I get from mason with the name as "{{#snakeCase}}{{name}}{{:snakeCase}}.dart"

mason make widget
name: dash container
routable: true
โœ“ Making widget (10.3ms)
Unclosed tag: 'snakeCase'. (1:1)
{{#snakeCase}}{{name}}{{:snakeCase}}.dart
^

Expected Behavior
Allow me to make a file named '"{{#snakeCase}}{{name}}{{/snakeCase}}.dart"

Support Multiple Templates in One Build Command

Motivation

I'm about to implement some templates into my Flutter app, but I ran into one little snag.

It would be super nice if you could specify multiple template files to build when writing your mason.yaml. For example, running mason build widget could generate view code and a test file.

We also may want to move where the vars property lives. I believe they are still bound to each template? If they were bound to a build command it would be easy to share them with multiple template files. Since mason.yaml is now required I don't think that's much of a stretch anyway.

If we're doing that, does it make sense to move all that metadata into a build command? I know we don't want to over-engineer the tool, but maybe it makes sense to keep the mason.yaml option available, but still pass in simple template.yaml files as well?

Example

mason.yaml

builds:
  greetings:
    description: A simple greeting in markdown.
    templates:
      - path: ./greetings.md
    vars:
      - name
  widget:
    description: A Flutter widget containing a view, bloc, and test scafold for the bloc.
    templates:
      - git:
          url: [email protected]:felangel/mason.git
          path: templates/widget/view_template.dart.txt
      - git:
          url: [email protected]:felangel/mason.git
          path: templates/widget/test_template.dart.txt
    vars:
      - name
      - generateBloc

YMK what you think. I'm happy to jump on a call to discuss, and happy to contribute the feature in a PR if you think it's a good direction to take things ๐Ÿ™‚

docs: Add example of bundle

Description
I didn't see any examples of the bundle command in the docs. So I tried myself with help of help xD and it worked flawlessly.
However, I see no problem about adding it to the README as very short text should be enough.

Requirements

  • Add a example
  • Explain the motivation/use cases of it
  • Update the usage section

Add hyperlink to pub badge

Add hyperlink to pub badge

[![Pub](https://img.shields.io/pub/v/mason.svg)](https://pub.dev/packages/mason)
Pub

docs: How to specify file name with pascalCase

Description

When I want to add new file with {{#snakeCase}}{{name}}{{/snakeCase}}.dart template, the / char will break name in VS Code and create a Folder called {{#snakeCase}}{{name}}{{ with file snakeCase}}.dart

Any Idea how to create it?

Requirements

  • [x ] use VS Code

fix: mason don't validate brick path on the get command

Description

When having bricks with non-existent paths in the mason.yml file, the mason get commands work fine, but then when using mason make brick, it gives a Could not find brick at PATH

Steps To Reproduce

Have the following mason.yml

bricks:
  flame_package:
    git:
      url: [email protected]:flame-engine/flame-bricks.git
      path: some_folder

Run mason get
Run mason make flame_package

You should see a Could not find brick at error

Expected Behavior
The error should be reported on the mason get command, and not on the make one

docs: adds list of all casing options

Description

The casing options for variables should be documented for variables in bricks and their paths.

Requirements

  • snake_case
  • dot.case
  • path/case
  • param-case
  • PascalCase
  • Header-Case
  • Title Case
  • camelCase
  • Sentence case
  • CONSTANT_CASE

Creating new brick with mason new <NAME> with empty mason.yaml throws error.

Steps to Reproduce

  1. Run mason init in new directory
  2. Open generated mason.yaml and delete all the contents
  3. Run mason new test

You'll receive the following stack trace:

Marcuss-MBP-2:temp mtwichel$ mason new test
Unhandled exception:
ParsedYamlException: line 1, column 1: Not a map
  โ•ท
1 โ”‚ 
  โ”‚ ^
  โ•ต
#0      checkedYamlDecode (package:checked_yaml/checked_yaml.dart:43:5)
#1      NewCommand.run (package:mason/src/commands/new_command.dart:68:23)
#2      CommandRunner.runCommand (package:args/command_runner.dart:197:27)
#3      CommandRunner.run.<anonymous closure> (package:args/command_runner.dart:112:25)
#4      new Future.sync (dart:async/future.dart:223:31)
#5      CommandRunner.run (package:args/command_runner.dart:112:14)
#6      main (file:///Users/mtwichel/.pub-cache/hosted/pub.dartlang.org/mason-0.0.1-dev.15/bin/mason.dart:27:20)
#7      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299:32)
#8      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168:12)

Expected Behavior

I would expect the CLI to generate a new bricks: entry in mason.yaml, then add my new brick to the file.

Background

I stumbled across this as I was trying out the new commands. The first thing I tried was mason init, said "cool this is great, I'll try it with my own template", then deleted everything that had generated from mason.yaml and tried mason new.

I believe this is occurring because the yaml parser isn't finding a valid yaml schema in the file because it's completely empty.

Potential Solutions

Two ideas I have:

  • Add try/catch to reading in mason.yaml and if something goes wrong, provide a more friendly message
  • Before parsing yaml file, make sure the file isn't empty. If it is, either show an error message or add bricks: entry

Let me know if you approve of these solution(s). I'm happy to submit a PR if need be.

fix: When a directory inside the __brick__ has no file it is not generated by mason make

Description
A clear and concise description of what the bug is.

Just create a new brick, populate the folder __bricks__ an create a folder but dont place any file inside.
Run mason make $yourBrick

Expected:

I expected that everything inside __brick__ was bundled together.

Just for context, I was creating a template for dart gRPC and I would like to include the directory structure within the template. If it is the default behaviour, there's any workaround?

feat: Output path

Description

mason make creates the output in cwd. I'd prefer when I can specify an output dir.

mason make --out some/path

Additionally, the name of the output folder should be adjustable in brick.yaml.

name: mytemplate
description: Template specifying an output path
dir_name: {{id}}_{{name}} # <-- using vars
vars:
  - id
  - name

So that mason make mytemplate --id 3 --name hello --out projects generates

./projects/3_hello/<__brick__-files>

feat: Use mustachex engine for improving usability

Description

ATM the way to go with recasing is with code like {{#pascalCase}}{{varName}}{{/pascalCase}}, with mustachex (mustache extended) the same code could be simplified to {{varName_pc}} and it will be pretty cheap to implement. Besides I'm the maintainer of the package and any required change could be done for this purpose (like migrating it to NNBD, first thing to do in my agenda).

Requirements

  • Replace mason's mustache package

Additional Context

There are other feature out of the box that could be useful for mason's users: hasFoo guards

If this improvement seems useful, I could make the PR implementing it

feat: Possibility to add multiple files dynamically

Description

I was wondering if it would be possible to add a feature wherein we can generate files dynamically if provided as an array. This would be very useful when using mason to generate a bunch of documentation files for example.

// config.json

{
    "page_info": [
        {
            "name": "Intro"
        },
        {
            "name": "Getting Started"
        },
        {
            "name": "FAQ"
        }
    ]
}

It would have been great if we can create a brick template like this under __brick__

{{#page_info}}{{name}}.md{{/page_info}}

and it should be able to generate like this

- out
| -- Intro.md
| -- Getting Started.md
| -- FAQ.md

fix: Escaped backslash issue on Windows

Description

When a new brick is created on Windows OS, its path misuses Windows path separation character (\).

Steps To Reproduce

  1. Within a folder with mason already initialized, create a new brick with mason new my_brick

  2. See the updated mason.yaml file with a content like the following snippet:

    bricks:
      ...
      test:
        path: "bricks\my_brick"
      ...

    Note the use of a backslash as path separator.

  3. Try to get registered bricks with mason get.

  4. See the logged error:

    image

    NOTE: The error that might vary according to the first character used for the new brick name or not log errors at all.

Expected Behavior

  • Option 1:
    Use an escaped backslash for brick paths.

  • Option 2:
    Use regular slash for brick paths.

Screenshots

  1. mason.yaml for a recently initialized Mason folder:
    image
    NO apparent errors after running mason get but bricks.json uses backslash as well.

  2. mason.yaml after adding the new_brick test brick.
    image
    NO apparent errors after running mason get but bricks.json uses backslash as well.

  3. mason.yaml after adding the test_brick test brick.
    image
    NO apparent errors after running mason get but bricks.json uses backslash as well and format inconsistency could lead to future issues.

  4. mason.yaml after adding the other_brick test brick.
    image

    After running mason get the following error is shown:
    image

Additional Context

  • OS: Windows OS
  • mason version: 0.0.1-dev.27

fix: add git would fail if path is null

Description

 void _ensureRemoteBrickExists(Directory directory, GitPath gitPath) {
      final brickYaml = File(
        p.join(directory.path, gitPath.path, BrickYaml.file),
      );
      if (!brickYaml.existsSync()) {
        directory.deleteSync(recursive: true);
        throw BrickNotFoundException('${gitPath.url}/${gitPath.path}');
      }
    }

if path is null, it would error.

https://github.com/felangel/mason/blob/master/lib/src/bricks_json.dart#:~:text=directory%2C%20GitPath%20gitPath)%20%7B-,final%20brickYaml%20%3D%20File(,)%3B,-if%20(!brickYaml.existsSync

reproduction
mason add -g --source git https://github.com/RomanticEra/bricks

Expected Behavior
if path is null , replace it ''

feat: Run command after generating brick

Description

Run command after generating brick. The command would also accept parameters.

Description

I would use mason to generate folder structures and generic boilerplate for Flutter applications.
I myself and quite many other people rely on some sort of code generation, so it would be great if we could run code generation after the brick content is generated.

fix: Special characters (like the dot) are encoded in the rendered files

Description
Mason seems to encode some special characters, when it shouldn't ?

Steps To Reproduce

  1. Create the Hello brick sample
  2. Execute mason make hello --name '../../mypath'
  3. Open the generated readme.md file
  4. See the content Hello ..&#x2F;..&#x2F;mypath!

Expected Behavior
When using this kind of string value in a raw mustache template (and applying the value using the mustache package), my special characters (the slashes) are not encoded in any way. They appear as they should in my final file.

Am I missing something to make this work ?

How to keep {{var.var2}}?

Description
file in brick:

...
with:
     credential: ${{ secrets.CREDENTIAL_JSON }}
...

it would switch to as follow

...
with:
     credential: $
...

I don't want to change ${{ secrets.CREDENTIAL_JSON }}

I also tried {{{ }}}. it is the same thing

  • reproduct
  1. mason new hello
    2. remove vars in brick.yaml
  2. make vars something like var1.var2
  3. change content of HELLO.md

name: hello
description: A new brick created with the Mason CLI.
vars:

  • Fri Dec 3 13:24:18 CST 2021
  • Question: Whether vars,which is with split by ., are allowed in brick.yaml?
    Example:
name: hello
description: An example hello brick.
vars:
  - "name.a"

This might prompt an error: use var: name for the prompt

docs: Unsure of what the bundle command does.

Description

From the documentation and CLI help, I can understand what the bundle command does. But how do I use it? Can I create a brick from a bundle? Can you provide a usage example for the bundled output?

Requirements

  • Provide usage example of bundled output.

nested File paths don't work

Description

the slash / is replaced with &#x2F; in nested folders

Within my brick template I have
brick

  • {{url}}
    • {{#snakeCase}}{{name}}{{/snakeCase}}.dart

my brick.yaml

name: widget
description: A custom Flutter widget
vars:
  - name
  - routable
  - url

When I make the brick it creates the file in this folder

mason make widget
name: dart container
routable: false
url: features/dart_container
โœ“ Made brick widget (24.8ms)
โœ“ Generated 1 file(s):
  .../features&#x2F;dart_container/dart_container.dart (new)

instead of features&#x2F;dart_container it should be features/dart_container

Steps To Reproduce

  1. add a folder with the name of {{url}}
  2. provide features/dart_container for the url tag

Expected Behavior
instead of features&#x2F;dart_container it should be features/dart_container

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.