@storepress/create-plugin-html 0.0.3 → 0.0.5
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 +14 -11
- package/package.json +1 -1
- package/plugin-templates/index.html.mustache +2 -2
- 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
|
@@ -36,9 +36,9 @@ module.exports = {
|
|
|
36
36
|
attributes: {},
|
|
37
37
|
license: 'GPL-2.0-or-later',
|
|
38
38
|
customScripts: {
|
|
39
|
-
'postinstall': 'git init -q &&
|
|
39
|
+
'postinstall': 'git init -q && rimraf .husky && npx husky init && echo "npx lint-staged" > .husky/pre-commit',
|
|
40
40
|
|
|
41
|
-
'prebuild': '
|
|
41
|
+
'prebuild': 'rimraf build',
|
|
42
42
|
'build': 'npm run start -- --no-watch && wp-scripts build --webpack-copy-php --experimental-modules',
|
|
43
43
|
|
|
44
44
|
'check-engines': 'wp-scripts check-engines',
|
|
@@ -62,7 +62,7 @@ module.exports = {
|
|
|
62
62
|
|
|
63
63
|
'packages-update': 'wp-scripts packages-update',
|
|
64
64
|
|
|
65
|
-
'prepackage': '
|
|
65
|
+
'prepackage': 'rimraf ${npm_package_name}.zip && npm run build',
|
|
66
66
|
'package': './tools/package.js',
|
|
67
67
|
|
|
68
68
|
'plugin-zip': 'npm run package -- --zip',
|
|
@@ -70,7 +70,7 @@ module.exports = {
|
|
|
70
70
|
'test:e2e': 'wp-scripts test-e2e',
|
|
71
71
|
'test:unit': 'wp-scripts test-unit-js',
|
|
72
72
|
|
|
73
|
-
'start': '
|
|
73
|
+
'start': 'rimraf build && wp-scripts start --webpack-copy-php --experimental-modules',
|
|
74
74
|
},
|
|
75
75
|
npmDependencies: [
|
|
76
76
|
'@storepress/utils',
|
|
@@ -84,11 +84,12 @@ module.exports = {
|
|
|
84
84
|
'eslint-plugin-you-dont-need-lodash-underscore',
|
|
85
85
|
'husky',
|
|
86
86
|
'lint-staged',
|
|
87
|
-
"prettier@npm:wp-prettier
|
|
87
|
+
"prettier@npm:wp-prettier",
|
|
88
88
|
'fs-extra',
|
|
89
89
|
'webpack-remove-empty-scripts',
|
|
90
|
-
'eslint-plugin-prettier',
|
|
91
|
-
'eslint-formatter-pretty
|
|
90
|
+
'eslint-plugin-prettier@5.2.1',
|
|
91
|
+
'eslint-formatter-pretty',
|
|
92
|
+
'rimraf',
|
|
92
93
|
],
|
|
93
94
|
customPackageJSON: {
|
|
94
95
|
'publishConfig': {
|
|
@@ -100,12 +101,13 @@ module.exports = {
|
|
|
100
101
|
'main': 'build/index.js',
|
|
101
102
|
'module': 'src/index.js',
|
|
102
103
|
'files': [
|
|
103
|
-
'build/**',
|
|
104
104
|
'src/**',
|
|
105
105
|
],
|
|
106
|
-
'
|
|
107
|
-
'
|
|
108
|
-
|
|
106
|
+
'zip': [
|
|
107
|
+
'build/**',
|
|
108
|
+
'index.html',
|
|
109
|
+
'global-style.css',
|
|
110
|
+
],
|
|
109
111
|
},
|
|
110
112
|
transformer: (view) => {
|
|
111
113
|
const todayDate = new Date().toJSON().slice(0, 10)
|
|
@@ -117,6 +119,7 @@ module.exports = {
|
|
|
117
119
|
const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
|
|
118
120
|
return {
|
|
119
121
|
...view,
|
|
122
|
+
name: `@${kebabNamespace}/${kebabSlug}`,
|
|
120
123
|
todayDate: todayDate,
|
|
121
124
|
constantNamespace: constantNamespace,
|
|
122
125
|
kebabNamespace: kebabNamespace,
|
package/package.json
CHANGED
|
@@ -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
|