@lsbjordao/type-taxon-script 1.1.10 → 1.1.11
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 +1 -1
- package/dist/exportOntology.js +20 -10
- package/dist/exportSources.js +1 -1
- package/dist/exportToCsv.js +1 -1
- package/dist/findProperty.js +1 -1
- package/dist/import.js +1 -1
- package/dist/init.js +18 -8
- package/dist/new.js +1 -1
- package/dist/tts.js +0 -15
- package/package.json +1 -1
- package/dist/src/export.js +0 -238
- package/dist/src/exportOntology.js +0 -366
- package/dist/src/exportSources.js +0 -63
- package/dist/src/exportToCsv.js +0 -268
- package/dist/src/findProperty.js +0 -58
- package/dist/src/import.js +0 -98
- package/dist/src/init.js +0 -141
- package/dist/src/new.js +0 -47
- package/dist/src/tts.js +0 -130
package/dist/export.js
CHANGED
|
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.default = ttsExport;
|
|
15
16
|
const fs_1 = __importDefault(require("fs"));
|
|
16
17
|
const path_1 = __importDefault(require("path"));
|
|
17
18
|
const child_process_1 = require("child_process");
|
|
@@ -235,4 +236,3 @@ console.log(jsonData)
|
|
|
235
236
|
}
|
|
236
237
|
});
|
|
237
238
|
}
|
|
238
|
-
exports.default = ttsExport;
|
package/dist/exportOntology.js
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -35,6 +45,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
45
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
46
|
};
|
|
37
47
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.default = ttsExportOntology;
|
|
38
49
|
const fs_1 = __importDefault(require("fs"));
|
|
39
50
|
const path_1 = __importDefault(require("path"));
|
|
40
51
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
@@ -239,8 +250,8 @@ function serializeObject(writer, subject, object, objectTypeName, objectId, visi
|
|
|
239
250
|
}
|
|
240
251
|
}
|
|
241
252
|
function buildOntologyTTL() {
|
|
242
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
243
253
|
return __awaiter(this, void 0, void 0, function* () {
|
|
254
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
244
255
|
const writer = createWriter();
|
|
245
256
|
const modules = yield importModules('./characters/v1/**/*.ts');
|
|
246
257
|
for (const { mod } of modules) {
|
|
@@ -285,8 +296,8 @@ function buildOntologyTTL() {
|
|
|
285
296
|
});
|
|
286
297
|
}
|
|
287
298
|
function buildInstancesTTL(genus) {
|
|
288
|
-
var _a, _b;
|
|
289
299
|
return __awaiter(this, void 0, void 0, function* () {
|
|
300
|
+
var _a, _b;
|
|
290
301
|
const writer = createWriter();
|
|
291
302
|
const modules = yield importModules(`./taxon/${genus}/**/*.ts`);
|
|
292
303
|
const visited = new WeakSet();
|
|
@@ -353,4 +364,3 @@ function ttsExportOntology(genus) {
|
|
|
353
364
|
console.log(`\x1b[1m\x1b[32m✔ Combined semantic graph exported: \x1b[33m${semanticPath}\x1b[0m`);
|
|
354
365
|
});
|
|
355
366
|
}
|
|
356
|
-
exports.default = ttsExportOntology;
|
package/dist/exportSources.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = ttsExportSources;
|
|
6
7
|
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
9
|
function ttsExportSources(genus) {
|
|
@@ -60,4 +61,3 @@ function ttsExportSources(genus) {
|
|
|
60
61
|
}
|
|
61
62
|
});
|
|
62
63
|
}
|
|
63
|
-
exports.default = ttsExportSources;
|
package/dist/exportToCsv.js
CHANGED
|
@@ -12,6 +12,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.default = ttsExportToCsv;
|
|
15
16
|
const fs_1 = __importDefault(require("fs"));
|
|
16
17
|
const path_1 = __importDefault(require("path"));
|
|
17
18
|
const child_process_1 = require("child_process");
|
|
@@ -265,4 +266,3 @@ console.log(jsonData)
|
|
|
265
266
|
}
|
|
266
267
|
});
|
|
267
268
|
}
|
|
268
|
-
exports.default = ttsExportToCsv;
|
package/dist/findProperty.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = ttsfindProperty;
|
|
6
7
|
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const lodash_1 = __importDefault(require("lodash"));
|
|
8
9
|
function ttsfindProperty(property, genus) {
|
|
@@ -55,4 +56,3 @@ function ttsfindProperty(property, genus) {
|
|
|
55
56
|
}
|
|
56
57
|
});
|
|
57
58
|
}
|
|
58
|
-
exports.default = ttsfindProperty;
|
package/dist/import.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = ttsImportFromCsv;
|
|
6
7
|
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const csv_parser_1 = __importDefault(require("csv-parser"));
|
|
8
9
|
const mustache_1 = __importDefault(require("mustache"));
|
|
@@ -95,4 +96,3 @@ function ttsImportFromCsv(genus) {
|
|
|
95
96
|
}
|
|
96
97
|
});
|
|
97
98
|
}
|
|
98
|
-
exports.default = ttsImportFromCsv;
|
package/dist/init.js
CHANGED
|
@@ -15,14 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.default = ttsInit;
|
|
26
37
|
const fs = __importStar(require("fs"));
|
|
27
38
|
const path = __importStar(require("path"));
|
|
28
39
|
function createInputCSVFiles() {
|
|
@@ -128,4 +139,3 @@ function ttsInit() {
|
|
|
128
139
|
}
|
|
129
140
|
});
|
|
130
141
|
}
|
|
131
|
-
exports.default = ttsInit;
|
package/dist/new.js
CHANGED
|
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = ttsNewDesc;
|
|
6
7
|
const fs_1 = __importDefault(require("fs"));
|
|
7
8
|
const mustache_1 = __importDefault(require("mustache"));
|
|
8
9
|
function ttsNewDesc(genus, species) {
|
|
@@ -44,4 +45,3 @@ function ttsNewDesc(genus, species) {
|
|
|
44
45
|
console.error('An error occurred:', error);
|
|
45
46
|
}
|
|
46
47
|
}
|
|
47
|
-
exports.default = ttsNewDesc;
|
package/dist/tts.js
CHANGED
|
@@ -10,7 +10,6 @@ const import_1 = __importDefault(require("./import"));
|
|
|
10
10
|
const export_1 = __importDefault(require("./export"));
|
|
11
11
|
const exportSources_1 = __importDefault(require("./exportSources"));
|
|
12
12
|
const exportToCsv_1 = __importDefault(require("./exportToCsv"));
|
|
13
|
-
const exportOntology_1 = __importDefault(require("./exportOntology"));
|
|
14
13
|
const findProperty_1 = __importDefault(require("./findProperty"));
|
|
15
14
|
yargs_1.default.version();
|
|
16
15
|
yargs_1.default.command({
|
|
@@ -108,20 +107,6 @@ yargs_1.default.command({
|
|
|
108
107
|
(0, exportToCsv_1.default)(argv.genus, argv.load);
|
|
109
108
|
},
|
|
110
109
|
});
|
|
111
|
-
yargs_1.default.command({
|
|
112
|
-
command: 'exportOntology',
|
|
113
|
-
describe: 'Export ontology schema and RDF instances',
|
|
114
|
-
builder: {
|
|
115
|
-
genus: {
|
|
116
|
-
describe: 'Genus name',
|
|
117
|
-
demandOption: true,
|
|
118
|
-
type: 'string',
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
handler: (argv) => {
|
|
122
|
-
(0, exportOntology_1.default)(argv.genus);
|
|
123
|
-
},
|
|
124
|
-
});
|
|
125
110
|
yargs_1.default.command({
|
|
126
111
|
command: 'findProperty',
|
|
127
112
|
describe: 'Find a property',
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lsbjordao/type-taxon-script",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.11",
|
|
4
4
|
"author": "Lucas Jordão <tucarj@gmail.com> & André Eppinghaus <andreeppinghaus@gmail.com> & Vicente Calfo <vicentecalfo@gmail.com>",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"description": "TypeTaxonScript",
|
package/dist/src/export.js
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
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
|
-
exports.default = ttsExport;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const child_process_1 = require("child_process");
|
|
19
|
-
const csv_parser_1 = __importDefault(require("csv-parser"));
|
|
20
|
-
const cli_spinner_1 = require("cli-spinner");
|
|
21
|
-
function deleteJSFiles(folderPath) {
|
|
22
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
try {
|
|
24
|
-
const files = yield fs_1.default.promises.readdir(folderPath);
|
|
25
|
-
for (const file of files) {
|
|
26
|
-
if (file.endsWith('.js')) {
|
|
27
|
-
yield fs_1.default.promises.unlink(`${folderPath}/${file}`);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
console.error('Error deleting files:', err);
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
|
-
}
|
|
36
|
-
function ttsExport(genus, load) {
|
|
37
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
if (genus === '') {
|
|
39
|
-
console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
if (!fs_1.default.existsSync('./input') && !fs_1.default.existsSync('./output')) {
|
|
43
|
-
console.error("\x1b[31m✖ The ./input and ./output directories are not present within the project.\x1b[0m\n\x1b[36mℹ️ Please run \x1b[33m`tts init`\x1b[36m before attempting to export a database.\x1b[0m");
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
const spinner = new cli_spinner_1.Spinner('\x1b[36mProcessing... %s\x1b[0m');
|
|
47
|
-
spinner.setSpinnerString('|/-\\'); // spinner sequence
|
|
48
|
-
spinner.start();
|
|
49
|
-
const taxa = [];
|
|
50
|
-
fs_1.default.mkdirSync('./temp', { recursive: true });
|
|
51
|
-
if (load === 'all') {
|
|
52
|
-
const directoryPath = `./taxon/${genus}/`;
|
|
53
|
-
fs_1.default.readdir(directoryPath, (err, files) => {
|
|
54
|
-
if (err) {
|
|
55
|
-
spinner.stop();
|
|
56
|
-
console.error('Error reading directory:', err);
|
|
57
|
-
process.exit();
|
|
58
|
-
}
|
|
59
|
-
const taxa = files
|
|
60
|
-
.filter(file => file.endsWith('.ts') && file !== 'index.ts')
|
|
61
|
-
.map(file => path_1.default.parse(file).name);
|
|
62
|
-
const importStatements = taxa.map((species) => {
|
|
63
|
-
return `import { ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())} } from '../taxon/${genus}/${species.replace(/\s/g, '_')}'`;
|
|
64
|
-
}).join('\n');
|
|
65
|
-
const speciesCall = taxa.map((species) => {
|
|
66
|
-
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
67
|
-
}).join('\n');
|
|
68
|
-
const fileContent = `// Import genus ${genus}
|
|
69
|
-
import { ${genus} } from '../taxon/${genus}'
|
|
70
|
-
|
|
71
|
-
// Import species of ${genus}
|
|
72
|
-
${importStatements}
|
|
73
|
-
|
|
74
|
-
const ${genus}_species: ${genus}[] = [
|
|
75
|
-
${speciesCall}
|
|
76
|
-
]
|
|
77
|
-
|
|
78
|
-
// Export ${genus}DB.json
|
|
79
|
-
//import { writeFileSync } from 'fs'
|
|
80
|
-
const jsonData = JSON.stringify(${genus}_species);
|
|
81
|
-
console.log(jsonData)
|
|
82
|
-
//const inputFilePath = '../output/${genus}DB.json'
|
|
83
|
-
//writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
84
|
-
//console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
85
|
-
const tempFilePath = './temp/exportTemp.ts';
|
|
86
|
-
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
87
|
-
const fileToTranspile = 'exportTemp';
|
|
88
|
-
(0, child_process_1.exec)(`tsc ./temp/${fileToTranspile}.ts`, (error, stdout, stderr) => {
|
|
89
|
-
if (stdout) {
|
|
90
|
-
spinner.stop();
|
|
91
|
-
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stdout}`);
|
|
92
|
-
process.exit();
|
|
93
|
-
}
|
|
94
|
-
if (stderr) {
|
|
95
|
-
spinner.stop();
|
|
96
|
-
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stderr}`);
|
|
97
|
-
process.exit();
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.ts`);
|
|
101
|
-
}
|
|
102
|
-
catch (err) {
|
|
103
|
-
spinner.stop();
|
|
104
|
-
console.error(`An error occurred while deleting the file: ${err}`);
|
|
105
|
-
process.exit();
|
|
106
|
-
}
|
|
107
|
-
(0, child_process_1.exec)(`node ./temp/${fileToTranspile}.js > ./output/${genus}DB.json`, (error, stdout, stderr) => {
|
|
108
|
-
// if (error) {
|
|
109
|
-
// spinner.stop()
|
|
110
|
-
// console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${error.message}`)
|
|
111
|
-
// process.exit()
|
|
112
|
-
// }
|
|
113
|
-
if (stdout) {
|
|
114
|
-
spinner.stop();
|
|
115
|
-
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stdout}`);
|
|
116
|
-
process.exit();
|
|
117
|
-
}
|
|
118
|
-
if (stderr) {
|
|
119
|
-
spinner.stop();
|
|
120
|
-
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stderr}`);
|
|
121
|
-
process.exit();
|
|
122
|
-
}
|
|
123
|
-
deleteJSFiles(`./taxon/${genus}`).then(() => {
|
|
124
|
-
const filePath = './output/';
|
|
125
|
-
console.log(`\x1b[1m\x1b[32m✔ JSON database exported: \x1b[33m${filePath}${genus}DB.json\x1b[0m\x1b[1m\x1b[32m\x1b[0m`);
|
|
126
|
-
spinner.stop();
|
|
127
|
-
try {
|
|
128
|
-
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.js`);
|
|
129
|
-
fs_1.default.rm('./temp', { recursive: true }, (err) => {
|
|
130
|
-
if (err) {
|
|
131
|
-
console.error('Error deleting directory:', err);
|
|
132
|
-
process.exit();
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
catch (err) {
|
|
137
|
-
console.error(`An error occurred while deleting the file: ${err}`);
|
|
138
|
-
process.exit();
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
if (load === 'csv') {
|
|
146
|
-
const inputFilePath = './input/taxaToExport.csv';
|
|
147
|
-
const tempFilePath = './temp/exportTemp.ts';
|
|
148
|
-
fs_1.default.createReadStream(inputFilePath)
|
|
149
|
-
.pipe((0, csv_parser_1.default)({ headers: false }))
|
|
150
|
-
.on('data', (data) => {
|
|
151
|
-
taxa.push(data['0']);
|
|
152
|
-
})
|
|
153
|
-
.on('end', () => __awaiter(this, void 0, void 0, function* () {
|
|
154
|
-
const importStatements = taxa.map((species) => {
|
|
155
|
-
return `import { ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())} } from '../taxon/${genus}/${species.replace(/\s/g, '_')}'`;
|
|
156
|
-
}).join('\n');
|
|
157
|
-
const speciesCall = taxa.map((species) => {
|
|
158
|
-
return ` ${species.replace(/\s/g, '_').replace(/\-([a-z])/, (_, match) => match.toUpperCase())},`;
|
|
159
|
-
}).join('\n');
|
|
160
|
-
const fileContent = `// Import genus ${genus}
|
|
161
|
-
import { ${genus} } from '../taxon/${genus}'
|
|
162
|
-
|
|
163
|
-
// Import species of ${genus}
|
|
164
|
-
${importStatements}
|
|
165
|
-
|
|
166
|
-
const ${genus}_species: ${genus}[] = [
|
|
167
|
-
${speciesCall}
|
|
168
|
-
]
|
|
169
|
-
|
|
170
|
-
// Export ${genus}DB.json
|
|
171
|
-
const jsonData = JSON.stringify(${genus}_species);
|
|
172
|
-
console.log(jsonData)
|
|
173
|
-
// import { writeFileSync } from 'fs'
|
|
174
|
-
// const jsonData = JSON.stringify(${genus}_species)
|
|
175
|
-
// const inputFilePath = '../output/${genus}DB.json'
|
|
176
|
-
// writeFileSync(inputFilePath, jsonData, 'utf-8')
|
|
177
|
-
// console.log('\\x1b[1m\\x1b[32m✔ Process finished.\\x1b[0m')`;
|
|
178
|
-
fs_1.default.writeFileSync(tempFilePath, fileContent, 'utf-8');
|
|
179
|
-
const fileToTranspile = 'exportTemp';
|
|
180
|
-
(0, child_process_1.exec)(`tsc ./temp/${fileToTranspile}.ts`, (error, stdout, stderr) => {
|
|
181
|
-
if (stdout) {
|
|
182
|
-
spinner.stop();
|
|
183
|
-
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stdout}`);
|
|
184
|
-
process.exit();
|
|
185
|
-
}
|
|
186
|
-
if (stderr) {
|
|
187
|
-
spinner.stop();
|
|
188
|
-
console.error('\x1b[31m✖ TS Error:\x1b[0m\n\n' + `${stdout}`);
|
|
189
|
-
process.exit();
|
|
190
|
-
}
|
|
191
|
-
try {
|
|
192
|
-
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.ts`);
|
|
193
|
-
}
|
|
194
|
-
catch (err) {
|
|
195
|
-
spinner.stop();
|
|
196
|
-
console.error(`An error occurred while deleting the file: ${err}`);
|
|
197
|
-
process.exit();
|
|
198
|
-
}
|
|
199
|
-
(0, child_process_1.exec)(`node ./temp/${fileToTranspile}.js > ./output/${genus}DB.json`, (error, stdout, stderr) => {
|
|
200
|
-
// if (error) {
|
|
201
|
-
// spinner.stop()
|
|
202
|
-
// console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${error.message}`)
|
|
203
|
-
// process.exit()
|
|
204
|
-
// }
|
|
205
|
-
if (stdout) {
|
|
206
|
-
spinner.stop();
|
|
207
|
-
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stdout}`);
|
|
208
|
-
process.exit();
|
|
209
|
-
}
|
|
210
|
-
if (stderr) {
|
|
211
|
-
spinner.stop();
|
|
212
|
-
console.error('\x1b[31m✖ JS execution time error:\x1b[0m\n\n' + `${stderr}`);
|
|
213
|
-
process.exit();
|
|
214
|
-
}
|
|
215
|
-
deleteJSFiles(`./taxon/${genus}`).then(() => {
|
|
216
|
-
const filePath = './output/';
|
|
217
|
-
console.log(`\x1b[1m\x1b[32m✔ JSON database exported: \x1b[33m${filePath}${genus}DB.json\x1b[0m\x1b[1m\x1b[32m\x1b[0m`);
|
|
218
|
-
spinner.stop();
|
|
219
|
-
try {
|
|
220
|
-
fs_1.default.unlinkSync(`./temp/${fileToTranspile}.js`);
|
|
221
|
-
fs_1.default.rm('./temp', { recursive: true }, (err) => {
|
|
222
|
-
if (err) {
|
|
223
|
-
console.error('Error deleting directory:', err);
|
|
224
|
-
process.exit();
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
}
|
|
228
|
-
catch (err) {
|
|
229
|
-
console.error(`An error occurred while deleting the file: ${err}`);
|
|
230
|
-
process.exit();
|
|
231
|
-
}
|
|
232
|
-
});
|
|
233
|
-
});
|
|
234
|
-
});
|
|
235
|
-
}));
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
}
|