@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.
@@ -1,161 +1,161 @@
1
- import { existsSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
2
- import Seven from 'node-7z'
3
- import sevenBin from '7zip-bin'
4
- import { Config } from "../utils/config/config.js";
5
- import prompts from "prompts";
6
- import chalk from "chalk";
7
- import { fileURLToPath } from 'url';
8
- import { dirname } from 'path';
9
- import path from "path";
10
- import ora from "ora";
11
- import { cp } from "fs/promises";
12
-
13
- const __filename = fileURLToPath(import.meta.url);
14
- const __dirname = dirname(__filename);
15
-
16
- export default async function bundleProduct(cli) {
17
- console.log()
18
-
19
- const config = await Config.getConfig();
20
-
21
- let success = true;
22
-
23
- const folders = readdirSync(process.cwd(), { withFileTypes: true }).filter(dirent => !dirent.isFile()).map(dirent => { return { title: dirent.name } })
24
-
25
- const configDirectories = readdirSync(config.configIndividualPathEclipse, { withFileTypes: true }).filter(dirent => dirent.isDirectory()).map(dirent => { return { title: dirent.name } })
26
-
27
-
28
- const results = await prompts([
29
- {
30
- // Ordnerauswahl von vorhandenen Ordner in configIndividual
31
- type: 'autocomplete',
32
- name: 'folder',
33
- message: 'Product-Folder?',
34
- choices: folders,
35
- initial: "eclipse"
36
- },
37
- {
38
- // Ordnerauswahl von vorhandenen Ordner in configIndividual
39
- type: 'autocomplete',
40
- name: 'configIndividual',
41
- message: 'Customer-Config (from Eclipse-Repository)?',
42
- choices: configDirectories
43
- },
44
- {
45
- // Ordnerauswahl von vorhandenen Ordner in configIndividual
46
- type: 'text',
47
- name: 'ram',
48
- message: 'Xmx-Value (Max. RAM) in GB?',
49
- initial: "8",
50
- validate: input => {
51
- if (isNaN(input)) {
52
- return "Enter a Number"
53
- }
54
- return true;
55
- }
56
- },
57
- {
58
- // Ordnerauswahl von vorhandenen Ordner in configIndividual
59
- type: 'text',
60
- name: 'folderName',
61
- message: 'Product-Name?',
62
- initial: "eclipse"
63
- },
64
- ], {
65
- onCancel: () => {
66
- console.log()
67
- console.log(chalk.red("Cancelled Import!"))
68
- console.log()
69
- success = false
70
- }
71
- })
72
-
73
- if (success) {
74
- console.log()
75
-
76
- const spinnerRemoveOld = ora("Removing old configs")
77
- const configPath = path.resolve(".", results.folder, "config");
78
- const configIndividualPath = path.resolve(".", results.folder, "configIndividual");
79
-
80
- if (existsSync(configPath)) {
81
- rmSync(configPath, { recursive: true, force: true });
82
- }
83
-
84
- if (existsSync(configIndividualPath)) {
85
- rmSync(configIndividualPath, { recursive: true, force: true });
86
- }
87
-
88
- spinnerRemoveOld.succeed("Removed old configs")
89
-
90
- const spinnerConfig = ora('Copying config').start();
91
-
92
-
93
- const sourceConfig = path.resolve(config.configIndividualPathEclipse, '..', "config");
94
- const destConfig = path.resolve(".", results.folder, "config")
95
-
96
- await cp(sourceConfig, destConfig, { recursive: true })
97
-
98
- spinnerConfig.succeed("Config copied")
99
-
100
- const spinnerConfigIndividual = ora('Copying configIndividual: ' + results.configIndividual).start();
101
-
102
-
103
- const sourceConfigIndividual = path.resolve(config.configIndividualPathEclipse, results.configIndividual);
104
- const destConfigIndividual = path.resolve(".", results.folder, "configIndividual", results.configIndividual)
105
-
106
- await cp(sourceConfigIndividual, destConfigIndividual, { recursive: true })
107
-
108
- spinnerConfigIndividual.succeed("ConfigIndividual copied: " + results.configIndividual)
109
-
110
- const spinnerIcon = ora('Copying icon').start();
111
-
112
- const sourceIcon = path.resolve(__dirname, "..", "ressources", "wegas_p.ico");
113
- const destIcon = path.resolve(".", results.folder, "wegas_p.ico")
114
-
115
- await cp(sourceIcon, destIcon, { recursive: true })
116
-
117
- spinnerIcon.succeed("Icon copied")
118
-
119
- const spinnerIniRewrite = ora('Rewriting wegas.ini: -Xmx' + results.ram + "g").start();
120
-
121
- const iniPath = path.resolve(".", results.folder, "wegas.ini")
122
-
123
- let iniContent = readFileSync(iniPath, 'utf-8');
124
- const updatedContent = iniContent.replace(/-Xmx\d+[mgMG]?/, `-Xmx${results.ram}g`);
125
- writeFileSync(iniPath, updatedContent);
126
-
127
- spinnerIniRewrite.succeed("wegas.ini rewritten: -Xmx" + results.ram + "g")
128
-
129
- const spinnerRename = ora("Renaming folder: " + results.folder + " -> " + results.folderName).start();
130
- renameSync(path.resolve(".", results.folder), path.resolve(".", results.folderName))
131
- spinnerRename.succeed("Folder renamed: " + results.folder + " -> " + results.folderName)
132
-
133
- const spinnerZIP = ora('Zipping: ' + results.folderName + ".zip").start();
134
-
135
- const zipPath = path.resolve(".", results.folderName + ".zip")
136
- const addPath = path.resolve(".", results.folderName)
137
- const add = Seven.add(zipPath, addPath, {
138
- $bin: sevenBin.path7za
139
- })
140
-
141
- await getPromiseFromEvent(add, "end")
142
-
143
- spinnerZIP.succeed('Zipped: ' + results.folderName + ".zip")
144
-
145
- const spinnerRenameRevert = ora("Renaming folder: " + results.folderName + " -> " + results.folder).start();
146
- renameSync(path.resolve(".", results.folderName), path.resolve(".", results.folder))
147
- spinnerRenameRevert.succeed("Folder renamed: " + results.folderName + " -> " + results.folder)
148
-
149
-
150
- console.log()
151
- }
152
- }
153
-
154
- function getPromiseFromEvent(item, event) {
155
- return new Promise((resolve) => {
156
- const listener = (data) => {
157
- resolve(data);
158
- }
159
- item.on(event, listener);
160
- })
1
+ import { existsSync, readdirSync, readFileSync, renameSync, rmSync, writeFileSync } from "fs";
2
+ import Seven from 'node-7z'
3
+ import sevenBin from '7zip-bin'
4
+ import { Config } from "../utils/config/config.js";
5
+ import prompts from "prompts";
6
+ import chalk from "chalk";
7
+ import { fileURLToPath } from 'url';
8
+ import { dirname } from 'path';
9
+ import path from "path";
10
+ import ora from "ora";
11
+ import { cp } from "fs/promises";
12
+
13
+ const __filename = fileURLToPath(import.meta.url);
14
+ const __dirname = dirname(__filename);
15
+
16
+ export default async function bundleProduct(cli) {
17
+ console.log()
18
+
19
+ const config = await Config.getConfig();
20
+
21
+ let success = true;
22
+
23
+ const folders = readdirSync(process.cwd(), { withFileTypes: true }).filter(dirent => !dirent.isFile()).map(dirent => { return { title: dirent.name } })
24
+
25
+ const configDirectories = readdirSync(config.configIndividualPathEclipse, { withFileTypes: true }).filter(dirent => dirent.isDirectory()).map(dirent => { return { title: dirent.name } })
26
+
27
+
28
+ const results = await prompts([
29
+ {
30
+ // Ordnerauswahl von vorhandenen Ordner in configIndividual
31
+ type: 'autocomplete',
32
+ name: 'folder',
33
+ message: 'Product-Folder?',
34
+ choices: folders,
35
+ initial: "eclipse"
36
+ },
37
+ {
38
+ // Ordnerauswahl von vorhandenen Ordner in configIndividual
39
+ type: 'autocomplete',
40
+ name: 'configIndividual',
41
+ message: 'Customer-Config (from Eclipse-Repository)?',
42
+ choices: configDirectories
43
+ },
44
+ {
45
+ // Ordnerauswahl von vorhandenen Ordner in configIndividual
46
+ type: 'text',
47
+ name: 'ram',
48
+ message: 'Xmx-Value (Max. RAM) in GB?',
49
+ initial: "8",
50
+ validate: input => {
51
+ if (isNaN(input)) {
52
+ return "Enter a Number"
53
+ }
54
+ return true;
55
+ }
56
+ },
57
+ {
58
+ // Ordnerauswahl von vorhandenen Ordner in configIndividual
59
+ type: 'text',
60
+ name: 'folderName',
61
+ message: 'Product-Name?',
62
+ initial: "eclipse"
63
+ },
64
+ ], {
65
+ onCancel: () => {
66
+ console.log()
67
+ console.log(chalk.red("Cancelled Import!"))
68
+ console.log()
69
+ success = false
70
+ }
71
+ })
72
+
73
+ if (success) {
74
+ console.log()
75
+
76
+ const spinnerRemoveOld = ora("Removing old configs")
77
+ const configPath = path.resolve(".", results.folder, "config");
78
+ const configIndividualPath = path.resolve(".", results.folder, "configIndividual");
79
+
80
+ if (existsSync(configPath)) {
81
+ rmSync(configPath, { recursive: true, force: true });
82
+ }
83
+
84
+ if (existsSync(configIndividualPath)) {
85
+ rmSync(configIndividualPath, { recursive: true, force: true });
86
+ }
87
+
88
+ spinnerRemoveOld.succeed("Removed old configs")
89
+
90
+ const spinnerConfig = ora('Copying config').start();
91
+
92
+
93
+ const sourceConfig = path.resolve(config.configIndividualPathEclipse, '..', "config");
94
+ const destConfig = path.resolve(".", results.folder, "config")
95
+
96
+ await cp(sourceConfig, destConfig, { recursive: true })
97
+
98
+ spinnerConfig.succeed("Config copied")
99
+
100
+ const spinnerConfigIndividual = ora('Copying configIndividual: ' + results.configIndividual).start();
101
+
102
+
103
+ const sourceConfigIndividual = path.resolve(config.configIndividualPathEclipse, results.configIndividual);
104
+ const destConfigIndividual = path.resolve(".", results.folder, "configIndividual", results.configIndividual)
105
+
106
+ await cp(sourceConfigIndividual, destConfigIndividual, { recursive: true })
107
+
108
+ spinnerConfigIndividual.succeed("ConfigIndividual copied: " + results.configIndividual)
109
+
110
+ const spinnerIcon = ora('Copying icon').start();
111
+
112
+ const sourceIcon = path.resolve(__dirname, "..", "ressources", "wegas_p.ico");
113
+ const destIcon = path.resolve(".", results.folder, "wegas_p.ico")
114
+
115
+ await cp(sourceIcon, destIcon, { recursive: true })
116
+
117
+ spinnerIcon.succeed("Icon copied")
118
+
119
+ const spinnerIniRewrite = ora('Rewriting wegas.ini: -Xmx' + results.ram + "g").start();
120
+
121
+ const iniPath = path.resolve(".", results.folder, "wegas.ini")
122
+
123
+ let iniContent = readFileSync(iniPath, 'utf-8');
124
+ const updatedContent = iniContent.replace(/-Xmx\d+[mgMG]?/, `-Xmx${results.ram}g`);
125
+ writeFileSync(iniPath, updatedContent);
126
+
127
+ spinnerIniRewrite.succeed("wegas.ini rewritten: -Xmx" + results.ram + "g")
128
+
129
+ const spinnerRename = ora("Renaming folder: " + results.folder + " -> " + results.folderName).start();
130
+ renameSync(path.resolve(".", results.folder), path.resolve(".", results.folderName))
131
+ spinnerRename.succeed("Folder renamed: " + results.folder + " -> " + results.folderName)
132
+
133
+ const spinnerZIP = ora('Zipping: ' + results.folderName + ".zip").start();
134
+
135
+ const zipPath = path.resolve(".", results.folderName + ".zip")
136
+ const addPath = path.resolve(".", results.folderName)
137
+ const add = Seven.add(zipPath, addPath, {
138
+ $bin: sevenBin.path7za
139
+ })
140
+
141
+ await getPromiseFromEvent(add, "end")
142
+
143
+ spinnerZIP.succeed('Zipped: ' + results.folderName + ".zip")
144
+
145
+ const spinnerRenameRevert = ora("Renaming folder: " + results.folderName + " -> " + results.folder).start();
146
+ renameSync(path.resolve(".", results.folderName), path.resolve(".", results.folder))
147
+ spinnerRenameRevert.succeed("Folder renamed: " + results.folderName + " -> " + results.folder)
148
+
149
+
150
+ console.log()
151
+ }
152
+ }
153
+
154
+ function getPromiseFromEvent(item, event) {
155
+ return new Promise((resolve) => {
156
+ const listener = (data) => {
157
+ resolve(data);
158
+ }
159
+ item.on(event, listener);
160
+ })
161
161
  }
@@ -1,118 +1,118 @@
1
- import chalk from 'chalk';
2
- import csv from 'csv-parser';
3
- import fs from "fs";
4
- import prompts from "prompts";
5
-
6
- export default async function csvMerge() {
7
- console.log()
8
-
9
- let success = true;
10
-
11
- const promptResults = await prompts([
12
- {
13
- // Output-File
14
- type: 'text',
15
- name: 'output',
16
- message: 'Output-File?',
17
- initial: "results.csv"
18
- },
19
- {
20
- // Filterverwendung
21
- type: 'toggle',
22
- name: 'useFilter',
23
- message: 'Use Filter?',
24
- initial: false,
25
- active: 'yes',
26
- inactive: 'no'
27
- },
28
- {
29
- type: prev => prev == true ? "select" : null,
30
- name: 'filtertype',
31
- message: 'Filter type?',
32
- choices: [
33
- { title: 'Equal', value: 'eq' },
34
- { title: 'Non-Equal', value: 'neq' }
35
- ]
36
- },
37
- {
38
- type: prev => prev != "" ? "text" : null,
39
- name: 'filterfield',
40
- message: 'Filter field?'
41
- },
42
- {
43
- type: prev => prev != "" ? "text" : null,
44
- name: 'filtervalue',
45
- message: 'Filter value?'
46
- },
47
- ], {
48
- onCancel: () => {
49
- console.log()
50
- console.log(chalk.red("Cancelled CSV-Merge!"))
51
- console.log()
52
- success = false
53
- }
54
- })
55
-
56
-
57
- if (success) {
58
- console.log()
59
-
60
- let files = fs.readdirSync(process.cwd(), { withFileTypes: true }).filter(file => file.isFile && file.name.endsWith(".csv") && file.name != promptResults.output);
61
-
62
- let finalResult = [];
63
- let counter = 0;
64
-
65
- files.forEach(file => {
66
- const results = [];
67
-
68
- fs.createReadStream(process.cwd() + "/" + file.name)
69
- .pipe(csv({ separator: ";", quote: "'" }))
70
- .on('data', (data) => results.push(data))
71
- .on('end', () => {
72
- const filteredResults = results.map(row => {
73
- const newRow = {}
74
- Object.entries(row).forEach(entry => {
75
- newRow[entry[0].replaceAll("'", "").replaceAll("`", "")] = entry[1]
76
- })
77
- newRow.file = file.name
78
- return newRow
79
- }).filter(row => {
80
- if (promptResults.useFilter) {
81
- switch (promptResults.filtertype){
82
- case "neq":
83
- if(row[promptResults.filterfield] != promptResults.filtervalue){
84
- return true
85
- }
86
- return false;
87
- case "eq":
88
- if(row[promptResults.filterfield] == promptResults.filtervalue){
89
- return true
90
- }
91
- return false;
92
- }
93
- return false;
94
- }
95
- return true;
96
- })
97
-
98
- finalResult = finalResult.concat(filteredResults)
99
- counter = counter + filteredResults.length
100
-
101
- let firstLine = true;
102
- fs.writeFileSync(process.cwd() + "/" + promptResults.output, finalResult.map(row => {
103
- let prev = ""
104
- if (firstLine) {
105
- prev = Object.keys(row).map(entry => { return "\"" + entry + "\"" }).join(";") + "\n";
106
- firstLine = false;
107
- }
108
- return prev + Object.values(row).map(entry => { return "\"" + entry + "\"" }).join(";");
109
- }).join("\n"))
110
- console.log(chalk.green(file.name + " merged."))
111
- });
112
-
113
- })
114
- }
115
-
116
-
117
-
1
+ import chalk from 'chalk';
2
+ import csv from 'csv-parser';
3
+ import fs from "fs";
4
+ import prompts from "prompts";
5
+
6
+ export default async function csvMerge() {
7
+ console.log()
8
+
9
+ let success = true;
10
+
11
+ const promptResults = await prompts([
12
+ {
13
+ // Output-File
14
+ type: 'text',
15
+ name: 'output',
16
+ message: 'Output-File?',
17
+ initial: "results.csv"
18
+ },
19
+ {
20
+ // Filterverwendung
21
+ type: 'toggle',
22
+ name: 'useFilter',
23
+ message: 'Use Filter?',
24
+ initial: false,
25
+ active: 'yes',
26
+ inactive: 'no'
27
+ },
28
+ {
29
+ type: prev => prev == true ? "select" : null,
30
+ name: 'filtertype',
31
+ message: 'Filter type?',
32
+ choices: [
33
+ { title: 'Equal', value: 'eq' },
34
+ { title: 'Non-Equal', value: 'neq' }
35
+ ]
36
+ },
37
+ {
38
+ type: prev => prev != "" ? "text" : null,
39
+ name: 'filterfield',
40
+ message: 'Filter field?'
41
+ },
42
+ {
43
+ type: prev => prev != "" ? "text" : null,
44
+ name: 'filtervalue',
45
+ message: 'Filter value?'
46
+ },
47
+ ], {
48
+ onCancel: () => {
49
+ console.log()
50
+ console.log(chalk.red("Cancelled CSV-Merge!"))
51
+ console.log()
52
+ success = false
53
+ }
54
+ })
55
+
56
+
57
+ if (success) {
58
+ console.log()
59
+
60
+ let files = fs.readdirSync(process.cwd(), { withFileTypes: true }).filter(file => file.isFile && file.name.endsWith(".csv") && file.name != promptResults.output);
61
+
62
+ let finalResult = [];
63
+ let counter = 0;
64
+
65
+ files.forEach(file => {
66
+ const results = [];
67
+
68
+ fs.createReadStream(process.cwd() + "/" + file.name)
69
+ .pipe(csv({ separator: ";", quote: "'" }))
70
+ .on('data', (data) => results.push(data))
71
+ .on('end', () => {
72
+ const filteredResults = results.map(row => {
73
+ const newRow = {}
74
+ Object.entries(row).forEach(entry => {
75
+ newRow[entry[0].replaceAll("'", "").replaceAll("`", "")] = entry[1]
76
+ })
77
+ newRow.file = file.name
78
+ return newRow
79
+ }).filter(row => {
80
+ if (promptResults.useFilter) {
81
+ switch (promptResults.filtertype){
82
+ case "neq":
83
+ if(row[promptResults.filterfield] != promptResults.filtervalue){
84
+ return true
85
+ }
86
+ return false;
87
+ case "eq":
88
+ if(row[promptResults.filterfield] == promptResults.filtervalue){
89
+ return true
90
+ }
91
+ return false;
92
+ }
93
+ return false;
94
+ }
95
+ return true;
96
+ })
97
+
98
+ finalResult = finalResult.concat(filteredResults)
99
+ counter = counter + filteredResults.length
100
+
101
+ let firstLine = true;
102
+ fs.writeFileSync(process.cwd() + "/" + promptResults.output, finalResult.map(row => {
103
+ let prev = ""
104
+ if (firstLine) {
105
+ prev = Object.keys(row).map(entry => { return "\"" + entry + "\"" }).join(";") + "\n";
106
+ firstLine = false;
107
+ }
108
+ return prev + Object.values(row).map(entry => { return "\"" + entry + "\"" }).join(";");
109
+ }).join("\n"))
110
+ console.log(chalk.green(file.name + " merged."))
111
+ });
112
+
113
+ })
114
+ }
115
+
116
+
117
+
118
118
  }