Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/remix template #286

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.6.7 (2023-6-13)

- feat: add remix-dapp template

## 0.6.6 (2023-6-10)

- chore: update deps
Expand Down
5 changes: 5 additions & 0 deletions packages/create-app/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ const templates = [
display: '[dapp] react + gun.js + express.js',
color: blue,
},
{
name: 'remix-dapp',
display: '[dapp] remix',
color: blue,
},
{
name: 'react-static',
display: '[static] react',
Expand Down
2 changes: 2 additions & 0 deletions packages/create-app/templates/remix-dapp/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SESSION_SECRET="super-duper-s3cret"
DATABASE_URL="file:./data.db?connection_limit=1"
9 changes: 9 additions & 0 deletions packages/create-app/templates/remix-dapp/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
root: true,
extends: [
"@remix-run/eslint-config",
"@remix-run/eslint-config/node",
"prettier",
],
};
11 changes: 11 additions & 0 deletions packages/create-app/templates/remix-dapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
node_modules

/build
/public/build
.blocklet
.blocklet-server

/prisma/data.db
/prisma/data.db-journal

.env
1 change: 1 addition & 0 deletions packages/create-app/templates/remix-dapp/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
legacy-peer-deps=true
6 changes: 6 additions & 0 deletions packages/create-app/templates/remix-dapp/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
node_modules

/build
/public/build

/app/styles/tailwind.css
143 changes: 143 additions & 0 deletions packages/create-app/templates/remix-dapp/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Getting Started with Create Blocklet

This project was bootstrapped with [Create Blocklet](https://github.com/blocklet/create-blocklet).

This blocklet is a dapp project, which means this is a full-stack application. It's contained both `server` and `client` code.

## File Structure

- screenshots/ - Screenshots
- app/ - Remix application code
- prisma/ - SQLite database
- server.js - Api side entry point
- .prettierrc - Prettier configuration
- blocklet.md - Blocklet README
- blocklet.yml - Blocklet configuration
- LICENSE - License file
- logo.png - Blocklet logo file
- Makefile - Makefile
- package.json - Npm package file
- README.md - A guide for this blocklet
- version - Version file

## Development

1. Make sure you have [@blocklet/cli](https://www.npmjs.com/package/@blocklet/cli) installed

Blocklet needs blocklet server as a dependency. So you need to install it first.
`npm install -g @blocklet/cli`
See details in [https://developer.blocklet.io/docs/en/quick-start/blocklet-server#use-the-binary-distribution](https://developer.blocklet.io/docs/en/quick-start/blocklet-server#use-the-binary-distribution)

2. Init blocklet server & start blocklet server

Before starting an blocklet server, you need to init blocklet server.
`blocklet server init --mode=debug`
`blocklet server start`
See details in [https://developer.blocklet.io/docs/en/quick-start/blocklet-server](https://developer.blocklet.io/docs/en/quick-start/blocklet-server)

3. Go to the project directory `cd [name]`
4. Install dependencies: `npm install` or `yarn`
5. Initialize database: `npm run setup` or `yarn setup`
6. Build application: `npm run build` or `yarn build`
7. Start development server: `blocklet dev`

## Bundle

After developing a blocklet, you may need to bundle it. Use `npm run bundle` command.

## Deploy

- If you want to deploy this blocklet to local blocklet server, you can use `blocklet deploy .blocklet/bundle` command(Make sure the blocklet is bundled before deployment.)
> Or you can simply use `npm run deploy` command.
- If you want to deploy this blocklet to remote blocklet server, you can use the command below.

```shell
blocklet deploy .blocklet/bundle --endpoint {your blocklet server url} --access-key {blocklet server access key} --access-secret {blocklet server access secret}
```

> Make sure the blocklet is bundled before deployment.

## Upload to blocklet store

- If you want to upload the blocklet to any store for other users to download and use, you can following the following instructions.

Bump version at first.

```shell
make bump-version
```

Then config blocklet store url.
You can use those store url in below.

1. [https://store.blocklet.dev/](https://store.blocklet.dev/)
2. [https://dev.store.blocklet.dev/](https://dev.store.blocklet.dev/)
3. A blocklet store started by yourself.
> Make sure you have installed a `blocklet store` on your own blocklet server. Check it on here: [https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ](https://store.blocklet.dev/blocklet/z8ia29UsENBg6tLZUKi2HABj38Cw1LmHZocbQ)

```shell
blocklet config set store {store url}
```

Get a `accessToken` by using this command.

> Why we need a `accessToken`?
> A `accessToken` is genrate by blocklet store, which help us upload our blocklet to any store.

Set `accessToken` to blocklet config

```shell
blocklet config set accessToken {accessToken}
```

Upload a new version to a store.

> Make sure the blocklet is bundled before upload.

```shell
blocklet upload
```

Or you can simply use `npm run upload` command.

- You also can upload a new version to a store by Github CI.
Bump version at first.

```shell
make bump-version
```

Push your code to Github main/master branch, or make a pull request to the main/master branch.
The CI workflow will automatically upload a new version to a store.

## Q & A

1. Q: How to change a blocklet's name?

A: Change the `name` field in the `package.json` file, change the `name` field in the `blocklet.yml` file.

You can also change the `title` field and `description` field in the `blocklet.yml` file.

Run `blocklet meta` command, you will get a `did` config, copy the `did` value.

Replace this command `"bundle:client": "PUBLIC_URL='/.blocklet/proxy/{did}' npm run build",` in `package.json`

Replace `did` field in the `blocklet.yml`

2. Q: How to change a blocklet's logo?

Change the `logo.png` file root folder.

Or you can change the `logo` field in the `blocklet.yml` file.

> Make sure you have added the logo path to the `blocklet.yml` file `files` field.

## Learn More

- Full specification of `blocklet.yml`: [https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md](https://github.com/blocklet/blocklet-specification/blob/main/docs/meta.md)
- Full document of Blocklet Server & blocklet development: [https://developer.blocklet.io/docs/en](https://developer.blocklet.io/docs/en)

## License

The code is licensed under the Apache 2.0 license found in the
[LICENSE](LICENSE) file.
23 changes: 23 additions & 0 deletions packages/create-app/templates/remix-dapp/app/db.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PrismaClient } from "@prisma/client";

let prisma: PrismaClient;

declare global {
var __db__: PrismaClient | undefined;
}

// This is needed because in development we don't want to restart
// the server with every change, but we want to make sure we don't
// create a new connection to the DB with every change either.
// In production, we'll have a single connection to the DB.
if (process.env.NODE_ENV === "production") {
prisma = new PrismaClient();
} else {
if (!global.__db__) {
global.__db__ = new PrismaClient();
}
prisma = global.__db__;
prisma.$connect();
}

export { prisma };
18 changes: 18 additions & 0 deletions packages/create-app/templates/remix-dapp/app/entry.client.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* By default, Remix will handle hydrating your app on the client for you.
* You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨
* For more information, see https://remix.run/docs/en/main/file-conventions/entry.client
*/

import { RemixBrowser } from "@remix-run/react";
import { startTransition, StrictMode } from "react";
import { hydrateRoot } from "react-dom/client";

startTransition(() => {
hydrateRoot(
document,
<StrictMode>
<RemixBrowser />
</StrictMode>
);
});
120 changes: 120 additions & 0 deletions packages/create-app/templates/remix-dapp/app/entry.server.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/**
* By default, Remix will handle generating the HTTP Response for you.
* You are free to delete this file if you'd like to, but if you ever want it revealed again, you can run `npx remix reveal` ✨
* For more information, see https://remix.run/docs/en/main/file-conventions/entry.server
*/

import { PassThrough } from "node:stream";

import type { EntryContext } from "@remix-run/node";
import { Response } from "@remix-run/node";
import { RemixServer } from "@remix-run/react";
import isbot from "isbot";
import { renderToPipeableStream } from "react-dom/server";

const ABORT_DELAY = 5_000;

export default function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext
) {
return isbot(request.headers.get("user-agent"))
? handleBotRequest(
request,
responseStatusCode,
responseHeaders,
remixContext
)
: handleBrowserRequest(
request,
responseStatusCode,
responseHeaders,
remixContext
);
}

function handleBotRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext
) {
return new Promise((resolve, reject) => {
const { pipe, abort } = renderToPipeableStream(
<RemixServer
context={remixContext}
url={request.url}
abortDelay={ABORT_DELAY}
/>,
{
onAllReady() {
const body = new PassThrough();

responseHeaders.set("Content-Type", "text/html");

resolve(
new Response(body, {
headers: responseHeaders,
status: responseStatusCode,
})
);

pipe(body);
},
onShellError(error: unknown) {
reject(error);
},
onError(error: unknown) {
responseStatusCode = 500;
console.error(error);
},
}
);

setTimeout(abort, ABORT_DELAY);
});
}

function handleBrowserRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
remixContext: EntryContext
) {
return new Promise((resolve, reject) => {
const { pipe, abort } = renderToPipeableStream(
<RemixServer
context={remixContext}
url={request.url}
abortDelay={ABORT_DELAY}
/>,
{
onShellReady() {
const body = new PassThrough();

responseHeaders.set("Content-Type", "text/html");

resolve(
new Response(body, {
headers: responseHeaders,
status: responseStatusCode,
})
);

pipe(body);
},
onShellError(error: unknown) {
reject(error);
},
onError(error: unknown) {
console.error(error);
responseStatusCode = 500;
},
}
);

setTimeout(abort, ABORT_DELAY);
});
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading