Skip to content

Commit fd1946f

Browse files
committed
Move validation to front and rename variables
1 parent eeb1e64 commit fd1946f

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

lib/node_modules/@stdlib/_tools/scaffold/scripts/scaffold_ai.sh

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#
2323
# Environment Variables:
2424
#
25-
# STDLIB_SCAFFOLDING_API_KEY: API key for the AI service.
25+
# SCAFFOLD_API_KEY: API key for the AI service.
2626

2727
## USER-DEFINED VARIABLES ##
2828

@@ -64,7 +64,7 @@ function scaffold_request() {
6464
func_name=$(echo "$1" | sed 's/[\/.]/-/g')
6565

6666
# Authentication query string:
67-
auth="clientId=${git_email}&code=${STDLIB_SCAFFOLDING_API_KEY}"
67+
auth="clientId=${git_email}&code=${SCAFFOLD_API_KEY}"
6868

6969
# Endpoint URL:
7070
url="${endpoint}/${func_name}?${auth}"
@@ -91,11 +91,11 @@ main() {
9191
echo "Scaffolding package: ${pkg}" >&2
9292
echo '' >&2
9393

94-
# `README.md` contents:
95-
readme_file=$(cat ${readme} | jq -Rs)
96-
97-
# JSON payload for the API:
98-
README='{"readme": '$readme_file'}'
94+
# Check whether authentication key is set:
95+
if [ -z "${SCAFFOLD_API_KEY}" ]; then
96+
echo "Error: missing environment variable 'SCAFFOLD_API_KEY'." >&2
97+
exit 1
98+
fi
9999

100100
# Bail if the destination directory does not exist:
101101
if [ ! -d "${dest_dir}" ]; then
@@ -109,11 +109,11 @@ main() {
109109
exit 1
110110
fi
111111

112-
# Check whether authentication key is set:
113-
if [ -z "${STDLIB_SCAFFOLDING_API_KEY}" ]; then
114-
echo "Error: missing environment variable 'STDLIB_SCAFFOLDING_API_KEY'." >&2
115-
exit 1
116-
fi
112+
# `README.md` contents:
113+
readme_file=$(cat ${readme} | jq -Rs)
114+
115+
# JSON payload for the API:
116+
README='{"readme": '$readme_file'}'
117117

118118
if [[ ! -f "${dest_dir}/package.json" ]]; then
119119
scaffold_request "package.json" "$README"
@@ -160,9 +160,11 @@ main() {
160160
if [[ ! -f "${dest_dir}/test/test.cli.js" ]]; then
161161
scaffold_request "test/test.cli.js" "$README"
162162
fi
163-
if [[ ! -f "${dest_dir}/test/fixtures/stdin_error.js.txt" ]]; then
164-
mkdir -p ${dest_dir}/test/fixtures
165-
curl -s "${endpoint}/test-fixtures-stdlib-error-js-txt" > ${dest_dir}/test/fixtures/stdin_error.js.txt
163+
if grep -q "standard stream" "${readme}"; then
164+
if [[ ! -f "${dest_dir}/test/fixtures/stdin_error.js.txt" ]]; then
165+
mkdir -p ${dest_dir}/test/fixtures
166+
curl -s "${endpoint}/test-fixtures-stdlib-error-js-txt" > ${dest_dir}/test/fixtures/stdin_error.js.txt
167+
fi
166168
fi
167169
fi
168170
if grep -q "\`\`\`c" "${readme}"; then

tools/make/common.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,4 +602,4 @@ DEPS_CPPCHECK_BUILD_OUT ?= $(DEPS_BUILD_DIR)/cppcheck_$(deps_cppcheck_version_sl
602602
DEPS_CPPCHECK_PLATFORM := $(shell command -v $(NODE) >/dev/null 2>&1 && $(NODE_HOST_PLATFORM))
603603

604604
# API key for the stdlib scaffolding service:
605-
STDLIB_SCAFFOLDING_API_KEY ?= $$STDLIB_SCAFFOLDING_API_KEY
605+
SCAFFOLD_API_KEY ?= $$SCAFFOLD_API_KEY

tools/make/lib/scaffold/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ SCAFFOLD_SCRIPT ?= $(TOOLS_PKGS_DIR)/scaffold/scripts/scaffold_ai.sh
3131
#
3232
# - The package directory has to exist and must contain at least the package's `README.md` file for the command to work.
3333
#
34-
# @param {string} PKG - package to scaffold (e.g., `math/base/special/sin`)
35-
# @param {string} STDLIB_SCAFFOLDING_API_KEY - API key for accessing the stdlib scaffolding service
34+
# @param {string} SCAFFOLD_PKG - package to scaffold (e.g., `math/base/special/sin`)
35+
# @param {string} SCAFFOLD_API_KEY - API key for accessing the stdlib scaffolding service
3636
#
3737
# @example
38-
# make scaffold PKG=math/base/special/sin
38+
# make scaffold SCAFFOLD_PKG=math/base/special/sin
3939
#/
4040
scaffold:
41-
$(QUIET) $(STDLIB_SCAFFOLDING_API_KEY) $(SCAFFOLD_SCRIPT) $(PKG)
41+
$(QUIET) $(SCAFFOLD_API_KEY) $(SCAFFOLD_SCRIPT) $(SCAFFOLD_PKG)
4242

4343
.PHONY: scaffold

tools/make/lib/scaffold/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ Scaffold required files for a new or existing package. The package directory has
5151
<!-- run-disable -->
5252

5353
```bash
54-
$ make scaffold PKG=<pkg>
54+
$ make scaffold SCAFFOLD_PKG=<pkg>
5555
```
5656

5757
The command expects the following environment variables to be set:
5858

59-
- **PKG**: package to scaffold, e.g., `math/base/special/sin`.
60-
- **STDLIB_SCAFFOLDING_API_KEY**: API key for accessing the stdlib scaffolding service.
59+
- **SCAFFOLD_PKG**: package to scaffold, e.g., `math/base/special/sin`.
60+
- **SCAFFOLD_API_KEY**: API key for accessing the stdlib scaffolding service.
6161

6262
</section>
6363

0 commit comments

Comments
 (0)