diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..172351b --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,7 @@ +Copyright 2023-present, Weaverse JSC. + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index ce3b611..8406755 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,29 @@ -# Pilot 👨🏻‍✈️ - Weaverse's Hydrogen-driven Shopify Theme +

Pilot - Shopify Hydrogen Theme

-Pilot is an innovative Shopify theme, powered by Hydrogen, Remix, and Weaverse, designed to create lightning-fast storefronts with exceptional performance. This theme combines a collection of powerful tools and features to streamline your Shopify development experience. +
+

+ Version + + License: MIT + + + Twitter: weaverseio + +

+ +![Weaverse + Hydrogen + Shopify](https://cdn.shopify.com/s/files/1/0693/8201/3220/files/Logos.png?v=1695811776) + +📚 [Read the docs](https://weaverse.io/docs) | 🗣 [Join our community on Slack](https://join.slack.com/t/weaversecommunity/shared_invite/zt-235bv7d80-velzJU8CpZIHWdrzFwAdXg) | 🐞 [Report a bug](https://github.com/weaverse/pilot/issues) + +
+ +_Pilot is an innovative Shopify theme, powered by Hydrogen, Remix, and Weaverse, designed to create lightning-fast storefronts with exceptional performance. This theme combines a collection of powerful tools and features to streamline your Shopify development experience._ + +### Demo + +- [Live store](https://pilot.weaverse.dev) +- Try customizing Pilot on [Weaverse Playground](https://playground.weaverse.io) + ![demo](https://cdn.shopify.com/s/files/1/0693/8201/3220/files/Home.png?v=1695816170) ### What's included @@ -14,21 +37,251 @@ Pilot is an innovative Shopify theme, powered by Hydrogen, Remix, and Weaverse, - TypeScript and JavaScript flavors - Tailwind CSS (via PostCSS) - Full-featured setup of components and routes -- Easy to edit and customize with **Weaverse Hydrogen Editor** +- Fully customizable inside [Weaverse](https://weaverse.io) ### Getting started Follow these steps to get started with Pilot and begin crafting your Hydrogen-driven storefront: -1. Install [Weaverse Shopify App](https://apps.shopify.com/weaverse) from Shopify App Store. +1. Install [Weaverse Hydrogen Customizer](https://apps.shopify.com/weaverse) from Shopify App Store. 2. Create new Hydrogen storefront inside Weaverse. -3. Clone the repository that Weaverse has created for you. -4. Set environment variables in `.env` file then start the development server with `npm i && npm run dev`. -5. Open the Weaverse editor to start customizing and tailoring your storefront according to your preferences. +3. Initialize the project and start a local dev server with our CLI tool as instructed in the Weaverse editor. + ![Init Weaverse Storefront](https://cdn.shopify.com/s/files/1/0693/8201/3220/files/init-project_4882deaa-c661-47cc-a7bf-38b2704e6a0b.png?v=1695816089) +4. Open the Weaverse editor to start customizing and tailoring your storefront according to your preferences. + +### Features overview + +#### Fetching page data inside route's loader + +Fetching page data inside route's loader is a common pattern in Hydrogen. Weaverse provides a convenient way to do that by using `context.weaverse.loadPage` function. It accepts `RouteLoaderArgs` as an argument and returns a promise with the page data. + +```ts:routes/($locale)/_index.tsx +import {defer} from '@shopify/remix-oxygen'; +import {type RouteLoaderArgs} from '@weaverse/hydrogen'; + +export async function loader(args: RouteLoaderArgs) { + let {params, context} = args; + + return defer({ + weaverseData: await context.weaverse.loadPage(args), + // Other data... + }); +} +``` + +`weaverse` is an `WeaverseClient` instance that has been injected into the app context by Weaverse. It provides a set of methods to interact with the Weaverse API. + +```ts:server.ts +let handleRequest = createRequestHandler({ + build: remixBuild, + mode: process.env.NODE_ENV, + getLoadContext: () => ({ + // App context props + weaverse: createWeaverseClient({ + storefront, + request, + env, + cache, + waitUntil, + }), + }), +}); +``` + +#### Rendering page content + +Weaverse pages is rendered using `` component. + +```tsx:app/weaverse/index.tsx +import {WeaverseHydrogenRoot} from '@weaverse/hydrogen'; +import {GenericError} from '~/components/GenericError'; +import {components} from './components'; + +export function WeaverseContent() { + return ( + + ); +} + +``` + +And in your route: + +```tsx:routes/($locale)/_index.tsx +export default function Homepage() { + return ; +} +``` + +Dead simple, right? + +#### Global theme settings + +Weaverse global theme settings is loaded in the `root`'s loader with `context.weaverse.loadThemeSettings` function. + +```tsx:root.tsx +export async function loader({request, context}: RouteLoaderArgs) { + return defer({ + // App data... + weaverseTheme: await context.weaverse.loadThemeSettings(), + }); +} +``` + +And then you can use it in your components with `useThemeSettings` hook. + +```tsx:app/weaverse/components/Logo.tsx +import {useThemeSettings} from '@weaverse/hydrogen'; + +function Logo() { + let {logo} = useThemeSettings(); + + return ( +
+ Logo +
+ ); +} +``` + +The `App` component is wrapped with `withWeaverse` HoC in order to SSR the theme settings. + +```tsx:root.text +import {withWeaverse} from '@weaverse/hydrogen'; + +function App() { + return ( + + // App markup + + ); +} + +export default withWeaverse(App); +``` + +#### Create a section + +To create a section, you need to create a new file in `app/weaverse/sections` directory and register it in `app/weaverse/sections/index.ts` file. + +```tsx:app/weaverse/sections/Video.tsx +import type { + HydrogenComponentProps, + HydrogenComponentSchema, +} from '@weaverse/hydrogen'; +import {forwardRef} from 'react'; + +interface VideoProps extends HydrogenComponentProps { + heading: string; + description: string; + videoUrl: string; +} + +let Video = forwardRef((props, ref) => { + let {heading, description, videoUrl, ...rest} = props; + return ( +
+
+

+ {heading} +

+

+ {description} +

+