Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileMapToken refactoring #112

Open
anithri opened this issue Sep 25, 2017 · 8 comments
Open

fileMapToken refactoring #112

anithri opened this issue Sep 25, 2017 · 8 comments

Comments

@anithri
Copy link
Collaborator

anithri commented Sep 25, 2017

I'd like to make it possible to change the directory a blueprint is constucted in via configuration in the form of --path=new/path

To enable this we need to collapse the __root__ /__dumb__ type token to __path__. If the user wants something different, he can make declarations in fileMapTokens and use them.

Path standards should be...

  • path/to/dir - relative from project_path
  • ./path/to/dir - relative to project_path? cwd?
  • ~/path/to/dir - relative to process.env.HOME
  • /path/to/dir - absolute

Since all paths options would be stored in settings.outputPaths, we could auto generate fileMapTokens by assuming dumb corresponds to settings.outputPaths.dumb

@prescottprue
Copy link

Been wanting this for a while, but didn't have the time to work on the fix.

@jamesr73
Copy link
Contributor

jamesr73 commented Sep 28, 2017

Copying my comment from #101 ....

Using the smart blueprint as the example with __smart__ = components.

bp gen smart Button
> src/components/Button.js
> test/components/Button.test.js

To add Save as a child of Button would need a relative path?

bp gen smart Save --path=components/Button
> src/components/Button/Save.js
> test/components/Button/Save.test.js

This suggests that tokens such as __smart__, __dumb__ etc are unnecessary. We could just use the __path__ token which could then be overridden in any of blueprint/rc/cli:

bp: {
  smart: {
    path: 'components'
  }
}

A --path option would be provided by the generate command, i.e. common to all blueprints, and override the __path__ value.

This is a different use case from #72, which was adding to a path to support a fractal project structure.

bp gen smart LoginButton --fractal=Auth
> src/Auth/components/LoginButton.js
> test/Auth/components/LoginButton.test.js

I.e. __path__ === --fractal + --path

@jamesr73
Copy link
Contributor

jamesr73 commented Sep 28, 2017

Would also be cool to support ./path/to/dir as relative to current dir. i.e. __root__ == cwd and then figure out how to set __test__ relative to that.

@jamesr73
Copy link
Contributor

I have the CLI side of this working in a local branch on top of #110.

/Users/james73/github/bp-playground
jlite:james73 ../github/bp-playground $ cat .reduxrc
{
  "sourceBase":"src",
  "testBase":"test",
  "smartPath":"smart",
  "dumbPath":"dumb",
  "fileCasing":"default",
  "bp": {
    "smart": {
      "path": "container"
    },
    "dumb": {
      "path": "component"
    }
  }
}
/Users/james73/github/bp-playground
jlite:james73 ../github/bp-playground $ bp help generate smart
Usage:
  bp generate smart <name>

Generate Options:
  --dry-run, -d  List files but don't generate them                    [boolean]
  --verbose, -v  Verbose output, including file contents               [boolean]
  --help, -h     Show help                                             [boolean]

Blueprint Options:
  --path, -P  set __path__ for this blueprint
                                      [string] [required] [default: "container"]

/Users/james73/github/bp-playground
jlite:james73 ../github/bp-playground $ bp help generate dumb
Usage:
  bp generate dumb <name>

Generate Options:
  --dry-run, -d  List files but don't generate them                    [boolean]
  --verbose, -v  Verbose output, including file contents               [boolean]
  --help, -h     Show help                                             [boolean]

Blueprint Options:
  --path, -P  set __path__ for this blueprint
                                      [string] [required] [default: "component"]

/Users/james73/github/bp-playground
jlite:james73 ../github/bp-playground $ bp help generate duck
Usage:
  bp generate duck <name>

Generate Options:
  --dry-run, -d  List files but don't generate them                    [boolean]
  --verbose, -v  Verbose output, including file contents               [boolean]
  --help, -h     Show help                                             [boolean]

Blueprint Options:
  --path, -P  set __path__ for this blueprint                [string] [required]

/Users/james73/github/bp-playground
jlite:james73 ../github/bp-playground $

jamesr73 added a commit to jamesr73/redux-cli that referenced this issue Sep 30, 2017
@anithri
Copy link
Collaborator Author

anithri commented Oct 1, 2017

  • projectPath: the path that all the other paths are relative to
  • sourcePath: all code going under here.
  • testPath: all test going under here
  • genPath: generic smartPath, ...dumbPath

lets say the styledDumb generator is going to generate these files:

# <projectPath><srcPath><genPath>/__name__/index.js
~/project/src/components/CoolThing/index.js

# <projectPath><srcPath><genPath>/__name__/styles.css
~/project/src/components/CoolThing/styles.css 

# <projectPath>/<testPath>/<genPath>/__name__.test.js
~/project/src/test/components/CoolThing,test.js

Which part or parts does --path change in those?

$ bp g styledDumb --path myPath PrettyThing
? myPath/index.js
? myPath/CoolThing/index.js
? myPath/components/CoolThing/index.js 
? ~/project/myPath/CoolThing/index.js 
? ~/project/components/myPath/index.js 
? ~/project/components/myPath/CoolThing/index.js

And how do you deal with fractal

$ bp g dumb --fractal CoolThing BoringPart
~/project/src/components/CoolThing/BoringPart.js
~/project/src/test/components/CoolThing/BoringPart.js

@anithri
Copy link
Collaborator Author

anithri commented Oct 1, 2017

Goals?

  • override default paths
  • Fractal paths
  • generator group paths, so Dumb, styledDumb, Brainless and Stupid generators can have .../components to write into
  • file type paths, for source, tests, assets, config, blueprints...
  • way for Blueprint can ensure all needed paths are present
  • way to write path/<part>/__standard__.js descriptions for cli help text.
  • automapping most paths from settings to make fileMapTokens optional
  • easily graspable "api"
  • maintain __varName__ substitutions
  • generators free to ignore defaults

@jamesr73
Copy link
Contributor

jamesr73 commented Oct 1, 2017

gitter?

@anithri
Copy link
Collaborator Author

anithri commented Oct 1, 2017

Sure, I'm around for the rest of the day

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants