-
-
Notifications
You must be signed in to change notification settings - Fork 0
256 lines (229 loc) · 12.6 KB
/
bundle.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#/
# @license Apache-2.0
#
# Copyright (c) 2022 The Stdlib Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#/
# Workflow name:
name: bundle
# Workflow triggers:
on:
workflow_dispatch:
push:
branches:
- main
tags_ignore:
- 'v[0-9]+\.[0-9]+\.[0-9]+'
# Workflow jobs:
jobs:
deno:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Copy files to deno directory
run: |
mkdir -p deno
cp README.md LICENSE CONTRIBUTORS NOTICE ./deno
# Copy TypeScript definitions to deno directory:
if [ -d index.d.ts ]; then
cp index.d.ts ./deno/index.d.ts
fi
if [ -e ./docs/types/index.d.ts ]; then
cp ./docs/types/index.d.ts ./deno/mod.d.ts
fi
- uses: actions/setup-node@v2
with:
node-version: 16
timeout-minutes: 5
- name: Install production and development dependencies
id: install
run: |
npm install || npm install || npm install
timeout-minutes: 15
- name: Bundle package for Deno
id: deno-bundle
uses: stdlib-js/bundle-action@main
with:
target: 'deno'
- name: Rewrite file contents
run: |
# Replace links to other packages with links to the deno branch:
find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/deno/";
# Replace reference to `@stdlib/types` with CDN link:
find ./deno -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ <reference types=\"@stdlib\/types\"\/>/\/\/\/ <reference types=\"https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/types@main\/index.d.ts\"\/>/g"
# Change wording of project description to avoid reference to JavaScript and Node.js:
find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g"
# Rewrite all `require()`s to use jsDelivr links:
find ./deno -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// {
s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/
s/';/@deno\/mod.js';/
}"
# Remove `installation`, `cli`, and `c` sections:
find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"installation\">[^<]+<\/section>//g;"
find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
find ./deno -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
# Create package.json file for deno branch:
jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./mod.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./deno/package.json
- name: Publish to deno branch
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./deno
publish_branch: deno
keep_files: true
user_name: 'stdlib-bot'
user_email: 'noreply@stdlib.io'
commit_message: 'Auto-generated commit'
enable_jekyll: true
- name: Send status to Slack channel in case of failure
uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#npm-ci'
if: failure()
umd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Copy files to umd directory
run: |
mkdir -p umd
cp README.md LICENSE CONTRIBUTORS NOTICE ./umd
- uses: actions/setup-node@v2
with:
node-version: 16
timeout-minutes: 5
- name: Install production and development dependencies
id: install
run: |
npm install || npm install || npm install
timeout-minutes: 15
- name: Extract Alias
id: extract-alias
run: |
alias=$(grep -E 'require\(' README.md | head -n 1 | sed -E 's/^var ([a-zA-Z0-9_]+) = .+/\1/')
echo "::set-output name=alias::${alias}"
- name: Create Universal Module Definition (UMD) bundle
id: umd-bundle
uses: stdlib-js/bundle-action@main
with:
target: 'umd'
alias: ${{ steps.extract-alias.outputs.alias }}
- name: Rewrite file contents
run: |
# Replace links to other packages with links to the umd branch:
find ./umd -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/umd/";
# Remove `installation`, `cli`, and `c` sections:
find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"installation\">[^<]+<\/section>//g;"
find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
find ./umd -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
# Rewrite first `require()` to show consumption of the UMD bundle in Observable and via a `script` tag:
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\`\`\`/"
# Rewrite examples section to be a HTML file:
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\`\`\`/"
# Rewrite all `require()`s in the examples section as `script` tags loading the respective UMD bundle:
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"
# Wrap contents of `<script type="text/javascript">` tag contents in an IIFE:
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"
# Create package.json file for umd branch:
jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "main": "./bundle.js", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./umd/package.json
- name: Publish to umd branch
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./umd
publish_branch: umd
keep_files: true
user_name: 'stdlib-bot'
user_email: 'noreply@stdlib.io'
commit_message: 'Auto-generated commit'
enable_jekyll: true
- name: Send status to Slack channel in case of failure
uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#npm-ci'
if: failure()
esm:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Copy files to umd directory
run: |
mkdir -p esm
cp README.md LICENSE CONTRIBUTORS NOTICE ./esm
# Copy TypeScript definitions to esm directory:
if [ -e ./docs/types/index.d.ts ]; then
cp ./docs/types/index.d.ts ./esm/index.d.ts
fi
if [ -d index.d.ts ]; then
cp index.d.ts ./esm/index.d.ts
fi
- uses: actions/setup-node@v2
with:
node-version: 16
timeout-minutes: 5
- name: Install production and development dependencies
id: install
run: |
npm install || npm install || npm install
timeout-minutes: 15
- name: Create ES Module (ESM) bundle
id: esm-bundle
uses: stdlib-js/bundle-action@main
with:
target: 'esm'
- name: Rewrite file contents
run: |
# Replace links to other packages with links to the esm branch:
find ./esm -type f -name '*.md' -print0 | xargs -0 sed -Ei "/\/tree\/main/b; /^\[@stdlib[^:]+: https:\/\/github.com\/stdlib-js\// s/(.*)/\\1\/tree\/esm/";
# Replace reference to `@stdlib/types` with esm link:
find ./esm -type f -name '*.ts' -print0 | xargs -0 sed -Ei "s/\/\/\/ <reference types=\"@stdlib\/types\"\/>/\/\/\/ <reference types=\"https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js\/types@esm\/index.d.ts\"\/>/g"
# Change wording of project description to avoid reference to JavaScript and Node.js:
find ./esm -type f -name '*.md' -print0 | xargs -0 sed -Ei "s/a standard library for JavaScript and Node.js, /a standard library /g"
# Rewrite all `require()`s to use jsDelivr links:
find ./esm -type f -name '*.md' -print0 | xargs -0 sed -Ei "/require\( '@stdlib\// {
s/(var|let|const)\s+([a-z0-9_]+)\s+=\s*require\( '([^']+)' \);/import \2 from \'\3\';/i
s/@stdlib/https:\/\/cdn.jsdelivr.net\/gh\/stdlib-js/
s/';/@esm\/index.mjs';/
}"
# Remove `installation`, `cli`, and `c` sections:
find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/<section class=\"installation\">[^<]+<\/section>//g;"
find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"cli\">[\s\S]+<\!\-\- \/.cli \-\->//g"
find ./esm -type f -name '*.md' -print0 | xargs -0 perl -0777 -i -pe "s/(\* \* \*\n+)?<section class=\"c\">[\s\S]+<\!\-\- \/.c \-\->//g"
# Rewrite examples section to be a HTML file:
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"
# Create package.json file for esm branch:
jq --indent 2 '{"name": .name, "version": .version, "description": .description, "license": .license, "type": "module", "main": "./index.mjs", "homepage": .homepage, "repository": .repository, "bugs": .bugs, "keywords": .keywords, "funding": .funding}' package.json > ./esm/package.json
- name: Publish to esm branch
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./esm
publish_branch: esm
keep_files: true
user_name: 'stdlib-bot'
user_email: 'noreply@stdlib.io'
commit_message: 'Auto-generated commit'
enable_jekyll: true
- name: Send status to Slack channel in case of failure
uses: act10ns/slack@v1
with:
status: ${{ job.status }}
steps: ${{ toJson(steps) }}
channel: '#npm-ci'
if: failure()