### Setting up Commerce Layer CLI and Seeding Data Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/setup/README.md This snippet outlines the steps to install necessary npm packages, log into the Commerce Layer CLI, install seeder and imports plugins, and finally run the seeding process to populate an organization with data. It requires an existing Commerce Layer organization and valid application credentials. ```sh npm install npm install -g @commercelayer/cli commercelayer applications:login \ -i Oy5F2TbPYhOZsxy1tQd9ZVZ... \ -s 1ZHNJUgn_1lh1mel06gGDqa... \ -o my-awesome-organization \ -a admin commercelayer plugins:install seeder commercelayer plugins:install imports npm run seeder:seed # 🚀 ``` -------------------------------- ### Example Output of Transformed Product Data (JSON) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet shows an example of the `products.json` file generated by the conversion script. It illustrates the structure of the `RawDataProduct` array, including fields like `productCode`, `variantCode`, `sku`, `slug`, `name`, `description`, and `images`, ready for use by the Demo Store. ```ts //= output // [ // { // "productCode": "5PANECAP", // "variantCode": "5PANECAP000000", // "sku": "5PANECAP000000FFFFFFXXXX", // "slug": "/black-five-panel-cap-with-white-logo/5PANECAP000000FFFFFFXXXX", // "name": { // "en": "Black Five-Panel Cap with White Logo" // }, // "description": { // "en": "Soft-structured, five-panel, low-profile cap. 100% cotton, metal eyelets, nylon strap clip closure." // }, // "images": [ // "https://data.commercelayer.app/seed/images/skus/5PANECAP000000FFFFFFXXXX_FLAT.png" // ] // }, // { // "productCode": "5PANECAP", // "variantCode": "5PANECAP9D9CA1", // "sku": "5PANECAP9D9CA1FFFFFFXXXX", // "slug": "/gray-five-panel-cap-with-white-logo/5PANECAP9D9CA1FFFFFFXXXX", // "name": { // "en": "Gray Five-Panel Cap with White Logo" // }, // "description": { // "en": "Soft-structured, five-panel, low-profile cap. 100% cotton, metal eyelets, nylon strap clip closure." // }, // "images": [ // "https://data.commercelayer.app/seed/images/skus/5PANECAP9D9CA1FFFFFFXXXX_FLAT.png" // ] // }, // { // "productCode": "APRONXXX", // "variantCode": "APRONXXX000000", // "sku": "APRONXXX000000FFFFFFXXXX", // "slug": "/black-apron-with-white-logo/APRONXXX000000FFFFFFXXXX", // "name": { // "en": "Black Apron with White Logo" // }, // "description": { // "en": "This apron has a neck loop and long ties that are easy to adjust for any size. The two front pockets provide additional space for some much-needed cooking utensils, and together with our embroidered logo give the apron a sleek premium look." // }, // "images": [ // "https://data.commercelayer.app/seed/images/skus/APRONXXX000000FFFFFFXXXX_FLAT.png" // ] // } // ] ``` -------------------------------- ### Setting Up Node.js Project for Product Data Conversion (Shell) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet provides the shell commands to initialize a new Node.js project and install the necessary dependencies. It includes `typescript`, `@types/node`, `tsm` (for TypeScript module support), and `@commercelayer/demo-store-types` which defines the target data structure. ```sh mkdir demo cd demo npm init -y npm install typescript @types/node tsm @commercelayer/demo-store-types ``` -------------------------------- ### Updating Git Submodule and Installing Dependencies (Shell) Source: https://github.com/commercelayer/demo-store-core/blob/main/README.md This shell script updates the `demo-store-core` git submodule to its latest remote version and then installs or updates the project's npm dependencies. This process ensures that users leveraging the `demo-store` GitHub template receive the latest features and bug fixes from the `demo-store-core` repository. ```sh git submodule update --remote npm install ``` -------------------------------- ### Converting External Product Data to Demo Store Format (TypeScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This TypeScript code fetches product data from a mock external API, then maps each remote product to the `RawDataProduct` type. It extracts and transforms fields like `code`, `name`, `description`, and `image_url` to fit the Demo Store's `products.json` schema, finally writing the result to a file. ```ts //= index.ts import type { RawDataProduct } from '@commercelayer/demo-store-types' import { writeFile } from 'fs/promises' (async () => { // this represent a list of products taken from an external source const remoteProducts: any[] = await fetch('https://run.mocky.io/v3/57f0a452-eae1-4f67-8a33-e4119e73c2db') .then(response => response.json()) const demoStoreProducts: RawDataProduct[] = remoteProducts.map( ({ code, name, description, image_url }) => ({ productCode: code.substring(0, 8), variantCode: code.substring(0, 8 + 6), sku: code, slug: `/${name.toLowerCase().replace(/[\W]+/g, '-').replace(/^-|-$/g, '')}/${code}`, name: { en: name.replace(/\s\(.*\)$/, '') }, description: { en: description }, images: [ image_url ] }) satisfies RawDataProduct ) await writeFile('products.json', JSON.stringify(demoStoreProducts, undefined, 2)) console.log(demoStoreProducts) })() ``` -------------------------------- ### Testing Demo Store JSON Data (JavaScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This JavaScript snippet demonstrates how to import and use the `testJsonData` utility from the `@commercelayer/demo-store-types` package. It calls `testJsonData` with the path to the JSON data directory (`./data/json/`) to validate the data structure. ```JavaScript const { testJsonData } = require('@commercelayer/demo-store-types/dist/test') testJsonData('./data/json/') ``` -------------------------------- ### Running the Product Data Conversion Script (Shell) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This shell command executes the TypeScript file (`index.ts`) using Node.js. The `-r tsm` flag enables `tsm` (TypeScript Module) to allow Node.js to directly run TypeScript files without a prior compilation step. ```sh node -r tsm index.ts ``` -------------------------------- ### Executing Demo Store Data Tests (Shell) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This shell command executes the `runTestData.js` script using Node.js. This script, as shown in the previous snippet, is responsible for validating the Demo Store JSON data using the built-in testing utility. ```Shell node runTestData.js ``` -------------------------------- ### Writing Products Data to JSON (TypeScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet illustrates how to write an array of `RawDataProduct` objects to a `products.json` file. It uses `writeFileSync` to serialize the product data, ensuring type adherence with `satisfies`. ```TypeScript writeFileSync( 'products.json', JSON.stringify([{ ... }] satisfies RawDataProduct[]) ) ``` -------------------------------- ### Writing Catalogs Data to JSON (TypeScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet demonstrates how to write an array of `RawDataCatalog` objects to a `catalogs.json` file. It uses `writeFileSync` to serialize the data into a JSON string, ensuring type safety with the `satisfies` operator. ```TypeScript writeFileSync( 'catalogs.json', JSON.stringify([{ ... }] satisfies RawDataCatalog[]) ) ``` -------------------------------- ### Writing Taxonomies Data to JSON (TypeScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet demonstrates how to write an array of `RawDataTaxonomy` objects to a `taxonomies.json` file. `writeFileSync` is used to convert the typed data into a JSON string for storage. ```TypeScript writeFileSync( 'taxonomies.json', JSON.stringify([{ ... }] satisfies RawDataTaxonomy[]) ) ``` -------------------------------- ### Writing Organization Data to JSON (TypeScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet demonstrates how to write a single `RawDataOrganization` object to an `organization.json` file. `writeFileSync` is used to convert the typed object into a JSON string for storage. ```TypeScript writeFileSync( 'organization.json', JSON.stringify({ ... } satisfies RawDataOrganization) ) ``` -------------------------------- ### Writing Languages Data to JSON (TypeScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet illustrates how to write an array of `RawDataLanguage` objects to a `languages.json` file. It leverages `writeFileSync` to serialize the data, ensuring it conforms to the `RawDataLanguage` type. ```TypeScript writeFileSync( 'languages.json', JSON.stringify([{ ... }] satisfies RawDataLanguage[]) ) ``` -------------------------------- ### Writing Pages Data to JSON (TypeScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet shows how to save `RawDataPages` data, which includes nested language-specific content, to a `pages.json` file. `writeFileSync` is employed to serialize the complex object structure into a JSON string. ```TypeScript writeFileSync( 'pages.json', JSON.stringify({ '/': { 'en': { ... } } } satisfies RawDataPages) ) ``` -------------------------------- ### Writing Countries Data to JSON (TypeScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet shows how to save an array of `RawDataCountry` objects into a `countries.json` file. The `writeFileSync` function is used to convert the typed data into a JSON string for persistence. ```TypeScript writeFileSync( 'countries.json', JSON.stringify([{ ... }] satisfies RawDataCountry[]) ) ``` -------------------------------- ### Writing Taxons Data to JSON (TypeScript) Source: https://github.com/commercelayer/demo-store-core/blob/main/packages/types/README.md This snippet shows how to save an array of `RawDataTaxon` objects into a `taxons.json` file. The `writeFileSync` function is used to serialize the typed data into a JSON string. ```TypeScript writeFileSync( 'taxons.json', JSON.stringify([{ ... }] satisfies RawDataTaxon[]) ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.