Skip to content

Commit 3196f4c

Browse files
committed
🐛 rename package
1 parent 1945908 commit 3196f4c

File tree

13 files changed

+7730
-550
lines changed

13 files changed

+7730
-550
lines changed

.github/workflows/ci.yml

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

.github/workflows/pr.yml

Lines changed: 21 additions & 0 deletions
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

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Generated files
2-
build/
2+
.build/
3+
.docs/
4+
coverage/
35
*.d.ts
46
*.map
57
example.js

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[submodule "wiki"]
22
path = wiki
3-
url = https://github.com/nodef/extra-sortedarray.wiki
3+
url = https://github.com/nodef/extra-sorted-array.wiki

.npmignore

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1-
# Parts
1+
# Source only
2+
.gitmodules
3+
.github/
4+
.docs/
25
src/
6+
data/
37
wiki/
4-
.gitmodules
8+
tests/
9+
unused/
10+
test.js
11+
CITATION.cff
12+
TODO
513

614
# Build
7-
build/
8-
build.js
15+
.build/
16+
coverage/
917
.travis.yml
18+
.coveralls.yml
1019
tsconfig.json
20+
jest.config.js
1121
rollup.config.js
12-
13-
# Others
14-
unused/
15-
unused.*
16-
TODO
22+
build.js

.travis.yml

Lines changed: 0 additions & 11 deletions
This file was deleted.

build.js

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
const fs = require('fs');
2+
const build = require('extra-build');
3+
4+
const owner = 'nodef';
5+
const repo = build.readMetadata('.').name;
6+
const srcts = 'index.ts';
7+
const LOCATIONS = [
8+
'src/index.ts',
9+
];
10+
11+
12+
13+
14+
// Get keywords for main/sub package.
15+
function keywords(ds, less=false) {
16+
var rkind = /namespace|function/i;
17+
var ds = less? ds.filter(d => rkind.test(d.kind)) : ds;
18+
var m = build.readMetadata('.');
19+
var s = new Set([...m.keywords, ...ds.map(d => d.name)]);
20+
return Array.from(s);
21+
}
22+
23+
24+
// Publish a root package to NPM, GitHub.
25+
function publishRootPackage(ds, ver, typ) {
26+
var _package = build.readDocument('package.json');
27+
var _readme = build.readDocument('README.md');
28+
var m = build.readMetadata('.');
29+
var md = build.readFileText('README.md');
30+
m.version = ver;
31+
m.keywords = keywords(ds);
32+
if (typ) {
33+
m.name = `${m.name}.${typ}`;
34+
m.description = m.description.replace(/\.$/, ` {${typ}}.`);
35+
md = md.replace(/(unpkg\.com\/)(\S+?)(\/\))/, `$1$2.${typ}$3`);
36+
}
37+
build.writeMetadata('.', m);
38+
build.writeFileText('README.md', md);
39+
build.publish('.');
40+
try { build.publishGithub('.', owner); }
41+
catch {}
42+
build.writeDocument(_package);
43+
build.writeDocument(_readme);
44+
}
45+
46+
47+
// Transform JSDoc in .d.ts file.
48+
function transformJsdoc(x, dm) {
49+
if (!dm.has(x.name)) return null;
50+
var link = `[📘](https://github.com/${owner}/${repo}/wiki/${x.name})`;
51+
x.description = x.description.replace(/\[📘\]\(.+?\)/g, '');
52+
x.description = x.description.trim() + '\n' + link;
53+
return x;
54+
}
55+
56+
57+
// Bundle script for test or publish.
58+
function bundleScript(ds) {
59+
var dm = new Map(ds.map(d => [d.name, d]));
60+
build.exec(`tsc`);
61+
build.bundleScript(`.build/${srcts}`);
62+
build.jsdocifyScript('index.d.ts', 'index.d.ts', x => transformJsdoc(x, dm));
63+
}
64+
65+
66+
// Publish root packages to NPM, GitHub.
67+
function publishRootPackages(ds, ver) {
68+
var m = build.readMetadata('.');
69+
var sym = build.symbolname(m.name);
70+
bundleScript(ds);
71+
publishRootPackage(ds, ver, '');
72+
build.webifyScript('index.mjs', 'index.mjs', {format: 'esm'});
73+
build.webifyScript('index.js', 'index.js', {format: 'cjs', symbol: sym});
74+
publishRootPackage(ds, ver, 'web');
75+
}
76+
77+
78+
// Publish docs.
79+
function publishDocs(ds) {
80+
build.updateGithubRepoDetails({owner, repo, topics: keywords(ds, true)});
81+
build.generateDocs(`src/${srcts}`);
82+
build.publishDocs();
83+
}
84+
85+
86+
// Pushish root, sub packages to NPM, GitHub.
87+
function publishPackages(ds) {
88+
var m = build.readMetadata('.');
89+
var ver = build.nextUnpublishedVersion(m.name, m.version);
90+
publishRootPackages(ds, ver);
91+
}
92+
93+
94+
// Generate wiki for all exported symbols.
95+
function generateWiki(ds) {
96+
var rkind = /namespace|function/i, useWiki = true;
97+
var dm = new Map(ds.map(d => [d.name, d]));
98+
for (var d of ds) {
99+
var f = `wiki/${d.name}.md`;
100+
if (!rkind.test(d.kind)) continue;
101+
if (!fs.existsSync(f)) {
102+
var txt = build.wikiMarkdown(d, {owner, repo, useWiki});
103+
build.writeFileText(f, txt);
104+
}
105+
else {
106+
var txt = build.readFileText(f);
107+
txt = build.wikiUpdateDescription(txt, d);
108+
txt = build.wikiUpdateCodeReference(txt, d, {owner, repo, useWiki})
109+
txt = build.wikiUpdateLinkReferences(txt, dm, {owner, repo, useWiki});
110+
build.writeFileText(f, txt);
111+
}
112+
}
113+
}
114+
115+
116+
// Get README index descriptions.
117+
function readmeDescription(d) {
118+
var rkind = /namespace|function/i;
119+
var sname = /a?sync$/i;
120+
if (!rkind.test(d.kind)) return '';
121+
if (sname.test(d.name) && d.name!=='spawnAsync') return '';
122+
var a = d.description.replace(/The.+method/, 'This method');
123+
a = a.replace(', with command-line arguments in ', ' and ');
124+
a = a.replace(/(\S)`(.*?)`/, '$1 `$2`');
125+
return a;
126+
}
127+
128+
129+
// Sort docs details by original order.
130+
function compareLocation(a, b) {
131+
if (a.kind!==b.kind) return 0;
132+
var alocn = a.location.replace(/.*?@types\/node.*?\:/, 'src/_file.ts:');
133+
var blocn = b.location.replace(/.*?@types\/node.*?\:/, 'src/_file.ts:');
134+
var [afile] = alocn.split(':');
135+
var [bfile] = blocn.split(':');
136+
return LOCATIONS.indexOf(afile) - LOCATIONS.indexOf(bfile) || alocn.localeCompare(blocn);
137+
}
138+
139+
140+
// Update README.
141+
function updateReadme(ds) {
142+
var m = build.readMetadata('.');
143+
var repo = m.name;
144+
var ds = ds.slice().sort(compareLocation);
145+
var dm = new Map(ds.map(d => [d.name, d]));
146+
var txt = build.readFileText('README.md');
147+
txt = build.wikiUpdateIndex(txt, dm, readmeDescription);
148+
txt = build.wikiUpdateLinkReferences(txt, dm, {owner, repo, useWiki: true});
149+
build.writeFileText('README.md', txt);
150+
}
151+
152+
153+
// Finally.
154+
function main(a) {
155+
var p = build.loadDocs([`src/${srcts}`]);
156+
var ds = p.children.map(build.docsDetails);
157+
if (a[2]==='wiki') generateWiki(ds);
158+
else if (a[2]==='readme') updateReadme(ds);
159+
else if (a[2]==='publish-docs') publishDocs(ds);
160+
else if (a[2]==='publish-packages') publishPackages(ds);
161+
else bundleScript(ds);
162+
}
163+
main(process.argv);

jest.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
collectCoverage: true,
3+
coverageDirectory: "coverage",
4+
coverageProvider: "v8",
5+
transform: {
6+
"^.+\\.(t|j)sx?$": "ts-jest"
7+
},
8+
};

0 commit comments

Comments
 (0)