npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

sphere-product-type-export

v1.0.0

Published

Exports product types from the commercetools platform.

Downloads

40

Readme

commercetools logo

sphere-product-type-export

Travis Codecov npm semantic-release Commitizen friendly NPM version

A library that helps with exporting product-types from the Commercetools Platform. This library is built to be used in conjunction with sphere-node-cli.

Features

  • Export product types from your CTP project
  • Creates 2 files - product type / attributes matrix and attributes list - that can be used to reimport product types

Configuration

The configuration object may contain:

  • config: configuration object that may contain the following options
    • delimiter: the delimiter to be used in the csv (default: ,)
    • outputFolder (required): the folder used to store the exported product types and attributes
    • exportFormat (optional): output format, supported are csv, xlsx (default: csv)
    • encoding (optional): encoding used when saving data, supported encodings are listed here (default: utf8)
    • where (optional): where predicate used to filter exported productTypes. More info here
    • includeProductTypeInAttributes (optional): flag to be used when all the attibutes need to be exported
  • sphereClientConfig: see the sphere-node-sdk docs for more information on this

Usage

This module can be used as a command line tool as well as a node.js module.

CLI

Before using this module in the command line, install it with a global flag.

npm install sphere-product-type-export -g

Command

Command accepts following arguments:

  • The --projectKey or -p parameter is required and contains a project key which should be used when exporting productTypes.
  • The --outputFolder or -o parameter is required and contains a path to an output folder where the output will be saved.
  • The --accessToken or -t parameter tells module if it should use access token instead of clientId and clientSecret.
  • The --sphereHost parameter tells module whether to use a different API URL.
  • The --sphereProtocol parameter tells module whether to use a different protocol.
  • The --where or -w parameter can be used for filtering productTypes before exporting.
  • The --exportFormat parameter specifies in which format (CSV or XLSX) shoud it save exported productTypes (default is CSV).
  • The --delimiter or -d parameter specifies what delimiter should be used when exporting to CSV (default is ',').
  • The --compressOutput or -c parameter specifies whether to archive export files after export is done (default is false).
  • The --encoding parameter specifies in which encoding should be exported CSV files (default is utf8).
  • The includeProductTypeInAttributes flag to be used when all the attibutes need to be exported.

To export all productTypes in the CSV format we can run this command:

product-type-export -p project-key -o tmp

Output

Export successful!
{
  "errors": [],
  "exported": {
    "productTypes": 3,
    "attributes": 18
  }
}

In the tmp folder there will be created two files attributes.csv and products-to-attributes.csv which describe exported productTypes.

JS

If you want more control, you can also use this library directly in JavaScript. To do this you first need to install it:

npm install sphere-product-type-export --save

Then you can use it to export product types like so:

export ProductTypeExport from 'sphere-product-type-export'

const config = {
  sphereClientConfig: {
    config: {
      project_key: <PROJECT_KEY>,
      client_id: '*********',
      client_secret: '*********'
    }
  },
  config: {
    outputFolder: '',
    delimiter: '',       // default: ,
    compressOutput: '',  // default: false
    exportFormat: '',    // default: csv
    encoding: '',        // default: utf8
    where: '',           // default: ''
  }
}
const productTypeExport = ProductTypeExport(config)

productTypeExport.run()
.then(() => {
  // done exporting the productType
  // look at the summary to see errors
  productTypeExport.summary
  // the summary hast the following structure
  // {
  //   errors: [],
  //   exported: [<some-name>],
  //   successfulExports: 1
  // }
})

Contributing

See CONTRIBUTING.md file for info on how to contribute to this library