@storepress/create-plugin-html 0.0.3 → 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 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, ...options, ...getOptionsFromAttribute(this.$element, ATTRIBUTE), ...PRIVATE,
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 { createPluginInstance, triggerEvent, getPluginInstance } from '@storepress/utils'
4
+ import { createStorePressPlugin } from '@storepress/utils';
5
5
 
6
6
  /**
7
7
  * Internal dependencies
8
8
  */
9
- import { Plugin as Instance } from './Plugin'
9
+ import { Plugin } from './Plugin';
10
10
 
11
- export default function {{pascaleSlug}}Plugin () {
12
- const Plugin = {
13
- createInstance (element, options) {
14
- return createPluginInstance(element, options, Instance)
15
- },
11
+ const {{pascaleSlug}} = createStorePressPlugin( {
12
+ selector: '[data-{{kebabSlug}}]',
13
+ options: {},
14
+ plugin: Plugin,
15
+ namespace: '{{pascaleSlug}}',
16
+ } );
16
17
 
17
- getInstance (element) {
18
- return getPluginInstance(element)
19
- },
18
+ {{pascaleSlug}}.setup();
20
19
 
21
- init ($selector, options) {
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}};
@@ -4,7 +4,7 @@
4
4
 
5
5
  $default-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
6
6
 
7
- :where([data-plugin-settings]) {
7
+ :where([data-{{kebabSlug}}]) {
8
8
  font-family: $default-font;
9
9
 
10
10
  @include plugin.init();
package/index.js CHANGED
@@ -84,7 +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
+ "prettier@npm:wp-prettier",
88
88
  'fs-extra',
89
89
  'webpack-remove-empty-scripts',
90
90
  'eslint-plugin-prettier',
@@ -100,12 +100,13 @@ module.exports = {
100
100
  'main': 'build/index.js',
101
101
  'module': 'src/index.js',
102
102
  'files': [
103
- 'build/**',
104
103
  'src/**',
105
104
  ],
106
- 'bin': {
107
- 'package': './tools/package.js',
108
- },
105
+ 'zip': [
106
+ 'build/**',
107
+ 'index.html',
108
+ 'global-style.css',
109
+ ],
109
110
  },
110
111
  transformer: (view) => {
111
112
  const todayDate = new Date().toJSON().slice(0, 10)
@@ -117,6 +118,7 @@ module.exports = {
117
118
  const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
118
119
  return {
119
120
  ...view,
121
+ name: `@${kebabNamespace}/${kebabSlug}`,
120
122
  todayDate: todayDate,
121
123
  constantNamespace: constantNamespace,
122
124
  kebabNamespace: kebabNamespace,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storepress/create-plugin-html",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A template to be used with `@wordpress/create-block` to create a StorePress HTML based JS Extension.",
5
5
  "author": "StorePress",
6
6
  "main": "index.js",
@@ -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-plugin-settings="{'greet': 'Hello'}">Hello ( Check Browser Console )</div>
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>
@@ -0,0 +1,8 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import {{pascaleSlug}} from '@{{kebabNamespace}}/{{kebabSlug}}';
5
+
6
+ document.addEventListener( 'DOMContentLoaded', () => {
7
+ {{pascaleSlug}}.init();
8
+ } );
@@ -0,0 +1,10 @@
1
+ @charset "UTF-8";
2
+
3
+ @use "./src/mixins" as plugin;
4
+
5
+ :where([data-{{kebabSlug}}]) {
6
+ @include plugin.init();
7
+ & {
8
+ --custom-variable: 1px;
9
+ }
10
+ }
@@ -27,12 +27,12 @@ const isZip = hasArgInCLI('--zip');
27
27
 
28
28
  let files = [];
29
29
 
30
- if (hasPackageProp('files')) {
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('files'), {
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
- getFile('style.scss'),
21
- getFile('index.js'),
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