@algolia/cli 4.0.8 → 5.10.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/index.js DELETED
@@ -1,373 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const program = require('commander');
4
- const { version } = require('./package.json');
5
- const chalk = require('chalk');
6
- const commands = require('./commands.js');
7
-
8
- // DOCS
9
-
10
- const examples = `
11
- Examples:
12
-
13
- $ algolia --help
14
- $ algolia --version
15
- $ algolia interactive
16
- $ algolia search -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -n EXAMPLE_INDEX_NAME -q 'example query' -p '{"filters":["category:book"]}' -o ~/Desktop/results.json
17
- $ algolia import -s ~/Desktop/example_data.json -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -n EXAMPLE_INDEX_NAME -b 5000 -t ~/Desktop/example_transformations.js -m 4 -p '{"delimiter":[":"]}'
18
- $ algolia export -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -n EXAMPLE_INDEX_NAME -o ~/Desktop/output_folder/ -p '{"filters":["category:book"]}'
19
- $ algolia getsettings -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -n EXAMPLE_INDEX_NAME
20
- $ algolia setsettings -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -n EXAMPLE_INDEX_NAME -s ~/Desktop/example_settings.js -p '{"forwardToReplicas":true}'
21
- $ algolia addrules -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -n EXAMPLE_INDEX_NAME -s ~/Desktop/example_rules.json
22
- $ algolia addsynonyms -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -n EXAMPLE_INDEX_NAME -s ~/Desktop/example_synonyms.csv
23
- $ algolia exportrules -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -n EXAMPLE_INDEX_NAME -o ~/Desktop/output_file.json
24
- $ algolia exportsynonyms -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -n EXAMPLE_INDEX_NAME -o ~/Desktop/output_file.json
25
- $ algolia transferindex -a EXAMPLE_SOURCE_APP_ID -k EXAMPLE_SOURCE_API_KEY -n EXAMPLE_SOURCE_INDEX_NAME -d EXAMPLE_DESTINATION_APP_ID -y EXAMPLE_DESTINATION_API_KEY -i EXAMPLE_DESTINATION_INDEX_NAME -t ~/Desktop/example_transformations.js -e true
26
- $ algolia transferindexconfig -a EXAMPLE_SOURCE_APP_ID -k EXAMPLE_SOURCE_API_KEY -n EXAMPLE_SOURCE_INDEX_NAME -d EXAMPLE_DESTINATION_APP_ID -y EXAMPLE_DESTINATION_API_KEY -i EXAMPLE_DESTINATION_INDEX_NAME -p '{"batchSynonymsParams":{"forwardToReplicas":true}}' -e true
27
- $ algolia deleteindicespattern -a EXAMPLE_APP_ID -k EXAMPLE_API_KEY -r '^regex' -x true
28
- $ algolia transformlines -s ~/Desktop/example_source.json -o ~/Desktop/example_output.json -t ~/Desktop/example_transformations.js
29
- $ algolia examples
30
- `;
31
-
32
- // HELPERS
33
-
34
- const registerDefaultProcessEventListeners = () => {
35
- // Handle process cancellation
36
- process.on('SIGINT', () => {
37
- console.log(chalk.white.bgYellow('\nCancelled'));
38
- process.exit(1);
39
- });
40
- // Handle uncaught exceptions
41
- process.on('uncaughtException', e => {
42
- process.exitCode = 1;
43
- console.log(chalk.white.bgRed('\nUncaught Exception'), chalk.red(`\n${e}`));
44
- });
45
- };
46
-
47
- const defaultCommand = command => {
48
- console.error(`Unknown command "${command}".`);
49
- console.error('Run "algolia --help" to view options.');
50
- process.exit(1);
51
- };
52
-
53
- // COMMANDS
54
-
55
- program.version(version, '-v, --version');
56
-
57
- // Search
58
- program
59
- .command('search')
60
- .alias('s')
61
- .description('Search an Algolia index')
62
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
63
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
64
- .option(
65
- '-n, --algoliaindexname <algoliaIndexName>',
66
- 'Required | Algolia index name'
67
- )
68
- .option('-q, --query <query>', 'Optional | Algolia search query string')
69
- .option('-p, --params <params>', 'Optional | Algolia search params')
70
- .option('-o, --outputpath <outputPath>', 'Optional | Output filepath')
71
- .action(cmd => {
72
- commands.search.start(cmd);
73
- });
74
-
75
- // Import
76
- program
77
- .command('import')
78
- .alias('i')
79
- .description('Import local JSON or CSV data to an Algolia index')
80
- .option('-s, --sourcefilepath <sourceFilepath>', 'Required | Source filepath')
81
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
82
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
83
- .option(
84
- '-n, --algoliaindexname <algoliaIndexName>',
85
- 'Required | Algolia index name'
86
- )
87
- .option(
88
- '-b, --batchsize <batchSize>',
89
- 'Optional | Number of objects to import per batch'
90
- )
91
- .option(
92
- '-t, --transformationfilepath <transformationFilepath>',
93
- 'Optional | Transformation filepath'
94
- )
95
- .option(
96
- '-m, --maxconcurrency <maxConcurrency>',
97
- 'Optional | Maximum number of concurrent filestreams to process'
98
- )
99
- .option('-p, --params <params>', 'Optional | CsvToJson params')
100
- .action(cmd => {
101
- commands.import.start(cmd);
102
- });
103
-
104
- // Export
105
- program
106
- .command('export')
107
- .alias('e')
108
- .description('Export the contents of an Algolia index to local JSON files')
109
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
110
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
111
- .option(
112
- '-n, --algoliaindexname <algoliaIndexName>',
113
- 'Required | Algolia index name'
114
- )
115
- .option('-o, --outputpath <outputPath>', 'Optional | Output filepath')
116
- .option('-p, --params <params>', 'Optional | Algolia browseAll params')
117
- .action(cmd => {
118
- commands.export.start(cmd);
119
- });
120
-
121
- // Get Settings
122
- program
123
- .command('getsettings')
124
- .alias('gs')
125
- .description('Get the settings of an Algolia index as JSON')
126
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
127
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
128
- .option(
129
- '-n, --algoliaindexname <algoliaIndexName>',
130
- 'Required | Algolia index name'
131
- )
132
- .action(cmd => {
133
- commands.getsettings.start(cmd);
134
- });
135
-
136
- // Set Settings
137
- program
138
- .command('setsettings')
139
- .alias('ss')
140
- .description('Set the settings of an Algolia index from a JSON file')
141
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
142
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
143
- .option(
144
- '-n, --algoliaindexname <algoliaIndexName>',
145
- 'Required | Algolia index name'
146
- )
147
- .option('-s, --sourcefilepath <sourceFilepath>', 'Required | Source filepath')
148
- .option('-p, --params <params>', 'Optional | Algolia setSettings params')
149
- .action(cmd => {
150
- commands.setsettings.start(cmd);
151
- });
152
-
153
- // Add Rules
154
- program
155
- .command('addrules')
156
- .alias('ar')
157
- .description('Add query rules to an Algolia index from a JSON file')
158
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
159
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
160
- .option(
161
- '-n, --algoliaindexname <algoliaIndexName>',
162
- 'Required | Algolia index name'
163
- )
164
- .option('-s, --sourcefilepath <sourceFilepath>', 'Required | Source filepath')
165
- .option('-p, --params <params>', 'Optional | Algolia batchRules params')
166
- .action(cmd => {
167
- commands.addrules.start(cmd);
168
- });
169
-
170
- // Add Synonyms
171
- program
172
- .command('addsynonyms')
173
- .alias('as')
174
- .description('Add synonyms to an Algolia index from a CSV or JSON file')
175
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
176
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
177
- .option(
178
- '-n, --algoliaindexname <algoliaIndexName>',
179
- 'Required | Algolia index name'
180
- )
181
- .option('-s, --sourcefilepath <sourceFilepath>', 'Required | Source filepath')
182
- .option('-p, --params <params>', 'Optional | Algolia batchSynonyms params')
183
- .action(cmd => {
184
- commands.addsynonyms.start(cmd);
185
- });
186
-
187
- // Export Rules
188
- program
189
- .command('exportrules')
190
- .alias('er')
191
- .description('Export the query rules of an Algolia index to local JSON file')
192
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
193
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
194
- .option(
195
- '-n, --algoliaindexname <algoliaIndexName>',
196
- 'Required | Algolia index name'
197
- )
198
- .option('-o, --outputpath <outputPath>', 'Optional | Output filepath')
199
- .action(cmd => {
200
- commands.exportrules.start(cmd);
201
- });
202
-
203
- // Export Synonyms
204
- program
205
- .command('exportsynonyms')
206
- .alias('es')
207
- .description('Export the synonyms of an Algolia index to local JSON file')
208
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
209
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
210
- .option(
211
- '-n, --algoliaindexname <algoliaIndexName>',
212
- 'Required | Algolia index name'
213
- )
214
- .option('-o, --outputpath <outputPath>', 'Optional | Output filepath')
215
- .action(cmd => {
216
- commands.exportsynonyms.start(cmd);
217
- });
218
-
219
- // Transfer Index
220
- program
221
- .command('transferindex')
222
- .alias('ti')
223
- .description(
224
- 'Duplicate the data and settings of an index from one Algolia App to another'
225
- )
226
- .option(
227
- '-a, --sourcealgoliaappid <algoliaAppId>',
228
- 'Required | Algolia app ID'
229
- )
230
- .option(
231
- '-k, --sourcealgoliaapikey <algoliaApiKey>',
232
- 'Required | Algolia API key'
233
- )
234
- .option(
235
- '-n, --sourcealgoliaindexname <algoliaIndexName>',
236
- 'Required | Algolia index name'
237
- )
238
- .option(
239
- '-d, --destinationalgoliaappid <algoliaAppId>',
240
- 'Required | Algolia app ID'
241
- )
242
- .option(
243
- '-y, --destinationalgoliaapikey <algoliaApiKey>',
244
- 'Required | Algolia API key'
245
- )
246
- .option(
247
- '-i, --destinationindexname <algoliaIndexName>',
248
- 'Optional | Algolia index name'
249
- )
250
- .option(
251
- '-t, --transformationfilepath <transformationFilepath>',
252
- 'Optional | Transformation filepath'
253
- )
254
- .option(
255
- '-e, --excludereplicas <boolean>',
256
- 'Optional | Exclude replicas property of settings object'
257
- )
258
- .action(cmd => {
259
- commands.transferindex.start(cmd);
260
- });
261
-
262
- // Transfer Index Config
263
- program
264
- .command('transferindexconfig')
265
- .alias('tig')
266
- .description(
267
- 'Duplicate the settings, synonyms, and query rules of an index from one Algolia App to another'
268
- )
269
- .option(
270
- '-a, --sourcealgoliaappid <algoliaAppId>',
271
- 'Required | Algolia app ID'
272
- )
273
- .option(
274
- '-k, --sourcealgoliaapikey <algoliaApiKey>',
275
- 'Required | Algolia API key'
276
- )
277
- .option(
278
- '-n, --sourcealgoliaindexname <algoliaIndexName>',
279
- 'Required | Algolia index name'
280
- )
281
- .option(
282
- '-d, --destinationalgoliaappid <algoliaAppId>',
283
- 'Required | Algolia app ID'
284
- )
285
- .option(
286
- '-y, --destinationalgoliaapikey <algoliaApiKey>',
287
- 'Required | Algolia API key'
288
- )
289
- .option(
290
- '-i, --destinationindexname <algoliaIndexName>',
291
- 'Optional | Algolia index name'
292
- )
293
- .option(
294
- '-p, --params <params>',
295
- 'Optional | Algolia batchSynonyms and batchRules params'
296
- )
297
- .option(
298
- '-e, --excludereplicas <boolean>',
299
- 'Optional | Exclude replicas property of settings object'
300
- )
301
- .action(cmd => {
302
- commands.transferindexconfig.start(cmd);
303
- });
304
-
305
- // Delete Indices
306
-
307
- program
308
- .command('deleteindicespattern')
309
- .alias('dip')
310
- .description('Delete multiple indices using a regular expression')
311
- .option('-a, --algoliaappid <algoliaAppId>', 'Required | Algolia app ID')
312
- .option('-k, --algoliaapikey <algoliaApiKey>', 'Required | Algolia API key')
313
- .option('-r, --regexp <regexp>', 'Required | Regexp to use for filtering')
314
- .option(
315
- '-x, --dryrun <boolean>',
316
- 'Required | Dry run, will only output what would be done'
317
- )
318
- .action(cmd => {
319
- commands.deleteindicespattern.start(cmd);
320
- });
321
-
322
- // Transform Lines
323
- program
324
- .command('transformlines')
325
- .alias('tl')
326
- .description(
327
- 'Apply a custom transformation to each line of a file saving output lines to a new file'
328
- )
329
- .option('-s, --sourcefilepath <sourceFilepath>', 'Required | Source filepath')
330
- .option('-o, --outputpath <outputPath>', 'Optional | Output filepath')
331
- .option(
332
- '-t, --transformationfilepath <transformationFilepath>',
333
- 'Optional | Transformation filepath'
334
- )
335
- .action(cmd => {
336
- commands.transformlines.start(cmd);
337
- });
338
-
339
- // Interactive command
340
- program
341
- .command('interactive')
342
- .alias('shell')
343
- .description('Run in an interactive mode')
344
- .action(cmd => {
345
- commands.interactive.start(cmd);
346
- });
347
-
348
- // Display command examples
349
- program
350
- .command('examples')
351
- .alias('ex')
352
- .description('View command examples')
353
- .action(() => {
354
- console.log(examples);
355
- });
356
-
357
- // Default Command
358
- program
359
- .command('*')
360
- .alias('default')
361
- .description('Default command if none input')
362
- .action(cmd => {
363
- defaultCommand(cmd);
364
- });
365
-
366
- // LOGIC
367
-
368
- // Process command
369
- program.parse(process.argv);
370
- // Register node process event listeners
371
- registerDefaultProcessEventListeners();
372
- // Handle no-command case
373
- if (program.args.length === 0) program.help();