Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete rewrite #2

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 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
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
root = true

[*]
indent_style = space
indent_size = 2
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
end_of_line = lf

[*.php]
indent_size = 4

[*.md]
indent_size = 4
trim_trailing_whitespace = false
31 changes: 31 additions & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Tests
on: [push, pull_request]
jobs:
bedrock:
name: ScriptsStylesLoader (PHP ${{ matrix.php-versions }})
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3']
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP, with composer and extensions
uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php
with:
php-version: ${{ matrix.php-versions }}
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
# Use composer.json for key, if composer.lock is not committed.
# key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install -n --prefer-dist
- name: PHP test
run: composer check
91 changes: 52 additions & 39 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
name: Release

on:
push:
tags:
- '*'

- '*'
jobs:
release:
runs-on: ubuntu-latest
Expand All @@ -17,56 +15,71 @@ jobs:
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF#refs/tags/}
- name: Setup php
uses: shivammathur/setup-php@v2
with:
php-version: '7.3'
- name: Setup node
uses: actions/setup-node@v1
with:
node-version: '12.x'
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v1
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Composer Install
run: composer install --no-dev
- name: Get yarn cache directory
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- name: Cache yarn dependencies
uses: actions/cache@v1
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Yarn Install
run: yarn install
- name: Yarn Build
run: yarn build
- name: Create Zip File
uses: thedoctor0/zip-release@master
if: startsWith(github.ref, 'refs/tags/')
with:
filename: '${{ steps.get_repo_name.outputs.REPOSITORY_NAME }}.zip'
exclusions: '.babelrc
.circleci/config.yml
.deployignore
exclusions: '*.git*
*.lock
*.log
.distignore
.DS_Store
.editorconfig
.eslint*
.idea
.phpcs.xml
.phpcs.xml.dist
.travis.yml
.vscode
*.git*
*.lock
*.log
*.sql
*.tar.gz
*.zip
behat.yml
bin
bitbucket-pipelines.yml
circle.yml
composer*
dependencies.yml
Gruntfile.js
.phpunit.result.cache
composer.json
docker*
gulp*
multisite.*
node_modules
package*
phpcs*
phpunit*
phpcs.xml
phpstan.neon
phpunit.xml.dist
README.md
src
require-checker.config.json
stylelint*
tests
Thumbs.db
tsconfig.json
vendor
webpack.config.js
wp-cli.local.yml'
/assets/src/*
/docker/*
/node_modules/*
/test/*
/wordpress/*'
- name: Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: ${{ steps.get_repo_name.outputs.REPOSITORY_NAME }}.zip
name: Version ${{ steps.get_version.outputs.VERSION }}
files: ${{ steps.get_repo_name.outputs.REPOSITORY_NAME }}.zip
name: Version ${{ steps.get_version.outputs.VERSION }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
59 changes: 11 additions & 48 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,55 +1,18 @@
### Plugin ###
assets

# GulpPress Local Config
gulppress.local.config.ts

### Logs ###
*.log

### Dotenv ###
.env
.env.*
!.env.example

### Composer ###
/vendor

### WP-CLI ###
wp-cli.local.yml

### Database dumps ###
db-sync
*.sql
/assets/*
!/assets/src/
/wordpress/

### Composer ###
vendor
/vendor/
/composer.lock

### Node ###
.node/
node_modules/
npm-debug.log
.npmrc

### Log files ###
**/log
npm-debug.log*
yarn-error.log*

### Mac OSX + Windows ###
.DS_Store
Thumbs.db

### Vim ###
*.sw[op]
*.un~
/node_modules/
/yarn.lock

### Editor directory ###
.idea
.vscode
**/.idea
**/.vscode
### GulpPress Local Config ###
/gulppress.local.config.ts

### Archives ###
*.tar.gz
*.zip
## Tests ###
/infection-log.txt
2 changes: 0 additions & 2 deletions .idea/.gitignore

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/composerJson.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/misc.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/php.xml

This file was deleted.

13 changes: 0 additions & 13 deletions .idea/scripts-styles-loader.iml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

85 changes: 84 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,84 @@
# wplib-AssetLoader
# WordPress Plugin - Woda Scripts Styles Loader

> Load assets without the hassle

## Installation

You can install the plugin by uploading it in the WordPress Admin or via `composer`.

```bash
composer require woda/wp-scripts-styles-loader
```

## Configure

Pass the settings to the init function or hook into the supplied filter

```php
use Woda\WordPress\ScriptsStylesLoader\HashFile;
use Woda\WordPress\ScriptsStylesLoader\Script;
use Woda\WordPress\ScriptsStylesLoader\Style;

// Import a json containing cache busting hash values, versions, etc.
$scriptsHashFile = new HashFile(get_stylesheet_directory() . '/assets/js/.assets.json');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe describe format of assets.json or reference the node package that is creating this
and maybe reference to gulppress


/**
* Create a Script Helper
*
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
* @param string[] $deps Optional. An array of registered script handles this script depends on. Default empty array.
* @param string $handle Optional. Name of the script. Should be unique.
* If empty, handle will be generated from prefix and file name.
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
* as a query string for cache busting purposes. If version is set to false, a version
* number is automatically added equal to current installed WordPress version.
* If set to null, no version is added.
* @param string $inFooter Optional. Whether to enqueue the script before </body> instead of in the <head>.
* Default 'false'.
*/
(new Script(get_stylesheet_directory_uri() . '/assets/js/main.js', ['jquery'], null, null, true))
// Cache busting via a hash file
->addHashFile($scriptsHashFile)
// Enqueue in the frontend.
->enqueue()
// Enqueue in the backend.
->enqueueAdmin();

// Replace jQuery in the frontend with your own version
(new Script(get_stylesheet_directory_uri() . '/assets/js/vendor/jquery.js', ['jquery-core', 'jquery-migrate'], 'jquery'))
// Calculate an md5 hash value for cache busting purposes.
->calculateHashValue()
// Deregister the handle we are about to reregister
->deregister()
// Register our replacement
->register();


$stylesHashFile = new HashFile(get_stylesheet_directory() . '/assets/css/.assets.json');
/**
* Create a Style Helper
*
* @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
* @param string[] $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
* @param string $handle Optional. Name of the stylesheet. Should be unique.
* If empty, handle will be generated from prefix and file name.
* @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
* as a query string for cache busting purposes. If version is set to false, a version
* number is automatically added equal to current installed WordPress version.
* If set to null, no version is added.
* @param string $media Optional. The media for which this stylesheet has been defined.
* Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
* '(orientation: portrait)' and '(max-width: 640px)'.
*/
(new Style(get_stylesheet_directory_uri() . '/assets/css/main.css'))
->addHashFile($stylesHashFile)
->enqueue();
(new Style(get_stylesheet_directory_uri() . '/assets/css/admin.css'))
->addHashFile($stylesHashFile)
->enqueueAdmin();
(new Style(get_stylesheet_directory_uri() . '/assets/css/editor2.css'))
->addHashFile($stylesHashFile)
// Add an editor style
// https://codex.wordpress.org/Editor_Style
->enqueueEditor();
```
Loading