Skip to content

Commit

Permalink
fix: Add support for package json scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
deregtd committed Sep 30, 2024
1 parent d4163bc commit f918ec4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 8 deletions.
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ Stencil modules can be a native and/or template module. A native module is one

In the `arguments` section of the `manifest.yaml` file, you can specify the following options:

| Option | Default | Description |
| -------------------- | --------------- | -------------------------------------------------------------- |
| `description` | Required | Friendly-but-short description string for the frontend app |
| `owner` | Required | Pod or Portfolio ID for the owner of the frontend app |
| `nativeModule` | `false` | Does this module include native module golang code |
| `templateModule` | `false` | Does this module include templated code |
| `buildAndTestRunner` | `ubuntu-latest` | The github actions runner to use for the build and test CI job |
| Option | Default | Description |
| -------------------- | --------------- | ------------------------------------------------------------------------------ |
| `description` | Required | Friendly-but-short description string for the frontend app |
| `owner` | Required | Pod or Portfolio ID for the owner of the frontend app |
| `nativeModule` | `false` | Does this module include native module golang code |
| `templateModule` | `false` | Does this module include templated code |
| `buildAndTestRunner` | `ubuntu-latest` | The github actions runner to use for the build and test CI job |
| `packageJsonDeps` | `{}` | package.json dependencies to add to the generated package.json (key/value map) |
| `packageJsonScripts` | `{}` | package.json scripts to add to the generated package.json (key/value map) |
5 changes: 4 additions & 1 deletion manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ arguments:
type: string
packageJsonDeps:
required: false
description: The package.json dependencies to add to the generated package.json
description: package.json dependencies to add to the generated package.json (key/value map)
packageJsonScripts:
required: false
description: package.json scripts to add to the generated package.json (key/value map)
## <</Stencil::Block>>
modules:
- name: github.com/udemy/eng-team-management
Expand Down
13 changes: 13 additions & 0 deletions templates/package.json.tpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
{
"name": "{{ .Config.Name }}",
{{- if (stencil.Arg "packageJsonScripts") }}
"scripts": {
{{- $len := len (stencil.Arg "packageJsonScripts") }}
{{- range $key, $value := (stencil.Arg "packageJsonScripts") }}
{{- $len = (add $len -1) }}
{{- if ne 0 $len }}
"{{ $key }}": {{ $value | printf "%q" }},
{{- else }}
"{{ $key }}": {{ $value | printf "%q" }}
{{- end }}
{{- end }}
},
{{- end }}
"devDependencies": {
{{- range $key, $value := (stencil.Arg "packageJsonDeps") }}
"{{ $key }}": "{{ $value }}",
Expand Down
3 changes: 3 additions & 0 deletions tests/template/stencil.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ arguments:
description: Test template module for validating changes to stencil-module-base
owner: platform
templateModule: true
packageJsonScripts:
build: echo "build"
test: echo "test"
modules:
- name: github.com/udemy/stencil-module-base
replacements:
Expand Down

0 comments on commit f918ec4

Please sign in to comment.