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

[PLAY-1414] ViteJS Update #3520

Merged
merged 66 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
1ef9c85
Init: remove webpack(er) deps
thestephenmarshall Jun 27, 2024
ec5be52
Bye, Felicia
thestephenmarshall Jun 27, 2024
d895d35
Install Vite
thestephenmarshall Jun 28, 2024
3458ab4
WIP
thestephenmarshall Jun 28, 2024
59f9822
WIP
thestephenmarshall Jul 9, 2024
daff439
WIP
thestephenmarshall Jul 11, 2024
4616321
Merge remote-tracking branch 'origin/master' into PLAY-1414
thestephenmarshall Jul 11, 2024
af94684
WIP: Dockerfile
thestephenmarshall Jul 11, 2024
501b3bd
Update scripts
thestephenmarshall Jul 11, 2024
f08540a
Fix tests
thestephenmarshall Jul 11, 2024
c747162
Add jest module mapping
thestephenmarshall Jul 11, 2024
4fac65a
Fix Jest-react
thestephenmarshall Jul 11, 2024
64b0f95
Provide errorElement to beta website router
thestephenmarshall Jul 11, 2024
0eb8fb6
Merge remote-tracking branch 'origin/master' into PLAY-1414
thestephenmarshall Jul 11, 2024
e8fe73b
ReactDocgen fixes
thestephenmarshall Jul 12, 2024
793b034
More docgen tweaks
thestephenmarshall Jul 12, 2024
cfdbf69
Try using public dir for JSON
thestephenmarshall Jul 12, 2024
3c0692c
Docker will run reactdocgen for all kits in prod
thestephenmarshall Jul 12, 2024
8608884
Reactdocgen: read cache with Ruby
thestephenmarshall Jul 12, 2024
5bc80ff
Document scripts
thestephenmarshall Jul 12, 2024
7b23689
Fix ruby gem build
thestephenmarshall Jul 15, 2024
1aa3706
Remove 99% of Dart deprecation errors
thestephenmarshall Jul 15, 2024
d28db34
Remove cache function from react-docgen
thestephenmarshall Jul 15, 2024
32eb117
Remove last webpack.config.js
thestephenmarshall Jul 15, 2024
c0b1160
Add playbook and reset scss files
thestephenmarshall Jul 15, 2024
728a22e
How I killed Flow
thestephenmarshall Jul 15, 2024
ca42606
Move intl-tel-input css import to sass
thestephenmarshall Jul 15, 2024
e03a0c8
Move deps to devDeps
thestephenmarshall Jul 17, 2024
8ac4b30
Minify in production
thestephenmarshall Jul 17, 2024
ff039f5
Remove comment tags
thestephenmarshall Jul 17, 2024
55c4cd3
Adjust tsconfig.json
thestephenmarshall Jul 17, 2024
a25f73d
Cleanup package deps
thestephenmarshall Jul 17, 2024
1a39bd8
Specify react resolutions and externals
thestephenmarshall Jul 18, 2024
229bd4e
Merge remote-tracking branch 'origin/master' into PLAY-1414
thestephenmarshall Jul 18, 2024
dfdfdc0
Don't use relative paths
thestephenmarshall Jul 18, 2024
39e9244
Merge branch 'master' into PLAY-1414
thestephenmarshall Jul 18, 2024
b2e5c1a
Revert a25f73d5f65567be07b4debb95ea5ea10e66029e
thestephenmarshall Jul 18, 2024
953f0d6
Merge remote-tracking branch 'origin/master' into PLAY-1414
thestephenmarshall Jul 19, 2024
963fcb4
Fix import path
thestephenmarshall Jul 19, 2024
70ded8e
Fix relative path
thestephenmarshall Jul 19, 2024
c82d9ad
Use terser package for minification
thestephenmarshall Jul 19, 2024
d3e0230
Remove non-module files from tokens/exports
thestephenmarshall Jul 19, 2024
00e1616
Externalize react-trix
thestephenmarshall Jul 22, 2024
37c4fa0
Cleanup RTE Trix import
thestephenmarshall Jul 22, 2024
86a865d
Upgrade react-trix
thestephenmarshall Jul 22, 2024
e408af9
Fix other layout templates
thestephenmarshall Jul 23, 2024
9b47611
Fix sandpack URL
thestephenmarshall Jul 23, 2024
0f26d6e
Fix beta/kits
thestephenmarshall Jul 23, 2024
4c56aaa
Move trix to only peerDependency
thestephenmarshall Jul 24, 2024
c570ad9
Merge remote-tracking branch 'origin/master' into PLAY-1414
thestephenmarshall Jul 24, 2024
bfde02e
Better handling of trix-toolbar
thestephenmarshall Jul 24, 2024
3534a4f
Merge branch 'master' into PLAY-1414
thestephenmarshall Jul 25, 2024
c96d58d
Better handling of trix-toolbar
thestephenmarshall Jul 24, 2024
eda8358
Visualize Vite bundle
thestephenmarshall Jul 27, 2024
b0b2e97
Move deps
thestephenmarshall Jul 27, 2024
9478b85
Roll custom trix-toolbar dedupe
thestephenmarshall Jul 27, 2024
bedbf2f
Externalize maplibre-gl
thestephenmarshall Jul 27, 2024
46a9e2c
Lodash-es
thestephenmarshall Jul 27, 2024
03cd04d
Merge remote-tracking branch 'origin/master' into PLAY-1414
thestephenmarshall Jul 27, 2024
b60d0bc
Also check for presence in text.js:isEmpty
thestephenmarshall Jul 27, 2024
7c3295e
For?? where did you come from?
thestephenmarshall Jul 27, 2024
25ad7a0
Update kit generator paths
thestephenmarshall Aug 1, 2024
06de46e
Merge branch 'master' into PLAY-1414
thestephenmarshall Aug 1, 2024
f5b4e97
react-trix peer dep
thestephenmarshall Aug 1, 2024
1325dd8
Fix eslintrc.json
thestephenmarshall Aug 2, 2024
46b2cc6
CHANGELOG for 13.34.1 (#3556)
nidaqg Aug 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/github-actions-alpha-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
npm publish --registry https://registry.npmjs.org playbook-ui-${{ env.new_npm_alpha_version }}.tgz --tag alpha
- name: Version Up, Distribute and Publish (RubyGems)
run: |
gem build playbook_ui.gemspec
bin/build_gem
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
gem build lib/playbook_ui_docs.gemspec
rm -rf dist/playbook-doc.js dist/playbook-rails.js dist/app dist/pb_doc_helper.rb dist/menu.yml
echo "${{ env.new_ruby_alpha_version }}"
Expand Down
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ RUN --mount=type=cache,id=playbook-apt-cache,target=/var/cache/apt,sharing=locke
RUN /pd_build/ruby_support/finalize.sh

ENV BUNDLE_TO /usr/local/rvm/gems
ENV NODE_OPTIONS "--openssl-legacy-provider --max-old-space-size=8192"
ENV NVM_VERSION v0.33.8
ENV NODE_VERSION v20.11.0
ENV NPM_VERSION 6.14.10
Expand Down Expand Up @@ -76,9 +75,11 @@ COPY --from=rubydeps --link $BUNDLE_TO $BUNDLE_TO
COPY --link --chown=9999:9999 playbook /home/app/src/playbook
COPY --link --chown=9999:9999 playbook-website /home/app/src/playbook-website
RUN --mount=id=playbook-yarncache,type=cache,target=/home/app/.cache/yarn,uid=9999,gid=9999,sharing=locked \
cd playbook; NODE_OPTIONS=$NODE_OPTIONS yarn release
cd playbook; NODE_ENV=production; yarn release
RUN --mount=id=playbook-yarncache,type=cache,target=/home/app/.cache/yarn,uid=9999,gid=9999,sharing=locked \
cd playbook-website; NODE_OPTIONS=$NODE_OPTIONS yarn release
cd playbook-website; NODE_ENV=production; yarn release
RUN --mount=id=playbook-yarncache,type=cache,target=/home/app/.cache/yarn,uid=9999,gid=9999,sharing=locked \
cd playbook-website; node /home/app/src/playbook-website/scripts/react-docgen.mjs --all-kits
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved

FROM base AS prod
COPY --from=rubydeps --link $BUNDLE_TO $BUNDLE_TO
Expand Down
3 changes: 2 additions & 1 deletion Procfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
setup: cd playbook-website && node scripts/global-props.mjs
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
website: cd playbook-website && ./bin/rails server -p 3000
website-watcher: cd playbook-website && yarn watch
website-watcher: cd playbook-website && bin/vite dev
library-watcher: cd playbook && yarn watch
4 changes: 0 additions & 4 deletions analyse-webpack-bundle.sh

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
"@typescript-eslint/parser": "4.33.0",
"babel-eslint": "10.1.0",
"eslint": "7.1.0",
"eslint-plugin-jsx-control-statements": "^3.0.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-jsx-control-statements": "2.2.1",
"foreman": "3.0.1",
"husky": "6.0.0",
"lint-staged": "10.5.4"
Expand Down
7 changes: 7 additions & 0 deletions playbook-website/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"presets": [
"@babel/preset-env",
"@babel/preset-typescript"
],
"plugins": ["react-docgen"]
}
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
12 changes: 9 additions & 3 deletions playbook-website/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,16 @@ public/assets
# Ignore master key for decrypting credentials and more.
config/master.key

public/packs
public/packs-test
node_modules
yarn-error.log
yarn-debug.log*
.yarn-integrity
.npmrc
.npmrc

# Vite Ruby
/public/vite*
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
/public/cache*
# Vite uses dotenv and suggests to ignore local-only env files. See
# https://vitejs.dev/guide/env-and-mode.html#env-files
*.local

2 changes: 1 addition & 1 deletion playbook-website/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ gem "playbook_ui", path: "../playbook"
gem "rails", "~> 7.0.8"
gem "turbo-rails", "~> 1.4.0"
gem "puma", "~> 6.3"
gem "webpacker", "5.4.4"
gem "vite_rails"
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
# Make Compatible with Ruby 3.1.0 Upgrade
gem "psych", "< 4"
gem "bootsnap", ">= 1.1.0", require: false
Expand Down
10 changes: 9 additions & 1 deletion playbook-website/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ GEM
crass (1.0.6)
date (3.3.4)
debug_inspector (1.1.0)
dry-cli (1.0.0)
erubi (1.12.0)
execjs (2.9.1)
faker (3.2.0)
Expand Down Expand Up @@ -262,6 +263,13 @@ GEM
view_component (2.55.0)
activesupport (>= 5.0.0, < 8.0)
method_source (~> 1.0)
vite_rails (3.0.17)
railties (>= 5.1, < 8)
vite_ruby (~> 3.0, >= 3.2.2)
vite_ruby (3.5.0)
dry-cli (>= 0.7, < 2)
rack-proxy (~> 0.6, >= 0.6.1)
zeitwerk (~> 2.2)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand Down Expand Up @@ -317,8 +325,8 @@ DEPENDENCIES
sentry-ruby
turbo-rails (~> 1.4.0)
tzinfo-data
vite_rails
web-console
webpacker (= 5.4.4)
will_paginate

RUBY VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
}) do %>
<%= pb_rails("image", props: {
alt: "React logo",
url: asset_pack_path("hp-react-solutions.svg")
url: vite_asset_path("images/hp-react-solutions.svg")
}) %>
<% end %>
<% end %>
Expand Down Expand Up @@ -166,7 +166,7 @@
}) do %>
<%= pb_rails("image", props: {
alt: "Rails logo",
url: asset_pack_path("hp-rails-solutions.svg")
url: vite_asset_path("images/hp-rails-solutions.svg")
}) %>
<% end %>
<% end %>
Expand Down Expand Up @@ -202,7 +202,7 @@
}) do %>
<%= pb_rails("image", props: {
alt: "swift logo",
url: asset_pack_path("hp-swift-solutions.svg")
url: vite_asset_path("images/hp-swift-solutions.svg")
}) %>
<% end %>
<% end %>
Expand Down Expand Up @@ -238,7 +238,7 @@
}) do %>
<%= pb_rails("image", props: {
alt: "HTML-CSS logo",
url: asset_pack_path("hp-htmlcss-solutions.svg")
url: vite_asset_path("images/hp-htmlcss-solutions.svg")
}) %>
<% end %>
<% end %>
Expand Down Expand Up @@ -275,4 +275,4 @@
<% end %>
<% end %>

<%= javascript_pack_tag 'imageComparsionSlider' %>
<%= vite_javascript_tag 'imageComparsionSlider' %>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}) do %>
<%= pb_rails("background", props: {
background_color: "dark",
image_url: asset_pack_path("media/images/hp-social-proof-background.png"),
image_url: vite_asset_path("images/hp-social-proof-background.png"),
border_radius: "lg",
background_repeat: "no-repeat",
background_position: "center right",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
}) do %>
<%= pb_rails("background", props: {
background_color: "dark",
image_url: asset_pack_path("media/images/hp-social-proof-background.png"),
image_url: vite_asset_path("images/hp-social-proof-background.png"),
border_radius: "lg",
background_repeat: "no-repeat",
background_position: "center right",
Expand Down
39 changes: 39 additions & 0 deletions playbook-website/app/components/playbook/pb_docs/kit_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,47 @@ def tsx_source
read_kit_file("", "_#{example_key}.tsx")
end

def available_props
target_kit_path = ::Playbook.kit_path(kit, "", "_#{example_key}.tsx")
if File.exist?(cached_kit_target)
puts "AvailableProps: Using cached JSON for #{target_kit_path}"
return cached_kit_json
end

exec_in_fork do
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
`node scripts/react-docgen.mjs #{target_kit_path}`
end
end

private

def exec_in_fork
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
read, write = IO.pipe

pid = fork do
read.close
result = yield
write.write(result)
write.close
exit!(0)
end

write.close
result = read.read
read.close
Process.wait(pid)

result
end

def cached_kit_json
File.read(cached_kit_target)
end

def cached_kit_target
Rails.root.join("public", "cache", "playbook", "_#{example_key}.json")
end

def sanitize_code(stringified_code)
stringified_code = stringified_code.gsub('"../.."', '"playbook-ui"')
.gsub('"../../"', '"playbook-ui"')
Expand Down
4 changes: 3 additions & 1 deletion playbook-website/app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
require "will_paginate/array"

class PagesController < ApplicationController
include ::ViteRails::TagHelpers
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved

before_action :set_js, only: %i[visual_guidelines]
before_action :set_kit, only: %i[kit_show_rails kit_show_react kit_show_swift]
before_action :ensure_kit_type_exists, only: %i[kit_show_rails kit_show_react kit_show_swift]
Expand All @@ -19,7 +21,7 @@ def application_beta
@kit = params[:name]
@params = params
@examples = pb_doc_kit_examples(@kit, @type)
@css = view_context.asset_pack_url("application.css")
@css = view_context.vite_asset_path("site_styles/main.scss")

# first example from each kit
examples = @examples.map do |example|
Expand Down
3 changes: 1 addition & 2 deletions playbook-website/app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
require "pb_doc_helper"

module ApplicationHelper
include ::Webpacker::React::Helpers
include ::Webpacker::Helper
include ::ViteRails::TagHelpers
include ::Playbook::PbFormsHelper
include ::Playbook::PbKitHelper
include ::PlaybookWebsite::Markdown::Helper
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,26 @@ import { Card, Nav, SectionSeparator, NavItem } from 'playbook-ui'
import GlobalProps from './globalProps'
import KitProps from './kitProps'

const reactDocgen = require('react-docgen')

const AvailableProps = ({ source, darkMode }) => {
const globalProps = ['aria', 'className', 'data', 'dark', 'id']
let showKitPropsTable = true, filteredProps = []

try {
const documentation = reactDocgen.parse(source)[0]
filteredProps = Object.entries(documentation.props).filter(([key, value]) => !globalProps.includes(key))
} catch (e) {
showKitPropsTable = false
}
type AvailablePropsType = {
availableProps: any,
darkMode: boolean
}

const [showKitTab, setShowKitTab] = useState(showKitPropsTable)
const AvailableProps = ({ availableProps, darkMode }: AvailablePropsType) => {
const props = JSON.parse(availableProps)
const [showKitTab, setShowKitTab] = useState(true)

return (
<>
<Card padding="none" dark={darkMode}>
<Card.Body padding="sm">
<Nav orientation="horizontal" variant="subtle" dark={darkMode}>
{showKitPropsTable && <NavItem text="Kit Props" active={showKitTab} onClick={() => setShowKitTab(true)} cursor="pointer" dark={darkMode}/>}
<NavItem text="Global Props" active={!showKitTab || !showKitPropsTable} onClick={() => setShowKitTab(false)} cursor="pointer" dark={darkMode} />
<NavItem text="Kit Props" active={showKitTab} onClick={() => setShowKitTab(true)} cursor="pointer" dark={darkMode}/>
<NavItem text="Global Props" active={!showKitTab} onClick={() => setShowKitTab(false)} cursor="pointer" dark={darkMode} />
</Nav>
</Card.Body>
<SectionSeparator dark={darkMode} />
{showKitTab && <KitProps kitPropsValues={filteredProps} darkMode={darkMode} />}
{showKitTab && <KitProps kitPropsValues={props} darkMode={darkMode} />}
{!showKitTab && <GlobalProps darkMode={darkMode}/>}
</Card>
</>
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
import React from 'react'
import { Body, Card, Table, Title } from 'playbook-ui'

const KitProps = ({ kitPropsValues, darkMode }) => {
type KitPropsType = {
kitPropsValues: {[key: string]: any},
darkMode: boolean
}

const KitProps = ({ kitPropsValues, darkMode }: KitPropsType) => {
const getTypeName = (typeName: string) => {
if (typeName.indexOf('{') !== -1) {
return 'object'
}
if (typeName.indexOf('|') !== -1) {
return 'union'
}
if (typeName.indexOf('=>') !== -1) {
return 'function'
}
return typeName
}
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved

const getTypeValue = (val: any) => {
const type = val.type
if (type.value) {
if (type.value.length > 2) {
return type.value.map((item: any) => item.value).join(' | ')
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
} else {
return val.type.value[1].value
}
} else {
if (type.name === 'string') return ''
return val.type.name
}
}

return (
<>
<Card.Body
Expand All @@ -22,7 +54,7 @@ const KitProps = ({ kitPropsValues, darkMode }) => {
</tr>
</thead>
<tbody>
{kitPropsValues.map(([propName, propsValue]) => (
{Object.entries(kitPropsValues).map(([propName, propsValue]) => (
<>
<tr>
<td>
Expand All @@ -45,16 +77,13 @@ const KitProps = ({ kitPropsValues, darkMode }) => {
className="kearning"
dark={darkMode}
>
{
propsValue.flowType.name === 'signature' ? propsValue.flowType.type : propsValue.flowType.name
}
{getTypeName(propsValue.type.name)}
</Body>
</Card>
</td>
<td>
{
// eslint-disable-next-line jsx-control-statements/jsx-use-if-tag
propsValue.flowType.raw ? (
thestephenmarshall marked this conversation as resolved.
Show resolved Hide resolved
propsValue.type.name ? (
<Card
background={darkMode ? 'dark' : 'light'}
borderNone
Expand All @@ -68,7 +97,7 @@ const KitProps = ({ kitPropsValues, darkMode }) => {
className="kearning"
dark={darkMode}
>
{propsValue.flowType.name === 'union' && propsValue.flowType.raw}
{getTypeValue(propsValue)}
</Body>
</Card>
) : null
Expand Down
15 changes: 15 additions & 0 deletions playbook-website/app/javascript/components/Error/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from 'react';
import { Caption, Icon, Title } from 'playbook-ui';
import styles from './styles.module.scss';

const Error = () => {
return (
<div className={styles.error}>
<Icon className={styles.icon} icon="warning" size="3x" />
<Title text="404" size={1} />
<Caption>Page not found</Caption>
</div>
);
}

export default Error;
Loading
Loading