Skip to content

Commit 3577f85

Browse files
committed
Make default npm project path configurable via taskfile variable
A repository might contain multiple npm-managed projects. For this reason, the appropriate npm-managed tasks have a parameter environment variable that allows it to be configured for an arbitrary path, with the "Check npm" workflow having a job matrix of paths to pass. Generally, even if there are multiple npm-managed projects, there will be one primary project that is most often the target of contributor operation. Since it would be inconvenient for the contributor to pass the environment variable path every time they want to run a task for that primary project, the tasks are configured to have a default path which is used if the variable is not defined by the user. Since the primary npm-managed project would typically be in the root of the repository, the default value is set to the root. In the case where the primary npm-managed project is not in the root of the repository, the template installer will need to adjust this. Previously the default was hard coded in each individual task. The template will be made easier to install by defining the default in a single place via a friendly taskfile variable, following the convention already established by the templates for Go-based projects.
1 parent e46af3d commit 3577f85

File tree

8 files changed

+43
-11
lines changed

8 files changed

+43
-11
lines changed

Taskfile.yml

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ vars:
99
CLANG_FORMAT_GOLDEN_TEST_DATA_FOLDER: "{{.CLANG_FORMAT_TEST_DATA_FOLDER}}/golden"
1010
# See: https://github.com/arduino/arduino-ide/blob/main/arduino-ide-extension/package.json
1111
DEFAULT_CLANG_FORMAT_VERSION: 14.0.0
12+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
13+
# Path of the project's primary npm-managed project:
14+
DEFAULT_NPM_PROJECT_PATH: ./
1215

1316
tasks:
1417
check:
@@ -91,6 +94,8 @@ tasks:
9194
TEMPLATE_WORKFLOWS_DATA_PATH: "./workflow-templates/*.{yml,yaml}"
9295
deps:
9396
- task: npm:install-deps
97+
vars:
98+
PROJECT_PATH: ./
9499
cmds:
95100
- |
96101
wget \
@@ -571,6 +576,8 @@ tasks:
571576
desc: Format all supported files with Prettier
572577
deps:
573578
- task: npm:install-deps
579+
vars:
580+
PROJECT_PATH: ./
574581
cmds:
575582
- npx prettier --write .
576583

@@ -684,6 +691,8 @@ tasks:
684691
deps:
685692
- task: docs:generate
686693
- task: npm:install-deps
694+
vars:
695+
PROJECT_PATH: ./
687696
cmds:
688697
- |
689698
npx \
@@ -695,6 +704,8 @@ tasks:
695704
desc: Automatically correct linting violations in Markdown files where possible
696705
deps:
697706
- task: npm:install-deps
707+
vars:
708+
PROJECT_PATH: ./
698709
cmds:
699710
- npx markdownlint-cli --fix "**/*.md"
700711

@@ -703,6 +714,8 @@ tasks:
703714
desc: Check for problems in Markdown files
704715
deps:
705716
- task: npm:install-deps
717+
vars:
718+
PROJECT_PATH: ./
706719
cmds:
707720
- npx markdownlint-cli "**/*.md"
708721

@@ -735,10 +748,10 @@ tasks:
735748
desc: |
736749
Install dependencies managed by npm.
737750
Environment variable parameters:
738-
- PROJECT_PATH: Path of the npm-managed project (default: "./").
751+
- PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
739752
run: when_changed
740753
dir: |
741-
"{{default "./" .PROJECT_PATH}}"
754+
"{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}"
742755
cmds:
743756
- npm install
744757

@@ -749,7 +762,7 @@ tasks:
749762
Environment variable parameters:
750763
- PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
751764
dir: |
752-
"{{default "./" .PROJECT_PATH}}"
765+
"{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}"
753766
cmds:
754767
- |
755768
npm \
@@ -762,7 +775,7 @@ tasks:
762775
desc: |
763776
Validate npm configuration files against their JSON schema.
764777
Environment variable parameters:
765-
- PROJECT_PATH: Path of the npm-managed project (default: "./").
778+
- PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
766779
deps:
767780
- task: npm:install-deps
768781
vars:
@@ -807,7 +820,7 @@ tasks:
807820
STYLELINTRC_SCHEMA_PATH:
808821
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
809822
INSTANCE_PATH: >-
810-
{{default "." .PROJECT_PATH}}/package.json
823+
{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}/package.json
811824
cmds:
812825
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}
813826
- wget --quiet --output-document="{{.AVA_SCHEMA_PATH}}" {{.AVA_SCHEMA_URL}}

workflow-templates/assets/check-action-metadata-task/Taskfile.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ tasks:
1010
sh: task utility:mktemp-file TEMPLATE="github-action-schema-XXXXXXXXXX.json"
1111
deps:
1212
- task: npm:install-deps
13+
vars:
14+
PROJECT_PATH: ./
1315
cmds:
1416
- |
1517
wget \

workflow-templates/assets/check-markdown-task/Taskfile.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ tasks:
3939
deps:
4040
- task: docs:generate
4141
- task: npm:install-deps
42+
vars:
43+
PROJECT_PATH: ./
4244
cmds:
4345
- |
4446
npx \
@@ -50,6 +52,8 @@ tasks:
5052
desc: Automatically correct linting violations in Markdown files where possible
5153
deps:
5254
- task: npm:install-deps
55+
vars:
56+
PROJECT_PATH: ./
5357
cmds:
5458
- npx markdownlint-cli --fix "**/*.md"
5559

@@ -58,5 +62,7 @@ tasks:
5862
desc: Check for problems in Markdown files
5963
deps:
6064
- task: npm:install-deps
65+
vars:
66+
PROJECT_PATH: ./
6167
cmds:
6268
- npx markdownlint-cli "**/*.md"

workflow-templates/assets/check-npm-task/Taskfile.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ tasks:
77
desc: |
88
Fix problems with the npm configuration file.
99
Environment variable parameters:
10-
- PROJECT_PATH: Path of the npm-managed project (default: ./).
10+
- PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
1111
dir: |
12-
"{{default "./" .PROJECT_PATH}}"
12+
"{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}"
1313
cmds:
1414
- |
1515
npm \
@@ -22,7 +22,7 @@ tasks:
2222
desc: |
2323
Validate npm configuration files against their JSON schema.
2424
Environment variable parameters:
25-
- PROJECT_PATH: Path of the npm-managed project (default: "./").
25+
- PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
2626
deps:
2727
- task: npm:install-deps
2828
vars:
@@ -67,7 +67,7 @@ tasks:
6767
STYLELINTRC_SCHEMA_PATH:
6868
sh: task utility:mktemp-file TEMPLATE="stylelintrc-schema-XXXXXXXXXX.json"
6969
INSTANCE_PATH: >-
70-
{{default "." .PROJECT_PATH}}/package.json
70+
{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}/package.json
7171
cmds:
7272
- wget --quiet --output-document="{{.SCHEMA_PATH}}" {{.SCHEMA_URL}}
7373
- wget --quiet --output-document="{{.AVA_SCHEMA_PATH}}" {{.AVA_SCHEMA_URL}}

workflow-templates/assets/check-prettier-formatting-task/Taskfile.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,7 @@ tasks:
77
desc: Format all supported files with Prettier
88
deps:
99
- task: npm:install-deps
10+
vars:
11+
PROJECT_PATH: ./
1012
cmds:
1113
- npx prettier --write .

workflow-templates/assets/check-toc-task/Taskfile.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ tasks:
1111
- FILE_PATH: path to the file that contains the ToC.
1212
deps:
1313
- task: npm:install-deps
14+
vars:
15+
PROJECT_PATH: ./
1416
cmds:
1517
- |
1618
npx markdown-toc \

workflow-templates/assets/check-workflows-task/Taskfile.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ tasks:
1313
WORKFLOWS_DATA_PATH: "./.github/workflows/*.{yml,yaml}"
1414
deps:
1515
- task: npm:install-deps
16+
vars:
17+
PROJECT_PATH: ./
1618
cmds:
1719
- |
1820
wget \
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
# See: https://taskfile.dev/#/usage
22
version: "3"
33

4+
vars:
5+
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
6+
# Path of the project's primary npm-managed project:
7+
DEFAULT_NPM_PROJECT_PATH: ./
8+
49
tasks:
510
# Source: https://github.com/arduino/tooling-project-assets/blob/main/workflow-templates/assets/npm-task/Taskfile.yml
611
npm:install-deps:
712
desc: |
813
Install dependencies managed by npm.
914
Environment variable parameters:
10-
- PROJECT_PATH: Path of the npm-managed project (default: "./").
15+
- PROJECT_PATH: Path of the npm-managed project (default: {{.DEFAULT_NPM_PROJECT_PATH}}).
1116
run: when_changed
1217
dir: |
13-
"{{default "./" .PROJECT_PATH}}"
18+
"{{default .DEFAULT_NPM_PROJECT_PATH .PROJECT_PATH}}"
1419
cmds:
1520
- npm install

0 commit comments

Comments
 (0)