@storepress/create-plugin-html 0.0.4 → 0.0.6

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
@@ -7,17 +7,16 @@ This is a template for [`@wordpress/create-block`](https://developer.wordpress.o
7
7
  This template can be used by running the following command:
8
8
 
9
9
  ```bash
10
- npx @wordpress/create-block@latest --template @storepress/create-plugin-html my-extension-name
10
+ npx -y @wordpress/create-block@latest --template @storepress/create-plugin-html --no-wp-scripts my-html-extension-name && cd "$_"
11
11
  ```
12
12
 
13
13
  Navigate to the newly created folder and get started.
14
14
 
15
15
  ```
16
- cd my-extension-name
17
- npm i prettier@npm:wp-prettier@latest --save-dev
18
- npm i # Install dependencies
19
- npm run build # Build the javascript
20
- npx @wp-now/wp-now start # Start Wordpress environment
16
+ npm i # Install dependencies
17
+ npm run packages-update # Update package dependency
18
+ npm run build # Build the javascript
19
+ npx -y http-server # Start Server
21
20
  ```
22
21
 
23
22
  ## Development
@@ -25,7 +24,7 @@ npx @wp-now/wp-now start # Start Wordpress environment
25
24
  For development on this tool itself, you can also install from a local directory.
26
25
 
27
26
  ```bash
28
- npx @wordpress/create-block@latest --template ./path/to/storepress/create-plugin-html my-extension-name
27
+ npx -y @wordpress/create-block@latest --template ./path/to/storepress/create-plugin-html --no-wp-scripts my-html-extension-name && cd "$_"
29
28
  ```
30
29
 
31
30
  ### Add Tests
package/index.js CHANGED
@@ -1,140 +1,146 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- const { join } = require('path')
4
+ const {join} = require('path')
5
5
 
6
6
  // two-words
7
- function kebabCase (input) {
8
- const regex = /[-._\s+]/gi
9
- return input.replace(regex, '-').toLowerCase()
7
+ function kebabCase(input) {
8
+ const regex = /[-._\s+]/gi
9
+ return input.replace(regex, '-').toLowerCase()
10
10
  }
11
11
 
12
- function constantCase (input) {
13
- const regex = /[-._\s+]/gi
14
- return input.replace(regex, '_').toUpperCase()
12
+ function constantCase(input) {
13
+ const regex = /[-._\s+]/gi
14
+ return input.replace(regex, '_').toUpperCase()
15
15
  }
16
16
 
17
- function pascalStorePress (input) {
18
- return 'storepress' === input ? 'StorePress' : input
17
+ function pascalStorePress(input) {
18
+ return 'storepress' === input ? 'StorePress' : input
19
19
  }
20
20
 
21
- function pascalCase (input) {
22
- return (input.match(/[a-zA-Z0-9]+/g) || []).map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join('')
21
+ function pascalCase(input) {
22
+ return (input.match(/[a-zA-Z0-9]+/g) || []).map(w => `${w.charAt(0).toUpperCase()}${w.slice(1)}`).join('')
23
23
  }
24
24
 
25
25
  module.exports = {
26
- defaultValues: {
27
- folderName: 'src',
28
- namespace: 'storepress',
29
- slug: 'plugin',
30
- version: '0.0.1',
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',
26
+ defaultValues : {
27
+ folderName : 'src',
28
+ namespace : 'storepress',
29
+ slug : 'plugin',
30
+ version : '0.0.1',
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 && rimraf .husky && npx husky init && echo "npx lint-staged" > .husky/pre-commit',
40
+
41
+ 'prebuild' : 'rimraf 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-install:all" : "node ./tools/packages-install.js",
64
+ "packages-update:storepress" : "node ./tools/packages-update.js",
65
+
66
+ "packages-update" : "wp-scripts packages-update && npm run packages-update:storepress && npm run packages-install:all",
67
+
68
+ 'prepackage' : 'rimraf ${npm_package_name}.zip && npm run build',
69
+ 'package' : 'node ./tools/package.js',
70
+
71
+ 'plugin-zip' : 'npm run package -- --zip',
72
+
73
+ 'test:e2e' : 'wp-scripts test-e2e',
74
+ 'test:unit' : 'wp-scripts test-unit-js',
75
+
76
+ 'start' : 'rimraf build && wp-scripts start --webpack-copy-php --experimental-modules',
77
+ },
78
+ npmDependencies : [
79
+ '@storepress/utils',
80
+ ],
81
+ npmDevDependencies : [
82
+ '@wordpress/scripts',
83
+ '@woocommerce/dependency-extraction-webpack-plugin',
84
+ '@woocommerce/eslint-plugin',
85
+ '@wordpress/base-styles',
86
+ '@wordpress/dependency-extraction-webpack-plugin',
87
+ 'eslint-plugin-you-dont-need-lodash-underscore',
88
+ 'husky',
89
+ 'lint-staged',
90
+ "prettier@npm:wp-prettier",
91
+ 'fs-extra',
92
+ 'webpack-remove-empty-scripts',
93
+ 'eslint-plugin-prettier@5.2.1',
94
+ 'eslint-formatter-pretty',
95
+ 'rimraf',
96
+ ],
97
+ customPackageJSON : {
98
+ 'publishConfig' : {
99
+ 'access' : 'public',
100
+ },
101
+ 'sideEffects' : [
102
+ 'src/**',
103
+ ],
104
+ 'main' : 'build/index.js',
105
+ 'module' : 'src/index.js',
106
+ 'files' : [
107
+ 'src/**',
108
+ ],
109
+ 'zip' : [
110
+ 'build/**',
111
+ 'index.html',
112
+ 'global-style.css',
113
+ ],
114
+ },
115
+ transformer : (view) => {
116
+ const todayDate = new Date().toJSON().slice(0, 10)
117
+ const pascaleNamespace = pascalCase(pascalStorePress(view.namespace))
118
+ const constantNamespace = constantCase(view.namespace)
119
+ const kebabNamespace = kebabCase(view.namespace)
120
+ const constantSlug = constantCase(view.slug) // TWO_WORDS
121
+ const kebabSlug = kebabCase(view.slug) // two-words
122
+ const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
123
+ return {
124
+ ...view,
125
+ name : `@${kebabNamespace}/${kebabSlug}`,
126
+ todayDate : todayDate,
127
+ constantNamespace : constantNamespace,
128
+ kebabNamespace : kebabNamespace,
129
+ pascaleNamespace : pascaleNamespace,
130
+
131
+ constantSlug : constantSlug,
132
+ kebabSlug : kebabSlug,
133
+ pascaleSlug : pascaleSlug,
134
+
135
+ GITHUB_REPOSITORY_NAME : '${{ github.event.repository.name }}',
136
+ GITHUB_RELEASE_NAME : '${{ env.RELEASE_NAME }}',
137
+ GITHUB_RELEASE_TAG : '${{ env.RELEASE_TAG }}',
138
+ GITHUB_TOKEN : '${{ secrets.GITHUB_TOKEN }}',
139
+ GITHUB_PAGE_URL : '${{ steps.deployment.outputs.page_url }}',
140
+ GITHUB_CHANGELOG_CONTENT : "${{ steps.changelog.outputs.changelog }}",
141
+ }
142
+ },
74
143
  },
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
- "prettier@npm:wp-prettier",
88
- 'fs-extra',
89
- 'webpack-remove-empty-scripts',
90
- 'eslint-plugin-prettier',
91
- 'eslint-formatter-pretty@5',
92
- ],
93
- customPackageJSON: {
94
- 'publishConfig': {
95
- 'access': 'public',
96
- },
97
- 'sideEffects': [
98
- 'src/**',
99
- ],
100
- 'main': 'build/index.js',
101
- 'module': 'src/index.js',
102
- 'files': [
103
- 'src/**',
104
- ],
105
- 'zip': [
106
- 'build/**',
107
- 'index.html',
108
- 'global-style.css',
109
- ],
110
- },
111
- transformer: (view) => {
112
- const todayDate = new Date().toJSON().slice(0, 10)
113
- const pascaleNamespace = pascalCase(pascalStorePress(view.namespace))
114
- const constantNamespace = constantCase(view.namespace)
115
- const kebabNamespace = kebabCase(view.namespace)
116
- const constantSlug = constantCase(view.slug) // TWO_WORDS
117
- const kebabSlug = kebabCase(view.slug) // two-words
118
- const pascaleSlug = pascalCase(pascalStorePress(view.slug)) // 'TwoWords'
119
- return {
120
- ...view,
121
- name: `@${kebabNamespace}/${kebabSlug}`,
122
- todayDate: todayDate,
123
- constantNamespace: constantNamespace,
124
- kebabNamespace: kebabNamespace,
125
- pascaleNamespace: pascaleNamespace,
126
-
127
- constantSlug: constantSlug,
128
- kebabSlug: kebabSlug,
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 }}',
135
- }
136
- },
137
- },
138
- pluginTemplatesPath: join(__dirname, 'plugin-templates'),
139
- blockTemplatesPath: join(__dirname, 'block-templates'),
144
+ pluginTemplatesPath : join(__dirname, 'plugin-templates'),
145
+ blockTemplatesPath : join(__dirname, 'block-templates'),
140
146
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storepress/create-plugin-html",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
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",
@@ -25,6 +25,7 @@ jobs:
25
25
  # - Make Zip
26
26
  # - Get Release Version
27
27
  # - Get Release Filename
28
+ # - Get Changelog
28
29
  # - Make Release
29
30
 
30
31
  build:
@@ -53,11 +54,19 @@ jobs:
53
54
  run: |
54
55
  echo "RELEASE_NAME=$(node -p -e "require('./package.json').name")" >> $GITHUB_ENV
55
56
 
57
+ - name: "Get Changelog"
58
+ id: changelog
59
+ run: |
60
+ echo "changelog<<EOF" >> $GITHUB_OUTPUT
61
+ node ./tools/changelog.js >> $GITHUB_OUTPUT
62
+ echo "EOF" >> $GITHUB_OUTPUT
63
+
56
64
  - name: "Make Release"
57
65
  uses: softprops/action-gh-release@v2
58
66
  with:
59
67
  files: ./{{ GITHUB_RELEASE_NAME }}.zip
60
68
  make_latest: true
61
69
  name: Release - v{{ GITHUB_RELEASE_TAG }}
70
+ body: {{ GITHUB_CHANGELOG_CONTENT }}
62
71
  env:
63
72
  GITHUB_TOKEN: {{ GITHUB_TOKEN }}
@@ -13,7 +13,7 @@ project.properties
13
13
  *.sublime-project
14
14
  *.sublime-workspace
15
15
  .sublimelinterrc
16
- .husky/_
16
+ .husky
17
17
  src/block.json
18
18
 
19
19
  # Sass
@@ -3,8 +3,11 @@
3
3
  {{description}}
4
4
 
5
5
  ## Development
6
+
6
7
  - `npm i`
7
- - `npm run packages-update` - Update WordPress packages
8
+ - `npm run packages-update` - Update WordPress packages
9
+ - `npm run build` - Build
10
+ - `npx -y http-server` - Start Server
8
11
 
9
12
  ## Develop
10
13
 
@@ -0,0 +1,12 @@
1
+ *** {{title}} ***
2
+
3
+ 2023-09-30 - version 1.0.0
4
+ * Added - add msg
5
+ * Update - update msg
6
+ * Fixed - fix msg
7
+ * Tweak - what we tweak
8
+ * Enhancement - add action / add filter
9
+ * Performance - if any performance added
10
+
11
+ 2023-09-18 - version 1.0.0
12
+ * Initial release
@@ -6,6 +6,23 @@
6
6
  <title>{{title}}</title>
7
7
  <link rel="stylesheet" href="./global-style.css" />
8
8
  <link rel="stylesheet" href="./build/style-plugin.css" />
9
+
10
+ <script type="importmap">
11
+ {
12
+ "imports":
13
+ {
14
+ "@storepress/utils":"./build/storepress-utils-module.js"
15
+ "@huggingface/transformers":"https://esm.sh/@huggingface/transformers"
16
+ "@babycommando/entity-db":"https://esm.sh/@babycommando/entity-db"
17
+ }
18
+ }
19
+ </script>
20
+
21
+ <link rel="modulepreload" href="./build/storepress-utils-module.js" />
22
+ <link rel="modulepreload" href="https://esm.sh/@huggingface/transformers" />
23
+ <link rel="modulepreload" href="https://esm.sh/@babycommando/entity-db" />
24
+
25
+ <script type="module" src="./custom-module.js"></script>
9
26
  </head>
10
27
 
11
28
  <body>
@@ -0,0 +1,60 @@
1
+ #!/usr/bin/env node
2
+ 'use strict'
3
+ /**
4
+ * External dependencies
5
+ */
6
+ const fs = require('fs-extra')
7
+ const { stdout } = require('process')
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+
13
+ const {
14
+ getPackageProp,
15
+ fromProjectRoot,
16
+ } = require('@wordpress/scripts/utils')
17
+
18
+ const version = getPackageProp('version')
19
+
20
+ const changelogFile = fromProjectRoot('changelog.txt')
21
+
22
+ // 2. Read and find the changelog entry for the current version.
23
+ const changelogJs = fs.readFileSync(changelogFile, 'utf8')
24
+ const lines = changelogJs.split('\n')
25
+ const changelogEntry = []
26
+ let inSection = false
27
+ const versionString = `version ${version}`
28
+ const dateRegex = /^\d{4}-\d{2}-\d{2}/
29
+
30
+ for (const line of lines) {
31
+ if (inSection) {
32
+ if (dateRegex.test(line) && !line.includes(versionString)) {
33
+ break
34
+ }
35
+ changelogEntry.push(line)
36
+ } else if (line.includes(versionString)) {
37
+ inSection = true
38
+ // continue
39
+ // changelogEntry.push(line)
40
+ }
41
+ }
42
+
43
+ if (changelogEntry.length === 0) {
44
+ changelogEntry.push(`- No changelog entry for version ${version}.\n\n`)
45
+ }
46
+
47
+ // 3. Prepare the final output string
48
+ const finalOutput = changelogEntry.join('\n').trim()
49
+
50
+ // 4. Check if running in GitHub Actions environment
51
+ /*if (process.env.GITHUB_OUTPUT) {
52
+ // If yes, write to the GITHUB_OUTPUT file to set an output variable
53
+ // The format `key<<DELIMITER` is used for multiline strings
54
+ fs.appendFileSync(process.env.GITHUB_OUTPUT, `changelog_body<<EOF\n${finalOutput}\nEOF\n`)
55
+ } else {
56
+ stdout.write(`${finalOutput}\n`)
57
+ }*/
58
+
59
+ stdout.write(`## What's Changed\n\n`)
60
+ stdout.write(`${finalOutput}\n`)
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+ /**
4
+ * External dependencies
5
+ */
6
+ const fs = require('fs')
7
+ const spawn = require('cross-spawn')
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ const {
13
+ getArgFromCLI,
14
+ } = require('@wordpress/scripts/utils')
15
+
16
+ /**
17
+ * Constants
18
+ */
19
+
20
+ function readJSONFile (fileName) {
21
+ const data = fs.readFileSync(fileName, 'utf8')
22
+ return JSON.parse(data)
23
+ }
24
+
25
+ const EXACT_VERSION_PACKAGES = {
26
+ 'eslint-formatter-pretty':'5.0.0',
27
+ 'eslint-plugin-prettier':'^5.5.4',
28
+ 'prettier':'npm:wp-prettier@3.0.3',
29
+ }
30
+
31
+ function getAllPackages ({ dependencies = {}, devDependencies = {} }) {
32
+ return Object.keys(dependencies).concat(Object.keys(devDependencies)).filter((packageName) => true)
33
+ }
34
+
35
+ function getPackageVersionDiff (initialPackageJSON, finalPackageJSON) {
36
+ const diff = ['dependencies', 'devDependencies'].reduce(
37
+ (result, keyPackageJSON) => {
38
+ return Object.keys(
39
+ finalPackageJSON[keyPackageJSON] || {},
40
+ ).reduce((_result, dependency) => {
41
+ const initial =
42
+ initialPackageJSON[keyPackageJSON][dependency]
43
+ const final = finalPackageJSON[keyPackageJSON][dependency]
44
+ if (initial !== final) {
45
+ _result.push({ dependency, initial, final })
46
+ }
47
+ return _result
48
+ }, result)
49
+ },
50
+ [],
51
+ )
52
+ return diff.sort((a, b) => a.dependency.localeCompare(b.dependency))
53
+ }
54
+
55
+ function updatePackagesToLatestVersion (packages) {
56
+ const distTag = getArgFromCLI('--dist-tag') || 'latest'
57
+
58
+ const packagesWithLatest = packages.map(
59
+ (packageName) => {
60
+
61
+ const tag = EXACT_VERSION_PACKAGES[packageName] || distTag
62
+
63
+ return `${packageName}@${tag}`
64
+ },
65
+ )
66
+
67
+ return spawn.sync('npm', ['install', ...packagesWithLatest, '--save'], {
68
+ stdio: 'inherit',
69
+ })
70
+ }
71
+
72
+ function outputPackageDiffReport (packageDiff) {
73
+ console.log(
74
+ [
75
+ 'The following package versions were changed:',
76
+ ...packageDiff.map(({ dependency, initial, final }) => {
77
+ return `${dependency}: ${initial} -> ${final}`
78
+ }),
79
+ ].join('\n'),
80
+ )
81
+ }
82
+
83
+ function updatePackageJSON () {
84
+ const initialPackageJSON = readJSONFile('package.json')
85
+ const packages = getAllPackages(initialPackageJSON)
86
+
87
+ const result = updatePackagesToLatestVersion(packages)
88
+
89
+
90
+ const finalPackageJSON = readJSONFile('package.json')
91
+ outputPackageDiffReport(
92
+ getPackageVersionDiff(initialPackageJSON, finalPackageJSON),
93
+ )
94
+ process.exit(result.status)
95
+ }
96
+
97
+ updatePackageJSON()
98
+ /* eslint-enable no-console */
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env node
2
+ /* eslint-disable no-console */
3
+ /**
4
+ * External dependencies
5
+ */
6
+ const fs = require('fs')
7
+ const spawn = require('cross-spawn')
8
+
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ const {
13
+ getArgFromCLI,
14
+ } = require('@wordpress/scripts/utils')
15
+
16
+ /**
17
+ * Constants
18
+ */
19
+
20
+ const PACKAGES_PREFIX = ['@storepress/']
21
+
22
+ function readJSONFile (fileName) {
23
+ const data = fs.readFileSync(fileName, 'utf8')
24
+ return JSON.parse(data)
25
+ }
26
+
27
+ function getStorePressPackages ({ dependencies = {}, devDependencies = {} }) {
28
+ return Object.keys(dependencies).concat(Object.keys(devDependencies)).filter((packageName) => {
29
+ return PACKAGES_PREFIX.some((prefix) => packageName.startsWith(prefix))
30
+ })
31
+ }
32
+
33
+ function getPackageVersionDiff (initialPackageJSON, finalPackageJSON) {
34
+ const diff = ['dependencies', 'devDependencies'].reduce(
35
+ (result, keyPackageJSON) => {
36
+ return Object.keys(
37
+ finalPackageJSON[keyPackageJSON] || {},
38
+ ).reduce((_result, dependency) => {
39
+ const initial =
40
+ initialPackageJSON[keyPackageJSON][dependency]
41
+ const final = finalPackageJSON[keyPackageJSON][dependency]
42
+ if (initial !== final) {
43
+ _result.push({ dependency, initial, final })
44
+ }
45
+ return _result
46
+ }, result)
47
+ },
48
+ [],
49
+ )
50
+ return diff.sort((a, b) => a.dependency.localeCompare(b.dependency))
51
+ }
52
+
53
+ function updatePackagesToLatestVersion (packages) {
54
+ const distTag = getArgFromCLI('--dist-tag') || 'latest'
55
+
56
+ const packagesWithLatest = packages.map(
57
+ (packageName) => `${packageName}@${distTag}`,
58
+ )
59
+
60
+ return spawn.sync('npm', ['install', ...packagesWithLatest, '--save'], {
61
+ stdio: 'inherit',
62
+ })
63
+ }
64
+
65
+ function outputPackageDiffReport (packageDiff) {
66
+ console.log(
67
+ [
68
+ 'The following package versions were changed:',
69
+ ...packageDiff.map(({ dependency, initial, final }) => {
70
+ return `${dependency}: ${initial} -> ${final}`
71
+ }),
72
+ ].join('\n'),
73
+ )
74
+ }
75
+
76
+ function updatePackageJSON () {
77
+ const initialPackageJSON = readJSONFile('package.json')
78
+ const packages = getStorePressPackages(initialPackageJSON)
79
+
80
+ const result = updatePackagesToLatestVersion(packages)
81
+
82
+ const finalPackageJSON = readJSONFile('package.json')
83
+ outputPackageDiffReport(
84
+ getPackageVersionDiff(initialPackageJSON, finalPackageJSON),
85
+ )
86
+ process.exit(result.status)
87
+ }
88
+
89
+ updatePackageJSON()
90
+ /* eslint-enable no-console */
@@ -2,29 +2,78 @@
2
2
  /**
3
3
  * External dependencies
4
4
  */
5
- const { getProjectSourcePath } = require( '@wordpress/scripts/utils/config' );
6
- const { fromProjectRoot } = require( '@wordpress/scripts/utils/file' );
7
- const { sep } = require( 'path' );
5
+ const {getProjectSourcePath} = require('@wordpress/scripts/utils/config');
6
+ const {fromProjectRoot} = require('@wordpress/scripts/utils/file');
7
+ const {sep} = require('path');
8
8
 
9
9
  // jquery --> window.jQuery
10
10
  // react-dom --> window.ReactDOM
11
11
  // Add `slick-carousel`, `@woocommerce/blocks-registry`,`@woocommerce/settings` on `.eslintrc.js` -> 'import/core-modules'
12
12
  const externalScriptsMap = {
13
- '@storepress/utils' : ['StorePress','Utils'],
13
+ '@storepress/utils' : ['StorePress', 'Utils'],
14
14
  };
15
15
 
16
16
  // @babel/runtime/regenerator --> wp-polyfill
17
17
  const scriptHandleMap = {
18
- '@storepress/utils' : 'storepress-utils',
18
+ '@storepress/utils' : 'storepress-utils',
19
19
  };
20
20
 
21
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
- };
22
+ // 1. static import.
23
+ // '@wordpress/a11y': 'import @wordpress/a11y',
24
+ // '@storepress/utils': 'import @storepress/utils',
25
+
26
+ // view.js <script type="module" src="./view.js"></script>
27
+ // import { ... } from '@storepress/utils';
28
+
29
+ // 2. dynamic import.
30
+ // '@storepress/utils': 'module @storepress/utils',
31
+
32
+ // view.js <script type="module" src="./view.js"></script>
33
+ // import('@storepress/utils').then(()=>{});
34
+ // OR
35
+ // const config = await fetch('../config.json').then(response => response.json());
36
+ // const driver = await import(`@storepress/utils`);
37
+ // driver.connect();
38
+
39
+ /*
40
+ ```html
41
+ <script type="importmap">
42
+ {
43
+ "imports":
44
+ {
45
+ "@wordpress/interactivity":"http://example.com/wp-includes/js/dist/script-modules/interactivity/index.min.js"
46
+ "@storepress/utils":"./build/storepress-utils-module.js"
47
+ }
48
+ }
49
+ </script>
50
+
51
+ <link rel="modulepreload" href="http://example.com/wp-includes/js/dist/script-modules/interactivity/index.min.js" fetchpriority="low" />
52
+ <link rel="modulepreload" href="./build/storepress-utils-module.js" fetchpriority="low" />
53
+ ```*/
54
+
55
+ // in view.js
56
+ // ```js
57
+ // "import" prefix — static import (top-level, resolved at load time)
58
+ // import { store, getContext } from '@wordpress/a11y';
59
+ // ```
60
+
61
+ // dynamic import.
62
+ // @see: https://github.com/WordPress/gutenberg/blob/trunk/packages/block-library/src/query/view.js#L40
63
+ // ```js
64
+ // import('@wordpress/interactivity-router').then({});
65
+ // ```
66
+ // '@wordpress/interactivity-router': 'import @wordpress/interactivity-router',
67
+
68
+ // view.js
69
+
70
+ // "import" prefix — static import (top-level, resolved at load time)
71
+ // import { store, getContext } from '@wordpress/interactivity';
72
+
73
+ // "module" prefix — dynamic import (lazy, resolved at runtime)
74
+ // const loadRouter = () => import('@wordpress/interactivity-router');
75
+ }
76
+ ;
28
77
 
29
78
  /**
30
79
  * Default request to global transformation
@@ -37,10 +86,10 @@ const externalModulesMap = {
37
86
  * @return {string|string[]|undefined} The resulting external definition. Return `undefined`
38
87
  * to ignore the request. Return `string|string[]` to map the request to an external.
39
88
  */
40
- function requestToExternal( request ) {
41
- if ( externalScriptsMap[ request ] ) {
42
- return externalScriptsMap[ request ];
43
- }
89
+ function requestToExternal(request) {
90
+ if (externalScriptsMap[request]) {
91
+ return externalScriptsMap[request];
92
+ }
44
93
  }
45
94
 
46
95
  /**
@@ -54,10 +103,10 @@ function requestToExternal( request ) {
54
103
  * @return {string|undefined} WordPress script handle to map the request to. Return `undefined`
55
104
  * to use the same name as the module.
56
105
  */
57
- function requestToHandle( request ) {
58
- if ( scriptHandleMap[ request ] ) {
59
- return scriptHandleMap[ request ];
60
- }
106
+ function requestToHandle(request) {
107
+ if (scriptHandleMap[request]) {
108
+ return scriptHandleMap[request];
109
+ }
61
110
  }
62
111
 
63
112
  /**
@@ -76,35 +125,35 @@ function requestToHandle( request ) {
76
125
  * - Return `string` to map the request to an external.
77
126
  * - Return `Error` to emit an error.
78
127
  */
79
- function requestToExternalModule( request ) {
80
- if ( externalModulesMap[ request ] ) {
81
- return externalModulesMap[ request ];
82
- }
128
+ function requestToExternalModule(request) {
129
+ if (externalModulesMap[request]) {
130
+ return externalModulesMap[request];
131
+ }
83
132
  }
84
133
 
85
- function getFile( fileName ) {
86
- return fromProjectRoot( getProjectSourcePath() + sep + fileName );
134
+ function getFile(fileName) {
135
+ return fromProjectRoot(getProjectSourcePath() + sep + fileName);
87
136
  }
88
137
 
89
- function getRootFile( fileName ) {
90
- return fromProjectRoot( fileName );
138
+ function getRootFile(fileName) {
139
+ return fromProjectRoot(fileName);
91
140
  }
92
141
 
93
142
  function getWebPackAlias() {
94
- return {
95
- // '@utils': getFile('utils/Plugin'), // Add @utils on .eslintrc.js -> 'import/core-modules'
96
- //'@storepress/icons': getFile('packages/icons'),
97
- //'@storepress/utils': getFile('packages/utils'),
98
- //'@storepress/components': getFile('packages/components'),
99
- '@{{kebabNamespace}}/{{kebabSlug}}': getFile('index.js'),
100
- };
143
+ return {
144
+ // '@utils': getFile('utils/Plugin'), // Add @utils on .eslintrc.js -> 'import/core-modules'
145
+ //'@storepress/icons': getFile('packages/icons'),
146
+ //'@storepress/utils': getFile('packages/utils'),
147
+ //'@storepress/components': getFile('packages/components'),
148
+ '@{{kebabNamespace}}/{{kebabSlug}}' : getFile('index.js'),
149
+ };
101
150
  }
102
151
 
103
152
  module.exports = {
104
- getFile,
105
- getRootFile,
106
- getWebPackAlias,
107
- requestToExternal,
108
- requestToHandle,
109
- requestToExternalModule,
153
+ getFile,
154
+ getRootFile,
155
+ getWebPackAlias,
156
+ requestToExternal,
157
+ requestToHandle,
158
+ requestToExternalModule,
110
159
  };
@@ -65,6 +65,12 @@ const moduleConfig = {
65
65
  entry: {
66
66
  // ...defaultModuleConfig.entry(),
67
67
  // 'custom-module': getFile( 'custom-module.js' ),
68
+ /*'storepress-utils-module': {
69
+ import: '@storepress/utils/build-module/index.js',
70
+ library: {
71
+ type: 'module',
72
+ },
73
+ }*/
68
74
  },
69
75
 
70
76
  resolve: {