@@ -69,15 +69,15 @@ jobs:
69
69
70
70
# Rewrite all `require()`s to use jsDelivr links:
71
71
find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// {
72
- s/(var|let|const)\s+([a-z0-9 ]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
72
+ s/(var|let|const)\s+([a-z0-9_ ]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
73
73
s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/
74
74
s/';/@deno\/mod.js';/
75
75
}"
76
76
77
77
# Remove `installation`, `cli`, and `c` sections:
78
78
find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"installation\">[^<]+<\/section>//g;"
79
- find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
80
- find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
79
+ find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)? <section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
80
+ find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)? <section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
81
81
82
82
- name : Publish to deno branch
83
83
uses : peaceiris/actions-gh-pages@v3
@@ -107,18 +107,39 @@ jobs:
107
107
run : |
108
108
npm install || npm install || npm install
109
109
timeout-minutes : 15
110
+ - name : Extract Alias
111
+ id : extract-alias
112
+ run : |
113
+ alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/')
114
+ echo "::set-output name=alias::${alias}"
110
115
- name : Create Universal Module Definition (UMD) bundle
111
116
id : umd-bundle
112
117
uses : stdlib-js/bundle-action@main
113
118
with :
114
119
target : ' umd'
120
+ alias : ${{ steps.extract-alias.outputs.alias }}
115
121
- name : Rewrite file contents
116
122
run : |
117
123
124
+ # Replace links to other packages with links to the umd branch:
125
+ find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/";
126
+
118
127
# Remove `installation`, `cli`, and `c` sections:
119
128
find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"installation\">[^<]+<\/section>//g;"
120
- find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
121
- find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
129
+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
130
+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
131
+
132
+ # Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag:
133
+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\`\`\`javascript\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);\n\`\`\`/To use in Observable,\n\n\`\`\`javascript\n\2 = require\( 'https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/bundle.js' \)\n\`\`\`\n\nTo include the bundle in a webpage,\n\n\`\`\`html\n<script type=\"text\/javascript\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/bundle.js\"><\/script>\n\`\`\`\n\nIf no recognized module system is present, access bundle contents via the global scope:\n\n\`\`\`html\n<script type=\"text\/javascript\">\n window.\2;\n<\/script>\n\`\`\`/"
134
+
135
+ # Rewrite examples section to be a HTML file:
136
+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\#\# Examples([\s\S]*)\`\`\`javascript([\s\S]+?)\`\`\`/\#\# Examples\1\`\`\`html\n<\!DOCTYPE html>\n<html lang=\"en\">\n<body>\n<script type=\"text\/javascript\">\2\n<\/script>\n<\/body>\n<\/html>\n\`\`\`/"
137
+
138
+ # Rewrite all `require()`s in the examples section as `script` tags loading the respective UMD bundle:
139
+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "1 while s/<script type=\"text\/javascript\">\n(var|let|const)\s+([a-zA-Z0-9_]+)\s+=\s*require\( '\@stdlib\/([^']+)' \);?/<script type=\"text\/javascript\" src=\"https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/\3\@umd\/bundle.js\"><\/script>\n<script type=\"text\/javascript\">/g"
140
+
141
+ # Wrap contents of `<script type="text/javascript">` tag contents in an IIFE:
142
+ find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<script type=\"text\/javascript\">([\s\S]+?)<\/script>/<script type=\"text\/javascript\">\n\(function \(\) {\1}\)\(\)\n<\/script>/g"
122
143
123
144
- name : Publish to umd branch
124
145
uses : peaceiris/actions-gh-pages@v3
@@ -175,18 +196,18 @@ jobs:
175
196
176
197
# Rewrite all `require()`s to use jsDelivr links:
177
198
find ./esm -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// {
178
- s/(var|let|const)\s+([a-z0-9 ]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
199
+ s/(var|let|const)\s+([a-z0-9_ ]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
179
200
s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/
180
201
s/';/@esm\/index.mjs';/
181
202
}"
182
203
183
204
# Remove `installation`, `cli`, and `c` sections:
184
205
find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"installation\">[^<]+<\/section>//g;"
185
- find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
186
- find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
206
+ find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)? <section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
207
+ find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)? <section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
187
208
188
209
# Rewrite examples section to be a HTML file:
189
- find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\#\# Examples([\s\S]*)\`\`\`javascript([\s\S]+?)\`\`\`/\#\# Examples\1\`\`\`html\n<\!DOCTYPE html>\n<html lang=\"en\">\n<head >\n<script type=\"module\">\n\2\n<\/script>\n<\/head >\n<\/html>\n\`\`\`/g"
210
+ find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/\#\# Examples([\s\S]*)\`\`\`javascript([\s\S]+?)\`\`\`/\#\# Examples\1\`\`\`html\n<\!DOCTYPE html>\n<html lang=\"en\">\n<body >\n<script type=\"module\">\n\2\n<\/script>\n<\/body >\n<\/html>\n\`\`\`/g"
190
211
191
212
- name : Publish to esm branch
192
213
uses : peaceiris/actions-gh-pages@v3
0 commit comments