Skip to content

Commit 406f030

Browse files
committed
🥭 update build setup
1 parent 34cc274 commit 406f030

File tree

7 files changed

+343
-212
lines changed

7 files changed

+343
-212
lines changed

.github/workflows/ci.yml

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
name: CI
2+
on:
3+
push:
4+
branches:
5+
- main
6+
- master
7+
tags:
8+
- '!*' # Do not execute on tags
9+
env:
10+
GITHUB_TOKEN: ${{secrets.GH_TOKEN}}
11+
CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
12+
FORCE_COLOR: 1
13+
14+
15+
jobs:
16+
test:
17+
strategy:
18+
matrix:
19+
platform: [ubuntu-latest, windows-latest, macOS-latest]
20+
node: [16.x, 18.x]
21+
name: Test with Node ${{matrix.node}} on ${{matrix.platform}}
22+
runs-on: ${{matrix.platform}}
23+
steps:
24+
- uses: actions/checkout@v3
25+
- uses: actions/setup-node@v2
26+
with:
27+
node-version: ${{matrix.node}}
28+
- run: npm ci
29+
- run: npm test
30+
31+
32+
coverage:
33+
name: Publish coverage
34+
needs: [test]
35+
runs-on: ubuntu-latest
36+
steps:
37+
- uses: actions/checkout@v3
38+
- uses: actions/setup-node@v2
39+
with:
40+
node-version: 18.x
41+
- run: npm ci
42+
- run: npm test
43+
- uses: paambaati/[email protected]
44+
- uses: coverallsapp/github-action@master
45+
with:
46+
github-token: ${{secrets.GITHUB_TOKEN}}
47+
48+
49+
docs:
50+
name: Publish docs
51+
needs: [test]
52+
runs-on: ubuntu-latest
53+
steps:
54+
- uses: actions/checkout@v3
55+
- uses: actions/setup-node@v2
56+
with:
57+
node-version: 18.x
58+
- run: git clone https://${GITHUB_TOKEN}@github.com/nodef/deploy "$HOME/deploy"
59+
- run: bash "$HOME/deploy/setup.sh"
60+
- run: npm i -g typescript typedoc
61+
- run: npm ci
62+
- run: npm run publish-docs
63+
64+
65+
packages:
66+
name: Publish packages
67+
needs: [test]
68+
runs-on: ubuntu-latest
69+
steps:
70+
- uses: actions/checkout@v3
71+
- uses: actions/setup-node@v2
72+
with:
73+
node-version: 18.x
74+
- run: git clone https://${GITHUB_TOKEN}@github.com/nodef/deploy "$HOME/deploy"
75+
- run: bash "$HOME/deploy/setup.sh"
76+
- run: npm i -g typescript rollup typedoc browserify terser
77+
- run: npm ci
78+
- run: npm run publish-packages

.github/workflows/deploy.yml

-16
This file was deleted.

.github/workflows/pr.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: PR
2+
on: [pull_request]
3+
env:
4+
FORCE_COLOR: 1
5+
6+
7+
jobs:
8+
test:
9+
strategy:
10+
matrix:
11+
platform: [ubuntu-latest, windows-latest, macOS-latest]
12+
node: [16.x, 18.x]
13+
name: Test with Node ${{ matrix.node }} on ${{ matrix.platform }}
14+
runs-on: ${{ matrix.platform }}
15+
steps:
16+
- uses: actions/checkout@v3
17+
- uses: actions/setup-node@v2
18+
with:
19+
node-version: ${{ matrix.node }}
20+
- run: npm ci
21+
- run: npm test

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ coverage/
1818
.coveralls.yml
1919
tsconfig.json
2020
jestconfig.json
21+
jest.config.js
2122
rollup.config.js
2223
build.js

build.js

+44-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const build = require('extra-build');
22

33
const owner = 'nodef';
4+
const repo = build.readMetadata('.').name;
45
const srcts = 'index.ts';
56
const LOCATIONS = [
67
'src/index.ts',
@@ -17,8 +18,8 @@ function keywords(ds) {
1718
}
1819

1920

20-
// Publish root package to NPM, GitHub.
21-
function publishRoot(ds, ver, typ) {
21+
// Publish a root package to NPM, GitHub.
22+
function publishRootPackage(ds, ver, typ) {
2223
var _package = build.readDocument('package.json');
2324
var _readme = build.readDocument('README.md');
2425
var m = build.readMetadata('.');
@@ -27,8 +28,8 @@ function publishRoot(ds, ver, typ) {
2728
m.keywords = keywords(ds);
2829
if (typ) {
2930
m.name = `${m.name}.${typ}`;
30-
m.description.replace(/\.$/, `{${typ}}.`);
31-
md.replace(/(unpkg\.com\/)(\S+?)(\/\))/, `$1$2.${typ}$3`);
31+
m.description = m.description.replace(/\.$/, `{${typ}}.`);
32+
md = md.replace(/(unpkg\.com\/)(\S+?)(\/\))/, `$1$2.${typ}$3`);
3233
}
3334
build.writeMetadata('.', m);
3435
build.writeFileText('README.md', md);
@@ -40,27 +41,49 @@ function publishRoot(ds, ver, typ) {
4041
}
4142

4243

43-
// Deploy root package to NPM, GitHub.
44-
function deployRoot(ds, ver) {
44+
// Transform JSDoc in .d.ts file.
45+
function transformJsdoc(x, dm) {
46+
if (!dm.has(x.name)) return null;
47+
var link = `[📘](https://github.com/${owner}/${repo}/wiki/${x.name})`;
48+
x.description = x.description.trim() + '\n' + link;
49+
return x;
50+
}
51+
52+
53+
// Bundle script for test or publish.
54+
function bundleScript(ds) {
55+
var dm = new Map(ds.map(d => [d.name, d]));
56+
build.exec(`tsc`);
57+
build.bundleScript(`.build/${srcts}`);
58+
build.jsdocifyScript('index.d.ts', 'index.d.ts', x => transformJsdoc(x, dm));
59+
}
60+
61+
62+
// Publish root packages to NPM, GitHub.
63+
function publishRootPackages(ds, ver) {
4564
var m = build.readMetadata('.');
4665
var sym = build.symbolname(m.name);
47-
build.bundleScript(`.build/${srcts}`);
48-
publishRoot(ds, ver, '');
66+
bundleScript(ds);
67+
publishRootPackage(ds, ver, '');
4968
build.webifyScript('index.mjs', 'index.mjs', {format: 'esm'});
5069
build.webifyScript('index.js', 'index.js', {format: 'cjs', symbol: sym});
51-
publishRoot(ds, ver, 'web');
70+
publishRootPackage(ds, ver, 'web');
5271
}
5372

5473

55-
// Deploy root, sub packages to NPM, GitHub.
56-
function deployAll(ds) {
57-
var m = build.readMetadata('.');
58-
var ver = build.nextUnpublishedVersion(m.name, m.version);
59-
build.exec(`tsc`);
74+
// Publish docs.
75+
function publishDocs(ds) {
6076
build.updateGithubRepoDetails({topics: keywords(ds)});
6177
build.generateDocs(`src/${srcts}`);
6278
build.publishDocs();
63-
deployRoot(ds, ver);
79+
}
80+
81+
82+
// Pushish root, sub packages to NPM, GitHub.
83+
function publishPackages(ds) {
84+
var m = build.readMetadata('.');
85+
var ver = build.nextUnpublishedVersion(m.name, m.version);
86+
publishRootPackages(ds, ver);
6487
}
6588

6689

@@ -108,12 +131,14 @@ function updateReadme(ds) {
108131
}
109132

110133

134+
// Finally.
111135
function main(a) {
112136
var p = build.loadDocs([`src/${srcts}`]);
113137
var ds = p.children.map(build.docsDetails);
114-
if (a[2] === 'deploy') deployAll(ds);
115-
else if (a[2] === 'wiki') generateWiki(ds);
116-
else if (a[2] === 'readme') updateReadme(ds);
117-
else build.bundleScript(`.build/${srcts}`);
138+
if (a[2]==='wiki') generateWiki(ds);
139+
else if (a[2]==='readme') updateReadme(ds);
140+
else if (a[2]==='publish-docs') publishDocs(ds);
141+
else if (a[2]==='publish-packages') publishPackages(ds);
142+
else bundleScript(ds);
118143
}
119144
main(process.argv);

0 commit comments

Comments
 (0)