wikibase-cli 15.15.6 → 15.16.3
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/README.md +2 -0
- package/bin/wb-claims +1 -0
- package/bin/wb-props +1 -1
- package/bin/wd +9 -2
- package/lib/get_pattern_filter.js +19 -2
- package/lib/log_claims.js +1 -1
- package/lib/output.js +7 -5
- package/metadata/claims.js +1 -1
- package/metadata/props.js +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@ This tool is mostly a CLI interface to the JS modules [wikibase-edit](https://ww
|
|
|
5
5
|
|
|
6
6
|
It was primarily developed to target [Wikidata](https://wikidata.org), but as then been decoupled to support any Wikibase instance.
|
|
7
7
|
|
|
8
|
+
Supported systems: any system that can run [NodeJS](https://nodejs.org/en/download/) (Linux, Mac OS, Windows, and more)
|
|
9
|
+
|
|
8
10
|
This project received [a Wikimedia Project Grant](https://meta.wikimedia.org/wiki/Grants:Project/WikidataJS).
|
|
9
11
|
|
|
10
12
|
<div align="center">
|
package/bin/wb-claims
CHANGED
package/bin/wb-props
CHANGED
|
@@ -4,7 +4,7 @@ const { red } = require('chalk')
|
|
|
4
4
|
|
|
5
5
|
program
|
|
6
6
|
.option('-d, --details', 'include properties labels, types, descriptions, and aliases')
|
|
7
|
-
.option('-t, --type', 'include properties types')
|
|
7
|
+
.option('-t, --type [type]', 'include properties types, or if a type is specified, keep only properties with that type')
|
|
8
8
|
.option('--no-cache', 'ignore properties cache')
|
|
9
9
|
.option('-r, --reset', 'clear properties cache')
|
|
10
10
|
.process('props')
|
package/bin/wd
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
#!/usr/bin/env
|
|
2
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
process.env.WB_INSTANCE = 'https://www.wikidata.org'
|
|
4
|
+
process.env.WB_SPARQL_ENDPOINT = 'https://query.wikidata.org/sparql'
|
|
5
|
+
// Fake the executed script to be wb to trick commander to believe it
|
|
6
|
+
// as it would otherwise fail to build subcommand paths
|
|
7
|
+
process.argv[1] = process.argv[1].replace(/\/wd$/, '/wb')
|
|
8
|
+
|
|
9
|
+
require('./wb')
|
|
@@ -1,9 +1,18 @@
|
|
|
1
|
+
const program = require('./program')
|
|
1
2
|
const { propTypes } = require('./properties')
|
|
2
3
|
|
|
3
4
|
module.exports = (pattern, includeTypes) => {
|
|
4
|
-
|
|
5
|
+
const { type } = program
|
|
6
|
+
if (!(pattern && pattern.length > 0)) {
|
|
7
|
+
if (typeof type === 'string') {
|
|
8
|
+
// Consider that what was passed as a type argument was actually a pattern
|
|
9
|
+
if (!(type.toLowerCase() in propTypes)) pattern = type
|
|
10
|
+
} else {
|
|
11
|
+
return
|
|
12
|
+
}
|
|
13
|
+
}
|
|
5
14
|
|
|
6
|
-
if (includeTypes && pattern in propTypes) {
|
|
15
|
+
if (includeTypes && pattern.toLowerCase() in propTypes) {
|
|
7
16
|
return propData => propData.type === pattern
|
|
8
17
|
}
|
|
9
18
|
|
|
@@ -13,7 +22,15 @@ module.exports = (pattern, includeTypes) => {
|
|
|
13
22
|
const flag = allLowercased ? 'ig' : 'g'
|
|
14
23
|
const filterRegex = new RegExp(pattern, flag)
|
|
15
24
|
|
|
25
|
+
let typeFilter
|
|
26
|
+
if (typeof type === 'string' && type.toLowerCase() in propTypes) {
|
|
27
|
+
typeFilter = propData => propData.type === type
|
|
28
|
+
} else {
|
|
29
|
+
typeFilter = () => true
|
|
30
|
+
}
|
|
31
|
+
|
|
16
32
|
const filterFn = propData => {
|
|
33
|
+
if (!typeFilter(propData)) return false
|
|
17
34
|
if (propData == null) return false
|
|
18
35
|
const { label, description, aliases } = propData
|
|
19
36
|
const propStr = [ label, description, aliases ].join(' ')
|
package/lib/log_claims.js
CHANGED
|
@@ -16,7 +16,7 @@ module.exports = async ({ program, simplifiedClaims, extraData = {}, pattern, re
|
|
|
16
16
|
|
|
17
17
|
logExtraData(extraData, labels)
|
|
18
18
|
|
|
19
|
-
if (pattern) {
|
|
19
|
+
if (pattern || program.type) {
|
|
20
20
|
simplifiedClaims = filterClaimsProperties(propertiesData, simplifiedClaims, pattern)
|
|
21
21
|
}
|
|
22
22
|
|
package/lib/output.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
const types = require('./types')
|
|
2
|
+
const { promisify } = require('util')
|
|
3
|
+
const stdoutWrite = promisify(process.stdout.write).bind(process.stdout)
|
|
2
4
|
|
|
3
5
|
// Calling program just in time, so that code running
|
|
4
6
|
// after this first level function can still change the option
|
|
5
|
-
module.exports = program => (data, optional, customColors) => {
|
|
7
|
+
module.exports = program => async (data, optional, customColors) => {
|
|
6
8
|
const isArray = types.isArray(data)
|
|
7
9
|
const isPlainObject = types.isPlainObject(data)
|
|
8
10
|
const isCollection = types.isCollection(data)
|
|
@@ -16,7 +18,7 @@ module.exports = program => (data, optional, customColors) => {
|
|
|
16
18
|
if (optional) {
|
|
17
19
|
if (!program.verbose) return
|
|
18
20
|
if (!customColors) data = require('chalk').grey(data)
|
|
19
|
-
log(data)
|
|
21
|
+
await log(data)
|
|
20
22
|
} else {
|
|
21
23
|
if (isArray && !isCollection && !program.json) {
|
|
22
24
|
if (program.format === 'inline') data = data.join(' ')
|
|
@@ -36,16 +38,16 @@ module.exports = program => (data, optional, customColors) => {
|
|
|
36
38
|
if (program.clipboard) {
|
|
37
39
|
require('./copy')(data)
|
|
38
40
|
} else {
|
|
39
|
-
log(data)
|
|
41
|
+
await log(data)
|
|
40
42
|
process.exit(0)
|
|
41
43
|
}
|
|
42
44
|
}
|
|
43
45
|
}
|
|
44
46
|
|
|
45
|
-
const log = data => {
|
|
47
|
+
const log = async data => {
|
|
46
48
|
if (typeof data === 'string') {
|
|
47
49
|
if (!data.endsWith('\n')) data += '\n'
|
|
48
|
-
|
|
50
|
+
await stdoutWrite(data)
|
|
49
51
|
} else {
|
|
50
52
|
console.log(data)
|
|
51
53
|
}
|
package/metadata/claims.js
CHANGED
|
@@ -13,7 +13,7 @@ module.exports = {
|
|
|
13
13
|
examples: [
|
|
14
14
|
{ args: 'Q2001', comment: 'fetch all claims for the entity Q2001' },
|
|
15
15
|
{ args: 'Q2001 P106', comment: 'or just the claims for the property P106' },
|
|
16
|
-
{ args: 'Q2001 Url', comment: 'or just the claims from properties of type Url (other possible types: ExternalId, String, WikibaseItem, WikibaseProperty, Time, Monolingualtext, Quantity, CommonsMedia, GlobeCoordinate)' },
|
|
16
|
+
{ args: 'Q2001 --type Url', comment: 'or just the claims from properties of type Url (other possible types: ExternalId, String, WikibaseItem, WikibaseProperty, Time, Monolingualtext, Quantity, CommonsMedia, GlobeCoordinate)' },
|
|
17
17
|
{ args: 'Q2001 library', comment: 'or just the claims from properties with labels matching "library"' },
|
|
18
18
|
{ args: 'Q2001 website', comment: 'or website, etc' },
|
|
19
19
|
{ args: 'Q2001 --lang de', comment: 'fetch all claims for the entity Q2001 with properties labels in German' }
|
package/metadata/props.js
CHANGED
|
@@ -16,6 +16,7 @@ module.exports = {
|
|
|
16
16
|
{ args: '--details', comment: 'output all properties, with their labels, types, descriptions, and aliases' },
|
|
17
17
|
{ args: 'image', comment: 'filter the properties to keep only those with labels matching "image"' },
|
|
18
18
|
{ args: '--type Url', comment: 'filter the properties to keep only those of type Url (other possible types: ExternalId, String, WikibaseItem, WikibaseProperty, Time, Monolingualtext, Quantity, CommonsMedia, GlobeCoordinate)' },
|
|
19
|
+
{ args: '--type Url ref', comment: 'filter the properties to keep only those of type Url matching the pattern "ref"' },
|
|
19
20
|
{ args: '--lang sv', comment: 'output all the properties with their label in Swedish' },
|
|
20
21
|
{ args: '--no-cache', comment: 'ignore properties cache: fetch properties from the SPARQL endpoint, even if already cached' },
|
|
21
22
|
{ args: '--reset', comment: 'delete all the cached properties files to get fresh versions on the next execution' }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wikibase-cli",
|
|
3
|
-
"version": "15.
|
|
3
|
+
"version": "15.16.3",
|
|
4
4
|
"description": "A command-line interface to Wikibase",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"lint-staged": "./scripts/lint_staged",
|
|
14
14
|
"prepublishOnly": "npm run lint && npm test",
|
|
15
15
|
"postpublish": "npm run docker:publish && git push --tags",
|
|
16
|
-
"test": "mocha --exit --timeout 20000",
|
|
16
|
+
"test": "mocha --exit --timeout 20000 $MOCHA_OPTIONS",
|
|
17
17
|
"update-toc": "./scripts/update_toc"
|
|
18
18
|
},
|
|
19
19
|
"repository": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"read": "^1.0.7",
|
|
50
50
|
"split": "^1.0.1",
|
|
51
51
|
"through": "^2.3.8",
|
|
52
|
-
"wikibase-edit": "^4.
|
|
52
|
+
"wikibase-edit": "^4.16.0",
|
|
53
53
|
"wikibase-sdk": "^7.14.1",
|
|
54
54
|
"wikidata-lang": "^2.0.11"
|
|
55
55
|
},
|