@airfleet/generator-init 0.17.7 → 0.19.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.
- package/README.md +7 -6
- package/generators/plugin/index.js +31 -0
- package/generators/plugin/templates/inc/RegisterViews.php.ejs +37 -0
- package/generators/plugin/templates/inc/Setup.php.ejs +1 -0
- package/generators/view/index.js +126 -0
- package/generators/view/prompts.js +290 -0
- package/generators/view/templates/ViewController.php.ejs +9 -0
- package/generators/view/templates/ViewSetup.php.ejs +11 -0
- package/generators/view/templates/blocks/block-meta.json.ejs +6 -0
- package/generators/view/templates/blocks/blocks-group.json.ejs +24 -0
- package/generators/view/templates/blocks/blocks-template.blade.php.ejs +3 -0
- package/generators/view/templates/components/components-group.json.ejs +24 -0
- package/generators/view/templates/components/components-template.blade.php.ejs +3 -0
- package/generators/view/templates/custom-templates/custom-templates-group.json.ejs +24 -0
- package/generators/view/templates/custom-templates/custom-templates-template.blade.php.ejs +35 -0
- package/generators/view/templates/partials/partials-template.blade.php.ejs +3 -0
- package/generators/view/templates/script/import.js.ejs +1 -0
- package/generators/view/templates/script/view.js.ejs +21 -0
- package/generators/view/templates/setup/OverrideSetup.php.ejs +24 -0
- package/generators/view/templates/templates/templates-template.blade.php.ejs +33 -0
- package/generators/view/templates/view.scss.ejs +3 -0
- package/generators/view/templates.js +158 -0
- package/package.json +1 -1
- package/utils/copyTemplates.js +4 -1
- package/utils/objectPropertyFromValue.js +7 -0
- package/utils/objectToListArray.js +9 -0
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,6 +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 objectPropertyFromValue from '../../objectPropertyFromValue';
|
|
13
14
|
|
|
14
15
|
export default class extends Generator {
|
|
15
16
|
async prompting() {
|
|
@@ -33,6 +34,11 @@ export default class extends Generator {
|
|
|
33
34
|
])
|
|
34
35
|
);
|
|
35
36
|
|
|
37
|
+
const viewsPrefixOptions = {
|
|
38
|
+
none: "None",
|
|
39
|
+
elements: "Elements",
|
|
40
|
+
pluginSlug: "Use plugin short slug",
|
|
41
|
+
};
|
|
36
42
|
const prompts = [
|
|
37
43
|
{
|
|
38
44
|
type: "input",
|
|
@@ -80,6 +86,14 @@ export default class extends Generator {
|
|
|
80
86
|
validate: requiredText("Please enter the Node version"),
|
|
81
87
|
default: ">=16",
|
|
82
88
|
},
|
|
89
|
+
{
|
|
90
|
+
type: "list",
|
|
91
|
+
name: "viewsPrefix",
|
|
92
|
+
message:
|
|
93
|
+
"Views prefix?",
|
|
94
|
+
choices: [viewsPrefixOptions.none, viewsPrefixOptions.elements, viewsPrefixOptions.pluginSlug],
|
|
95
|
+
default: viewsPrefixOptions.elements,
|
|
96
|
+
},
|
|
83
97
|
{
|
|
84
98
|
type: "list",
|
|
85
99
|
name: "pluginCreateOptions",
|
|
@@ -114,6 +128,7 @@ export default class extends Generator {
|
|
|
114
128
|
.replace(/^airfleet/i, "")
|
|
115
129
|
.trim();
|
|
116
130
|
this.nameNoAirfleet = nameCases(nameNoAirfleet);
|
|
131
|
+
this.viewsPrefix = this._getViewsPrefix(this.answers, viewsPrefixOptions, this.nameNoAirfleet);
|
|
117
132
|
this.data = {
|
|
118
133
|
answers: this.answers,
|
|
119
134
|
name: this.name,
|
|
@@ -124,6 +139,7 @@ export default class extends Generator {
|
|
|
124
139
|
year: new Date().getFullYear(),
|
|
125
140
|
ajaxVariables: this.ajaxVariables,
|
|
126
141
|
optionsPage: this.optionsPage,
|
|
142
|
+
viewsPrefix: this.viewsPrefix,
|
|
127
143
|
};
|
|
128
144
|
}
|
|
129
145
|
|
|
@@ -145,6 +161,7 @@ export default class extends Generator {
|
|
|
145
161
|
"assets/frontend/scripts/index.entry.js",
|
|
146
162
|
"assets/frontend/styles/critical.entry.scss",
|
|
147
163
|
"assets/frontend/styles/index.entry.scss",
|
|
164
|
+
"inc/RegisterViews.php.ejs",
|
|
148
165
|
"inc/Setup.php.ejs",
|
|
149
166
|
"views/parcelkeep.entry.scss",
|
|
150
167
|
".airfleet-release",
|
|
@@ -218,4 +235,18 @@ export default class extends Generator {
|
|
|
218
235
|
install() {
|
|
219
236
|
this.spawnCommand("composer", ["install"]);
|
|
220
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
|
+
|
|
221
252
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
<?php
|
|
2
|
+
|
|
3
|
+
namespace Airfleet\Plugins\<%= nameNoAirfleet.pascal %>;
|
|
4
|
+
|
|
5
|
+
use Airfleet\Plugins\<%= nameNoAirfleet.pascal %>\Vendor\Airfleet\Framework\Features\BasePluginFeature;
|
|
6
|
+
|
|
7
|
+
class RegisterViews extends BasePluginFeature {
|
|
8
|
+
public function initialize(): void {
|
|
9
|
+
add_filter(
|
|
10
|
+
'airfleet/views/config',
|
|
11
|
+
function ( array $views ): array {
|
|
12
|
+
$views[] = [
|
|
13
|
+
'namespace' => 'Airfleet\\Plugins\\<%= nameNoAirfleet.pascal %>\\Views',
|
|
14
|
+
'path' => \<%= name.constant %>_PATH . DIRECTORY_SEPARATOR . 'views',
|
|
15
|
+
'version' => \<%= name.constant %>_VERSION,
|
|
16
|
+
'url' => \<%= name.constant %>_URL . '/views',
|
|
17
|
+
'source' => \<%= name.constant %>_SLUG,
|
|
18
|
+
'prefix' => '<%= viewsPrefix %>',
|
|
19
|
+
'priority' => 10,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
// Register dist folder for compiled assets
|
|
23
|
+
$views[] = [
|
|
24
|
+
'namespace' => 'Airfleet\\Plugins\\<%= nameNoAirfleet.pascal %>\\Views',
|
|
25
|
+
'path' => \<%= name.constant %>_PATH . DIRECTORY_SEPARATOR . 'dist' . DIRECTORY_SEPARATOR . 'views',
|
|
26
|
+
'version' => \<%= name.constant %>_VERSION,
|
|
27
|
+
'url' => \<%= name.constant %>_URL . '/dist/views',
|
|
28
|
+
'source' => \<%= name.constant %>_SLUG,
|
|
29
|
+
'prefix' => '<%= viewsPrefix %>',
|
|
30
|
+
'priority' => 10,
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
return $views;
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -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,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,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,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 @@
|
|
|
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,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
package/utils/copyTemplates.js
CHANGED