Skip to content
Merged

Es6 #20

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
13 changes: 7 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ composer.lock export-ignore
docker-compose.yml export-ignore
Dockerfile export-ignore
Makefile export-ignore
contribute.md export-ignore
CONTRIBUTING.md export-ignore
/.github export-ignore
nacc2/include-stripper.php export-ignore
nacc2/index.html export-ignore
nacc2/index.php export-ignore
nacc2/LICENSE.txt export-ignore
nacc2/unit_test.html export-ignore
nacc2/src/ export-ignore
nacc2/package.json export-ignore
nacc2/package-lock.json export-ignore
nacc2/node_modules/ export-ignore
nacc2/vite.config.js export-ignore
nacc2/LICENSE.txt export-ignore
nacc2/README.md export-ignore
nacc2/index.html export-ignore
44 changes: 18 additions & 26 deletions .github/workflows/latest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,53 +11,45 @@ jobs:
id-token: write
contents: write
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
BUILD_DIR: build
DIST_DIR_S3_JS: dist_naccjs/s3
DIST_DIR_S3: dist/s3
DIST_DIR_GITHUB_JS: dist_naccjs/github
DIST_DIR_GITHUB: dist/github
GITHUB_RELEASE_FILENAME_JS: naccjs.zip
GITHUB_RELEASE_FILENAME: nacc-wordpress-plugin.zip
ZIP_FILENAME_JS: naccjs.zip
ZIP_FILENAME: nacc-wordpress-plugin.zip
S3_KEY_JS: naccjs
S3_KEY: nacc-wordpress-plugin
steps:
- name: Check out code 🛒
uses: actions/checkout@v6

- name: Build nacc zip file 🔧
- name: Setup Node.js 📦
uses: actions/setup-node@v6
with:
node-version: '20'

- name: Build nacc2 JavaScript 🔨
working-directory: nacc2
run: |
export ZIP_FILENAME_JS=naccjs-build${GITHUB_RUN_NUMBER}-${GITHUB_SHA}.zip
echo "ZIP_FILENAME_JS=${ZIP_FILENAME_JS}" >> $GITHUB_ENV
export ZIP_FILENAME=nacc-wordpress-plugin-build${GITHUB_RUN_NUMBER}-${GITHUB_SHA}.zip
echo "ZIP_FILENAME=${ZIP_FILENAME}" >> $GITHUB_ENV
find ./ -type d | xargs chmod 755
find ./ -name '*.php' | xargs chmod 644
git archive --format=zip --output=${ZIP_FILENAME} ${GITHUB_SHA}
zip -r ${ZIP_FILENAME_JS} nacc2/*
TAG="${GITHUB_REF##*/}"
mkdir -p $BUILD_DIR && mv $ZIP_FILENAME_JS $BUILD_DIR/ && mv $ZIP_FILENAME $BUILD_DIR/
mkdir -p $DIST_DIR_S3_JS && cp $BUILD_DIR/$ZIP_FILENAME_JS $DIST_DIR_S3_JS/$ZIP_FILENAME_JS
mkdir -p $DIST_DIR_GITHUB_JS && cp $BUILD_DIR/$ZIP_FILENAME_JS $DIST_DIR_GITHUB_JS/$GITHUB_RELEASE_FILENAME_JS
mkdir -p $DIST_DIR_S3 && cp $BUILD_DIR/$ZIP_FILENAME $DIST_DIR_S3/$ZIP_FILENAME
mkdir -p $DIST_DIR_GITHUB && cp $BUILD_DIR/$ZIP_FILENAME $DIST_DIR_GITHUB/$GITHUB_RELEASE_FILENAME
npm ci
npm run build

- name: Build nacc zip file 🔧
run: make build

- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v5
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::${{ secrets.AWS_ACCOUNT_ID }}:role/github-actions/gh-ci-s3-artifact
role-session-name: gh-actions-nacc
aws-region: us-east-1

- name: copy nacc artifacts to s3 🪣
run: |
aws s3 cp ${DIST_DIR_S3_JS}/${ZIP_FILENAME_JS} s3://${{ secrets.S3_BUCKET }}/${S3_KEY_JS}/${ZIP_FILENAME_JS}
aws s3 cp ${DIST_DIR_S3}/${ZIP_FILENAME} s3://${{ secrets.S3_BUCKET }}/${S3_KEY}/${ZIP_FILENAME}
aws s3 cp $BUILD_DIR/$ZIP_FILENAME_JS s3://${{ secrets.S3_BUCKET }}/$S3_KEY_JS/naccjs-${{ github.run_number }}-${{ github.sha }}.zip
aws s3 cp $BUILD_DIR/$ZIP_FILENAME s3://${{ secrets.S3_BUCKET }}/$S3_KEY/nacc-wordpress-plugin-${{ github.run_number }}-${{ github.sha }}.zip

- name: Publish Release to Latest WP 🎉
id: publish_latest
uses: bmlt-enabled/wordpress-releases-github-action@v2
with:
file: ${{ env.DIST_DIR_S3 }}/${{ env.ZIP_FILENAME }}
file: ${{ env.BUILD_DIR }}/${{ env.ZIP_FILENAME }}
aws_account_id: ${{ secrets.AWS_ACCOUNT_ID }}
s3_key: ${{ env.S3_KEY }}
11 changes: 11 additions & 0 deletions .github/workflows/pull-requests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ jobs:
uses: actions/checkout@v6
id: code-checkout

- name: Setup Node.js 📦
uses: actions/setup-node@v6
with:
node-version: '22'

- name: Build nacc2 JavaScript 🔨
working-directory: nacc2
run: |
npm ci
npm run build

- name: Validate composer.json and composer.lock 🎼
id: composer-validate
run: composer validate
Expand Down
60 changes: 23 additions & 37 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,31 @@ jobs:
id-token: write
contents: write
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
WORDPRESS_USERNAME: ${{ secrets.WORDPRESS_USERNAME }}
WORDPRESS_PASSWORD: ${{ secrets.WORDPRESS_PASSWORD }}
BUILD_DIR: build
DIST_DIR_S3_JS: dist_naccjs/s3
DIST_DIR_S3: dist/s3
DIST_DIR_GITHUB_JS: dist_naccjs/github
DIST_DIR_GITHUB: dist/github
GITHUB_RELEASE_FILENAME_JS: naccjs.zip
GITHUB_RELEASE_FILENAME: nacc-wordpress-plugin.zip
S3_KEY_JS: naccjs
S3_KEY: nacc-wordpress-plugin
PLUGIN: nacc-wordpress-plugin
MAINFILE: nacc-wordpress-plugin.php
ZIP_FILENAME_JS: naccjs.zip
ZIP_FILENAME: nacc-wordpress-plugin.zip
steps:
- name: Check out code 🛒
uses: actions/checkout@v6

- name: Build nacc zip file 🔧
- name: Setup Node.js 📦
uses: actions/setup-node@v6
with:
node-version: '22'

- name: Build nacc2 JavaScript 🔨
working-directory: nacc2
run: |
export ZIP_FILENAME_JS=naccjs-build${GITHUB_RUN_NUMBER}-${GITHUB_SHA}.zip
echo "ZIP_FILENAME_JS=${ZIP_FILENAME_JS}" >> $GITHUB_ENV
export ZIP_FILENAME=nacc-wordpress-plugin-build${GITHUB_RUN_NUMBER}-${GITHUB_SHA}.zip
echo "ZIP_FILENAME=${ZIP_FILENAME}" >> $GITHUB_ENV
echo "GITHUB_RELEASE_FILENAME_JS=${GITHUB_RELEASE_FILENAME_JS}" >> $GITHUB_ENV
echo "GITHUB_RELEASE_FILENAME=${GITHUB_RELEASE_FILENAME}" >> $GITHUB_ENV
echo "GITHUB_RELEASE_PATH_JS=${DIST_DIR_GITHUB_JS}/${GITHUB_RELEASE_FILENAME_JS}" >> $GITHUB_ENV
echo "GITHUB_RELEASE_PATH=${DIST_DIR_GITHUB}/${GITHUB_RELEASE_FILENAME}" >> $GITHUB_ENV
find ./ -type d | xargs chmod 755
find ./ -name '*.php' | xargs chmod 644
git archive --format=zip --output=${ZIP_FILENAME} ${GITHUB_SHA}
zip -r ${ZIP_FILENAME_JS} nacc2/*
TAG="${GITHUB_REF##*/}"
mkdir -p $BUILD_DIR && mv $ZIP_FILENAME_JS $BUILD_DIR/ && mv $ZIP_FILENAME $BUILD_DIR/
mkdir -p $DIST_DIR_S3_JS && cp $BUILD_DIR/$ZIP_FILENAME_JS $DIST_DIR_S3_JS/$ZIP_FILENAME_JS
mkdir -p $DIST_DIR_GITHUB_JS && cp $BUILD_DIR/$ZIP_FILENAME_JS $DIST_DIR_GITHUB_JS/$GITHUB_RELEASE_FILENAME_JS
mkdir -p $DIST_DIR_S3 && cp $BUILD_DIR/$ZIP_FILENAME $DIST_DIR_S3/$ZIP_FILENAME
mkdir -p $DIST_DIR_GITHUB && cp $BUILD_DIR/$ZIP_FILENAME $DIST_DIR_GITHUB/$GITHUB_RELEASE_FILENAME
npm ci
npm run build

- name: Build nacc zip file 🔧
run: make build

- name: Generate Release Notes 📝
if: github.ref_type == 'tag'
run: |
curl -LO https://raw.githubusercontent.com/bmlt-enabled/release-notes-tool/master/gh-release-notes.sh
curl -LO https://raw.githubusercontent.com/bmlt-enabled/release-notes-tool/main/gh-release-notes.sh
chmod +x gh-release-notes.sh
./gh-release-notes.sh readme.txt "wp"
RELEASE_TYPE=$(if [[ "$GITHUB_REF_NAME" =~ "beta" ]]; then echo "true"; else echo "false"; fi)
Expand All @@ -63,17 +45,21 @@ jobs:
uses: ncipollo/release-action@v1
if: github.ref_type == 'tag'
with:
artifacts: ${{ env.GITHUB_RELEASE_PATH }},${{ env.GITHUB_RELEASE_PATH_JS }}
artifacts: build/${{ env.ZIP_FILENAME }},build/${{ env.ZIP_FILENAME_JS }}
bodyFile: "changelog.txt"
prerelease: ${{ env.RELEASE_TYPE }}

- name: Wordpress Release ⛴
if: "!contains(github.ref, 'beta')"
id: wordpress-stable-release
env:
WORDPRESS_USERNAME : ${{ secrets.WORDPRESS_USERNAME }}
WORDPRESS_PASSWORD : ${{ secrets.WORDPRESS_PASSWORD }}
WORDPRESS_USERNAME: ${{ secrets.WORDPRESS_USERNAME }}
WORDPRESS_PASSWORD: ${{ secrets.WORDPRESS_PASSWORD }}
DIST_DIR_GITHUB: ${{ env.BUILD_DIR }}
GITHUB_RELEASE_FILENAME: ${{ env.ZIP_FILENAME }}
PLUGIN: nacc-wordpress-plugin
MAINFILE: nacc-wordpress-plugin.php
run: |
curl -LO https://raw.githubusercontent.com/bmlt-enabled/bmlt-wordpress-deploy/master/deploy-wordpress.sh
curl -LO https://raw.githubusercontent.com/bmlt-enabled/bmlt-wordpress-deploy/main/deploy-wordpress.sh
chmod +x deploy-wordpress.sh
./deploy-wordpress.sh
11 changes: 9 additions & 2 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,17 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Setup Node.js
uses: actions/setup-node@v6
with:
node-version: '20'
- name: Build nacc2 JavaScript
working-directory: nacc2
run: |
npm ci
npm run build
- name: Setup Pages
uses: actions/configure-pages@v5
# - name: Build
# run: make docs
- name: Upload artifact
uses: actions/upload-pages-artifact@v4
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ build/
*.zip
.phpdoc/
docs/
nacc2/node_modules/
108 changes: 89 additions & 19 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,79 @@ Take a look at the [issues](https://github.com/bmlt-enabled/nacc/issues) for bug

Once your pull request is merged, it will be released in the next version.

## Local Development Setup
## Prerequisites

To get things going in your local environment:
- PHP 8.0+
- [Composer](https://getcomposer.org/)
- [Node.js](https://nodejs.org/) v18+ and npm
- [Docker](https://www.docker.com/) (optional, for local WordPress environment)

1. Run the following command to start the development environment:
```bash
docker compose up
```
## Setup

2. Set up your WordPress installation and remember your admin password.
```bash
# Install PHP dev dependencies (PHPCS)
composer install

# Build nacc2 JavaScript
cd nacc2 && npm install && npm run build && cd ..
```

## Local Development

### WordPress Environment (Docker)

```bash
make dev # starts WordPress + MariaDB via Docker
make mysql # connect to the database
make bash # shell into the WordPress container
```

3. Once it's running, log in to the admin panel and activate the "NACC WordPress Plugin" plugin.
The plugin is mounted into the container. After starting, activate it in the WordPress admin and add the `[nacc]` shortcode to a page.

4. You can now make edits to the `nacc-wordpress-plugin.php` file and changes will take effect instantly.
### nacc2 JavaScript

The calculator UI lives in `nacc2/` as ES6 modules built with [Vite](https://vite.dev/).

```bash
cd nacc2
npm install
npm run build # builds nacc2/nacc.js (IIFE bundle)
```

Source files are in `nacc2/src/`. After editing, run `npm run build` to regenerate `nacc2/nacc.js`. The built file is committed to the repo so the WordPress plugin works without a build step during development.

### Project Structure

```
nacc-wordpress-plugin.php # WordPress plugin (shortcode, settings, asset loading)
readme.txt # WordPress.org plugin readme
nacc2/
nacc.js # built output (committed)
nacc.css # styles and themes
images/ # keytag images by language
src/ # ES6 source modules
nacc.js # main NACC class
calc.js # date calculation logic
sprintf.js # string formatting
lang/ # one file per language
package.json
vite.config.js
```

### How the Plugin Integrates nacc2

The WordPress plugin:
1. Enqueues `nacc2/nacc.css` and `nacc2/nacc.js` via `wp_enqueue_style`/`wp_enqueue_script`
2. Renders a `<div id="nacc_container"></div>` via the `[nacc]` shortcode
3. Injects `new NACC('nacc_container', theme, lang, layout, special, siteURI)` as inline JS
4. `siteURI` is the full URL to `nacc2/` so keytag images resolve correctly

### Adding a New Language

1. Create `nacc2/src/lang/xx.js` following the pattern in `nacc2/src/lang/en.js` (all string keys must be present)
2. Add the export to `nacc2/src/lang/index.js`
3. Add keytag images to `nacc2/images/xx/` (same filenames as other language directories)
4. Rebuild with `cd nacc2 && npm run build`

## Code Standards

Expand All @@ -35,19 +94,30 @@ Please make note of the `.editorconfig` file and adhere to it, as this will mini

This project uses PHP CodeSniffer (phpcs) for code style enforcement. The coding standards are configured in `.phpcs.xml`.

To check your code for style violations:
```bash
make lint
```

To automatically fix code style issues:
```bash
make fmt
make lint # check PHP code style
make fmt # auto-fix PHP style issues
```

Make sure to run these commands before submitting your pull request to ensure your code adheres to the project's coding standards.

## Release Tagging
## Release Process

Releases are triggered by pushing a git tag:

1. Update the version in `nacc-wordpress-plugin.php` header and `readme.txt` stable tag
2. Add a changelog entry to `readme.txt`
3. Commit, tag, and push: `git tag 5.2.0 && git push origin 5.2.0`

The `release.yml` workflow will:
- Build `nacc2/nacc.js` from source
- Create a WordPress plugin zip (`nacc-wordpress-plugin.zip`)
- Create a standalone JS zip (`naccjs.zip`)
- Upload both to S3 and create a GitHub Release
- Deploy to WordPress.org (non-beta tags only)

Tags containing "beta" (e.g. `5.2.0-beta1`) create pre-releases and skip WordPress.org deployment.

## What Ships in the WordPress Plugin

- If a release is tagged with `beta`, it will be pushed as a zip file in the GitHub release
- If it's not tagged as beta, it will be published to the WordPress directory as a release in addition to GitHub
The `.gitattributes` file controls what's included in the distribution zip. Dev files (`nacc2/src/`, `nacc2/package.json`, `nacc2/vite.config.js`, `nacc2/node_modules/`, etc.) are excluded. Only `nacc2/nacc.js`, `nacc2/nacc.css`, `nacc2/images/`, and `nacc2/icon.png` are shipped.
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
COMMIT := $(shell git rev-parse --short=8 HEAD)
ZIP_FILENAME := $(or $(ZIP_FILENAME), $(shell echo "$${PWD\#\#*/}.zip"))
ZIP_FILENAME_JS := $(or $(ZIP_FILENAME_JS), naccjs.zip)
BUILD_DIR := $(or $(BUILD_DIR),"build")
VENDOR_AUTOLOAD := vendor/autoload.php

help: ## Print the help documentation
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.PHONY: nacc2
nacc2: ## Build nacc2 JavaScript
cd nacc2 && npm install && npm run build

.PHONY: build-js
build-js: ## Build nacc2 JS-only zip (run make nacc2 first)
zip -r ${ZIP_FILENAME_JS} nacc2/* -x "nacc2/node_modules/*" "nacc2/src/*" "nacc2/package.json" "nacc2/package-lock.json" "nacc2/vite.config.js"
mkdir -p ${BUILD_DIR} && mv ${ZIP_FILENAME_JS} ${BUILD_DIR}/

.PHONY: build
build: ## Build
build: build-js ## Build WordPress plugin zip (run make nacc2 first)
git archive --format=zip --output=${ZIP_FILENAME} $(COMMIT)
mkdir -p ${BUILD_DIR} && mv ${ZIP_FILENAME} ${BUILD_DIR}/

.PHONY: all
all: nacc2 build ## Build everything

.PHONY: clean
clean: ## clean
rm -rf build dist
Expand Down
2 changes: 1 addition & 1 deletion nacc-wordpress-plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Install: Drop this directory in the "wp-content/plugins/" directory and activate it. You need to specify "[NACC]" in the code section of a page or a post.
* Contributors: BMLTGuy, pjaudiomv, bmltenabled
* Authors: bmltenabled
* Version: 5.1.1
* Version: 5.2.0
* Requires PHP: 8.0
* Requires at least: 5.3
* License: GPL v2 or later
Expand Down
Loading