@storepress/create-plugin-html 0.0.1
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/README.md +34 -0
- package/block-templates/Plugin.js.mustache +78 -0
- package/block-templates/_mixins.scss.mustache +53 -0
- package/block-templates/index.js.mustache +64 -0
- package/block-templates/style.scss.mustache +15 -0
- package/index.js +144 -0
- package/package.json +20 -0
- package/plugin-templates/.editorconfig.mustache +27 -0
- package/plugin-templates/.eslintrc.js.mustache +196 -0
- package/plugin-templates/.github/workflows/deploy-github-pages.yaml.mustache +52 -0
- package/plugin-templates/.github/workflows/release.yaml.mustache +62 -0
- package/plugin-templates/.gitignore.mustache +67 -0
- package/plugin-templates/.husky/pre-commit.mustache +1 -0
- package/plugin-templates/.npmrc.mustache +1 -0
- package/plugin-templates/.prettierrc.json.mustache +1 -0
- package/plugin-templates/.stylelintrc.json.mustache +28 -0
- package/plugin-templates/README.md.mustache +34 -0
- package/plugin-templates/index.html.mustache +20 -0
- package/plugin-templates/postcss.config.js.mustache +6 -0
- package/plugin-templates/style.css.mustache +14 -0
- package/plugin-templates/tools/package.js.mustache +91 -0
- package/plugin-templates/tools/webpack-helpers.js.mustache +104 -0
- package/plugin-templates/webpack.config.js.mustache +97 -0
package/README.md
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# @storepress/create-plugin-html
|
|
2
|
+
|
|
3
|
+
This is a template for [`@wordpress/create-block`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/) to create StorePress Plugin.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
This template can be used by running the following command:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx @wordpress/create-block@latest --template @storepress/create-plugin-html my-extension-name
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Navigate to the newly created folder and get started.
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
cd my-extension-name
|
|
17
|
+
npm i # Install dependencies
|
|
18
|
+
npm run build # Build the javascript
|
|
19
|
+
npx @wp-now/wp-now start # Start Wordpress environment
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Development
|
|
23
|
+
|
|
24
|
+
For development on this tool itself, you can also install from a local directory.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
npx @wordpress/create-block@latest --template ./path/to/storepress/create-plugin-html my-extension-name
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
### Add Tests
|
|
31
|
+
|
|
32
|
+
Please check [Base Plugin](https://github.com/EmranAhmed/storepress-base-plugin/) to add `test` and others.
|
|
33
|
+
|
|
34
|
+
This is a template to used with [`@wordpress/create-block`](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-create-block/) to create a StorePress Plugin starting point.
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { getOptionsFromAttribute, triggerEvent } from '@storepress/utils'
|
|
5
|
+
|
|
6
|
+
export function Plugin (element, options) {
|
|
7
|
+
// Default Settings
|
|
8
|
+
const DEFAULTS = {}
|
|
9
|
+
|
|
10
|
+
const PRIVATE = {}
|
|
11
|
+
|
|
12
|
+
// Collecting settings from html attribute
|
|
13
|
+
const ATTRIBUTE = 'plugin-settings' //
|
|
14
|
+
|
|
15
|
+
const CLASSES = {}
|
|
16
|
+
|
|
17
|
+
// Do what you need and return expose fn.
|
|
18
|
+
const init = () => {
|
|
19
|
+
this.$element = element
|
|
20
|
+
this.settings = {
|
|
21
|
+
...DEFAULTS, ...options, ...getOptionsFromAttribute(this.$element, ATTRIBUTE), ...PRIVATE,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
initial()
|
|
25
|
+
|
|
26
|
+
addClasses()
|
|
27
|
+
|
|
28
|
+
addEvents()
|
|
29
|
+
|
|
30
|
+
return expose()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const noop = () => () => {}
|
|
34
|
+
|
|
35
|
+
const getElementComputedStyle = (cssProperty) => {
|
|
36
|
+
return window.getComputedStyle(this.$element).getPropertyValue(cssProperty)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const getComputedStyle = ($element, property) => {
|
|
40
|
+
return window.getComputedStyle($element).getPropertyValue(property)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const initial = () => {
|
|
44
|
+
console.log(this.settings)
|
|
45
|
+
triggerEvent(this.$element, 'afterInit', {})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const cssVariableIsTrue = (string) => {
|
|
49
|
+
return string === 'true' || string === '1' || string === 'yes'
|
|
50
|
+
}
|
|
51
|
+
const addClasses = () => {
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const removeClasses = () => {
|
|
56
|
+
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const addEvents = () => {
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const removeEvents = () => {
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const reset = () => {
|
|
68
|
+
removeClasses()
|
|
69
|
+
removeEvents()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Expose to public.
|
|
73
|
+
const expose = () => ({
|
|
74
|
+
removeEvents, reset,
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
return init()
|
|
78
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
@property --custom-variable {
|
|
2
|
+
syntax: "<integer>";
|
|
3
|
+
inherits: true;
|
|
4
|
+
initial-value: 0;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
@property --custom-variable-2 {
|
|
8
|
+
syntax: "<length>";
|
|
9
|
+
inherits: true;
|
|
10
|
+
initial-value: 0px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@property --custom-variable-3 {
|
|
14
|
+
syntax: "<color>";
|
|
15
|
+
inherits: true;
|
|
16
|
+
initial-value: #000;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@property --custom-variable-4 {
|
|
20
|
+
syntax: "<length>|<percentage>|auto";
|
|
21
|
+
inherits: true;
|
|
22
|
+
initial-value: 100%;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@property --custom-variable-5 {
|
|
26
|
+
syntax: "true|false";
|
|
27
|
+
inherits: true;
|
|
28
|
+
initial-value: true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
@property --custom-variable-6 {
|
|
32
|
+
syntax: "<time>";
|
|
33
|
+
inherits: true;
|
|
34
|
+
initial-value: 500ms;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@mixin variables() {
|
|
38
|
+
--custom-variable: 5px;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
@mixin base-style() {
|
|
42
|
+
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// @use "./mixins" as plugin;
|
|
46
|
+
// :where(.selector){ @include plugin.init(); }
|
|
47
|
+
|
|
48
|
+
@mixin init() {
|
|
49
|
+
& {
|
|
50
|
+
@include variables();
|
|
51
|
+
@include base-style();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { createPluginInstance, triggerEvent } from '@storepress/utils'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from './Plugin'
|
|
10
|
+
|
|
11
|
+
export default function StorePressPlugin () {
|
|
12
|
+
const StorePressPlugin = {
|
|
13
|
+
getInstance (element) {
|
|
14
|
+
return createPluginInstance(element, false, Plugin)
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
initWith ($selector = '[data-plugin-settings]') {
|
|
18
|
+
for (const { element, unregister } of this.getInstance($selector)) {
|
|
19
|
+
element.addEventListener('destroy', unregister)
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
|
|
23
|
+
init () {
|
|
24
|
+
for (const { element, unregister } of this.getInstance('[data-plugin-settings]')) {
|
|
25
|
+
element.addEventListener('destroy', unregister)
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
|
|
29
|
+
destroy () {
|
|
30
|
+
for (const { destroy } of this.getInstance('[data-plugin-settings]')) {
|
|
31
|
+
destroy()
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
destroyWith ($selector = '[data-plugin-settings]') {
|
|
36
|
+
for (const { destroy } of this.getInstance($selector)) {
|
|
37
|
+
destroy()
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
document.addEventListener('storepress_plugin_init', () => {
|
|
43
|
+
StorePressPlugin.init()
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
document.addEventListener('storepress_plugin_destroy', () => {
|
|
47
|
+
StorePressPlugin.destroy()
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
document.addEventListener('storepress_plugin_init_with', (event) => {
|
|
51
|
+
const selector = event.detail?.element
|
|
52
|
+
StorePressPlugin.initWith(selector)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
document.addEventListener('storepress_plugin_destroy_with', (event) => {
|
|
56
|
+
const selector = event.detail?.element
|
|
57
|
+
StorePressPlugin.destroyWith(selector)
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
62
|
+
StorePressPlugin()
|
|
63
|
+
triggerEvent(document, 'storepress_plugin_init')
|
|
64
|
+
})
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
@charset "UTF-8";
|
|
2
|
+
|
|
3
|
+
@use "./mixins" as plugin;
|
|
4
|
+
|
|
5
|
+
$default-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
6
|
+
|
|
7
|
+
:where([data-plugin-settings]) {
|
|
8
|
+
font-family: $default-font;
|
|
9
|
+
|
|
10
|
+
@include plugin.init();
|
|
11
|
+
|
|
12
|
+
& {
|
|
13
|
+
--custom-variable: 1px;
|
|
14
|
+
}
|
|
15
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
const { join } = require('path')
|
|
5
|
+
|
|
6
|
+
// two-words
|
|
7
|
+
function kebabCase (input) {
|
|
8
|
+
const regex = /[-._\s+]/gi
|
|
9
|
+
return input.replace(regex, '-').toLowerCase()
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function constantCase (input) {
|
|
13
|
+
const regex = /[-._\s+]/gi
|
|
14
|
+
return input.replace(regex, '_').toUpperCase()
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function pascalStorePress (input) {
|
|
18
|
+
return 'storepress' === input ? 'StorePress' : input
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function pascalCase (input) {
|
|
22
|
+
return (input.match(/[a-zA-Z0-9]+/g) || []).map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join('')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
defaultValues: {
|
|
27
|
+
folderName: 'src',
|
|
28
|
+
namespace: 'storepress',
|
|
29
|
+
slug: 'plugin',
|
|
30
|
+
version: '0.1.0',
|
|
31
|
+
title: 'StorePress Plugin',
|
|
32
|
+
description: 'A StorePress Plugin',
|
|
33
|
+
author: 'EmranAhmed',
|
|
34
|
+
dashicon: 'pets',
|
|
35
|
+
category: 'storepress',
|
|
36
|
+
attributes: {},
|
|
37
|
+
license: 'GPL-2.0-or-later',
|
|
38
|
+
customScripts: {
|
|
39
|
+
'postinstall': 'git init -q && rm -rf ./.husky && npx husky init && echo "npx lint-staged" > .husky/pre-commit',
|
|
40
|
+
|
|
41
|
+
'prebuild': 'rm -rf ./build',
|
|
42
|
+
'build': 'npm run start -- --no-watch && wp-scripts build --webpack-copy-php --experimental-modules',
|
|
43
|
+
|
|
44
|
+
'check-engines': 'wp-scripts check-engines',
|
|
45
|
+
'check-licenses': 'wp-scripts check-licenses',
|
|
46
|
+
|
|
47
|
+
'format': 'wp-scripts format ./src',
|
|
48
|
+
'format:all': 'npm run format:php && npm run format:css && npm run format:js',
|
|
49
|
+
'format:js': 'wp-scripts format \'./src/**/*.js\'',
|
|
50
|
+
'format:css': 'wp-scripts format \'./src/**/*.scss\'',
|
|
51
|
+
|
|
52
|
+
'lint:css': 'wp-scripts lint-style \'./src/**/*.scss\'',
|
|
53
|
+
'lint:css:report': 'npm run lint:css -- --output-file scss-report.txt',
|
|
54
|
+
'lint:css:fix': 'npm run lint:css -- --fix',
|
|
55
|
+
|
|
56
|
+
'lint:js': 'wp-scripts lint-js --format=pretty \'./src/**/*.js\'',
|
|
57
|
+
'lint:js:report': 'npm run lint:js -- --format html --output-file lint-report.html',
|
|
58
|
+
'lint:js:fix': 'npm run lint:js -- --fix',
|
|
59
|
+
|
|
60
|
+
'lint:md:docs': 'wp-scripts lint-md-docs',
|
|
61
|
+
'lint:pkg-json': 'wp-scripts lint-pkg-json',
|
|
62
|
+
|
|
63
|
+
'packages-update': 'wp-scripts packages-update',
|
|
64
|
+
|
|
65
|
+
'prepackage': 'rm -rf ./${npm_package_name}.zip && npm run build',
|
|
66
|
+
'package': './tools/package.js',
|
|
67
|
+
|
|
68
|
+
'plugin-zip': 'npm run package -- --zip',
|
|
69
|
+
|
|
70
|
+
'test:e2e': 'wp-scripts test-e2e',
|
|
71
|
+
'test:unit': 'wp-scripts test-unit-js',
|
|
72
|
+
|
|
73
|
+
'start': 'rm -rf ./build && wp-scripts start --webpack-copy-php --experimental-modules',
|
|
74
|
+
},
|
|
75
|
+
npmDependencies: [
|
|
76
|
+
'@storepress/utils',
|
|
77
|
+
],
|
|
78
|
+
npmDevDependencies: [
|
|
79
|
+
'@wordpress/scripts',
|
|
80
|
+
'@woocommerce/dependency-extraction-webpack-plugin',
|
|
81
|
+
'@woocommerce/eslint-plugin',
|
|
82
|
+
'@wordpress/base-styles',
|
|
83
|
+
'@wordpress/dependency-extraction-webpack-plugin',
|
|
84
|
+
'eslint-plugin-you-dont-need-lodash-underscore',
|
|
85
|
+
'husky',
|
|
86
|
+
'lint-staged',
|
|
87
|
+
'fs-extra',
|
|
88
|
+
'webpack-remove-empty-scripts',
|
|
89
|
+
'eslint-plugin-prettier',
|
|
90
|
+
'eslint-formatter-pretty@5',
|
|
91
|
+
],
|
|
92
|
+
customPackageJSON: {
|
|
93
|
+
'publishConfig': {
|
|
94
|
+
'access': 'public',
|
|
95
|
+
},
|
|
96
|
+
'sideEffects': [
|
|
97
|
+
'src/**',
|
|
98
|
+
],
|
|
99
|
+
'lint-staged': {
|
|
100
|
+
'./src/**/*.scss': [
|
|
101
|
+
'npm run lint:css',
|
|
102
|
+
],
|
|
103
|
+
'./src/**/*.{js,ts,tsx}': [
|
|
104
|
+
'npm run lint:js',
|
|
105
|
+
],
|
|
106
|
+
'./*.md': [
|
|
107
|
+
'npm run lint:md:docs',
|
|
108
|
+
],
|
|
109
|
+
'./package.json': [
|
|
110
|
+
'npm run lint:pkg-json',
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
'main': 'build/index.js',
|
|
114
|
+
'module': 'src/index.js',
|
|
115
|
+
'files': [
|
|
116
|
+
'build/**',
|
|
117
|
+
'src/**',
|
|
118
|
+
],
|
|
119
|
+
'bin': {
|
|
120
|
+
'package': './tools/package.js',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
transformer: (view) => {
|
|
124
|
+
const todayDate = new Date().toJSON().slice(0, 10)
|
|
125
|
+
const pascaleNamespace = pascalCase(pascalStorePress(view.namespace))
|
|
126
|
+
const constantNamespace = constantCase(view.namespace)
|
|
127
|
+
const kebabNamespace = kebabCase(view.namespace)
|
|
128
|
+
const constantSlug = constantCase(view.slug) // TWO_WORDS
|
|
129
|
+
const kebabSlug = kebabCase(view.slug) // two-words
|
|
130
|
+
return {
|
|
131
|
+
...view,
|
|
132
|
+
todayDate: todayDate,
|
|
133
|
+
constantNamespace: constantNamespace,
|
|
134
|
+
kebabNamespace: kebabNamespace,
|
|
135
|
+
pascaleNamespace: pascaleNamespace,
|
|
136
|
+
|
|
137
|
+
constantSlug: constantSlug,
|
|
138
|
+
kebabSlug: kebabSlug,
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
pluginTemplatesPath: join(__dirname, 'plugin-templates'),
|
|
143
|
+
blockTemplatesPath: join(__dirname, 'block-templates'),
|
|
144
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@storepress/create-plugin-html",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "A template to be used with `@wordpress/create-block` to create a StorePress HTML based JS Extension.",
|
|
5
|
+
"author": "StorePress",
|
|
6
|
+
"main": "index.js",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/EmranAhmed/storepress-create-plugin-html.git"
|
|
10
|
+
},
|
|
11
|
+
"keywords": ["html", "dom", "javascript", "storepress"],
|
|
12
|
+
"license": "GPL-2.0-or-later",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/EmranAhmed/storepress-create-plugin-html/issues"
|
|
15
|
+
},
|
|
16
|
+
"homepage": "https://github.com/EmranAhmed/storepress-create-plugin-html#readme",
|
|
17
|
+
"publishConfig": {
|
|
18
|
+
"access": "public"
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# This file is for unifying the coding style for different editors and IDEs
|
|
2
|
+
# editorconfig.org
|
|
3
|
+
|
|
4
|
+
# WordPress Coding Standards
|
|
5
|
+
# https://make.wordpress.org/core/handbook/coding-standards/
|
|
6
|
+
|
|
7
|
+
root = true
|
|
8
|
+
|
|
9
|
+
[*]
|
|
10
|
+
charset = utf-8
|
|
11
|
+
end_of_line = lf
|
|
12
|
+
indent_size = 4
|
|
13
|
+
tab_width = 4
|
|
14
|
+
indent_style = tab
|
|
15
|
+
insert_final_newline = true
|
|
16
|
+
trim_trailing_whitespace = true
|
|
17
|
+
|
|
18
|
+
[*.txt]
|
|
19
|
+
trim_trailing_whitespace = false
|
|
20
|
+
|
|
21
|
+
[*.{md,json,yml}]
|
|
22
|
+
trim_trailing_whitespace = false
|
|
23
|
+
indent_style = space
|
|
24
|
+
indent_size = 2
|
|
25
|
+
|
|
26
|
+
[*.json]
|
|
27
|
+
indent_style = tab
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
const restrictedImports = [
|
|
2
|
+
{
|
|
3
|
+
name: 'lodash',
|
|
4
|
+
importNames: [
|
|
5
|
+
'camelCase',
|
|
6
|
+
'capitalize',
|
|
7
|
+
'castArray',
|
|
8
|
+
'chunk',
|
|
9
|
+
'clamp',
|
|
10
|
+
'clone',
|
|
11
|
+
'cloneDeep',
|
|
12
|
+
'compact',
|
|
13
|
+
'concat',
|
|
14
|
+
'countBy',
|
|
15
|
+
'debounce',
|
|
16
|
+
'deburr',
|
|
17
|
+
'defaults',
|
|
18
|
+
'defaultTo',
|
|
19
|
+
'delay',
|
|
20
|
+
'difference',
|
|
21
|
+
'differenceWith',
|
|
22
|
+
'dropRight',
|
|
23
|
+
'each',
|
|
24
|
+
'escape',
|
|
25
|
+
'escapeRegExp',
|
|
26
|
+
'every',
|
|
27
|
+
'extend',
|
|
28
|
+
'filter',
|
|
29
|
+
'find',
|
|
30
|
+
'findIndex',
|
|
31
|
+
'findKey',
|
|
32
|
+
'findLast',
|
|
33
|
+
'first',
|
|
34
|
+
'flatMap',
|
|
35
|
+
'flatten',
|
|
36
|
+
'flattenDeep',
|
|
37
|
+
'flow',
|
|
38
|
+
'flowRight',
|
|
39
|
+
'forEach',
|
|
40
|
+
'fromPairs',
|
|
41
|
+
'has',
|
|
42
|
+
'identity',
|
|
43
|
+
'includes',
|
|
44
|
+
'invoke',
|
|
45
|
+
'isArray',
|
|
46
|
+
'isBoolean',
|
|
47
|
+
'isEqual',
|
|
48
|
+
'isFinite',
|
|
49
|
+
'isFunction',
|
|
50
|
+
'isMatch',
|
|
51
|
+
'isNil',
|
|
52
|
+
'isNumber',
|
|
53
|
+
'isObject',
|
|
54
|
+
'isObjectLike',
|
|
55
|
+
'isPlainObject',
|
|
56
|
+
'isString',
|
|
57
|
+
'isUndefined',
|
|
58
|
+
'keyBy',
|
|
59
|
+
'keys',
|
|
60
|
+
'last',
|
|
61
|
+
'lowerCase',
|
|
62
|
+
'map',
|
|
63
|
+
'mapKeys',
|
|
64
|
+
'maxBy',
|
|
65
|
+
'memoize',
|
|
66
|
+
'merge',
|
|
67
|
+
'negate',
|
|
68
|
+
'noop',
|
|
69
|
+
'nth',
|
|
70
|
+
'omit',
|
|
71
|
+
'omitBy',
|
|
72
|
+
'once',
|
|
73
|
+
'orderby',
|
|
74
|
+
'overEvery',
|
|
75
|
+
'partial',
|
|
76
|
+
'partialRight',
|
|
77
|
+
'pick',
|
|
78
|
+
'pickBy',
|
|
79
|
+
'random',
|
|
80
|
+
'reduce',
|
|
81
|
+
'reject',
|
|
82
|
+
'repeat',
|
|
83
|
+
'reverse',
|
|
84
|
+
'setWith',
|
|
85
|
+
'size',
|
|
86
|
+
'snakeCase',
|
|
87
|
+
'some',
|
|
88
|
+
'sortBy',
|
|
89
|
+
'startCase',
|
|
90
|
+
'startsWith',
|
|
91
|
+
'stubFalse',
|
|
92
|
+
'stubTrue',
|
|
93
|
+
'sum',
|
|
94
|
+
'sumBy',
|
|
95
|
+
'take',
|
|
96
|
+
'throttle',
|
|
97
|
+
'times',
|
|
98
|
+
'toString',
|
|
99
|
+
'trim',
|
|
100
|
+
'truncate',
|
|
101
|
+
'unescape',
|
|
102
|
+
'unionBy',
|
|
103
|
+
'uniq',
|
|
104
|
+
'uniqBy',
|
|
105
|
+
'uniqueId',
|
|
106
|
+
'uniqWith',
|
|
107
|
+
'upperFirst',
|
|
108
|
+
'values',
|
|
109
|
+
'without',
|
|
110
|
+
'words',
|
|
111
|
+
'xor',
|
|
112
|
+
'zip',
|
|
113
|
+
],
|
|
114
|
+
message:
|
|
115
|
+
'This Lodash method is not recommended. Please use native functionality instead. If using `memoize`, please use `memize` instead.',
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
name: 'classnames',
|
|
119
|
+
message:
|
|
120
|
+
"Please use `clsx` instead. It's a lighter and faster drop-in replacement for `classnames`.",
|
|
121
|
+
},
|
|
122
|
+
];
|
|
123
|
+
|
|
124
|
+
module.exports = {
|
|
125
|
+
root: true,
|
|
126
|
+
extends: [
|
|
127
|
+
'plugin:@woocommerce/eslint-plugin/recommended',
|
|
128
|
+
'plugin:you-dont-need-lodash-underscore/compatible',
|
|
129
|
+
],
|
|
130
|
+
settings: {
|
|
131
|
+
// List of modules that are externals in our webpack config.
|
|
132
|
+
// This helps the `import/no-extraneous-dependencies` and
|
|
133
|
+
//`import/no-unresolved` rules account for them.
|
|
134
|
+
'import/core-modules': [
|
|
135
|
+
'@woocommerce/blocks-registry',
|
|
136
|
+
'@wordpress/is-shallow-equal',
|
|
137
|
+
'@woocommerce/block-data',
|
|
138
|
+
'@woocommerce/blocks-checkout',
|
|
139
|
+
'@woocommerce/price-format',
|
|
140
|
+
'@woocommerce/settings',
|
|
141
|
+
'@woocommerce/shared-context',
|
|
142
|
+
'@woocommerce/shared-hocs',
|
|
143
|
+
'@woocommerce/data',
|
|
144
|
+
'@wordpress/components',
|
|
145
|
+
'@wordpress/i18n',
|
|
146
|
+
'@wordpress/blocks',
|
|
147
|
+
'@wordpress/a11y',
|
|
148
|
+
'@wordpress/api-fetch',
|
|
149
|
+
'@wordpress/block-editor',
|
|
150
|
+
'@wordpress/compose',
|
|
151
|
+
'@wordpress/data',
|
|
152
|
+
'@wordpress/core-data',
|
|
153
|
+
'@wordpress/editor',
|
|
154
|
+
'@wordpress/escape-html',
|
|
155
|
+
'@wordpress/hooks',
|
|
156
|
+
'@wordpress/keycodes',
|
|
157
|
+
'@wordpress/url',
|
|
158
|
+
'@wordpress/element',
|
|
159
|
+
'@woocommerce/blocks-test-utils',
|
|
160
|
+
'@woocommerce/e2e-utils',
|
|
161
|
+
'lodash',
|
|
162
|
+
'jquery',
|
|
163
|
+
'@storepress/utils',
|
|
164
|
+
'@utils', // See: getWebPackAlias() from tools/webpack-helpers.js
|
|
165
|
+
],
|
|
166
|
+
'import/resolver': {
|
|
167
|
+
node: {},
|
|
168
|
+
webpack: {},
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
env: {
|
|
172
|
+
browser: true,
|
|
173
|
+
es6: true,
|
|
174
|
+
node: true,
|
|
175
|
+
},
|
|
176
|
+
globals: {
|
|
177
|
+
jQuery: 'readonly',
|
|
178
|
+
wp: true,
|
|
179
|
+
wpApiSettings: true,
|
|
180
|
+
wcSettings: true,
|
|
181
|
+
es6: true,
|
|
182
|
+
StorePress: true,
|
|
183
|
+
},
|
|
184
|
+
rules: {
|
|
185
|
+
'@woocommerce/dependency-group': 'off',
|
|
186
|
+
'@wordpress/no-unsafe-wp-apis': 'warn',
|
|
187
|
+
'react/react-in-jsx-scope': 'off',
|
|
188
|
+
'no-restricted-imports': [
|
|
189
|
+
'error',
|
|
190
|
+
{
|
|
191
|
+
paths: restrictedImports,
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
'@wordpress/no-global-active-element': 'warn'
|
|
195
|
+
},
|
|
196
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# Simple workflow for deploying static content to GitHub Pages
|
|
2
|
+
name: Deploy to Pages
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
# Runs on pushes targeting the default branch
|
|
6
|
+
push:
|
|
7
|
+
branches: [$default-branch]
|
|
8
|
+
|
|
9
|
+
# Allows you to run this workflow manually from the Actions tab
|
|
10
|
+
workflow_dispatch:
|
|
11
|
+
|
|
12
|
+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
13
|
+
permissions:
|
|
14
|
+
contents: read
|
|
15
|
+
pages: write
|
|
16
|
+
id-token: write
|
|
17
|
+
|
|
18
|
+
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued.
|
|
19
|
+
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete.
|
|
20
|
+
concurrency:
|
|
21
|
+
group: "pages"
|
|
22
|
+
cancel-in-progress: false
|
|
23
|
+
|
|
24
|
+
jobs:
|
|
25
|
+
# Single deploy job since we're just deploying
|
|
26
|
+
deploy:
|
|
27
|
+
environment:
|
|
28
|
+
name: github-pages
|
|
29
|
+
url: ${{ steps.deployment.outputs.page_url }}
|
|
30
|
+
runs-on: ubuntu-latest
|
|
31
|
+
steps:
|
|
32
|
+
- name: Checkout
|
|
33
|
+
uses: actions/checkout@v4
|
|
34
|
+
# Set up Node
|
|
35
|
+
- name: Setup Node
|
|
36
|
+
uses: actions/setup-node@v4
|
|
37
|
+
with:
|
|
38
|
+
node-version: 18
|
|
39
|
+
- name: Install and Build
|
|
40
|
+
run: |
|
|
41
|
+
npm install
|
|
42
|
+
npm run build
|
|
43
|
+
#- name: Setup Pages
|
|
44
|
+
# uses: actions/configure-pages@v5
|
|
45
|
+
- name: Upload artifact
|
|
46
|
+
uses: actions/upload-pages-artifact@v3
|
|
47
|
+
with:
|
|
48
|
+
# Upload entire repository
|
|
49
|
+
path: '.'
|
|
50
|
+
- name: Deploy to GitHub Pages
|
|
51
|
+
id: deployment
|
|
52
|
+
uses: actions/deploy-pages@v4
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
on:
|
|
2
|
+
push:
|
|
3
|
+
# Sequence of patterns matched against refs/tags
|
|
4
|
+
tags:
|
|
5
|
+
- '**' # Push events to matching i.e. 1.0, 20.15.10, including hierarchical tags like v1.0/beta
|
|
6
|
+
# Semver (https://semver.org/) release pattern.
|
|
7
|
+
# - '[0-9]+.[0-9]+.[0-9]+*'
|
|
8
|
+
|
|
9
|
+
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages
|
|
10
|
+
permissions: write-all
|
|
11
|
+
|
|
12
|
+
env:
|
|
13
|
+
REPOSITORY_NAME: ${{ github.event.repository.name }}
|
|
14
|
+
|
|
15
|
+
name: Release
|
|
16
|
+
|
|
17
|
+
jobs:
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
# Build distribution release.
|
|
21
|
+
#
|
|
22
|
+
# Performs the following steps:
|
|
23
|
+
# - Checks out the repository.
|
|
24
|
+
# - Set up PHP.
|
|
25
|
+
# - Install PHP Dependencies.
|
|
26
|
+
# - Setup and Install Node.js.
|
|
27
|
+
# - Make Zip.
|
|
28
|
+
# - Upload Release.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
build:
|
|
32
|
+
name: Release
|
|
33
|
+
runs-on: ubuntu-latest
|
|
34
|
+
steps:
|
|
35
|
+
- name: "Checks out the repository"
|
|
36
|
+
uses: actions/checkout@v4
|
|
37
|
+
|
|
38
|
+
- name: "Setup and Install Node.js"
|
|
39
|
+
uses: actions/setup-node@v4
|
|
40
|
+
with:
|
|
41
|
+
node-version: '20.x'
|
|
42
|
+
- run: npm clean-install
|
|
43
|
+
|
|
44
|
+
- name: "Make Zip"
|
|
45
|
+
run: npm run plugin-zip --if-present
|
|
46
|
+
|
|
47
|
+
- name: "Get release version."
|
|
48
|
+
run: |
|
|
49
|
+
echo "RELEASE_TAG=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV
|
|
50
|
+
|
|
51
|
+
- name: "Get release file base name."
|
|
52
|
+
run: |
|
|
53
|
+
echo "RELEASE_NAME=$(node -p -e "require('./package.json').name")" >> $GITHUB_ENV
|
|
54
|
+
|
|
55
|
+
- name: "Upload Release"
|
|
56
|
+
uses: softprops/action-gh-release@v2
|
|
57
|
+
with:
|
|
58
|
+
files: ./${{ env.RELEASE_NAME }}.zip
|
|
59
|
+
make_latest: true
|
|
60
|
+
name: Release - v${{ env.RELEASE_TAG }}
|
|
61
|
+
env:
|
|
62
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
|
|
2
|
+
# Operating System files
|
|
3
|
+
.DS_Store
|
|
4
|
+
Thumbs.db
|
|
5
|
+
|
|
6
|
+
# IDE files
|
|
7
|
+
.idea
|
|
8
|
+
.vscode/*
|
|
9
|
+
project.xml
|
|
10
|
+
project.properties
|
|
11
|
+
.project
|
|
12
|
+
.settings*
|
|
13
|
+
*.sublime-project
|
|
14
|
+
*.sublime-workspace
|
|
15
|
+
.sublimelinterrc
|
|
16
|
+
.husky/_
|
|
17
|
+
src/block.json
|
|
18
|
+
|
|
19
|
+
# Sass
|
|
20
|
+
.sass-cache/
|
|
21
|
+
|
|
22
|
+
# Logs
|
|
23
|
+
logs/
|
|
24
|
+
|
|
25
|
+
# Environment files
|
|
26
|
+
wp-cli.local.yml
|
|
27
|
+
yarn-error.log
|
|
28
|
+
npm-debug.log
|
|
29
|
+
.pnpm-debug.log
|
|
30
|
+
*.lock
|
|
31
|
+
|
|
32
|
+
# Build files
|
|
33
|
+
*.sql
|
|
34
|
+
*.swp
|
|
35
|
+
*.zip
|
|
36
|
+
|
|
37
|
+
# Built packages
|
|
38
|
+
build/
|
|
39
|
+
build-module/
|
|
40
|
+
build-style/
|
|
41
|
+
build-types/
|
|
42
|
+
dist/
|
|
43
|
+
|
|
44
|
+
# Project files
|
|
45
|
+
node_modules/
|
|
46
|
+
vendor/
|
|
47
|
+
languages/
|
|
48
|
+
{{slug}}/
|
|
49
|
+
|
|
50
|
+
# TypeScript files
|
|
51
|
+
tsconfig.tsbuildinfo
|
|
52
|
+
|
|
53
|
+
# Node Package Dependencies
|
|
54
|
+
# package-lock.json
|
|
55
|
+
|
|
56
|
+
# wp-env config
|
|
57
|
+
.wp-env.override.json
|
|
58
|
+
|
|
59
|
+
# Unit tests
|
|
60
|
+
tmp/
|
|
61
|
+
|
|
62
|
+
# Composer
|
|
63
|
+
bin/composer/**/vendor/
|
|
64
|
+
lib/vendor/
|
|
65
|
+
contributors.md
|
|
66
|
+
contributors.html
|
|
67
|
+
*-report*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
npx lint-staged
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"@wordpress/prettier-config"
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends" : "@wordpress/stylelint-config/scss",
|
|
3
|
+
"syntax" : "scss",
|
|
4
|
+
"rules": {
|
|
5
|
+
"at-rule-empty-line-before" : null,
|
|
6
|
+
"at-rule-no-unknown" : null,
|
|
7
|
+
"comment-empty-line-before" : null,
|
|
8
|
+
"font-weight-notation" : null,
|
|
9
|
+
"font-family-name-quotes" : "always-unless-keyword",
|
|
10
|
+
"font-family-no-missing-generic-family-keyword" : null,
|
|
11
|
+
"no-descending-specificity" : null,
|
|
12
|
+
"no-duplicate-selectors" : null,
|
|
13
|
+
"rule-empty-line-before" : null,
|
|
14
|
+
"selector-class-pattern" : null,
|
|
15
|
+
"value-keyword-case" : null,
|
|
16
|
+
"scss/operator-no-unspaced" : null,
|
|
17
|
+
"scss/selector-no-redundant-nesting-selector" : null,
|
|
18
|
+
"scss/at-import-partial-extension" : null,
|
|
19
|
+
"scss/no-global-function-names" : null,
|
|
20
|
+
"scss/comment-no-empty" : null,
|
|
21
|
+
"scss/at-extend-no-missing-placeholder" : null,
|
|
22
|
+
"scss/operator-no-newline-after" : null,
|
|
23
|
+
"scss/at-if-closing-brace-newline-after" : null,
|
|
24
|
+
"scss/at-else-empty-line-before" : null,
|
|
25
|
+
"scss/at-if-closing-brace-space-after" : null,
|
|
26
|
+
"no-invalid-position-at-import-rule" : null
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# {{title}}
|
|
2
|
+
|
|
3
|
+
{{description}}
|
|
4
|
+
|
|
5
|
+
## Development
|
|
6
|
+
- `npm i`
|
|
7
|
+
- `npm run packages-update` - Update WordPress packages
|
|
8
|
+
|
|
9
|
+
## Develop
|
|
10
|
+
|
|
11
|
+
- `npm start`
|
|
12
|
+
|
|
13
|
+
## Lint
|
|
14
|
+
|
|
15
|
+
- `npm run lint:js` - Lint Javascript
|
|
16
|
+
- `npm run lint:js:report` - Lint Javascript and will generate `lint-report.html`. From terminal `open lint-report.html`
|
|
17
|
+
- `npm run lint:css` - Lint CSS
|
|
18
|
+
- `npm run lint:css:report` - Lint CSS and will generate `scss-report.txt` file.
|
|
19
|
+
|
|
20
|
+
## Fix
|
|
21
|
+
|
|
22
|
+
- `npm run lint:js:fix` - Fix Javascript Lint Issue.
|
|
23
|
+
- `npm run lint:css:fix` - Fix SCSS Lint Issue.
|
|
24
|
+
|
|
25
|
+
## Format
|
|
26
|
+
|
|
27
|
+
- `npm run format:js` - Format Javascript
|
|
28
|
+
- `npm run format:css` - Format SCSS
|
|
29
|
+
- `npm run format` - Format `./src`
|
|
30
|
+
|
|
31
|
+
## Release
|
|
32
|
+
|
|
33
|
+
- `npm run plugin-zip` - make zip based on `package.json` `files` list.
|
|
34
|
+
- `npm run package` - make directory based on `package.json` `files` list.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<title>{{title}}</title>
|
|
7
|
+
<link rel="stylesheet" href="./build/style-plugin.css" />
|
|
8
|
+
<link rel="stylesheet" href="./style.css" />
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
|
|
13
|
+
<div class="wrapper">
|
|
14
|
+
<div data-plugin-settings="{'greet': 'Hello'}">Hello ( Check Browser Console )</div>
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
<script src="./build/storepress-utils.js"></script>
|
|
18
|
+
<script src="./build/plugin.js"></script>
|
|
19
|
+
</body>
|
|
20
|
+
</html>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
/**
|
|
4
|
+
* External dependencies
|
|
5
|
+
*/
|
|
6
|
+
const AdmZip = require('adm-zip');
|
|
7
|
+
const { sync: glob } = require('fast-glob');
|
|
8
|
+
const { dirname } = require('path');
|
|
9
|
+
const { stdout } = require('process');
|
|
10
|
+
const fs = require('fs-extra');
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const {
|
|
16
|
+
hasPackageProp,
|
|
17
|
+
getPackageProp,
|
|
18
|
+
hasArgInCLI,
|
|
19
|
+
} = require('@wordpress/scripts/utils');
|
|
20
|
+
|
|
21
|
+
const npm_package_name = getPackageProp('name');
|
|
22
|
+
const npm_package_version = getPackageProp('version');
|
|
23
|
+
|
|
24
|
+
stdout.write(`Creating package for \`${npm_package_name}\` plugin... 🎁\n\n`);
|
|
25
|
+
const zip = new AdmZip();
|
|
26
|
+
const isZip = hasArgInCLI('--zip');
|
|
27
|
+
|
|
28
|
+
let files = [];
|
|
29
|
+
|
|
30
|
+
if (hasPackageProp('files')) {
|
|
31
|
+
stdout.write(
|
|
32
|
+
'Using the `files` field from `package.json` to detect files:\n\n'
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
files = glob(getPackageProp('files'), {
|
|
36
|
+
caseSensitiveMatch: false,
|
|
37
|
+
});
|
|
38
|
+
} else {
|
|
39
|
+
stdout.write('Using Plugin Handbook best practices to discover files:\n\n');
|
|
40
|
+
// See https://developer.wordpress.org/plugins/plugin-basics/best-practices/#file-organization.
|
|
41
|
+
files = glob(
|
|
42
|
+
[
|
|
43
|
+
'admin/**',
|
|
44
|
+
'build/**',
|
|
45
|
+
'includes/**',
|
|
46
|
+
'languages/**',
|
|
47
|
+
'public/**',
|
|
48
|
+
`${npm_package_name}.php`,
|
|
49
|
+
'uninstall.php',
|
|
50
|
+
'block.json',
|
|
51
|
+
'changelog.*',
|
|
52
|
+
'license.*',
|
|
53
|
+
'readme.*',
|
|
54
|
+
],
|
|
55
|
+
{
|
|
56
|
+
caseSensitiveMatch: false,
|
|
57
|
+
}
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (isZip) {
|
|
62
|
+
stdout.write(
|
|
63
|
+
`Creating archive for \`${npm_package_name}\` plugin... 🎁\n\n`
|
|
64
|
+
);
|
|
65
|
+
files.forEach((file) => {
|
|
66
|
+
stdout.write(` 🥳 Adding \`${file}\`.\n`);
|
|
67
|
+
const zipDirectory = dirname(file);
|
|
68
|
+
zip.addLocalFile(file, zipDirectory !== '.' ? zipDirectory : '');
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
zip.writeZip(`./${npm_package_name}.zip`);
|
|
72
|
+
stdout.write(`\nDone. \`${npm_package_name}.zip\` is ready! 🎉\n`);
|
|
73
|
+
} else {
|
|
74
|
+
fs.remove(npm_package_name).then(() => {
|
|
75
|
+
fs.ensureDir(npm_package_name, () => {
|
|
76
|
+
stdout.write(
|
|
77
|
+
`Creating directory for \`${npm_package_name}\` plugin... 🎁\n\n`
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
files.forEach((file) => {
|
|
81
|
+
const to = `${npm_package_name}/${file}`;
|
|
82
|
+
stdout.write(` 🥳 Adding \`${file}\`.\n`);
|
|
83
|
+
fs.copy(file, to);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
stdout.write(
|
|
87
|
+
`\n\nDone. \`${npm_package_name}\` directory is ready! 🎉\n`
|
|
88
|
+
);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
// @see: https://developer.wordpress.org/block-editor/reference-guides/packages/packages-dependency-extraction-webpack-plugin/
|
|
2
|
+
/**
|
|
3
|
+
* External dependencies
|
|
4
|
+
*/
|
|
5
|
+
const { getProjectSourcePath } = require( '@wordpress/scripts/utils/config' );
|
|
6
|
+
const { fromProjectRoot } = require( '@wordpress/scripts/utils/file' );
|
|
7
|
+
const { sep } = require( 'path' );
|
|
8
|
+
|
|
9
|
+
// jquery --> window.jQuery
|
|
10
|
+
// react-dom --> window.ReactDOM
|
|
11
|
+
// Add `slick-carousel`, `@woocommerce/blocks-registry`,`@woocommerce/settings` on `.eslintrc.js` -> 'import/core-modules'
|
|
12
|
+
const externalScriptsMap = {
|
|
13
|
+
'@storepress/utils' : ['StorePress','Utils'],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// @babel/runtime/regenerator --> wp-polyfill
|
|
17
|
+
const scriptHandleMap = {
|
|
18
|
+
'@storepress/utils' : 'storepress-utils',
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const externalModulesMap = {
|
|
22
|
+
// static import.
|
|
23
|
+
// '@wordpress/interactivity': 'module @wordpress/interactivity',
|
|
24
|
+
// dynamic import.
|
|
25
|
+
// @see: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/query/view.js#L36
|
|
26
|
+
// '@wordpress/interactivity-router': 'import @wordpress/interactivity-router',
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Default request to global transformation
|
|
31
|
+
*
|
|
32
|
+
* Transform @wordpress dependencies:
|
|
33
|
+
* - request `@wordpress/api-fetch` becomes `[ 'wp', 'apiFetch' ]`
|
|
34
|
+
* - request `@wordpress/i18n` becomes `[ 'wp', 'i18n' ]`
|
|
35
|
+
*
|
|
36
|
+
* @param {string} request Module request (the module name in `import from`) to be transformed
|
|
37
|
+
* @return {string|string[]|undefined} The resulting external definition. Return `undefined`
|
|
38
|
+
* to ignore the request. Return `string|string[]` to map the request to an external.
|
|
39
|
+
*/
|
|
40
|
+
function requestToExternal( request ) {
|
|
41
|
+
if ( externalScriptsMap[ request ] ) {
|
|
42
|
+
return externalScriptsMap[ request ];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Default request to WordPress script handle transformation
|
|
48
|
+
*
|
|
49
|
+
* Transform @wordpress dependencies:
|
|
50
|
+
* - request `@wordpress/i18n` becomes `wp-i18n`
|
|
51
|
+
* - request `@wordpress/escape-html` becomes `wp-escape-html`
|
|
52
|
+
*
|
|
53
|
+
* @param {string} request Module request (the module name in `import from`) to be transformed
|
|
54
|
+
* @return {string|undefined} WordPress script handle to map the request to. Return `undefined`
|
|
55
|
+
* to use the same name as the module.
|
|
56
|
+
*/
|
|
57
|
+
function requestToHandle( request ) {
|
|
58
|
+
if ( scriptHandleMap[ request ] ) {
|
|
59
|
+
return scriptHandleMap[ request ];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Default request to external module transformation
|
|
65
|
+
*
|
|
66
|
+
* Currently Supports:
|
|
67
|
+
* - @wordpress/interactivity
|
|
68
|
+
* - @wordpress/interactivity-router
|
|
69
|
+
*
|
|
70
|
+
* Do not use the boolean shorthand here, it's only handled for the
|
|
71
|
+
* `requestToExternalModule` option.
|
|
72
|
+
*
|
|
73
|
+
* @param {string} request Module request (the module name in `import from`) to be transformed
|
|
74
|
+
* @return {string|Error|undefined} The resulting external definition.
|
|
75
|
+
* - Return `undefined` to ignore the request (do not externalize).
|
|
76
|
+
* - Return `string` to map the request to an external.
|
|
77
|
+
* - Return `Error` to emit an error.
|
|
78
|
+
*/
|
|
79
|
+
function requestToExternalModule( request ) {
|
|
80
|
+
if ( externalModulesMap[ request ] ) {
|
|
81
|
+
return externalModulesMap[ request ];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function getFile( fileName ) {
|
|
86
|
+
return fromProjectRoot( getProjectSourcePath() + sep + fileName );
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getWebPackAlias() {
|
|
90
|
+
return {
|
|
91
|
+
// '@utils': getFile('utils/Plugin'), // Add @utils on .eslintrc.js -> 'import/core-modules'
|
|
92
|
+
//'@storepress/icons': getFile('packages/icons'),
|
|
93
|
+
//'@storepress/utils': getFile('packages/utils'),
|
|
94
|
+
//'@storepress/components': getFile('packages/components'),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
module.exports = {
|
|
99
|
+
getFile,
|
|
100
|
+
getWebPackAlias,
|
|
101
|
+
requestToExternal,
|
|
102
|
+
requestToHandle,
|
|
103
|
+
requestToExternalModule,
|
|
104
|
+
};
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const [
|
|
2
|
+
defaultJSConfig,
|
|
3
|
+
defaultModuleConfig,
|
|
4
|
+
] = require( '@wordpress/scripts/config/webpack.config' );
|
|
5
|
+
const {
|
|
6
|
+
requestToExternal,
|
|
7
|
+
requestToHandle,
|
|
8
|
+
requestToExternalModule,
|
|
9
|
+
getFile,
|
|
10
|
+
getWebPackAlias,
|
|
11
|
+
} = require( './tools/webpack-helpers' );
|
|
12
|
+
const WoocommerceDependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' );
|
|
13
|
+
const DependencyExtractionWebpackPlugin = require( '@wordpress/dependency-extraction-webpack-plugin' );
|
|
14
|
+
const RemoveEmptyScriptsPlugin = require( 'webpack-remove-empty-scripts' );
|
|
15
|
+
|
|
16
|
+
const scriptConfig = {
|
|
17
|
+
...defaultJSConfig,
|
|
18
|
+
entry: {
|
|
19
|
+
[`plugin`]: [
|
|
20
|
+
getFile('style.scss'),
|
|
21
|
+
getFile('index.js'),
|
|
22
|
+
],
|
|
23
|
+
'storepress-utils': {
|
|
24
|
+
import: '@storepress/utils/build-module/index.js',
|
|
25
|
+
library: {
|
|
26
|
+
name: ['StorePress','Utils'],
|
|
27
|
+
type: 'window'
|
|
28
|
+
},
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
resolve: {
|
|
33
|
+
...defaultJSConfig.resolve,
|
|
34
|
+
alias: {
|
|
35
|
+
...defaultJSConfig.resolve.alias,
|
|
36
|
+
...getWebPackAlias(),
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
plugins: [
|
|
41
|
+
// ...defaultJSConfig.plugins,
|
|
42
|
+
...defaultJSConfig.plugins.filter(
|
|
43
|
+
( plugin ) =>
|
|
44
|
+
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
|
|
45
|
+
),
|
|
46
|
+
new WoocommerceDependencyExtractionWebpackPlugin( {
|
|
47
|
+
requestToExternal,
|
|
48
|
+
requestToHandle,
|
|
49
|
+
requestToExternalModule,
|
|
50
|
+
} ),
|
|
51
|
+
|
|
52
|
+
// Removes the empty `.js` files generated by webpack but
|
|
53
|
+
// sets it after WP has generated its `*.asset.php` file.
|
|
54
|
+
new RemoveEmptyScriptsPlugin( {
|
|
55
|
+
stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS,
|
|
56
|
+
} ),
|
|
57
|
+
]
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const moduleConfig = {
|
|
61
|
+
...defaultModuleConfig,
|
|
62
|
+
output: { ...defaultModuleConfig.output, module: true },
|
|
63
|
+
experiments: { outputModule: true },
|
|
64
|
+
entry: {
|
|
65
|
+
// ...defaultModuleConfig.entry(),
|
|
66
|
+
// 'custom-module': getFile( 'custom-module.js' ),
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
resolve: {
|
|
70
|
+
...defaultModuleConfig.resolve,
|
|
71
|
+
alias: {
|
|
72
|
+
...defaultModuleConfig.resolve.alias,
|
|
73
|
+
...getWebPackAlias(),
|
|
74
|
+
},
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
plugins: [
|
|
78
|
+
// ...defaultModuleConfig.plugins,
|
|
79
|
+
...defaultModuleConfig.plugins.filter(
|
|
80
|
+
( plugin ) =>
|
|
81
|
+
plugin.constructor.name !== 'DependencyExtractionWebpackPlugin'
|
|
82
|
+
),
|
|
83
|
+
new DependencyExtractionWebpackPlugin( {
|
|
84
|
+
requestToExternal,
|
|
85
|
+
requestToHandle,
|
|
86
|
+
requestToExternalModule,
|
|
87
|
+
} ),
|
|
88
|
+
|
|
89
|
+
// Removes the empty `.js` files generated by webpack but
|
|
90
|
+
// sets it after WP has generated its `*.asset.php` file.
|
|
91
|
+
new RemoveEmptyScriptsPlugin( {
|
|
92
|
+
stage: RemoveEmptyScriptsPlugin.STAGE_AFTER_PROCESS_PLUGINS,
|
|
93
|
+
} ),
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
module.exports = [ scriptConfig, moduleConfig ];
|