@airfleet/generator-init 0.1.0 → 0.4.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 (33) hide show
  1. package/README.md +9 -0
  2. package/generators/app/index.js +5 -0
  3. package/generators/block/index.js +184 -0
  4. package/generators/block/templates/acf/barebones.json.ejs +23 -0
  5. package/generators/block/templates/acf/building-block.json.ejs +348 -0
  6. package/generators/block/templates/acf/building-repeater-block.json.ejs +547 -0
  7. package/generators/block/templates/barebones.blade.php.ejs +8 -0
  8. package/generators/block/templates/building-block.blade.php.ejs +20 -0
  9. package/generators/block/templates/building-repeater-block.blade.php.ejs +52 -0
  10. package/generators/block/templates/composer.php.ejs +16 -0
  11. package/generators/block/templates/scripts/block.js.ejs +9 -0
  12. package/generators/block/templates/styles/_block.scss.ejs +3 -0
  13. package/generators/block/templates/styles/index.scss.ejs +1 -0
  14. package/generators/component/index.js +14 -14
  15. package/generators/component/templates/component.blade.php.ejs +2 -2
  16. package/generators/component/templates/{controller.php.ejs → composer.php.ejs} +0 -0
  17. package/generators/component/templates/scripts/component.js.ejs +1 -1
  18. package/generators/component/templates/styles/_component.scss.ejs +1 -1
  19. package/generators/npm/index.js +110 -0
  20. package/generators/npm/templates/.airfleet-release +1 -0
  21. package/generators/npm/templates/.editorconfig +18 -0
  22. package/generators/npm/templates/.gitattributes +11 -0
  23. package/generators/npm/templates/.gitlab-ci.yml +8 -0
  24. package/generators/npm/templates/CHANGELOG.md +10 -0
  25. package/generators/npm/templates/LICENSE.ejs +2 -0
  26. package/generators/npm/templates/README.md.ejs +20 -0
  27. package/generators/npm/templates/package.json.ejs +27 -0
  28. package/package.json +3 -7
  29. package/utils/acfData.js +5 -2
  30. package/utils/log/boxes/infoBox.js +9 -0
  31. package/utils/log/themeFeature.js +0 -2
  32. package/utils/mapFilesToTemplates.js +13 -0
  33. package/utils/nameCases.js +4 -1
@@ -16,34 +16,34 @@ export default class extends Generator {
16
16
  const prompts = [
17
17
  {
18
18
  type: "input",
19
- name: "name",
19
+ name: "componentName",
20
20
  message: "What is the name of the component?",
21
21
  validate: requiredText("Please enter a name"),
22
22
  },
23
23
  {
24
24
  type: "confirm",
25
- name: "createComposer",
25
+ name: "createComponentComposer",
26
26
  message: "Create composer (controller)?",
27
27
  default: true,
28
28
  store: true,
29
29
  },
30
30
  {
31
31
  type: "confirm",
32
- name: "createStyles",
32
+ name: "createComponentStyles",
33
33
  message: "Create SCSS stylesheet?",
34
34
  default: true,
35
35
  store: true,
36
36
  },
37
37
  {
38
38
  type: "confirm",
39
- name: "createScript",
39
+ name: "createComponentScript",
40
40
  message: "Create JavaScript file?",
41
41
  default: false,
42
42
  store: true,
43
43
  },
44
44
  {
45
45
  type: "confirm",
46
- name: "createAcf",
46
+ name: "createComponentAcf",
47
47
  message: "Create custom fields?",
48
48
  default: false,
49
49
  store: true,
@@ -51,8 +51,8 @@ export default class extends Generator {
51
51
  ];
52
52
 
53
53
  this.answers = await this.prompt(prompts);
54
- this.name = nameCases(this.answers.name);
55
- this.acf = acfData({ prefix: "group_" }),
54
+ this.name = nameCases(this.answers.componentName);
55
+ this.acf = acfData();
56
56
  this.data = {
57
57
  answers: this.answers,
58
58
  name: this.name,
@@ -68,38 +68,38 @@ export default class extends Generator {
68
68
  isEnabled: true,
69
69
  },
70
70
  {
71
- template: "controller.php.ejs",
71
+ template: "composer.php.ejs",
72
72
  destination: `app/src/Components/${this.name.pascal}Component.php`,
73
- isEnabled: this.answers.createComposer,
73
+ isEnabled: this.answers.createComponentComposer,
74
74
  },
75
75
  {
76
76
  template: "styles/_component.scss.ejs",
77
77
  destination: `resources/styles/theme/components/_${this.name.slug}.scss`,
78
- isEnabled: this.answers.createStyles,
78
+ isEnabled: this.answers.createComponentStyles,
79
79
  },
80
80
  {
81
81
  template: "scripts/component.js.ejs",
82
82
  destination: `resources/scripts/theme/components/${this.name.camel}.js`,
83
- isEnabled: this.answers.createScript,
83
+ isEnabled: this.answers.createComponentScript,
84
84
  },
85
85
  {
86
86
  template: "acf/group.json.ejs",
87
87
  destination: `theme/acf-json/${this.acf.key}.json`,
88
- isEnabled: this.answers.createAcf,
88
+ isEnabled: this.answers.createComponentAcf,
89
89
  },
90
90
  ];
91
91
  const appends = [
92
92
  {
93
93
  template: "styles/index.scss.ejs",
94
94
  destination: "resources/styles/theme/components/index.scss",
95
- isEnabled: this.answers.createStyles,
95
+ isEnabled: this.answers.createComponentStyles,
96
96
  },
97
97
  ];
98
98
 
99
99
  copyTemplates(this, templates, this.data);
100
100
  appendTemplates(this, appends, this.data);
101
101
 
102
- if (this.answers.createScript) {
102
+ if (this.answers.createComponentScript) {
103
103
  addThemeScript(this, {
104
104
  indexPath: "resources/scripts/theme/index.js",
105
105
  importName: this.name.pascal,
@@ -1,9 +1,9 @@
1
- <%_ if (answers.createAcf) { _%>
1
+ <%_ if (answers.createComponentAcf) { _%>
2
2
  {{--
3
3
  Key: <%= acf.key %>
4
4
  --}}
5
5
  <% } _%>
6
- <%_ if (!answers.createComposer) { _%>
6
+ <%_ if (!answers.createComponentComposer) { _%>
7
7
  @php
8
8
  $class = af_value_or_default( $class, '' );
9
9
  @endphp
@@ -4,6 +4,6 @@ export default class <%= name.pascal %> {
4
4
  }
5
5
 
6
6
  bootstrap() {
7
-
7
+
8
8
  }
9
9
  }
@@ -1,3 +1,3 @@
1
1
  .c-<%= name.slug %> {
2
-
2
+
3
3
  }
@@ -0,0 +1,110 @@
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 mapFilesToTemplates from "../../utils/mapFilesToTemplates.js";
7
+ import requiredText from "../../utils/validation/requiredText.js";
8
+ import title from "../../utils/log/title.js";
9
+ import highlightText from "../../utils/log/text/highlightText.js";
10
+ 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
+ import infoBox from "../../utils/log/boxes/infoBox.js";
14
+
15
+ export default class extends Generator {
16
+ async prompting() {
17
+ this.log(
18
+ lines([
19
+ title(`Let's generate an ${highlightText("npm package")}!`),
20
+ infoBox(
21
+ lines([
22
+ "This will create an npm package that will be",
23
+ `published to npm under the ${brandText("airfleet")} scope`,
24
+ "as soon as the changes are pushed to the main",
25
+ "branch.",
26
+ "",
27
+ dangerText("Make sure to add a feature in code and update"),
28
+ dangerText("change log before merging to main branch!"),
29
+ "",
30
+ "Before starting you should have:",
31
+ " - Created a repository",
32
+ " - Created the Notion page (can start empty)",
33
+ "",
34
+ "All the files will be created in the current",
35
+ "folder. Make sure to navigate to repo folder",
36
+ "first.",
37
+ ])
38
+ ),
39
+ "",
40
+ ])
41
+ );
42
+
43
+ const prompts = [
44
+ {
45
+ type: "input",
46
+ name: "npmName",
47
+ message: "What is the name of the npm package? (will be prescoped with \"@airfleet\")",
48
+ validate: requiredText("Please enter a name"),
49
+ },
50
+ {
51
+ type: "input",
52
+ name: "npmTitle",
53
+ message: "What is the title of the npm package?",
54
+ validate: requiredText("Please enter a title"),
55
+ },
56
+ {
57
+ type: "input",
58
+ name: "npmDescription",
59
+ message: "How would you describe the npm package?",
60
+ validate: requiredText("Please enter a description"),
61
+ },
62
+ {
63
+ type: "input",
64
+ name: "npmRepository",
65
+ message: "What's the repository URL? (start with https and end with .git)",
66
+ validate: requiredText("Please enter the repository URL"),
67
+ },
68
+ {
69
+ type: "input",
70
+ name: "npmDocumentationUrl",
71
+ message: "What's the documentation URL? (Notion page)",
72
+ validate: requiredText("Please enter the documentation URL"),
73
+ },
74
+ {
75
+ type: "input",
76
+ name: "npmNodeVersion",
77
+ message: "What's the required Node version?",
78
+ validate: requiredText("Please enter the Node version"),
79
+ default: ">=14",
80
+ },
81
+ ];
82
+
83
+ this.answers = await this.prompt(prompts);
84
+ this.name = nameCases(this.answers.npmName);
85
+ this.data = {
86
+ answers: this.answers,
87
+ name: this.name,
88
+ packageName: `@airfleet/${this.name.slug}`,
89
+ repositoryBase: this.answers.npmRepository.replace(/\.git$/, ""),
90
+ year: new Date().getFullYear(),
91
+ };
92
+ }
93
+
94
+ writing() {
95
+ const files = [
96
+ ".airfleet-release",
97
+ ".editorconfig",
98
+ ".gitattributes",
99
+ ".gitignore",
100
+ ".gitlab-ci.yml",
101
+ "CHANGELOG.md",
102
+ "LICENSE.ejs",
103
+ "package.json.ejs",
104
+ "README.md.ejs",
105
+ ];
106
+ const templates = mapFilesToTemplates(files);
107
+
108
+ copyTemplates(this, templates, this.data);
109
+ }
110
+ }
@@ -0,0 +1 @@
1
+ minor
@@ -0,0 +1,18 @@
1
+ # editorconfig.org
2
+
3
+ root = true
4
+
5
+ [*]
6
+ charset = utf-8
7
+ end_of_line = lf
8
+ indent_style = space
9
+ indent_size = 2
10
+ trim_trailing_whitespace = true
11
+ insert_final_newline = true
12
+
13
+ [*.md]
14
+ trim_trailing_whitespace = false
15
+
16
+ [*.php]
17
+ indent_style = tab
18
+ indent_size = 4
@@ -0,0 +1,11 @@
1
+ *.js eol=lf
2
+ *.jsx eol=lf
3
+ *.ts eol=lf
4
+ *.tsx eol=lf
5
+ *.json eol=lf
6
+ *.md eol=lf
7
+ *.yml eol=lf
8
+ *.yaml eol=lf
9
+ *.css eol=lf
10
+ *.scss eol=lf
11
+ *.php eol=lf
@@ -0,0 +1,8 @@
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'
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](http://keepachangelog.com/)
6
+ and this project adheres to [Semantic Versioning](http://semver.org/).
7
+
8
+ ## [Unreleased]
9
+
10
+ ### Added
@@ -0,0 +1,2 @@
1
+ Copyright (c) <%= year %> Airfleet <dev@airfleet.co> (https://www.airfleet.co/)
2
+ All rights reserved.
@@ -0,0 +1,20 @@
1
+ # <%= answers.npmTitle %>
2
+
3
+ ![npm](https://img.shields.io/npm/v/<%= packageName %>)
4
+ [![pipeline status](<%= repositoryBase %>/badges/main/pipeline.svg)](<%= repositoryBase %>/-/commits/main)
5
+
6
+ <%= answers.npmDescription %>
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ npm install --save-dev <%= packageName %>
12
+ ```
13
+
14
+ ## Documentation
15
+
16
+ - [Documentation](<%= answers.npmDocumentationUrl %>).
17
+
18
+ ## License
19
+
20
+ © [Airfleet](https://www.airfleet.co/)
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "<%= packageName %>",
3
+ "description": "<%= answers.npmDescription %>",
4
+ "version": "0.0.0",
5
+ "scripts": {},
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "keywords": [
10
+ "airfleet"
11
+ ],
12
+ "homepage": "https://www.airfleet.co",
13
+ "author": {
14
+ "name": "Airfleet",
15
+ "email": "dev@airfleet.co",
16
+ "url": "https://www.airfleet.co/"
17
+ },
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "<%= answers.npmRepository %>"
21
+ },
22
+ "type": "module",
23
+ "engines": {
24
+ "node": "<%- answers.npmNodeVersion %>"
25
+ },
26
+ "dependencies": {}
27
+ }
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.1.0",
4
+ "version": "0.4.0",
5
5
  "scripts": {},
6
6
  "publishConfig": {
7
7
  "access": "public"
@@ -10,7 +10,7 @@
10
10
  "airfleet",
11
11
  "yeoman-generator"
12
12
  ],
13
- "homepage": "https://www.airfleet.co/",
13
+ "homepage": "https://www.airfleet.co",
14
14
  "author": {
15
15
  "name": "Airfleet",
16
16
  "email": "dev@airfleet.co",
@@ -27,7 +27,7 @@
27
27
  "utils"
28
28
  ],
29
29
  "engines": {
30
- "node": ">=14"
30
+ "node": ">=12"
31
31
  },
32
32
  "dependencies": {
33
33
  "boxen": "^6.2.1",
@@ -38,9 +38,5 @@
38
38
  "title-case": "^3.0.3",
39
39
  "yeoman-generator": "^5.4.2",
40
40
  "yosay": "^2.0.2"
41
- },
42
- "devDependencies": {
43
- "@release-it/keep-a-changelog": "^2.3.0",
44
- "release-it": "^14.11.7"
45
41
  }
46
42
  }
package/utils/acfData.js CHANGED
@@ -1,9 +1,12 @@
1
1
  import { uniqid } from "locutus/php/misc/index.js";
2
2
  import { time } from "locutus/php/datetime/index.js";
3
3
 
4
- export default function acfData({ prefix }) {
4
+ export default function acfData(options = {}) {
5
5
  return {
6
- key: uniqid(prefix),
6
+ key: uniqid("group_"),
7
7
  timestamp: time(),
8
+ fields: Object.fromEntries(
9
+ (options.fields || []).map((key) => [key, uniqid("field_")])
10
+ ),
8
11
  };
9
12
  }
@@ -0,0 +1,9 @@
1
+ import box from "./box.js";
2
+
3
+ export default function infoBox(message, options) {
4
+ return box(message, {
5
+ borderColor: "cyan",
6
+ title: "Info",
7
+ ...options,
8
+ });
9
+ }
@@ -1,10 +1,8 @@
1
1
  import title from "./title.js";
2
2
  import brandText from "./text/brandText.js";
3
- import dangerText from "./text/dangerText.js";
4
3
  import highlightText from "./text/highlightText.js";
5
4
  import lines from "./text/lines.js";
6
5
  import dangerBox from "./boxes/dangerBox.js";
7
- import box from "./boxes/box.js";
8
6
 
9
7
  export default function themeFeature(feature) {
10
8
  return lines([
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Take a list of strings and create objects to be passed to `copyTemplates`.
3
+ * Assumes all files/templates will be copied to the same directory.
4
+ *
5
+ * @param {string[]} files Template files.
6
+ */
7
+ export default function mapFilesToTemplates(files) {
8
+ return files.map((file) => ({
9
+ template: file,
10
+ destination: file.replace(/\.ejs$/, ""),
11
+ isEnabled: true,
12
+ }));
13
+ }
@@ -1,4 +1,4 @@
1
- import { camelCase, paramCase, pascalCase } from "change-case";
1
+ import { camelCase, noCase, paramCase, pascalCase } from "change-case";
2
2
  import { titleCase } from "title-case";
3
3
 
4
4
  export default function nameCases(name) {
@@ -17,5 +17,8 @@ export default function nameCases(name) {
17
17
 
18
18
  // "Test String"
19
19
  title: titleCase(name),
20
+
21
+ // "test string"
22
+ noCase: noCase(name),
20
23
  };
21
24
  }