@botonic/plugin-contentful
Version:
Botonic Plugin Contentful is one of the **[available](https://github.com/hubtype/botonic/tree/master/packages)** plugins for Botonic. **[Contentful](http://www.contentful.com)** is a CMS (Content Management System) which manages contents of a great variet
33 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const fs = tslib_1.__importStar(require("fs"));
const path_1 = require("path");
const xlsx_1 = require("xlsx");
const nlp_1 = require("../../../nlp");
if (process.argv.length < 4 || process.argv[2] == '--help') {
console.warn(`Usage: xlsName locale [targetPath]`);
// eslint-disable-next-line no-process-exit
process.exit(1);
}
const xslName = process.argv[2];
const locale = process.argv[3];
const csvPath = process.argv.length > 4 ? process.argv[4] : '.';
function getCsvName(csvPath) {
if (csvPath.endsWith('.csv')) {
return csvPath;
}
return (0, path_1.join)(csvPath, `contentful_${(0, nlp_1.fixLocale)(locale)}.csv`);
}
function main() {
const csvName = getCsvName(csvPath);
const workBook = (0, xlsx_1.readFile)(xslName);
const sheetName = workBook.SheetNames[0];
const sheet = workBook.Sheets[sheetName];
const stream = xlsx_1.stream.to_csv(sheet, { FS: ';' });
stream.pipe(fs.createWriteStream(csvName));
console.log(`CSV written to ${csvName}`);
return csvName;
}
void main();
//# sourceMappingURL=xls-to-csv.js.map