@lsbjordao/type-taxon-script 1.0.4 → 1.0.5

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,58 +1,58 @@
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 ttsfindProperty(property, genus) {
9
- if (property === '') {
10
- console.error('\x1b[31m✖ Argument `--property` cannot be empty.\x1b[0m');
11
- return;
12
- }
13
- if (genus === '') {
14
- console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
15
- return;
16
- }
17
- const filePath = `./output/${genus}DB.json`;
18
- const propertyPathToFind = property;
19
- fs_1.default.readFile(filePath, 'utf8', (err, data) => {
20
- if (err) {
21
- console.error('Error reading the file:', err);
22
- return;
23
- }
24
- try {
25
- const jsonData = JSON.parse(data);
26
- const findPropertyPath = (obj, propertyPath, currentPath = []) => {
27
- const paths = [];
28
- const findPathsRecursively = (currentObj, path) => {
29
- const lastKey = path[path.length - 1];
30
- if (lodash_1.default.get(currentObj, propertyPath)) {
31
- if (typeof lastKey !== 'number') {
32
- paths.push(path.join('.'));
33
- }
34
- }
35
- lodash_1.default.forEach(currentObj, (value, key) => {
36
- if (lodash_1.default.isObject(value)) {
37
- findPathsRecursively(value, [...path, key]);
38
- }
39
- });
40
- };
41
- findPathsRecursively(obj, currentPath);
42
- return paths;
43
- };
44
- const resultIndicesAndPaths = jsonData.flatMap((item, index) => {
45
- const paths = findPropertyPath(item, propertyPathToFind);
46
- if (paths.length > 0) {
47
- return { index, paths, specificEpithet: jsonData[index].specificEpithet };
48
- }
49
- return [];
50
- });
51
- console.log(`\x1b[36mℹ️ Indices and paths of objects with the property \x1b[33m${propertyPathToFind}\x1b[0m\x1b[36m:\n\n\x1b[0m`, resultIndicesAndPaths);
52
- }
53
- catch (jsonErr) {
54
- console.error('Error parsing JSON:', jsonErr);
55
- }
56
- });
57
- }
58
- exports.default = ttsfindProperty;
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 ttsfindProperty(property, genus) {
9
+ if (property === '') {
10
+ console.error('\x1b[31m✖ Argument `--property` cannot be empty.\x1b[0m');
11
+ return;
12
+ }
13
+ if (genus === '') {
14
+ console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
15
+ return;
16
+ }
17
+ const filePath = `./output/${genus}DB.json`;
18
+ const propertyPathToFind = property;
19
+ fs_1.default.readFile(filePath, 'utf8', (err, data) => {
20
+ if (err) {
21
+ console.error('Error reading the file:', err);
22
+ return;
23
+ }
24
+ try {
25
+ const jsonData = JSON.parse(data);
26
+ const findPropertyPath = (obj, propertyPath, currentPath = []) => {
27
+ const paths = [];
28
+ const findPathsRecursively = (currentObj, path) => {
29
+ const lastKey = path[path.length - 1];
30
+ if (lodash_1.default.get(currentObj, propertyPath)) {
31
+ if (typeof lastKey !== 'number') {
32
+ paths.push(path.join('.'));
33
+ }
34
+ }
35
+ lodash_1.default.forEach(currentObj, (value, key) => {
36
+ if (lodash_1.default.isObject(value)) {
37
+ findPathsRecursively(value, [...path, key]);
38
+ }
39
+ });
40
+ };
41
+ findPathsRecursively(obj, currentPath);
42
+ return paths;
43
+ };
44
+ const resultIndicesAndPaths = jsonData.flatMap((item, index) => {
45
+ const paths = findPropertyPath(item, propertyPathToFind);
46
+ if (paths.length > 0) {
47
+ return { index, paths, specificEpithet: jsonData[index].specificEpithet };
48
+ }
49
+ return [];
50
+ });
51
+ console.log(`\x1b[36mℹ️ Indices and paths of objects with the property \x1b[33m${propertyPathToFind}\x1b[0m\x1b[36m:\n\n\x1b[0m`, resultIndicesAndPaths);
52
+ }
53
+ catch (jsonErr) {
54
+ console.error('Error parsing JSON:', jsonErr);
55
+ }
56
+ });
57
+ }
58
+ exports.default = ttsfindProperty;
package/dist/import.js CHANGED
@@ -1,98 +1,98 @@
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 csv_parser_1 = __importDefault(require("csv-parser"));
8
- const mustache_1 = __importDefault(require("mustache"));
9
- const mapColumns = {
10
- 'specificEpithet': 'specificEpithet',
11
- 'descriptionAuthorship': 'descriptionAuthorship',
12
- 'leaf.bipinnate.pinnae.numberOfPairs.rarelyMin': 'leafBipinnatePinnaeNumberOfPairsRarelyMin',
13
- 'leaf.bipinnate.pinnae.numberOfPairs.min': 'leafBipinnatePinnaeNumberOfPairsMin',
14
- 'leaf.bipinnate.pinnae.numberOfPairs.max': 'leafBipinnatePinnaeNumberOfPairsMax',
15
- 'leaf.bipinnate.pinnae.numberOfPairs.rarelyMax': 'leafBipinnatePinnaeNumberOfPairsRarelyMax',
16
- 'leaf.bipinnate.pinnae.numberOfPairs.value': 'leafBipinnatePinnaeNumberOfPairsValue',
17
- 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMin': 'leafBipinnatePinnaeLeafletNumberOfPairsRarelyMin',
18
- 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.min': 'leafBipinnatePinnaeLeafletNumberOfPairsMin',
19
- 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.max': 'leafBipinnatePinnaeLeafletNumberOfPairsMax',
20
- 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMax': 'leafBipinnatePinnaeLeafletNumberOfPairsRarelyMax',
21
- 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.value': 'leafBipinnatePinnaeLeafletNumberOfPairsValue',
22
- 'inflorescence.type': 'inflorescenceType',
23
- 'inflorescence.shape': 'inflorescenceShape',
24
- 'flower.merism': 'flowerMerism',
25
- 'flower.numberWhorlsOfStamens': 'numberWhorlsOfStamens',
26
- 'flower.calyx.shape': 'flowerCalyxShape',
27
- 'flower.corolla.shape': 'flowerCorollaShape',
28
- 'androecium.filaments.colour': 'androeciumFilamentsColour',
29
- 'timestamp': 'timestamp'
30
- };
31
- let genusErrorShown = {};
32
- function generateDescription(taxon, genus) {
33
- try {
34
- const template = fs_1.default.readFileSync(`./taxon/${genus}/${genus}_template.txt`, 'utf-8');
35
- const outputDir = 'output/';
36
- const context = {};
37
- for (const column in mapColumns) {
38
- const templateColumn = mapColumns[column];
39
- if (taxon[column]) {
40
- context[templateColumn] = taxon[column];
41
- }
42
- }
43
- if (taxon['inflorescence.capitate'] === 'yes') {
44
- context['capitateInflorescence'] = true;
45
- }
46
- if (taxon['inflorescence.spicate'] === 'yes') {
47
- context['spicateInflorescence'] = true;
48
- }
49
- let sanitizeSpecificEpithet = taxon['specificEpithet'].replace(/\s/g, '_');
50
- sanitizeSpecificEpithet = sanitizeSpecificEpithet.replace(/-(\w)/, function (match, p1) {
51
- return p1.toUpperCase();
52
- });
53
- context['specificEpithet'] = sanitizeSpecificEpithet;
54
- let output = mustache_1.default.render(template, context);
55
- const specificEpithet = taxon['specificEpithet'];
56
- const fileName = `${outputDir}${genus}_${specificEpithet.replace(/\s/g, '_')}.ts`;
57
- // timestamp
58
- output = output.replace('date:', `date: ` + Math.floor(Date.now() / 1000));
59
- output = output
60
- .replace(/'\[/g, '[')
61
- .replace(/\]'/g, ']')
62
- .replace(/'/g, '\'');
63
- if (output.trim() !== '') {
64
- fs_1.default.writeFileSync(fileName, output);
65
- console.log(`\x1b[1m\x1b[32m✔ New script file: \x1b[0m\x1b[1m\x1b[33m./${fileName}\x1b[0m`);
66
- }
67
- }
68
- catch (error) {
69
- if (error.code === 'ENOENT') {
70
- if (genus !== '' && !genusErrorShown[genus]) {
71
- console.error(`\x1b[31m✖ A TTS project for genus \x1b[33m\x1b[3m${genus}\x1b[0m\x1b[31m has not been implemented yet.\x1b[0m`);
72
- console.log('\x1b[36m + ℹ️ To create a new TTS project, visit:\x1b[0m');
73
- console.log('\x1b[33m https://www.npmjs.com/package/typetaxonscript?activeTab=readme#creating-and-editing-a-genus-template.\x1b[0m');
74
- genusErrorShown[genus] = true;
75
- }
76
- }
77
- else {
78
- console.error('An error occurred while reading the file:', error);
79
- }
80
- }
81
- }
82
- function ttsImportFromCsv(genus) {
83
- if (genus === '') {
84
- console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
85
- return;
86
- }
87
- fs_1.default.createReadStream('./input/importTaxa.csv')
88
- .pipe((0, csv_parser_1.default)({ separator: ';' }))
89
- .on('data', (taxon) => {
90
- generateDescription(taxon, genus);
91
- })
92
- .on('end', () => {
93
- if (!genusErrorShown[genus]) {
94
- //console.log('\x1b[1m\x1b[32m✔ Process finished.\x1b[0m')
95
- }
96
- });
97
- }
98
- exports.default = ttsImportFromCsv;
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 csv_parser_1 = __importDefault(require("csv-parser"));
8
+ const mustache_1 = __importDefault(require("mustache"));
9
+ const mapColumns = {
10
+ 'specificEpithet': 'specificEpithet',
11
+ 'descriptionAuthorship': 'descriptionAuthorship',
12
+ 'leaf.bipinnate.pinnae.numberOfPairs.rarelyMin': 'leafBipinnatePinnaeNumberOfPairsRarelyMin',
13
+ 'leaf.bipinnate.pinnae.numberOfPairs.min': 'leafBipinnatePinnaeNumberOfPairsMin',
14
+ 'leaf.bipinnate.pinnae.numberOfPairs.max': 'leafBipinnatePinnaeNumberOfPairsMax',
15
+ 'leaf.bipinnate.pinnae.numberOfPairs.rarelyMax': 'leafBipinnatePinnaeNumberOfPairsRarelyMax',
16
+ 'leaf.bipinnate.pinnae.numberOfPairs.value': 'leafBipinnatePinnaeNumberOfPairsValue',
17
+ 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMin': 'leafBipinnatePinnaeLeafletNumberOfPairsRarelyMin',
18
+ 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.min': 'leafBipinnatePinnaeLeafletNumberOfPairsMin',
19
+ 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.max': 'leafBipinnatePinnaeLeafletNumberOfPairsMax',
20
+ 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMax': 'leafBipinnatePinnaeLeafletNumberOfPairsRarelyMax',
21
+ 'leaf.bipinnate.pinnae.leaflet.numberOfPairs.value': 'leafBipinnatePinnaeLeafletNumberOfPairsValue',
22
+ 'inflorescence.type': 'inflorescenceType',
23
+ 'inflorescence.shape': 'inflorescenceShape',
24
+ 'flower.merism': 'flowerMerism',
25
+ 'flower.numberWhorlsOfStamens': 'numberWhorlsOfStamens',
26
+ 'flower.calyx.shape': 'flowerCalyxShape',
27
+ 'flower.corolla.shape': 'flowerCorollaShape',
28
+ 'androecium.filaments.colour': 'androeciumFilamentsColour',
29
+ 'timestamp': 'timestamp'
30
+ };
31
+ let genusErrorShown = {};
32
+ function generateDescription(taxon, genus) {
33
+ try {
34
+ const template = fs_1.default.readFileSync(`./taxon/${genus}/${genus}_template.txt`, 'utf-8');
35
+ const outputDir = 'output/';
36
+ const context = {};
37
+ for (const column in mapColumns) {
38
+ const templateColumn = mapColumns[column];
39
+ if (taxon[column]) {
40
+ context[templateColumn] = taxon[column];
41
+ }
42
+ }
43
+ if (taxon['inflorescence.capitate'] === 'yes') {
44
+ context['capitateInflorescence'] = true;
45
+ }
46
+ if (taxon['inflorescence.spicate'] === 'yes') {
47
+ context['spicateInflorescence'] = true;
48
+ }
49
+ let sanitizeSpecificEpithet = taxon['specificEpithet'].replace(/\s/g, '_');
50
+ sanitizeSpecificEpithet = sanitizeSpecificEpithet.replace(/-(\w)/, function (match, p1) {
51
+ return p1.toUpperCase();
52
+ });
53
+ context['specificEpithet'] = sanitizeSpecificEpithet;
54
+ let output = mustache_1.default.render(template, context);
55
+ const specificEpithet = taxon['specificEpithet'];
56
+ const fileName = `${outputDir}${genus}_${specificEpithet.replace(/\s/g, '_')}.ts`;
57
+ // timestamp
58
+ output = output.replace('date:', `date: ` + Math.floor(Date.now() / 1000));
59
+ output = output
60
+ .replace(/'\[/g, '[')
61
+ .replace(/\]'/g, ']')
62
+ .replace(/'/g, '\'');
63
+ if (output.trim() !== '') {
64
+ fs_1.default.writeFileSync(fileName, output);
65
+ console.log(`\x1b[1m\x1b[32m✔ New script file: \x1b[0m\x1b[1m\x1b[33m./${fileName}\x1b[0m`);
66
+ }
67
+ }
68
+ catch (error) {
69
+ if (error.code === 'ENOENT') {
70
+ if (genus !== '' && !genusErrorShown[genus]) {
71
+ console.error(`\x1b[31m✖ A TTS project for genus \x1b[33m\x1b[3m${genus}\x1b[0m\x1b[31m has not been implemented yet.\x1b[0m`);
72
+ console.log('\x1b[36m + ℹ️ To create a new TTS project, visit:\x1b[0m');
73
+ console.log('\x1b[33m https://www.npmjs.com/package/typetaxonscript?activeTab=readme#creating-and-editing-a-genus-template.\x1b[0m');
74
+ genusErrorShown[genus] = true;
75
+ }
76
+ }
77
+ else {
78
+ console.error('An error occurred while reading the file:', error);
79
+ }
80
+ }
81
+ }
82
+ function ttsImportFromCsv(genus) {
83
+ if (genus === '') {
84
+ console.error('\x1b[31m✖ Argument `--genus` cannot be empty.\x1b[0m');
85
+ return;
86
+ }
87
+ fs_1.default.createReadStream('./input/importTaxa.csv')
88
+ .pipe((0, csv_parser_1.default)({ separator: ';' }))
89
+ .on('data', (taxon) => {
90
+ generateDescription(taxon, genus);
91
+ })
92
+ .on('end', () => {
93
+ if (!genusErrorShown[genus]) {
94
+ //console.log('\x1b[1m\x1b[32m✔ Process finished.\x1b[0m')
95
+ }
96
+ });
97
+ }
98
+ exports.default = ttsImportFromCsv;
package/dist/init.js CHANGED
@@ -1,35 +1,35 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- const fs = __importStar(require("fs"));
27
- const path = __importStar(require("path"));
28
- function createInputCSVFiles() {
29
- const inputDir = 'input';
30
- if (!fs.existsSync(inputDir)) {
31
- fs.mkdirSync(inputDir);
32
- console.log('\x1b[36mℹ️ The', '\x1b[33m./input', '\x1b[36mdirectory has been created.\x1b[0m');
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const fs = __importStar(require("fs"));
27
+ const path = __importStar(require("path"));
28
+ function createInputCSVFiles() {
29
+ const inputDir = 'input';
30
+ if (!fs.existsSync(inputDir)) {
31
+ fs.mkdirSync(inputDir);
32
+ console.log('\x1b[36mℹ️ The', '\x1b[33m./input', '\x1b[36mdirectory has been created.\x1b[0m');
33
33
  const taxaToExportContent = `Mimosa afranioi
34
34
  Mimosa arenosa var arenosa
35
35
  Mimosa aurivillus var calothamnos
@@ -43,89 +43,89 @@ Mimosa debilis var debilis
43
43
  Mimosa diplotricha var diplotricha
44
44
  Mimosa dolens var dolens
45
45
  Mimosa dryandroides var dryandroides
46
- Mimosa elliptica`;
46
+ Mimosa elliptica`;
47
47
  const importTaxaContent = `"specificEpithet";"leaf.bipinnate.pinnae.numberOfPairs.rarelyMin";"leaf.bipinnate.pinnae.numberOfPairs.min";"leaf.bipinnate.pinnae.numberOfPairs.max";"leaf.bipinnate.pinnae.numberOfPairs.rarelyMax";"leaf.bipinnate.pinnae.numberOfPairs.value";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMin";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.min";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.max";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.rarelyMax";"leaf.bipinnate.pinnae.leaflet.numberOfPairs.value";"inflorescence.spicate";"inflorescence.capitate";"flower.merism";"flower.calyx.shape";"flower.corolla.shape";"flower.numberWhorlsOfStamens";"androecium.filaments.colour";"descriptionAuthorship"
48
48
  "arenosa var arenosa";"";"4";"12";"";"";"";"12";"30";"";"";"yes";"";"['4-merous', '5-merous']";"campanulate";"turbinate";"diplostemonous";"withish";"June Doe"
49
49
  "artemisiana";"";"7";"12";"";"";"";"15";"29";"";"";"yes";"";"4-merous";"campanulate";"campanulate";"diplostemonous";"withish";"June Doe"
50
- "ceratonia var pseudo-obovata";"";"2";"4";"5";"";"";"2";"4";"5";"";"";"yes";"3-merous";"campanulate";"turbinate";"diplostemonous";"withish";"June Doe"`;
51
- const taxaToExportPath = path.join(inputDir, 'taxaToExport.csv');
52
- const importTaxaPath = path.join(inputDir, 'importTaxa.csv');
53
- fs.writeFileSync(taxaToExportPath, taxaToExportContent);
54
- fs.writeFileSync(importTaxaPath, importTaxaContent);
55
- console.log('\x1b[36mℹ️ The', '\x1b[33m./input/importTaxa.csv', '\x1b[36mfile has been created.\x1b[0m');
56
- console.log('\x1b[90m + This file is needed to execute the `import` command.\x1b[0m');
57
- console.log('\x1b[90m + It is a simple headerless CSV with each taxon on a separate line/row.\x1b[0m');
58
- console.log('\x1b[36mℹ️ The', '\x1b[33m./input/taxaToExport.csv', '\x1b[36mfile has been created.\x1b[0m');
59
- console.log('\x1b[90m + This file is needed to execute argument `--load csv` of `export` command.\x1b[0m');
60
- console.log('\x1b[90m + It is used to export a specific list of taxa instead of exporting all, which is the default setting.\x1b[0m');
61
- }
62
- }
63
- function ttsInit() {
64
- // Checking directories
65
- fs.readdir('./', (err, dirs) => {
66
- if (err) {
67
- console.error('Error reading directories:', err);
68
- return;
69
- }
70
- if (dirs.length === 0) {
71
- console.error('\x1b[36mℹ️ The directory is empty. Please clone a TTS project first.\x1b[0m');
72
- console.log('\x1b[36mℹ️ Please, visit:\x1b[0m');
73
- console.log('\x1b[36m TypeTaxonScript package:', '\x1b[33mhttps://www.npmjs.com/package/typetaxonscript.\x1b[0m');
74
- console.log('\x1b[36m TTS project (Mimosa):', '\x1b[33mhttps://github.com/lsbjordao/TTS-Mimosa.\x1b[0m');
75
- return;
76
- }
77
- if (!dirs.includes('taxon') && !dirs.includes('character')) {
78
- console.error('\x1b[36mℹ️ The directory does not contain a TTS project.\x1b[0m');
79
- console.log('\x1b[36mℹ️ Please, visit:\x1b[0m');
80
- console.log('\x1b[36m TypeTaxonScript package:', '\x1b[33mhttps://www.npmjs.com/package/typetaxonscript.\x1b[0m');
81
- console.log('\x1b[36m TTS project (Mimosa):', '\x1b[33mhttps://github.com/lsbjordao/TTS-Mimosa.\x1b[0m');
82
- return;
83
- }
84
- const requiredDirs = ['input', 'output', 'characters', 'taxon'];
85
- const allRequiredDirsPresent = requiredDirs.every(dir => dirs.includes(dir));
86
- if (allRequiredDirsPresent) {
87
- console.error('\x1b[36mℹ️ The root directory is not clean. Look:\x1b[0m');
88
- const listDirectoryTree = (dir, prefix = '') => {
89
- const files = fs.readdirSync(dir);
90
- files.forEach((file, index) => {
91
- const filePath = path.join(dir, file);
92
- const isDirectory = fs.statSync(filePath).isDirectory();
93
- const isLast = index === files.length - 1;
94
- console.log(`${prefix}${isLast ? '└──' : '├──'} ${file}`);
95
- if (isDirectory) {
96
- const nestedPrefix = `${prefix}${isLast ? ' ' : '│ '}`;
97
- listDirectoryTree(filePath, nestedPrefix);
98
- }
99
- });
100
- };
101
- const excludedDirectories = ['node_modules', '.git', 'dist'];
102
- const hasPreviousProject = (dir, prefix = '') => {
103
- const files = fs.readdirSync(dir, { withFileTypes: true });
104
- const directories = files
105
- .filter(dirent => dirent.isDirectory() && !excludedDirectories.includes(dirent.name))
106
- .map(dirent => dirent.name);
107
- directories.forEach((directory, index) => {
108
- const directoryPath = path.join(dir, directory);
109
- const isLast = index === directories.length - 1;
110
- console.log(`${prefix}${isLast ? '└──' : '├──'} ${directory}`);
111
- const nestedPrefix = `${prefix}${isLast ? ' ' : '│ '}`;
112
- hasPreviousProject(directoryPath, nestedPrefix);
113
- });
114
- };
115
- hasPreviousProject('./');
116
- console.error('\x1b[36mℹ️ A previous project is already found.\x1b[0m');
117
- return;
118
- }
119
- else {
120
- createInputCSVFiles();
121
- const outputDir = 'output';
122
- if (!fs.existsSync(outputDir)) {
123
- fs.mkdirSync(outputDir);
124
- const gitKeepFile = `${outputDir}/.gitkeep`;
125
- fs.writeFileSync(gitKeepFile, '');
126
- console.log('\x1b[36mℹ️ The', '\x1b[33m./output', '\x1b[36mdirectory has been created.\x1b[0m');
127
- }
128
- }
129
- });
130
- }
131
- exports.default = ttsInit;
50
+ "ceratonia var pseudo-obovata";"";"2";"4";"5";"";"";"2";"4";"5";"";"";"yes";"3-merous";"campanulate";"turbinate";"diplostemonous";"withish";"June Doe"`;
51
+ const taxaToExportPath = path.join(inputDir, 'taxaToExport.csv');
52
+ const importTaxaPath = path.join(inputDir, 'importTaxa.csv');
53
+ fs.writeFileSync(taxaToExportPath, taxaToExportContent);
54
+ fs.writeFileSync(importTaxaPath, importTaxaContent);
55
+ console.log('\x1b[36mℹ️ The', '\x1b[33m./input/importTaxa.csv', '\x1b[36mfile has been created.\x1b[0m');
56
+ console.log('\x1b[90m + This file is needed to execute the `import` command.\x1b[0m');
57
+ console.log('\x1b[90m + It is a simple headerless CSV with each taxon on a separate line/row.\x1b[0m');
58
+ console.log('\x1b[36mℹ️ The', '\x1b[33m./input/taxaToExport.csv', '\x1b[36mfile has been created.\x1b[0m');
59
+ console.log('\x1b[90m + This file is needed to execute argument `--load csv` of `export` command.\x1b[0m');
60
+ console.log('\x1b[90m + It is used to export a specific list of taxa instead of exporting all, which is the default setting.\x1b[0m');
61
+ }
62
+ }
63
+ function ttsInit() {
64
+ // Checking directories
65
+ fs.readdir('./', (err, dirs) => {
66
+ if (err) {
67
+ console.error('Error reading directories:', err);
68
+ return;
69
+ }
70
+ if (dirs.length === 0) {
71
+ console.error('\x1b[36mℹ️ The directory is empty. Please clone a TTS project first.\x1b[0m');
72
+ console.log('\x1b[36mℹ️ Please, visit:\x1b[0m');
73
+ console.log('\x1b[36m TypeTaxonScript package:', '\x1b[33mhttps://www.npmjs.com/package/typetaxonscript.\x1b[0m');
74
+ console.log('\x1b[36m TTS project (Mimosa):', '\x1b[33mhttps://github.com/lsbjordao/TTS-Mimosa.\x1b[0m');
75
+ return;
76
+ }
77
+ if (!dirs.includes('taxon') && !dirs.includes('character')) {
78
+ console.error('\x1b[36mℹ️ The directory does not contain a TTS project.\x1b[0m');
79
+ console.log('\x1b[36mℹ️ Please, visit:\x1b[0m');
80
+ console.log('\x1b[36m TypeTaxonScript package:', '\x1b[33mhttps://www.npmjs.com/package/typetaxonscript.\x1b[0m');
81
+ console.log('\x1b[36m TTS project (Mimosa):', '\x1b[33mhttps://github.com/lsbjordao/TTS-Mimosa.\x1b[0m');
82
+ return;
83
+ }
84
+ const requiredDirs = ['input', 'output', 'characters', 'taxon'];
85
+ const allRequiredDirsPresent = requiredDirs.every(dir => dirs.includes(dir));
86
+ if (allRequiredDirsPresent) {
87
+ console.error('\x1b[36mℹ️ The root directory is not clean. Look:\x1b[0m');
88
+ const listDirectoryTree = (dir, prefix = '') => {
89
+ const files = fs.readdirSync(dir);
90
+ files.forEach((file, index) => {
91
+ const filePath = path.join(dir, file);
92
+ const isDirectory = fs.statSync(filePath).isDirectory();
93
+ const isLast = index === files.length - 1;
94
+ console.log(`${prefix}${isLast ? '└──' : '├──'} ${file}`);
95
+ if (isDirectory) {
96
+ const nestedPrefix = `${prefix}${isLast ? ' ' : '│ '}`;
97
+ listDirectoryTree(filePath, nestedPrefix);
98
+ }
99
+ });
100
+ };
101
+ const excludedDirectories = ['node_modules', '.git', 'dist'];
102
+ const hasPreviousProject = (dir, prefix = '') => {
103
+ const files = fs.readdirSync(dir, { withFileTypes: true });
104
+ const directories = files
105
+ .filter(dirent => dirent.isDirectory() && !excludedDirectories.includes(dirent.name))
106
+ .map(dirent => dirent.name);
107
+ directories.forEach((directory, index) => {
108
+ const directoryPath = path.join(dir, directory);
109
+ const isLast = index === directories.length - 1;
110
+ console.log(`${prefix}${isLast ? '└──' : '├──'} ${directory}`);
111
+ const nestedPrefix = `${prefix}${isLast ? ' ' : '│ '}`;
112
+ hasPreviousProject(directoryPath, nestedPrefix);
113
+ });
114
+ };
115
+ hasPreviousProject('./');
116
+ console.error('\x1b[36mℹ️ A previous project is already found.\x1b[0m');
117
+ return;
118
+ }
119
+ else {
120
+ createInputCSVFiles();
121
+ const outputDir = 'output';
122
+ if (!fs.existsSync(outputDir)) {
123
+ fs.mkdirSync(outputDir);
124
+ const gitKeepFile = `${outputDir}/.gitkeep`;
125
+ fs.writeFileSync(gitKeepFile, '');
126
+ console.log('\x1b[36mℹ️ The', '\x1b[33m./output', '\x1b[36mdirectory has been created.\x1b[0m');
127
+ }
128
+ }
129
+ });
130
+ }
131
+ exports.default = ttsInit;