populate
populate
Populates the Vendure server with some initial data and (optionally) product data from a supplied CSV file. The format of the CSV file is described in the section Importing Product Data.
If the channelOrToken
argument is provided, all ChannelAware entities (Products, ProductVariants,
Assets, ShippingMethods, PaymentMethods etc.) will be assigned to the specified Channel.
The argument can be either a Channel object or a valid channel token
.
Internally the populate()
function does the following:
- Uses the Populator to populate the InitialData.
- If
productsCsvPath
is provided, uses Importer to populate Product data. - Uses {@Populator} to populate collections specified in the InitialData.
Example
import { bootstrap } from '@vendure/core';
import { populate } from '@vendure/core/cli';
import { config } from './vendure-config.ts'
import { initialData } from './my-initial-data.ts';
const productsCsvFile = path.join(__dirname, 'path/to/products.csv')
populate(
() => bootstrap(config),
initialData,
productsCsvFile,
)
.then(app => app.close())
.then(
() => process.exit(0),
err => {
console.log(err);
process.exit(1);
},
);
Signature
function populate<T extends INestApplicationContext>(bootstrapFn: () => Promise<T | undefined>, initialDataPathOrObject: string | object, productsCsvPath?: string, channelOrToken?: string | import('@vendure/core').Channel): Promise<T>
Parameters
bootstrapFn
parameter
type:
() => Promise<T | undefined>
initialDataPathOrObject
parameter
type:
string | object
productsCsvPath
parameter
type:
string
channelOrToken
parameter
type:
string | import('@vendure/core').Channel