-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (67 loc) · 2.18 KB
/
index.js
File metadata and controls
77 lines (67 loc) · 2.18 KB
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
const fs = require('fs');
const path = require('path');
const promptSync = require('prompt-sync')();
const { execSync } = require('child_process');
// Local imports
const copyTo = require('./helpers/copyTo');
const packageJSON = require('./package.json');
/* eslint-disable no-console */
// Prep command executor
const exec = (command) => {
return execSync(command, { stdio: 'inherit' });
};
// Import helpers
const print = require('./helpers/print');
const prompt = (title, notRequired) => {
const val = promptSync(title);
if (val === null || (!notRequired && !val)) {
process.exit(0);
}
return val;
};
print.savePrompt(prompt);
// Initializer script
module.exports = () => {
const targetFilename = path.join(
process.env.PWD,
'Keywords/Kaixa.groovy'
);
const updating = fs.existsSync(targetFilename);
// Make sure we're in a Katalon project
if (
!fs.existsSync(path.join(process.env.PWD, 'Keywords'))
|| !fs.existsSync(path.join(process.env.PWD, 'Include'))
|| !fs.existsSync(path.join(process.env.PWD, 'Profiles'))
|| !fs.existsSync(path.join(process.env.PWD, 'Drivers'))
|| !fs.existsSync(path.join(process.env.PWD, 'Test Cases'))
) {
// Not in a Katalon project folder
console.log('');
print.title('Error | Kaixa Setup');
console.log('');
console.log('Oops! Looks like you\'re not in the right folder.');
console.log('Navigate to the top-level folder of a Katalon project then try this again.')
return;
}
// Welcome
print.title(`${updating ? 'Updating' : 'Adding'} Kaixa`);
console.log('');
console.log(`We are about to ${updating ? 'update your Kaixa version to' : 'install Kaixa version'} ${packageJSON.version}.`);
console.log(`Project to ${updating ? 'update' : 'set up'}: ${process.env.PWD}`);
console.log('');
print.enterToContinue();
// Copy Kaixa
copyTo(
path.join(__dirname, 'src/Kaixa.groovy'),
targetFilename
);
// Confirm
console.log('');
print.title('Done!');
console.log('');
if (updating) {
console.log(`We updated to Kaixa version ${packageJSON.version} for this project.\n`);
} else {
console.log(`We added Kaixa version ${packageJSON.version} to this project.\n`);
}
};