wikibase-cli 18.2.1 → 18.3.0
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/lib/config/check_config_file_existance.js +28 -0
- package/lib/config/file_path.js +20 -11
- package/lib/get_claims_texts.js +1 -1
- package/lib/global_options_help.js +5 -1
- package/lib/platform_agnostic_path.js +6 -0
- package/lib/program.js +7 -4
- package/lib/properties.js +12 -11
- package/package.json +1 -1
- package/lib/path.js +0 -3
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { access, writeFile } from 'fs/promises'
|
|
2
|
+
import read from 'read'
|
|
3
|
+
|
|
4
|
+
export async function checkConfigFileExistance (configFilePath) {
|
|
5
|
+
try {
|
|
6
|
+
await access(configFilePath)
|
|
7
|
+
} catch (err) {
|
|
8
|
+
if (err.code === 'ENOENT') {
|
|
9
|
+
await offerToCreateMissingConfigFile(configFilePath)
|
|
10
|
+
} else {
|
|
11
|
+
throw err
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function offerToCreateMissingConfigFile (configFilePath) {
|
|
17
|
+
try {
|
|
18
|
+
const res = await read({ prompt: `Config file not found at ${configFilePath}. Create? y/N` })
|
|
19
|
+
if (res.trim() === 'y') {
|
|
20
|
+
await writeFile(configFilePath, '{}', { mode: 0o600 })
|
|
21
|
+
} else {
|
|
22
|
+
process.exit(1)
|
|
23
|
+
}
|
|
24
|
+
} catch (err) {
|
|
25
|
+
if (err.message === 'canceled') process.exit(1)
|
|
26
|
+
else throw err
|
|
27
|
+
}
|
|
28
|
+
}
|
package/lib/config/file_path.js
CHANGED
|
@@ -1,20 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { join, resolve } from '#lib/platform_agnostic_path'
|
|
2
2
|
import configFolderFactory from '../get_folder_path.js'
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
const configFolder = configFolderFactory('config')
|
|
3
|
+
import { checkConfigFileExistance } from './check_config_file_existance.js'
|
|
6
4
|
|
|
7
5
|
export let configFilePath
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
configFilePath = path.join(configFolder, 'config.json')
|
|
7
|
+
const configFolder = configFolderFactory('config')
|
|
11
8
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
// Arguments parsing needs to be done manually as relying on lib/program
|
|
10
|
+
// would be a circular dependecy
|
|
11
|
+
const args = process.argv.slice(2)
|
|
12
|
+
const configArg = args.find(arg => arg.startsWith('--config'))
|
|
13
|
+
if (configArg) {
|
|
14
|
+
let configFilePathFromArgs
|
|
15
|
+
if (configArg.split('=')[1]) {
|
|
16
|
+
configFilePathFromArgs = configArg.split('=')[1]
|
|
17
|
+
} else {
|
|
18
|
+
configFilePathFromArgs = args[args.indexOf(configArg) + 1]
|
|
17
19
|
}
|
|
20
|
+
configFilePath = resolve(process.cwd(), configFilePathFromArgs)
|
|
21
|
+
} else if (process.env.WB_CONFIG) {
|
|
22
|
+
configFilePath = process.env.WB_CONFIG
|
|
23
|
+
} else if (configFolder != null) {
|
|
24
|
+
configFilePath = join(configFolder, 'config.json')
|
|
18
25
|
} else {
|
|
19
26
|
configFilePath = null
|
|
20
27
|
}
|
|
28
|
+
|
|
29
|
+
if (configFilePath) await checkConfigFileExistance(configFilePath)
|
package/lib/get_claims_texts.js
CHANGED
|
@@ -21,7 +21,7 @@ const buildClaimsText = (labels, prop, values, propertiesData) => {
|
|
|
21
21
|
if (!propData) return missingProperty(prop)
|
|
22
22
|
|
|
23
23
|
const { label, type } = propData
|
|
24
|
-
const propColor = propTypes[type]
|
|
24
|
+
const propColor = propTypes[type]?.color
|
|
25
25
|
const propLabel = propColor ? chalk[propColor](label) : black(bgWhite(label))
|
|
26
26
|
|
|
27
27
|
const propText = formatEntity(propLabel, prop) + grey(': ')
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
export
|
|
1
|
+
export const globalOptions = {
|
|
2
|
+
config: [ '--config <path>', 'Path to the config.json file' ],
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export const commandSpecificOptions = {
|
|
2
6
|
lang: [ '-l, --lang <lang>', 'specify the language to use' ],
|
|
3
7
|
verbose: [ '-v, --verbose', 'make the output more verbose' ],
|
|
4
8
|
dry: [ '-d, --dry', 'output the generated data, do not run the query' ],
|
package/lib/program.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import program from 'commander'
|
|
4
4
|
import { debug } from '#lib/debug'
|
|
5
5
|
import { applyEnvAndConfigDefault } from './apply_env_and_config_default.js'
|
|
6
|
-
import
|
|
6
|
+
import { globalOptions, commandSpecificOptions } from './global_options_help.js'
|
|
7
7
|
import logCommandExamples from './log_command_examples.js'
|
|
8
8
|
|
|
9
9
|
program.process = async command => {
|
|
@@ -14,9 +14,12 @@ program.process = async command => {
|
|
|
14
14
|
;({ options } = metadata)
|
|
15
15
|
program.arguments(args)
|
|
16
16
|
program.description(description)
|
|
17
|
-
Object.
|
|
18
|
-
if (options[
|
|
19
|
-
}
|
|
17
|
+
for (const [ name, params ] of Object.entries(commandSpecificOptions)) {
|
|
18
|
+
if (options[name]) program.option(...params)
|
|
19
|
+
}
|
|
20
|
+
for (const params of Object.values(globalOptions)) {
|
|
21
|
+
program.option(...params)
|
|
22
|
+
}
|
|
20
23
|
program.on('--help', () => logCommandExamples(command, examples, doc))
|
|
21
24
|
}
|
|
22
25
|
const isCommandsWithCustomHelpMenu = program.customHelpOption != null
|
package/lib/properties.js
CHANGED
|
@@ -3,21 +3,22 @@ export const mainProps = {
|
|
|
3
3
|
}
|
|
4
4
|
|
|
5
5
|
export const propTypes = {
|
|
6
|
-
'external-id': { factor: 0.1, color: 'grey' },
|
|
7
|
-
string: { factor: 1 },
|
|
8
|
-
'wikibase-item': { factor: 1 },
|
|
9
|
-
time: { factor: 1 },
|
|
10
|
-
monolingualtext: { factor: 2 },
|
|
11
|
-
quantity: { factor: 1 },
|
|
12
|
-
'wikibase-property': { factor: 1 },
|
|
13
|
-
url: { factor: 0.5 },
|
|
14
6
|
commonsMedia: { factor: 0.5 },
|
|
7
|
+
'entity-schema': { factor: 0.5 },
|
|
8
|
+
'external-id': { factor: 0.1, color: 'grey' },
|
|
9
|
+
'geo-shape': { factor: 0.5 },
|
|
15
10
|
'globe-coordinate': { factor: 0.5 },
|
|
16
11
|
math: { factor: 0.5 },
|
|
17
|
-
|
|
12
|
+
monolingualtext: { factor: 2 },
|
|
13
|
+
'musical-notation': { factor: 0.5 },
|
|
14
|
+
quantity: { factor: 1 },
|
|
15
|
+
string: { factor: 1 },
|
|
18
16
|
'tabular-data': { factor: 0.5 },
|
|
19
|
-
|
|
17
|
+
time: { factor: 1 },
|
|
18
|
+
url: { factor: 0.5 },
|
|
20
19
|
'wikibase-form': { factor: 0.5 },
|
|
20
|
+
'wikibase-item': { factor: 1 },
|
|
21
|
+
'wikibase-lexeme': { factor: 0.5 },
|
|
22
|
+
'wikibase-property': { factor: 1 },
|
|
21
23
|
'wikibase-sense': { factor: 0.5 },
|
|
22
|
-
'musical-notation': { factor: 0.5 },
|
|
23
24
|
}
|
package/package.json
CHANGED
package/lib/path.js
DELETED