@airfleet/generator-init 0.18.0 → 0.20.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 (30) hide show
  1. package/README.md +7 -6
  2. package/generators/plugin/index.js +16 -2
  3. package/generators/plugin/templates/composer-scoped.json.ejs +1 -1
  4. package/generators/plugin/templates/composer-scoped.lock.ejs +7 -7
  5. package/generators/plugin/templates/inc/Pages.php.ejs +1 -1
  6. package/generators/plugin/templates/inc/Setup.php.ejs +2 -2
  7. package/generators/plugin/templates/package.json.ejs +1 -1
  8. package/generators/view/index.js +126 -0
  9. package/generators/view/prompts.js +290 -0
  10. package/generators/view/templates/ViewController.php.ejs +9 -0
  11. package/generators/view/templates/ViewSetup.php.ejs +11 -0
  12. package/generators/view/templates/blocks/block-meta.json.ejs +6 -0
  13. package/generators/view/templates/blocks/blocks-group.json.ejs +24 -0
  14. package/generators/view/templates/blocks/blocks-template.blade.php.ejs +3 -0
  15. package/generators/view/templates/components/components-group.json.ejs +24 -0
  16. package/generators/view/templates/components/components-template.blade.php.ejs +3 -0
  17. package/generators/view/templates/custom-templates/custom-templates-group.json.ejs +24 -0
  18. package/generators/view/templates/custom-templates/custom-templates-template.blade.php.ejs +35 -0
  19. package/generators/view/templates/partials/partials-template.blade.php.ejs +3 -0
  20. package/generators/view/templates/script/import.js.ejs +1 -0
  21. package/generators/view/templates/script/view.js.ejs +21 -0
  22. package/generators/view/templates/setup/OverrideSetup.php.ejs +24 -0
  23. package/generators/view/templates/templates/templates-template.blade.php.ejs +33 -0
  24. package/generators/view/templates/view.scss.ejs +3 -0
  25. package/generators/view/templates.js +158 -0
  26. package/package.json +1 -1
  27. package/utils/copyTemplates.js +4 -1
  28. package/utils/objectPropertyFromValue.js +7 -0
  29. package/utils/objectToListArray.js +9 -0
  30. package/utils/getViewsPrefix.js +0 -10
package/README.md CHANGED
@@ -18,12 +18,13 @@ npm install -g @airfleet/generator-init
18
18
 
19
19
  ## Generators
20
20
 
21
- | Generator | Command | Description |
22
- | --------- | ------------------------------------- | ----------------------------------------- |
23
- | Block | `yo @airfleet/init:block --force` | Create a block for the Airfleet Theme |
24
- | Component | `yo @airfleet/init:component --force` | Create a component for the Airfleet Theme |
25
- | npm | `yo @airfleet/init:npm` | Generate an npm package for publishing |
26
- | Plugin | `yo @airfleet/init:plugin` | Create a WP plugin |
21
+ | Generator | Command | Description |
22
+ | --------- | ------------------------------------- | ------------------------------------------- |
23
+ | Block | `yo @airfleet/init:block --force` | Create a block for the Airfleet Theme |
24
+ | Component | `yo @airfleet/init:component --force` | Create a component for the Airfleet Theme |
25
+ | npm | `yo @airfleet/init:npm` | Generate an npm package for publishing |
26
+ | Plugin | `yo @airfleet/init:plugin` | Create a WP plugin |
27
+ | View | `yo @airfleet/init:view` | Create a view for the Airfleet Views plugin |
27
28
 
28
29
  ## Documentation
29
30
 
@@ -10,7 +10,7 @@ import title from "../../utils/log/title.js";
10
10
  import highlightText from "../../utils/log/text/highlightText.js";
11
11
  import lines from "../../utils/log/text/lines.js";
12
12
  import infoBox from "../../utils/log/boxes/infoBox.js";
13
- import getViewsPrefix from "../../utils/getViewsPrefix.js";
13
+ import objectPropertyFromValue from '../../objectPropertyFromValue';
14
14
 
15
15
  export default class extends Generator {
16
16
  async prompting() {
@@ -128,7 +128,7 @@ export default class extends Generator {
128
128
  .replace(/^airfleet/i, "")
129
129
  .trim();
130
130
  this.nameNoAirfleet = nameCases(nameNoAirfleet);
131
- this.viewsPrefix = getViewsPrefix(this.answers, viewsPrefixOptions, this.nameNoAirfleet);
131
+ this.viewsPrefix = this._getViewsPrefix(this.answers, viewsPrefixOptions, this.nameNoAirfleet);
132
132
  this.data = {
133
133
  answers: this.answers,
134
134
  name: this.name,
@@ -235,4 +235,18 @@ export default class extends Generator {
235
235
  install() {
236
236
  this.spawnCommand("composer", ["install"]);
237
237
  }
238
+
239
+ _getViewsPrefix(answers, options, nameNoAirfleet) {
240
+ switch(answers.viewsPrefix) {
241
+ case options.none:
242
+ return '';
243
+ case options.pluginSlug:
244
+ return nameNoAirfleet.slug;
245
+ default:
246
+ const option = objectPropertyFromValue(options, answers.viewsPrefix);
247
+
248
+ return option || answers.viewsPrefix;
249
+ }
250
+ }
251
+
238
252
  }
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "require": {
3
- "airfleet/wordpress-framework": "^0.5.0"
3
+ "airfleet/wordpress-framework": "^1.0.0"
4
4
  }
5
5
  }
@@ -4,20 +4,20 @@
4
4
  "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
5
5
  "This file is @generated automatically"
6
6
  ],
7
- "content-hash": "559111f6923900cb21145144a501fa7e",
7
+ "content-hash": "cee694cc7b6248dede1cd8b177347244",
8
8
  "packages": [
9
9
  {
10
10
  "name": "airfleet/wordpress-framework",
11
- "version": "0.5.0",
11
+ "version": "1.0.0",
12
12
  "source": {
13
13
  "type": "git",
14
14
  "url": "https://github.com/airfleet/airfleet-wordpress-framework-php.git",
15
- "reference": "df7a4db928d6f17509f70dbb6ee72df76756f660"
15
+ "reference": "d9cb7a014209981d8c74696a26d942d0bc487ca6"
16
16
  },
17
17
  "dist": {
18
18
  "type": "zip",
19
- "url": "https://api.github.com/repos/airfleet/airfleet-wordpress-framework-php/zipball/df7a4db928d6f17509f70dbb6ee72df76756f660",
20
- "reference": "df7a4db928d6f17509f70dbb6ee72df76756f660",
19
+ "url": "https://api.github.com/repos/airfleet/airfleet-wordpress-framework-php/zipball/d9cb7a014209981d8c74696a26d942d0bc487ca6",
20
+ "reference": "d9cb7a014209981d8c74696a26d942d0bc487ca6",
21
21
  "shasum": ""
22
22
  },
23
23
  "require": {
@@ -40,9 +40,9 @@
40
40
  "description": "Airfleet framework for WordPress",
41
41
  "support": {
42
42
  "issues": "https://github.com/airfleet/airfleet-wordpress-framework-php/issues",
43
- "source": "https://github.com/airfleet/airfleet-wordpress-framework-php/tree/0.5.0"
43
+ "source": "https://github.com/airfleet/airfleet-wordpress-framework-php/tree/1.0.0"
44
44
  },
45
- "time": "2023-07-14T11:12:48+00:00"
45
+ "time": "2023-08-25T12:54:58+00:00"
46
46
  },
47
47
  {
48
48
  "name": "jawira/case-converter",
@@ -25,7 +25,7 @@ class Pages extends BasePluginFeature {
25
25
  ),
26
26
  ],
27
27
  ],
28
- 'airfleet'
28
+ 'settings'
29
29
  );
30
30
  }
31
31
 
@@ -8,7 +8,7 @@ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Feat
8
8
  use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Plugin\SettingsLink;
9
9
  <%_ } _%>
10
10
  <%_ if (optionsPage === 'acf' ) { _%>
11
- use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Plugin\AcfAirfleetOptionsSubPage;
11
+ use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Plugin\AcfSettingsOptionsSubPage;
12
12
  use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Plugin\AcfSettingsLink;
13
13
  <%_ } _%>
14
14
  <%_ if (answers.pluginAcfLocalJson) { _%>
@@ -29,7 +29,7 @@ class Setup extends PluginFeatures {
29
29
  new SettingsLink( $config ),
30
30
  <%_ } _%>
31
31
  <%_ if (optionsPage === 'acf' ) { _%>
32
- new AcfAirfleetOptionsSubPage( $config ),
32
+ new AcfSettingsOptionsSubPage( $config ),
33
33
  new AcfSettingsLink( $config ),
34
34
  <%_ } _%>
35
35
  <%_ if (ajaxVariables.frontend) { _%>
@@ -42,7 +42,7 @@
42
42
  },
43
43
  "dependencies": {},
44
44
  "devDependencies": {
45
- "@airfleet/wordpress-dev": "^2.2.3"
45
+ "@airfleet/wordpress-dev": "^2.2.4"
46
46
  },
47
47
  "browserslist": [
48
48
  "defaults",
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ import Generator from "yeoman-generator";
3
+
4
+ import nameCases from "../../utils/nameCases.js";
5
+ import copyTemplates from "../../utils/copyTemplates.js";
6
+ import title from "../../utils/log/title.js";
7
+ import highlightText from "../../utils/log/text/highlightText.js";
8
+ import dangerText from "../../utils/log/text/dangerText.js";
9
+ import lines from "../../utils/log/text/lines.js";
10
+ import infoBox from "../../utils/log/boxes/infoBox.js";
11
+ import Prompts from "./prompts.js";
12
+ import Templates from "./templates.js";
13
+ import acfData from "../../utils/acfData.js";
14
+
15
+ export default class extends Generator {
16
+ constructor(args, opts) {
17
+ super(args, opts);
18
+ this.prompts = new Prompts(this);
19
+ this.templates = new Templates(this);
20
+ }
21
+
22
+ async prompting() {
23
+ this.log(
24
+ lines([
25
+ title(`Let's generate an ${highlightText("Airfleet View")}!`),
26
+ infoBox(lines(["This will bootstrap the files for a view."])),
27
+ "",
28
+ ])
29
+ );
30
+
31
+ this.answers = await this.prompts.prompt();
32
+ this.name = nameCases(this.answers.viewName);
33
+ this.pluginName = nameCases(
34
+ (this.answers.pluginName || "").replace(/^airfleet/i, "").trim()
35
+ );
36
+ this.viewsPrefix = this._viewsPrefix();
37
+ this.viewType = nameCases(this.answers.viewType);
38
+ this.viewSlug = (
39
+ this.viewsPrefix
40
+ ? [this.viewsPrefix, this.viewType.slug, this.name.slug]
41
+ : [this.viewType.slug, this.name.slug]
42
+ ).join("-");
43
+ this.viewFolder = `${this.answers.viewsFolder}/${this.viewType.slug}/${this.name.slug}`;
44
+ this.cssClassPrefix = this._cssClassPrefix(this.viewType.slug);
45
+ this.cssClass = `${this.cssClassPrefix}-${this.name.slug}`;
46
+ this.namespace = this._phpNamespace();
47
+ this.acf = acfData();
48
+ this.data = {
49
+ answers: this.answers,
50
+ name: this.name,
51
+ viewType: this.viewType,
52
+ viewFolder: this.viewFolder,
53
+ cssClass: this.cssClass,
54
+ cssClassPrefix: this.cssClassPrefix,
55
+ namespace: this.namespace,
56
+ pluginName: this.pluginName,
57
+ viewSlug: this.viewSlug,
58
+ acf: this.acf,
59
+ blockDescription: this.answers.blockDescription,
60
+ blockKeywords: (this.answers.blockKeywords || '')
61
+ .replaceAll('"', "")
62
+ .split(",")
63
+ .map((k) => k.trim()),
64
+ };
65
+ }
66
+
67
+ _viewsPrefix() {
68
+ if (this.answers.viewsPrefix === "other") {
69
+ return nameCases(this.answers.viewsPrefixOther).slug;
70
+ }
71
+
72
+ if (this.answers.viewsPrefix === "theme") {
73
+ return '';
74
+ }
75
+
76
+ return this.answers.viewsPrefix;
77
+ }
78
+
79
+ _phpNamespace() {
80
+ switch (this.answers.source) {
81
+ case "starter-theme":
82
+ return "App";
83
+ case "lightyear-theme":
84
+ return "Airfleet\\Themes\\Lightyear";
85
+ default:
86
+ return `Airfleet\\Plugins\\` + this.pluginName.pascal;
87
+ }
88
+ }
89
+
90
+ _cssClassPrefix(viewType) {
91
+ switch (viewType) {
92
+ case "partials":
93
+ return "afp";
94
+ case "components":
95
+ return "afc";
96
+ case "blocks":
97
+ return "afb";
98
+ case "custom-templates":
99
+ return "aft";
100
+ case "templates":
101
+ return "aft";
102
+ }
103
+ }
104
+
105
+ writing() {
106
+ copyTemplates(this, this.templates.templates(), this.data);
107
+ }
108
+
109
+ end() {
110
+ if (this.answers.createController) {
111
+ this.log(
112
+ lines([
113
+ "",
114
+ infoBox(
115
+ lines([
116
+ "If you are extending a controller instead of",
117
+ `overriding, ${dangerText(
118
+ "review the controller's parent class"
119
+ )}.`,
120
+ ])
121
+ ),
122
+ ])
123
+ );
124
+ }
125
+ }
126
+ }
@@ -0,0 +1,290 @@
1
+ "use strict";
2
+
3
+ import requiredText from "../../utils/validation/requiredText.js";
4
+ import highlightText from "../../utils/log/text/highlightText.js";
5
+
6
+ export default class {
7
+ constructor(generator) {
8
+ this.generator = generator;
9
+ this.answers = {};
10
+ }
11
+
12
+ async prompt() {
13
+ await this._promptNext([this._sourcePrompt()]);
14
+
15
+ if (this.answers.source === "plugin") {
16
+ await this._promptNext([this._pluginNamePrompt()]);
17
+ }
18
+ await this._promptNext([
19
+ this._viewsFolderPrompt(),
20
+ this._viewsPrefixPrompt(),
21
+ ]);
22
+
23
+ if (this.answers.viewsPrefix === "other") {
24
+ await this._promptNext([this._viewsPrefixOtherPrompt()]);
25
+ }
26
+ await this._promptNext([
27
+ this._viewTypePrompt(),
28
+ this._viewNamePrompt(),
29
+ ]);
30
+
31
+ if (this.answers.viewType === "blocks") {
32
+ await this._promptNext([...this._blockPrompts()]);
33
+ }
34
+
35
+ if (this.answers.viewType !== "partials" && this.answers.viewType !== "templates") {
36
+ await this._promptNext([this._createCustomFields()]);
37
+ }
38
+ await this._promptNext([
39
+ this._createTemplatePrompt(),
40
+ this._createControllerPrompt(),
41
+ this._createSetupPrompt(),
42
+ this._stylesPrompt(),
43
+ this._scriptsPrompt(),
44
+ ]);
45
+
46
+ if (this.answers.styles.length > 0 || this.answers.scripts.length > 0) {
47
+ await this._promptNext([
48
+ this._overrideResourcesPrompt(),
49
+ ]);
50
+ }
51
+
52
+ return this.answers;
53
+ }
54
+
55
+ async _promptNext(questions) {
56
+ this.answers = {
57
+ ...(this.answers || {}),
58
+ ...(await this.generator.prompt(questions)),
59
+ };
60
+ }
61
+
62
+ _sourcePrompt() {
63
+ return {
64
+ type: "list",
65
+ name: "source",
66
+ message: "Where are you creating the view?",
67
+ choices: [
68
+ {
69
+ name: "Starter Theme",
70
+ value: "starter-theme",
71
+ },
72
+ {
73
+ name: "Lightyear Theme",
74
+ value: "lightyear-theme",
75
+ },
76
+ {
77
+ name: "Plugin",
78
+ value: "plugin",
79
+ },
80
+ ],
81
+ default: "starter-theme",
82
+ store: true,
83
+ };
84
+ }
85
+
86
+ _pluginNamePrompt() {
87
+ return {
88
+ type: "input",
89
+ name: "pluginName",
90
+ message: `Plugin name? (e.g. "Analytics")`,
91
+ validate: requiredText("Please enter the plugin name"),
92
+ store: true,
93
+ };
94
+ }
95
+
96
+ _viewsPrefixPrompt() {
97
+ return {
98
+ type: "list",
99
+ name: "viewsPrefix",
100
+ message: `Views prefix?`,
101
+ choices: [
102
+ "theme",
103
+ "elements",
104
+ "other",
105
+ ],
106
+ default: "theme",
107
+ store: true,
108
+ };
109
+ }
110
+
111
+ _viewsPrefixOtherPrompt() {
112
+ return {
113
+ type: "input",
114
+ name: "viewsPrefixOther",
115
+ message: `Views prefix?`,
116
+ store: false,
117
+ };
118
+ }
119
+
120
+ _viewsFolderPrompt() {
121
+ return {
122
+ type: "input",
123
+ name: "viewsFolder",
124
+ message: "Views folder?",
125
+ validate: requiredText("Please enter the views folder"),
126
+ default: "views",
127
+ store: true,
128
+ };
129
+ }
130
+
131
+ _viewTypePrompt() {
132
+ return {
133
+ type: "list",
134
+ name: "viewType",
135
+ message: "View type?",
136
+ choices: [
137
+ {
138
+ name: "Partial",
139
+ value: "partials",
140
+ },
141
+ {
142
+ name: "Component",
143
+ value: "components",
144
+ },
145
+ {
146
+ name: "Block",
147
+ value: "blocks",
148
+ },
149
+ {
150
+ name: "Custom Page Template",
151
+ value: "custom-templates",
152
+ },
153
+ {
154
+ name: "WP Hierarchy Template",
155
+ value: "templates",
156
+ },
157
+ ],
158
+ default: "components",
159
+ store: true,
160
+ };
161
+ }
162
+
163
+ _blockPrompts() {
164
+ return [
165
+ {
166
+ type: "input",
167
+ name: "blockDescription",
168
+ message: "Block description?",
169
+ store: false,
170
+ },
171
+ {
172
+ type: "input",
173
+ name: "blockKeywords",
174
+ message: `Block keywords? (${highlightText('separate with commas')}, e.g. "airfleet, hero")`,
175
+ store: false,
176
+ }
177
+ ];
178
+ }
179
+
180
+ _viewNamePrompt() {
181
+ return {
182
+ type: "input",
183
+ name: "viewName",
184
+ message: "View name? (e.g. button, hero)",
185
+ validate: requiredText("Please enter a name for the view"),
186
+ store: false,
187
+ };
188
+ }
189
+
190
+ _createTemplatePrompt() {
191
+ return {
192
+ type: "confirm",
193
+ name: "createTemplate",
194
+ message: "Create template file?",
195
+ default: true,
196
+ };
197
+ }
198
+
199
+ _createControllerPrompt() {
200
+ return {
201
+ type: "confirm",
202
+ name: "createController",
203
+ message: "Create controller file?",
204
+ default: false,
205
+ };
206
+ }
207
+
208
+ _createSetupPrompt() {
209
+ return {
210
+ type: "confirm",
211
+ name: "createSetup",
212
+ message: "Create setup file?",
213
+ default: false,
214
+ };
215
+ }
216
+
217
+ _createCustomFields() {
218
+ return {
219
+ type: "confirm",
220
+ name: "createCustomFields",
221
+ message: "Create custom fields group?",
222
+ default: true,
223
+ };
224
+ }
225
+
226
+ _stylesPrompt() {
227
+ return {
228
+ type: "checkbox",
229
+ name: "styles",
230
+ message: "Which styles to create?",
231
+ choices: [
232
+ {
233
+ name: "Frontend",
234
+ value: "frontend",
235
+ checked: true,
236
+ },
237
+ {
238
+ name: "Critical",
239
+ value: "critical",
240
+ },
241
+ {
242
+ name: "Editor",
243
+ value: "editor",
244
+ },
245
+ {
246
+ name: "Admin",
247
+ value: "admin",
248
+ },
249
+ ],
250
+ store: true,
251
+ };
252
+ }
253
+
254
+ _scriptsPrompt() {
255
+ return {
256
+ type: "checkbox",
257
+ name: "scripts",
258
+ message: "Which scripts to create?",
259
+ choices: [
260
+ {
261
+ name: "Frontend",
262
+ value: "frontend",
263
+ checked: true,
264
+ },
265
+ {
266
+ name: "Critical",
267
+ value: "critical",
268
+ },
269
+ {
270
+ name: "Editor",
271
+ value: "editor",
272
+ },
273
+ {
274
+ name: "Admin",
275
+ value: "admin",
276
+ },
277
+ ],
278
+ store: true,
279
+ };
280
+ }
281
+
282
+ _overrideResourcesPrompt() {
283
+ return {
284
+ type: "confirm",
285
+ name: "overrideResources",
286
+ message: `Override parent styles/scripts?`,
287
+ default: false,
288
+ };
289
+ }
290
+ }
@@ -0,0 +1,9 @@
1
+ <?php
2
+
3
+ namespace <%= namespace %>\Views\<%= viewType.pascal %>\<%= name.pascal %>;
4
+
5
+ use Airfleet\Plugins\Views\View\ViewController;
6
+
7
+ class <%= name.pascal %>Controller extends ViewController {
8
+ // TODO
9
+ }
@@ -0,0 +1,11 @@
1
+ <?php
2
+
3
+ namespace <%= namespace %>\Views\<%= viewType.pascal %>\<%= name.pascal %>;
4
+
5
+ use Airfleet\Plugins\Views\View\ViewSetup;
6
+
7
+ class <%= name.pascal %>Setup extends ViewSetup {
8
+ public function initialize(): void {
9
+ // TODO
10
+ }
11
+ }
@@ -0,0 +1,6 @@
1
+ {
2
+ "name": "airfleet/<%= viewSlug %>",
3
+ "title": "<%= name.title %>",
4
+ "description": "<%= blockDescription %>",
5
+ "keywords": [<%- blockKeywords.map(k => `"${k}"`).join(", ") %>]
6
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "key": "<%= acf.key %>",
3
+ "title": "Block: <%= name.title %>",
4
+ "fields": [],
5
+ "location": [
6
+ [
7
+ {
8
+ "param": "block",
9
+ "operator": "==",
10
+ "value": "airfleet/<%= viewSlug %>"
11
+ }
12
+ ]
13
+ ],
14
+ "menu_order": 0,
15
+ "position": "normal",
16
+ "style": "default",
17
+ "label_placement": "top",
18
+ "instruction_placement": "label",
19
+ "hide_on_screen": "",
20
+ "active": true,
21
+ "description": "",
22
+ "show_in_rest": 0,
23
+ "modified": <%= acf.timestamp %>
24
+ }
@@ -0,0 +1,3 @@
1
+ <section class="<%= cssClass %> {{ $class }}">
2
+
3
+ </section>
@@ -0,0 +1,24 @@
1
+ {
2
+ "key": "<%= acf.key %>",
3
+ "title": "Component: <%= name.title %>",
4
+ "fields": [],
5
+ "location": [
6
+ [
7
+ {
8
+ "param": "airfleet_component",
9
+ "operator": "==",
10
+ "value": "<%= viewSlug %>"
11
+ }
12
+ ]
13
+ ],
14
+ "menu_order": 0,
15
+ "position": "normal",
16
+ "style": "default",
17
+ "label_placement": "top",
18
+ "instruction_placement": "label",
19
+ "hide_on_screen": "",
20
+ "active": true,
21
+ "description": "",
22
+ "show_in_rest": 0,
23
+ "modified": <%= acf.timestamp %>
24
+ }
@@ -0,0 +1,3 @@
1
+ <div class="<%= cssClass %> {{ $class }}">
2
+
3
+ </div>
@@ -0,0 +1,24 @@
1
+ {
2
+ "key": "<%= acf.key %>",
3
+ "title": "Template: <%= name.title %>",
4
+ "fields": [],
5
+ "location": [
6
+ [
7
+ {
8
+ "param": "page_template",
9
+ "operator": "==",
10
+ "value": "<%= viewSlug %>"
11
+ }
12
+ ]
13
+ ],
14
+ "menu_order": 0,
15
+ "position": "normal",
16
+ "style": "default",
17
+ "label_placement": "top",
18
+ "instruction_placement": "label",
19
+ "hide_on_screen": "",
20
+ "active": true,
21
+ "description": "",
22
+ "show_in_rest": 0,
23
+ "modified": <%= acf.timestamp %>
24
+ }
@@ -0,0 +1,35 @@
1
+ {{--
2
+ Template Name: <%= name.title %>
3
+ --}}
4
+
5
+ @view('partials-header')
6
+
7
+ @while( have_posts() )
8
+ @php the_post() @endphp
9
+ <article @php post_class( '<%= cssClass %>' ) @endphp>
10
+ <header class="<%= cssClass %>__head">
11
+ @if( has_post_thumbnail() )
12
+ <div class="<%= cssClass %>__thumbnail">
13
+ @php the_post_thumbnail() @endphp
14
+ </div>
15
+ @endif
16
+ <h1 class="<%= cssClass %>__title">
17
+ @php the_title() @endphp
18
+ </h1>
19
+ <div class="<%= cssClass %>__meta">
20
+ <p class="<%= cssClass %>__categories">
21
+ @php the_category() @endphp
22
+ </p>
23
+ <p>
24
+ @php the_time( 'F jS, Y ' ) @endphp
25
+ @php the_author() @endphp
26
+ </p>
27
+ </div>
28
+ </header>
29
+ <div class="<%= cssClass %>__body">
30
+ @php the_content() @endphp
31
+ </div>
32
+ </article>
33
+ @endwhile
34
+
35
+ @view('partials-footer')
@@ -0,0 +1,3 @@
1
+ <div class="<%= cssClass %> {{ $class }}">
2
+
3
+ </div>
@@ -0,0 +1 @@
1
+ import './<%= stylesheet %>';
@@ -0,0 +1,21 @@
1
+ <%_ if (importStyles) { _%>
2
+ import './<%= stylesheet %>';
3
+
4
+ <% } _%>
5
+ export class <%= name.pascal %> {
6
+ initialize() {
7
+ this.onReady(() => {
8
+ // TODO
9
+ });
10
+ }
11
+
12
+ onReady(callBack) {
13
+ if (document.readyState === 'loading') {
14
+ document.addEventListener('DOMContentLoaded', callBack);
15
+ } else {
16
+ callBack();
17
+ }
18
+ };
19
+ }
20
+
21
+ new <%= name.pascal %>().initialize();
@@ -0,0 +1,24 @@
1
+ <?php
2
+
3
+ namespace <%= namespace %>\Views\<%= viewType.pascal %>\<%= name.pascal %>;
4
+
5
+ use Airfleet\Plugins\Views\View\ViewSetup;
6
+
7
+ class <%= name.pascal %>Setup extends ViewSetup {
8
+ public function initialize(): void {
9
+ $this->override_resources();
10
+ }
11
+
12
+ protected function override_resources(): void {
13
+ <%_ ["styles", "scripts"].forEach(type => { _%>
14
+ <%_ resources[type].forEach(screen => { _%>
15
+ add_filter(
16
+ 'airfleet/views/enqueue/override/<%= viewSlug %>/<%= screen %>/<%= type %>',
17
+ function (): bool {
18
+ return true;
19
+ }
20
+ );
21
+ <%_ }); _%>
22
+ <%_ }); _%>
23
+ }
24
+ }
@@ -0,0 +1,33 @@
1
+ @view('partials-header')
2
+
3
+ @while( have_posts() )
4
+ @php the_post() @endphp
5
+ <article @php post_class( '<%= cssClass %>' ) @endphp>
6
+ <header class="<%= cssClass %>__head">
7
+ @if( has_post_thumbnail() )
8
+ <div class="<%= cssClass %>__thumbnail">
9
+ @php the_post_thumbnail() @endphp
10
+ </div>
11
+ @endif
12
+ <h2 class="<%= cssClass %>__title">
13
+ <a href="@php the_permalink() @endphp">
14
+ @php the_title() @endphp
15
+ </a>
16
+ </h2>
17
+ <div class="<%= cssClass %>__meta">
18
+ <p class="<%= cssClass %>__categories">
19
+ @php the_category() @endphp
20
+ </p>
21
+ <p>
22
+ @php the_time( 'F jS, Y ' ) @endphp
23
+ @php the_author() @endphp
24
+ </p>
25
+ </div>
26
+ </header>
27
+ <div class="<%= cssClass %>__body">
28
+ @php the_excerpt() @endphp
29
+ </div>
30
+ </article>
31
+ @endwhile
32
+
33
+ @view('partials-footer')
@@ -0,0 +1,3 @@
1
+ .<%= cssClass %> {
2
+ // TODO
3
+ }
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+
3
+ export default class {
4
+ constructor(generator) {
5
+ this.generator = generator;
6
+ }
7
+
8
+ templates() {
9
+ return [
10
+ this._templateTemplate(),
11
+ this._controllerTemplate(),
12
+ this._setupTemplate(),
13
+ this._acfTemplate(),
14
+ this._blockMetaTemplate(),
15
+ ...this._stylesTemplates(),
16
+ ...this._scriptsTemplates(),
17
+ ];
18
+ }
19
+
20
+ _templateTemplate() {
21
+ return {
22
+ template: `${this.generator.viewType.slug}/${this.generator.viewType.slug}-template.blade.php.ejs`,
23
+ destination: `${this.generator.viewFolder}/${this.generator.name.slug}.blade.php`,
24
+ isEnabled: this.generator.answers.createTemplate,
25
+ };
26
+ }
27
+
28
+ _acfTemplate() {
29
+ return {
30
+ template: `${this.generator.viewType.slug}/${this.generator.viewType.slug}-group.json.ejs`,
31
+ destination: `${this.generator.viewFolder}/${this.generator.acf.key}.json`,
32
+ isEnabled: this.generator.answers.createCustomFields,
33
+ };
34
+ }
35
+
36
+ _blockMetaTemplate() {
37
+ return {
38
+ template: `blocks/block-meta.json.ejs`,
39
+ destination: `${this.generator.viewFolder}/${this.generator.name.slug}.block.json`,
40
+ isEnabled: this.generator.viewType.slug === "blocks",
41
+ };
42
+ }
43
+
44
+ _controllerTemplate() {
45
+ return {
46
+ template: `ViewController.php.ejs`,
47
+ destination: `${this.generator.viewFolder}/${this.generator.name.pascal}Controller.php`,
48
+ isEnabled: this.generator.answers.createController,
49
+ };
50
+ }
51
+
52
+ _setupTemplate() {
53
+ return {
54
+ template: this.generator.answers.overrideResources ? 'setup/OverrideSetup.php.ejs' : `ViewSetup.php.ejs`,
55
+ destination: `${this.generator.viewFolder}/${this.generator.name.pascal}Setup.php`,
56
+ isEnabled: this.generator.answers.createSetup || this.generator.answers.overrideResources,
57
+ data: {
58
+ resources: this._resources(),
59
+ },
60
+ };
61
+ }
62
+
63
+ _stylesTemplates() {
64
+ const extension = this.generator.answers.source === "starter-theme" ? "scss" : "entry.scss";
65
+
66
+ return [
67
+ {
68
+ template: `view.scss.ejs`,
69
+ destination: `${this.generator.viewFolder}/${this.generator.name.slug}.${extension}`,
70
+ isEnabled: this._styleEnabled("frontend"),
71
+ },
72
+ {
73
+ template: `view.scss.ejs`,
74
+ destination: `${this.generator.viewFolder}/${this.generator.name.slug}.critical.${extension}`,
75
+ isEnabled: this._styleEnabled("critical"),
76
+ },
77
+ {
78
+ template: `view.scss.ejs`,
79
+ destination: `${this.generator.viewFolder}/${this.generator.name.slug}.editor.${extension}`,
80
+ isEnabled: this._styleEnabled("editor"),
81
+ },
82
+ {
83
+ template: `view.scss.ejs`,
84
+ destination: `${this.generator.viewFolder}/${this.generator.name.slug}.admin.${extension}`,
85
+ isEnabled: this._styleEnabled("admin"),
86
+ },
87
+ ];
88
+ }
89
+
90
+ _scriptsTemplates() {
91
+ const screens = ["frontend", "critical", "editor", "admin"];
92
+
93
+ return screens.map((screen) => {
94
+ const suffix = screen === "frontend" ? "" : `.${screen}`;
95
+ const extension = this.generator.answers.source === "starter-theme" ? "js" : "entry.js";
96
+
97
+ return {
98
+ template: this._scriptTemplate(screen),
99
+ destination: `${this.generator.viewFolder}/${this.generator.name.slug}${suffix}.${extension}`,
100
+ isEnabled: this._scriptEnabled(screen),
101
+ data: {
102
+ importStyles: this._shouldImportStylesForScript(screen),
103
+ stylesheet: `${this.generator.name.slug}${suffix}.scss`,
104
+ },
105
+ };
106
+ });
107
+ }
108
+
109
+ _resources() {
110
+ const screens = ["frontend", "critical", "editor", "admin"];
111
+ const result = {
112
+ styles: [],
113
+ scripts: [],
114
+ };
115
+
116
+ screens.forEach(screen => {
117
+ if (this._styleEnabled(screen)) {
118
+ result.styles.push(screen);
119
+ }
120
+
121
+ if (this._scriptEnabled(screen)) {
122
+ result.scripts.push(screen);
123
+ }
124
+ });
125
+
126
+ return result;
127
+ }
128
+
129
+ _styleEnabled(style) {
130
+ return this.generator.answers.styles.includes(style);
131
+ }
132
+
133
+ _scriptEnabled(script) {
134
+ return (
135
+ this.generator.answers.scripts.includes(script) ||
136
+ this._shouldImportStylesForScript(script)
137
+ );
138
+ }
139
+
140
+ _scriptTemplate(script) {
141
+ if (this.generator.answers.scripts.includes(script)) {
142
+ return "script/view.js.ejs";
143
+ }
144
+
145
+ if (this._shouldImportStylesForScript(script)) {
146
+ return "script/import.js.ejs";
147
+ }
148
+
149
+ return "";
150
+ }
151
+
152
+ _shouldImportStylesForScript(script) {
153
+ return (
154
+ this.generator.answers.source === "starter-theme" &&
155
+ this._styleEnabled(script)
156
+ );
157
+ }
158
+ }
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.18.0",
4
+ "version": "0.20.0",
5
5
  "scripts": {},
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -20,7 +20,10 @@ export default function copyTemplates(context, templates, data) {
20
20
  context.fs.copyTpl(
21
21
  context.templatePath(file.template),
22
22
  context.destinationPath(file.destination),
23
- data
23
+ {
24
+ ...data,
25
+ ...(file.data || {}),
26
+ }
24
27
  );
25
28
  }
26
29
  });
@@ -0,0 +1,7 @@
1
+ export default function objectPropertyFromValue(options, value) {
2
+ for (const property in options) {
3
+ if (options[property] === value) {
4
+ return property;
5
+ }
6
+ }
7
+ }
@@ -0,0 +1,9 @@
1
+ export default function objectToListArray(options) {
2
+ const result = [];
3
+
4
+ for (const property in options) {
5
+ result.push(options[property]);
6
+ }
7
+
8
+ return result;
9
+ }
@@ -1,10 +0,0 @@
1
- export default function getViewsPrefix(answers, options, nameNoAirfleet) {
2
- switch(answers.viewsPrefix) {
3
- case options.none:
4
- return '';
5
- case options.pluginSlug:
6
- return nameNoAirfleet.slug;
7
- default:
8
- return (options[answers.viewsPrefix] || answers.viewsPrefix).toLowerCase();
9
- }
10
- }