Skip to content

Commit

Permalink
Merge pull request #38 from dreamsicle-io/release/2.0.0-RC4
Browse files Browse the repository at this point in the history
Release/2.0.0 rc4
  • Loading branch information
theenoahmason authored Aug 3, 2023
2 parents c8f9341 + e8bfb4b commit 2e25984
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 52 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Release

on:
push:
branches: [master]

jobs:
release:
runs-on: ubuntu-latest
steps:

# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it.
- name: Checkout Repo
id: checkout_repo
uses: actions/checkout@v2

# Gets the version from package.json and sets it as an environment variable.
- name: Set Package Version
id: set_package_version
run: echo "PACKAGE_VERSION=$(jq -r '.version' package.json)" >> $GITHUB_ENV

# Creates a release draft.
- name: Create Release
id: create_release
uses: ncipollo/release-action@v1
with:
name: ${{ env.PACKAGE_VERSION }}
tag: ${{ env.PACKAGE_VERSION }}
commit: master
draft: true
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}
generateReleaseNotes: true
skipIfReleaseExists: true
48 changes: 14 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

A simple, zero configuration [Gulp](https://gulpjs.com) build & lint setup for developing modern [WordPress](https://wordpress.org) themes.

This package is built entirely on Gulp 4, and will lint, build and optimize `.js` and `.scss` assets, generate `.pot` language localization files, and optimize images. This package will also create the required `style.css` file and its formatted header comment, as well as the required, [theme directory](https://wordpress.org/themes) friendly `README.md` file with all it's content; all generated by the theme root's `package.json` data.
This package contains a task runner built entirely on Gulp 4, and will lint `.php` according to the WordPress coding standards, build and optimize `.js`, `.scss` assets, generate a `.pot` language localization file, and optimize images. This package will also create the required `style.css` file and its formatted header comment, as well as the required, [theme directory](https://wordpress.org/themes) friendly `README.md` file with all it's content. This package also comes bundled with utilities to automatically fix code issues, GitHub actions for automatically building release assets and creating releases, and contains recommended extensions and settings for the [VSCode](https://code.visualstudio.com/) IDE.

Finally, this package also includes a `WP_Theme_Assets` [php class](https://github.com/dreamsicle-io/wp-theme-assets/blob/master/package/includes/class-wp-theme-assets.php), located in `includes/class-wp-theme-assets.php`. This class beautifully handles all script and stylesheet enqueues of built assets automatically.

## Getting Started

The best way to scaffold this project is to use [@dreamsicle.io/create-wp-theme](https://github.com/dreamsicle-io/create-wp-theme). This is a node command line utility that will allow walk you through a prompt in the command line.
The best way to scaffold this project is to use [@dreamsicle.io/create-wp-theme](https://github.com/dreamsicle-io/create-wp-theme). This is a node command line utility that will walk you through a prompt in the command line.

### 1. Scaffold a Theme

Expand All @@ -32,87 +32,67 @@ cd path/to/theme
npm install
```

### 3. Run a production build.
### 3. Run Builds

**From the theme's root, run the build command:**
**Run a production build:**

```shell
npm run build
```

> **Note:** This will create a directory at `assets/dist` and build all `.css` and `.js` files, as well as optimize all images. This will also create a `languages` directory and place a built `.pot` file inside of it. Lastly, this will build the required `style.css` and `README.md` files in the theme root.
### 4. Run a development build and watch for changes.

**From the theme's root, run the build command:**
**Run a development build and watch for changes:**

```shell
npm start
```

### 5. Initialize WP_Theme_Assets Class

The included `WP_Theme_Assets` [php class](https://github.com/dreamsicle-io/wp-theme-assets/blob/master/package/includes/class-wp-theme-assets.php), found at `includes/class-wp-theme-assets.php`, beautifully handles all script and stylesheet enqueues of built assets automatically. It also loads the theme textdomain and registers the languages directory.

**Place the following snippet in the theme's `functions.php` file:**

```php
// Require the class-wp-theme-assets.php file.
require get_template_directory() . '/includes/class-wp-theme-assets.php';

// Hook the `WP_Theme_Assets` class's `init()` method to `after_setup_theme`.
add_action( 'after_setup_theme', array( new WP_Theme_Assets, 'init' ), 0 );
```

> **Note:** This is hooked at priority `0` to allow the class's methods to use `after_setup_theme` also.
## Development Commands

The included [gulpfile](https://github.com/dreamsicle-io/wp-theme-assets/blob/master/package/gulpfile.js) contains all tasks that handle linting and building in this package. The included [development commands](https://github.com/dreamsicle-io/wp-theme-assets/blob/master/package/package.json), found on the `scripts` key in the `package.json` file, control all top level commands needed for this setup to function properly.
The included [gulpfile](https://github.com/dreamsicle-io/wp-theme-assets/blob/master/package/gulpfile.js) contains all tasks that handle linting and building this package.

### Install

This command will install all dependencies listed on the `devDependencies` key in the `package.json` file. This will generate a `package-lock.json` file and a `node_modules` directory in the theme root, both of which are ignored in the `.gitignore` file by default.
Install all `npm` and `composer` dependencies.

```shell
npm install
```

### Start

This command will start the `default` task, which runs the `lint`, `build:assets`, and `watch` tasks in series.
Run a development build and watch for changes.

```shell
npm start
```

### Build

This command will start the `build` task, which runs the `clean`, `build:assets`, and `zip` tasks in series.
Run a production build.

```shell
npm run build
```

### Lint

This command will start the `fix` task, which runs the `fix:php`, `fix:sass`, and `fix:js` tasks in series.
Find and report code errors and issues.

```shell
npm run fix
npm run lint
```

### Fix

This command will start the `lint` task, which runs the `lint:php`, `lint:sass`, and `lint:js` tasks in series.
Correct all fixable code issues.

```shell
npm run lint
npm run fix
```

### Clean

This command will start the `clean` task, which will delete all built assets including those inside the `assets/dist` directory, as well as `languages/{textdomain}.pot`, `REAMDE.md`, and `style.css`.
Clean all built files.

```shell
npm run clean
Expand Down
2 changes: 1 addition & 1 deletion package/assets/src/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { announceEnqueued } from './modules/utils';

announceEnqueued('admin.js');
announceEnqueued('admin.js');
2 changes: 1 addition & 1 deletion package/assets/src/js/customizer-controls.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { announceEnqueued } from './modules/utils';

announceEnqueued('customizer-controls.js');
announceEnqueued('customizer-controls.js');
2 changes: 1 addition & 1 deletion package/assets/src/js/customizer-preview.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { announceEnqueued } from './modules/utils';

announceEnqueued('customizer-preview.js');
announceEnqueued('customizer-preview.js');
2 changes: 1 addition & 1 deletion package/assets/src/js/login.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { announceEnqueued } from './modules/utils';

announceEnqueued('login.js');
announceEnqueued('login.js');
2 changes: 1 addition & 1 deletion package/assets/src/md/COPYRIGHT.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
## Copyright

This is the copyright information for the theme and third-party resources.
This is the copyright information for the theme.
12 changes: 12 additions & 0 deletions package/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php
/**
* Functions
*
* @since 0.0.1
*/

// Require files.
require get_template_directory() . '/includes/class-wp-theme-assets.php';

// Initialize classes.
add_action( 'after_setup_theme', array( new WP_Theme_Assets(), 'init' ), 0 );
34 changes: 21 additions & 13 deletions package/includes/class-wp-theme-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,39 @@ class WP_Theme_Assets {
* @since 0.0.1
* @var string $theme_directory_uri
*/
public $theme_directory_uri;
public string $theme_directory_uri;

/**
* Theme Textdomain
*
* @since 0.0.1
* @var string $theme_textdomain
*/
public $theme_textdomain;
public string $theme_textdomain;

/**
* Theme Version
*
* @since 0.0.1
* @var string $theme_version
*/
public $theme_version;
public string $theme_version;

/**
* Assets Directory URI
*
* @since 0.0.1
* @var string $assets_directory_uri
*/
public $assets_directory_uri;
public string $assets_directory_uri;

/**
* Languages Directory URI
*
* @since 0.0.1
* @var string $languages_directory_uri
*/
public $languages_directory_uri;
public string $languages_directory_uri;

/**
* Construct
Expand All @@ -70,8 +70,9 @@ public function __construct() {
* Init
*
* @since 0.0.1
* @return void
*/
public function init() {
public function init(): void {
add_action( 'after_setup_theme', array( $this, 'load_languages' ), 10 );
add_action( 'after_setup_theme', array( $this, 'enqueue_editor_assets' ), 10 );
add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_site_assets' ), 10 );
Expand All @@ -85,8 +86,9 @@ public function init() {
* Load Languages
*
* @since 0.0.1
* @return void
*/
public function load_languages() {
public function load_languages(): void {
load_theme_textdomain(
$this->theme_textdomain,
$this->languages_directory_uri
Expand All @@ -97,17 +99,19 @@ public function load_languages() {
* Enqueue Editor Assets
*
* @since 0.0.1
* @return void
*/
public function enqueue_editor_assets() {
public function enqueue_editor_assets(): void {
add_editor_style( $this->assets_directory_uri . '/css/editor.min.css' );
}

/**
* Enqueue Site Assets
*
* @since 0.0.1
* @return void
*/
public function enqueue_site_assets() {
public function enqueue_site_assets(): void {
wp_enqueue_style(
$this->theme_textdomain,
$this->assets_directory_uri . '/css/site.min.css',
Expand All @@ -127,8 +131,9 @@ public function enqueue_site_assets() {
* Enqueue Admin Assets
*
* @since 0.0.1
* @return void
*/
public function enqueue_admin_assets() {
public function enqueue_admin_assets(): void {
wp_enqueue_style(
$this->theme_textdomain . '-admin',
$this->assets_directory_uri . '/css/admin.min.css',
Expand All @@ -148,8 +153,9 @@ public function enqueue_admin_assets() {
* Enqueue Login Assets
*
* @since 0.0.1
* @return void
*/
public function enqueue_login_assets() {
public function enqueue_login_assets(): void {
wp_enqueue_style(
$this->theme_textdomain . '-login',
$this->assets_directory_uri . '/css/login.min.css',
Expand All @@ -169,8 +175,9 @@ public function enqueue_login_assets() {
* Enqueue Customizer Preview Assets
*
* @since 0.0.1
* @return void
*/
public function enqueue_customizer_preview_assets() {
public function enqueue_customizer_preview_assets(): void {
wp_enqueue_style(
$this->theme_textdomain . '-customizer-preview',
$this->assets_directory_uri . '/css/customizer-preview.min.css',
Expand All @@ -190,8 +197,9 @@ public function enqueue_customizer_preview_assets() {
* Enqueue Customizer Controls Assets
*
* @since 0.0.1
* @return void
*/
public function enqueue_customizer_controls_assets() {
public function enqueue_customizer_controls_assets(): void {
wp_enqueue_style(
$this->theme_textdomain . '-customizer-controls',
$this->assets_directory_uri . '/css/customizer-controls.min.css',
Expand Down

0 comments on commit 2e25984

Please sign in to comment.