Skip to content

Commit 94ef82c

Browse files
committed
Don't require README.md file for scaffolding
1 parent fd1946f commit 94ef82c

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# See the License for the specific language governing permissions and
1717
# limitations under the License.
1818

19-
# Script for scaffolding a package based off a README.md file via AI.
19+
# Script for scaffolding a package via AI.
2020
#
2121
# Usage: scaffold.h
2222
#
@@ -63,11 +63,11 @@ function scaffold_request() {
6363
# Get function name from file path:
6464
func_name=$(echo "$1" | sed 's/[\/.]/-/g')
6565

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

6969
# Endpoint URL:
70-
url="${endpoint}/${func_name}?${auth}"
70+
url="${endpoint}/${func_name}?${query}"
7171

7272
# Make a request to the Azure stdlib scaffolding API:
7373
response=$(curl -s -X POST -H "Content-Type: application/json" -d "$2" "${url}")
@@ -97,23 +97,24 @@ main() {
9797
exit 1
9898
fi
9999

100-
# Bail if the destination directory does not exist:
100+
# Create the destination directory if it does not exist:
101101
if [ ! -d "${dest_dir}" ]; then
102-
echo "Destination directory does not exist: ${dest_dir}" >&2
103-
exit 1
102+
mkdir -p "${dest_dir}"
104103
fi
105104

106-
# Bail if the README.md file does not exist:
105+
# Scaffold README.md file if does not exist:
107106
if [ ! -f "${readme}" ]; then
108-
echo "README.md file does not exist: ${readme}" >&2
109-
exit 1
110-
fi
107+
scaffold_request "README.md" "{}"
108+
README='{}'
109+
else
110+
echo "README.md already exists, using it to scaffold remaining files via AI..." >&2
111111

112-
# `README.md` contents:
113-
readme_file=$(cat ${readme} | jq -Rs)
112+
# `README.md` contents:
113+
readme_file=$(cat ${readme} | jq -Rs)
114114

115-
# JSON payload for the API:
116-
README='{"readme": '$readme_file'}'
115+
# JSON payload for the API:
116+
README='{"readme": '$readme_file'}'
117+
fi
117118

118119
if [[ ! -f "${dest_dir}/package.json" ]]; then
119120
scaffold_request "package.json" "$README"
@@ -127,6 +128,9 @@ main() {
127128
if [[ ! -f "${dest_dir}/lib/main.js" ]]; then
128129
scaffold_request "lib/main.js" "$README"
129130
fi
131+
if [[ ! -f "${dest_dir}/lib/validate.js" ]] && [[ $(cat ${readme} | grep -c 'options') -gt 0 ]]; then
132+
scaffold_request "lib/validate.js" "$README"
133+
fi
130134
if [[ ! -f "${dest_dir}/test/test.js" ]]; then
131135
scaffold_request "test/test.js" "$README"
132136
fi

tools/make/lib/scaffold/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ Usage: make <command> [<ENV_VAR>=<value> <ENV_VAR>=<value> ...]
4646

4747
#### scaffold
4848

49-
Scaffold required files for a new or existing package. The package directory has to exist and must contain at least the package's `README.md` file for the command to work.
49+
Scaffold required files for a new or existing package. The command will create highly customized files when the package directory already contains at least the `README.md` file; otherwise, the command will create a default `README.md` and scaffold the remaining files using placeholder values.
5050

5151
<!-- run-disable -->
5252

0 commit comments

Comments
 (0)