Skip to content

Commit

Permalink
linting: Add log-viewer-webui to js-lint tasks. (#475)
Browse files Browse the repository at this point in the history
Co-authored-by: Junhao Liao <[email protected]>
  • Loading branch information
kirkrodrigues and junhaoliao authored Jul 8, 2024
1 parent 02fbea4 commit 6e21665
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 34 deletions.
99 changes: 99 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ vars:
G_BUILD_DIR: "{{.ROOT_DIR}}/build"
G_CORE_COMPONENT_BUILD_DIR: "{{.G_BUILD_DIR}}/core"
G_METEOR_BUILD_DIR: "{{.G_BUILD_DIR}}/meteor"
G_NODEJS_22_DIR: "{{.G_BUILD_DIR}}/nodejs-22"
G_PACKAGE_BUILD_DIR: "{{.G_BUILD_DIR}}/clp-package"
G_PACKAGE_VENV_DIR: "{{.G_BUILD_DIR}}/package-venv"
G_WEBUI_BUILD_DIR: "{{.G_BUILD_DIR}}/webui"
Expand All @@ -26,6 +27,7 @@ tasks:
clean:
cmds:
- "rm -rf '{{.G_BUILD_DIR}}'"
- task: "clean-log-viewer-webui"
- task: "clean-python-component"
vars:
COMPONENT: "clp-package-utils"
Expand All @@ -35,6 +37,18 @@ tasks:
- task: "clean-python-component"
vars:
COMPONENT: "job-orchestration"
- task: "clean-webui"

clean-log-viewer-webui:
cmds:
- "rm -rf 'components/log-viewer-webui/client/node_modules'"
- "rm -rf 'components/log-viewer-webui/node_modules'"
- "rm -rf 'components/log-viewer-webui/server/node_modules'"

clean-webui:
cmds:
- "rm -rf 'components/webui/.meteor/local'"
- "rm -rf 'components/webui/node_modules'"

clp-json-pkg-tar:
cmds:
Expand Down Expand Up @@ -204,6 +218,19 @@ tasks:
- "tests/**/*"
generates: ["{{.CHECKSUM_FILE}}"]

nodejs-22:
internal: true
vars:
CHECKSUM_FILE: "{{.G_BUILD_DIR}}/{{.TASK}}.md5"
OUTPUT_DIR: "{{.G_NODEJS_22_DIR}}"
run: "once"
cmds:
- task: "nodejs"
vars:
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
NODEJS_VERSION: "v22.4.0"
OUTPUT_DIR: "{{.OUTPUT_DIR}}"

webui-nodejs:
internal: true
vars:
Expand Down Expand Up @@ -274,6 +301,78 @@ tasks:
sources: ["{{.TASKFILE}}"]
generates: ["{{.CHECKSUM_FILE}}"]

# NOTE: The log-viewer-webui has three different node_modules directories (client, server, and the
# top-level one we call "package"), meaning we have to create three different checksums. To allow
# tasks which depend on this task to only have to check one checksum file, we concatenate the
# three checksum files into one.
log-viewer-webui-node-modules:
internal: true
vars:
# Checksum files
CHECKSUM_FILE: "{{.G_BUILD_DIR}}/{{.TASK}}.md5"
CLIENT_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/log-viewer-webui-client-node-modules.md5"
PACKAGE_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/log-viewer-webui-package-node-modules.md5"
SERVER_CHECKSUM_FILE: "{{.G_BUILD_DIR}}/log-viewer-webui-server-node-modules.md5"

# Directories
SRC_DIR: "{{.TASKFILE_DIR}}/components/log-viewer-webui"
CLIENT_OUTPUT_DIR: "{{.SRC_DIR}}/client/node_modules"
PACKAGE_OUTPUT_DIR: "{{.SRC_DIR}}/node_modules"
SERVER_OUTPUT_DIR: "{{.SRC_DIR}}/server/node_modules"
dir: "{{.SRC_DIR}}"
deps:
- "nodejs-22"
- task: "utils:validate-checksum"
vars:
CHECKSUM_FILE: "{{.CLIENT_CHECKSUM_FILE}}"
DATA_DIR: "{{.CLIENT_OUTPUT_DIR}}"
- task: "utils:validate-checksum"
vars:
CHECKSUM_FILE: "{{.SERVER_CHECKSUM_FILE}}"
DATA_DIR: "{{.SERVER_OUTPUT_DIR}}"
- task: "utils:validate-checksum"
vars:
CHECKSUM_FILE: "{{.PACKAGE_CHECKSUM_FILE}}"
DATA_DIR: "{{.PACKAGE_OUTPUT_DIR}}"
cmds:
- "rm -f {{.CHECKSUM_FILE}}"
- task: "clean-log-viewer-webui"
- "PATH='{{.G_NODEJS_22_DIR}}/bin':$PATH npm run init"
# These commands must be last
- task: "utils:compute-checksum"
vars:
DATA_DIR: "{{.CLIENT_OUTPUT_DIR}}"
OUTPUT_FILE: "{{.CLIENT_CHECKSUM_FILE}}"
- task: "utils:compute-checksum"
vars:
DATA_DIR: "{{.PACKAGE_OUTPUT_DIR}}"
OUTPUT_FILE: "{{.PACKAGE_CHECKSUM_FILE}}"
- task: "utils:compute-checksum"
vars:
DATA_DIR: "{{.SERVER_OUTPUT_DIR}}"
OUTPUT_FILE: "{{.SERVER_CHECKSUM_FILE}}"
# This command must be last
- >-
cat
"{{.CLIENT_CHECKSUM_FILE}}"
"{{.PACKAGE_CHECKSUM_FILE}}"
"{{.SERVER_CHECKSUM_FILE}}"
> "{{.CHECKSUM_FILE}}"
sources:
- "{{.G_BUILD_DIR}}/nodejs-22.md5"
- "{{.TASKFILE}}"
- "client/package.json"
- "client/package-lock.json"
- "package.json"
- "package-lock.json"
- "server/package.json"
- "server/package-lock.json"
generates:
- "{{.CHECKSUM_FILE}}"
- "{{.CLIENT_CHECKSUM_FILE}}"
- "{{.PACKAGE_CHECKSUM_FILE}}"
- "{{.SERVER_CHECKSUM_FILE}}"

meteor:
run: "once"
preconditions:
Expand Down
22 changes: 20 additions & 2 deletions docs/src/dev-guide/components-log-viewer-webui.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,31 @@ npm test

## Linting

To check for linting errors in either the client or server:
You can lint this component either as part of the entire project or as a standalone component.

### Lint as part of the project

To check for linting errors:

```shell
task lint:js-check
```

To also fix linting errors (if applicable):

```shell
task lint:js-fix
```

### Lint the component alone

To check for linting errors:

```shell
npm run lint:check
```

To also fix linting errors (if possible):
To also fix linting errors (if applicable):

```shell
npm run lint:fix
Expand Down
62 changes: 30 additions & 32 deletions lint-tasks.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
version: "3"

vars:
G_LINTER_NODEJS_BUILD_DIR: "{{.G_BUILD_DIR}}/linter-nodejs"
G_LINTER_NODEJS_BIN_DIR: "{{.G_LINTER_NODEJS_BUILD_DIR}}/bin"
G_LINT_VENV_DIR: "{{.G_BUILD_DIR}}/lint-venv"
G_LOG_VIEWER_WEBUI_SRC_DIR: "{{.ROOT_DIR}}/components/log-viewer-webui"
G_NODEJS_22_BIN_DIR: "{{.G_NODEJS_22_DIR}}/bin"
G_WEBUI_SRC_DIR: "{{.ROOT_DIR}}/components/webui"

tasks:
check:
Expand Down Expand Up @@ -47,29 +48,34 @@ tasks:
sources: *cpp_source_files

js-check:
dir: "components/webui"
cmds:
- task: "js"
vars:
LINT_CMD: "check"
sources: &js_source_files
- "{{.G_BUILD_DIR}}/lint#linter-node-modules.md5"
- "{{.G_BUILD_DIR}}/log-viewer-webui-node-modules.md5"
- "{{.G_BUILD_DIR}}/webui-node-modules.md5"
- "{{.G_LOG_VIEWER_WEBUI_SRC_DIR}}/client/src/**/*.css"
- "{{.G_LOG_VIEWER_WEBUI_SRC_DIR}}/client/src/**/*.jsx"
- "{{.G_LOG_VIEWER_WEBUI_SRC_DIR}}/client/src/package.json"
- "{{.G_LOG_VIEWER_WEBUI_SRC_DIR}}/client/src/webpack.config.js"
- "{{.G_LOG_VIEWER_WEBUI_SRC_DIR}}/server/src/**/*.js"
- "{{.G_LOG_VIEWER_WEBUI_SRC_DIR}}/server/src/**/package.json"
- "{{.G_WEBUI_SRC_DIR}}/client/**/*.js"
- "{{.G_WEBUI_SRC_DIR}}/client/**/*.jsx"
- "{{.G_WEBUI_SRC_DIR}}/imports/**/*.js"
- "{{.G_WEBUI_SRC_DIR}}/imports/**/*.jsx"
- "{{.G_WEBUI_SRC_DIR}}/launcher.js"
- "{{.G_WEBUI_SRC_DIR}}/package.json"
- "{{.G_WEBUI_SRC_DIR}}/server/**/*.js"
- "{{.G_WEBUI_SRC_DIR}}/server/**/*.jsx"
- "{{.G_WEBUI_SRC_DIR}}/tests/**/*.js"
- "{{.G_WEBUI_SRC_DIR}}/tests/**/*.jsx"
- "{{.ROOT_DIR}}/Taskfile.yml"
- "{{.TASKFILE}}"
- "client/**/*.js"
- "client/**/*.jsx"
- "imports/**/*.js"
- "imports/**/*.jsx"
- "launcher.js"
- "package.json"
- "server/**/*.js"
- "server/**/*.jsx"
- "tests/**/*.js"
- "tests/**/*.jsx"

js-fix:
dir: "components/webui"
cmds:
- task: "js"
vars:
Expand Down Expand Up @@ -127,10 +133,14 @@ tasks:
internal: true
requires:
vars: ["LINT_CMD"]
deps: ["linter-node-modules"]
dir: "components/webui"
deps: [":log-viewer-webui-node-modules", "linter-node-modules"]
cmds:
- "PATH='{{.G_LINTER_NODEJS_BIN_DIR}}':$PATH npm run 'lint:{{.LINT_CMD}}'"
- for:
- "components/log-viewer-webui"
- "components/webui"
cmd: |-
cd "{{.ITEM}}"
PATH="{{.G_NODEJS_22_BIN_DIR}}":$PATH npm run "lint:{{.LINT_CMD}}"
py:
internal: true
Expand All @@ -149,18 +159,6 @@ tasks:
black --color --line-length 100 {{.BLACK_FLAGS}} .
ruff check {{.RUFF_FLAGS}} .
linter-nodejs:
internal: true
vars:
CHECKSUM_FILE: "{{.G_BUILD_DIR}}/{{.TASK | replace \":\" \"#\"}}.md5"
OUTPUT_DIR: "{{.G_LINTER_NODEJS_BUILD_DIR}}"
cmds:
- task: ":nodejs"
vars:
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
NODEJS_VERSION: "latest"
OUTPUT_DIR: "{{.OUTPUT_DIR}}"

linter-node-modules:
internal: true
deps:
Expand All @@ -170,22 +168,22 @@ tasks:
vars:
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
DATA_DIR: "{{.OUTPUT_DIR}}"
- "linter-nodejs"
- ":nodejs-22"
dir: "{{.WEBUI_LINTER_DIR}}"
vars:
WEBUI_LINTER_DIR: "{{.ROOT_DIR}}/components/webui/linter"
OUTPUT_DIR: "{{.WEBUI_LINTER_DIR}}/node_modules"
CHECKSUM_FILE: "{{.G_BUILD_DIR}}/{{.TASK | replace \":\" \"#\"}}.md5"
cmds:
- "rm -rf '{{.OUTPUT_DIR}}'"
- "PATH='{{.G_LINTER_NODEJS_BIN_DIR}}':$PATH npm update"
- "PATH='{{.G_NODEJS_22_BIN_DIR}}':$PATH npm update"
# This command must be last
- task: ":utils:compute-checksum"
vars:
DATA_DIR: "{{.OUTPUT_DIR}}"
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
sources:
- "{{.G_BUILD_DIR}}/lint#linter-nodejs.md5"
- "{{.G_BUILD_DIR}}/nodejs-22.md5"
- "{{.G_BUILD_DIR}}/webui-node-modules.md5"
- "{{.ROOT_DIR}}/Taskfile.yml"
- "{{.TASKFILE}}"
Expand Down

0 comments on commit 6e21665

Please sign in to comment.