Skip to content
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
29 changes: 29 additions & 0 deletions .github/workflows/eslint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ESLint

on:
push:
branches: master
pull_request:
branches: master
workflow_dispatch:

jobs:
js-and-style:
name: ESLint

runs-on: ubuntu-latest

steps:
- name: Check out the source code
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22

- name: Install dependencies
run: npm install

- name: Run ESLint
run: npm run lint
21 changes: 21 additions & 0 deletions .github/workflows/typos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Spell Check

on:
push:
branches: master
pull_request:
branches: master
workflow_dispatch:

jobs:
testing:
name: Spell Check with Typos

runs-on: ubuntu-latest

steps:
- name: Checkout Actions Repository
uses: actions/checkout@v4

- name: Check spelling
uses: crate-ci/typos@master
29 changes: 29 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Unit Tests

on:
push:
branches: master
pull_request:
branches: master
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

name: Jest Unit Tests

steps:
- name: Check out the source code
uses: actions/checkout@v4

- name: Setup Node
uses: actions/setup-node@v4
with:
node-version: 22

- name: Install dependencies
run: npm install

- name: Run Jest Unit Tests
run: npm run test
103 changes: 102 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,104 @@
# Polylang Build Scripts

These are the scripts needed to build Polylang. They are meant to be use as **dependencies** of both [Polylang](https://github.com/polylang/polylang) and [Polylang Pro](https://polylang.pro/products). Outside of this context, we do not guarantee that they provide you any value.
Webpack configuration helpers for building Polylang projects. Provides two main functions for generating webpack configs: `getVanillaConfig` for vanilla JS/CSS files and `getReactifiedConfig` for React-based builds.

## Installation

```bash
npm install @wpsyntex/polylang-build-scripts
```

## getVanillaConfig

Generates webpack configurations for vanilla JS and CSS files. Creates both minified and unminified versions.

**Required options:**
- `workingDirectory` - Working directory for glob resolution (typically `__dirname`)
- `jsBuildDirectory` - Output directory for JS files
- `cssBuildDirectory` - Output directory for CSS files
- `isProduction` - Enable production mode optimizations

**Optional options:**
- `jsPatterns` - Glob patterns for JS files (default: `['**/*.js']`)
- `jsIgnorePatterns` - Patterns to ignore for JS files (default: `[]`)
- `cssPatterns` - Glob patterns for CSS files (default: `['**/*.css']`)
- `cssIgnorePatterns` - Patterns to ignore for CSS files (default: `[]`)

**Example:**

```javascript
const { getVanillaConfig } = require( '@wpsyntex/polylang-build-scripts' );

const vanillaConfigs = getVanillaConfig( {
workingDirectory: __dirname,
jsPatterns: [ '**/*.js' ],
jsIgnorePatterns: [ 'node_modules/**', '**/build/**', '**/*.min.js' ],
cssPatterns: [ '**/*.css' ],
cssIgnorePatterns: [ 'node_modules/**', '**/build/**', '**/*.min.css' ],
jsBuildDirectory: path.resolve( __dirname, 'js/build' ),
cssBuildDirectory: path.resolve( __dirname, 'css/build' ),
isProduction: mode === 'production',
} );

module.exports = vanillaConfigs;
```

## getReactifiedConfig

Generates webpack configurations for React-based builds (blocks, editors). Creates minified and unminified builds with Babel transpilation.

**Required options:**
- `entryPoints` - Entry points for webpack (e.g., `{ blocks: './js/src/blocks/index.js' }`)
- `outputPath` - Base path for output files (typically `__dirname`)
- `libraryName` - Library name for the bundle (e.g., `'polylang'`)
- `isProduction` - Enable production mode optimizations
- `wpDependencies` - WordPress package dependencies to mark as externals (e.g., `['blocks', 'element', 'i18n']`)

**Optional options:**
- `additionalExternals` - Additional external dependencies (e.g., `{ jquery: 'jQuery' }`)

**Example:**

```javascript
const { getReactifiedConfig } = require( '@wpsyntex/polylang-build-scripts' );

const wpDependencies = [
'api-fetch',
'block-editor',
'blocks',
'components',
'data',
'element',
'i18n',
];

const reactConfigs = getReactifiedConfig( {
entryPoints: { blocks: './js/src/blocks/index.js' },
outputPath: __dirname,
libraryName: 'polylang',
isProduction: mode === 'production',
wpDependencies,
} );

module.exports = reactConfigs;
```

## Combined Usage

```javascript
const { getVanillaConfig, getReactifiedConfig } = require( '@wpsyntex/polylang-build-scripts' );

module.exports = ( env, argv ) => {
const mode = argv.mode || 'development';
const isProduction = mode === 'production';

return [
...getVanillaConfig( { /* options */ } ),
...getReactifiedConfig( { /* options */ } ),
];
};
```

---

These scripts are meant to be used as dependencies of Polylang-related projects but can easily be adapted for any WordPress project requiring JS or React build tools.
Loading