From d45d7dd64b34c308cd9bcfe223d0def466833438 Mon Sep 17 00:00:00 2001 From: Paul Sealock Date: Wed, 7 Dec 2022 07:16:40 +1300 Subject: [PATCH] Add WooCommerce Extension environment scaffold (#35755) --- .../js/create-extension/$slug.php.mustache | 84 +++ .../create-extension/.editorconfig.mustache | 27 + .../js/create-extension/.eslintrc.js.mustache | 6 + .../js/create-extension/.gitignore.mustache | 62 +++ .../.prettierrc.json.mustache | 1 + .../js/create-extension/.wp-env.json.mustache | 13 + packages/js/create-extension/README.md | 19 + .../js/create-extension/README.md.mustache | 20 + .../js/create-extension/changelog/.gitkeep | 0 .../js/create-extension/changelog/add-dev-env | 5 + packages/js/create-extension/composer.json | 32 ++ .../create-extension/composer.json.mustache | 18 + packages/js/create-extension/composer.lock | 483 ++++++++++++++++++ .../includes/Admin/Setup.php.mustache | 81 +++ packages/js/create-extension/index.js | 17 + .../languages/woo-plugin-setup.pot.mustache | 45 ++ packages/js/create-extension/package.json | 25 + .../js/create-extension/src/index.js.mustache | 27 + .../create-extension/src/index.scss.mustache | 3 + .../create-extension/tests/Test.php.mustache | 15 + .../webpack.config.js.mustache | 13 + 21 files changed, 996 insertions(+) create mode 100644 packages/js/create-extension/$slug.php.mustache create mode 100644 packages/js/create-extension/.editorconfig.mustache create mode 100644 packages/js/create-extension/.eslintrc.js.mustache create mode 100644 packages/js/create-extension/.gitignore.mustache create mode 100644 packages/js/create-extension/.prettierrc.json.mustache create mode 100644 packages/js/create-extension/.wp-env.json.mustache create mode 100644 packages/js/create-extension/README.md create mode 100644 packages/js/create-extension/README.md.mustache create mode 100644 packages/js/create-extension/changelog/.gitkeep create mode 100644 packages/js/create-extension/changelog/add-dev-env create mode 100644 packages/js/create-extension/composer.json create mode 100644 packages/js/create-extension/composer.json.mustache create mode 100644 packages/js/create-extension/composer.lock create mode 100644 packages/js/create-extension/includes/Admin/Setup.php.mustache create mode 100644 packages/js/create-extension/index.js create mode 100644 packages/js/create-extension/languages/woo-plugin-setup.pot.mustache create mode 100644 packages/js/create-extension/package.json create mode 100644 packages/js/create-extension/src/index.js.mustache create mode 100644 packages/js/create-extension/src/index.scss.mustache create mode 100644 packages/js/create-extension/tests/Test.php.mustache create mode 100644 packages/js/create-extension/webpack.config.js.mustache diff --git a/packages/js/create-extension/$slug.php.mustache b/packages/js/create-extension/$slug.php.mustache new file mode 100644 index 00000000000..cad48cdb97c --- /dev/null +++ b/packages/js/create-extension/$slug.php.mustache @@ -0,0 +1,84 @@ +=5.6", + "symfony/console": "^3.4 || ^5.2", + "symfony/process": "^3.4 || ^5.2", + "wikimedia/at-ease": "^1.2 || ^2.0" + }, + "require-dev": { + "wikimedia/testing-access-wrapper": "^1.0 || ^2.0", + "yoast/phpunit-polyfills": "1.0.3" + }, + "bin": [ + "bin/changelogger" + ], + "type": "project", + "extra": { + "autotagger": true, + "branch-alias": { + "dev-trunk": "3.1.x-dev" + }, + "mirror-repo": "Automattic/jetpack-changelogger", + "version-constants": { + "::VERSION": "src/Application.php" + }, + "changelogger": { + "link-template": "https://github.com/Automattic/jetpack-changelogger/compare/${old}...${new}" + } + }, + "autoload": { + "psr-4": { + "Automattic\\Jetpack\\Changelog\\": "lib", + "Automattic\\Jetpack\\Changelogger\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "description": "Jetpack Changelogger tool. Allows for managing changelogs by dropping change files into a changelog directory with each PR.", + "support": { + "source": "https://github.com/Automattic/jetpack-changelogger/tree/v3.1.3" + }, + "time": "2022-06-21T07:31:56+00:00" + }, + { + "name": "psr/log", + "version": "1.1.4", + "source": { + "type": "git", + "url": "https://github.com/php-fig/log.git", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-fig/log/zipball/d49695b909c3b7628b6289db5479a1c204601f11", + "reference": "d49695b909c3b7628b6289db5479a1c204601f11", + "shasum": "" + }, + "require": { + "php": ">=5.3.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Psr\\Log\\": "Psr/Log/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "PHP-FIG", + "homepage": "https://www.php-fig.org/" + } + ], + "description": "Common interface for logging libraries", + "homepage": "https://github.com/php-fig/log", + "keywords": [ + "log", + "psr", + "psr-3" + ], + "support": { + "source": "https://github.com/php-fig/log/tree/1.1.4" + }, + "time": "2021-05-03T11:20:27+00:00" + }, + { + "name": "symfony/console", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/console.git", + "reference": "a10b1da6fc93080c180bba7219b5ff5b7518fe81" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/console/zipball/a10b1da6fc93080c180bba7219b5ff5b7518fe81", + "reference": "a10b1da6fc93080c180bba7219b5ff5b7518fe81", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8", + "symfony/debug": "~2.8|~3.0|~4.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/dependency-injection": "<3.4", + "symfony/process": "<3.3" + }, + "provide": { + "psr/log-implementation": "1.0" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "~3.3|~4.0", + "symfony/dependency-injection": "~3.4|~4.0", + "symfony/event-dispatcher": "~2.8|~3.0|~4.0", + "symfony/lock": "~3.4|~4.0", + "symfony/process": "~3.3|~4.0" + }, + "suggest": { + "psr/log": "For using the console logger", + "symfony/event-dispatcher": "", + "symfony/lock": "", + "symfony/process": "" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Console\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Console Component", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/console/tree/3.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-24T10:57:07+00:00" + }, + { + "name": "symfony/debug", + "version": "4.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/debug.git", + "reference": "1a692492190773c5310bc7877cb590c04c2f05be" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/debug/zipball/1a692492190773c5310bc7877cb590c04c2f05be", + "reference": "1a692492190773c5310bc7877cb590c04c2f05be", + "shasum": "" + }, + "require": { + "php": ">=7.1.3", + "psr/log": "^1|^2|^3" + }, + "conflict": { + "symfony/http-kernel": "<3.4" + }, + "require-dev": { + "symfony/http-kernel": "^3.4|^4.0|^5.0" + }, + "default-branch": true, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Debug\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides tools to ease debugging PHP code", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/debug/tree/v4.4.44" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "abandoned": "symfony/error-handler", + "time": "2022-07-28T16:29:46+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "dev-main", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-mbstring": "*" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "default-branch": true, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, + { + "name": "symfony/process", + "version": "3.4.x-dev", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "b8648cf1d5af12a44a51d07ef9bf980921f15fca" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/b8648cf1d5af12a44a51d07ef9bf980921f15fca", + "reference": "b8648cf1d5af12a44a51d07ef9bf980921f15fca", + "shasum": "" + }, + "require": { + "php": "^5.5.9|>=7.0.8" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/process/tree/3.4" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-10-24T10:57:07+00:00" + }, + { + "name": "wikimedia/at-ease", + "version": "v2.0.0", + "source": { + "type": "git", + "url": "https://github.com/wikimedia/at-ease.git", + "reference": "013ac61929797839c80a111a3f1a4710d8248e7a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/wikimedia/at-ease/zipball/013ac61929797839c80a111a3f1a4710d8248e7a", + "reference": "013ac61929797839c80a111a3f1a4710d8248e7a", + "shasum": "" + }, + "require": { + "php": ">=5.6.99" + }, + "require-dev": { + "jakub-onderka/php-console-highlighter": "0.3.2", + "jakub-onderka/php-parallel-lint": "1.0.0", + "mediawiki/mediawiki-codesniffer": "22.0.0", + "mediawiki/minus-x": "0.3.1", + "ockcyp/covers-validator": "0.5.1 || 0.6.1", + "phpunit/phpunit": "4.8.36 || ^6.5" + }, + "type": "library", + "autoload": { + "files": [ + "src/Wikimedia/Functions.php" + ], + "psr-4": { + "Wikimedia\\AtEase\\": "src/Wikimedia/AtEase/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "GPL-2.0-or-later" + ], + "authors": [ + { + "name": "Tim Starling", + "email": "tstarling@wikimedia.org" + }, + { + "name": "MediaWiki developers", + "email": "wikitech-l@lists.wikimedia.org" + } + ], + "description": "Safe replacement to @ for suppressing warnings.", + "homepage": "https://www.mediawiki.org/wiki/at-ease", + "support": { + "source": "https://github.com/wikimedia/at-ease/tree/master" + }, + "time": "2018-10-10T15:39:06+00:00" + } + ], + "aliases": [], + "minimum-stability": "dev", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "platform-overrides": { + "php": "7.2" + }, + "plugin-api-version": "2.3.0" +} diff --git a/packages/js/create-extension/includes/Admin/Setup.php.mustache b/packages/js/create-extension/includes/Admin/Setup.php.mustache new file mode 100644 index 00000000000..43e5c6723e6 --- /dev/null +++ b/packages/js/create-extension/includes/Admin/Setup.php.mustache @@ -0,0 +1,81 @@ + array(), + 'version' => filemtime( $script_path ), + ); + $script_url = plugins_url( $script_path, MAIN_PLUGIN_FILE ); + + wp_register_script( + '{{slug}}', + $script_url, + $script_asset['dependencies'], + $script_asset['version'], + true + ); + + wp_register_style( + '{{slug}}', + plugins_url( '/build/index.css', MAIN_PLUGIN_FILE ), + // Add any dependencies styles may have, such as wp-components. + array(), + filemtime( dirname( MAIN_PLUGIN_FILE ) . '/build/index.css' ) + ); + + wp_enqueue_script( '{{slug}}' ); + wp_enqueue_style( '{{slug}}' ); + } + + /** + * Register page in wc-admin. + * + * @since 1.0.0 + */ + public function register_page() { + + if ( ! function_exists( 'wc_admin_register_page' ) ) { + return; + } + + wc_admin_register_page( + array( + 'id' => '{{slugSnakeCase}}-example-page', + 'title' => __( '{{title}}', '{{slugSnakeCase}}' ), + 'parent' => 'woocommerce', + 'path' => '/{{slug}}', + ) + ); + } +} diff --git a/packages/js/create-extension/index.js b/packages/js/create-extension/index.js new file mode 100644 index 00000000000..b4af0d6a82e --- /dev/null +++ b/packages/js/create-extension/index.js @@ -0,0 +1,17 @@ +module.exports = { + templatesPath: __dirname, + defaultValues: { + npmDependencies: [ '@wordpress/hooks', '@wordpress/i18n' ], + npmDevDependencies: [ + '@woocommerce/dependency-extraction-webpack-plugin', + '@woocommerce/eslint-plugin', + '@wordpress/prettier-config', + '@wordpress/scripts', + ], + namespace: 'extension', + license: 'GPL-3.0+', + }, + customScripts: { + postinstall: 'composer install', + }, +}; diff --git a/packages/js/create-extension/languages/woo-plugin-setup.pot.mustache b/packages/js/create-extension/languages/woo-plugin-setup.pot.mustache new file mode 100644 index 00000000000..6b65dab9437 --- /dev/null +++ b/packages/js/create-extension/languages/woo-plugin-setup.pot.mustache @@ -0,0 +1,45 @@ +# Copyright (C) 2022 WooCommerce +# This file is distributed under the GNU General Public License v3.0. +msgid "" +msgstr "" +"Project-Id-Version: Woo Plugin Setup 1.0.0\n" +"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/{{slug}}\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"POT-Creation-Date: 2022-11-27T21:35:18+00:00\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"X-Generator: WP-CLI 2.7.1\n" +"X-Domain: {{slug}}\n" + +#. Plugin Name of the plugin +msgid "Woo Plugin Setup" +msgstr "" + +#. Plugin URI of the plugin +msgid "https://github.com/psealock/woo-plugin-setup" +msgstr "" + +#. Description of the plugin +msgid "This is an example of an extension template to follow." +msgstr "" + +#. Author of the plugin +msgid "WooCommerce" +msgstr "" + +#. Author URI of the plugin +msgid "https://woocommerce.com" +msgstr "" + +#: build/index.js:1 +#: src/index.js:13 +msgid "My Example Extension" +msgstr "" + +#: build/index.js:1 +#: src/index.js:20 +msgid "My Example Page" +msgstr "" diff --git a/packages/js/create-extension/package.json b/packages/js/create-extension/package.json new file mode 100644 index 00000000000..27940cc14a0 --- /dev/null +++ b/packages/js/create-extension/package.json @@ -0,0 +1,25 @@ +{ + "name": "@woocommerce/create-extension", + "version": "1.0.0", + "description": "A template to be used with `@wordpress/create-block` to create a WooCommerce extension.", + "main": "index.js", + "engines": { + "node": "^16.13.1", + "pnpm": "^7.13.3" + }, + "scripts": { + "postinstall": "composer install", + "changelog": "composer exec -- changelogger" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/woocommerce/woocommerce.git" + }, + "keywords": [], + "author": "", + "license": "GPL-3.0+", + "bugs": { + "url": "https://github.com/woocommerce/woocommerce/issues" + }, + "homepage": "https://github.com/woocommerce/woocommerce/tree/trunk/packages/js/create-extensionv#readme" +} diff --git a/packages/js/create-extension/src/index.js.mustache b/packages/js/create-extension/src/index.js.mustache new file mode 100644 index 00000000000..f4ea611bfc8 --- /dev/null +++ b/packages/js/create-extension/src/index.js.mustache @@ -0,0 +1,27 @@ +/** + * External dependencies + */ +import { addFilter } from '@wordpress/hooks'; +import { __ } from '@wordpress/i18n'; + +/** + * Internal dependencies + */ +import './index.scss'; + +const MyExamplePage = () => ( +

{ __( 'My Example Extension', '{{textdomain}}' ) }

+); + +addFilter( 'woocommerce_admin_pages_list', '{{slug}}', ( pages ) => { + pages.push( { + container: MyExamplePage, + path: '/{{slug}}', + breadcrumbs: [ __( '{{title}}', '{{textdomain}}' ) ], + navArgs: { + id: '{{slugSnakeCase}}', + }, + } ); + + return pages; +} ); diff --git a/packages/js/create-extension/src/index.scss.mustache b/packages/js/create-extension/src/index.scss.mustache new file mode 100644 index 00000000000..b0130a56356 --- /dev/null +++ b/packages/js/create-extension/src/index.scss.mustache @@ -0,0 +1,3 @@ +h1 { + background-color: gold; +} diff --git a/packages/js/create-extension/tests/Test.php.mustache b/packages/js/create-extension/tests/Test.php.mustache new file mode 100644 index 00000000000..2a23d935674 --- /dev/null +++ b/packages/js/create-extension/tests/Test.php.mustache @@ -0,0 +1,15 @@ +assertEquals( 1, 1 ); + } +} diff --git a/packages/js/create-extension/webpack.config.js.mustache b/packages/js/create-extension/webpack.config.js.mustache new file mode 100644 index 00000000000..7c211bc7ca0 --- /dev/null +++ b/packages/js/create-extension/webpack.config.js.mustache @@ -0,0 +1,13 @@ +const defaultConfig = require( '@wordpress/scripts/config/webpack.config' ); +const WooCommerceDependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' ); + +module.exports = { + ...defaultConfig, + plugins: [ + ...defaultConfig.plugins.filter( + ( plugin ) => + plugin.constructor.name !== 'DependencyExtractionWebpackPlugin' + ), + new WooCommerceDependencyExtractionWebpackPlugin(), + ], +};