Skip to content

Commit 920997a

Browse files
committed
🐛 upgrade package
1 parent 3df61ef commit 920997a

File tree

15 files changed

+6100
-326
lines changed

15 files changed

+6100
-326
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: [20.x, 22.x]
24+
name: Test with Node ${{matrix.node}} on ${{matrix.platform}}
25+
runs-on: ${{matrix.platform}}
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: actions/setup-node@v3
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@v4
41+
- uses: actions/setup-node@v3
42+
with:
43+
node-version: 22.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@v4
58+
- uses: actions/setup-node@v3
59+
with:
60+
node-version: 22.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@v4
73+
- uses: actions/setup-node@v3
74+
with:
75+
node-version: 22.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: [20.x, 22.x]
13+
name: Test with Node ${{ matrix.node }} on ${{ matrix.platform }}
14+
runs-on: ${{ matrix.platform }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v3
18+
with:
19+
node-version: ${{ matrix.node }}
20+
- run: npm ci
21+
- run: npm test

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# Generated files
2+
.build/
3+
.docs/
4+
coverage/
5+
*.d.ts
6+
*.map
7+
example.js
8+
index.js
9+
index.?js
10+
111
# Logs
212
logs
313
*.log

.npmignore

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Source only
2+
.gitmodules
3+
.github/
4+
.docs/
5+
src/
6+
data/
7+
wiki/
8+
tests/
9+
unused/
10+
test.js
11+
CITATION.cff
12+
TODO
13+
14+
# Build
15+
.build/
16+
coverage/
17+
.travis.yml
18+
.coveralls.yml
19+
tsconfig.json
20+
jest.config.js
21+
rollup.config.js
22+
build.js

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018-20 Subhajit Sahu
3+
Copyright (c) 2018-25 Subhajit Sahu
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
1-
[SQL] is designed for managing or stream processing data in an RDBMS.
2-
Includes SQL command generation functions, with a few for text matching (PostgreSQL).
1+
[SQL] is designed for managing or stream processing data in an RDBMS. Includes SQL command generation functions, with a few for text matching (PostgreSQL).
32

43
```javascript
5-
const sql = require('extra-sql');
4+
const xsql = require('extra-sql');
65

7-
sql.tableExists('food');
8-
// SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name='food');
6+
xsql.tableExists('food');
7+
// SELECT EXISTS (SELECT 1 FROM information_schema.tables WHERE table_name='food');
98

10-
sql.setupTable('food', {code: 'TEXT', name: 'TEXT'},
9+
xsql.setupTable('food', {code: 'TEXT', name: 'TEXT'},
1110
[{code: 'F1', name: 'Mango'}, {code: 'F2', name: 'Lychee'}]);
12-
// CREATE TABLE IF NOT EXISTS "food" ("code" TEXT, "name" TEXT);
13-
// INSERT INTO "food" ("code", "name") VALUES
14-
// ('F1', 'Mango'),
15-
// ('F2', 'Lychee');
11+
// CREATE TABLE IF NOT EXISTS "food" ("code" TEXT, "name" TEXT);
12+
// INSERT INTO "food" ("code", "name") VALUES
13+
// ('F1', 'Mango'),
14+
// ('F2', 'Lychee');
1615

17-
sql.selectTsquery('columns', 'total fat');
18-
// SELECT * FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat');
16+
xsql.selectTsquery('columns', 'total fat');
17+
// SELECT * FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat');
1918

20-
sql.matchTsquery('columns', ['total', 'fat']);
21-
// SELECT *, '2'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat') UNION ALL
22-
// SELECT *, '1'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total');
19+
xsql.matchTsquery('columns', ['total', 'fat']);
20+
// SELECT *, '2'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total fat') UNION ALL
21+
// SELECT *, '1'::INT AS "matchTsquery" FROM "columns" WHERE "tsvector" @@ plainto_tsquery('total');
2322
```
2423

25-
### reference
2624

27-
| Name | Action
25+
## Index
26+
27+
| Property | Description
2828
|---------------------|-------
2929
| [createTable] | Generates SQL command for CREATE TABLE.
3030
| [createIndex] | Generates SQL command for CREATE INDEX.
@@ -40,7 +40,10 @@ sql.matchTsquery('columns', ['total', 'fat']);
4040
<br>
4141
<br>
4242

43-
[![nodef](https://merferry.glitch.me/card/extra-sql.svg)](https://nodef.github.io)
43+
44+
[![](https://img.youtube.com/vi/u6EuAUjq92k/maxresdefault.jpg)](https://www.youtube.com/watch?v=u6EuAUjq92k)<br>
45+
[![ORG](https://img.shields.io/badge/org-nodef-green?logo=Org)](https://nodef.github.io)
46+
4447

4548
[createTable]: https://github.com/nodef/extra-sql/wiki/createTable
4649
[createIndex]: https://github.com/nodef/extra-sql/wiki/createIndex

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);

0 commit comments

Comments
 (0)