@lsbjordao/type-taxon-script 1.1.0 → 1.1.2
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/dist/export.js +201 -205
- package/dist/exportSources.js +59 -63
- package/dist/findProperty.js +58 -58
- package/dist/import.js +98 -98
- package/dist/init.js +115 -115
- package/dist/new.js +47 -47
- package/dist/tts.js +108 -130
- package/package.json +1 -1
- package/readme.md +458 -2
- package/dist/exportToCsv.js +0 -268
package/dist/export.js
CHANGED
|
@@ -1,69 +1,65 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
const fs_1 = __importDefault(require("fs"));
|
|
16
|
-
const path_1 = __importDefault(require("path"));
|
|
17
|
-
const child_process_1 = require("child_process");
|
|
18
|
-
const csv_parser_1 = __importDefault(require("csv-parser"));
|
|
19
|
-
const cli_spinner_1 = require("cli-spinner");
|
|
20
|
-
function deleteJSFiles(folderPath) {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
try {
|
|
23
|
-
const files = yield fs_1.default.promises.readdir(folderPath);
|
|
24
|
-
for (const file of files) {
|
|
25
|
-
if (file.endsWith('.js')) {
|
|
26
|
-
yield fs_1.default.promises.unlink(`${folderPath}/${file}`);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
catch (err) {
|
|
31
|
-
console.error('Error deleting files:', err);
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
function ttsExport(genus, load) {
|
|
36
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
if (genus === '') {
|
|
38
|
-
console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}).join('\n');
|
|
64
|
-
const speciesCall = taxa.map((species) => {
|
|
65
|
-
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
66
|
-
}).join('\n');
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const fs_1 = __importDefault(require("fs"));
|
|
16
|
+
const path_1 = __importDefault(require("path"));
|
|
17
|
+
const child_process_1 = require("child_process");
|
|
18
|
+
const csv_parser_1 = __importDefault(require("csv-parser"));
|
|
19
|
+
const cli_spinner_1 = require("cli-spinner");
|
|
20
|
+
function deleteJSFiles(folderPath) {
|
|
21
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
+
try {
|
|
23
|
+
const files = yield fs_1.default.promises.readdir(folderPath);
|
|
24
|
+
for (const file of files) {
|
|
25
|
+
if (file.endsWith('.js')) {
|
|
26
|
+
yield fs_1.default.promises.unlink(`${folderPath}/${file}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
console.error('Error deleting files:', err);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function ttsExport(genus, load) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
if (genus === '') {
|
|
38
|
+
console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const spinner = new cli_spinner_1.Spinner('\x1b[36mProcessing... %s\x1b[0m');
|
|
42
|
+
spinner.setSpinnerString('|/-\\'); // spinner sequence
|
|
43
|
+
spinner.start();
|
|
44
|
+
const taxa = [];
|
|
45
|
+
fs_1.default.mkdirSync('./temp', { recursive: true });
|
|
46
|
+
if (load === 'all') {
|
|
47
|
+
const directoryPath = `./taxon/${genus}/`;
|
|
48
|
+
fs_1.default.readdir(directoryPath, (err, files) => {
|
|
49
|
+
if (err) {
|
|
50
|
+
spinner.stop();
|
|
51
|
+
console.error('Error reading directory:', err);
|
|
52
|
+
process.exit();
|
|
53
|
+
}
|
|
54
|
+
const taxa = files
|
|
55
|
+
.filter(file => file.endsWith('.ts') && file !== 'index.ts')
|
|
56
|
+
.map(file => path_1.default.parse(file).name);
|
|
57
|
+
const importStatements = taxa.map((species) => {
|
|
58
|
+
return `import { ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())} } from '../taxon/${genus}/${species.replace(/\s/g, '_')}'`;
|
|
59
|
+
}).join('\n');
|
|
60
|
+
const speciesCall = taxa.map((species) => {
|
|
61
|
+
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
62
|
+
}).join('\n');
|
|
67
63
|
const fileContent = `// Import genus ${genus}
|
|
68
64
|
import { ${genus} } from '../taxon/${genus}'
|
|
69
65
|
|
|
@@ -80,82 +76,82 @@ const jsonData = JSON.stringify(${genus}_species);
|
|
|
80
76
|
console.log(jsonData)
|
|
81
77
|
//const inputFilePath = '../output/${genus}DB.json'
|
|
82
78
|
//writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
83
|
-
//console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
84
|
-
const tempFilePath = './temp/exportTemp.ts';
|
|
85
|
-
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
86
|
-
const fileToTranspile = 'exportTemp';
|
|
87
|
-
(0, child_process_1.exec)(`tsc ./temp/${fileToTranspile}.ts`, (error, stdout, stderr) => {
|
|
88
|
-
if (stdout) {
|
|
89
|
-
spinner.stop();
|
|
90
|
-
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stdout}`);
|
|
91
|
-
process.exit();
|
|
92
|
-
}
|
|
93
|
-
if (stderr) {
|
|
94
|
-
spinner.stop();
|
|
95
|
-
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stderr}`);
|
|
96
|
-
process.exit();
|
|
97
|
-
}
|
|
98
|
-
try {
|
|
99
|
-
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.ts`);
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
spinner.stop();
|
|
103
|
-
console.error(`An error occurred while deleting the file: ${err}`);
|
|
104
|
-
process.exit();
|
|
105
|
-
}
|
|
106
|
-
(0, child_process_1.exec)(`node ./temp/${fileToTranspile}.js > ./output/${genus}DB.json`, (error, stdout, stderr) => {
|
|
107
|
-
// if (error) {
|
|
108
|
-
// spinner.stop()
|
|
109
|
-
// console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${error.message}`)
|
|
110
|
-
// process.exit()
|
|
111
|
-
// }
|
|
112
|
-
if (stdout) {
|
|
113
|
-
spinner.stop();
|
|
114
|
-
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stdout}`);
|
|
115
|
-
process.exit();
|
|
116
|
-
}
|
|
117
|
-
if (stderr) {
|
|
118
|
-
spinner.stop();
|
|
119
|
-
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stderr}`);
|
|
120
|
-
process.exit();
|
|
121
|
-
}
|
|
122
|
-
deleteJSFiles(`./taxon/${genus}`).then(() => {
|
|
123
|
-
const filePath = './output/';
|
|
124
|
-
console.log(`\x1b[1m\x1b[32m✔
|
|
125
|
-
spinner.stop();
|
|
126
|
-
try {
|
|
127
|
-
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.js`);
|
|
128
|
-
fs_1.default.rm('./temp', { recursive: true }, (err) => {
|
|
129
|
-
if (err) {
|
|
130
|
-
console.error('Error deleting directory:', err);
|
|
131
|
-
process.exit();
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
catch (err) {
|
|
136
|
-
console.error(`An error occurred while deleting the file: ${err}`);
|
|
137
|
-
process.exit();
|
|
138
|
-
}
|
|
139
|
-
});
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
if (load === 'csv') {
|
|
145
|
-
const inputFilePath = './input/taxaToExport.csv';
|
|
146
|
-
const tempFilePath = './temp/exportTemp.ts';
|
|
147
|
-
fs_1.default.createReadStream(inputFilePath)
|
|
148
|
-
.pipe((0, csv_parser_1.default)({ headers: false }))
|
|
149
|
-
.on('data', (data) => {
|
|
150
|
-
taxa.push(data['0']);
|
|
151
|
-
})
|
|
152
|
-
.on('end', () => __awaiter(this, void 0, void 0, function* () {
|
|
153
|
-
const importStatements = taxa.map((species) => {
|
|
154
|
-
return `import { ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())} } from '../taxon/${genus}/${species.replace(/\s/g, '_')}'`;
|
|
155
|
-
}).join('\n');
|
|
156
|
-
const speciesCall = taxa.map((species) => {
|
|
157
|
-
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
158
|
-
}).join('\n');
|
|
79
|
+
//console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
80
|
+
const tempFilePath = './temp/exportTemp.ts';
|
|
81
|
+
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
82
|
+
const fileToTranspile = 'exportTemp';
|
|
83
|
+
(0, child_process_1.exec)(`tsc ./temp/${fileToTranspile}.ts`, (error, stdout, stderr) => {
|
|
84
|
+
if (stdout) {
|
|
85
|
+
spinner.stop();
|
|
86
|
+
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stdout}`);
|
|
87
|
+
process.exit();
|
|
88
|
+
}
|
|
89
|
+
if (stderr) {
|
|
90
|
+
spinner.stop();
|
|
91
|
+
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stderr}`);
|
|
92
|
+
process.exit();
|
|
93
|
+
}
|
|
94
|
+
try {
|
|
95
|
+
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.ts`);
|
|
96
|
+
}
|
|
97
|
+
catch (err) {
|
|
98
|
+
spinner.stop();
|
|
99
|
+
console.error(`An error occurred while deleting the file: ${err}`);
|
|
100
|
+
process.exit();
|
|
101
|
+
}
|
|
102
|
+
(0, child_process_1.exec)(`node ./temp/${fileToTranspile}.js > ./output/${genus}DB.json`, (error, stdout, stderr) => {
|
|
103
|
+
// if (error) {
|
|
104
|
+
// spinner.stop()
|
|
105
|
+
// console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${error.message}`)
|
|
106
|
+
// process.exit()
|
|
107
|
+
// }
|
|
108
|
+
if (stdout) {
|
|
109
|
+
spinner.stop();
|
|
110
|
+
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stdout}`);
|
|
111
|
+
process.exit();
|
|
112
|
+
}
|
|
113
|
+
if (stderr) {
|
|
114
|
+
spinner.stop();
|
|
115
|
+
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stderr}`);
|
|
116
|
+
process.exit();
|
|
117
|
+
}
|
|
118
|
+
deleteJSFiles(`./taxon/${genus}`).then(() => {
|
|
119
|
+
const filePath = './output/';
|
|
120
|
+
console.log(`\x1b[1m\x1b[32m✔ Database exported: \x1b[33m${filePath}${genus}DB.json\x1b[0m\x1b[1m\x1b[32m\x1b[0m`);
|
|
121
|
+
spinner.stop();
|
|
122
|
+
try {
|
|
123
|
+
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.js`);
|
|
124
|
+
fs_1.default.rm('./temp', { recursive: true }, (err) => {
|
|
125
|
+
if (err) {
|
|
126
|
+
console.error('Error deleting directory:', err);
|
|
127
|
+
process.exit();
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
catch (err) {
|
|
132
|
+
console.error(`An error occurred while deleting the file: ${err}`);
|
|
133
|
+
process.exit();
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
if (load === 'csv') {
|
|
141
|
+
const inputFilePath = './input/taxaToExport.csv';
|
|
142
|
+
const tempFilePath = './temp/exportTemp.ts';
|
|
143
|
+
fs_1.default.createReadStream(inputFilePath)
|
|
144
|
+
.pipe((0, csv_parser_1.default)({ headers: false }))
|
|
145
|
+
.on('data', (data) => {
|
|
146
|
+
taxa.push(data['0']);
|
|
147
|
+
})
|
|
148
|
+
.on('end', () => __awaiter(this, void 0, void 0, function* () {
|
|
149
|
+
const importStatements = taxa.map((species) => {
|
|
150
|
+
return `import { ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())} } from '../taxon/${genus}/${species.replace(/\s/g, '_')}'`;
|
|
151
|
+
}).join('\n');
|
|
152
|
+
const speciesCall = taxa.map((species) => {
|
|
153
|
+
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
154
|
+
}).join('\n');
|
|
159
155
|
const fileContent = `// Import genus ${genus}
|
|
160
156
|
import { ${genus} } from '../taxon/${genus}'
|
|
161
157
|
|
|
@@ -173,66 +169,66 @@ console.log(jsonData)
|
|
|
173
169
|
// const jsonData = JSON.stringify(${genus}_species)
|
|
174
170
|
// const inputFilePath = '../output/${genus}DB.json'
|
|
175
171
|
// writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
176
|
-
// console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
177
|
-
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
178
|
-
const fileToTranspile = 'exportTemp';
|
|
179
|
-
(0, child_process_1.exec)(`tsc ./temp/${fileToTranspile}.ts`, (error, stdout, stderr) => {
|
|
180
|
-
if (stdout) {
|
|
181
|
-
spinner.stop();
|
|
182
|
-
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stdout}`);
|
|
183
|
-
process.exit();
|
|
184
|
-
}
|
|
185
|
-
if (stderr) {
|
|
186
|
-
spinner.stop();
|
|
187
|
-
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stdout}`);
|
|
188
|
-
process.exit();
|
|
189
|
-
}
|
|
190
|
-
try {
|
|
191
|
-
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.ts`);
|
|
192
|
-
}
|
|
193
|
-
catch (err) {
|
|
194
|
-
spinner.stop();
|
|
195
|
-
console.error(`An error occurred while deleting the file: ${err}`);
|
|
196
|
-
process.exit();
|
|
197
|
-
}
|
|
198
|
-
(0, child_process_1.exec)(`node ./temp/${fileToTranspile}.js > ./output/${genus}DB.json`, (error, stdout, stderr) => {
|
|
199
|
-
// if (error) {
|
|
200
|
-
// spinner.stop()
|
|
201
|
-
// console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${error.message}`)
|
|
202
|
-
// process.exit()
|
|
203
|
-
// }
|
|
204
|
-
if (stdout) {
|
|
205
|
-
spinner.stop();
|
|
206
|
-
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stdout}`);
|
|
207
|
-
process.exit();
|
|
208
|
-
}
|
|
209
|
-
if (stderr) {
|
|
210
|
-
spinner.stop();
|
|
211
|
-
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stderr}`);
|
|
212
|
-
process.exit();
|
|
213
|
-
}
|
|
214
|
-
deleteJSFiles(`./taxon/${genus}`).then(() => {
|
|
215
|
-
const filePath = './output/';
|
|
216
|
-
console.log(`\x1b[1m\x1b[32m✔
|
|
217
|
-
spinner.stop();
|
|
218
|
-
try {
|
|
219
|
-
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.js`);
|
|
220
|
-
fs_1.default.rm('./temp', { recursive: true }, (err) => {
|
|
221
|
-
if (err) {
|
|
222
|
-
console.error('Error deleting directory:', err);
|
|
223
|
-
process.exit();
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
catch (err) {
|
|
228
|
-
console.error(`An error occurred while deleting the file: ${err}`);
|
|
229
|
-
process.exit();
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
}));
|
|
235
|
-
}
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
exports.default = ttsExport;
|
|
172
|
+
// console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
173
|
+
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
174
|
+
const fileToTranspile = 'exportTemp';
|
|
175
|
+
(0, child_process_1.exec)(`tsc ./temp/${fileToTranspile}.ts`, (error, stdout, stderr) => {
|
|
176
|
+
if (stdout) {
|
|
177
|
+
spinner.stop();
|
|
178
|
+
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stdout}`);
|
|
179
|
+
process.exit();
|
|
180
|
+
}
|
|
181
|
+
if (stderr) {
|
|
182
|
+
spinner.stop();
|
|
183
|
+
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stdout}`);
|
|
184
|
+
process.exit();
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.ts`);
|
|
188
|
+
}
|
|
189
|
+
catch (err) {
|
|
190
|
+
spinner.stop();
|
|
191
|
+
console.error(`An error occurred while deleting the file: ${err}`);
|
|
192
|
+
process.exit();
|
|
193
|
+
}
|
|
194
|
+
(0, child_process_1.exec)(`node ./temp/${fileToTranspile}.js > ./output/${genus}DB.json`, (error, stdout, stderr) => {
|
|
195
|
+
// if (error) {
|
|
196
|
+
// spinner.stop()
|
|
197
|
+
// console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${error.message}`)
|
|
198
|
+
// process.exit()
|
|
199
|
+
// }
|
|
200
|
+
if (stdout) {
|
|
201
|
+
spinner.stop();
|
|
202
|
+
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stdout}`);
|
|
203
|
+
process.exit();
|
|
204
|
+
}
|
|
205
|
+
if (stderr) {
|
|
206
|
+
spinner.stop();
|
|
207
|
+
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stderr}`);
|
|
208
|
+
process.exit();
|
|
209
|
+
}
|
|
210
|
+
deleteJSFiles(`./taxon/${genus}`).then(() => {
|
|
211
|
+
const filePath = './output/';
|
|
212
|
+
console.log(`\x1b[1m\x1b[32m✔ Database exported: \x1b[33m${filePath}${genus}DB.json\x1b[0m\x1b[1m\x1b[32m\x1b[0m`);
|
|
213
|
+
spinner.stop();
|
|
214
|
+
try {
|
|
215
|
+
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.js`);
|
|
216
|
+
fs_1.default.rm('./temp', { recursive: true }, (err) => {
|
|
217
|
+
if (err) {
|
|
218
|
+
console.error('Error deleting directory:', err);
|
|
219
|
+
process.exit();
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
catch (err) {
|
|
224
|
+
console.error(`An error occurred while deleting the file: ${err}`);
|
|
225
|
+
process.exit();
|
|
226
|
+
}
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
}));
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
exports.default = ttsExport;
|
package/dist/exportSources.js
CHANGED
|
@@ -1,63 +1,59 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const fs_1 = __importDefault(require("fs"));
|
|
7
|
-
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
-
function ttsExportSources(genus) {
|
|
9
|
-
if (genus === '') {
|
|
10
|
-
console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
|
|
11
|
-
return;
|
|
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
|
-
exports.default = ttsExportSources;
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = __importDefault(require("fs"));
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
function ttsExportSources(genus) {
|
|
9
|
+
if (genus === '') {
|
|
10
|
+
console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const filePath = `./output/${genus}DB.json`;
|
|
14
|
+
fs_1.default.readFile(filePath, 'utf8', (err, data) => {
|
|
15
|
+
if (err) {
|
|
16
|
+
console.error('Error reading the file:', err);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
const jsonData = JSON.parse(data);
|
|
21
|
+
const findObjectsWithSources = (obj, currentPath = []) => {
|
|
22
|
+
let objectsWithSources = [];
|
|
23
|
+
const findObjectsWithSourcesRecursively = (currentObj, path) => {
|
|
24
|
+
if (lodash_1.default.isObject(currentObj)) {
|
|
25
|
+
lodash_1.default.forOwn(currentObj, (value, key) => {
|
|
26
|
+
if (key === 'sources' && Array.isArray(value) && value.length > 0) {
|
|
27
|
+
value.forEach((source) => {
|
|
28
|
+
objectsWithSources.push({
|
|
29
|
+
index: path[0],
|
|
30
|
+
path: path.join('.'),
|
|
31
|
+
specificEpithet: lodash_1.default.get(jsonData[path[0]], 'specificEpithet'),
|
|
32
|
+
source: source
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (lodash_1.default.isObject(value)) {
|
|
37
|
+
findObjectsWithSourcesRecursively(value, [...path, key]);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
findObjectsWithSourcesRecursively(obj, currentPath);
|
|
43
|
+
objectsWithSources.forEach(item => {
|
|
44
|
+
item.path = item.path.replace(new RegExp(`^${item.index}\\.|${item.index}$`), '');
|
|
45
|
+
});
|
|
46
|
+
return objectsWithSources;
|
|
47
|
+
};
|
|
48
|
+
const objectsWithSources = findObjectsWithSources(jsonData.map((item, index) => (Object.assign(Object.assign({}, item), { index }))));
|
|
49
|
+
const filePathOutput = `./output/${genus}SourcesDB.json`;
|
|
50
|
+
const jsonContent = JSON.stringify(objectsWithSources, null, 2);
|
|
51
|
+
fs_1.default.writeFileSync(filePathOutput, jsonContent, 'utf-8');
|
|
52
|
+
console.log(`\x1b[1m\x1b[32m✔ Database exported: \x1b[33m${filePathOutput}\x1b[0m\x1b[1m\x1b[32m\x1b[0m`);
|
|
53
|
+
}
|
|
54
|
+
catch (jsonErr) {
|
|
55
|
+
console.error('Error parsing JSON:', jsonErr);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
exports.default = ttsExportSources;
|