-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
81 lines (75 loc) · 1.75 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env node
'use strict'
const program = require('commander')
const { generateFilesFromSpreadsheet } = require('./lib')
// Used to get version number from package.json
require('pkginfo')(module, 'version')
// Default options values
const DEFAULT_BEAUTIFY = 0
const DEFAULT_CLIENT = './client_secret.json'
const DEFAULT_FORMAT = 'json'
const DEFAULT_KEY_INDEX = 0
const DEFAULT_LANG_INDEX = 1
const DEFAULT_OUTPUT_DIR = './locales'
const DEFAULT_RANGE = 'Sheet1'
const DEFAULT_TOKEN = './credentials.json'
// Generate documentation and parse arguments
program
.name("gs-i18n")
.usage('<spreadsheetId> [options]')
.version(module.exports.version, '-v, --version')
.arguments('<spreadsheetId>')
.option(
'-b, --beautify <number>', // TODO: Allow string to handle tabs?
'number of spaces to insert white space in JSON/JS files (min: 0, max: 10)',
parseInt,
DEFAULT_BEAUTIFY,
)
.option(
'-c, --client <path>',
'path of client secret file',
DEFAULT_CLIENT,
)
.option(
'-f, --format <format>',
'format of generated files (available values: "cjs", "esm", "json")',
DEFAULT_FORMAT,
)
.option(
'-k, --key <index>',
'index of key column',
DEFAULT_KEY_INDEX,
)
.option(
'-l, --lang <index>',
'index of first language column',
DEFAULT_LANG_INDEX,
)
.option(
'-o, --output <path>',
'path of output directory',
DEFAULT_OUTPUT_DIR,
)
.option(
'-r, --range <range>',
'range of data to parse',
DEFAULT_RANGE,
)
.option(
'-t, --token <path>',
'path of credentials file',
DEFAULT_TOKEN,
)
.parse(process.argv)
// Run script
generateFilesFromSpreadsheet(
program.args[0], // spreadsheetId
program.client,
program.token,
program.range,
program.key,
program.lang,
program.output,
program.format,
program.beautify,
)