@larsgw/formica 0.5.0 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.gitattributes +1 -0
- package/.github/workflows/ci.yml +27 -0
- package/CHANGELOG.md +18 -0
- package/README.md +20 -1
- package/lib/bin/process-resources-index.js +7 -5
- package/lib/bin/process-resources.js +1 -1
- package/package.json +1 -1
- package/src/bin/process-resources-index.ts +6 -4
- package/src/bin/process-resources.ts +1 -1
package/.gitattributes
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
*.ts linguist-language=TypeScript
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
name: Node.js CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ "main" ]
|
|
6
|
+
pull_request:
|
|
7
|
+
branches: [ "main" ]
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
build:
|
|
11
|
+
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
strategy:
|
|
15
|
+
matrix:
|
|
16
|
+
node-version: [18.x, 20.x]
|
|
17
|
+
|
|
18
|
+
steps:
|
|
19
|
+
- uses: actions/checkout@v3
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v3
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
- run: npm install
|
|
25
|
+
- run: npm run build
|
|
26
|
+
- run: npm run lint
|
|
27
|
+
- run: npm test
|
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
## [0.5.2](https://github.com/identification-resources/formica/compare/v0.5.1...v0.5.2) (2023-11-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **resources:** fix GBIF index generation ([c88e2d2](https://github.com/identification-resources/formica/commit/c88e2d2b306b930ca0b00b978e3eb89b8adfb656))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## [0.5.1](https://github.com/identification-resources/formica/compare/v0.5.0...v0.5.1) (2023-11-03)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Bug Fixes
|
|
14
|
+
|
|
15
|
+
* **resources:** fix file listing in processor ([009b980](https://github.com/identification-resources/formica/commit/009b98091b0f597e91213ace82252facbe3b5fed))
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
1
19
|
# [0.5.0](https://github.com/identification-resources/formica/compare/v0.4.3...v0.5.0) (2023-10-24)
|
|
2
20
|
|
|
3
21
|
|
package/README.md
CHANGED
|
@@ -3,7 +3,17 @@
|
|
|
3
3
|
**Formica** is an SDK and a collection of tools for the data in the Library of
|
|
4
4
|
Identification Resources.
|
|
5
5
|
|
|
6
|
-
##
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
Install globally:
|
|
9
|
+
|
|
10
|
+
npm install --global @larsgw/formica
|
|
11
|
+
|
|
12
|
+
Run locally:
|
|
13
|
+
|
|
14
|
+
npx --package @larsgw/formica -- ...
|
|
15
|
+
|
|
16
|
+
## CLI
|
|
7
17
|
|
|
8
18
|
- `loir-validate-catalog [./catalog.csv ./authors.csv ./places.csv ./publishers.csv]`:
|
|
9
19
|
Validate the CSV files containing metadata ([schema](https://github.com/identification-resources/catalog/blob/main/docs/tools-resources.md)).
|
|
@@ -17,3 +27,12 @@ Identification Resources.
|
|
|
17
27
|
`--update` flag in a Git repo to update existing Darwin Core files while keeping
|
|
18
28
|
the identifiers stable (in most cases).
|
|
19
29
|
- `loir-resources-index [./resources]`: Create indices of the Darwin Core archives.
|
|
30
|
+
|
|
31
|
+
## API
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
const Formica = require('@larsgw/formica')
|
|
35
|
+
|
|
36
|
+
// Load catalog data
|
|
37
|
+
const catalog = Formica.catalog.loadData(`...`, 'catalog')
|
|
38
|
+
```
|
|
@@ -96,7 +96,7 @@ function main(args) {
|
|
|
96
96
|
file = _a.sent();
|
|
97
97
|
return [2 /*return*/, Promise.all(index_1.resources.parseTextFileHeader(file).map(function (resource, index) {
|
|
98
98
|
return __awaiter(this, void 0, void 0, function () {
|
|
99
|
-
var amendedResource, dwcFile, _a,
|
|
99
|
+
var amendedResource, dwcFile, _a, header, dwc, _b, _c, gbifColumn, gbifAcceptedColumn, _i, dwc_1, taxon, gbifId;
|
|
100
100
|
return __generator(this, function (_d) {
|
|
101
101
|
switch (_d.label) {
|
|
102
102
|
case 0:
|
|
@@ -108,14 +108,16 @@ function main(args) {
|
|
|
108
108
|
_c = (_b = index_1.csv).parseCsv;
|
|
109
109
|
return [4 /*yield*/, fs_1.promises.readFile(dwcFile, 'utf-8')];
|
|
110
110
|
case 1:
|
|
111
|
-
_a = _c.apply(_b, [_d.sent()]),
|
|
111
|
+
_a = _c.apply(_b, [_d.sent()]), header = _a[0], dwc = _a.slice(1);
|
|
112
|
+
gbifColumn = header.indexOf('gbifTaxonID');
|
|
113
|
+
gbifAcceptedColumn = header.indexOf('gbifAcceptedTaxonID');
|
|
112
114
|
for (_i = 0, dwc_1 = dwc; _i < dwc_1.length; _i++) {
|
|
113
115
|
taxon = dwc_1[_i];
|
|
114
|
-
gbifId = taxon[
|
|
116
|
+
gbifId = taxon[gbifColumn];
|
|
115
117
|
if (gbifId) {
|
|
116
118
|
addTaxon(gbifIndex, gbifId, taxon);
|
|
117
|
-
if (taxon[
|
|
118
|
-
addTaxon(gbifIndex, taxon[
|
|
119
|
+
if (taxon[gbifAcceptedColumn] !== taxon[gbifColumn]) {
|
|
120
|
+
addTaxon(gbifIndex, taxon[gbifAcceptedColumn], taxon);
|
|
119
121
|
}
|
|
120
122
|
}
|
|
121
123
|
amendedResource.taxonCount += 1;
|
|
@@ -155,7 +155,7 @@ function listUnprocessedFiles(directory, outputDirectory) {
|
|
|
155
155
|
return [4 /*yield*/, fs_1.promises.readdir(outputDirectory)];
|
|
156
156
|
case 2:
|
|
157
157
|
output = new (_a.apply(Set, [void 0, _b.sent()]))();
|
|
158
|
-
return [2 /*return*/, input.filter(function (file) { return output.has(file + '-1'); })];
|
|
158
|
+
return [2 /*return*/, input.filter(function (file) { return !output.has(file + '-1.csv'); })];
|
|
159
159
|
}
|
|
160
160
|
});
|
|
161
161
|
});
|
package/package.json
CHANGED
|
@@ -54,13 +54,15 @@ async function main (args: string[]): Promise<void> {
|
|
|
54
54
|
return
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
const [
|
|
57
|
+
const [header, ...dwc] = csv.parseCsv(await fs.readFile(dwcFile, 'utf-8'))
|
|
58
|
+
const gbifColumn = header.indexOf('gbifTaxonID')
|
|
59
|
+
const gbifAcceptedColumn = header.indexOf('gbifAcceptedTaxonID')
|
|
58
60
|
for (const taxon of dwc) {
|
|
59
|
-
const gbifId = taxon[
|
|
61
|
+
const gbifId = taxon[gbifColumn]
|
|
60
62
|
if (gbifId) {
|
|
61
63
|
addTaxon(gbifIndex, gbifId, taxon)
|
|
62
|
-
if (taxon[
|
|
63
|
-
addTaxon(gbifIndex, taxon[
|
|
64
|
+
if (taxon[gbifAcceptedColumn] !== taxon[gbifColumn]) {
|
|
65
|
+
addTaxon(gbifIndex, taxon[gbifAcceptedColumn], taxon)
|
|
64
66
|
}
|
|
65
67
|
}
|
|
66
68
|
amendedResource.taxonCount += 1
|
|
@@ -98,7 +98,7 @@ async function listFiles (directory: string): Promise<string[]> {
|
|
|
98
98
|
async function listUnprocessedFiles (directory: string, outputDirectory: string): Promise<string[]> {
|
|
99
99
|
const input = await listFiles(directory)
|
|
100
100
|
const output = new Set(await fs.readdir(outputDirectory))
|
|
101
|
-
return input.filter(file => output.has(file + '-1'))
|
|
101
|
+
return input.filter(file => !output.has(file + '-1.csv'))
|
|
102
102
|
}
|
|
103
103
|
|
|
104
104
|
async function listChangedFiles (directory: string): Promise<string[]> {
|