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

Remove shared assets #277

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion mu-plugins/10up-plugin/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
assets/js/vendor
assets/js/admin/vendor
assets/js/frontend/vendor
assets/js/shared/vendor
tests
dist
1 change: 0 additions & 1 deletion mu-plugins/10up-plugin/assets/css/frontend/base/index.css

This file was deleted.

This file was deleted.

7 changes: 0 additions & 7 deletions mu-plugins/10up-plugin/assets/css/frontend/global/colors.css

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions mu-plugins/10up-plugin/assets/css/frontend/style.css

This file was deleted.

6 changes: 0 additions & 6 deletions mu-plugins/10up-plugin/assets/css/shared/shared-style.css

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions mu-plugins/10up-plugin/assets/js/frontend/frontend.js

This file was deleted.

3 changes: 0 additions & 3 deletions mu-plugins/10up-plugin/assets/js/shared/shared.js

This file was deleted.

4 changes: 1 addition & 3 deletions mu-plugins/10up-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
},
"10up-toolkit": {
"entry": {
"admin": "./assets/js/admin/admin.js",
"frontend": "./assets/js/frontend/frontend.js",
"shared": "./assets/js/shared/shared.js"
"admin": "./assets/js/admin/admin.js"
},
"paths": {
"globalStylesDir": "../../themes/10up-theme/assets/css/globals/",
Expand Down
123 changes: 2 additions & 121 deletions mu-plugins/10up-plugin/src/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ public function can_register() {
* @return void
*/
public function register() {
add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'styles' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_styles' ] );

Expand All @@ -47,147 +45,30 @@ public function register() {
add_filter( 'script_loader_tag', [ $this, 'script_loader_tag' ], 10, 2 );
}

/**
* The list of knows contexts for enqueuing scripts/styles.
*
* @return array<string>
*/
protected function get_enqueue_contexts() {
return [ 'admin', 'frontend', 'shared' ];
}

/**
* Generate an URL to a script, taking into account whether SCRIPT_DEBUG is enabled.
*
* @param string $script Script file name (no .js extension)
* @param string $context Context for the script ('admin', 'frontend', or 'shared')
*
* @return string URL
* @throws \RuntimeException If an invalid $context is specified.
*/
public function script_url( $script, $context ) {

if ( ! in_array( $context, $this->get_enqueue_contexts(), true ) ) {
throw new \RuntimeException( 'Invalid $context specified in TenUpPlugin script loader.' );
}

return TENUP_PLUGIN_URL . "dist/js/{$script}.js";
}

/**
* Generate an URL to a stylesheet, taking into account whether SCRIPT_DEBUG is enabled.
*
* @param string $stylesheet Stylesheet file name (no .css extension)
* @param string $context Context for the script ('admin', 'frontend', or 'shared')
*
* @return string URL
* @throws \RuntimeException If an invalid $context is specified.
*/
public function style_url( $stylesheet, $context ) {

if ( ! in_array( $context, $this->get_enqueue_contexts(), true ) ) {
throw new \RuntimeException( 'Invalid $context specified in TenUpPlugin stylesheet loader.' );
}

return TENUP_PLUGIN_URL . "dist/css/{$stylesheet}.css";
}

/**
* Enqueue scripts for front-end.
*
* @return void
*/
public function scripts() {

wp_enqueue_script(
'tenup_plugin_shared',
$this->script_url( 'shared', 'shared' ),
$this->get_asset_info( 'shared', 'dependencies' ),
$this->get_asset_info( 'shared', 'version' ),
true
);

wp_enqueue_script(
'tenup_plugin_frontend',
$this->script_url( 'frontend', 'frontend' ),
$this->get_asset_info( 'frontend', 'dependencies' ),
$this->get_asset_info( 'frontend', 'version' ),
true
);
}

/**
* Enqueue scripts for admin.
*
* @return void
*/
public function admin_scripts() {

wp_enqueue_script(
'tenup_plugin_shared',
$this->script_url( 'shared', 'shared' ),
$this->get_asset_info( 'shared', 'dependencies' ),
$this->get_asset_info( 'shared', 'version' ),
true
);

wp_enqueue_script(
'tenup_plugin_admin',
$this->script_url( 'admin', 'admin' ),
TENUP_PLUGIN_URL . 'dist/js/admin.js',
$this->get_asset_info( 'admin', 'dependencies' ),
$this->get_asset_info( 'admin', 'version' ),
true
);
}

/**
* Enqueue styles for front-end.
*
* @return void
*/
public function styles() {

wp_enqueue_style(
'tenup_plugin_shared',
$this->style_url( 'shared', 'shared' ),
[],
$this->get_asset_info( 'shared', 'version' ),
);

if ( is_admin() ) {
wp_enqueue_style(
'tenup_plugin_admin',
$this->style_url( 'admin', 'admin' ),
[],
$this->get_asset_info( 'admin', 'version' ),
);
} else {
wp_enqueue_style(
'tenup_plugin_frontend',
$this->style_url( 'frontend', 'frontend' ),
[],
$this->get_asset_info( 'frontend', 'version' ),
);
}
}

/**
* Enqueue styles for admin.
*
* @return void
*/
public function admin_styles() {

wp_enqueue_style(
'tenup_plugin_shared',
$this->style_url( 'shared', 'shared' ),
[],
$this->get_asset_info( 'shared', 'version' ),
);

wp_enqueue_style(
'tenup_plugin_admin',
$this->style_url( 'admin', 'admin' ),
TENUP_PLUGIN_URL . 'dist/css/admin-style.css',
[],
$this->get_asset_info( 'admin', 'version' ),
);
Expand Down
1 change: 0 additions & 1 deletion themes/10up-theme/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
assets/js/vendor
assets/js/admin/vendor
assets/js/frontend/vendor
assets/js/shared/vendor
tests
dist
5 changes: 0 additions & 5 deletions themes/10up-theme/assets/css/admin/admin-style.css

This file was deleted.

6 changes: 0 additions & 6 deletions themes/10up-theme/assets/css/shared/shared-style.css

This file was deleted.

3 changes: 0 additions & 3 deletions themes/10up-theme/assets/js/admin/admin.js

This file was deleted.

2 changes: 0 additions & 2 deletions themes/10up-theme/assets/js/shared/shared.js

This file was deleted.

4 changes: 1 addition & 3 deletions themes/10up-theme/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,8 @@
"useBlockAssets": true,
"loadBlockSpecificStyles": true,
"entry": {
"admin": "./assets/js/admin/admin.js",
"editor-style-overrides": "./assets/js/admin/editor-style-overrides.js",
"editor-style-overrides": "./assets/js/frontend/editor-style-overrides.js",
"frontend": "./assets/js/frontend/frontend.js",
"shared": "./assets/js/shared/shared.js",
"block-editor-script": "./assets/js/block-editor/block-editor-script.js"
},
"paths": {
Expand Down
68 changes: 0 additions & 68 deletions themes/10up-theme/src/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public function can_register() {
*/
public function register() {
add_action( 'wp_enqueue_scripts', [ $this, 'scripts' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_styles' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'admin_scripts' ] );
add_action( 'enqueue_block_editor_assets', [ $this, 'enqueue_block_editor_scripts' ] );
add_action( 'wp_enqueue_scripts', [ $this, 'styles' ] );
add_action( 'wp_head', [ $this, 'js_detection' ], 0 );
Expand All @@ -65,48 +63,6 @@ public function scripts() {
$this->get_asset_info( 'frontend', 'version' ),
true
);

/**
* Enqueuing shared.js is required to get css hot reloading working in the frontend
* If you're not shipping any shared js wrap this enqueue in a SCRIPT_DEBUG check.
*/

/*
* Uncoment this to use the shared.js file.
wp_enqueue_script(
'shared',
TENUP_THEME_TEMPLATE_URL . '/dist/js/shared.js',
$this->get_asset_info( 'shared', 'dependencies' ),
$this->get_asset_info( 'shared', 'version' ),
true
);
*/
}

/**
* Enqueue scripts for admin
*
* @return void
*/
public function admin_scripts() {
wp_enqueue_script(
'admin',
TENUP_THEME_TEMPLATE_URL . '/dist/js/admin.js',
$this->get_asset_info( 'admin', 'dependencies' ),
$this->get_asset_info( 'admin', 'version' ),
true
);

/*
* Uncoment this to use the shared.js file.
wp_enqueue_script(
'shared',
TENUP_THEME_TEMPLATE_URL . '/dist/js/shared.js',
$this->get_asset_info( 'shared', 'dependencies' ),
$this->get_asset_info( 'shared', 'version' ),
true
);
*/
}

/**
Expand All @@ -124,30 +80,6 @@ public function enqueue_block_editor_scripts() {
);
}

/**
* Enqueue styles for admin
*
* @return void
*/
public function admin_styles() {
wp_enqueue_style(
'admin-style',
TENUP_THEME_TEMPLATE_URL . '/dist/css/admin.css',
[],
$this->get_asset_info( 'admin-style', 'version' )
);

/*
* Uncoment this to use the shared.css file.
wp_enqueue_style(
'shared-style',
TENUP_THEME_TEMPLATE_URL . '/dist/css/shared.css',
[],
$this->get_asset_info( 'shared', 'version' )
);
*/
}

/**
* Enqueue styles for front-end.
*
Expand Down
Loading