[Embeds] Create vite project and add to build pipeline (#3448)

* add bskyembed vite app

* create build script (temp until embedr is ready)
zio/stable
Samuel Newman 2024-04-12 15:52:26 +01:00 committed by GitHub
parent 24bd3d6986
commit ad97d4350c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 3946 additions and 3 deletions

View File

@ -32,7 +32,8 @@ RUN \. "$NVM_DIR/nvm.sh" && \
npm install --global yarn && \
yarn && \
yarn intl:build && \
yarn build-web
yarn build-web && \
yarn build-embed
# DEBUG
RUN find ./bskyweb/static && find ./web-build/static

View File

@ -12,6 +12,7 @@ help: ## Print info about all commands
build-web: ## Compile web bundle, copy to bskyweb directory
yarn intl:build
yarn build-web
yarn build-embed
.PHONY: test
test: ## Run all tests

View File

@ -0,0 +1,20 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "simple-import-sort"],
"extends": [
"eslint:recommended",
"preact",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking"
],
"rules": {
"simple-import-sort/imports": "warn",
"simple-import-sort/exports": "warn"
},
"parserOptions": {
"sourceType": "module",
"ecmaVersion": "latest",
"project": "./tsconfig.json"
}
}

5
bskyembed/.gitignore vendored 100644
View File

@ -0,0 +1,5 @@
node_modules
.DS_Store
dist
dist-ssr
*.local

View File

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Vite App</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

View File

@ -0,0 +1,21 @@
{
"name": "bskyembed",
"version": "0.0.0",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint --cache --ext .js,.jsx,.ts,.tsx src"
},
"dependencies": {
"preact": "^10.4.8"
},
"devDependencies": {
"@prefresh/vite": "^1.2.1",
"eslint": "^8.19.0",
"eslint-config-preact": "^1.3.0",
"eslint-plugin-simple-import-sort": "^12.0.0",
"typescript": "^4.0.5",
"vite": "^1.0.0-rc.13",
"vite-tsconfig-paths": "^4.3.2"
}
}

View File

@ -0,0 +1,18 @@
import {Fragment, h} from 'preact'
export function App() {
return (
<>
<p>Hello Vite + Preact!</p>
<p>
<a
className="link"
href="https://preactjs.com/"
target="_blank"
rel="noopener noreferrer">
Learn Preact
</a>
</p>
</>
)
}

View File

@ -0,0 +1,29 @@
html, body {
height: 100%;
width: 100%;
padding: 0;
margin: 0;
background: #FAFAFA;
font-family: 'Helvetica Neue', arial, sans-serif;
font-weight: 400;
color: #444;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
* {
box-sizing: border-box;
}
#app {
height: 100%;
text-align: center;
background-color: #673ab8;
color: #fff;
font-size: 1.5em;
padding-top: 100px;
}
.link {
color: #fff;
}

View File

@ -0,0 +1,9 @@
import './index.css'
import {h, render} from 'preact'
import {App} from './app'
const root = document.getElementById('app')
if (!root) throw new Error('No root element')
render(<App />, root)

View File

@ -0,0 +1,23 @@
{
"compilerOptions": {
"target": "ES5",
"lib": ["DOM", "DOM.Iterable", "ESNext"],
"types": [],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react",
"jsxFactory": "h",
"jsxFragmentFactory": "Fragment"
},
"include": ["src"]
}

View File

@ -0,0 +1,18 @@
import {resolve} from 'node:path'
// @ts-expect-error - not important
import preactRefresh from '@prefresh/vite'
import type {UserConfig} from 'vite'
import paths from 'vite-tsconfig-paths'
const config: UserConfig = {
jsx: {
factory: 'h',
fragment: 'Fragment',
},
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
plugins: [preactRefresh(), paths()],
assetsDir: 'static/embed/assets',
}
export default config

3737
bskyembed/yarn.lock 100644

File diff suppressed because it is too large Load Diff

View File

@ -83,11 +83,10 @@ To run the build with Go, use staging credentials, your own, or any other accoun
```
cd social-app
yarn && yarn build-web
cp ./web-build/static/js/*.* bskyweb/static/js/
cd bskyweb/
go mod tidy
go build -v -tags timetzdata -o bskyweb ./cmd/bskyweb
./bskyweb serve --pds-host=https://staging.bsky.dev --handle=<HANDLE> --password=<PASSWORD>
./bskyweb serve --appview-host=https://public.api.bsky.app
```
On build success, access the application at [http://localhost:8100/](http://localhost:8100/). Subsequent changes require re-running the above steps in order to be reflected.

View File

@ -20,6 +20,7 @@
"build-ios": "yarn use-build-number-with-bump eas build -p ios",
"build-android": "yarn use-build-number-with-bump eas build -p android",
"build": "yarn use-build-number-with-bump eas build",
"build-embed": "cd bskyembed && yarn build && cd .. && node ./scripts/post-embed-build.js",
"start": "expo start --dev-client",
"start:prod": "expo start --dev-client --no-dev --minify",
"clean-cache": "rm -rf node_modules/.cache/babel-loader/*",

View File

@ -0,0 +1,49 @@
// const path = require('node:path')
// const fs = require('node:fs')
// const projectRoot = path.join(__dirname, '..')
// // copy embed assets to web-build
// const embedAssetSource = path.join(
// projectRoot,
// 'bskyembed',
// 'dist',
// 'static',
// 'embed',
// 'assets',
// )
// const embedAssetDest = path.join(
// projectRoot,
// 'web-build',
// 'static',
// 'embed',
// 'assets',
// )
// fs.cpSync(embedAssetSource, embedAssetDest, {recursive: true})
// // copy entrypoint(s) to web-build
// // additional entrypoints will need more work, but this'll do for now
// const embedHtmlSource = path.join(
// projectRoot,
// 'bskyembed',
// 'dist',
// 'index.html',
// )
// const embedHtmlDest = path.join(
// projectRoot,
// 'web-build',
// 'static',
// 'embed',
// 'post.html',
// )
// fs.copyFileSync(embedHtmlSource, embedHtmlDest)
// console.log(`Copied embed assets to web-build`)
console.log('post-embed-build.js - waiting for embedr!')