@storepress/create-plugin-html 0.0.2 → 0.0.4
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 +1 -0
- package/block-templates/Plugin.js.mustache +4 -2
- package/block-templates/index.js.mustache +10 -79
- package/block-templates/style.scss.mustache +1 -1
- package/index.js +12 -18
- package/package.json +1 -1
- package/plugin-templates/.github/workflows/deploy-github-pages.yaml.mustache +11 -11
- package/plugin-templates/.github/workflows/release.yaml.mustache +17 -16
- package/plugin-templates/.npmrc.mustache +1 -1
- package/plugin-templates/index.html.mustache +2 -2
- package/plugin-templates/lint-staged.config.js.mustache +6 -0
- package/plugin-templates/script.js.mustache +8 -0
- package/plugin-templates/style.scss.mustache +10 -0
- package/plugin-templates/tools/package.js.mustache +2 -2
- package/plugin-templates/tools/webpack-helpers.js.mustache +6 -0
- package/plugin-templates/webpack.config.js.mustache +3 -2
- package/plugin-templates/.husky/pre-commit.mustache +0 -1
- /package/plugin-templates/{style.css.mustache → global-style.css.mustache} +0 -0
package/README.md
CHANGED
|
@@ -14,6 +14,7 @@ Navigate to the newly created folder and get started.
|
|
|
14
14
|
|
|
15
15
|
```
|
|
16
16
|
cd my-extension-name
|
|
17
|
+
npm i prettier@npm:wp-prettier@latest --save-dev
|
|
17
18
|
npm i # Install dependencies
|
|
18
19
|
npm run build # Build the javascript
|
|
19
20
|
npx @wp-now/wp-now start # Start Wordpress environment
|
|
@@ -46,7 +46,6 @@ export function Plugin (element, options) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
const removeEvents = () => {
|
|
49
|
-
|
|
50
49
|
this.controller.abort('Reset')
|
|
51
50
|
}
|
|
52
51
|
|
|
@@ -68,7 +67,10 @@ export function Plugin (element, options) {
|
|
|
68
67
|
const init = () => {
|
|
69
68
|
this.$element = element
|
|
70
69
|
this.settings = {
|
|
71
|
-
...DEFAULTS,
|
|
70
|
+
...DEFAULTS,
|
|
71
|
+
...options,
|
|
72
|
+
...getOptionsFromAttribute(this.$element, ATTRIBUTE),
|
|
73
|
+
...PRIVATE,
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
this.controller = new AbortController()
|
|
@@ -1,89 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import {
|
|
4
|
+
import { createStorePressPlugin } from '@storepress/utils';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { Plugin
|
|
9
|
+
import { Plugin } from './Plugin';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
const {{pascaleSlug}} = createStorePressPlugin( {
|
|
12
|
+
selector: '[data-{{kebabSlug}}]',
|
|
13
|
+
options: {},
|
|
14
|
+
plugin: Plugin,
|
|
15
|
+
namespace: '{{pascaleSlug}}',
|
|
16
|
+
} );
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
return getPluginInstance(element)
|
|
19
|
-
},
|
|
18
|
+
{{pascaleSlug}}.setup();
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
for (const { element, reset } of this.createInstance($selector, options)) {
|
|
23
|
-
element.addEventListener('destroy', reset)
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
|
|
27
|
-
destroy ($selector) {
|
|
28
|
-
for (const { destroy } of this.getInstance($selector)) {
|
|
29
|
-
destroy()
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
|
|
33
|
-
reload ($selector, options) {
|
|
34
|
-
this.destroy($selector)
|
|
35
|
-
this.init($selector, options)
|
|
36
|
-
},
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
document.addEventListener('storepress_plugin_init', (event) => {
|
|
40
|
-
|
|
41
|
-
const defaultSettings = {}
|
|
42
|
-
const settings = { ...defaultSettings, ...event.detail?.settings }
|
|
43
|
-
const element = event.detail?.element
|
|
44
|
-
|
|
45
|
-
if (Array.isArray(element)) {
|
|
46
|
-
for (const el of element) {
|
|
47
|
-
Plugin.init(el, settings)
|
|
48
|
-
}
|
|
49
|
-
} else {
|
|
50
|
-
Plugin.init(element, settings)
|
|
51
|
-
}
|
|
52
|
-
}, { passive: true })
|
|
53
|
-
|
|
54
|
-
document.addEventListener('storepress_plugin_destroy', (event) => {
|
|
55
|
-
|
|
56
|
-
const element = event.detail?.element
|
|
57
|
-
|
|
58
|
-
if (Array.isArray(element)) {
|
|
59
|
-
for (const el of element) {
|
|
60
|
-
Plugin.destroy(el)
|
|
61
|
-
}
|
|
62
|
-
} else {
|
|
63
|
-
Plugin.destroy(element)
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
}, { passive: true })
|
|
67
|
-
|
|
68
|
-
document.addEventListener('storepress_plugin_reload', (event) => {
|
|
69
|
-
const defaultSettings = {}
|
|
70
|
-
const settings = { ...defaultSettings, ...event.detail?.settings }
|
|
71
|
-
const element = event.detail?.element
|
|
72
|
-
|
|
73
|
-
if (Array.isArray(element)) {
|
|
74
|
-
for (const el of element) {
|
|
75
|
-
Plugin.reload(el, settings)
|
|
76
|
-
}
|
|
77
|
-
} else {
|
|
78
|
-
Plugin.reload(element, settings)
|
|
79
|
-
}
|
|
80
|
-
}, { passive: true })
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
document.addEventListener('DOMContentLoaded', () => {
|
|
84
|
-
{{pascaleSlug}}Plugin()
|
|
85
|
-
triggerEvent(document, 'storepress_plugin_init', {
|
|
86
|
-
element: ['[data-plugin-settings]'],
|
|
87
|
-
settings: {},
|
|
88
|
-
})
|
|
89
|
-
})
|
|
20
|
+
export default {{pascaleSlug}};
|
package/index.js
CHANGED
|
@@ -84,6 +84,7 @@ module.exports = {
|
|
|
84
84
|
'eslint-plugin-you-dont-need-lodash-underscore',
|
|
85
85
|
'husky',
|
|
86
86
|
'lint-staged',
|
|
87
|
+
"prettier@npm:wp-prettier",
|
|
87
88
|
'fs-extra',
|
|
88
89
|
'webpack-remove-empty-scripts',
|
|
89
90
|
'eslint-plugin-prettier',
|
|
@@ -96,29 +97,16 @@ module.exports = {
|
|
|
96
97
|
'sideEffects': [
|
|
97
98
|
'src/**',
|
|
98
99
|
],
|
|
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
100
|
'main': 'build/index.js',
|
|
114
101
|
'module': 'src/index.js',
|
|
115
102
|
'files': [
|
|
116
|
-
'build/**',
|
|
117
103
|
'src/**',
|
|
118
104
|
],
|
|
119
|
-
'
|
|
120
|
-
'
|
|
121
|
-
|
|
105
|
+
'zip': [
|
|
106
|
+
'build/**',
|
|
107
|
+
'index.html',
|
|
108
|
+
'global-style.css',
|
|
109
|
+
],
|
|
122
110
|
},
|
|
123
111
|
transformer: (view) => {
|
|
124
112
|
const todayDate = new Date().toJSON().slice(0, 10)
|
|
@@ -130,6 +118,7 @@ module.exports = {
|
|
|
130
118
|
const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
|
|
131
119
|
return {
|
|
132
120
|
...view,
|
|
121
|
+
name: `@${kebabNamespace}/${kebabSlug}`,
|
|
133
122
|
todayDate: todayDate,
|
|
134
123
|
constantNamespace: constantNamespace,
|
|
135
124
|
kebabNamespace: kebabNamespace,
|
|
@@ -138,6 +127,11 @@ module.exports = {
|
|
|
138
127
|
constantSlug: constantSlug,
|
|
139
128
|
kebabSlug: kebabSlug,
|
|
140
129
|
pascaleSlug: pascaleSlug,
|
|
130
|
+
GITHUB_REPOSITORY_NAME: '${{ github.event.repository.name }}',
|
|
131
|
+
GITHUB_RELEASE_NAME: '${{ env.RELEASE_NAME }}',
|
|
132
|
+
GITHUB_RELEASE_TAG: '${{ env.RELEASE_TAG }}',
|
|
133
|
+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}',
|
|
134
|
+
GITHUB_PAGE_URL: '${{ steps.deployment.outputs.page_url }}',
|
|
141
135
|
}
|
|
142
136
|
},
|
|
143
137
|
},
|
package/package.json
CHANGED
|
@@ -26,27 +26,27 @@ jobs:
|
|
|
26
26
|
deploy:
|
|
27
27
|
environment:
|
|
28
28
|
name: github-pages
|
|
29
|
-
url:
|
|
29
|
+
url: {{ GITHUB_PAGE_URL }}
|
|
30
30
|
runs-on: ubuntu-latest
|
|
31
31
|
steps:
|
|
32
|
-
- name: Checkout
|
|
32
|
+
- name: "Checkout"
|
|
33
33
|
uses: actions/checkout@v4
|
|
34
|
-
|
|
35
|
-
- name: Setup Node
|
|
34
|
+
|
|
35
|
+
- name: "Setup Node"
|
|
36
36
|
uses: actions/setup-node@v4
|
|
37
37
|
with:
|
|
38
|
-
node-version:
|
|
39
|
-
|
|
38
|
+
node-version: '20.x'
|
|
39
|
+
|
|
40
|
+
- name: "Install and Build"
|
|
40
41
|
run: |
|
|
41
42
|
npm install
|
|
42
43
|
npm run build
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
- name: Upload
|
|
44
|
+
rm -rf node_modules
|
|
45
|
+
|
|
46
|
+
- name: "Upload Page Contents"
|
|
46
47
|
uses: actions/upload-pages-artifact@v3
|
|
47
48
|
with:
|
|
48
|
-
# Upload entire repository
|
|
49
49
|
path: '.'
|
|
50
|
-
- name: Deploy to GitHub Pages
|
|
50
|
+
- name: "Deploy to GitHub Pages"
|
|
51
51
|
id: deployment
|
|
52
52
|
uses: actions/deploy-pages@v4
|
|
@@ -10,23 +10,22 @@ on:
|
|
|
10
10
|
permissions: write-all
|
|
11
11
|
|
|
12
12
|
env:
|
|
13
|
-
REPOSITORY_NAME:
|
|
13
|
+
REPOSITORY_NAME: {{ GITHUB_REPOSITORY_NAME }}
|
|
14
14
|
|
|
15
15
|
name: Release
|
|
16
16
|
|
|
17
17
|
jobs:
|
|
18
18
|
|
|
19
|
-
|
|
20
19
|
# Build distribution release.
|
|
21
20
|
#
|
|
22
21
|
# Performs the following steps:
|
|
23
|
-
# - Checks out the repository
|
|
24
|
-
# -
|
|
25
|
-
# - Install
|
|
26
|
-
# -
|
|
27
|
-
# -
|
|
28
|
-
# -
|
|
29
|
-
|
|
22
|
+
# - Checks out the repository
|
|
23
|
+
# - Setup and Install Node.js
|
|
24
|
+
# - NPM Install
|
|
25
|
+
# - Make Zip
|
|
26
|
+
# - Get Release Version
|
|
27
|
+
# - Get Release Filename
|
|
28
|
+
# - Make Release
|
|
30
29
|
|
|
31
30
|
build:
|
|
32
31
|
name: Release
|
|
@@ -39,24 +38,26 @@ jobs:
|
|
|
39
38
|
uses: actions/setup-node@v4
|
|
40
39
|
with:
|
|
41
40
|
node-version: '20.x'
|
|
42
|
-
|
|
41
|
+
|
|
42
|
+
- name: "NPM Install"
|
|
43
|
+
run: npm install
|
|
43
44
|
|
|
44
45
|
- name: "Make Zip"
|
|
45
46
|
run: npm run plugin-zip --if-present
|
|
46
47
|
|
|
47
|
-
- name: "Get
|
|
48
|
+
- name: "Get Release Version"
|
|
48
49
|
run: |
|
|
49
50
|
echo "RELEASE_TAG=$(node -p -e "require('./package.json').version")" >> $GITHUB_ENV
|
|
50
51
|
|
|
51
|
-
- name: "Get
|
|
52
|
+
- name: "Get Release Filename"
|
|
52
53
|
run: |
|
|
53
54
|
echo "RELEASE_NAME=$(node -p -e "require('./package.json').name")" >> $GITHUB_ENV
|
|
54
55
|
|
|
55
|
-
- name: "
|
|
56
|
+
- name: "Make Release"
|
|
56
57
|
uses: softprops/action-gh-release@v2
|
|
57
58
|
with:
|
|
58
|
-
files:
|
|
59
|
+
files: ./{{ GITHUB_RELEASE_NAME }}.zip
|
|
59
60
|
make_latest: true
|
|
60
|
-
name: Release - v
|
|
61
|
+
name: Release - v{{ GITHUB_RELEASE_TAG }}
|
|
61
62
|
env:
|
|
62
|
-
GITHUB_TOKEN:
|
|
63
|
+
GITHUB_TOKEN: {{ GITHUB_TOKEN }}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
package-lock=false
|
|
@@ -4,14 +4,14 @@
|
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
6
|
<title>{{title}}</title>
|
|
7
|
+
<link rel="stylesheet" href="./global-style.css" />
|
|
7
8
|
<link rel="stylesheet" href="./build/style-plugin.css" />
|
|
8
|
-
<link rel="stylesheet" href="./style.css" />
|
|
9
9
|
</head>
|
|
10
10
|
|
|
11
11
|
<body>
|
|
12
12
|
|
|
13
13
|
<div class="wrapper">
|
|
14
|
-
<div data-
|
|
14
|
+
<div data-{{kebabSlug}}="{'greet': 'Hello'}">Hello ( Check Browser Console )</div>
|
|
15
15
|
</div>
|
|
16
16
|
|
|
17
17
|
<script src="./build/storepress-utils.js"></script>
|
|
@@ -27,12 +27,12 @@ const isZip = hasArgInCLI('--zip');
|
|
|
27
27
|
|
|
28
28
|
let files = [];
|
|
29
29
|
|
|
30
|
-
if (hasPackageProp('
|
|
30
|
+
if (hasPackageProp('zip')) {
|
|
31
31
|
stdout.write(
|
|
32
32
|
'Using the `files` field from `package.json` to detect files:\n\n'
|
|
33
33
|
);
|
|
34
34
|
|
|
35
|
-
files = glob(getPackageProp('
|
|
35
|
+
files = glob(getPackageProp('zip'), {
|
|
36
36
|
caseSensitiveMatch: false,
|
|
37
37
|
});
|
|
38
38
|
} else {
|
|
@@ -86,17 +86,23 @@ function getFile( fileName ) {
|
|
|
86
86
|
return fromProjectRoot( getProjectSourcePath() + sep + fileName );
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
function getRootFile( fileName ) {
|
|
90
|
+
return fromProjectRoot( fileName );
|
|
91
|
+
}
|
|
92
|
+
|
|
89
93
|
function getWebPackAlias() {
|
|
90
94
|
return {
|
|
91
95
|
// '@utils': getFile('utils/Plugin'), // Add @utils on .eslintrc.js -> 'import/core-modules'
|
|
92
96
|
//'@storepress/icons': getFile('packages/icons'),
|
|
93
97
|
//'@storepress/utils': getFile('packages/utils'),
|
|
94
98
|
//'@storepress/components': getFile('packages/components'),
|
|
99
|
+
'@{{kebabNamespace}}/{{kebabSlug}}': getFile('index.js'),
|
|
95
100
|
};
|
|
96
101
|
}
|
|
97
102
|
|
|
98
103
|
module.exports = {
|
|
99
104
|
getFile,
|
|
105
|
+
getRootFile,
|
|
100
106
|
getWebPackAlias,
|
|
101
107
|
requestToExternal,
|
|
102
108
|
requestToHandle,
|
|
@@ -7,6 +7,7 @@ const {
|
|
|
7
7
|
requestToHandle,
|
|
8
8
|
requestToExternalModule,
|
|
9
9
|
getFile,
|
|
10
|
+
getRootFile,
|
|
10
11
|
getWebPackAlias,
|
|
11
12
|
} = require( './tools/webpack-helpers' );
|
|
12
13
|
const WoocommerceDependencyExtractionWebpackPlugin = require( '@woocommerce/dependency-extraction-webpack-plugin' );
|
|
@@ -17,8 +18,8 @@ const scriptConfig = {
|
|
|
17
18
|
...defaultJSConfig,
|
|
18
19
|
entry: {
|
|
19
20
|
[`plugin`]: [
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
getRootFile('style.scss'),
|
|
22
|
+
getRootFile('script.js'),
|
|
22
23
|
],
|
|
23
24
|
'storepress-utils': {
|
|
24
25
|
import: '@storepress/utils/build-module/index.js',
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
npx lint-staged
|
|
File without changes
|