@wordpress/build 0.9.0 → 0.10.1-next.v.202603102151.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.cjs +6 -0
- package/CHANGELOG.md +11 -0
- package/lib/build.mjs +53 -54
- package/package.json +2 -2
- package/templates/module-registration.php.template +32 -34
- package/templates/page-wp-admin.php.template +222 -236
- package/templates/page.php.template +264 -278
- package/templates/routes-page-functions.php.template +12 -16
- package/templates/routes-registration.php.template +49 -45
- package/templates/script-registration.php.template +65 -69
- package/templates/style-registration.php.template +52 -56
|
@@ -32,57 +32,61 @@ foreach ( $routes_by_page as $page_slug => $page_routes ) {
|
|
|
32
32
|
$GLOBALS[ $global_name ] = $page_routes;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
$build_constants = require __DIR__ . '/constants.php';
|
|
35
|
+
/**
|
|
36
|
+
* Generic helper function to register routes for a page.
|
|
37
|
+
*
|
|
38
|
+
* @param array $page_routes Array of route data for the page.
|
|
39
|
+
* @param string $register_function_name Name of the function to call for registering each route.
|
|
40
|
+
*/
|
|
41
|
+
function {{PREFIX}}_register_page_routes( $page_routes, $register_function_name ) {
|
|
42
|
+
// Load build constants
|
|
43
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
foreach ( $page_routes as $route ) {
|
|
46
|
+
$content_handle = null;
|
|
47
|
+
$route_handle = null;
|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
49
|
+
// Register content module if exists
|
|
50
|
+
if ( $route['has_content'] ) {
|
|
51
|
+
$content_asset_path = __DIR__ . "/routes/{$route['name']}/content.min.asset.php";
|
|
52
|
+
if ( file_exists( $content_asset_path ) ) {
|
|
53
|
+
$content_asset = require $content_asset_path;
|
|
54
|
+
$content_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/content';
|
|
55
|
+
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
56
|
+
// Deregister first to override any previously registered version
|
|
57
|
+
// (e.g., Core's default modules when running as a plugin).
|
|
58
|
+
wp_deregister_script_module( $content_handle );
|
|
59
|
+
wp_register_script_module(
|
|
60
|
+
$content_handle,
|
|
61
|
+
$build_constants['build_url'] . 'routes/' . $route['name'] . '/content' . $extension,
|
|
62
|
+
$content_asset['module_dependencies'] ?? array(),
|
|
63
|
+
$content_asset['version'] ?? false
|
|
64
|
+
);
|
|
64
65
|
}
|
|
66
|
+
}
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
// Register route module if exists
|
|
69
|
+
if ( $route['has_route'] ) {
|
|
70
|
+
$route_asset_path = __DIR__ . "/routes/{$route['name']}/route.min.asset.php";
|
|
71
|
+
if ( file_exists( $route_asset_path ) ) {
|
|
72
|
+
$route_asset = require $route_asset_path;
|
|
73
|
+
$route_handle = '{{HANDLE_PREFIX}}/routes/' . $route['name'] . '/route';
|
|
74
|
+
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
75
|
+
// Deregister first to override any previously registered version
|
|
76
|
+
// (e.g., Core's default modules when running as a plugin).
|
|
77
|
+
wp_deregister_script_module( $route_handle );
|
|
78
|
+
wp_register_script_module(
|
|
79
|
+
$route_handle,
|
|
80
|
+
$build_constants['build_url'] . 'routes/' . $route['name'] . '/route' . $extension,
|
|
81
|
+
$route_asset['module_dependencies'] ?? array(),
|
|
82
|
+
$route_asset['version'] ?? false
|
|
83
|
+
);
|
|
80
84
|
}
|
|
85
|
+
}
|
|
81
86
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
87
|
+
// Register route with page
|
|
88
|
+
if ( function_exists( $register_function_name ) ) {
|
|
89
|
+
call_user_func( $register_function_name, $route['path'], $content_handle, $route_handle );
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
}
|
|
@@ -6,84 +6,80 @@
|
|
|
6
6
|
* @package {{PREFIX}}
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*/
|
|
9
|
+
/**
|
|
10
|
+
* Registers a script according to `wp_register_script`. Honors this request by
|
|
11
|
+
* reassigning internal dependency properties of any script handle already
|
|
12
|
+
* registered by that name. It does not deregister the original script, to
|
|
13
|
+
* avoid losing inline scripts which may have been attached.
|
|
14
|
+
*
|
|
15
|
+
* @param WP_Scripts $scripts WP_Scripts instance.
|
|
16
|
+
* @param string $handle Name of the script. Should be unique.
|
|
17
|
+
* @param string $src Full URL of the script, or path of the script relative to the WordPress root directory.
|
|
18
|
+
* @param array $deps Optional. An array of registered script handles this script depends on. Default empty array.
|
|
19
|
+
* @param string|bool|null $ver Optional. String specifying script version number, if it has one, which is added to the URL
|
|
20
|
+
* as a query string for cache busting purposes. If version is set to false, a version
|
|
21
|
+
* number is automatically added equal to current installed WordPress version.
|
|
22
|
+
* If set to null, no version is added.
|
|
23
|
+
* @param bool $in_footer Optional. Whether to enqueue the script before </body> instead of in the <head>.
|
|
24
|
+
* Default 'false'.
|
|
25
|
+
*/
|
|
26
|
+
function {{PREFIX}}_override_script( $scripts, $handle, $src, $deps = array(), $ver = false, $in_footer = false ) {
|
|
27
|
+
$script = $scripts->query( $handle, 'registered' );
|
|
28
|
+
if ( $script ) {
|
|
29
|
+
/*
|
|
30
|
+
* In many ways, this is a reimplementation of `wp_register_script` but
|
|
31
|
+
* bypassing consideration of whether a script by the given handle had
|
|
32
|
+
* already been registered.
|
|
33
|
+
*/
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
// See: `_WP_Dependency::__construct` .
|
|
36
|
+
$script->src = $src;
|
|
37
|
+
$script->deps = $deps;
|
|
38
|
+
$script->ver = $ver;
|
|
39
|
+
$script->args = $in_footer ? 1 : null;
|
|
40
|
+
} else {
|
|
41
|
+
$scripts->add( $handle, $src, $deps, $ver, ( $in_footer ? 1 : null ) );
|
|
42
|
+
}
|
|
44
43
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
44
|
+
if ( in_array( 'wp-i18n', $deps, true ) ) {
|
|
45
|
+
$scripts->set_translations( $handle );
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
49
|
+
/**
|
|
50
|
+
* Register all package scripts.
|
|
51
|
+
*/
|
|
52
|
+
function {{PREFIX}}_register_package_scripts( $scripts ) {
|
|
53
|
+
// Load build constants
|
|
54
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
55
|
+
$default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
|
|
56
|
+
$extension = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '.js' : '.min.js';
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
58
|
+
$scripts_dir = __DIR__ . '/scripts';
|
|
59
|
+
$scripts_file = $scripts_dir . '/registry.php';
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
if ( ! file_exists( $scripts_file ) ) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
67
64
|
|
|
68
|
-
|
|
69
|
-
|
|
65
|
+
$scripts_data = require $scripts_file;
|
|
66
|
+
$plugin_dir = dirname( __FILE__ );
|
|
70
67
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
68
|
+
foreach ( $scripts_data as $script_data ) {
|
|
69
|
+
$asset_file = $scripts_dir . '/' . $script_data['asset'];
|
|
70
|
+
$asset = file_exists( $asset_file ) ? require $asset_file : array();
|
|
71
|
+
$dependencies = $asset['dependencies'] ?? array();
|
|
72
|
+
$version = $asset['version'] ?? $default_version;
|
|
76
73
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
}
|
|
74
|
+
{{PREFIX}}_override_script(
|
|
75
|
+
$scripts,
|
|
76
|
+
$script_data['handle'],
|
|
77
|
+
$build_constants['build_url'] . 'scripts/' . $script_data['path'] . $extension,
|
|
78
|
+
$dependencies,
|
|
79
|
+
$version,
|
|
80
|
+
true
|
|
81
|
+
);
|
|
86
82
|
}
|
|
87
|
-
|
|
88
|
-
add_action( 'wp_default_scripts', '{{PREFIX}}_register_package_scripts' );
|
|
89
83
|
}
|
|
84
|
+
|
|
85
|
+
add_action( 'wp_default_scripts', '{{PREFIX}}_register_package_scripts' );
|
|
@@ -9,69 +9,65 @@
|
|
|
9
9
|
* @package {{PREFIX}}
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
$styles->remove( $handle );
|
|
33
|
-
}
|
|
34
|
-
$styles->add( $handle, $src, $deps, $ver, $media );
|
|
12
|
+
/**
|
|
13
|
+
* Registers a style according to `wp_register_style`. Honors this request by
|
|
14
|
+
* deregistering any style by the same handler before registration.
|
|
15
|
+
*
|
|
16
|
+
* @param WP_Styles $styles WP_Styles instance.
|
|
17
|
+
* @param string $handle Name of the stylesheet. Should be unique.
|
|
18
|
+
* @param string $src Full URL of the stylesheet, or path of the stylesheet relative to the WordPress root directory.
|
|
19
|
+
* @param array $deps Optional. An array of registered stylesheet handles this stylesheet depends on. Default empty array.
|
|
20
|
+
* @param string|bool|null $ver Optional. String specifying stylesheet version number, if it has one, which is added to the URL
|
|
21
|
+
* as a query string for cache busting purposes. If version is set to false, a version
|
|
22
|
+
* number is automatically added equal to current installed WordPress version.
|
|
23
|
+
* If set to null, no version is added.
|
|
24
|
+
* @param string $media Optional. The media for which this stylesheet has been defined.
|
|
25
|
+
* Default 'all'. Accepts media types like 'all', 'print' and 'screen', or media queries like
|
|
26
|
+
* '(orientation: portrait)' and '(max-width: 640px)'.
|
|
27
|
+
*/
|
|
28
|
+
function {{PREFIX}}_override_style( $styles, $handle, $src, $deps = array(), $ver = false, $media = 'all' ) {
|
|
29
|
+
$style = $styles->query( $handle, 'registered' );
|
|
30
|
+
if ( $style ) {
|
|
31
|
+
$styles->remove( $handle );
|
|
35
32
|
}
|
|
33
|
+
$styles->add( $handle, $src, $deps, $ver, $media );
|
|
36
34
|
}
|
|
37
35
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
$suffix = SCRIPT_DEBUG ? '' : '.min';
|
|
36
|
+
/**
|
|
37
|
+
* Register all package styles (simple cases only).
|
|
38
|
+
* Complex cases should be manually registered in lib/client-assets.php.
|
|
39
|
+
*
|
|
40
|
+
* @param WP_Styles $styles WP_Styles instance.
|
|
41
|
+
*/
|
|
42
|
+
function {{PREFIX}}_register_package_styles( $styles ) {
|
|
43
|
+
// Load build constants
|
|
44
|
+
$build_constants = require __DIR__ . '/constants.php';
|
|
45
|
+
$default_version = ! SCRIPT_DEBUG ? $build_constants['version'] : time();
|
|
46
|
+
$suffix = SCRIPT_DEBUG ? '' : '.min';
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
$styles_dir = __DIR__ . '/styles';
|
|
49
|
+
$styles_file = $styles_dir . '/registry.php';
|
|
53
50
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
if ( ! file_exists( $styles_file ) ) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
57
54
|
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
$styles_data = require $styles_file;
|
|
56
|
+
$plugin_dir = dirname( __FILE__ );
|
|
60
57
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
foreach ( $styles_data as $style_data ) {
|
|
59
|
+
{{PREFIX}}_override_style(
|
|
60
|
+
$styles,
|
|
61
|
+
$style_data['handle'],
|
|
62
|
+
$build_constants['build_url'] . 'styles/' . $style_data['path'] . $suffix . '.css',
|
|
63
|
+
$style_data['dependencies'],
|
|
64
|
+
$default_version
|
|
65
|
+
);
|
|
69
66
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
67
|
+
// Enable RTL support (WordPress automatically loads -rtl.css variant)
|
|
68
|
+
$styles->add_data( $style_data['handle'], 'rtl', 'replace' );
|
|
69
|
+
$styles->add_data( $style_data['handle'], 'suffix', $suffix );
|
|
74
70
|
}
|
|
75
|
-
|
|
76
|
-
add_action( 'wp_default_styles', '{{PREFIX}}_register_package_styles' );
|
|
77
71
|
}
|
|
72
|
+
|
|
73
|
+
add_action( 'wp_default_styles', '{{PREFIX}}_register_package_styles' );
|