Skip to content

Commit

Permalink
feat: remove PLUGIN_NAME env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
j7-dev committed Apr 2, 2024
1 parent 4fe5467 commit db84871
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
1 change: 0 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
GITHUB_TOKEN="ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
PLUGIN_NAME="wp-react-plugin"
12 changes: 10 additions & 2 deletions release/.release-it.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,17 @@
* documentation
* @see https://github.com/release-it/release-it/blob/main/docs/configuration.md
*/
const pluginName = process?.env?.PLUGIN_NAME || 'wp-react-plugin'

const path = require('path')

// get parent directory path
const parentDirectoryPath = path.resolve(__dirname, `../`)

// get parent directory name
const pluginName = path.basename(parentDirectoryPath)

module.exports = {
releasedPluginName: 'wp-react-plugin',
git: {
commit: true,
commitMessage: 'chore: release v${version}',
Expand Down Expand Up @@ -44,7 +52,7 @@ module.exports = {
assets: [`./release/${pluginName}.zip`], // relative path
web: false,
},
includes: [
allowedItems: [
'inc',
'js/dist',
'required_plugins',
Expand Down
14 changes: 9 additions & 5 deletions release/README_cn-zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,8 @@ composer install

`GITHUB_TOKEN` 填入您的 [`github personal token`](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens#creating-a-personal-access-token-classic)

`PLUGIN_NAME` 填入您的套件目錄名稱,如果填寫錯誤,將無法正確完成打包,🚩寫名稱就好,不需要寫路徑

```bash
GITHUB_TOKEN="ghp_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
PLUGIN_NAME="wp-react-plugin"
```

🚩🚩🚩 因為安全因素,請勿將 GITHUB_TOKEN, 即此 `.env` 納入 github 版本控制中 (預設已在 `.gitignore` 排除),否則 github 將會 Block 你的 push
Expand All @@ -96,13 +93,17 @@ PLUGIN_NAME="wp-react-plugin"

所有預設 config 可以參考這 [default config](https://github.com/release-it/release-it/blob/main/config/release-it.json)

接著到設定您要打包的目錄,只有被寫入在 `includes` array 內的檔案會被複製 (會遞規複製裡面的檔案&目錄),例如
---

我們在 `.release-it.cjs` 有兩個自訂的配置項: `allowedItems``releasedPluginName`

`allowedItems`: 只有被寫入在 `allowedItems` array 內的檔案會被複製 (會遞規複製裡面的檔案&目錄),例如

```
// .release-it.cjs
{
...
includes: [
allowedItems: [
'inc',
'js/dist', // 只複製 js/dist,而不會複製 js/src
'required_plugins',
Expand All @@ -115,6 +116,9 @@ PLUGIN_NAME="wp-react-plugin"
}
```

`releasedPluginName`: 最終打包的 zip 檔案名稱,例如: 您也可以叫做 my-plugin-release


### 3. 發布

發布前確保一系列工具指令是可以運作的,例如 `eslint`, `phpcbf` 可以作用
Expand Down
7 changes: 3 additions & 4 deletions release/create-release.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
const fs = require('fs')
const path = require('path')
const { deleteRelease } = require('./delete-release.cjs')
const { includes } = require('./.release-it.cjs')
const pluginName = process?.env?.PLUGIN_NAME || 'wp-react-plugin'
const { allowedItems, releasedPluginName } = require('./.release-it.cjs')
const sourceDir = path.resolve(__dirname, '../')
const destinationDir = path.resolve(__dirname, `./${pluginName}`)
const destinationDir = path.resolve(__dirname, `./${releasedPluginName}`)

/**
* Recursively copy directories and files
Expand Down Expand Up @@ -88,4 +87,4 @@ deleteRelease()

// then create release directory

recursiveCopy(sourceDir, destinationDir, includes)
recursiveCopy(sourceDir, destinationDir, allowedItems)
6 changes: 3 additions & 3 deletions release/delete-release.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
* Clear files in the release directory
*/

const pluginName = process?.env?.PLUGIN_NAME || 'wp-react-plugin'
const { releasedPluginName } = require('./.release-it.cjs')
const fs = require('fs')
const path = require('path')
const entryDir = path.resolve(__dirname, `./${pluginName}`)
const outputZip = path.resolve(__dirname, `./${pluginName}.zip`)
const entryDir = path.resolve(__dirname, `./${releasedPluginName}`)
const outputZip = path.resolve(__dirname, `./${releasedPluginName}.zip`)

/**
* Delete directory recursively
Expand Down
6 changes: 3 additions & 3 deletions release/zip.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
* @see https://www.npmjs.com/package/archiver
*/

const pluginName = process?.env?.PLUGIN_NAME || 'wp-react-plugin'
const { releasedPluginName } = require('./.release-it.cjs')
const fs = require('fs')
const path = require('path')
const entryDir = path.resolve(__dirname, `./${pluginName}`)
const outputZip = path.resolve(__dirname, `./${pluginName}.zip`)
const entryDir = path.resolve(__dirname, `./${releasedPluginName}`)
const outputZip = path.resolve(__dirname, `./${releasedPluginName}.zip`)
const archiver = require('archiver')

// 創建一個檔案來存儲zip檔案
Expand Down

0 comments on commit db84871

Please sign in to comment.