diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..ae10a5c --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +# editorconfig.org +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true diff --git a/.env.defaults b/.env.defaults new file mode 100644 index 0000000..fb88fb3 --- /dev/null +++ b/.env.defaults @@ -0,0 +1,19 @@ +# These environment variables will be used by default if you do not create any +# yourself in .env. This file should be safe to check into your version control +# system. Any custom values should go in .env and .env should *not* be checked +# into version control. + +# schema.prisma defaults +DATABASE_URL=file:./dev.db + +# location of the test database for api service scenarios (defaults to ./.redwood/test.db if not set) +# TEST_DATABASE_URL=file:./.redwood/test.db + +# disables Prisma CLI update notifier +PRISMA_HIDE_UPDATE_MESSAGE=true + +# Option to override the current environment's default api-side log level +# See: https://redwoodjs.com/docs/logger for level options, defaults to "trace" otherwise. +# Most applications want "debug" or "info" during dev, "trace" when you have issues and "warn" in production. +# Ordered by how verbose they are: trace | debug | info | warn | error | silent +# LOG_LEVEL=debug diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..2a2de6c --- /dev/null +++ b/.env.example @@ -0,0 +1,4 @@ +# DATABASE_URL=file:./dev.db +# TEST_DATABASE_URL=file:./.redwood/test.db +# PRISMA_HIDE_UPDATE_MESSAGE=true +# LOG_LEVEL=trace diff --git a/.gitignore b/.gitignore index ceaea36..9b81495 100644 --- a/.gitignore +++ b/.gitignore @@ -1,132 +1,22 @@ -# ---> Node -# Logs -logs -*.log -npm-debug.log* -yarn-debug.log* -yarn-error.log* -lerna-debug.log* -.pnpm-debug.log* - -# Diagnostic reports (https://nodejs.org/api/report.html) -report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json - -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage -*.lcov - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Snowpack dependency directory (https://snowpack.dev/) -web_modules/ - -# TypeScript cache -*.tsbuildinfo - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional stylelint cache -.stylelintcache - -# Microbundle cache -.rpt2_cache/ -.rts2_cache_cjs/ -.rts2_cache_es/ -.rts2_cache_umd/ - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variable files +.idea +.DS_Store .env -.env.development.local -.env.test.local -.env.production.local -.env.local - -# parcel-bundler cache (https://parceljs.org/) -.cache -.parcel-cache - -# Next.js build output -.next -out - -# Nuxt.js build / generate output -.nuxt +.netlify +.redwood/* +!.redwood/README.md +dev.db* dist - -# Gatsby files -.cache/ -# Comment in the public line in if your project uses Gatsby and not Next.js -# https://nextjs.org/blog/next-9-1#public-directory-support -# public - -# vuepress build output -.vuepress/dist - -# vuepress v2.x temp and cache directory -.temp -.cache - -# Docusaurus cache and generated files -.docusaurus - -# Serverless directories -.serverless/ - -# FuseBox cache -.fusebox/ - -# DynamoDB Local files -.dynamodb/ - -# TernJS port file -.tern-port - -# Stores VSCode versions used for testing VSCode extensions -.vscode-test - -# yarn v2 -.yarn/cache -.yarn/unplugged -.yarn/build-state.yml -.yarn/install-state.gz +dist-babel +node_modules +yarn-error.log +web/public/mockServiceWorker.js +web/types/graphql.d.ts +api/types/graphql.d.ts +api/src/lib/generateGraphiQLHeader.* .pnp.* - +.yarn/* +!.yarn/patches +!.yarn/plugins +!.yarn/releases +!.yarn/sdks +!.yarn/versions diff --git a/README.md b/README.md index f703ecc..08f5886 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,122 @@ -# snowglobs +# README -Generate and download a snowglob \ No newline at end of file +Welcome to [RedwoodJS](https://redwoodjs.com)! + +> **Prerequisites** +> +> - Redwood requires [Node.js](https://nodejs.org/en/) (=18.x) and [Yarn](https://yarnpkg.com/) (>=1.15) +> - Are you on Windows? For best results, follow our [Windows development setup](https://redwoodjs.com/docs/how-to/windows-development-setup) guide + +Start by installing dependencies: + +``` +yarn install +``` + +Then start the development server: + +``` +yarn redwood dev +``` + +Your browser should automatically open to [http://localhost:8910](http://localhost:8910) where you'll see the Welcome Page, which links out to many great resources. + +> **The Redwood CLI** +> +> Congratulations on running your first Redwood CLI command! From dev to deploy, the CLI is with you the whole way. And there's quite a few commands at your disposal: +> +> ``` +> yarn redwood --help +> ``` +> +> For all the details, see the [CLI reference](https://redwoodjs.com/docs/cli-commands). + +## Prisma and the database + +Redwood wouldn't be a full-stack framework without a database. It all starts with the schema. Open the [`schema.prisma`](api/db/schema.prisma) file in `api/db` and replace the `UserExample` model with the following `Post` model: + +```prisma +model Post { + id Int @id @default(autoincrement()) + title String + body String + createdAt DateTime @default(now()) +} +``` + +Redwood uses [Prisma](https://www.prisma.io/), a next-gen Node.js and TypeScript ORM, to talk to the database. Prisma's schema offers a declarative way of defining your app's data models. And Prisma [Migrate](https://www.prisma.io/migrate) uses that schema to make database migrations hassle-free: + +``` +yarn rw prisma migrate dev + +# ... + +? Enter a name for the new migration: › create posts +``` + +> `rw` is short for `redwood` + +You'll be prompted for the name of your migration. `create posts` will do. + +Now let's generate everything we need to perform all the CRUD (Create, Retrieve, Update, Delete) actions on our `Post` model: + +``` +yarn redwood generate scaffold post +``` + +Navigate to [http://localhost:8910/posts/new](http://localhost:8910/posts/new), fill in the title and body, and click "Save". + +Did we just create a post in the database? Yup! With `yarn rw generate scaffold `, Redwood created all the pages, components, and services necessary to perform all CRUD actions on our posts table. + +## Frontend first with Storybook + +Don't know what your data models look like? That's more than ok—Redwood integrates Storybook so that you can work on design without worrying about data. Mockup, build, and verify your React components, even in complete isolation from the backend: + +``` +yarn rw storybook +``` + +Seeing "Couldn't find any stories"? That's because you need a `*.stories.{tsx,jsx}` file. The Redwood CLI makes getting one easy enough—try generating a [Cell](https://redwoodjs.com/docs/cells), Redwood's data-fetching abstraction: + +``` +yarn rw generate cell examplePosts +``` + +The Storybook server should hot reload and now you'll have four stories to work with. They'll probably look a little bland since there's no styling. See if the Redwood CLI's `setup ui` command has your favorite styling library: + +``` +yarn rw setup ui --help +``` + +## Testing with Jest + +It'd be hard to scale from side project to startup without a few tests. Redwood fully integrates Jest with both the front- and back-ends, and makes it easy to keep your whole app covered by generating test files with all your components and services: + +``` +yarn rw test +``` + +To make the integration even more seamless, Redwood augments Jest with database [scenarios](https://redwoodjs.com/docs/testing#scenarios) and [GraphQL mocking](https://redwoodjs.com/docs/testing#mocking-graphql-calls). + +## Ship it + +Redwood is designed for both serverless deploy targets like Netlify and Vercel and serverful deploy targets like Render and AWS: + +``` +yarn rw setup deploy --help +``` + +Don't go live without auth! Lock down your app with Redwood's built-in, database-backed authentication system ([dbAuth](https://redwoodjs.com/docs/authentication#self-hosted-auth-installation-and-setup)), or integrate with nearly a dozen third-party auth providers: + +``` +yarn rw setup auth --help +``` + +## Next Steps + +The best way to learn Redwood is by going through the comprehensive [tutorial](https://redwoodjs.com/docs/tutorial/foreword) and joining the community (via the [Discourse forum](https://community.redwoodjs.com) or the [Discord server](https://discord.gg/redwoodjs)). + +## Quick Links + +- Stay updated: read [Forum announcements](https://community.redwoodjs.com/c/announcements/5), follow us on [Twitter](https://twitter.com/redwoodjs), and subscribe to the [newsletter](https://redwoodjs.com/newsletter) +- [Learn how to contribute](https://redwoodjs.com/docs/contributing) diff --git a/api/db/schema.prisma b/api/db/schema.prisma new file mode 100644 index 0000000..3dea71a --- /dev/null +++ b/api/db/schema.prisma @@ -0,0 +1,18 @@ +datasource db { + provider = "sqlite" + url = env("DATABASE_URL") +} + +generator client { + provider = "prisma-client-js" + binaryTargets = "native" +} + +// Define your own datamodels here and run `yarn redwood prisma migrate dev` +// to create migrations for them and apply to your dev DB. +// TODO: Please remove the following example: +model UserExample { + id Int @id @default(autoincrement()) + email String @unique + name String? +} diff --git a/api/jest.config.js b/api/jest.config.js new file mode 100644 index 0000000..932fc82 --- /dev/null +++ b/api/jest.config.js @@ -0,0 +1,8 @@ +// More info at https://redwoodjs.com/docs/project-configuration-dev-test-build + +const config = { + rootDir: '../', + preset: '@redwoodjs/testing/config/jest/api', +} + +module.exports = config diff --git a/api/package.json b/api/package.json new file mode 100644 index 0000000..29e22bf --- /dev/null +++ b/api/package.json @@ -0,0 +1,9 @@ +{ + "name": "api", + "version": "0.0.0", + "private": true, + "dependencies": { + "@redwoodjs/api": "6.0.6", + "@redwoodjs/graphql-server": "6.0.6" + } +} diff --git a/api/server.config.js b/api/server.config.js new file mode 100644 index 0000000..e82b04e --- /dev/null +++ b/api/server.config.js @@ -0,0 +1,52 @@ +/** + * This file allows you to configure the Fastify Server settings + * used by the RedwoodJS dev server. + * + * It also applies when running RedwoodJS with `yarn rw serve`. + * + * For the Fastify server options that you can set, see: + * https://www.fastify.io/docs/latest/Reference/Server/#factory + * + * Examples include: logger settings, timeouts, maximum payload limits, and more. + * + * Note: This configuration does not apply in a serverless deploy. + */ + +/** @type {import('fastify').FastifyServerOptions} */ +const config = { + requestTimeout: 15_000, + logger: { + // Note: If running locally using `yarn rw serve` you may want to adjust + // the default non-development level to `info` + level: process.env.NODE_ENV === 'development' ? 'debug' : 'warn', + }, +} + +/** + * You can also register Fastify plugins and additional routes for the API and Web sides + * in the configureFastify function. + * + * This function has access to the Fastify instance and options, such as the side + * (web, api, or proxy) that is being configured and other settings like the apiRootPath + * of the functions endpoint. + * + * Note: This configuration does not apply in a serverless deploy. + */ + +/** @type {import('@redwoodjs/api-server/dist/fastify').FastifySideConfigFn} */ +const configureFastify = async (fastify, options) => { + if (options.side === 'api') { + fastify.log.trace({ custom: { options } }, 'Configuring api side') + } + + if (options.side === 'web') { + fastify.log.trace({ custom: { options } }, 'Configuring web side') + } + + return fastify +} + +module.exports = { + config, + configureFastify, +} diff --git a/api/src/directives/requireAuth/requireAuth.test.ts b/api/src/directives/requireAuth/requireAuth.test.ts new file mode 100644 index 0000000..0f01aa3 --- /dev/null +++ b/api/src/directives/requireAuth/requireAuth.test.ts @@ -0,0 +1,18 @@ +import { mockRedwoodDirective, getDirectiveName } from '@redwoodjs/testing/api' + +import requireAuth from './requireAuth' + +describe('requireAuth directive', () => { + it('declares the directive sdl as schema, with the correct name', () => { + expect(requireAuth.schema).toBeTruthy() + expect(getDirectiveName(requireAuth.schema)).toBe('requireAuth') + }) + + it('requireAuth has stub implementation. Should not throw when current user', () => { + // If you want to set values in context, pass it through e.g. + // mockRedwoodDirective(requireAuth, { context: { currentUser: { id: 1, name: 'Lebron McGretzky' } }}) + const mockExecution = mockRedwoodDirective(requireAuth, { context: {} }) + + expect(mockExecution).not.toThrowError() + }) +}) diff --git a/api/src/directives/requireAuth/requireAuth.ts b/api/src/directives/requireAuth/requireAuth.ts new file mode 100644 index 0000000..59daccb --- /dev/null +++ b/api/src/directives/requireAuth/requireAuth.ts @@ -0,0 +1,27 @@ +import gql from 'graphql-tag' + +import { + createValidatorDirective, + ValidatorDirectiveFunc, +} from '@redwoodjs/graphql-server' + +import { requireAuth as applicationRequireAuth } from 'src/lib/auth' + +export const schema = gql` + """ + Use to check whether or not a user is authenticated and is associated + with an optional set of roles. + """ + directive @requireAuth(roles: [String]) on FIELD_DEFINITION +` + +type RequireAuthValidate = ValidatorDirectiveFunc<{ roles?: string[] }> + +const validate: RequireAuthValidate = ({ directiveArgs }) => { + const { roles } = directiveArgs + applicationRequireAuth({ roles }) +} + +const requireAuth = createValidatorDirective(schema, validate) + +export default requireAuth diff --git a/api/src/directives/skipAuth/skipAuth.test.ts b/api/src/directives/skipAuth/skipAuth.test.ts new file mode 100644 index 0000000..88d99a5 --- /dev/null +++ b/api/src/directives/skipAuth/skipAuth.test.ts @@ -0,0 +1,10 @@ +import { getDirectiveName } from '@redwoodjs/testing/api' + +import skipAuth from './skipAuth' + +describe('skipAuth directive', () => { + it('declares the directive sdl as schema, with the correct name', () => { + expect(skipAuth.schema).toBeTruthy() + expect(getDirectiveName(skipAuth.schema)).toBe('skipAuth') + }) +}) diff --git a/api/src/directives/skipAuth/skipAuth.ts b/api/src/directives/skipAuth/skipAuth.ts new file mode 100644 index 0000000..e85b94a --- /dev/null +++ b/api/src/directives/skipAuth/skipAuth.ts @@ -0,0 +1,16 @@ +import gql from 'graphql-tag' + +import { createValidatorDirective } from '@redwoodjs/graphql-server' + +export const schema = gql` + """ + Use to skip authentication checks and allow public access. + """ + directive @skipAuth on FIELD_DEFINITION +` + +const skipAuth = createValidatorDirective(schema, () => { + return +}) + +export default skipAuth diff --git a/api/src/functions/graphql.ts b/api/src/functions/graphql.ts new file mode 100644 index 0000000..f395c3b --- /dev/null +++ b/api/src/functions/graphql.ts @@ -0,0 +1,19 @@ +import { createGraphQLHandler } from '@redwoodjs/graphql-server' + +import directives from 'src/directives/**/*.{js,ts}' +import sdls from 'src/graphql/**/*.sdl.{js,ts}' +import services from 'src/services/**/*.{js,ts}' + +import { db } from 'src/lib/db' +import { logger } from 'src/lib/logger' + +export const handler = createGraphQLHandler({ + loggerConfig: { logger, options: {} }, + directives, + sdls, + services, + onException: () => { + // Disconnect from your database with an unhandled exception. + db.$disconnect() + }, +}) diff --git a/api/src/graphql/.keep b/api/src/graphql/.keep new file mode 100644 index 0000000..e69de29 diff --git a/api/src/lib/auth.ts b/api/src/lib/auth.ts new file mode 100644 index 0000000..f98fe93 --- /dev/null +++ b/api/src/lib/auth.ts @@ -0,0 +1,25 @@ +/** + * Once you are ready to add authentication to your application + * you'll build out requireAuth() with real functionality. For + * now we just return `true` so that the calls in services + * have something to check against, simulating a logged + * in user that is allowed to access that service. + * + * See https://redwoodjs.com/docs/authentication for more info. + */ +export const isAuthenticated = () => { + return true +} + +export const hasRole = ({ roles }) => { + return roles !== undefined +} + +// This is used by the redwood directive +// in ./api/src/directives/requireAuth + +// Roles are passed in by the requireAuth directive if you have auth setup +// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars +export const requireAuth = ({ roles }) => { + return isAuthenticated() +} diff --git a/api/src/lib/db.ts b/api/src/lib/db.ts new file mode 100644 index 0000000..5006d00 --- /dev/null +++ b/api/src/lib/db.ts @@ -0,0 +1,21 @@ +// See https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-client/constructor +// for options. + +import { PrismaClient } from '@prisma/client' + +import { emitLogLevels, handlePrismaLogging } from '@redwoodjs/api/logger' + +import { logger } from './logger' + +/* + * Instance of the Prisma Client + */ +export const db = new PrismaClient({ + log: emitLogLevels(['info', 'warn', 'error']), +}) + +handlePrismaLogging({ + db, + logger, + logLevels: ['info', 'warn', 'error'], +}) diff --git a/api/src/lib/logger.ts b/api/src/lib/logger.ts new file mode 100644 index 0000000..150a309 --- /dev/null +++ b/api/src/lib/logger.ts @@ -0,0 +1,17 @@ +import { createLogger } from '@redwoodjs/api/logger' + +/** + * Creates a logger with RedwoodLoggerOptions + * + * These extend and override default LoggerOptions, + * can define a destination like a file or other supported pino log transport stream, + * and sets whether or not to show the logger configuration settings (defaults to false) + * + * @param RedwoodLoggerOptions + * + * RedwoodLoggerOptions have + * @param {options} LoggerOptions - defines how to log, such as redaction and format + * @param {string | DestinationStream} destination - defines where to log, such as a transport stream or file + * @param {boolean} showConfig - whether to display logger configuration on initialization + */ +export const logger = createLogger({}) diff --git a/api/src/services/.keep b/api/src/services/.keep new file mode 100644 index 0000000..e69de29 diff --git a/api/tsconfig.json b/api/tsconfig.json new file mode 100644 index 0000000..65c666c --- /dev/null +++ b/api/tsconfig.json @@ -0,0 +1,35 @@ +{ + "compilerOptions": { + "noEmit": true, + "allowJs": true, + "esModuleInterop": true, + "target": "esnext", + "module": "esnext", + "moduleResolution": "node", + "skipLibCheck": false, + "baseUrl": "./", + "rootDirs": [ + "./src", + "../.redwood/types/mirror/api/src" + ], + "paths": { + "src/*": [ + "./src/*", + "../.redwood/types/mirror/api/src/*" + ], + "types/*": ["./types/*", "../types/*"], + "@redwoodjs/testing": ["../node_modules/@redwoodjs/testing/api"] + }, + "typeRoots": [ + "../node_modules/@types", + "./node_modules/@types" + ], + "types": ["jest"] + }, + "include": [ + "src", + "../.redwood/types/includes/all-*", + "../.redwood/types/includes/api-*", + "../types" + ] +} diff --git a/colorbar.png b/colorbar.png new file mode 100644 index 0000000..7dbd05f Binary files /dev/null and b/colorbar.png differ diff --git a/colorbarGenerator.js b/colorbarGenerator.js new file mode 100644 index 0000000..e3d8ec4 --- /dev/null +++ b/colorbarGenerator.js @@ -0,0 +1,22 @@ +const Jimp = require("jimp") + +async function generateColorbar() { + const base = await Jimp.create(300, 8, '#e7e2dc') + const pixel = await Jimp.create(1, 8, '#788ea5') + for (let i=0; i < 300; i++) { + const hue = i + base.composite( + pixel.color([ + {apply: 'spin', params: [1]} + ]), + i, + 0, + { mode: Jimp.BLEND_SOURCE_OVER } + ) + } + return base +} + +generateColorbar().then( (result) => { + result.write('./web/public/img/colorbar.png') +}) diff --git a/graphql.config.js b/graphql.config.js new file mode 100644 index 0000000..2da7862 --- /dev/null +++ b/graphql.config.js @@ -0,0 +1,5 @@ +const { getPaths } = require('@redwoodjs/internal') + +module.exports = { + schema: getPaths().generated.schema, +} diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 0000000..c6b395c --- /dev/null +++ b/jest.config.js @@ -0,0 +1,8 @@ +// This the Redwood root jest config +// Each side, e.g. ./web/ and ./api/ has specific config that references this root +// More info at https://redwoodjs.com/docs/project-configuration-dev-test-build + +module.exports = { + rootDir: '.', + projects: ['/{*,!(node_modules)/**/}/jest.config.js'], +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..b40911c --- /dev/null +++ b/package.json @@ -0,0 +1,35 @@ +{ + "private": true, + "workspaces": { + "packages": [ + "api", + "web" + ] + }, + "devDependencies": { + "@redwoodjs/core": "6.0.6" + }, + "eslintConfig": { + "extends": "@redwoodjs/eslint-config", + "root": true + }, + "engines": { + "node": "=18.x", + "yarn": ">=1.15" + }, + "prisma": { + "seed": "yarn rw exec seed" + }, + "packageManager": "yarn@3.6.1", + "dependencies": { + "browserify-zlib": "^0.2.0", + "https-browserify": "^1.0.0", + "jimp": "^0.16.2", + "js-file-download": "^0.4.12", + "node-polyfill-webpack-plugin": "^2.0.1", + "path-browserify": "^1.0.1", + "process": "^0.11.10", + "stream-browserify": "^3.0.0", + "stream-http": "^3.2.0" + } +} diff --git a/prettier.config.js b/prettier.config.js new file mode 100644 index 0000000..45058f7 --- /dev/null +++ b/prettier.config.js @@ -0,0 +1,18 @@ +// https://prettier.io/docs/en/options.html +/** @type {import('prettier').RequiredOptions} */ +module.exports = { + trailingComma: 'es5', + bracketSpacing: true, + tabWidth: 2, + semi: false, + singleQuote: true, + arrowParens: 'always', + overrides: [ + { + files: 'Routes.*', + options: { + printWidth: 999, + }, + }, + ], +} diff --git a/production.sh b/production.sh new file mode 100755 index 0000000..ec46143 --- /dev/null +++ b/production.sh @@ -0,0 +1,7 @@ +#!/bin/bash +source ~/.nvm/nvm.sh +nvm use 18 +if [ "$1" == "build" ]; then + yarn rw build +fi +yarn rw serve -p 8969 diff --git a/redwood.toml b/redwood.toml new file mode 100644 index 0000000..46bc0eb --- /dev/null +++ b/redwood.toml @@ -0,0 +1,22 @@ +# This file contains the configuration settings for your Redwood app. +# This file is also what makes your Redwood app a Redwood app. +# If you remove it and try to run `yarn rw dev`, you'll get an error. +# +# For the full list of options, see the "App Configuration: redwood.toml" doc: +# https://redwoodjs.com/docs/app-configuration-redwood-toml + +[web] + bundler = "webpack" + title = "Redwood App" + port = 8910 + apiUrl = "/.redwood/functions" # You can customize graphql and dbauth urls individually too: see https://redwoodjs.com/docs/app-configuration-redwood-toml#api-paths + includeEnvironmentVariables = [ + # Add any ENV vars that should be available to the web side to this array + # See https://redwoodjs.com/docs/environment-variables#web + ] +[api] + port = 8911 +[browser] + open = true +[notifications] + versionUpdates = ["latest"] diff --git a/scripts/.keep b/scripts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/scripts/seed.ts b/scripts/seed.ts new file mode 100644 index 0000000..5797fd9 --- /dev/null +++ b/scripts/seed.ts @@ -0,0 +1,63 @@ +import type { Prisma } from '@prisma/client' +import { db } from 'api/src/lib/db' + +export default async () => { + try { + // + // Manually seed via `yarn rw prisma db seed` + // Seeds automatically with `yarn rw prisma migrate dev` and `yarn rw prisma migrate reset` + // + // Update "const data = []" to match your data model and seeding needs + // + const data: Prisma.UserExampleCreateArgs['data'][] = [ + // To try this example data with the UserExample model in schema.prisma, + // uncomment the lines below and run 'yarn rw prisma migrate dev' + // + // { name: 'alice', email: 'alice@example.com' }, + // { name: 'mark', email: 'mark@example.com' }, + // { name: 'jackie', email: 'jackie@example.com' }, + // { name: 'bob', email: 'bob@example.com' }, + ] + console.log( + "\nUsing the default './scripts/seed.{js,ts}' template\nEdit the file to add seed data\n" + ) + + // Note: if using PostgreSQL, using `createMany` to insert multiple records is much faster + // @see: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#createmany + Promise.all( + // + // Change to match your data model and seeding needs + // + data.map(async (data: Prisma.UserExampleCreateArgs['data']) => { + const record = await db.userExample.create({ data }) + console.log(record) + }) + ) + + // If using dbAuth and seeding users, you'll need to add a `hashedPassword` + // and associated `salt` to their record. Here's how to create them using + // the same algorithm that dbAuth uses internally: + // + // import { hashPassword } from '@redwoodjs/auth-dbauth-api' + // + // const users = [ + // { name: 'john', email: 'john@example.com', password: 'secret1' }, + // { name: 'jane', email: 'jane@example.com', password: 'secret2' } + // ] + // + // for (const user of users) { + // const [hashedPassword, salt] = hashPassword(user.password) + // await db.user.create({ + // data: { + // name: user.name, + // email: user.email, + // hashedPassword, + // salt + // } + // }) + // } + } catch (error) { + console.warn('Please define your seed data.') + console.error(error) + } +} diff --git a/scripts/tsconfig.json b/scripts/tsconfig.json new file mode 100644 index 0000000..babc7c4 --- /dev/null +++ b/scripts/tsconfig.json @@ -0,0 +1,42 @@ +{ + "compilerOptions": { + "noEmit": true, + "allowJs": true, + "esModuleInterop": true, + "target": "esnext", + "module": "esnext", + "moduleResolution": "node", + "baseUrl": "./", + "paths": { + "$api/*": [ + "../api/*" + ], + "api/*": [ + "../api/*" + ], + "$web/*": [ + "../web/*" + ], + "web/*": [ + "../web/*" + ], + "$web/src/*": [ + "../web/src/*", + "../.redwood/types/mirror/web/src/*" + ], + "web/src/*": [ + "../web/src/*", + "../.redwood/types/mirror/web/src/*" + ], + "types/*": ["../types/*", "../web/types/*", "../api/types/*"] + }, + "typeRoots": ["../node_modules/@types"], + "jsx": "preserve" + }, + "include": [ + ".", + "../.redwood/types/includes/all-*", + "../.redwood/types/includes/web-*", + "../types" + ] +} diff --git a/web/config/chakra.config.js b/web/config/chakra.config.js new file mode 100644 index 0000000..7477c5b --- /dev/null +++ b/web/config/chakra.config.js @@ -0,0 +1,4 @@ +// This object will be used to override Chakra-UI theme defaults. +// See https://chakra-ui.com/docs/styled-system/theming/theme for theming options +const theme = {} +export default theme diff --git a/web/config/storybook.preview.js b/web/config/storybook.preview.js new file mode 100644 index 0000000..0ce50bf --- /dev/null +++ b/web/config/storybook.preview.js @@ -0,0 +1,23 @@ +import * as React from 'react' +import { ChakraProvider, extendTheme } from '@chakra-ui/react' +import * as theme from 'config/chakra.config' +/** @type { import("@storybook/csf").GlobalTypes } */ +export const globalTypes = {} +/** + * An example, no-op storybook decorator. Use a function like this to create decorators. + * @param { import("@storybook/addons").StoryFn} StoryFn + * @param { import("@storybook/addons").StoryContext} context + * @returns StoryFn, unmodified. + */ +const _exampleDecorator = (StoryFn, _context) => { + return +} +const extendedTheme = extendTheme(theme) +const withChakra = (StoryFn) => { + return ( + + + + ) +} +export const decorators = [withChakra] diff --git a/web/config/webpack.config.js b/web/config/webpack.config.js new file mode 100644 index 0000000..bceefd2 --- /dev/null +++ b/web/config/webpack.config.js @@ -0,0 +1,40 @@ +/** @returns {import('webpack').Configuration} Webpack Configuration */ +const NodePolyfillPlugin = require('node-polyfill-webpack-plugin') +var webpack = require('webpack') + +module.exports = (config, { mode }) => { + if (mode === 'development') { + // Add dev plugin + } + + config.module.rules.push({ + resolve: { + fallback: { + fs: false, + path: require.resolve('path-browserify'), + http: require.resolve('stream-http'), + https: require.resolve('https-browserify'), + zlib: require.resolve('browserify-zlib'), + stream: require.resolve('stream-browserify'), + querystring: require.resolve('querystring-es3') + }, + }, + }) + + config.plugins.push( + // fix "process is not defined" error: + // (do "npm install process" before running the build) + new webpack.ProvidePlugin({ + process: 'process/browser.js', + Buffer: ['buffer', 'Buffer'], + }) + ) + + // Add custom rules for your project + // config.module.rules.push(YOUR_RULE) + + // Add custom plugins for your project + // config.plugins.push(YOUR_PLUGIN) + + return config +} diff --git a/web/jest.config.js b/web/jest.config.js new file mode 100644 index 0000000..0e54869 --- /dev/null +++ b/web/jest.config.js @@ -0,0 +1,8 @@ +// More info at https://redwoodjs.com/docs/project-configuration-dev-test-build + +const config = { + rootDir: '../', + preset: '@redwoodjs/testing/config/jest/web', +} + +module.exports = config diff --git a/web/package.json b/web/package.json new file mode 100644 index 0000000..3c26b8e --- /dev/null +++ b/web/package.json @@ -0,0 +1,28 @@ +{ + "name": "web", + "version": "0.0.0", + "private": true, + "browserslist": { + "development": [ + "last 1 version" + ], + "production": [ + "defaults" + ] + }, + "dependencies": { + "@chakra-ui/react": "^2", + "@emotion/react": "^11", + "@emotion/styled": "^11", + "@redwoodjs/forms": "6.0.6", + "@redwoodjs/router": "6.0.6", + "@redwoodjs/web": "6.0.6", + "framer-motion": "^9", + "prop-types": "15.8.1", + "react": "18.2.0", + "react-dom": "18.2.0" + }, + "devDependencies": { + "@redwoodjs/vite": "6.0.6" + } +} diff --git a/web/public/README.md b/web/public/README.md new file mode 100644 index 0000000..618395f --- /dev/null +++ b/web/public/README.md @@ -0,0 +1,35 @@ +# Static Assets +Use this folder to add static files directly to your app. All included files and folders will be copied directly into the `/dist` folder (created when Vite builds for production). They will also be available during development when you run `yarn rw dev`. +>Note: files will *not* hot reload while the development server is running. You'll need to manually stop/start to access file changes. + +### Example Use +A file like `favicon.png` will be copied to `/dist/favicon.png`. A folder containing a file such as `static-files/my-logo.jpg` will be copied to `/dist/static-files/my-logo.jpg`. These can be referenced in your code directly without any special handling, e.g. +``` + +``` +and +``` + alt="Logo" /> +``` + + +## Best Practices +Because assets in this folder are bypassing the javascript module system, **this folder should be used sparingly** for assets such as favicons, robots.txt, manifests, libraries incompatible with Vite, etc. + +In general, it's best to import files directly into a template, page, or component. This allows Vite to include that file in the bundle when small enough, or to copy it over to the `dist` folder with a hash. + +### Example Asset Import with Vite +Instead of handling our logo image as a static file per the example above, we can do the following: +``` +import React from "react" +import logo from "./my-logo.jpg" + + +function Header() { + return Logo +} + +export default Header +``` + +See Vite's docs for [static asset handling](https://vitejs.dev/guide/assets.html) diff --git a/web/public/favicon.png b/web/public/favicon.png new file mode 100644 index 0000000..0f37d0f Binary files /dev/null and b/web/public/favicon.png differ diff --git a/web/public/img/base.png b/web/public/img/base.png new file mode 100644 index 0000000..4cba1f9 Binary files /dev/null and b/web/public/img/base.png differ diff --git a/web/public/img/bottom.png b/web/public/img/bottom.png new file mode 100644 index 0000000..d648062 Binary files /dev/null and b/web/public/img/bottom.png differ diff --git a/web/public/img/colorbar.png b/web/public/img/colorbar.png new file mode 100644 index 0000000..4defd57 Binary files /dev/null and b/web/public/img/colorbar.png differ diff --git a/web/public/img/middle.png b/web/public/img/middle.png new file mode 100644 index 0000000..82c686d Binary files /dev/null and b/web/public/img/middle.png differ diff --git a/web/public/img/snowglobs.png b/web/public/img/snowglobs.png new file mode 100644 index 0000000..f342dd6 Binary files /dev/null and b/web/public/img/snowglobs.png differ diff --git a/web/public/img/snowglobs.xcf b/web/public/img/snowglobs.xcf new file mode 100644 index 0000000..8093114 Binary files /dev/null and b/web/public/img/snowglobs.xcf differ diff --git a/web/public/img/top.png b/web/public/img/top.png new file mode 100644 index 0000000..23b9cdb Binary files /dev/null and b/web/public/img/top.png differ diff --git a/web/public/robots.txt b/web/public/robots.txt new file mode 100644 index 0000000..eb05362 --- /dev/null +++ b/web/public/robots.txt @@ -0,0 +1,2 @@ +User-agent: * +Disallow: diff --git a/web/src/App.tsx b/web/src/App.tsx new file mode 100644 index 0000000..bb3d805 --- /dev/null +++ b/web/src/App.tsx @@ -0,0 +1,27 @@ +import { FatalErrorBoundary, RedwoodProvider } from '@redwoodjs/web' +import { RedwoodApolloProvider } from '@redwoodjs/web/apollo' + +import { ChakraProvider, ColorModeScript, extendTheme } from '@chakra-ui/react' +import * as theme from 'config/chakra.config' + +import FatalErrorPage from 'src/pages/FatalErrorPage' +import Routes from 'src/Routes' + +import './index.css' + +const extendedTheme = extendTheme(theme) + +const App = () => ( + + + + + + + + + + +) + +export default App diff --git a/web/src/Routes.tsx b/web/src/Routes.tsx new file mode 100644 index 0000000..0291fd9 --- /dev/null +++ b/web/src/Routes.tsx @@ -0,0 +1,21 @@ +// In this file, all Page components from 'src/pages` are auto-imported. Nested +// directories are supported, and should be uppercase. Each subdirectory will be +// prepended onto the component name. +// +// Examples: +// +// 'src/pages/HomePage/HomePage.js' -> HomePage +// 'src/pages/Admin/BooksPage/BooksPage.js' -> AdminBooksPage + +import { Router, Route } from '@redwoodjs/router' + +const Routes = () => { + return ( + + + + + ) +} + +export default Routes diff --git a/web/src/components/.keep b/web/src/components/.keep new file mode 100644 index 0000000..e69de29 diff --git a/web/src/entry.client.tsx b/web/src/entry.client.tsx new file mode 100644 index 0000000..ffee44f --- /dev/null +++ b/web/src/entry.client.tsx @@ -0,0 +1,17 @@ +import { hydrateRoot, createRoot } from 'react-dom/client' + +import App from './App' +/** + * When `#redwood-app` isn't empty then it's very likely that you're using + * prerendering. So React attaches event listeners to the existing markup + * rather than replacing it. + * https://reactjs.org/docs/react-dom-client.html#hydrateroot + */ +const redwoodAppElement = document.getElementById('redwood-app') + +if (redwoodAppElement.children?.length > 0) { + hydrateRoot(redwoodAppElement, ) +} else { + const root = createRoot(redwoodAppElement) + root.render() +} diff --git a/web/src/index.css b/web/src/index.css new file mode 100644 index 0000000..e69de29 diff --git a/web/src/index.html b/web/src/index.html new file mode 100644 index 0000000..e240b8e --- /dev/null +++ b/web/src/index.html @@ -0,0 +1,15 @@ + + + + + + + + + + + +
+ + + diff --git a/web/src/layouts/.keep b/web/src/layouts/.keep new file mode 100644 index 0000000..e69de29 diff --git a/web/src/pages/FatalErrorPage/FatalErrorPage.tsx b/web/src/pages/FatalErrorPage/FatalErrorPage.tsx new file mode 100644 index 0000000..b2bb436 --- /dev/null +++ b/web/src/pages/FatalErrorPage/FatalErrorPage.tsx @@ -0,0 +1,57 @@ +// This page will be rendered when an error makes it all the way to the top of the +// application without being handled by a Javascript catch statement or React error +// boundary. +// +// You can modify this page as you wish, but it is important to keep things simple to +// avoid the possibility that it will cause its own error. If it does, Redwood will +// still render a generic error page, but your users will prefer something a bit more +// thoughtful :) + +// This import will be automatically removed when building for production +import { DevFatalErrorPage } from '@redwoodjs/web/dist/components/DevFatalErrorPage' + +export default DevFatalErrorPage || + (() => ( +
+