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

Add translation and generative apps to monorepo #7

Merged
merged 2 commits into from
Aug 1, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const pushItemToFlow = async (
if (!res?.addItemsToFlowStage?.content || res?.addItemsToFlowStage?.content.length === 0) {
throw new Error(
res?.addItemsToFlowStage?.error ||
`Failed to add item to flow ${id}-${language}-${version} to stage ${stage}`,
`Failed to add item to flow ${id}-${language}-${version} to stage ${stage}`,
);
}
};
5 changes: 5 additions & 0 deletions components/generative-ai-app/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CRYSTALLIZE_ACCESS_TOKEN_ID=xxx
CRYSTALLIZE_ACCESS_TOKEN_SECRET=xxx
OPENAI_API_KEY=xxx
JWT_SECRET=xxx
CRYSTALLIZE_SIGNATURE_SECRET=xxx
2 changes: 2 additions & 0 deletions components/generative-ai-app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.env
3 changes: 3 additions & 0 deletions components/generative-ai-app/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
generative-ai-app.crystallize.app.local {
reverse_proxy 127.0.0.1:3000
}
13 changes: 13 additions & 0 deletions components/generative-ai-app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:20-slim as base
LABEL fly_launch_runtime="Remix"
RUN mkdir /app
WORKDIR /app
ARG PNPM_VERSION=9.0.1
RUN npm install -g pnpm@$PNPM_VERSION
COPY . .
RUN pnpm install --frozen-lockfile --prod=false
RUN pnpm build
ENV NODE_ENV=production
ENV PORT=80
EXPOSE 80
CMD [ "pnpm", "start" ]
63 changes: 63 additions & 0 deletions components/generative-ai-app/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Styles
YELLOW=$(shell echo "\033[00;33m")
RED=$(shell echo "\033[00;31m")
RESTORE=$(shell echo "\033[0m")

# Variables
PACKAGE_MANAGER := pnpm
CADDY := caddy
CADDY_PID_FILE := caddy.dev.pid
CADDYFILE := Caddyfile

.DEFAULT_GOAL := list

.PHONY: list
list:
@echo "******************************"
@echo "${YELLOW}Available targets${RESTORE}:"
@grep -E '^[a-zA-Z-]+:.*?## .*$$' Makefile | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " ${YELLOW}%-15s${RESTORE} > %s\n", $$1, $$2}'
@echo "${RED}==============================${RESTORE}"

.PHONY: clean
clean: stop ## Clean non-essential files
@rm -rf node_modules

.PHONY: install
install: ## Install dependencies
@$(PACKAGE_MANAGER) install

.PHONY: serve-https
serve-https: ## Start the HTTPS proxy
@$(CADDY) start --config $(CADDYFILE) --pidfile $(CADDY_PID_FILE)

.PHONY: serve-front
serve-front: ## Serve the Frontend
@$(PACKAGE_MANAGER) run codegen
@$(PACKAGE_MANAGER) run dev

.PHONY: stop
stop: ## Stop all the local services you need
-@$(CADDY) stop > /dev/null 2>&1 &
-@if [ -f $(CADDY_PID_FILE) ]; then \
kill -9 `cat $(CADDY_PID_FILE)`; \
rm -f $(CADDY_PID_FILE); \
fi

.PHONY: serve
serve: stop serve-https serve-front ## Run all the local services you need


.PHONY: codeclean
codeclean: ## Code Clean
@$(PACKAGE_MANAGER) run lint:fix
@$(PACKAGE_MANAGER) run prettier:fix
@$(PACKAGE_MANAGER) run lint:check
@$(PACKAGE_MANAGER) run prettier:check

.PHONY: strict-codeclean
strict-codeclean: codeclean
@$(PACKAGE_MANAGER) run typecheck

.PHONY: tests
tests: ## Run All the Tests
@$(PACKAGE_MANAGER) run test
26 changes: 26 additions & 0 deletions components/generative-ai-app/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Crystallize - Generate Content with AI APP

## Requirements

- Volta.sh (that will bring good version of Node )
- Docker
- Node: 20.x
- PNPM: 9+

## Installation

```bash
make install
```

> Important!: You need to adapt variables in the `.env`.

## Run the project

```bash
make serve
```

## Contributing

- `make codeclean` will keep the project in order.
32 changes: 32 additions & 0 deletions components/generative-ai-app/codegen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { CodegenConfig } from '@graphql-codegen/cli';

const tokenId = process.env.CRYSTALLIZE_ACCESS_TOKEN_ID;
const tokenSecret = process.env.CRYSTALLIZE_ACCESS_TOKEN_SECRET;

if (!tokenId || !tokenSecret) {
throw new Error('Missing env variable(s) when generating api legacy schemas');
}

const config: CodegenConfig = {
overwrite: true,
schema: [
{
[`https://pim.crystallize.com/graphql`]: {
headers: {
'X-Crystallize-Access-Token-Id': tokenId,
'X-Crystallize-Access-Token-Secret': tokenSecret,
},
},
},
],
generates: {
'./src/__generated__/types.ts': {
plugins: ['typescript'],
config: {
preResolveTypes: false,
},
},
},
};

export default config;
22 changes: 22 additions & 0 deletions components/generative-ai-app/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# fly.toml app configuration file generated for generative-ai-app on 2024-04-17T10:24:31+02:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = 'generative-ai-app'
primary_region = 'lhr'

[build]

[http_service]
internal_port = 80
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ['app']

[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
62 changes: 62 additions & 0 deletions components/generative-ai-app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
{
"name": "crystallize-generative-ai-app",
"private": true,
"sideEffects": false,
"type": "module",
"scripts": {
"build": "remix vite:build",
"dev": "remix vite:dev --host",
"lint": "eslint --ignore-path .gitignore --cache --cache-location ./node_modules/.cache/eslint .",
"start": "remix-serve ./build/server/index.js",
"codegen": "graphql-codegen --require dotenv/config --config codegen.ts",
"typecheck": "tsc",
"lint:check": "eslint .",
"lint:fix": "eslint . --fix",
"prettier:fix": "prettier --write .",
"prettier:check": "prettier --check .",
"test": "echo todo"
},
"dependencies": {
"@crystallize/app-signal": "^1.1.1",
"@crystallize/design-system": "^1.24.6",
"@crystallize/js-api-client": "^2.5.0",
"@remix-run/node": "^2.8.1",
"@remix-run/react": "^2.8.1",
"@remix-run/serve": "^2.8.1",
"isbot": "^4.1.0",
"jose": "^5.2.4",
"openai": "^4.36.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-textarea-autosize": "^8.5.3"
},
"devDependencies": {
"@graphql-codegen/cli": "^5.0.2",
"@graphql-codegen/typescript": "^4.0.6",
"@remix-run/dev": "^2.8.1",
"@tailwindcss/container-queries": "^0.1.1",
"@types/react": "^18.2.20",
"@types/react-dom": "^18.2.7",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"autoprefixer": "^10.4.19",
"eslint": "^8.38.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-import": "^2.28.1",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"prettier": "^3.2.5",
"tailwindcss": "^3.4.3",
"typescript": "^5.1.6",
"vite": "^5.1.0",
"vite-tsconfig-paths": "^4.2.1"
},
"engines": {
"node": ">=20.0.0"
},
"packageManager": "[email protected]",
"volta": {
"node": "20.12.2"
}
}
Loading
Loading