@airfleet/generator-init 0.15.2 → 0.16.0

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.
Files changed (25) hide show
  1. package/README.md +2 -2
  2. package/generators/npm/index.js +0 -1
  3. package/generators/plugin/index.js +64 -11
  4. package/generators/plugin/templates/.github/workflows/create-asana-attachment.yaml +19 -0
  5. package/generators/plugin/templates/.github/workflows/release-plugin.yml +185 -0
  6. package/generators/plugin/templates/.github/workflows/test-wordpress.yml +56 -0
  7. package/generators/plugin/templates/.prettierignore +3 -0
  8. package/generators/plugin/templates/README.md.ejs +2 -1
  9. package/generators/plugin/templates/composer-scoped.json.ejs +5 -0
  10. package/generators/plugin/templates/composer-scoped.lock.ejs +56 -0
  11. package/generators/plugin/templates/composer.json.ejs +15 -2
  12. package/generators/plugin/templates/gitignore +2 -0
  13. package/generators/plugin/templates/inc/AjaxVariables.php.ejs +22 -0
  14. package/generators/plugin/templates/inc/AjaxVariablesAdmin.php.ejs +22 -0
  15. package/generators/plugin/templates/inc/Options/GeneralOptions.php.ejs +43 -0
  16. package/generators/plugin/templates/inc/Options.php.ejs +17 -0
  17. package/generators/plugin/templates/inc/Pages.php.ejs +35 -0
  18. package/generators/plugin/templates/inc/Setup.php.ejs +36 -65
  19. package/generators/plugin/templates/package.json.ejs +2 -1
  20. package/generators/plugin/templates/phpcs.xml.ejs +4 -0
  21. package/generators/plugin/templates/plugin-name.php.ejs +23 -2
  22. package/generators/plugin/templates/scoper.custom.php.ejs +8 -0
  23. package/package.json +2 -2
  24. package/generators/npm/templates/.gitlab-ci.yml +0 -8
  25. package/generators/plugin/templates/.gitlab-ci.yml +0 -14
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Airfleet Generator
2
2
 
3
- ![npm](https://img.shields.io/npm/v/@airfleet/generator-init)
4
- [![pipeline status](https://gitlab.com/codersclan/tools/airfleet-generator/badges/main/pipeline.svg)](https://gitlab.com/codersclan/tools/airfleet-generator/-/commits/main)
3
+ [![npm](https://img.shields.io/npm/v/@airfleet/generator-init)](https://www.npmjs.com/package/@airfleet/generator-init)
4
+ [![📦 Release (npm)](https://github.com/airfleet/airfleet-generator-cli/actions/workflows/release-npm.yml/badge.svg)](https://github.com/airfleet/airfleet-generator-cli/actions/workflows/release-npm.yml)
5
5
 
6
6
  A Yeoman generator to scaffold common Airfleet features.
7
7
 
@@ -96,7 +96,6 @@ export default class extends Generator {
96
96
  ".airfleet-release",
97
97
  ".editorconfig",
98
98
  ".gitattributes",
99
- ".gitlab-ci.yml",
100
99
  "CHANGELOG.md",
101
100
  "LICENSE.ejs",
102
101
  "package.json.ejs",
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  import Generator from "yeoman-generator";
3
+ import { paramCase } from "change-case";
3
4
 
4
5
  import nameCases from "../../utils/nameCases.js";
5
6
  import copyTemplates from "../../utils/copyTemplates.js";
@@ -8,8 +9,6 @@ import requiredText from "../../utils/validation/requiredText.js";
8
9
  import title from "../../utils/log/title.js";
9
10
  import highlightText from "../../utils/log/text/highlightText.js";
10
11
  import lines from "../../utils/log/text/lines.js";
11
- import brandText from "../../utils/log/text/brandText.js";
12
- import dangerText from "../../utils/log/text/dangerText.js";
13
12
  import infoBox from "../../utils/log/boxes/infoBox.js";
14
13
 
15
14
  export default class extends Generator {
@@ -60,12 +59,6 @@ export default class extends Generator {
60
59
  message: "What's the documentation URL? (Notion page)",
61
60
  validate: requiredText("Please enter the documentation URL"),
62
61
  },
63
- {
64
- type: "confirm",
65
- name: "pluginCreateOptions",
66
- message: "Create theme options page?",
67
- default: true,
68
- },
69
62
  {
70
63
  type: "input",
71
64
  name: "pluginVersion",
@@ -78,7 +71,7 @@ export default class extends Generator {
78
71
  name: "pluginPhpVersion",
79
72
  message: "What's the required PHP version?",
80
73
  validate: requiredText("Please enter the PHP version"),
81
- default: ">=7.4",
74
+ default: ">=8.0",
82
75
  },
83
76
  {
84
77
  type: "input",
@@ -87,10 +80,35 @@ export default class extends Generator {
87
80
  validate: requiredText("Please enter the Node version"),
88
81
  default: ">=16",
89
82
  },
83
+ {
84
+ type: "list",
85
+ name: "pluginCreateOptions",
86
+ message: "Create options page?",
87
+ choices: ["No", "Framework", "ACF"],
88
+ default: "Framework",
89
+ },
90
+ {
91
+ type: "confirm",
92
+ name: "pluginAcfLocalJson",
93
+ message: "Add ACF Local JSON?",
94
+ default: false,
95
+ },
96
+ {
97
+ type: "list",
98
+ name: "pluginAjaxVariables",
99
+ message: "Add AJAX variables?",
100
+ choices: ["No", "Frontend", "Admin", "Both"],
101
+ default: "No",
102
+ },
90
103
  ];
91
104
 
92
105
  this.answers = await this.prompt(prompts);
93
106
  this.name = nameCases(this.answers.pluginName);
107
+ this.ajaxVariables = {
108
+ frontend: this.answers.pluginAjaxVariables === 'Both' || this.answers.pluginAjaxVariables === 'Frontend',
109
+ admin: this.answers.pluginAjaxVariables === 'Both' || this.answers.pluginAjaxVariables === 'Admin',
110
+ };
111
+ this.optionsPage = paramCase(this.answers.pluginCreateOptions);
94
112
 
95
113
  const nameNoAirfleet = this.answers.pluginName
96
114
  .replace(/^airfleet/i, "")
@@ -104,14 +122,18 @@ export default class extends Generator {
104
122
  packageName: `@airfleet/${this.nameNoAirfleet.slug}-wp-plugin`,
105
123
  mainBranch: "main",
106
124
  year: new Date().getFullYear(),
125
+ ajaxVariables: this.ajaxVariables,
126
+ optionsPage: this.optionsPage,
107
127
  };
108
128
  }
109
129
 
110
130
  writing() {
111
131
  const files = [
132
+ ".github/workflows/create-asana-attachment.yaml",
133
+ ".github/workflows/release-plugin.yml",
134
+ ".github/workflows/test-wordpress.yml",
112
135
  ".husky/pre-commit",
113
136
  ".vscode/settings.json",
114
- "acf-json/.gitkeep",
115
137
  "assets/admin/scripts/admin.entry.js",
116
138
  "assets/admin/styles/admin.entry.scss",
117
139
  "assets/editor/scripts/editor.entry.js",
@@ -128,16 +150,17 @@ export default class extends Generator {
128
150
  ".editorconfig",
129
151
  ".env",
130
152
  ".gitattributes",
131
- ".gitlab-ci.yml",
132
153
  ".parcelrc",
133
154
  ".prettierignore",
134
155
  "CHANGELOG.md",
156
+ "composer-scoped.json.ejs",
135
157
  "composer.json.ejs",
136
158
  "index.php",
137
159
  "LICENSE.ejs",
138
160
  "package.json.ejs",
139
161
  "phpcs.xml.ejs",
140
162
  "README.md.ejs",
163
+ "scoper.custom.php.ejs",
141
164
  ];
142
165
  const templates = [
143
166
  ...mapFilesToTemplates(files),
@@ -156,6 +179,36 @@ export default class extends Generator {
156
179
  destination: `${this.name.slug}.php`,
157
180
  isEnabled: true,
158
181
  },
182
+ {
183
+ template: "inc/AjaxVariables.php.ejs",
184
+ destination: `inc/AjaxVariables.php`,
185
+ isEnabled: this.ajaxVariables.frontend,
186
+ },
187
+ {
188
+ template: "inc/AjaxVariablesAdmin.php.ejs",
189
+ destination: `inc/AjaxVariablesAdmin.php`,
190
+ isEnabled: this.ajaxVariables.admin,
191
+ },
192
+ {
193
+ template: "inc/Options.php.ejs",
194
+ destination: `inc/Options.php`,
195
+ isEnabled: this.optionsPage === 'framework',
196
+ },
197
+ {
198
+ template: "inc/Options/GeneralOptions.php.ejs",
199
+ destination: `inc/Options/GeneralOptions.php`,
200
+ isEnabled: this.optionsPage === 'framework',
201
+ },
202
+ {
203
+ template: "inc/Pages.php.ejs",
204
+ destination: `inc/Pages.php`,
205
+ isEnabled: this.optionsPage === 'framework',
206
+ },
207
+ {
208
+ template: "acf-json/.gitkeep",
209
+ destination: `acf-json/.gitkeep`,
210
+ isEnabled: this.answers.pluginAcfLocalJson,
211
+ },
159
212
  ];
160
213
 
161
214
  copyTemplates(this, templates, this.data);
@@ -0,0 +1,19 @@
1
+ name: ✍️ Asana Create PR Attachment
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, reopened]
6
+
7
+ jobs:
8
+ create-asana-attachment-job:
9
+ runs-on: ubuntu-latest
10
+ timeout-minutes: 1
11
+ name: Create pull request attachments on Asana tasks
12
+ steps:
13
+ - name: Create pull request attachments
14
+ uses: Asana/create-app-attachment-github-action@latest
15
+ id: postAttachment
16
+ with:
17
+ asana-secret: ${{ secrets.ASANA_SECRET }}
18
+ - name: Log output status
19
+ run: echo "Status is ${{ steps.postAttachment.outputs.status }}"
@@ -0,0 +1,185 @@
1
+ name: 📦 Release (Plugin)
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ workflow_dispatch:
7
+
8
+ jobs:
9
+ release:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - name: 🚚 Get latest code
14
+ uses: actions/checkout@v3
15
+
16
+ - name: ⚙️ Setup PHP
17
+ uses: shivammathur/setup-php@v2
18
+ with:
19
+ php-version: "8.1"
20
+ ini-values: short_open_tag=1
21
+ env:
22
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
23
+
24
+ - name: ⚙️ Setup Node
25
+ uses: actions/setup-node@v3
26
+ with:
27
+ node-version: 16
28
+ cache: "npm"
29
+
30
+ - name: ⚙️ Get Composer cache directory
31
+ id: composer-cache
32
+ run: echo "::set-output name=dir::$(composer config cache-files-dir)"
33
+
34
+ - name: ⚙️ Cache Composer dependencies
35
+ uses: actions/cache@v3
36
+ with:
37
+ path: ${{ steps.composer-cache.outputs.dir }}
38
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
39
+ restore-keys: ${{ runner.os }}-composer-
40
+
41
+ - name: 🔨 Increase composer timeout
42
+ run: composer --global config process-timeout 1500
43
+
44
+ - name: 🔨 Composer install (with dev dependencies)
45
+ run: composer install --prefer-dist --no-ansi --no-interaction --no-progress --optimize-autoloader
46
+
47
+ - name: 🔨 npm install
48
+ run: npm ci
49
+
50
+ - name: 🔬 Test
51
+ run: npm test
52
+
53
+ - name: 🔨 Composer install (without dev dependencies)
54
+ run: composer install --prefer-dist --no-ansi --no-interaction --no-progress --no-dev --optimize-autoloader
55
+
56
+ - name: 🔨 Install release dependencies
57
+ run: npm install -g release-it@^15 @release-it/keep-a-changelog@^3
58
+
59
+ - name: 🔨 Additional release dependencies
60
+ run: |
61
+ npm install -g @release-it/bumper@^4 json
62
+ sudo apt-get install jo
63
+
64
+ - name: 🔨 Config git
65
+ run: |
66
+ git config user.name "${GITHUB_ACTOR}"
67
+ git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
68
+
69
+ - name: 🔧 Get plugin name
70
+ id: plugin
71
+ # For a better understanding of how the name is generated
72
+ # see https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
73
+ # see https://www.gnu.org/software/bash/manual/html_node/Shell-Parameter-Expansion.html
74
+ # basically we start with "airfleet/airfleet-analytics-plugin" and end up with "airfleet-analytics"
75
+ run: |
76
+ NAME=${GITHUB_REPOSITORY#*/}
77
+ NAME=${NAME%-plugin}
78
+ echo "Plugin name: ${NAME}"
79
+ echo "::set-output name=PLUGIN_NAME::$NAME"
80
+
81
+ - name: 🔧 Get changelog
82
+ id: changelog
83
+ run: |
84
+ echo "$(sed '/## \[Unreleased\]/,/## \[/!d' CHANGELOG.md | sed '1d;$d')" > $RUNNER_TEMP/latest_changelog.txt
85
+ cat $RUNNER_TEMP/latest_changelog.txt
86
+
87
+ - name: 📦 Release
88
+ run:
89
+ export PLUGIN="${{ steps.plugin.outputs.PLUGIN_NAME }}" && npx release-it $(cat .airfleet-release)
90
+ -VV
91
+ --ci
92
+ --hooks.before:release='echo Building $PLUGIN'
93
+ --hooks.before:release='npm run build --if-present'
94
+ --hooks.before:release='mkdir -p $RUNNER_TEMP/.release-dist/$PLUGIN/'
95
+ --hooks.before:release='rsync -a . $RUNNER_TEMP/.release-dist/$PLUGIN/'
96
+ --hooks.before:release='cd $RUNNER_TEMP/.release-dist && du -hs $PLUGIN'
97
+ --hooks.before:release='rm -rf $RUNNER_TEMP/.release-dist/$PLUGIN/.git/'
98
+ --hooks.before:release='rm -rf $RUNNER_TEMP/.release-dist/$PLUGIN/node_modules/'
99
+ --hooks.before:release='rm -rf $RUNNER_TEMP/.release-dist/$PLUGIN/.parcel-cache/'
100
+ --hooks.before:release='cd $RUNNER_TEMP/.release-dist && du -hs $PLUGIN'
101
+ --hooks.before:release='cd $RUNNER_TEMP/.release-dist && ls -la'
102
+ --hooks.before:release='cd $RUNNER_TEMP/.release-dist/$PLUGIN/ && ls -la'
103
+ --hooks.before:release='cd $RUNNER_TEMP/.release-dist && zip -rq $PLUGIN.zip $PLUGIN'
104
+ --hooks.before:release='cd $RUNNER_TEMP/.release-dist && du -hs $PLUGIN.zip'
105
+ --hooks.before:release='rm -rf $RUNNER_TEMP/.release-dist/$PLUGIN/'
106
+ --hooks.before:release='cd $RUNNER_TEMP/.release-dist && ls -la'
107
+ --hooks.before:release='cp -R $RUNNER_TEMP/.release-dist dist/.release-dist'
108
+ --git.pushArgs='--follow-tags'
109
+ --git.pushArgs='-o ci.skip'
110
+ --no-npm.publish
111
+ --github.release
112
+ --github.assets='dist/.release-dist/**/*'
113
+ --plugins.@release-it/keep-a-changelog.filename=CHANGELOG.md
114
+ --no-plugins.@release-it/keep-a-changelog.strictLatest
115
+ --plugins.@release-it/keep-a-changelog.addUnreleased
116
+ --plugins.@release-it/keep-a-changelog.addVersionUrl
117
+ --plugins.@release-it/keep-a-changelog.head=main
118
+ --plugins.@release-it/bumper.out.file=*.php
119
+ --plugins.@release-it/bumper.out.type=text/php
120
+ env:
121
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
122
+
123
+ - name: ⚒️ Build plugin.json
124
+ run: |
125
+ PLUGIN="${{ steps.plugin.outputs.PLUGIN_NAME }}"
126
+ NAME="$(grep 'Plugin Name' $PLUGIN.php | sed 's/\*//; s/Plugin Name://; s/^[ t]*//')"
127
+ DESCRIPTION="$(cat package.json | json description)"
128
+ SLUG="$PLUGIN/$PLUGIN.php"
129
+ VERSION="$(cat package.json | json version)"
130
+ DATE="$(date -u +%FT%TZ)"
131
+ CHANGELOG="$(cat $RUNNER_TEMP/latest_changelog.txt)"
132
+ VERSIONS="[$(jo version="$VERSION" date="$DATE" changelog="$CHANGELOG" )]"
133
+ echo "Plugin: $PLUGIN"
134
+ echo "Name: $NAME"
135
+ echo "Description: $DESCRIPTION"
136
+ echo "Slug: $SLUG"
137
+ echo "Version: $VERSION"
138
+ echo "Date: $DATE"
139
+ echo "Changelog: $CHANGELOG"
140
+ echo "Versions: $VERSIONS"
141
+ jo -p name="$NAME" description="$DESCRIPTION" slug="$SLUG" versions="$VERSIONS" > $RUNNER_TEMP/plugin.json
142
+ cat $RUNNER_TEMP/plugin.json
143
+
144
+ - name: ⚙️ Configure AWS Credentials
145
+ uses: aws-actions/configure-aws-credentials@v1
146
+ with:
147
+ aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
148
+ aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
149
+ aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
150
+
151
+ - name: 🚀 Upload plugin zip file to AWS
152
+ run: |
153
+ PLUGIN="${{ steps.plugin.outputs.PLUGIN_NAME }}"
154
+ BUCKET="${{ secrets.AWS_S3_BUCKET }}"
155
+ FILENAME="$PLUGIN.$(cat $RUNNER_TEMP/plugin.json | json versions.0.version).zip"
156
+ aws s3 cp $RUNNER_TEMP/.release-dist/$PLUGIN.zip s3://$BUCKET/$PLUGIN/$FILENAME
157
+
158
+ - name: 📥 Download plugins list from AWS
159
+ run: |
160
+ BUCKET="${{ secrets.AWS_S3_BUCKET }}"
161
+ aws s3 cp s3://$BUCKET/plugins.json $RUNNER_TEMP/plugins.json
162
+ echo "Current plugins.json from S3"
163
+ cat $RUNNER_TEMP/plugins.json | json
164
+
165
+ - name: ⚒️ Build new plugins list
166
+ # Reference https://trentm.com/json/
167
+ run: |
168
+ NL=$'\n'
169
+ PLUGIN_SLUG=$(cat $RUNNER_TEMP/plugin.json | json slug)
170
+ echo "Plugin slug: $PLUGIN_SLUG"
171
+ PLUGIN_VERSIONS=$(echo "$(cat $RUNNER_TEMP/plugin.json | json versions)${NL}$(cat $RUNNER_TEMP/plugins.json | json plugins | json -c "this.slug === '$PLUGIN_SLUG'" | json 0.versions)" | json --group)
172
+ echo "Plugin versions:"
173
+ echo $PLUGIN_VERSIONS | json
174
+ PLUGIN_UPDATED=$(echo "$(cat $RUNNER_TEMP/plugins.json | json plugins | json -c "this.slug === '$PLUGIN_SLUG'" | json 0)${NL}$(cat $RUNNER_TEMP/plugin.json | json)" | json --merge | json -e "this.versions = $PLUGIN_VERSIONS" | json)
175
+ echo "Plugin updated:"
176
+ echo $PLUGIN_UPDATED | json
177
+ PLUGINS_LIST_UPDATED=$(echo "$(cat $RUNNER_TEMP/plugins.json | json plugins | json -c "this.slug !== '$PLUGIN_SLUG'")${NL}$(echo $(echo $PLUGIN_UPDATED) | json --group)" | json --group)
178
+ echo "Plugins list updated:"
179
+ echo $PLUGINS_LIST_UPDATED | json
180
+ cat $RUNNER_TEMP/plugins.json | json -e "this.plugins = $PLUGINS_LIST_UPDATED" | json > $RUNNER_TEMP/plugins_updated.json
181
+
182
+ - name: 🚀 Upload updated plugins list to AWS
183
+ run: |
184
+ BUCKET="${{ secrets.AWS_S3_BUCKET }}"
185
+ aws s3 cp $RUNNER_TEMP/plugins_updated.json s3://$BUCKET/plugins.json
@@ -0,0 +1,56 @@
1
+ name: 🧪 Test
2
+
3
+ on:
4
+ push:
5
+ branches: ["staging", "development"]
6
+ pull_request:
7
+ branches: ["main", "staging", "development"]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ test:
12
+ runs-on: ubuntu-latest
13
+
14
+ steps:
15
+ - name: 🚚 Get latest code
16
+ uses: actions/checkout@v3
17
+
18
+ - name: ⚙️ Setup PHP
19
+ uses: shivammathur/setup-php@v2
20
+ with:
21
+ php-version: "8.1"
22
+ ini-values: short_open_tag=1
23
+ env:
24
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
25
+
26
+ - name: ⚙️ Setup Node
27
+ uses: actions/setup-node@v3
28
+ with:
29
+ node-version: 16
30
+ cache: "npm"
31
+
32
+ - name: ⚙️ Get Composer cache directory
33
+ id: composer-cache
34
+ run: echo "::set-output name=dir::$(composer config cache-files-dir)"
35
+
36
+ - name: ⚙️ Cache Composer dependencies
37
+ uses: actions/cache@v3
38
+ with:
39
+ path: ${{ steps.composer-cache.outputs.dir }}
40
+ key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
41
+ restore-keys: ${{ runner.os }}-composer-
42
+
43
+ - name: 🔨 Increase composer timeout
44
+ run: composer --global config process-timeout 1500
45
+
46
+ - name: 🔨 Composer install
47
+ run: composer install --prefer-dist --no-ansi --no-interaction --no-progress --optimize-autoloader
48
+
49
+ - name: 🔨 npm install
50
+ run: npm ci
51
+
52
+ - name: 🔬 Test
53
+ run: npm test
54
+
55
+ - name: 📦 Build
56
+ run: npm run build --if-present
@@ -10,3 +10,6 @@ dist
10
10
  .composer-cache
11
11
  acf-json
12
12
  CHANGELOG.md
13
+ .github
14
+ vendor-scoped
15
+ wp-content
@@ -1,6 +1,7 @@
1
1
  # <%= name.title %> WordPress Plugin
2
2
 
3
- [![pipeline status](<%= repositoryBase %>/badges/main/pipeline.svg)](<%= repositoryBase %>/-/commits/main)
3
+ [![🧪 Test](<%= repositoryBase %>/actions/workflows/test-wordpress.yml/badge.svg)](<%= repositoryBase %>/actions/workflows/test-wordpress.yml)
4
+ [![📦 Release (Plugin)](<%= repositoryBase %>/actions/workflows/release-plugin.yml/badge.svg)](<%= repositoryBase %>/actions/workflows/release-plugin.yml)
4
5
 
5
6
  <%= answers.pluginDescription %>
6
7
 
@@ -0,0 +1,5 @@
1
+ {
2
+ "require": {
3
+ "airfleet/wordpress-framework": "^0.3.0"
4
+ }
5
+ }
@@ -0,0 +1,56 @@
1
+ {
2
+ "_readme": [
3
+ "This file locks the dependencies of your project to a known state",
4
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
+ "This file is @generated automatically"
6
+ ],
7
+ "content-hash": "73f083775f13a46ceb1fe9e556b8e1c5",
8
+ "packages": [
9
+ {
10
+ "name": "airfleet/wordpress-framework",
11
+ "version": "0.3.0",
12
+ "source": {
13
+ "type": "git",
14
+ "url": "https://github.com/airfleet/airfleet-wordpress-framework-php.git",
15
+ "reference": "063b33c80a313f046dd4eaba265b5cff173554a4"
16
+ },
17
+ "dist": {
18
+ "type": "zip",
19
+ "url": "https://api.github.com/repos/airfleet/airfleet-wordpress-framework-php/zipball/063b33c80a313f046dd4eaba265b5cff173554a4",
20
+ "reference": "063b33c80a313f046dd4eaba265b5cff173554a4",
21
+ "shasum": ""
22
+ },
23
+ "require": {
24
+ "php": ">=8.0"
25
+ },
26
+ "type": "library",
27
+ "autoload": {
28
+ "psr-4": {
29
+ "Airfleet\\Framework\\": "inc/"
30
+ }
31
+ },
32
+ "notification-url": "https://packagist.org/downloads/",
33
+ "authors": [
34
+ {
35
+ "name": "Airfleet",
36
+ "email": "dev@airfleet.co"
37
+ }
38
+ ],
39
+ "description": "Airfleet framework for WordPress",
40
+ "support": {
41
+ "issues": "https://github.com/airfleet/airfleet-wordpress-framework-php/issues",
42
+ "source": "https://github.com/airfleet/airfleet-wordpress-framework-php/tree/0.3.0"
43
+ },
44
+ "time": "2023-04-13T13:58:54+00:00"
45
+ }
46
+ ],
47
+ "packages-dev": [],
48
+ "aliases": [],
49
+ "minimum-stability": "stable",
50
+ "stability-flags": [],
51
+ "prefer-stable": false,
52
+ "prefer-lowest": false,
53
+ "platform": [],
54
+ "platform-dev": [],
55
+ "plugin-api-version": "2.3.0"
56
+ }
@@ -12,7 +12,8 @@
12
12
  "composer/installers": "^2.0"
13
13
  },
14
14
  "require-dev": {
15
- "airfleet/wordpress-dev": "^2.1.0"
15
+ "airfleet/wordpress-dev": "^2.1.0",
16
+ "wpify/scoper": "^2.5"
16
17
  },
17
18
  "autoload": {
18
19
  "psr-4": {
@@ -32,7 +33,19 @@
32
33
  "config": {
33
34
  "allow-plugins": {
34
35
  "composer/installers": true,
35
- "dealerdirect/phpcodesniffer-composer-installer": true
36
+ "dealerdirect/phpcodesniffer-composer-installer": true,
37
+ "wpify/scoper": true
38
+ }
39
+ },
40
+ "extra": {
41
+ "wpify-scoper": {
42
+ "prefix": "Airfleet\\Plugins\\<%= nameNoAirfleet.pascal %>\\Vendor",
43
+ "folder": "vendor-scoped",
44
+ "globals": [
45
+ "wordpress"
46
+ ],
47
+ "composerjson": "composer-scoped.json",
48
+ "composerlock": "composer-scoped.lock"
36
49
  }
37
50
  }
38
51
  }
@@ -9,3 +9,5 @@ dist
9
9
  .phpcscache
10
10
  .composer-cache
11
11
  .env
12
+ vendor-scoped
13
+ wp-content
@@ -0,0 +1,22 @@
1
+ <?php
2
+
3
+ namespace Airfleet\Plugins\<%= nameNoAirfleet.pascal %>;
4
+
5
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Assets\FrontendVariables;
6
+
7
+ class AjaxVariables extends FrontendVariables {
8
+ public function __construct() {
9
+ parent::__construct(
10
+ [
11
+ 'slug' => \<%= name.constant %>_SLUG,
12
+ 'name' => '_<%= name.camel %>',
13
+ 'variables' => function (): array {
14
+ return [
15
+ 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
16
+ 'ajaxNonce' => wp_create_nonce( '<%= name.camel %>Nonce' ),
17
+ ];
18
+ },
19
+ ]
20
+ );
21
+ }
22
+ }
@@ -0,0 +1,22 @@
1
+ <?php
2
+
3
+ namespace Airfleet\Plugins\<%= nameNoAirfleet.pascal %>;
4
+
5
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Assets\AdminVariables;
6
+
7
+ class AjaxVariablesAdmin extends AdminVariables {
8
+ public function __construct() {
9
+ parent::__construct(
10
+ [
11
+ 'slug' => \<%= name.constant %>_SLUG,
12
+ 'name' => '_<%= name.camel %>',
13
+ 'variables' => function (): array {
14
+ return [
15
+ 'ajaxUrl' => admin_url( 'admin-ajax.php' ),
16
+ 'ajaxNonce' => wp_create_nonce( '<%= name.camel %>Nonce' ),
17
+ ];
18
+ },
19
+ ]
20
+ );
21
+ }
22
+ }
@@ -0,0 +1,43 @@
1
+ <?php
2
+
3
+ namespace Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Options;
4
+
5
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Options\Group;
6
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Options\Wizard;
7
+
8
+ class GeneralOptions extends Group {
9
+ private const IS_ENABLED = 'is_enabled';
10
+
11
+ // phpcs:ignore NeutronStandard.Functions.LongFunction.LongFunction
12
+ public function __construct() {
13
+ parent::__construct(
14
+ '<%= name.snake %>_general_group',
15
+ '<%= name.snake %>_general',
16
+ Wizard::create_sections(
17
+ [
18
+ '<%= name.snake %>_general_settings' => [
19
+ 'title' => __( 'General Settings', 'airfleet' ),
20
+ 'description' => __( 'General settings for <%= name.title %>.', 'airfleet' ),
21
+ 'fields' => [
22
+ self::IS_ENABLED => [
23
+ 'type' => 'checkbox',
24
+ 'title' => __( '<%= name.title %> enabled?', 'airfleet' ),
25
+ 'label' => __( 'Enable <%= name.title %>', 'airfleet' ),
26
+ 'default' => false,
27
+ ],
28
+ ],
29
+ ],
30
+ ]
31
+ )
32
+ );
33
+ }
34
+
35
+ /**
36
+ * Check if the functionality is enabled.
37
+ *
38
+ * @return boolean
39
+ */
40
+ public function is_enabled(): bool {
41
+ return $this->value( self::IS_ENABLED );
42
+ }
43
+ }
@@ -0,0 +1,17 @@
1
+ <?php
2
+
3
+ namespace Airfleet\Plugins\<%= nameNoAirfleet.pascal %>;
4
+
5
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Options\GeneralOptions;
6
+
7
+ class Options {
8
+ protected GeneralOptions $general;
9
+
10
+ public function __construct() {
11
+ $this->general = new GeneralOptions( $this );
12
+ }
13
+
14
+ public function general(): GeneralOptions {
15
+ return $this->general;
16
+ }
17
+ }
@@ -0,0 +1,35 @@
1
+ <?php
2
+
3
+ namespace Airfleet\Plugins\<%= nameNoAirfleet.pascal %>;
4
+
5
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Features\BasePluginFeature;
6
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Options\Pages\MenuTabsPage;
7
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Options\Tabs\OptionsTab;
8
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Options;
9
+
10
+ class Pages extends BasePluginFeature {
11
+ protected MenuTabsPage $page;
12
+
13
+ public function __construct( Options $options ) {
14
+ $this->page = new MenuTabsPage(
15
+ [
16
+ 'slug' => \<%= name.constant %>_SLUG,
17
+ 'title' => \<%= name.constant %>_TITLE_SHORT,
18
+ 'class' => '<%= name.slug %>-page',
19
+ 'tabs' => [
20
+ new OptionsTab(
21
+ 'general',
22
+ __( 'General', 'airfleet' ),
23
+ $options->general(),
24
+ '<%= name.snake %>_general_page'
25
+ ),
26
+ ],
27
+ ],
28
+ 'airfleet'
29
+ );
30
+ }
31
+
32
+ public function initialize(): void {
33
+ $this->page->initialize();
34
+ }
35
+ }
@@ -2,72 +2,43 @@
2
2
 
3
3
  namespace Airfleet\Plugins\<%= nameNoAirfleet.pascal %>;
4
4
 
5
- class Setup {
5
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Assets\Enqueue;
6
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Features\PluginFeatures;
7
+ <%_ if (optionsPage === 'framework' ) { _%>
8
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Plugin\SettingsLink;
9
+ <%_ } _%>
10
+ <%_ if (optionsPage === 'acf' ) { _%>
11
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Plugin\AcfAirfleetOptionsSubPage;
12
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Plugin\AcfSettingsLink;
13
+ <%_ } _%>
14
+ <%_ if (answers.pluginAcfLocalJson) { _%>
15
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Acf\LocalJson;
16
+ <%_ } _%>
6
17
 
7
- /**
8
- * Setup the plugin.
9
- *
10
- * @return void
11
- */
12
- public function initialize(): void {
13
- $this->show_admin_notice_if_missing_framework();
14
- add_action(
15
- 'airfleet/init',
16
- function () {
17
- $this->plugin_basic_setup();
18
- }
19
- );
20
- }
21
-
22
- /**
23
- * Basic setup for the plugin. Enqueue assets and add options page
24
- *
25
- * @return void
26
- */
27
- public function plugin_basic_setup(): void {
28
- $plugin = new \Airfleet\Plugin(
29
- [
30
- 'slug' => '<%= name.slug %>',
31
- 'title' => '<%= name.title %>',
32
- 'short_title' => '<%= nameNoAirfleet.title %>',
33
- 'url' => \<%= name.constant %>_URL,
34
- 'path' => \<%= name.constant %>_PATH,
35
- 'version' => \<%= name.constant %>_VERSION,
36
- 'namespace' => 'Airfleet\\Plugins\\<%= nameNoAirfleet.pascal %>',
37
- ]
38
- );
39
- $plugin->setup_acf_json();
40
- $plugin->enqueue();
41
- $plugin->enqueue_critical();
42
- $plugin->enqueue_admin();
43
- $plugin->enqueue_editor();
44
- <%_ if (answers.pluginCreateOptions) { _%>
45
- $plugin->add_options_page();
18
+ class Setup extends PluginFeatures {
19
+ public function __construct( array $config ) {
20
+ <%_ if (optionsPage === 'framework' ) { _%>
21
+ $options = new Options();
46
22
  <%_ } _%>
47
- $plugin->register_views();
48
- }
49
-
50
- /**
51
- * Show and admin notification if the Airfleet Framework plugin is not enabled.
52
- *
53
- * @return void
54
- */
55
- public function show_admin_notice_if_missing_framework(): void {
56
- add_action(
57
- 'admin_notices',
58
- function () {
59
- global $airfleet_framework_missing_notice;
60
-
61
- if ( $airfleet_framework_missing_notice || defined( 'AIRFLEET_FRAMEWORK_VERSION' ) ) {
62
- return;
63
- }
64
- $airfleet_framework_missing_notice = true;
65
- ?>
66
- <div class="notice notice-error">
67
- <p>Please install the Airfleet Framework to enable the Airfleet plugins.</p>
68
- </div>
69
- <?php
70
- }
71
- );
23
+ $this->features = [
24
+ new Enqueue( $config ),
25
+ <%_ if (optionsPage === 'framework' ) { _%>
26
+ new Pages( $options ),
27
+ new SettingsLink( $config ),
28
+ <%_ } _%>
29
+ <%_ if (optionsPage === 'acf' ) { _%>
30
+ new AcfAirfleetOptionsSubPage( $config ),
31
+ new AcfSettingsLink( $config ),
32
+ <%_ } _%>
33
+ <%_ if (ajaxVariables.frontend) { _%>
34
+ new AjaxVariables(),
35
+ <%_ } _%>
36
+ <%_ if (ajaxVariables.admin) { _%>
37
+ new AjaxVariablesAdmin(),
38
+ <%_ } _%>
39
+ <%_ if (answers.pluginAcfLocalJson) { _%>
40
+ new LocalJson( $config['path'] . 'acf-json' ),
41
+ <%_ } _%>
42
+ ];
72
43
  }
73
44
  }
@@ -5,6 +5,7 @@
5
5
  "scripts": {
6
6
  "build": "dotenv -- parcel build --log-level verbose \"./!(dist)/**/*.entry.{js,scss}\"",
7
7
  "start": "dotenv -- parcel serve --hmr-port 1236 --port 1234 --log-level verbose \"./!(dist)/**/*.entry.{js,scss}\"",
8
+ "watch": "dotenv -- parcel watch --no-hmr --log-level verbose \"./!(dist)/**/*.entry.{js,scss}\"",
8
9
  "base:eslint": "eslint \"**/*.js\" --cache --ignore-path .gitignore",
9
10
  "base:prettier": "prettier \"**/*.{js,jsx,ts,tsx,json,css,scss,xml,yaml,yml,md}\"",
10
11
  "base:stylelint": "stylelint \"**/*.{css,scss}\" --cache --ignore-path .gitignore --allow-empty-input",
@@ -42,7 +43,7 @@
42
43
  },
43
44
  "dependencies": {},
44
45
  "devDependencies": {
45
- "@airfleet/wordpress-dev": "^1.1.0"
46
+ "@airfleet/wordpress-dev": "^1.1.1"
46
47
  },
47
48
  "browserslist": [
48
49
  "defaults",
@@ -14,6 +14,10 @@
14
14
  <!-- Set cache file -->
15
15
  <arg name="cache" value=".phpcscache" />
16
16
 
17
+ <!-- Ignore the vendor-scoped folder -->
18
+ <exclude-pattern>vendor-scoped/*</exclude-pattern>
19
+ <exclude-pattern><%= name.slug %>/wp-content/*</exclude-pattern>
20
+
17
21
  <!-- Check all files in this directory and the directories below it. -->
18
22
  <file>.</file>
19
23
 
@@ -16,7 +16,7 @@
16
16
  * Author: Airfleet
17
17
  * Author URI: https://www.airfleet.co/
18
18
  * Text Domain: <%= name.slug %>
19
- * GitLab Plugin URI: <%= repositoryBase %>
19
+ * GitHub Plugin URI: <%= repositoryBase %>
20
20
  * Primary Branch: <%= mainBranch %>
21
21
  * Release Asset: true
22
22
  */
@@ -28,14 +28,35 @@ if ( ! defined( 'ABSPATH' ) ) {
28
28
 
29
29
  // Plugin constants.
30
30
  define( '<%= name.constant %>_VERSION', '<%= answers.pluginVersion %>' );
31
+ define( '<%= name.constant %>_SLUG', '<%= name.slug %>' );
32
+ define( '<%= name.constant %>_SLUG_SHORT', '<%= nameNoAirfleet.slug %>' );
33
+ define( '<%= name.constant %>_TITLE', '<%= name.title %>' );
34
+ define( '<%= name.constant %>_TITLE_SHORT', '<%= nameNoAirfleet.title %>' );
31
35
  define( '<%= name.constant %>_PATH', plugin_dir_path( __FILE__ ) );
32
36
  define( '<%= name.constant %>_URL', plugin_dir_url( __FILE__ ) );
37
+ define( '<%= name.constant %>_FILE', __FILE__ );
38
+ define( '<%= name.constant %>_DIR', __DIR__ );
39
+ define( '<%= name.constant %>_IMAGES_OPTIONS_URL', <%= name.constant %>_URL . '/assets/admin/images/options' );
33
40
 
34
41
  // Autoload classes.
35
42
  require_once __DIR__ . '/vendor/autoload.php';
43
+ require_once __DIR__ . '/vendor-scoped/scoper-autoload.php';
36
44
 
37
45
  // Initialize plugin.
38
- $<%= name.snake %> = new \Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Setup();
46
+ $<%= name.snake %> = new \Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Setup(
47
+ [
48
+ 'slug' => \<%= name.constant %>_SLUG,
49
+ 'short_slug' => \<%= name.constant %>_SLUG_SHORT,
50
+ 'title' => \<%= name.constant %>_TITLE,
51
+ 'short_title' => \<%= name.constant %>_TITLE_SHORT,
52
+ 'url' => \<%= name.constant %>_URL,
53
+ 'path' => \<%= name.constant %>_PATH,
54
+ 'version' => \<%= name.constant %>_VERSION,
55
+ ]
56
+ );
57
+ register_activation_hook( __FILE__, [ $<%= name.snake %>, 'on_activation' ] );
58
+ register_deactivation_hook( __FILE__, [ $<%= name.snake %>, 'on_deactivation' ] );
59
+ register_uninstall_hook( __FILE__, [ '\Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Setup', 'uninstall' ] );
39
60
  $<%= name.snake %>->initialize();
40
61
 
41
62
  /**
@@ -0,0 +1,8 @@
1
+ <?php
2
+
3
+ // phpcs:ignore
4
+ function customize_php_scoper_config( array $config ): array {
5
+ $config['exclude-functions'] = [ 'af_field', '/acf\_*/' ];
6
+
7
+ return $config;
8
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@airfleet/generator-init",
3
3
  "description": "A Yeoman generator to scaffold common Airfleet features",
4
- "version": "0.15.2",
4
+ "version": "0.16.0",
5
5
  "scripts": {},
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -18,7 +18,7 @@
18
18
  },
19
19
  "repository": {
20
20
  "type": "git",
21
- "url": "https://gitlab.com/codersclan/tools/airfleet-generator.git"
21
+ "url": "https://github.com/airfleet/airfleet-generator-cli.git"
22
22
  },
23
23
  "type": "module",
24
24
  "exports": "./generators/app/index.js",
@@ -1,8 +0,0 @@
1
- stages:
2
- - release
3
-
4
- include:
5
- # Release process
6
- - project: 'codersclan/tools/gitlab-ci-templates'
7
- ref: main
8
- file: '/release/npm.yaml'
@@ -1,14 +0,0 @@
1
- stages:
2
- - test
3
- - release
4
- - upload
5
-
6
- include:
7
- # Test
8
- - project: "codersclan/tools/gitlab-ci-templates"
9
- ref: main
10
- file: "/test/wordpress.yaml"
11
- # Release process
12
- - project: "codersclan/tools/gitlab-ci-templates"
13
- ref: main
14
- file: "/release/wp-plugin.yaml"