@storepress/create-plugin-html 0.0.1 → 0.0.3
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/block-templates/Plugin.js.mustache +36 -27
- package/block-templates/index.js.mustache +60 -35
- package/index.js +9 -15
- 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/lint-staged.config.js.mustache +6 -0
|
@@ -10,24 +10,10 @@ export function Plugin (element, options) {
|
|
|
10
10
|
const PRIVATE = {}
|
|
11
11
|
|
|
12
12
|
// Collecting settings from html attribute
|
|
13
|
-
const ATTRIBUTE = 'plugin-settings' //
|
|
13
|
+
const ATTRIBUTE = 'plugin-settings' // html data-plugin-settings
|
|
14
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()
|
|
15
|
+
const CLASSES = {
|
|
16
|
+
NEW: 'new-class',
|
|
31
17
|
}
|
|
32
18
|
|
|
33
19
|
const noop = () => () => {}
|
|
@@ -41,27 +27,31 @@ export function Plugin (element, options) {
|
|
|
41
27
|
}
|
|
42
28
|
|
|
43
29
|
const initial = () => {
|
|
44
|
-
|
|
30
|
+
console.log(this.settings)
|
|
45
31
|
triggerEvent(this.$element, 'afterInit', {})
|
|
46
32
|
}
|
|
47
33
|
|
|
48
|
-
const cssVariableIsTrue = (string) => {
|
|
49
|
-
return string === 'true' || string === '1' || string === 'yes'
|
|
50
|
-
}
|
|
51
34
|
const addClasses = () => {
|
|
52
|
-
|
|
35
|
+
this.$element.classList.add(CLASSES.NEW)
|
|
53
36
|
}
|
|
54
37
|
|
|
55
|
-
const
|
|
38
|
+
const addEvents = () => {
|
|
56
39
|
|
|
57
|
-
|
|
40
|
+
this.$element.addEventListener('click', (e) => {
|
|
58
41
|
|
|
59
|
-
|
|
42
|
+
console.log(e.target.getAttribute('class'))
|
|
43
|
+
|
|
44
|
+
}, { signal: this.signal, passive: true })
|
|
60
45
|
|
|
61
46
|
}
|
|
62
47
|
|
|
63
48
|
const removeEvents = () => {
|
|
64
49
|
|
|
50
|
+
this.controller.abort('Reset')
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const removeClasses = () => {
|
|
54
|
+
this.$element.classList.remove(CLASSES.NEW)
|
|
65
55
|
}
|
|
66
56
|
|
|
67
57
|
const reset = () => {
|
|
@@ -69,10 +59,29 @@ export function Plugin (element, options) {
|
|
|
69
59
|
removeEvents()
|
|
70
60
|
}
|
|
71
61
|
|
|
72
|
-
// Expose to public.
|
|
62
|
+
// Expose reset to public.
|
|
73
63
|
const expose = () => ({
|
|
74
|
-
|
|
64
|
+
reset,
|
|
75
65
|
})
|
|
76
66
|
|
|
67
|
+
// Do what you need and return expose fn.
|
|
68
|
+
const init = () => {
|
|
69
|
+
this.$element = element
|
|
70
|
+
this.settings = {
|
|
71
|
+
...DEFAULTS, ...options, ...getOptionsFromAttribute(this.$element, ATTRIBUTE), ...PRIVATE,
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
this.controller = new AbortController()
|
|
75
|
+
this.signal = this.controller.signal
|
|
76
|
+
|
|
77
|
+
initial()
|
|
78
|
+
|
|
79
|
+
addClasses()
|
|
80
|
+
|
|
81
|
+
addEvents()
|
|
82
|
+
|
|
83
|
+
return expose()
|
|
84
|
+
}
|
|
85
|
+
|
|
77
86
|
return init()
|
|
78
87
|
}
|
|
@@ -1,64 +1,89 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { createPluginInstance, triggerEvent } from '@storepress/utils'
|
|
4
|
+
import { createPluginInstance, triggerEvent, getPluginInstance } from '@storepress/utils'
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Internal dependencies
|
|
8
8
|
*/
|
|
9
|
-
import { Plugin } from './Plugin'
|
|
9
|
+
import { Plugin as Instance } from './Plugin'
|
|
10
10
|
|
|
11
|
-
export default function
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
return createPluginInstance(element,
|
|
11
|
+
export default function {{pascaleSlug}}Plugin () {
|
|
12
|
+
const Plugin = {
|
|
13
|
+
createInstance (element, options) {
|
|
14
|
+
return createPluginInstance(element, options, Instance)
|
|
15
15
|
},
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
element.addEventListener('destroy', unregister)
|
|
20
|
-
}
|
|
17
|
+
getInstance (element) {
|
|
18
|
+
return getPluginInstance(element)
|
|
21
19
|
},
|
|
22
20
|
|
|
23
|
-
init () {
|
|
24
|
-
for (const { element,
|
|
25
|
-
element.addEventListener('destroy',
|
|
21
|
+
init ($selector, options) {
|
|
22
|
+
for (const { element, reset } of this.createInstance($selector, options)) {
|
|
23
|
+
element.addEventListener('destroy', reset)
|
|
26
24
|
}
|
|
27
25
|
},
|
|
28
26
|
|
|
29
|
-
destroy () {
|
|
30
|
-
for (const { destroy } of this.getInstance(
|
|
27
|
+
destroy ($selector) {
|
|
28
|
+
for (const { destroy } of this.getInstance($selector)) {
|
|
31
29
|
destroy()
|
|
32
30
|
}
|
|
33
31
|
},
|
|
34
32
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
33
|
+
reload ($selector, options) {
|
|
34
|
+
this.destroy($selector)
|
|
35
|
+
this.init($selector, options)
|
|
39
36
|
},
|
|
40
37
|
}
|
|
41
38
|
|
|
42
|
-
document.addEventListener('storepress_plugin_init', () => {
|
|
43
|
-
StorePressPlugin.init()
|
|
44
|
-
})
|
|
39
|
+
document.addEventListener('storepress_plugin_init', (event) => {
|
|
45
40
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
41
|
+
const defaultSettings = {}
|
|
42
|
+
const settings = { ...defaultSettings, ...event.detail?.settings }
|
|
43
|
+
const element = event.detail?.element
|
|
49
44
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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 })
|
|
54
53
|
|
|
55
|
-
document.addEventListener('
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
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 })
|
|
59
81
|
}
|
|
60
82
|
|
|
61
83
|
document.addEventListener('DOMContentLoaded', () => {
|
|
62
|
-
|
|
63
|
-
triggerEvent(document, 'storepress_plugin_init'
|
|
84
|
+
{{pascaleSlug}}Plugin()
|
|
85
|
+
triggerEvent(document, 'storepress_plugin_init', {
|
|
86
|
+
element: ['[data-plugin-settings]'],
|
|
87
|
+
settings: {},
|
|
88
|
+
})
|
|
64
89
|
})
|
package/index.js
CHANGED
|
@@ -27,7 +27,7 @@ module.exports = {
|
|
|
27
27
|
folderName: 'src',
|
|
28
28
|
namespace: 'storepress',
|
|
29
29
|
slug: 'plugin',
|
|
30
|
-
version: '0.1
|
|
30
|
+
version: '0.0.1',
|
|
31
31
|
title: 'StorePress Plugin',
|
|
32
32
|
description: 'A StorePress Plugin',
|
|
33
33
|
author: 'EmranAhmed',
|
|
@@ -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@latest",
|
|
87
88
|
'fs-extra',
|
|
88
89
|
'webpack-remove-empty-scripts',
|
|
89
90
|
'eslint-plugin-prettier',
|
|
@@ -96,20 +97,6 @@ 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': [
|
|
@@ -127,6 +114,7 @@ module.exports = {
|
|
|
127
114
|
const kebabNamespace = kebabCase(view.namespace)
|
|
128
115
|
const constantSlug = constantCase(view.slug) // TWO_WORDS
|
|
129
116
|
const kebabSlug = kebabCase(view.slug) // two-words
|
|
117
|
+
const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
|
|
130
118
|
return {
|
|
131
119
|
...view,
|
|
132
120
|
todayDate: todayDate,
|
|
@@ -136,6 +124,12 @@ module.exports = {
|
|
|
136
124
|
|
|
137
125
|
constantSlug: constantSlug,
|
|
138
126
|
kebabSlug: kebabSlug,
|
|
127
|
+
pascaleSlug: pascaleSlug,
|
|
128
|
+
GITHUB_REPOSITORY_NAME: '${{ github.event.repository.name }}',
|
|
129
|
+
GITHUB_RELEASE_NAME: '${{ env.RELEASE_NAME }}',
|
|
130
|
+
GITHUB_RELEASE_TAG: '${{ env.RELEASE_TAG }}',
|
|
131
|
+
GITHUB_TOKEN: '${{ secrets.GITHUB_TOKEN }}',
|
|
132
|
+
GITHUB_PAGE_URL: '${{ steps.deployment.outputs.page_url }}',
|
|
139
133
|
}
|
|
140
134
|
},
|
|
141
135
|
},
|
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
|