Skip to content

Commit

Permalink
docs: rework migration script and add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
theo-mesnil committed Jan 15, 2025
1 parent 537fed6 commit 2e97331
Show file tree
Hide file tree
Showing 6 changed files with 473 additions and 267 deletions.
2 changes: 1 addition & 1 deletion lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "welcome-ui",
"version": "1.0.0-beta.8",
"version": "1.0.0-beta.9",
"description": "Customizable design system with react • styled-components • styled-system and ariakit.",
"files": [
"dist"
Expand Down
1 change: 1 addition & 0 deletions lib/src/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export * from './Shape'
export * from './Slider'
export * from './Stack'
export * from './Swiper'
export * from './System'
export * from './Table'
export * from './Tabs'
export * from './Tag'
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"lint:ts": "cd lib tsc --noEmit && cd ../website && tsc --noEmit",
"lint:website": "cd website && yarn lint",
"lint": "yarn lint:js && yarn lint:css && yarn lint:ts && yarn lint:mdx && yarn lint:website",
"migrate": "node ./scripts/update-imports.js",
"postinstall": "husky install",
"dev:prerelease": "todo",
"release": "todo",
Expand Down
36 changes: 28 additions & 8 deletions scripts/update-imports.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,58 @@ const fs = require('fs')

const glob = require('glob')

const [pattern = ''] = process.argv.slice(2)

function mergeImports(content) {
// Extract all welcome-ui imports
const importRegex = /import\s+{([^}]+)}\s+from\s+['"](@welcome-ui\/[^'"]+|welcome-ui)['"]/g
// Extract all `welcome-ui` imports (normal and type imports)
const importRegex =
/import\s+(type\s+)?{([^}]+)}\s+from\s+['"](@welcome-ui\/[^'"]+|welcome-ui)['"]/g
const imports = new Set()
const typeImports = new Set()
let match

while ((match = importRegex.exec(content)) !== null) {
match[1]
const isTypeImport = match[1]?.trim() === 'type'
const importSet = isTypeImport ? typeImports : imports

match[2]
.split(',')
.map(i => i.trim())
.filter(Boolean)
.forEach(i => imports.add(i))
.forEach(i => {
// Rename WuiTheme to ThemeValues for type imports
if (isTypeImport && i === 'WuiTheme') {
importSet.add('ThemeValues')
} else {
importSet.add(i)
}
})
}

// Remove old imports
content = content.replace(
/import\s+{[^}]+}\s+from\s+['"](@welcome-ui\/[^'"]+|welcome-ui)['"]\n?/g,
/import\s+(type\s+)?{[^}]+}\s+from\s+['"](@welcome-ui\/[^'"]+|welcome-ui)['"]\n?/g,
''
)

// Add merged import at top
// Add merged imports at top
if (imports.size > 0) {
const mergedImport = `import { ${Array.from(imports).join(', ')} } from 'welcome-ui'\n`
const mergedImport = `import { ${Array.from(imports).join(', ')} } from 'welcome-ui';\n`
content = mergedImport + content
}

if (typeImports.size > 0) {
const mergedTypeImport = `import type { ${Array.from(typeImports).join(', ')} } from 'welcome-ui';\n`
content = mergedTypeImport + content
}

return content
}

const files = glob.sync('**/*.{ts,tsx}', {
const files = glob.sync(pattern, {
ignore: ['**/node_modules/**', '**/dist/**', '**/*.d.ts'],
})

files.forEach(file => {
const content = fs.readFileSync(file, 'utf8')
const newContent = mergeImports(content)
Expand Down
274 changes: 16 additions & 258 deletions website/build-app/pages/foundations/migration.mdx
Original file line number Diff line number Diff line change
@@ -1,279 +1,37 @@
## Version 6
# Version 7: Back of mono-package

Welcome UI V6 focuses on the rebranding of our **colors** and **tokens**, and we add a **Logo** component.
Welcome UI V7 bring back all on a mono-package: `welcome-ui`

![Version 6 illustation](https://github.com/user-attachments/assets/34259431-1bc3-4d97-84b7-e2048c7208da)
![Version 7 illustation](https://github.com/user-attachments/assets/34259431-1bc3-4d97-84b7-e2048c7208da)

## Upgrade steps

### 1. Update your dependencies
### 1. Script to migrate

Make sure you update all `@welcome-ui` packages to v6:

```diff
{
"dependencies": {
+ "@welcome-ui/YOUR_PACKAGE": "^6.0.0",
"@xstyled/styled-components": "^3.7.3",
"react": "^18.0.0",
"styled-components": "^5.3.9"
}
}
```

On VSCode search:

```bash
("@welcome-ui\/[^"]+":\s*)"\^?[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9\.]+)?"
```
And replace by:
In welcome-ui project, run this script move all `@welcome-ui/*` to only one `welcome-ui` import:

```bash
$1"6.0.0"
yarn migrate "../your-project/src/**/**.*{ts,tsx}"
```

### 2. Script to migrate
### 2. Update your dependencies

We reworked our theme's colors and variants name. Use the migration script to migrate easily to V6 on a welcome-ui project.
In your project, remove all `@welcome-ui` packages:

```bash
yarn migrate "../yourProject/src/**/**.{tsx,ts,js,mdx}"
```
### 3. Remove `welcomeTheme` & `welcomeDarkTheme`
To simplify our developements, we removed the 2 welcome themes. Now the default have primary colors from welcome ui brand:
```diff
+ import { createTheme, darkTheme } from '@welcome-ui/core'
- import { welcomeTheme } from '@welcome-ui/themes.welcome'
- import { darkTheme } from '@welcome-ui/dark'
- import { welcomeDarkTheme } from '@welcome-ui/themes.welcome-dark'
- const theme = createTheme(welcomeTheme)
+ const theme = createTheme()
- const darkTheme = createTheme(welcomeDarkTheme)
+ const darkTheme = createTheme(darkTheme)
```
and remove also from your `packages.json`:
```diff
- "@welcome-ui/themes.dark": "^5.22.1"
- "@welcome-ui/themes.welcome": "^5.22.1"
- "@welcome-ui/themes.welcome-dark": "^5.22.1"
```
### 4. Change variant `error` to `danger` on:
#### Alert
```diff
- <Alert variant="error">
+ <Alert variant="danger">
```
#### Table
```diff
- <Table.Tr variant="error">
+ <Table.Tr variant="danger">
```
#### Tag
```diff
- <Tag variant="error">
+ <Tag variant="danger">
```
#### Hint
```diff
- <Hint variant="error">
+ <Hint variant="danger">
```
#### Label
```diff
- <Label variant="error">
+ <Label variant="danger">
```
## Colors
We reworked our colors to prepare the next steps for tokenization.
[Discover our brand new colors](/foundations/theming/basics#colors)
### Range
Now the range is `color-10` to `color-90`.
```diff
- primary-100
+ primary-10
```
### Neutral replace Dark and Light
We merged Dark and Light colors in a Neutral new one, without opacity.
```diff
- light-100
+ neutral-10
- dark-900
+ neutral-90
```
### New colors
Hello `green` `teal` `blue` `violet` `pink` `red` `red-orange` `orange` and `yellow` 🥰
### Beige instead of Nude
The nude naming is changed for beige.
```diff
- nude-100
+ beige-10
```
### State colors removed
We've removed the state colors `danger`, `success`, `warning` and `info`. They'll be replaced with new tokens in the future.
```diff
- danger-100
+ red-10
```
### Secondary
Sub colors replaced by 6 new colors for the secondary palette:
```diff
- sub-1
+ secondary-blue
```
```diff
- sub-2
+ secondary-teal
```
```diff
- sub-3
+ secondary-pink
```
```diff
- sub-4
+ secondary-orange
yarn remove $(grep -o "@welcome-ui/[a-zA-Z0-9-]*" package.json | sort | uniq)
```

```diff
- sub-5
- sub-6
+ secondary-green
```
```diff
- sub-7
+ secondary-violet
```
## Dark mode
Dark mode is still on Beta 🚨 and will be released in a few minor versions.
```jsx
import { createTheme, darkTheme } from '@welcome-ui/core'
const theme = createTheme(darkTheme)
```
## Components
### Logo
A new [Logo](/components/logo) component is available, with svg export of:
```tsx
import { Logo, SolutionsSymbol, Symbol, WelcomeUILogo } from '@welcome-ui/logo'
And add new mono-package:

return <Logo w={100} />
```
- <strong>Logo</strong>: Welcome to the Jungle new logo
- <strong>Symbol</strong>
- <strong>SolutionsSymbol</strong>: Welcome to the solution new logo with symbol
- <strong>WelcomeUILogo</strong>: Welcome UI new logo
### Icons & IconsFont
- New icon Symbol on [Icons](/components/icon#welcome)
```tsx
<SymbolIcon />
```
- New icon Symbol on [IconFont](/components/icon-font#welcome)
```tsx
<Icons.Symbol />
```
### Fields
On the fields we removed the `info` variant property:
- All fields
- Labels
- Hints
### Button
We removed some variants property on states and add danger property for red button.
```diff
- <Button variant="primary-success">Primary success</Button>
- <Button variant="primary-warning">Primary warning</Button>
- <Button variant="primary-danger">Primary danger</Button>
+ <Button danger>Primary danger</Button>
- <Button variant="primary-info">Primary info</Button>
- <Button variant="secondary-success">Secondary success</Button>
- <Button variant="secondary-warning">Secondary warning</Button>
- <Button variant="secondary-danger">Secondary danger</Button>
+ <Button variant="tertiary" danger>Tertiary danger</Button>
- <Button variant="secondary-info">Secondary info</Button>
```
```diff
+ <Button variant="ghost" danger>Ghost danger</Button>
```
### Badge
We removed `shape` property on Badge component, now you will only have rounded badge.
```diff
- <Badge shape="square">Name</Badge>
+ <Badge>Name</Badge>
```bash
yarn add welcome-ui
```

### Tag
### 3. Add missing peerDependencies

We removed the `secondary` variant and replaced the `sub-*` variants. To use the `secondary` color please use the `Badge` component instead.
You need to check packages you used and add missing peer dependencies.

```diff
- <Tag variant="secondary">Name</Tag>
+ <Tag variant="green">Name</Tag>
```
### 4. Change imports

```diff
- <Tag variant="1">Name</Tag>
+ <Tag variant="blue">Name</Tag>
```
1. `WuiTheme` becomes `ThemeValues`
Loading

0 comments on commit 2e97331

Please sign in to comment.