Skip to content

Commit

Permalink
Add logic for copying template routes
Browse files Browse the repository at this point in the history
  • Loading branch information
blittle committed Nov 28, 2022
1 parent a3485af commit 508f29d
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 20 deletions.
9 changes: 6 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 25 additions & 17 deletions packages/hydrogen-remix/src/routing/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,8 @@ export async function hydrogenRoutes(
await buildLangRoutes();
}

const templatesPath = path.resolve(__dirname, '../../templates');
await copyTemplates();

// fs.copyFileSync(templatesPath)

// const templates = await readDir(templatesPath);

// for (const template of templates) {
// console.log(template);
// }

// @todo - extract into packaged helper function
// @todo - add logic for i18n
// const appRoutesPath = path.resolve(
// '../../templates/demo-store',
// 'app/routes',
// );
// @todo - generalize from `path.cwd()`
// const appRouteFiles = await readDir(appRoutesPath);
const hydrogenRoutesPath = path.resolve(process.cwd(), '.hydrogen/routes');
const hydrogenRouteFiles = await readDir(hydrogenRoutesPath);
return defineRoutes((route: any) => {
Expand All @@ -49,6 +33,30 @@ export async function hydrogenRoutes(
});
}

async function copyTemplates() {
const templates = await readDir(path.resolve(__dirname, '../../templates'));

const hydrogenDirectory = path.resolve(process.cwd(), '.hydrogen');
const hydrogenRoutesPath = path.resolve(process.cwd(), '.hydrogen/routes');

if (!fs.existsSync(hydrogenDirectory)) {
fs.mkdirSync(hydrogenDirectory);
}

if (!fs.existsSync(hydrogenRoutesPath)) {
fs.mkdirSync(hydrogenRoutesPath);
}

for (const template of templates) {
const destination = path.resolve(
hydrogenDirectory,
path.basename(path.dirname(template)),
path.basename(template),
);
fs.copyFileSync(template, destination);
}
}

async function buildLangRoutes() {
const appDir = path.resolve(process.cwd(), 'app');
const routesDir = path.resolve(appDir, 'routes');
Expand Down
7 changes: 7 additions & 0 deletions packages/hydrogen-remix/templates/routes/__health.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* DO NOT EDIT THIS FILE!
*
* It is generated each time Hydrogen is built. Instead, override this file by copying it to the
* `app/routes` directory in your project.
*/

export async function loader() {
return new Response(null, {status: 200});
}
7 changes: 7 additions & 0 deletions packages/hydrogen-remix/templates/routes/admin.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* DO NOT EDIT THIS FILE!
*
* It is generated each time Hydrogen is built. Instead, override this file by copying it to the
* `app/routes` directory in your project.
*/

import {LoaderArgs, redirect} from '@shopify/hydrogen-remix';

export async function loader({context}: LoaderArgs) {
Expand Down
7 changes: 7 additions & 0 deletions packages/hydrogen-remix/templates/routes/graphiql.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* DO NOT EDIT THIS FILE!
*
* It is generated each time Hydrogen is built. Instead, override this file by copying it to the
* `app/routes` directory in your project.
*/

import {LoaderArgs} from '@shopify/hydrogen-remix';

export async function loader({context}: LoaderArgs) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* DO NOT EDIT THIS FILE!
*
* It is generated each time Hydrogen is built. Instead, override this file by copying it to the
* `app/routes` directory in your project.
*/

import * as build from '@remix-run/dev/server-build';
import {RESOURCE_TYPES, REQUIRED_RESOURCES} from '@shopify/hydrogen-remix';

Expand Down
7 changes: 7 additions & 0 deletions templates/demo-store/.hydrogen/routes/__health.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* DO NOT EDIT THIS FILE!
*
* It is generated each time Hydrogen is built. Instead, override this file by copying it to the
* `app/routes` directory in your project.
*/

export async function loader() {
return new Response(null, {status: 200});
}
7 changes: 7 additions & 0 deletions templates/demo-store/.hydrogen/routes/admin.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* DO NOT EDIT THIS FILE!
*
* It is generated each time Hydrogen is built. Instead, override this file by copying it to the
* `app/routes` directory in your project.
*/

import {LoaderArgs, redirect} from '@shopify/hydrogen-remix';

export async function loader({context}: LoaderArgs) {
Expand Down
7 changes: 7 additions & 0 deletions templates/demo-store/.hydrogen/routes/graphiql.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* DO NOT EDIT THIS FILE!
*
* It is generated each time Hydrogen is built. Instead, override this file by copying it to the
* `app/routes` directory in your project.
*/

import {LoaderArgs} from '@shopify/hydrogen-remix';

export async function loader({context}: LoaderArgs) {
Expand Down
7 changes: 7 additions & 0 deletions templates/demo-store/.hydrogen/routes/route-manifest.json.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* DO NOT EDIT THIS FILE!
*
* It is generated each time Hydrogen is built. Instead, override this file by copying it to the
* `app/routes` directory in your project.
*/

import * as build from '@remix-run/dev/server-build';
import {RESOURCE_TYPES, REQUIRED_RESOURCES} from '@shopify/hydrogen-remix';

Expand Down

0 comments on commit 508f29d

Please sign in to comment.