Skip to content

Commit

Permalink
Add renamesetting to script and style. (output path)
Browse files Browse the repository at this point in the history
Fixes #72
  • Loading branch information
regisphilibert committed Sep 23, 2022
1 parent 12ed7ae commit 302e805
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 6 deletions.
2 changes: 2 additions & 0 deletions core/scripts/private/ParseScript.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
{{ $minify = partialCached "huge/env/When" $minify $minify }}
{{ $fingerprint := $script.fingerprint | default "production" }}
{{ $fingerprint = partialCached "huge/env/When" $fingerprint $fingerprint }}
{{ $rename := $script.rename | default "" }}
{{ $params := $script.params | default dict }}
{{ $shims := $script.shims | default slice }}
{{ $target := $script.target | default "esnext" }}
Expand All @@ -71,6 +72,7 @@
"externals" $externals
"minify" $minify
"fingerprint" $fingerprint
"rename" $rename
"params" $params
"shims" $shims
"target" $target
Expand Down
9 changes: 7 additions & 2 deletions core/scripts/private/transform/_.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,15 @@
{{ $resource = . | js.Build $options }}
{{ end }}

{{/* Fingerprinting is the only settings which is not part of the js.Build $options,
{{/* Fingerprinting is the only setting which is not part of the js.Build $options,
we perform that extra transformation here if needed. */}}
{{ if $.fingerprint }}
{{ $resource = $resource | fingerprint }}
{{ end }}

{{ return $resource }}
{{/* If user wants to customize the output path with the `rename` setting. */}}
{{ with $.rename }}
{{ $resource = $resource | resources.Copy . }}
{{ end }}

{{ return $resource }}
8 changes: 7 additions & 1 deletion core/styles/private/GetTransformations.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@
{{ if partialCached "huge/env/When" $fingerprint $fingerprint }}
{{ $transformations = $transformations | append "fingerprint" }}
{{ end }}

{{/* Most transformations don't need any arguments except for rename. We'll use a map for context */}}
{{ with .rename }}
{{ $transformations = $transformations | append (dict
"transformation" "copy"
"context" .
) }}
{{ end }}
{{ if $NotServer }}
{{ with .use }}
{{ if or (in . "tailwind") (in . "postprocess") }}
Expand Down
3 changes: 2 additions & 1 deletion core/styles/private/ParseStyle.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@
{{ $transformations := partial "huge/styles/private/GetTransformations" $style | default slice }}
{{ $internal := $style.internal | default false }}
{{ $integrity := $style.integrity | default false }}

{{ $rename := $style.rename | default false }}
{{ $data = dict
"name" $name
"path" $style.path
"internal" $internal
"integrity" $integrity
"transformations" $transformations
"rename" $rename
}}
{{ end }}

Expand Down
14 changes: 12 additions & 2 deletions core/styles/private/transform/_.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,20 @@
{{ else }}
{{ partial "huge/console/warn" (printf "Style file with path %s is not found" .path) }}
{{ end }}

{{ with $resource }}
{{ range $.transformations }}
{{ $resource = partial (print "huge/styles/private/transform/" .) $resource }}
{{ $partial := . }}
{{ $context := $resource }}
{{/* Some transformation holds arguments with a map context. For those, the partial name
will be held in .transformation while the context (or arguments) are hold in .context */}}
{{ if reflect.IsMap . }}
{{ $context = dict
"resource" $resource
"context" .context
}}
{{ $partial = .transformation }}
{{ end }}
{{ $resource = partial (print "huge/styles/private/transform/" $partial) $context }}
{{ end }}
{{ end }}

Expand Down
2 changes: 2 additions & 0 deletions core/styles/private/transform/copy.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{{ $resource := .resource | resources.Copy .context }}
{{ return $resource }}

0 comments on commit 302e805

Please sign in to comment.