How to use @commercetools/product-json-to-csv - 5 common examples

To help you get started, we’ve selected a few @commercetools/product-json-to-csv examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github commercetools / nodejs / packages / product-json-to-xlsx / src / writer.js View on Github external
export function finishWorksheetsAndArchive(
  exports: Array,
  dir: string,
  output: stream$Writable,
  logger: Object
) {
  if (exports.length === 0) return archiveDir(dir, output, logger)

  const writeStreams: Array = exports.map(
    exportInfo => exportInfo.excel.stream
  )
  onStreamsFinished(writeStreams, err => {
    if (err) {
      logger.error(err)
      output.emit('error', err)
    } else {
      archiveDir(dir, output, logger)
      logger.info('All products have been written to ZIP file')
    }
  })

  // close all excel workbooks
  return exports
github commercetools / nodejs / packages / product-json-to-xlsx / src / writer.js View on Github external
export function finishWorksheetsAndArchive(
  exports: Array,
  dir: string,
  output: stream$Writable,
  logger: Object
) {
  if (exports.length === 0) return archiveDir(dir, output, logger)

  const writeStreams: Array = exports.map(
    exportInfo => exportInfo.excel.stream
  )
  onStreamsFinished(writeStreams, err => {
    if (err) {
      logger.error(err)
      output.emit('error', err)
    } else {
      archiveDir(dir, output, logger)
      logger.info('All products have been written to ZIP file')
    }
  })

  // close all excel workbooks
  return exports
    .map((exportInfo: Object): Object => exportInfo.excel)
    .forEach((excel: Object) => excel.finish())
}
github commercetools / nodejs / packages / product-json-to-xlsx / src / writer.js View on Github external
.each((product: Object): void => {
      // check what productType are we exporting
      if (product.productType && product.productType !== lastProductType) {
        lastProductType = product.productType
        lastExport = exportByProductType[lastProductType]

        // if we haven't started exporting this productType yet
        if (!lastExport) {
          // generate a temp file name
          const fileName: string = `${slugify(product.productType)}.xlsx`
          const filePath: string = path.join(tmpDir, fileName)

          // create headers and file stream
          lastExport = {
            productType: lastProductType,
            headers: mapHeaders(Object.keys(product)),
            excel: new ProductExcel(fs.createWriteStream(filePath)),
          }

          // write a header row to XLSX file
          const headerNames: Array = lastExport.headers.map(
            header => header.label
          )
          lastExport.excel.writeHeader(headerNames)

          // register new export in cache
          exportByProductType[lastProductType] = lastExport
        }
      }

      // we have lastExport variable containing all necessary info
      lastExport.excel.writeRow(mapValues(lastExport.headers, product))
github commercetools / nodejs / packages / product-json-to-xlsx / src / writer.js View on Github external
export function writeToSingleXlsxFile(
  productStream: highlandStream,
  output: stream$Writable,
  logger: Object,
  headers: Array
) {
  const mappedHeaders = mapHeaders(headers)
  const headerNames = mappedHeaders.map(header => header.label)

  const excel = new ProductExcel(output)
  excel.writeHeader(headerNames)

  productStream
    .each(product => {
      const row = mapValues(mappedHeaders, product)
      if (row.join('')) excel.writeRow(row)
    })
    .done(() => {
      // finish workbook and close the stream
      excel.finish()
      logger.info('All products have been written to XLSX file')
    })
}
github commercetools / nodejs / packages / product-json-to-xlsx / src / writer.js View on Github external
onStreamsFinished(writeStreams, err => {
    if (err) {
      logger.error(err)
      output.emit('error', err)
    } else {
      archiveDir(dir, output, logger)
      logger.info('All products have been written to ZIP file')
    }
  })

@commercetools/product-json-to-csv

Converts commercetools products from JSON to CSV

MIT
Latest version published 2 years ago

Package Health Score

55 / 100
Full package analysis