all.bash,devtools: add support for running npx commands

We will need to run npx commands with docker when
running tests in CI. This change creates an npx
command in all.bash and modifies the docker_nodejs
script to share networking with the host so it can
connect to a local instance of the frontend.

Change-Id: Id8f32a7ff5bf017cb55c531b1e37a3f8aab0e73a
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/322635
Trust: Jamal Carvalho <jamal@golang.org>
Reviewed-by: Julie Qiu <julie@golang.org>
This commit is contained in:
Jamal Carvalho 2021-05-25 18:48:52 -04:00
Родитель 6a8197aed4
Коммит 29fa51cee2
2 изменённых файлов: 16 добавлений и 2 удалений

Просмотреть файл

@ -191,6 +191,18 @@ run_npm() {
runcmd $npmcmd $@
}
run_npx() {
npxcmd="./devtools/docker_nodejs.sh npx"
if [[ -x "$(command -v npx)" ]]; then
npxcmd="npx"
fi
# Run npm install if node_modules directory does not exist.
if [ ! -d "node_modules" ]; then
run_npm install --quiet
fi
runcmd $npxcmd $@
}
prettier_file_globs='content/static/**/*.{ts,css} **/*.md'
# run_prettier runs prettier on CSS, JS, and MD files. Uses globally
@ -236,7 +248,8 @@ Available subcommands:
headers - (lint) check source files for the license disclaimer
migrations - (lint) check migration sequence numbers
misspell - (lint) run misspell on source files
npm - run npm scripts from package.json
npm - run npm commands or scripts from package.json
npx - run a command from a local or remote npm package
script_hashes - (lint) check script hashes
script_output - (lint) check script output
staticcheck - (lint) run staticcheck on source files
@ -328,6 +341,7 @@ main() {
script_hashes) check_script_hashes ;;
build_static) run_build_static ;;
npm) run_npm ${@:2} ;;
npx) run_npx ${@:2} ;;
*)
usage

Просмотреть файл

@ -8,4 +8,4 @@ set -e
# Script for running a nodejs docker image.
docker run --rm -v `pwd`:/pkgsite -w /pkgsite node:15.14.0 $@
docker run --net=host --rm -v `pwd`:/pkgsite -w /pkgsite node:15.14.0 $@