wikibase-cli 17.0.0 → 17.0.1

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 CHANGED
@@ -54,7 +54,7 @@ See [CHANGELOG.md](CHANGELOG.md) for version info
54
54
  ## Dependencies
55
55
 
56
56
  ### General
57
- * [NodeJs](https://nodejs.org) **>= v10** (recommended way to install it: use the awesome [NVM](https://github.com/creationix/nvm) to install the latest LTS version `nvm install --lts`)
57
+ * [NodeJs](https://nodejs.org) **>= v14** (recommended way to install it: use the awesome [NVM](https://github.com/creationix/nvm) to install the latest LTS version `nvm install --lts`)
58
58
  * [Git](https://git-scm.com/)
59
59
 
60
60
  ### Per feature
package/bin/wd.js CHANGED
@@ -3,6 +3,10 @@ process.env.WB_INSTANCE = 'https://www.wikidata.org'
3
3
  process.env.WB_SPARQL_ENDPOINT = 'https://query.wikidata.org/sparql'
4
4
  // Fake the executed script to be wb to trick commander to believe it
5
5
  // as it would otherwise fail to build subcommand paths
6
- process.argv[1] = process.argv[1].replace(/wd\.js$/, 'wb.js')
6
+ process.argv[1] = process.argv[1]
7
+ // Case when called directly as ./bin/wd.js
8
+ .replace(/wd\.js$/, 'wb.js')
9
+ // Case when called directly as a link such as defined in package.json, ./node_modules/.bin/wd
10
+ .replace(/wd$/, 'wb')
7
11
 
8
12
  await import('./wb.js')
@@ -1,7 +1,7 @@
1
1
  // Args can't be just a line splitted on spaces
2
2
  // as there are JSON strings arguments, and signle or double quoted strings args
3
3
 
4
- import { parse } from 'shell-quote'
4
+ import parse from 'shell-quote/parse.js'
5
5
 
6
6
  export default line => {
7
7
  // One JSON object as single argument
@@ -1,9 +1,6 @@
1
- import { promisify } from 'node:util'
2
1
  import read from 'read'
3
2
  import { blue, yellow, grey } from '#lib/chalk'
4
3
 
5
- const readAsync = promisify(read)
6
-
7
4
  export default readsData => {
8
5
  const results = {}
9
6
 
@@ -30,7 +27,7 @@ const prompt = (label, pattern, options, info) => {
30
27
  })
31
28
  message += '\n-'
32
29
  }
33
- let res = await readAsync({ prompt: message })
30
+ let res = await read({ prompt: message })
34
31
  res = res.trim()
35
32
  if (!pattern || pattern.test(res)) {
36
33
  return res
@@ -22,6 +22,7 @@ export default (entity, attribute, lang, strictLang) => {
22
22
 
23
23
  const attributesPerType = {
24
24
  item: [ 'labels', 'descriptions', 'aliases' ],
25
- property: [ 'labels', 'descriptions', 'aliases' ],
26
25
  lexeme: [ 'lemmas' ],
26
+ mediainfo: [ 'labels', 'descriptions' ],
27
+ property: [ 'labels', 'descriptions', 'aliases' ],
27
28
  }
package/lib/fs.js CHANGED
@@ -1,28 +1,13 @@
1
- import fs from 'node:fs'
2
- import mkdirp from 'mkdirp'
1
+ import { accessSync, constants } from 'node:fs'
2
+ import { access } from 'node:fs/promises'
3
3
 
4
- export const writeFile = (filepath, content) => {
5
- return new Promise((resolve, reject) => {
6
- fs.writeFile(filepath, content, (err, res) => {
7
- err ? reject(err) : resolve(res)
8
- })
9
- })
10
- }
11
- export const exists = path => {
12
- return new Promise((resolve, reject) => {
13
- fs.access(path, (err, res) => err ? reject(err) : resolve(res))
14
- })
15
- }
16
- export const createFolder = path => {
17
- return new Promise((resolve, reject) => {
18
- mkdirp(path, err => err ? reject(err) : resolve())
19
- })
20
- }
21
- export const writeAccessSync = path => {
4
+ export const exists = path => access(path)
5
+
6
+ export const assertWriteAccessSync = path => {
22
7
  // Testing right to write
23
8
  // cf https://nodejs.org/api/fs.html#fs_fs_access_path_mode_callback
24
9
  // Will throw if failing
25
- fs.accessSync(path, fs.constants.W_OK)
10
+ accessSync(path, constants.W_OK)
26
11
  }
27
12
 
28
13
  export function getDirname (fileUrl) {
@@ -1,15 +1,18 @@
1
- import { exists, createFolder } from './fs.js'
1
+ import { access } from 'node:fs/promises'
2
+ import { mkdirp } from 'mkdirp'
2
3
  import getFolderPath from './get_folder_path.js'
3
4
 
4
- export default subfolder => {
5
+ export async function getCacheFolderPath (subfolder) {
5
6
  const subfolderPath = getFolderPath('cache', subfolder)
6
- return exists(subfolderPath)
7
- .catch(err => {
7
+ try {
8
+ await access(subfolderPath)
9
+ return subfolderPath
10
+ } catch (err) {
8
11
  if (err.code === 'ENOENT') {
9
- return createFolder(subfolderPath)
12
+ await mkdirp(subfolderPath)
13
+ return subfolderPath
10
14
  } else {
11
15
  throw err
12
16
  }
13
- })
14
- .then(() => subfolderPath)
17
+ }
15
18
  }
@@ -1,9 +1,9 @@
1
- import os from 'node:os'
1
+ import { homedir } from 'node:os'
2
2
  import path from 'node:path'
3
- import mkdirp from 'mkdirp'
4
- import { writeAccessSync } from './fs.js'
3
+ import { mkdirp } from 'mkdirp'
4
+ import { assertWriteAccessSync } from './fs.js'
5
5
 
6
- const homePath = os.homedir()
6
+ const homePath = homedir()
7
7
 
8
8
  export default (category, subfolderName) => {
9
9
  let folderPath
@@ -17,7 +17,7 @@ export default (category, subfolderName) => {
17
17
  }
18
18
  mkdirp.sync(folderPath)
19
19
  // Make sure we have write access right in case the folder already existed
20
- writeAccessSync(folderPath)
20
+ assertWriteAccessSync(folderPath)
21
21
 
22
22
  return folderPath
23
23
  }
@@ -1,9 +1,9 @@
1
+ import { writeFile } from 'node:fs/promises'
1
2
  import { URL } from 'node:url'
2
- import getCacheFolderPath from '#lib/get_cache_folder_path'
3
+ import { getCacheFolderPath } from '#lib/get_cache_folder_path'
3
4
  import { hashString } from '#lib/hash_string'
4
5
  import { readJsonFile } from '#lib/json'
5
6
  import fetchLangProps from './fetch_lang_props.js'
6
- import { writeFile } from './fs.js'
7
7
 
8
8
  export default async program => {
9
9
  const { lang, sparqlEndpoint, noCache } = program
@@ -1,4 +1,5 @@
1
1
  import { execSync } from 'node:child_process'
2
+ import { dirname } from 'node:path'
2
3
  import { grey } from '#lib/chalk'
3
4
 
4
5
  export default (command, examples, doc, dryRun = false) => {
@@ -8,10 +9,9 @@ export default (command, examples, doc, dryRun = false) => {
8
9
  let { args, comment } = example
9
10
  if (args instanceof Array) args = args.join(' ')
10
11
  if (comment) console.log(grey(`\n # ${comment}`))
11
- const cmd = `wb ${command} ${args}`
12
- console.log(` ${cmd}`)
12
+ console.log(` wb ${command} ${args}`)
13
13
  if (dryRun && example.dryRun !== false) {
14
- const generatedData = execSync(`${cmd} --dry`).toString()
14
+ const generatedData = execSync(`${getWbAbsolutePath()} ${command} ${args} --dry`).toString()
15
15
  console.log(grey(' # output:'))
16
16
  if (command.startsWith('sparql')) console.log(formatSparql(generatedData))
17
17
  else console.log(formatJsonInMixedOutput(generatedData))
@@ -23,6 +23,11 @@ export default (command, examples, doc, dryRun = false) => {
23
23
  console.log('')
24
24
  }
25
25
 
26
+ function getWbAbsolutePath () {
27
+ const binDirectory = dirname(process.argv[1])
28
+ return `${binDirectory}/wb.js`
29
+ }
30
+
26
31
  const indent = line => ' ' + line
27
32
 
28
33
  const formatJsonInMixedOutput = output => {
@@ -1,6 +1,6 @@
1
1
  import { exec } from 'node:child_process'
2
2
  import { green } from '#lib/chalk'
3
- import getCacheFolderPath from '#lib/get_cache_folder_path'
3
+ import { getCacheFolderPath } from '#lib/get_cache_folder_path'
4
4
 
5
5
  export default () => {
6
6
  return getCacheFolderPath('props')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wikibase-cli",
3
- "version": "17.0.0",
3
+ "version": "17.0.1",
4
4
  "description": "A command-line interface to Wikibase",
5
5
  "type": "module",
6
6
  "main": "index.js",
@@ -11,8 +11,8 @@
11
11
  "scripts": {
12
12
  "docker:publish": "./scripts/docker_publish",
13
13
  "git-pre-commit": "./scripts/githooks/pre-commit",
14
- "lint": "eslint -c .eslintrc.cjs bin/wb* lib/* lib/*/* test/* test/lib/*",
15
- "lint-fix": "eslint -c .eslintrc.cjs --fix bin/wb* lib/* lib/*/* test/* test/lib/*",
14
+ "lint": "eslint --config .eslintrc.cjs bin/* lib test",
15
+ "lint-fix": "eslint --config .eslintrc.cjs --fix bin/* lib test",
16
16
  "lint-staged": "./scripts/lint_staged",
17
17
  "prepublishOnly": "npm run lint && npm test",
18
18
  "postpublish": "npm run docker:publish && git push --tags",
@@ -47,15 +47,15 @@
47
47
  },
48
48
  "homepage": "https://github.com/maxlath/wikibase-cli#readme",
49
49
  "dependencies": {
50
- "chalk": "^2.4.2",
50
+ "chalk": "^5.3.0",
51
51
  "commander": "^6.0.0",
52
- "copy-paste": "^1.3.0",
52
+ "copy-paste": "^1.5.3",
53
53
  "lodash-es": "^4.17.21",
54
- "mkdirp": "^0.5.1",
54
+ "mkdirp": "^3.0.1",
55
55
  "node-fetch": "^2.6.0",
56
- "open": "^7.0.4",
57
- "read": "^1.0.7",
58
- "shell-quote": "^1.7.3",
56
+ "open": "^9.1.0",
57
+ "read": "^2.1.0",
58
+ "shell-quote": "^1.8.1",
59
59
  "split": "^1.0.1",
60
60
  "through": "^2.3.8",
61
61
  "wikibase-edit": "^6.0.1",
@@ -75,6 +75,6 @@
75
75
  "should": "^13.2.3"
76
76
  },
77
77
  "engines": {
78
- "node": ">= 14.0.0"
78
+ "node": ">= 14.17.0"
79
79
  }
80
80
  }