@intecoag/inteco-cli 0.5.1 → 1.0.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/.github/workflows/publish.yml +31 -0
- package/README.md +3 -3
- package/package.json +44 -35
- package/src/index.js +85 -85
- package/src/modules/adbBridge.js +51 -51
- package/src/modules/adbIntentSender.js +81 -81
- package/src/modules/bundleProduct.js +160 -160
- package/src/modules/csvMerger.js +117 -117
- package/src/modules/deleteDB.js +83 -83
- package/src/modules/dumpDB.js +215 -215
- package/src/modules/dumpTableToCSV.js +153 -153
- package/src/modules/extdSearch.js +226 -226
- package/src/modules/graphqlSchemaExport.js +60 -60
- package/src/modules/importDB.js +120 -120
- package/src/modules/rewriteConfig.js +78 -78
- package/src/modules/setCLIConfig.js +32 -32
- package/src/modules/syncConfig.js +264 -264
- package/src/modules/t003Rewrite.js +63 -63
- package/src/ressources/cmds.json +46 -46
- package/src/utils/config/config.js +70 -70
- package/src/utils/config/default.json +8 -8
- package/src/utils/db/DB.js +53 -53
- package/src/utils/fs/FS.js +87 -87
|
@@ -1,264 +1,264 @@
|
|
|
1
|
-
import prompts from "prompts";
|
|
2
|
-
import { mkdirSync, existsSync, readdirSync, rmSync } from "fs";
|
|
3
|
-
import path from "path";
|
|
4
|
-
import chalk from "chalk";
|
|
5
|
-
import { Config } from "../utils/config/config.js";
|
|
6
|
-
import { FS } from "../utils/fs/FS.js";
|
|
7
|
-
|
|
8
|
-
export default async function syncConfig() {
|
|
9
|
-
console.log()
|
|
10
|
-
|
|
11
|
-
const config = await Config.getConfig();
|
|
12
|
-
|
|
13
|
-
const configDirectoriesEclipse = readdirSync(config.configIndividualPathEclipse, { withFileTypes: true }).filter(dirent => dirent.isDirectory()).map(dirent => { return { title: dirent.name } })
|
|
14
|
-
|
|
15
|
-
const configDirectories = readdirSync(config.configIndividualPath, { withFileTypes: true }).filter(dirent => dirent.isDirectory()).map(dirent => { return { title: dirent.name } })
|
|
16
|
-
|
|
17
|
-
let success = true;
|
|
18
|
-
|
|
19
|
-
const responses = await prompts([
|
|
20
|
-
{
|
|
21
|
-
type: 'select',
|
|
22
|
-
name: 'direction',
|
|
23
|
-
message: 'Select Direction:',
|
|
24
|
-
choices: [
|
|
25
|
-
{ title: 'Import ConfigIndividual (Repository → Work)', value: 'import' },
|
|
26
|
-
{ title: 'Export ConfigIndividual (Work → Repository)', value: 'export' },
|
|
27
|
-
{ title: 'Import Config (Repository → Work)', value: 'import_config' },
|
|
28
|
-
{ title: 'Export Config (Work → Repository)', value: 'export_config' },
|
|
29
|
-
{ title: 'Import Everything (Repository → Work)', value: 'import_all' },
|
|
30
|
-
{ title: 'Export Everything (Work → Repository)', value: 'export_all' },
|
|
31
|
-
{ title: 'Import All ConfigIndividual (Repository → Work)', value: 'import_all_individuals' },
|
|
32
|
-
{ title: 'Export All ConfigIndividual (Work → Repository)', value: 'export_all_individuals' }
|
|
33
|
-
]
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
type: (prev) => (prev === 'import' || prev === 'export') ? 'autocomplete' : null,
|
|
37
|
-
name: 'configNameSource',
|
|
38
|
-
message: (prev, values) => values.direction === 'import'
|
|
39
|
-
? 'ConfigIndividual from Repository (Origin)?'
|
|
40
|
-
: 'ConfigIndividual from Work (Origin)?',
|
|
41
|
-
choices: (prev, values) => values.direction === 'import'
|
|
42
|
-
? configDirectoriesEclipse
|
|
43
|
-
: configDirectories
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
type: (prev, values) => (values.direction === 'import' || values.direction === 'export') ? 'autocomplete' : null,
|
|
47
|
-
name: 'configNameTarget',
|
|
48
|
-
message: (prev, values) => values.direction === 'import'
|
|
49
|
-
? 'ConfigIndividual in Work (Destination)?'
|
|
50
|
-
: 'ConfigIndividual in Repository (Destination)?',
|
|
51
|
-
choices: (prev, values) => values.direction === 'import'
|
|
52
|
-
? configDirectories
|
|
53
|
-
: configDirectoriesEclipse,
|
|
54
|
-
suggest: (input, choices) => {
|
|
55
|
-
const filtered = choices.filter(choice =>
|
|
56
|
-
choice.title.toLowerCase().includes(input.toLowerCase())
|
|
57
|
-
);
|
|
58
|
-
if (input && !choices.some(c => c.title === input)) {
|
|
59
|
-
return [...filtered, { title: `Use custom name: "${input}"`, value: input }];
|
|
60
|
-
}
|
|
61
|
-
return filtered;
|
|
62
|
-
}
|
|
63
|
-
},
|
|
64
|
-
{
|
|
65
|
-
type: 'toggle',
|
|
66
|
-
name: 'dryRun',
|
|
67
|
-
message: 'Dry run? (show what would happen without making changes)',
|
|
68
|
-
initial: false,
|
|
69
|
-
active: 'yes',
|
|
70
|
-
inactive: 'no'
|
|
71
|
-
},
|
|
72
|
-
{
|
|
73
|
-
type: 'select',
|
|
74
|
-
name: 'type',
|
|
75
|
-
message: 'Sync Type?',
|
|
76
|
-
choices: [
|
|
77
|
-
{ title: 'UPDATE', value: 'UPDATE' },
|
|
78
|
-
{ title: 'OVERWRITE', value: 'OVERWRITE' }
|
|
79
|
-
]
|
|
80
|
-
}
|
|
81
|
-
], {
|
|
82
|
-
onCancel: () => {
|
|
83
|
-
console.log();
|
|
84
|
-
console.log(chalk.red("Cancelled Operation!"));
|
|
85
|
-
console.log();
|
|
86
|
-
success = false;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
if (success) {
|
|
93
|
-
let sourcePaths, destPaths;
|
|
94
|
-
|
|
95
|
-
switch (responses.direction) {
|
|
96
|
-
case 'import':
|
|
97
|
-
sourcePaths = [path.join(config.configIndividualPathEclipse, responses.configNameSource)];
|
|
98
|
-
destPaths = [path.join(config.configIndividualPath, responses.configNameTarget)];
|
|
99
|
-
break;
|
|
100
|
-
|
|
101
|
-
case 'export':
|
|
102
|
-
sourcePaths = [path.join(config.configIndividualPath, responses.configNameSource)];
|
|
103
|
-
destPaths = [path.join(config.configIndividualPathEclipse, responses.configNameTarget)];
|
|
104
|
-
break;
|
|
105
|
-
|
|
106
|
-
case 'import_all':
|
|
107
|
-
sourcePaths = [path.resolve(config.configIndividualPathEclipse, '..', "config"), config.configIndividualPathEclipse];
|
|
108
|
-
destPaths = [path.resolve(config.configIndividualPath, '..', "config"), config.configIndividualPath];
|
|
109
|
-
break;
|
|
110
|
-
|
|
111
|
-
case 'export_all':
|
|
112
|
-
sourcePaths = [path.resolve(config.configIndividualPath, '..', "config"), config.configIndividualPath];
|
|
113
|
-
destPaths = [path.resolve(config.configIndividualPathEclipse, '..', "config"), config.configIndividualPathEclipse];
|
|
114
|
-
break;
|
|
115
|
-
|
|
116
|
-
case 'import_all_individuals':
|
|
117
|
-
sourcePaths = [path.resolve(config.configIndividualPathEclipse)];
|
|
118
|
-
destPaths = [path.resolve(config.configIndividualPath)];
|
|
119
|
-
break;
|
|
120
|
-
|
|
121
|
-
case 'export_all_individuals':
|
|
122
|
-
destPaths = [path.resolve(config.configIndividualPathEclipse)];
|
|
123
|
-
sourcePaths = [path.resolve(config.configIndividualPath)];
|
|
124
|
-
break;
|
|
125
|
-
|
|
126
|
-
case 'import_config': {
|
|
127
|
-
const sourceParent = path.resolve(config.configIndividualPathEclipse, '..');
|
|
128
|
-
const destParent = path.resolve(config.configIndividualPath, '..');
|
|
129
|
-
|
|
130
|
-
sourcePaths = [findConfigDirNamedConfigIn(sourceParent)];
|
|
131
|
-
destPaths = [findConfigDirNamedConfigIn(destParent)];
|
|
132
|
-
break;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
case 'export_config': {
|
|
136
|
-
const sourceParent = path.resolve(config.configIndividualPath, '..');
|
|
137
|
-
const destParent = path.resolve(config.configIndividualPathEclipse, '..');
|
|
138
|
-
|
|
139
|
-
sourcePaths = [findConfigDirNamedConfigIn(sourceParent)];
|
|
140
|
-
destPaths = [findConfigDirNamedConfigIn(destParent)];
|
|
141
|
-
break;
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
processMultiple(responses, responses.dryRun, sourcePaths, destPaths);
|
|
146
|
-
|
|
147
|
-
if (responses.dryRun) {
|
|
148
|
-
console.log()
|
|
149
|
-
const confirmationResults = await prompts([
|
|
150
|
-
{
|
|
151
|
-
type: 'confirm',
|
|
152
|
-
name: 'confirmation',
|
|
153
|
-
message: 'Would you like to execute the dry-run?',
|
|
154
|
-
initial: true
|
|
155
|
-
}
|
|
156
|
-
], {
|
|
157
|
-
onCancel: () => {
|
|
158
|
-
console.log();
|
|
159
|
-
console.log(chalk.red("Cancelled Operation!"));
|
|
160
|
-
console.log();
|
|
161
|
-
success = false;
|
|
162
|
-
}
|
|
163
|
-
})
|
|
164
|
-
|
|
165
|
-
if(confirmationResults.confirmation){
|
|
166
|
-
processMultiple(responses, false, sourcePaths, destPaths);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
console.log();
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
function processMultiple(responses, dryRun, sourcePaths, destPaths) {
|
|
175
|
-
console.log();
|
|
176
|
-
let summary = {};
|
|
177
|
-
|
|
178
|
-
switch (responses.type) {
|
|
179
|
-
case 'UPDATE':
|
|
180
|
-
console.log(chalk.yellow(`Updating files from ${sourcePaths.join(', ')} → ${destPaths.join(', ')}`));
|
|
181
|
-
summary = { added: 0, updated: 0 };
|
|
182
|
-
for(let i = 0; i < sourcePaths.length && i < destPaths.length; i++) {
|
|
183
|
-
FS.copyUpdatedFiles(sourcePaths[i], destPaths[i], dryRun, summary, ["wegas.properties", "path.yaml"]);
|
|
184
|
-
}
|
|
185
|
-
console.log();
|
|
186
|
-
console.log(chalk.green(`Summary: ${summary.updated} files added or updated.`));
|
|
187
|
-
break;
|
|
188
|
-
|
|
189
|
-
case 'OVERWRITE':
|
|
190
|
-
console.log(chalk.red(`Overwriting files from ${sourcePaths.join(', ')} → ${destPaths.join(', ')}`));
|
|
191
|
-
|
|
192
|
-
summary = { copied: 0 };
|
|
193
|
-
let deletedCount = 0;
|
|
194
|
-
for(let i = 0; i < sourcePaths.length && i < destPaths.length; i++) {
|
|
195
|
-
if (existsSync(destPaths[i])) {
|
|
196
|
-
deletedCount += countAndDeleteDir(destPaths[i], dryRun);
|
|
197
|
-
if (!dryRun) {
|
|
198
|
-
console.log(chalk.gray(`Deleted existing folder: ${destPaths[i]}`));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
|
|
202
|
-
if (!dryRun) {
|
|
203
|
-
mkdirSync(destPaths[i], { recursive: true });
|
|
204
|
-
} else {
|
|
205
|
-
console.log(chalk.gray(`[DryRun] Would create directory: ${destPaths[i]}`));
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
FS.copyAllFiles(sourcePaths[i], destPaths[i], dryRun, summary, ["wegas.properties", "path.yaml"]);
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
console.log();
|
|
212
|
-
console.log(chalk.green(`Summary: Deleted ${deletedCount} items, Copied ${summary.copied} files.`));
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
console.log();
|
|
217
|
-
if (dryRun) {
|
|
218
|
-
console.log(chalk.yellow("Dry run complete — no changes were made."));
|
|
219
|
-
} else {
|
|
220
|
-
console.log(chalk.green("Config sync completed successfully."));
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
function countAndDeleteDir(dirPath, dryRun = false) {
|
|
225
|
-
let deletedCount = 0;
|
|
226
|
-
|
|
227
|
-
if (existsSync(dirPath)) {
|
|
228
|
-
if (dryRun) {
|
|
229
|
-
console.log(chalk.red(`[DryRun] Would delete directory: ${dirPath}`));
|
|
230
|
-
// For dry run, recursively count files/directories without deleting
|
|
231
|
-
const entries = readdirSync(dirPath, { withFileTypes: true });
|
|
232
|
-
for (const entry of entries) {
|
|
233
|
-
const entryPath = path.join(dirPath, entry.name);
|
|
234
|
-
if (entry.isDirectory()) {
|
|
235
|
-
deletedCount += countAndDeleteDir(entryPath, dryRun);
|
|
236
|
-
} else {
|
|
237
|
-
deletedCount++;
|
|
238
|
-
console.log(chalk.red(`[DryRun] Would delete file: ${entryPath}`));
|
|
239
|
-
}
|
|
240
|
-
}
|
|
241
|
-
deletedCount++; // counting the directory itself
|
|
242
|
-
} else {
|
|
243
|
-
rmSync(dirPath, { recursive: true, force: true });
|
|
244
|
-
// Can't count after delete, so you may skip or count before if desired
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
return deletedCount;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
function findConfigDirNamedConfigIn(parentPath) {
|
|
251
|
-
if (!parentPath || typeof parentPath !== 'string') {
|
|
252
|
-
throw new Error('Invalid or undefined parent path');
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const candidate = path.join(parentPath, 'config');
|
|
256
|
-
if (existsSync(candidate)) {
|
|
257
|
-
return candidate;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
throw new Error(`No 'config/' directory found directly in ${parentPath}`);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
1
|
+
import prompts from "prompts";
|
|
2
|
+
import { mkdirSync, existsSync, readdirSync, rmSync } from "fs";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import { Config } from "../utils/config/config.js";
|
|
6
|
+
import { FS } from "../utils/fs/FS.js";
|
|
7
|
+
|
|
8
|
+
export default async function syncConfig() {
|
|
9
|
+
console.log()
|
|
10
|
+
|
|
11
|
+
const config = await Config.getConfig();
|
|
12
|
+
|
|
13
|
+
const configDirectoriesEclipse = readdirSync(config.configIndividualPathEclipse, { withFileTypes: true }).filter(dirent => dirent.isDirectory()).map(dirent => { return { title: dirent.name } })
|
|
14
|
+
|
|
15
|
+
const configDirectories = readdirSync(config.configIndividualPath, { withFileTypes: true }).filter(dirent => dirent.isDirectory()).map(dirent => { return { title: dirent.name } })
|
|
16
|
+
|
|
17
|
+
let success = true;
|
|
18
|
+
|
|
19
|
+
const responses = await prompts([
|
|
20
|
+
{
|
|
21
|
+
type: 'select',
|
|
22
|
+
name: 'direction',
|
|
23
|
+
message: 'Select Direction:',
|
|
24
|
+
choices: [
|
|
25
|
+
{ title: 'Import ConfigIndividual (Repository → Work)', value: 'import' },
|
|
26
|
+
{ title: 'Export ConfigIndividual (Work → Repository)', value: 'export' },
|
|
27
|
+
{ title: 'Import Config (Repository → Work)', value: 'import_config' },
|
|
28
|
+
{ title: 'Export Config (Work → Repository)', value: 'export_config' },
|
|
29
|
+
{ title: 'Import Everything (Repository → Work)', value: 'import_all' },
|
|
30
|
+
{ title: 'Export Everything (Work → Repository)', value: 'export_all' },
|
|
31
|
+
{ title: 'Import All ConfigIndividual (Repository → Work)', value: 'import_all_individuals' },
|
|
32
|
+
{ title: 'Export All ConfigIndividual (Work → Repository)', value: 'export_all_individuals' }
|
|
33
|
+
]
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
type: (prev) => (prev === 'import' || prev === 'export') ? 'autocomplete' : null,
|
|
37
|
+
name: 'configNameSource',
|
|
38
|
+
message: (prev, values) => values.direction === 'import'
|
|
39
|
+
? 'ConfigIndividual from Repository (Origin)?'
|
|
40
|
+
: 'ConfigIndividual from Work (Origin)?',
|
|
41
|
+
choices: (prev, values) => values.direction === 'import'
|
|
42
|
+
? configDirectoriesEclipse
|
|
43
|
+
: configDirectories
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: (prev, values) => (values.direction === 'import' || values.direction === 'export') ? 'autocomplete' : null,
|
|
47
|
+
name: 'configNameTarget',
|
|
48
|
+
message: (prev, values) => values.direction === 'import'
|
|
49
|
+
? 'ConfigIndividual in Work (Destination)?'
|
|
50
|
+
: 'ConfigIndividual in Repository (Destination)?',
|
|
51
|
+
choices: (prev, values) => values.direction === 'import'
|
|
52
|
+
? configDirectories
|
|
53
|
+
: configDirectoriesEclipse,
|
|
54
|
+
suggest: (input, choices) => {
|
|
55
|
+
const filtered = choices.filter(choice =>
|
|
56
|
+
choice.title.toLowerCase().includes(input.toLowerCase())
|
|
57
|
+
);
|
|
58
|
+
if (input && !choices.some(c => c.title === input)) {
|
|
59
|
+
return [...filtered, { title: `Use custom name: "${input}"`, value: input }];
|
|
60
|
+
}
|
|
61
|
+
return filtered;
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
type: 'toggle',
|
|
66
|
+
name: 'dryRun',
|
|
67
|
+
message: 'Dry run? (show what would happen without making changes)',
|
|
68
|
+
initial: false,
|
|
69
|
+
active: 'yes',
|
|
70
|
+
inactive: 'no'
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
type: 'select',
|
|
74
|
+
name: 'type',
|
|
75
|
+
message: 'Sync Type?',
|
|
76
|
+
choices: [
|
|
77
|
+
{ title: 'UPDATE', value: 'UPDATE' },
|
|
78
|
+
{ title: 'OVERWRITE', value: 'OVERWRITE' }
|
|
79
|
+
]
|
|
80
|
+
}
|
|
81
|
+
], {
|
|
82
|
+
onCancel: () => {
|
|
83
|
+
console.log();
|
|
84
|
+
console.log(chalk.red("Cancelled Operation!"));
|
|
85
|
+
console.log();
|
|
86
|
+
success = false;
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
if (success) {
|
|
93
|
+
let sourcePaths, destPaths;
|
|
94
|
+
|
|
95
|
+
switch (responses.direction) {
|
|
96
|
+
case 'import':
|
|
97
|
+
sourcePaths = [path.join(config.configIndividualPathEclipse, responses.configNameSource)];
|
|
98
|
+
destPaths = [path.join(config.configIndividualPath, responses.configNameTarget)];
|
|
99
|
+
break;
|
|
100
|
+
|
|
101
|
+
case 'export':
|
|
102
|
+
sourcePaths = [path.join(config.configIndividualPath, responses.configNameSource)];
|
|
103
|
+
destPaths = [path.join(config.configIndividualPathEclipse, responses.configNameTarget)];
|
|
104
|
+
break;
|
|
105
|
+
|
|
106
|
+
case 'import_all':
|
|
107
|
+
sourcePaths = [path.resolve(config.configIndividualPathEclipse, '..', "config"), config.configIndividualPathEclipse];
|
|
108
|
+
destPaths = [path.resolve(config.configIndividualPath, '..', "config"), config.configIndividualPath];
|
|
109
|
+
break;
|
|
110
|
+
|
|
111
|
+
case 'export_all':
|
|
112
|
+
sourcePaths = [path.resolve(config.configIndividualPath, '..', "config"), config.configIndividualPath];
|
|
113
|
+
destPaths = [path.resolve(config.configIndividualPathEclipse, '..', "config"), config.configIndividualPathEclipse];
|
|
114
|
+
break;
|
|
115
|
+
|
|
116
|
+
case 'import_all_individuals':
|
|
117
|
+
sourcePaths = [path.resolve(config.configIndividualPathEclipse)];
|
|
118
|
+
destPaths = [path.resolve(config.configIndividualPath)];
|
|
119
|
+
break;
|
|
120
|
+
|
|
121
|
+
case 'export_all_individuals':
|
|
122
|
+
destPaths = [path.resolve(config.configIndividualPathEclipse)];
|
|
123
|
+
sourcePaths = [path.resolve(config.configIndividualPath)];
|
|
124
|
+
break;
|
|
125
|
+
|
|
126
|
+
case 'import_config': {
|
|
127
|
+
const sourceParent = path.resolve(config.configIndividualPathEclipse, '..');
|
|
128
|
+
const destParent = path.resolve(config.configIndividualPath, '..');
|
|
129
|
+
|
|
130
|
+
sourcePaths = [findConfigDirNamedConfigIn(sourceParent)];
|
|
131
|
+
destPaths = [findConfigDirNamedConfigIn(destParent)];
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
case 'export_config': {
|
|
136
|
+
const sourceParent = path.resolve(config.configIndividualPath, '..');
|
|
137
|
+
const destParent = path.resolve(config.configIndividualPathEclipse, '..');
|
|
138
|
+
|
|
139
|
+
sourcePaths = [findConfigDirNamedConfigIn(sourceParent)];
|
|
140
|
+
destPaths = [findConfigDirNamedConfigIn(destParent)];
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
processMultiple(responses, responses.dryRun, sourcePaths, destPaths);
|
|
146
|
+
|
|
147
|
+
if (responses.dryRun) {
|
|
148
|
+
console.log()
|
|
149
|
+
const confirmationResults = await prompts([
|
|
150
|
+
{
|
|
151
|
+
type: 'confirm',
|
|
152
|
+
name: 'confirmation',
|
|
153
|
+
message: 'Would you like to execute the dry-run?',
|
|
154
|
+
initial: true
|
|
155
|
+
}
|
|
156
|
+
], {
|
|
157
|
+
onCancel: () => {
|
|
158
|
+
console.log();
|
|
159
|
+
console.log(chalk.red("Cancelled Operation!"));
|
|
160
|
+
console.log();
|
|
161
|
+
success = false;
|
|
162
|
+
}
|
|
163
|
+
})
|
|
164
|
+
|
|
165
|
+
if(confirmationResults.confirmation){
|
|
166
|
+
processMultiple(responses, false, sourcePaths, destPaths);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
console.log();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
function processMultiple(responses, dryRun, sourcePaths, destPaths) {
|
|
175
|
+
console.log();
|
|
176
|
+
let summary = {};
|
|
177
|
+
|
|
178
|
+
switch (responses.type) {
|
|
179
|
+
case 'UPDATE':
|
|
180
|
+
console.log(chalk.yellow(`Updating files from ${sourcePaths.join(', ')} → ${destPaths.join(', ')}`));
|
|
181
|
+
summary = { added: 0, updated: 0 };
|
|
182
|
+
for(let i = 0; i < sourcePaths.length && i < destPaths.length; i++) {
|
|
183
|
+
FS.copyUpdatedFiles(sourcePaths[i], destPaths[i], dryRun, summary, ["wegas.properties", "path.yaml"]);
|
|
184
|
+
}
|
|
185
|
+
console.log();
|
|
186
|
+
console.log(chalk.green(`Summary: ${summary.updated} files added or updated.`));
|
|
187
|
+
break;
|
|
188
|
+
|
|
189
|
+
case 'OVERWRITE':
|
|
190
|
+
console.log(chalk.red(`Overwriting files from ${sourcePaths.join(', ')} → ${destPaths.join(', ')}`));
|
|
191
|
+
|
|
192
|
+
summary = { copied: 0 };
|
|
193
|
+
let deletedCount = 0;
|
|
194
|
+
for(let i = 0; i < sourcePaths.length && i < destPaths.length; i++) {
|
|
195
|
+
if (existsSync(destPaths[i])) {
|
|
196
|
+
deletedCount += countAndDeleteDir(destPaths[i], dryRun);
|
|
197
|
+
if (!dryRun) {
|
|
198
|
+
console.log(chalk.gray(`Deleted existing folder: ${destPaths[i]}`));
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
if (!dryRun) {
|
|
203
|
+
mkdirSync(destPaths[i], { recursive: true });
|
|
204
|
+
} else {
|
|
205
|
+
console.log(chalk.gray(`[DryRun] Would create directory: ${destPaths[i]}`));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
FS.copyAllFiles(sourcePaths[i], destPaths[i], dryRun, summary, ["wegas.properties", "path.yaml"]);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
console.log();
|
|
212
|
+
console.log(chalk.green(`Summary: Deleted ${deletedCount} items, Copied ${summary.copied} files.`));
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
console.log();
|
|
217
|
+
if (dryRun) {
|
|
218
|
+
console.log(chalk.yellow("Dry run complete — no changes were made."));
|
|
219
|
+
} else {
|
|
220
|
+
console.log(chalk.green("Config sync completed successfully."));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function countAndDeleteDir(dirPath, dryRun = false) {
|
|
225
|
+
let deletedCount = 0;
|
|
226
|
+
|
|
227
|
+
if (existsSync(dirPath)) {
|
|
228
|
+
if (dryRun) {
|
|
229
|
+
console.log(chalk.red(`[DryRun] Would delete directory: ${dirPath}`));
|
|
230
|
+
// For dry run, recursively count files/directories without deleting
|
|
231
|
+
const entries = readdirSync(dirPath, { withFileTypes: true });
|
|
232
|
+
for (const entry of entries) {
|
|
233
|
+
const entryPath = path.join(dirPath, entry.name);
|
|
234
|
+
if (entry.isDirectory()) {
|
|
235
|
+
deletedCount += countAndDeleteDir(entryPath, dryRun);
|
|
236
|
+
} else {
|
|
237
|
+
deletedCount++;
|
|
238
|
+
console.log(chalk.red(`[DryRun] Would delete file: ${entryPath}`));
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
deletedCount++; // counting the directory itself
|
|
242
|
+
} else {
|
|
243
|
+
rmSync(dirPath, { recursive: true, force: true });
|
|
244
|
+
// Can't count after delete, so you may skip or count before if desired
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return deletedCount;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function findConfigDirNamedConfigIn(parentPath) {
|
|
251
|
+
if (!parentPath || typeof parentPath !== 'string') {
|
|
252
|
+
throw new Error('Invalid or undefined parent path');
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const candidate = path.join(parentPath, 'config');
|
|
256
|
+
if (existsSync(candidate)) {
|
|
257
|
+
return candidate;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
throw new Error(`No 'config/' directory found directly in ${parentPath}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
import chalk from "chalk";
|
|
2
|
-
import prompts from "prompts";
|
|
3
|
-
import { Config } from "../utils/config/config.js";
|
|
4
|
-
import { DB } from "../utils/db/DB.js";
|
|
5
|
-
|
|
6
|
-
export default async function t003Rewrite(cli) {
|
|
7
|
-
console.log()
|
|
8
|
-
|
|
9
|
-
const config = await Config.getConfig();
|
|
10
|
-
|
|
11
|
-
const databaseNames = await DB.getDatabaseNames();
|
|
12
|
-
|
|
13
|
-
let success = true;
|
|
14
|
-
|
|
15
|
-
const responseDB = await prompts([{
|
|
16
|
-
// DB-Auswahl von DB
|
|
17
|
-
type: 'autocomplete',
|
|
18
|
-
name: 'dbName',
|
|
19
|
-
message: 'DB-Name?',
|
|
20
|
-
choices: databaseNames.map(name => { return { title: name.name } })
|
|
21
|
-
}, {
|
|
22
|
-
type: 'number',
|
|
23
|
-
name: 'mnr',
|
|
24
|
-
message: 'Mandant?',
|
|
25
|
-
initial: '1'
|
|
26
|
-
}], {
|
|
27
|
-
onCancel: () => {
|
|
28
|
-
console.log()
|
|
29
|
-
console.log(chalk.red("Cancelled Rewrite!"))
|
|
30
|
-
console.log()
|
|
31
|
-
success = false
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
if (success) {
|
|
36
|
-
|
|
37
|
-
const users = await DB.executeQueryOnDB("SELECT t003_pw FROM t003 WHERE t003_mnr = " + responseDB.mnr, responseDB.dbName);
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const responses = await prompts([{
|
|
41
|
-
// Ordnerauswahl von vorhandenen Ordner in configIndividual
|
|
42
|
-
type: 'autocomplete',
|
|
43
|
-
name: 'username',
|
|
44
|
-
message: 'Username?',
|
|
45
|
-
choices: users.map(entry => { return ({ title: entry.t003_pw }) })
|
|
46
|
-
}], {
|
|
47
|
-
onCancel: () => {
|
|
48
|
-
console.log()
|
|
49
|
-
console.log(chalk.red("Cancelled Rewrite!"))
|
|
50
|
-
console.log()
|
|
51
|
-
success = false
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
if (success) {
|
|
56
|
-
console.log()
|
|
57
|
-
|
|
58
|
-
await DB.executeQueryOnDB("UPDATE t003 SET t003_pw = '"+config.wegasUsername+"' WHERE t003_mnr = "+responseDB.mnr+" AND t003_pw = '"+responses.username+"'", responseDB.dbName);
|
|
59
|
-
|
|
60
|
-
console.log(chalk.green("T003 rewritten!"))
|
|
61
|
-
console.log()
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
import chalk from "chalk";
|
|
2
|
+
import prompts from "prompts";
|
|
3
|
+
import { Config } from "../utils/config/config.js";
|
|
4
|
+
import { DB } from "../utils/db/DB.js";
|
|
5
|
+
|
|
6
|
+
export default async function t003Rewrite(cli) {
|
|
7
|
+
console.log()
|
|
8
|
+
|
|
9
|
+
const config = await Config.getConfig();
|
|
10
|
+
|
|
11
|
+
const databaseNames = await DB.getDatabaseNames();
|
|
12
|
+
|
|
13
|
+
let success = true;
|
|
14
|
+
|
|
15
|
+
const responseDB = await prompts([{
|
|
16
|
+
// DB-Auswahl von DB
|
|
17
|
+
type: 'autocomplete',
|
|
18
|
+
name: 'dbName',
|
|
19
|
+
message: 'DB-Name?',
|
|
20
|
+
choices: databaseNames.map(name => { return { title: name.name } })
|
|
21
|
+
}, {
|
|
22
|
+
type: 'number',
|
|
23
|
+
name: 'mnr',
|
|
24
|
+
message: 'Mandant?',
|
|
25
|
+
initial: '1'
|
|
26
|
+
}], {
|
|
27
|
+
onCancel: () => {
|
|
28
|
+
console.log()
|
|
29
|
+
console.log(chalk.red("Cancelled Rewrite!"))
|
|
30
|
+
console.log()
|
|
31
|
+
success = false
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
if (success) {
|
|
36
|
+
|
|
37
|
+
const users = await DB.executeQueryOnDB("SELECT t003_pw FROM t003 WHERE t003_mnr = " + responseDB.mnr, responseDB.dbName);
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
const responses = await prompts([{
|
|
41
|
+
// Ordnerauswahl von vorhandenen Ordner in configIndividual
|
|
42
|
+
type: 'autocomplete',
|
|
43
|
+
name: 'username',
|
|
44
|
+
message: 'Username?',
|
|
45
|
+
choices: users.map(entry => { return ({ title: entry.t003_pw }) })
|
|
46
|
+
}], {
|
|
47
|
+
onCancel: () => {
|
|
48
|
+
console.log()
|
|
49
|
+
console.log(chalk.red("Cancelled Rewrite!"))
|
|
50
|
+
console.log()
|
|
51
|
+
success = false
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
if (success) {
|
|
56
|
+
console.log()
|
|
57
|
+
|
|
58
|
+
await DB.executeQueryOnDB("UPDATE t003 SET t003_pw = '"+config.wegasUsername+"' WHERE t003_mnr = "+responseDB.mnr+" AND t003_pw = '"+responses.username+"'", responseDB.dbName);
|
|
59
|
+
|
|
60
|
+
console.log(chalk.green("T003 rewritten!"))
|
|
61
|
+
console.log()
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
64
|
}
|