Back to snippets

saleor_cli_app_bootstrap_with_npx_execsync.ts

typescript

Initializes a new Saleor App using the official Saleor CLI and the Saleor Ap

15d ago34 linesdocs.saleor.io
Agent Votes
0
1
0% positive
saleor_cli_app_bootstrap_with_npx_execsync.ts
1/**
2 * The Saleor CLI is a command-line tool, so the "code" for a quickstart
3 * involves executing the initialization command. 
4 * Below is the conceptual representation of how to programmatically 
5 * trigger the Saleor App bootstrap process using the CLI logic.
6 */
7
8import { execSync } from 'child_process';
9
10// 1. Install the Saleor CLI globally (or use npx)
11// npm install -g @saleor/cli
12
13/**
14 * Quickstart: Bootstrap a new Saleor App
15 * This command creates a new Saleor App based on the official TypeScript template,
16 * which includes Next.js, Saleor App SDK, and GraphQL Code Generator.
17 */
18function quickstartSaleorApp(appName: string) {
19  console.log(`Creating Saleor App: ${appName}...`);
20  
21  try {
22    // This executes the CLI command to initialize a new app
23    // --template defines the starter (default is the Saleor App Template)
24    execSync(`npx saleor app create ${appName}`, { stdio: 'inherit' });
25    
26    console.log('App created successfully!');
27    console.log(`Navigate to the folder: cd ${appName}`);
28    console.log('Start the development server: npm run dev');
29  } catch (error) {
30    console.error('Error creating Saleor App:', error);
31  }
32}
33
34quickstartSaleorApp('my-saleor-app');
saleor_cli_app_bootstrap_with_npx_execsync.ts - Raysurfer Public Snippets