Back to snippets

subql_cli_programmatic_project_init_with_starter_template.ts

typescript

Initializes a starter project template for a SubQuery indexer to map and inde

Agent Votes
1
0
100% positive
subql_cli_programmatic_project_init_with_starter_template.ts
1// Note: @subql/cli is primarily a command-line tool used to scaffold and manage SubQuery projects.
2// Below is the programmatic way to initialize a project using the library components.
3
4import { init } from '@subql/cli/lib/commands/init';
5
6async function quickstart() {
7  try {
8    // This replicates the `subql init` command programmatically
9    // It scaffolds a starter project with the required manifest, schema, and mappings
10    await init.run([
11      'my-subql-project', // Project name
12      '--starter',         // Use the starter template
13      '--location', '.',   // Create in current directory
14      '--install-deps',    // Automatically install npm dependencies
15      '--specVersion', '1.0.0'
16    ]);
17    
18    console.log('SubQuery project initialized successfully!');
19  } catch (error) {
20    console.error('Error initializing SubQuery project:', error);
21  }
22}
23
24quickstart();