### Creating a New Granite Project
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
Initializes a new Granite application using the specified package manager. This command starts an interactive CLI to guide you through project setup, including naming and selecting development tools.
```sh
npx create-granite-app@latest
```
```sh
pnpm create granite-app
```
```sh
yarn create granite-app
```
--------------------------------
### Starting the Granite Development Server
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
Launches the Granite development server, which compiles and serves the microservice application. This server enables hot reloading and provides a local environment for testing and development.
```sh
npm run dev
```
```sh
pnpm run dev
```
```sh
yarn dev
```
--------------------------------
### Granite Project Directory Structure Overview
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
Illustrates the standard directory and file structure of a newly created Granite project, highlighting key folders like `pages/` for screens and `src/` for source code, along with configuration files.
```text
my-granite-app/
├── pages/ # Screens in your microservices
│ ├── _404.tsx # 404 error page
│ └── index.tsx # Home screen
│
├── src/ # Source code
│ ├── _app.tsx # Microservice entry point
│ └── router.gen.ts # Auto-generated type-safe routing
│
├── granite.config.ts # Granite configuration
├── react-native.config.js # React Native settings
└── require.context.ts # Auto-generated routing context
```
--------------------------------
### Navigating to the Project Directory
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
Changes the current directory to the newly created Granite project folder, which is a prerequisite for installing dependencies and running development commands.
```sh
cd my-granite-app
```
--------------------------------
### Granite Development Server Welcome Output
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
Displays the console output upon successful startup of the Granite development server, including the Granite ASCII art logo and a list of common development commands for interacting with the running application.
```text
██████╗ ██████╗ █████╗ ███╗ ██╗██╗████████╗███████╗
██╔════╝ ██╔══██╗██╔══██╗████╗ ██║██║╚══██╔══╝██╔════╝
██║ ███╗██████╔╝███████║██╔██╗ ██║██║ ██║ █████╗
██║ ██║██╔══██╗██╔══██║██║╚██╗██║██║ ██║ ██╔══╝
╚██████╔╝██║ ██║██║ ██║██║ ╚████║██║ ██║ ███████╗
╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═╝╚═╝ ╚═══╝╚═╝ ╚═╝ ╚══════╝
Welcome to Granite
To reload the app press "r"
To open developer menu press "d"
To open debugger press "j"
```
--------------------------------
### Installing Project Dependencies
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
Installs all required Node.js dependencies for the Granite project using the chosen package manager (npm, pnpm, or yarn). This step is crucial for the application to function correctly.
```sh
npm install
```
```sh
pnpm install
```
```sh
yarn install
```
--------------------------------
### Interactive CLI Output for Granite Project Creation
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
Demonstrates the interactive command-line interface output when creating a new Granite project, showing prompts for project name, development tools, and the next steps to set up and run the application.
```sh
$ npx create-granite-app@latest
┌ Create Granite App Project
│
◆ Project Setup
◇ Project name or path:
│ my-granite-app
│
◇ Select development tools:
│ ◻ ESLint + Prettier (recommended)
│ ◻ Biome
│
◇ ✅ Created Granite App successfully!
│
◇ Next steps ─────────────╮
│ │
│ cd my-granite-app │
│ npm install │
│ npm run dev │
│ │
├──────────────────────────╯
│
└ 🎉 Done! Your Granite app is ready.
```
--------------------------------
### Building Production Bundles for Granite App (Shell)
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
These commands show how to build optimized production bundles for a Granite application using different package managers. Running these commands generates microservice bundles in the `dist/` directory, ready for deployment.
```sh
npm run build
```
```sh
pnpm run build
```
```sh
yarn build
```
--------------------------------
### Installing and Configuring AWS CLI
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Installs the AWS Command Line Interface (CLI) and then prompts the user to configure their AWS access key ID, secret access key, default region, and output format. This setup allows Pulumi to authenticate and interact with your AWS account.
```bash
# Install AWS CLI
# macOS: brew install awscli
# Windows: winget install Amazon.AWSCLI
# Linux: apt install awscli
# Configure your credentials
aws configure
```
--------------------------------
### Example URL Scheme with Specific Parameters
Source: https://github.com/toss/granite/blob/main/docs/guides/granite-router/params.md
Provides a concrete example of launching an application named `test-app` via a URL scheme, passing `name` as 'tom' and `age` as '10' as query parameters.
```URL Scheme
granite://test-app?name=tom&age=10
```
--------------------------------
### Granite Forge Deployment Output Example
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/deploy-your-app.md
This snippet shows an example of the console output during a successful deployment using the Granite Forge CLI. It illustrates the steps involved, from fetching deployment state to bundle upload and final success confirmation.
```sh
$ npx granite-forge deploy --bucket {Your bucket name}
┌ Start deployment
│
◇ Successfully fetched current deployment state
│
▲ No deployment state found
│
◇ Are you sure you want to deploy test-granite-app?
│ Yes
│
◇ Bundle uploaded
│
◇ Bundle list updated
│
◇ Deployed successfully! (Deployment ID: **********************)
│
└ Done
```
--------------------------------
### Creating a New Profile Screen Component (React Native)
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
Defines a new React Native functional component for a 'Profile Screen' within the `pages/` directory. This component renders a simple view with text, demonstrating how to add new screens to a Granite microservice. It requires `react` and `react-native` dependencies.
```tsx
import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
export default function ProfileScreen() {
return (
Profile Screen
This is your profile microservice!
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f5f5f5',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 16,
},
description: {
fontSize: 16,
textAlign: 'center',
color: '#666',
},
});
```
--------------------------------
### Basic Granite Service Configuration Example - TypeScript
Source: https://github.com/toss/granite/blob/main/docs/ko/reference/react-native/config/defineConfig.md
This example demonstrates a fundamental `granite.config.ts` setup. It configures the application name as 'my-app', sets the deep link URL scheme to 'granite', specifies 'index.ts' as the entry point, and integrates the Hermes plugin for JavaScript bundle optimization.
```typescript
import { defineConfig } from '@granite-js/react-native/config';
import { hermes } from '@granite-js/plugin-hermes';
export default defineConfig({
// 마이크로서비스의 이름
appName: 'my-app',
// 딥링크를 위한 URL 스킴
scheme: 'granite',
// 진입점 파일 경로
entryFile: 'index.ts',
// 사용할 플러그인 배열
plugins: [hermes()],
});
```
--------------------------------
### Installing Pulumi CLI on Windows
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Installs the Pulumi command-line interface on Windows using winget. Pulumi is a tool for infrastructure as code, enabling you to define and deploy cloud resources using programming languages.
```sh
winget install pulumi
```
--------------------------------
### Pulumi Project Initialization Prompt Example
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Shows the interactive prompts during Pulumi project initialization, including setting the project name, description, stack name, preferred package manager, and the target AWS region for deployment.
```bash
This command will walk you through creating a new Pulumi project.
Enter a value or leave blank to accept the (default), and press .
Press ^C at any time to quit.
Project name: my-granite-infrastructure
Project description: Granite app CDN infrastructure
Created project 'my-granite-infrastructure'
stack name: dev
Created stack 'dev'
The package manager to use for installing dependencies: {Your package manager}
The AWS region to deploy into (aws:region): {Your AWS region}
Saved config
```
--------------------------------
### Implementing Screen Navigation with Granite Router (TypeScript)
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/create-your-app.md
This snippet demonstrates how to add navigation between screens in a React Native application using the `@granite/router` library. It defines a `HomeScreen` component with a `TouchableOpacity` that navigates to a '/profile' route when pressed. It also includes basic styling for the component.
```tsx
import React from 'react';
import { View, Text, TouchableOpacity, StyleSheet } from 'react-native';
import { useRouter } from '@granite/router';
export default function HomeScreen() {
const router = useRouter();
return (
Welcome to Granite! router.push('/profile')}
>
Go to Profile
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#fff',
},
title: {
fontSize: 24,
fontWeight: 'bold',
marginBottom: 32,
},
button: {
backgroundColor: '#007AFF',
paddingHorizontal: 24,
paddingVertical: 12,
borderRadius: 8,
},
buttonText: {
color: 'white',
fontSize: 16,
fontWeight: '600',
},
});
```
--------------------------------
### Installing Granite Forge CLI
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/deploy-your-app.md
This command installs the Granite Forge CLI as a development dependency. This tool is essential for deploying Granite application bundles to AWS.
```sh
npm install @granite-js/forge-cli --save-dev
```
```sh
pnpm add @granite-js/forge-cli --save-dev
```
```sh
yarn add @granite-js/forge-cli --dev
```
--------------------------------
### Installing Pulumi CLI on Linux
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Installs the Pulumi command-line interface on Linux by downloading and executing a script. Pulumi is a tool for infrastructure as code, enabling you to define and deploy cloud resources using programming languages.
```sh
curl -fsSL https://get.pulumi.com | sh
```
--------------------------------
### Installing Granite Router Plugin
Source: https://github.com/toss/granite/blob/main/docs/guides/granite-router/plugin-router.md
These commands demonstrate how to install the @granite-js/plugin-router package as a development dependency using npm, pnpm, or yarn. This plugin is essential for enabling file-based routing in a Granite project.
```Shell
$ npm install @granite-js/plugin-router --save-dev
```
```Shell
$ pnpm install @granite-js/plugin-router --save-dev
```
```Shell
$ yarn add @granite-js/plugin-router --dev
```
--------------------------------
### Installing Hermes Plugin for Granite
Source: https://github.com/toss/granite/blob/main/packages/plugin-hermes/README.md
Provides instructions for installing the `@granite-js/plugin-hermes` using popular Node.js package managers: npm, pnpm, and yarn. These commands add the plugin as a dependency to your project.
```bash
# NPM
npm install @granite-js/plugin-hermes
# pnpm
pnpm install @granite-js/plugin-hermes
# yarn
yarn add @granite-js/plugin-hermes
```
--------------------------------
### Installing Granite Android App using ADB Command (Bash)
Source: https://github.com/toss/granite/blob/main/docs/guides/miscellaneous/install-native-app.md
This command installs the Granite Android application package (APK) onto a connected Android device or emulator using the Android Debug Bridge (ADB). It requires ADB to be installed and configured on the computer, typically provided with Android Studio. The command takes the path to the APK file as an argument, facilitating direct installation from the command line.
```bash
adb install granite_android.zip
```
--------------------------------
### Installing Pulumi CLI on macOS
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Installs the Pulumi command-line interface on macOS using Homebrew. Pulumi is a tool for infrastructure as code, enabling you to define and deploy cloud resources using programming languages.
```sh
brew install pulumi
```
--------------------------------
### Installing Granite Infrastructure Package with npm
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Installs the `@granite-js/pulumi-aws` package as a development dependency using npm. This package provides pre-built Pulumi components specifically designed for creating Granite CDN infrastructure.
```sh
npm install @granite-js/pulumi-aws --save-dev
```
--------------------------------
### Basic Granite Application Configuration with Hermes Plugin
Source: https://github.com/toss/granite/blob/main/docs/reference/react-native/config/defineConfig.md
This example demonstrates a basic `defineConfig` setup for a Granite application. It sets the app name to 'my-app', defines the URL scheme as 'granite', specifies 'index.ts' as the entry file, and integrates the Hermes plugin for JavaScript bundle optimization. This configuration makes the app accessible via `granite://my-app`.
```typescript
import { defineConfig } from '@granite-js/react-native/config';
import { hermes } from '@granite-js/plugin-hermes';
export default defineConfig({
// The name of your microservice
appName: 'my-app',
// The URL scheme for deep linking
scheme: 'granite',
// Entry file path
entryFile: 'index.ts',
// Array of plugins to use
plugins: [hermes()],
});
```
--------------------------------
### Installing @granite-js/pulumi-aws Package
Source: https://github.com/toss/granite/blob/main/infra/pulumi-aws/README.md
These commands install the `@granite-js/pulumi-aws` package and its dependencies using npm, yarn, or pnpm. This package provides the `ReactNativeBundleCDN` component for managing React Native CDN infrastructure on AWS.
```bash
npm install @granite-js/pulumi-aws
# or
yarn add @granite-js/pulumi-aws
# or
pnpm add @granite-js/pulumi-aws
```
--------------------------------
### AWS CLI Configuration Prompt Example
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Illustrates the interactive prompts for configuring AWS credentials using `aws configure`, showing where to input the access key ID, secret access key, default region, and desired output format (e.g., json).
```bash
AWS Access Key ID: [Your access key]
AWS Secret Access Key: [Your secret key]
Default region: [Your region]
Default output format: json
```
--------------------------------
### Installing Granite Infrastructure Package with yarn
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Installs the `@granite-js/pulumi-aws` package as a development dependency using yarn. This package provides pre-built Pulumi components specifically designed for creating Granite CDN infrastructure.
```sh
yarn add @granite-js/pulumi-aws --dev
```
--------------------------------
### Example Application Registration with Granite.registerApp - TSX
Source: https://github.com/toss/granite/blob/main/docs/reference/react-native/core/Granite.md
This TSX example demonstrates how to register a React Native application using `Granite.registerApp`. It shows importing necessary modules, defining a basic `AppContainer` component, and then passing it along with `appName` and `context` to `Granite.registerApp` to enable features like file-based routing and query parameter handling.
```TSX
import { PropsWithChildren } from 'react';
import { Granite, InitialProps } from '@granite-js/react-native';
import { context } from '../require.context';
function AppContainer({ children }: PropsWithChildren) {
return <>{children}>;
}
export default Granite.registerApp(AppContainer, {
appName: 'my-app',
context,
});
```
--------------------------------
### Creating a Basic Layout File (TypeScript)
Source: https://github.com/toss/granite/blob/main/docs/guides/granite-router/layouts.md
This snippet demonstrates the fundamental structure of a `_layout.tsx` file. It defines a simple React component that accepts `children` as props and renders them, serving as a placeholder for content that will be wrapped by the layout. This basic setup is the foundation for all layouts.
```tsx
import { PropsWithChildren } from 'react';
export default function Layout({ children }: PropsWithChildren) {
return <>{children}>;
}
```
--------------------------------
### Installing Granite Infrastructure Package with pnpm
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Installs the `@granite-js/pulumi-aws` package as a development dependency using pnpm. This package provides pre-built Pulumi components specifically designed for creating Granite CDN infrastructure.
```sh
pnpm add @granite-js/pulumi-aws --save-dev
```
--------------------------------
### Deploying AWS Infrastructure with Pulumi using Yarn PnP
Source: https://github.com/toss/granite/blob/main/docs/guides/quick-start/setup-aws.md
Installs the `pnpify` package for Yarn Plug'n'Play and then runs the Pulumi deployment command using `pnpify`. This is required when using Yarn PnP to ensure Pulumi commands execute correctly within the PnP environment.
```bash
yarn add @yarnpkg/pnpify -D
yarn pnpify pulumi up
```
--------------------------------
### Example HTML Body Element (HTML)
Source: https://github.com/toss/granite/blob/main/packages/devtools-frontend/src/front_end/ui/components/docs/elements_breadcrumbs/basic.html
Represents the basic HTML 'body' tag, which would typically contain the main content of a web page and serve as a root for other elements.
```HTML
body
```
--------------------------------
### Example Usage of useWaitForReturnNavigator in React Native
Source: https://github.com/toss/granite/blob/main/docs/reference/react-native/screen-control/useWaitForReturnNavigator.md
This example demonstrates how to use `useWaitForReturnNavigator` within a React Native component. It shows how to navigate to another screen and execute code (e.g., logging) synchronously upon returning to the original screen, ensuring actions are performed post-navigation return.
```TSX
import { Button } from 'react-native';
import { useWaitForReturnNavigator } from '@granite-js/react-native';
export function UseWaitForReturnNavigator() {
const navigate = useWaitForReturnNavigator();
return (
<>