-
Notifications
You must be signed in to change notification settings - Fork 50
/
cli.js
executable file
·142 lines (130 loc) · 3.59 KB
/
cli.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/usr/bin/env node
const osLocale = require('os-locale');
const meow = require('meow');
const { run } = require('../dist/src/index');
const { runImport } = require('../dist/src/import');
const { inquireParams } = require('../dist/src/params');
const { getDefaultLang } = require('../dist/src/lang');
const { getMessage } = require('../dist/src/messages');
const {
HTTP_PROXY,
HTTPS_PROXY,
KINTONE_DOMAIN,
KINTONE_USERNAME,
KINTONE_PASSWORD,
KINTONE_BASIC_AUTH_USERNAME,
KINTONE_BASIC_AUTH_PASSWORD
} = process.env;
const cli = meow(
`
Usage
$ kintone-customize-uploader <manifestFile>
Options
--domain Domain of your kintone
--username Login username
--password User's password
--basic-auth-username Basic Authentication username
--basic-auth-password Basic Authentication password
--proxy Proxy server
--watch Watch the changes of customize files and re-run
--dest-dir -d option for subcommand import.
this option stands for output directory
default value is dest/
--lang Using language (en or ja)
--guest-space-id Guest space ID for uploading files
SubCommands
import generate customize-manifest.json and
download js/css files from existing app customization
You can set the values through environment variables
domain: KINTONE_DOMAIN
username: KINTONE_USERNAME
password: KINTONE_PASSWORD
basic-auth-username: KINTONE_BASIC_AUTH_USERNAME
basic-auth-password: KINTONE_BASIC_AUTH_PASSWORD
proxy: HTTPS_PROXY or HTTP_PROXY
`,
{
flags: {
domain: {
type: 'string',
default: KINTONE_DOMAIN
},
username: {
type: 'string',
default: KINTONE_USERNAME
},
password: {
type: 'string',
default: KINTONE_PASSWORD
},
basicAuthUsername: {
type: 'string',
default: KINTONE_BASIC_AUTH_USERNAME
},
basicAuthPassword: {
type: 'string',
default: KINTONE_BASIC_AUTH_PASSWORD
},
proxy: {
type: 'string',
default: HTTPS_PROXY || HTTP_PROXY
},
watch: {
type: 'boolean',
default: false
},
lang: {
type: 'string',
default: getDefaultLang(osLocale.sync())
},
guestSpaceId: {
type: 'number',
default: 0
},
// Optional option for import subcommand
destDir: {
type: 'string',
default: 'dest',
alias: 'd'
}
}
}
);
const subCommands = ["import"];
const hasSubCommand = subCommands.indexOf(cli.input[0]) >= 0;
const subCommand = hasSubCommand ? cli.input[0] : null;
const isImportCommand = subCommand === "import";
const manifestFile = hasSubCommand ? cli.input[1] : cli.input[0];
const {
username,
password,
basicAuthUsername,
basicAuthPassword,
domain,
proxy,
watch,
lang,
guestSpaceId,
destDir,
} = cli.flags;
const options = proxy ? { watch, lang, proxy } : { watch, lang };
if (guestSpaceId) {
options.guestSpaceId = guestSpaceId;
}
if(isImportCommand) {
options.destDir = destDir;
}
if (!manifestFile) {
console.error(getMessage(lang, 'E_requiredManifestFile'));
cli.showHelp();
process.exit(1);
}
inquireParams({ username, password, domain, lang })
.then(({ username, password, domain }) => {
if(isImportCommand) {
runImport(domain, username, password, basicAuthUsername, basicAuthPassword, manifestFile, options)
} else {
run(domain, username, password, basicAuthUsername, basicAuthPassword, manifestFile, options)
}
})
.catch(error => console.log(error.message));