Skip to content

Commit 33eaeef

Browse files
committed
Build the package on install.
1 parent 9b54d96 commit 33eaeef

8 files changed

Lines changed: 222 additions & 38 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Directories
22
node_modules/
3+
build/
34

45
# Files
56
.DS_Store

README.md

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ A unified package of React components, icons, and utilities for Polylang project
99
- **API Middlewares** - WordPress REST API filtering utilities
1010
- **React Hooks** - Custom hooks for language management and state handling
1111

12-
> **Note**: This package distributes **source code** that is processed by consuming projects. No build step is needed.
13-
1412
## 🚀 Installation
1513

1614
### From GitHub
@@ -21,6 +19,8 @@ A unified package of React components, icons, and utilities for Polylang project
2119
npm install github:polylang/polylang-react-library
2220
```
2321

22+
The package automatically builds during installation via the `prepare` script. The source code in `src/` is transpiled to `build/` using Babel with WordPress presets.
23+
2424
## 💻 Usage
2525

2626
### Components
@@ -130,12 +130,21 @@ function LanguageSelector() {
130130
npm install
131131
```
132132

133+
### Building
134+
135+
The library uses Babel to transpile JSX and modern JavaScript:
136+
137+
```bash
138+
npm run build # Build src/ to build/
139+
```
140+
141+
The `prepare` script runs automatically on `npm install`, ensuring the library is always built when installed as a dependency.
142+
133143
### Linting
134144

135145
```bash
136146
npm run lint # Check code
137147
npm run lint:fix # Fix automatically
138-
npm run format # Format code
139148
```
140149

141150
## 📋 Available Exports

babel.config.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": [ "@wordpress/babel-preset-default" ]
3+
}

index.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

package-lock.json

Lines changed: 161 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@wpsyntex/polylang-react-library",
33
"version": "1.0.0",
4-
"description": "A collection of React components, icons, and utilities for Polylang-related projects. Distributes source code (no build required).",
4+
"description": "A collection of React components, icons, and utilities for Polylang-related projects.",
55
"keywords": [
66
"gutenberg",
77
"react",
@@ -21,22 +21,29 @@
2121
},
2222
"license": "GPL-3.0+",
2323
"author": "WP Syntex",
24-
"main": "index.js",
24+
"main": "build/index.js",
2525
"sideEffects": false,
2626
"files": [
27-
"index.js",
28-
"src/"
27+
"build/"
2928
],
3029
"scripts": {
30+
"build": "babel src --out-dir build --copy-files",
31+
"prepare": "npm run build",
3132
"lint": "wp-scripts lint-js",
3233
"lint:fix": "wp-scripts lint-js --fix"
3334
},
35+
"dependencies": {
36+
"@babel/cli": "^7.26.5",
37+
"@wordpress/babel-preset-default": "^8.10"
38+
},
3439
"peerDependencies": {
3540
"@wordpress/api-fetch": ">=7.0.0",
3641
"@wordpress/components": ">=27.0.0",
3742
"@wordpress/element": ">=6.0.0",
3843
"@wordpress/i18n": ">=5.0.0",
3944
"@wordpress/primitives": ">=4.0.0",
45+
"@wordpress/data": ">=10.0.0",
46+
"@wordpress/editor": ">=14.0.0",
4047
"lodash": ">=4.17.0",
4148
"react": ">=17.0.0"
4249
},

src/hooks/use-current-language.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* WordPress dependencies
33
*/
44
import { useSelect } from '@wordpress/data';
5+
// This package is not found in `@wordpress/scripts` like others (peer dependency).
6+
// eslint-disable-next-line import/no-unresolved
57
import { store as coreEditorStore } from '@wordpress/editor';
68

79
/**
@@ -19,7 +21,8 @@ export const useCurrentLanguage = ( languages ) => {
1921
return null;
2022
}
2123

22-
const currentLanguageSlug = currentPost.lang ?? pllEditorCurrentLanguageSlug;
24+
const currentLanguageSlug =
25+
currentPost.lang ?? pllEditorCurrentLanguageSlug; // eslint-disable-line no-undef
2326

2427
const currentLanguage = languages.find( ( language ) => {
2528
return language.slug === currentLanguageSlug;

src/index.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* Polylang React Library
3+
*
4+
* A collection of React components, icons, and utilities for Polylang projects.
5+
*/
6+
7+
// Export components
8+
export { LanguageDropdown } from './components/language-dropdown';
9+
export { default as LanguageFlag } from './components/language-flag';
10+
11+
// Export icons
12+
export { default as duplication } from './icons/duplication';
13+
export { default as pencil } from './icons/pencil';
14+
export { default as plus } from './icons/plus';
15+
export { default as synchronization } from './icons/synchronization';
16+
export { default as translation } from './icons/translation';
17+
export { default as trash } from './icons/trash';
18+
export { default as star } from './icons/star';
19+
export { default as SubmenuIcon } from './icons/submenu';
20+
export { default as DefaultLangIcon } from './icons/default-lang';
21+
22+
// Export middlewares
23+
export { default as filterPathMiddleware } from './middlewares/filter-path';
24+
export { default as editorsRequestsFilter } from './middlewares/editors-requests-filter';
25+
26+
// Export hooks
27+
export { useCuratedLanguages } from './hooks/use-curated-languages';
28+
export { useCurrentLanguage } from './hooks/use-current-language';
29+
export { useLanguagesList } from './hooks/use-languages-list';
30+
export { useMemoizedSwitcherLabel } from './hooks/use-memoized-switcher-label';

0 commit comments

Comments
 (0)