UNPKG

1.48 kBJavaScriptView Raw
1#!/usr/bin/env node
2
3const program = require('commander'),
4 prompts = require('prompts'),
5 Gateway = require('./lib/proxy'),
6 logger = require('./lib/logger'),
7 fetchAuthData = require('./lib/settings').fetchSettings,
8 version = require('./package.json').version;
9
10const clean = (gateway, confirmation) => {
11 logger.Info('Going to clean data');
12 gateway
13 .dataClean(confirmation)
14 .then(() => logger.Success('Instance data cleaned.'))
15 .catch({ statusCode: 404 }, () => logger.Error('[404] Data clean is not supported by the server'));
16};
17
18async function confirmCleanup(gateway) {
19 const confirmationText = 'CLEAN DATA';
20 const message = `WARNING!!! You are going to REMOVE your data.
21There is no comming back.
22If you still want to continue please type: '${confirmationText}' `;
23
24 const response = await prompts({ type: 'text', name: 'confirmation', message: message });
25 if (response.confirmation == confirmationText) {
26 clean(gateway, response.confirmation);
27 } else {
28 logger.Info('Closed without cleaning instance data.');
29 }
30}
31
32program
33 .version(version)
34 .arguments('[environment]', 'name of the environment. Example: staging')
35 .option('-c --config-file <config-file>', 'config file path', '.marketplace-kit')
36 .action((environment, params) => {
37 process.env.CONFIG_FILE_PATH = params.configFile;
38 const gateway = new Gateway(fetchAuthData(environment, program));
39
40 confirmCleanup(gateway);
41 });
42
43program.parse(process.argv);