Open tmura-ido opened 2 years ago
Hey, sorry for taking a while to respond.
I think this is kind of tricky to implement.
for [FTTemplatePath] these things come to mind
src/<template_name>
is an "absolute" notation that can resolve to very different things depending on the project
configuration IIRC. This would be problematic.src/template_name
but ./
or ././
etc. depending on how deep you currently are in the template folder hierarchy[FTRelativePath] doesn't make sense to me to be honest. It would be the same as a simple ./
or am I missing something here? Can you maybe give another example so I can understand better?
That would be nice to be implemented. In the file, we can have a path to file ../../../filename.ts
, however, you can create it in a different folder in the solution and the path won't work. You need to change it manually to correct one, e.g. ../../filename.ts
.
This would be useful. For example to define golang package name on each file using the name of the parent folder
project
|- foo
| |- bar.go
// bar.go
package foo
...
I'm not sure if this is the same thing or not, but I certainly think it would be useful to have a variable such as FTDirectory
which points to the directory in which you are creating your template folder.
Similar to how VSCode snippets offers a TM_DIRECTORY
variable.
This would allow me to include imports in my template files:
// Template folder
My Custom Template: // this is the template directory in .fttemplates
index.ts
other.ts
// in index.ts
import other from "<FTDirectory>/<FTName>/other";
Additional context: This would be useful in my case since we don't use relative imports (./
) in our repo—paths are all relative to the project root.
I think a variable like this would be useful specifically for templating a Storybook file, or a Jest test file, when you or your team have decided to follow a convention of naming stories and/or tests based on their top-down directory paths.
As of version 6.4, Storybook explicitly disallows a dynamic value for the default export's title
attribute of a story:
❌
// can't do this
const path = (__dirname.split("/src/app/")[1])
export default {
title: path, // eg: 'components/MyComponent'
✅
// this is ok
export default {
title: 'components/MyComponent',
Details: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#string-literal-titles
so the ability to output some sort of interpolation of the value of what the outputted file's __dirname
variable would be in a template could be very helpful in this situation:
export default {
title: '<FTDirectory>',
both to get around this limitation, and because a flat string in the outputted code might be easier to read anyway (albeit admittedly less dynamic at runtime, in case you end up moving the file around).
This could also be used for Jest test files. While Jest still allows this to be dynamic last I checked, eg:
✅
// this is ok
const path = (__dirname.split("/src/")[1])
describe(path, () => {
I'd, again, still prefer to be able to output it from a template:
describe('<FTDirectory>', () => {
For the same reason, because the following outputted code would be easier to read:
describe('app/components/MyComponent', () => {
It would be nice if there was a variable to add inside the template that contains the project template output path like imports.
example:
if I select the template path inside the project realtive path
src/
, inside thedatasource.js
would be two options to relative paths to the project[FTTemplatePath]
template output root path ->src/template_name
(orsrc
)[FTRelativePath]
template output file path ->src/template_name/inside_folder
so inside the
datasource.js
file I could use the relative path it has to import thefile.js