@flarum/cli 1.0.0 → 2.0.0-beta.1

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 (185) hide show
  1. package/README.md +2 -2
  2. package/bin/run +5 -3
  3. package/boilerplate/skeleton/extension/.gitattributes +16 -3
  4. package/boilerplate/skeleton/extension/.github/workflows/backend.yml +15 -0
  5. package/boilerplate/skeleton/extension/.github/workflows/frontend.yml +20 -0
  6. package/boilerplate/skeleton/extension/.styleci.yml +14 -0
  7. package/boilerplate/skeleton/extension/LICENSE.md +1 -0
  8. package/boilerplate/skeleton/extension/README.md +7 -7
  9. package/boilerplate/skeleton/extension/composer.json +11 -9
  10. package/boilerplate/skeleton/extension/extend.php +10 -10
  11. package/boilerplate/skeleton/extension/js/admin.js +2 -1
  12. package/boilerplate/skeleton/extension/js/forum.js +2 -1
  13. package/boilerplate/skeleton/extension/js/package.json +13 -9
  14. package/boilerplate/skeleton/extension/js/src/admin/index.js +4 -2
  15. package/boilerplate/skeleton/extension/js/src/common/index.js +5 -0
  16. package/boilerplate/skeleton/extension/js/src/forum/index.js +4 -2
  17. package/boilerplate/skeleton/extension/js/tsconfig.json +6 -1
  18. package/boilerplate/skeleton/extension/locale/en.yml +1 -1
  19. package/boilerplate/stubs/migration.php +1 -1
  20. package/lib/base-command.d.ts +27 -6
  21. package/lib/base-command.js +131 -41
  22. package/lib/boilersmith/exposed-param-manager.d.ts +8 -0
  23. package/lib/boilersmith/exposed-param-manager.js +31 -0
  24. package/lib/boilersmith/io.d.ts +50 -0
  25. package/lib/boilersmith/io.js +72 -0
  26. package/lib/boilersmith/paths.d.ts +22 -0
  27. package/lib/boilersmith/paths.js +29 -0
  28. package/lib/boilersmith/scaffolding/audit-step-factory.d.ts +5 -0
  29. package/lib/boilersmith/scaffolding/audit-step-factory.js +54 -0
  30. package/lib/boilersmith/scaffolding/infra-step-factory.d.ts +5 -0
  31. package/lib/boilersmith/scaffolding/infra-step-factory.js +34 -0
  32. package/lib/boilersmith/scaffolding/init-step-factory.d.ts +5 -0
  33. package/lib/boilersmith/scaffolding/init-step-factory.js +34 -0
  34. package/lib/boilersmith/scaffolding/module.d.ts +68 -0
  35. package/lib/boilersmith/scaffolding/module.js +111 -0
  36. package/lib/boilersmith/scaffolding/scaffolder.d.ts +32 -0
  37. package/lib/boilersmith/scaffolding/scaffolder.js +203 -0
  38. package/lib/boilersmith/scaffolding/template-param.d.ts +23 -0
  39. package/lib/boilersmith/scaffolding/template-param.js +46 -0
  40. package/lib/boilersmith/step-manager.d.ts +85 -0
  41. package/lib/boilersmith/step-manager.js +234 -0
  42. package/lib/boilersmith/steps/stub-base.d.ts +53 -0
  43. package/lib/boilersmith/steps/stub-base.js +54 -0
  44. package/lib/{utils → boilersmith/utils}/clone-and-fill.d.ts +0 -0
  45. package/lib/{utils → boilersmith/utils}/clone-and-fill.js +2 -2
  46. package/lib/boilersmith/utils/cond-format.d.ts +1 -0
  47. package/lib/boilersmith/utils/cond-format.js +8 -0
  48. package/lib/boilersmith/utils/json-leaf-paths.d.ts +7 -0
  49. package/lib/boilersmith/utils/json-leaf-paths.js +17 -0
  50. package/lib/boilersmith/utils/read-tpl.d.ts +2 -0
  51. package/lib/boilersmith/utils/read-tpl.js +10 -0
  52. package/lib/boilersmith/utils/rename-keys.d.ts +1 -0
  53. package/lib/boilersmith/utils/rename-keys.js +7 -0
  54. package/lib/commands/audit/infra.d.ts +16 -0
  55. package/lib/commands/audit/infra.js +27 -0
  56. package/lib/commands/infra.d.ts +20 -0
  57. package/lib/commands/infra.js +55 -0
  58. package/lib/commands/init.d.ts +4 -3
  59. package/lib/commands/init.js +8 -6
  60. package/lib/commands/make/backend/api-controller.d.ts +4 -3
  61. package/lib/commands/make/backend/api-controller.js +3 -2
  62. package/lib/commands/make/backend/api-serializer-attributes.d.ts +4 -3
  63. package/lib/commands/make/backend/api-serializer-attributes.js +1 -1
  64. package/lib/commands/make/backend/api-serializer.d.ts +4 -3
  65. package/lib/commands/make/backend/api-serializer.js +3 -2
  66. package/lib/commands/make/backend/command.d.ts +4 -3
  67. package/lib/commands/make/backend/command.js +3 -2
  68. package/lib/commands/make/backend/event-listener.d.ts +4 -3
  69. package/lib/commands/make/backend/event-listener.js +3 -2
  70. package/lib/commands/make/backend/handler.d.ts +4 -3
  71. package/lib/commands/make/backend/handler.js +4 -3
  72. package/lib/commands/make/backend/integration-test.d.ts +4 -3
  73. package/lib/commands/make/backend/integration-test.js +3 -2
  74. package/lib/commands/make/backend/job.d.ts +4 -3
  75. package/lib/commands/make/backend/job.js +3 -2
  76. package/lib/commands/make/backend/migration.d.ts +4 -3
  77. package/lib/commands/make/backend/migration.js +3 -2
  78. package/lib/commands/make/backend/model.d.ts +4 -3
  79. package/lib/commands/make/backend/model.js +22 -21
  80. package/lib/commands/make/backend/policy.d.ts +4 -3
  81. package/lib/commands/make/backend/policy.js +3 -2
  82. package/lib/commands/make/backend/repository.d.ts +4 -3
  83. package/lib/commands/make/backend/repository.js +3 -2
  84. package/lib/commands/make/backend/route.d.ts +4 -3
  85. package/lib/commands/make/backend/route.js +1 -1
  86. package/lib/commands/make/backend/service-provider.d.ts +4 -3
  87. package/lib/commands/make/backend/service-provider.js +3 -2
  88. package/lib/commands/make/backend/validator.d.ts +4 -3
  89. package/lib/commands/make/backend/validator.js +3 -2
  90. package/lib/commands/make/frontend/component.d.ts +4 -3
  91. package/lib/commands/make/frontend/component.js +3 -2
  92. package/lib/commands/make/frontend/modal.d.ts +4 -3
  93. package/lib/commands/make/frontend/modal.js +3 -2
  94. package/lib/commands/make/frontend/model.d.ts +4 -3
  95. package/lib/commands/make/frontend/model.js +3 -2
  96. package/lib/commands/update/js-imports.d.ts +4 -3
  97. package/lib/commands/update/js-imports.js +1 -1
  98. package/lib/help.d.ts +5 -6
  99. package/lib/help.js +5 -4
  100. package/lib/index.d.ts +1 -1
  101. package/lib/index.js +3 -2
  102. package/lib/providers/index.d.ts +5 -0
  103. package/lib/providers/index.js +2 -0
  104. package/lib/{provider → providers}/php-provider.d.ts +0 -0
  105. package/lib/{provider → providers}/php-provider.js +2 -2
  106. package/lib/steps/extenders/api-serializer.js +2 -3
  107. package/lib/steps/extenders/base.d.ts +10 -10
  108. package/lib/steps/extenders/base.js +11 -11
  109. package/lib/steps/extenders/console-command.js +2 -3
  110. package/lib/steps/extenders/event.js +2 -3
  111. package/lib/steps/extenders/policy.js +2 -3
  112. package/lib/steps/extenders/route.js +2 -3
  113. package/lib/steps/extenders/service-provider.js +2 -3
  114. package/lib/steps/gen-ext-scaffolder.d.ts +6 -0
  115. package/lib/steps/gen-ext-scaffolder.js +508 -0
  116. package/lib/steps/js/base.d.ts +9 -9
  117. package/lib/steps/js/base.js +11 -11
  118. package/lib/steps/js/model.d.ts +5 -5
  119. package/lib/steps/js/model.js +8 -13
  120. package/lib/steps/misc/composer.d.ts +5 -6
  121. package/lib/steps/misc/composer.js +3 -3
  122. package/lib/steps/misc/git.d.ts +11 -0
  123. package/lib/steps/misc/git.js +20 -0
  124. package/lib/steps/misc/yarn.d.ts +5 -6
  125. package/lib/steps/misc/yarn.js +3 -3
  126. package/lib/steps/stubs/backend/api-controller.d.ts +1 -8
  127. package/lib/steps/stubs/backend/api-controller.js +2 -3
  128. package/lib/steps/stubs/backend/api-serializer.d.ts +4 -9
  129. package/lib/steps/stubs/backend/api-serializer.js +4 -4
  130. package/lib/steps/stubs/backend/command.d.ts +0 -5
  131. package/lib/steps/stubs/backend/command.js +1 -1
  132. package/lib/steps/stubs/backend/event-listener.d.ts +0 -5
  133. package/lib/steps/stubs/backend/event-listener.js +1 -1
  134. package/lib/steps/stubs/backend/handler-command.js +1 -1
  135. package/lib/steps/stubs/backend/handler.js +1 -1
  136. package/lib/steps/stubs/backend/migration.d.ts +4 -5
  137. package/lib/steps/stubs/backend/migration.js +8 -8
  138. package/lib/steps/stubs/backend/model.d.ts +4 -4
  139. package/lib/steps/stubs/backend/model.js +4 -4
  140. package/lib/steps/stubs/backend/policy.d.ts +0 -5
  141. package/lib/steps/stubs/backend/policy.js +1 -1
  142. package/lib/steps/stubs/backend/repository.d.ts +0 -5
  143. package/lib/steps/stubs/backend/repository.js +1 -1
  144. package/lib/steps/stubs/flarum-base.d.ts +9 -0
  145. package/lib/steps/stubs/flarum-base.js +10 -0
  146. package/lib/steps/stubs/frontend/component.js +0 -1
  147. package/lib/steps/stubs/frontend/modal.js +0 -1
  148. package/lib/steps/stubs/frontend/model.d.ts +4 -4
  149. package/lib/steps/stubs/frontend/model.js +3 -3
  150. package/lib/steps/stubs/js-base.d.ts +6 -7
  151. package/lib/steps/stubs/js-base.js +11 -16
  152. package/lib/steps/stubs/php-base.d.ts +7 -8
  153. package/lib/steps/stubs/php-base.js +12 -20
  154. package/lib/steps/update/js-imports.d.ts +5 -6
  155. package/lib/steps/update/js-imports.js +13 -17
  156. package/lib/utils/composer.d.ts +64 -0
  157. package/lib/utils/composer.js +8 -0
  158. package/lib/utils/migration.js +3 -3
  159. package/lib/utils/model-name.js +6 -6
  160. package/lib/utils/validation.d.ts +10 -7
  161. package/lib/utils/validation.js +9 -6
  162. package/oclif.manifest.json +1 -1
  163. package/package.json +53 -31
  164. package/php-subsystem/src/NodeVisitors/AddExtender.php +2 -1
  165. package/boilerplate/skeleton/extension/.github/workflows/build.yml +0 -32
  166. package/boilerplate/skeleton/extension/.github/workflows/lint.yml +0 -32
  167. package/boilerplate/skeleton/extension/.github/workflows/test.yml +0 -78
  168. package/lib/commands/infra/backend-testing.d.ts +0 -14
  169. package/lib/commands/infra/backend-testing.js +0 -26
  170. package/lib/provider/param-provider.d.ts +0 -15
  171. package/lib/provider/param-provider.js +0 -39
  172. package/lib/provider/path-provider.d.ts +0 -19
  173. package/lib/provider/path-provider.js +0 -24
  174. package/lib/steps/infra/backend-testing.d.ts +0 -8
  175. package/lib/steps/infra/backend-testing.js +0 -22
  176. package/lib/steps/infra/base.d.ts +0 -20
  177. package/lib/steps/infra/base.js +0 -36
  178. package/lib/steps/init/extension-skeleton.d.ts +0 -12
  179. package/lib/steps/init/extension-skeleton.js +0 -142
  180. package/lib/steps/step-manager.d.ts +0 -71
  181. package/lib/steps/step-manager.js +0 -173
  182. package/lib/steps/stubs/base.d.ts +0 -49
  183. package/lib/steps/stubs/base.js +0 -58
  184. package/lib/utils/extension-metadata.d.ts +0 -2
  185. package/lib/utils/extension-metadata.js +0 -21
package/README.md CHANGED
@@ -37,7 +37,7 @@ $ npm install -g @flarum/cli
37
37
  $ flarum-cli COMMAND
38
38
  running command...
39
39
  $ flarum-cli (-v|--version|version)
40
- @flarum/cli/1.0.0 linux-x64 node-v14.17.2
40
+ @flarum/cli/2.0.0-beta.1 linux-x64 node-v16.13.0
41
41
  $ flarum-cli --help [COMMAND]
42
42
  USAGE
43
43
  $ flarum-cli COMMAND
@@ -192,7 +192,7 @@ For example:
192
192
  },
193
193
  ]);
194
194
  })
195
- .run(stubPathProviderFactory(), paramProviderFactory, stubPhpProviderFactory());
195
+ .run(new Paths({...}), new PromptsIO(), {php: new PhpProvider(...)});
196
196
  ```
197
197
 
198
198
 
package/bin/run CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- require('@oclif/command').run()
4
- .then(require('@oclif/command/flush'))
5
- .catch(require('@oclif/errors/handle'))
3
+ require('module-alias').addAlias('boilersmith', `${__dirname}/../lib/boilersmith`);
4
+
5
+ const oclif = require('@oclif/core');
6
+
7
+ oclif.run().then(require('@oclif/core/flush')).catch(require('@oclif/core/handle'));
@@ -1,4 +1,17 @@
1
- js/src export-ignore
2
- .git* export-ignore
1
+ .gitattributes export-ignore
2
+ .gitignore export-ignore
3
+ .gitmodules export-ignore
4
+ .github export-ignore
5
+ .travis export-ignore
6
+ .travis.yml export-ignore
7
+ .editorconfig export-ignore
8
+ .styleci.yml export-ignore
3
9
 
4
- js/dist/*.js -diff
10
+ phpunit.xml export-ignore
11
+ tests export-ignore
12
+
13
+ js/dist/* -diff
14
+ js/dist/* linguist-generated
15
+ js/dist-typings/* linguist-generated
16
+
17
+ * text=auto eol=lf
@@ -0,0 +1,15 @@
1
+ name: PHP
2
+
3
+ on: [workflow_dispatch, push, pull_request]
4
+
5
+ # The reusable workflow definitions will be moved to the `flarum/framework` repo soon.
6
+ # This will break your current script.
7
+ # When this happens, run `flarum-cli audit infra --fix` to update your infrastructure.
8
+
9
+ jobs:
10
+ run:
11
+ uses: flarum/.github/.github/workflows/REUSABLE_backend.yml@main
12
+ with:
13
+ enable_backend_testing: <%= modules.backendTesting %>
14
+
15
+ backend_directory: <%= params.backendDirectory %>
@@ -0,0 +1,20 @@
1
+ name: JS
2
+
3
+ on: [workflow_dispatch, push, pull_request]
4
+
5
+ # The reusable workflow definitions will be moved to the `flarum/framework` repo soon.
6
+ # This will break your current script.
7
+ # When this happens, run `flarum-cli audit infra --fix` to update your infrastructure.
8
+
9
+ jobs:
10
+ run:
11
+ uses: flarum/.github/.github/workflows/REUSABLE_frontend.yml@main
12
+ with:
13
+ enable_bundlewatch: <%= modules.bundlewatch %>
14
+ enable_prettier: <%= modules.prettier %>
15
+ enable_typescript: <%= modules.typescript %>
16
+
17
+ frontend_directory: <%= params.frontendDirectory %>
18
+ main_git_branch: <%= params.mainGitBranch %>
19
+ secrets:
20
+ bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
@@ -0,0 +1,14 @@
1
+ preset: recommended
2
+
3
+ enabled:
4
+ - logical_not_operators_with_successor_space
5
+
6
+ disabled:
7
+ - align_double_arrow
8
+ - blank_line_after_opening_tag
9
+ - multiline_array_trailing_comma
10
+ - new_with_braces
11
+ - phpdoc_align
12
+ - phpdoc_order
13
+ - phpdoc_separation
14
+ - phpdoc_types
@@ -0,0 +1 @@
1
+ <%= params.licenseText %>
@@ -1,27 +1,27 @@
1
- # <%= extensionName %>
1
+ # <%= params.extensionName %>
2
2
 
3
- ![License](https://img.shields.io/badge/license-<%= licenseType %>-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/<%= packageName %>.svg)](https://packagist.org/packages/<%= packageName %>) [![Total Downloads](https://img.shields.io/packagist/dt/<%= packageName %>.svg)](https://packagist.org/packages/<%= packageName %>)
3
+ ![License](https://img.shields.io/badge/license-<%= params.licenseType %>-blue.svg) [![Latest Stable Version](https://img.shields.io/packagist/v/<%= params.packageName %>.svg)](https://packagist.org/packages/<%= params.packageName %>) [![Total Downloads](https://img.shields.io/packagist/dt/<%= params.packageName %>.svg)](https://packagist.org/packages/<%= params.packageName %>)
4
4
 
5
- A [Flarum](http://flarum.org) extension. <%= packageDescription %>
5
+ A [Flarum](http://flarum.org) extension. <%= params.packageDescription %>
6
6
 
7
7
  ## Installation
8
8
 
9
9
  Install with composer:
10
10
 
11
11
  ```sh
12
- composer require <%= packageName %>:"*"
12
+ composer require <%= params.packageName %>:"*"
13
13
  ```
14
14
 
15
15
  ## Updating
16
16
 
17
17
  ```sh
18
- composer update <%= packageName %>:"*"
18
+ composer update <%= params.packageName %>:"*"
19
19
  php flarum migrate
20
20
  php flarum cache:clear
21
21
  ```
22
22
 
23
23
  ## Links
24
24
 
25
- - [Packagist](https://packagist.org/packages/<%= packageName %>)
26
- - [GitHub](https://github.com/<%= packageName %>)
25
+ - [Packagist](https://packagist.org/packages/<%= params.packageName %>)
26
+ - [GitHub](https://github.com/<%= params.packageName %>)
27
27
  - [Discuss](https://discuss.flarum.org/d/PUT_DISCUSS_SLUG_HERE)
@@ -1,37 +1,39 @@
1
1
  {
2
- "name": "<%= packageName %>",<% if (packageDescription) { %>
3
- "description": "<%= packageDescription %>",<% } %>
2
+ "name": "<%= params.packageName %>",<% if (params.packageDescription) { %>
3
+ "description": "<%= params.packageDescription %>",<% } %>
4
4
  "keywords": [
5
5
  "flarum"
6
6
  ],
7
7
  "type": "flarum-extension",
8
- "license": "<%= licenseType %>",
8
+ "license": "<%= params.licenseType %>",
9
9
  "require": {
10
10
  "flarum/core": "^1.0.0"
11
11
  },
12
12
  "require-dev": {
13
13
  "flarum/testing": "^1.0.0"
14
14
  },
15
- "authors": [<% if (authorName && authorEmail) { %>
15
+ "authors": [<% if (params.authorName) { %>
16
16
  {
17
- "name": "<%= authorName %>",<% if (authorEmail) { %>
18
- "email": "<%= authorEmail %>",<% } %>
17
+ "name": "<%= params.authorName %>",<% if (params.authorEmail) { %>
18
+ "email": "<%= params.authorEmail %>",<% } %>
19
19
  "role": "Developer"
20
20
  }
21
21
  <% } %>],
22
+ <% if (params.packageNamespace) { %>
22
23
  "autoload": {
23
24
  "psr-4": {
24
- "<%= packageNamespace %>\\": "src/"
25
+ "<%= params.packageNamespaceEscapedSlash %>\\": "src/"
25
26
  }
26
27
  },
28
+ <% } %>
27
29
  "autoload-dev": {
28
30
  "psr-4": {
29
- "<%= packageNamespace %>\\Tests\\": "tests/"
31
+ "<%= params.packageNamespaceEscapedSlash %>\\Tests\\": "tests/"
30
32
  }
31
33
  },
32
34
  "extra": {
33
35
  "flarum-extension": {
34
- "title": "<%= extensionName %>",
36
+ "title": "<%= params.extensionName %>",
35
37
  "category": "",
36
38
  "icon": {
37
39
  "name": "",
@@ -1,24 +1,24 @@
1
1
  <?php
2
2
 
3
3
  /*
4
- * This file is part of <%= packageName %>.
4
+ * This file is part of <%= params.packageName %>.
5
5
  *
6
- * Copyright (c) <%= year %> <%= authorName %>.
6
+ * Copyright (c) <%= params.year %> <%= params.authorName %>.
7
7
  *
8
8
  * For the full copyright and license information, please view the LICENSE.md
9
9
  * file that was distributed with this source code.
10
10
  */
11
11
 
12
- namespace <%= namespace %>;
12
+ namespace <%= params.packageNamespace %>;
13
13
 
14
14
  use Flarum\Extend;
15
15
 
16
16
  return [
17
- <% if (forum) { %>(new Extend\Frontend('forum'))
18
- <% if (useJs) { %>->js(__DIR__.'/js/dist/forum.js')<% if (!useCss) { %>,<% } %><% } %>
19
- <% if (useCss) { %>->css(__DIR__.'/less/forum.less'),<% } %><% } %>
20
- <% if (admin) { %>(new Extend\Frontend('admin'))
21
- <% if (useJs) { %>->js(__DIR__.'/js/dist/admin.js')<% if (!useCss) { %>,<% } %><% } %>
22
- <% if (useCss) { %>->css(__DIR__.'/less/admin.less'),<% } %><% } %>
23
- <% if (useLocale) { %>new Extend\Locales(__DIR__.'/locale'),<% } %>
17
+ <% if (modules.js || modules.css) { %>(new Extend\Frontend('forum'))
18
+ <% if (modules.js) { %>->js(__DIR__.'/js/dist/forum.js')<% if (!modules.css) { %>,<% } %><% } %>
19
+ <% if (modules.css) { %>->css(__DIR__.'/less/forum.less'),<% } %><% } %>
20
+ <% if (modules.js || modules.css) { %>(new Extend\Frontend('admin'))
21
+ <% if (modules.js) { %>->js(__DIR__.'/js/dist/admin.js')<% if (!modules.css) { %>,<% } %><% } %>
22
+ <% if (modules.css) { %>->css(__DIR__.'/less/admin.less'),<% } %><% } %>
23
+ <% if (modules.locale) { %>new Extend\Locales(__DIR__.'/locale'),<% } %>
24
24
  ];
@@ -1 +1,2 @@
1
- export * from './src/admin';
1
+ <% if (modules.jsCommon) { %>export * from './src/common';
2
+ <% } %>export * from './src/admin';
@@ -1 +1,2 @@
1
- export * from './src/forum';
1
+ <% if (modules.jsCommon) { %>export * from './src/common';
2
+ <% } %>export * from './src/forum';
@@ -1,22 +1,26 @@
1
1
  {
2
- "name": "@<%= packageName %>",
3
- "version": "0.0.0",
2
+ "name": "@<%= params.packageName %>",
4
3
  "private": true,
5
4
  "prettier": "@flarum/prettier-config",
6
5
  "dependencies": {
7
- "flarum-webpack-config": "^1.0.0",
8
- "flarum-tsconfig": "^1.0.0",
9
- "@flarum/prettier-config": "^1.0.0",
10
- "webpack": "^4.26.0",
11
- "webpack-cli": "^3.0.7"
12
6
  },
13
7
  "devDependencies": {
14
- "prettier": "^2.3.0"
8
+ "@flarum/prettier-config": "^1.0.0",
9
+ "flarum-tsconfig": "^1.0.2",
10
+ "flarum-webpack-config": "^2.0.0",
11
+ "prettier": "^2.4.1",
12
+ "typescript": "^4.4.4",
13
+ "typescript-coverage-report": "^0.6.1",
14
+ "webpack": "^5.61.0",
15
+ "webpack-cli": "^4.9.1"
15
16
  },
16
17
  "scripts": {
17
18
  "dev": "webpack --mode development --watch",
18
19
  "build": "webpack --mode production",
20
+ "analyze": "cross-env ANALYZER=true yarn build",
19
21
  "format": "prettier --write src",
20
- "format-check": "prettier --check src"
22
+ "format-check": "prettier --check src",
23
+ "check-typings": "tsc --noEmit --emitDeclarationOnly false",
24
+ "check-typings-coverage": "typescript-coverage-report"
21
25
  }
22
26
  }
@@ -1,3 +1,5 @@
1
- app.initializers.add('<%= packageName %>', () => {
2
- console.log('[<%= packageName %>] Hello, admin!');
1
+ import app from 'flarum/admin/app';
2
+
3
+ app.initializers.add('<%= params.packageName %>', () => {
4
+ console.log('[<%= params.packageName %>] Hello, admin!');
3
5
  });
@@ -0,0 +1,5 @@
1
+ import app from 'flarum/common/app';
2
+
3
+ app.initializers.add('<%= params.packageName %>', () => {
4
+ console.log('[<%= params.packageName %>] Hello, forum and admin!');
5
+ });
@@ -1,3 +1,5 @@
1
- app.initializers.add('<%= packageName %>', () => {
2
- console.log('[<%= packageName %>] Hello, forum!');
1
+ import app from 'flarum/forum/app';
2
+
3
+ app.initializers.add('<%= params.packageName %>', () => {
4
+ console.log('[<%= params.packageName %>] Hello, forum!');
3
5
  });
@@ -1,7 +1,12 @@
1
1
  {
2
+ // Use Flarum's tsconfig as a starting point
2
3
  "extends": "flarum-tsconfig",
3
- "include": ["src/**/*"],
4
+ // This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
5
+ // and also tells your Typescript server to read core's global typings for
6
+ // access to `dayjs` and `$` in the global namespace.
7
+ "include": ["src/**/*", "../vendor/flarum/core/js/dist-typings/@types/**/*", "@types/**/*"],
4
8
  "compilerOptions": {
9
+ // This will output typings to `dist-typings`
5
10
  "declarationDir": "./dist-typings",
6
11
  "baseUrl": ".",
7
12
  "paths": {
@@ -1,4 +1,4 @@
1
- <%= extensionId %>:
1
+ <%= params.extensionId %>:
2
2
  # For more details on the format
3
3
  # Checkout https://docs.flarum.org/extend/i18n.html#appendix-a-standard-key-format
4
4
  admin:
@@ -5,7 +5,7 @@ use Illuminate\Database\Schema\Blueprint;
5
5
  use Illuminate\Database\Schema\Builder;
6
6
 
7
7
  // HINT: you might want to use a `Flarum\Database\Migration` helper method for simplicity!
8
- // See https://docs.flarum.org/extend/data.html#migrations to learn more about migrations.
8
+ // See https://docs.flarum.org/extend/models.html#migrations to learn more about migrations.
9
9
  return [
10
10
  'up' => function (Builder $schema) {
11
11
  // up migration
@@ -1,7 +1,18 @@
1
- import { Command, flags } from '@oclif/command';
2
- import { StepManager } from './steps/step-manager';
1
+ import { Command, Interfaces } from '@oclif/core';
2
+ import { StepManager } from 'boilersmith/step-manager';
3
+ import { FlarumProviders } from './providers';
4
+ export declare enum LocationType {
5
+ FLARUM_EXTENSION = 0,
6
+ FLARUM_CORE = 1,
7
+ FLARUM_MONOREPO = 2
8
+ }
3
9
  export default abstract class BaseCommand extends Command {
4
- static flags: flags.Input<any>;
10
+ protected STUB_PATH: string;
11
+ protected dry: boolean;
12
+ protected locationType?: LocationType;
13
+ protected args: Record<string, any>;
14
+ protected flags: any;
15
+ static flags: Interfaces.FlagInput<any>;
5
16
  static args: {
6
17
  name: string;
7
18
  description: string;
@@ -11,8 +22,18 @@ export default abstract class BaseCommand extends Command {
11
22
  protected welcomeMessage(): string;
12
23
  protected goodbyeMessage(): string;
13
24
  protected additionalPreRunChecks(_extRoot: string): Promise<void>;
14
- protected abstract steps(stepManager: StepManager): StepManager;
15
- protected getFlarumExtensionRoot(currDir: string): Promise<string>;
25
+ protected abstract steps(stepManager: StepManager<FlarumProviders>): StepManager<FlarumProviders>;
26
+ protected monorepoPaths(options: {
27
+ includeCore: boolean;
28
+ includeExtensions: boolean;
29
+ includePhpPackages: boolean;
30
+ includeJSPackages: boolean;
31
+ }): string[];
32
+ protected isFlarumCore(path: string): boolean;
33
+ protected getFlarumExtensionRoot(currDir: string): Promise<{
34
+ path: string;
35
+ type: LocationType;
36
+ }>;
16
37
  protected confirmExtDir(extRoot: string): Promise<void>;
17
38
  protected ensureComposerInstallRan(extRoot: string): Promise<void>;
18
39
  /**
@@ -20,6 +41,6 @@ export default abstract class BaseCommand extends Command {
20
41
  * If true, files should be overriden.
21
42
  * If user says no, will exit and not return anything.
22
43
  */
23
- protected confirmOverrideFiles(dir: string, pattern: string, confirmationMessage: string): Promise<boolean>;
44
+ protected confirmOverrideFiles(dir: string, pattern: string | string[], confirmationMessage: string): Promise<boolean>;
24
45
  protected deleteFiles(dir: string, pattern: string): Promise<void>;
25
46
  }
@@ -1,25 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocationType = void 0;
3
4
  const tslib_1 = require("tslib");
4
- const command_1 = require("@oclif/command");
5
- const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
6
- const path_1 = require("path");
7
- const prompts_1 = tslib_1.__importDefault(require("prompts"));
8
- const globby_1 = tslib_1.__importDefault(require("globby"));
9
- const child_process_1 = require("child_process");
10
- const fs_1 = require("fs");
11
- const param_provider_1 = require("./provider/param-provider");
12
- const step_manager_1 = require("./steps/step-manager");
13
- const path_provider_1 = require("./provider/path-provider");
14
- const php_provider_1 = require("./provider/php-provider");
15
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
16
- class BaseCommand extends command_1.Command {
5
+ const core_1 = require("@oclif/core");
6
+ const cli_ux_1 = (0, tslib_1.__importDefault)(require("cli-ux"));
7
+ const node_path_1 = require("node:path");
8
+ const prompts_1 = (0, tslib_1.__importDefault)(require("prompts"));
9
+ const globby_1 = (0, tslib_1.__importDefault)(require("globby"));
10
+ const node_child_process_1 = require("node:child_process");
11
+ const node_fs_1 = require("node:fs");
12
+ const io_1 = require("boilersmith/io");
13
+ const step_manager_1 = require("boilersmith/step-manager");
14
+ const paths_1 = require("boilersmith/paths");
15
+ const php_provider_1 = require("./providers/php-provider");
16
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
17
+ var LocationType;
18
+ (function (LocationType) {
19
+ LocationType[LocationType["FLARUM_EXTENSION"] = 0] = "FLARUM_EXTENSION";
20
+ LocationType[LocationType["FLARUM_CORE"] = 1] = "FLARUM_CORE";
21
+ LocationType[LocationType["FLARUM_MONOREPO"] = 2] = "FLARUM_MONOREPO";
22
+ })(LocationType = exports.LocationType || (exports.LocationType = {}));
23
+ class BaseCommand extends core_1.Command {
17
24
  constructor() {
18
25
  super(...arguments);
26
+ this.STUB_PATH = (0, node_path_1.resolve)(__dirname, '../boilerplate/stubs/');
27
+ this.dry = false;
19
28
  this.requireExistingExtension = true;
20
29
  }
21
30
  async run() {
22
- const { args } = this.parse(this.constructor);
31
+ const { args, flags } = await this.parse(this.constructor);
32
+ this.args = args;
33
+ this.flags = flags;
23
34
  const path = args.path;
24
35
  const welcomeMessage = this.welcomeMessage();
25
36
  if (welcomeMessage) {
@@ -27,24 +38,67 @@ class BaseCommand extends command_1.Command {
27
38
  }
28
39
  let extRoot;
29
40
  if (this.requireExistingExtension) {
30
- extRoot = await this.getFlarumExtensionRoot(path || process.cwd());
31
- await this.confirmExtDir(extRoot);
41
+ const rootData = await this.getFlarumExtensionRoot(path || process.cwd());
42
+ extRoot = rootData.path;
43
+ this.locationType = rootData.type;
44
+ if (!this.flags.defaults) {
45
+ await this.confirmExtDir(extRoot);
46
+ }
32
47
  }
33
48
  else {
34
49
  extRoot = path || process.cwd();
35
50
  }
36
51
  await this.additionalPreRunChecks(extRoot);
37
- const pathProvider = new path_provider_1.PathFsProvider({
52
+ const paths = new paths_1.NodePaths({
38
53
  requestedDir: path,
39
- ext: extRoot,
54
+ package: extRoot,
40
55
  });
41
- const phpProvider = new php_provider_1.PhpSubsystemProvider(path_1.resolve(__dirname, '../php-subsystem/index.php'));
42
- const completed = await this.steps(new step_manager_1.StepManager())
43
- .run(pathProvider, param_provider_1.paramProviderFactory, phpProvider);
56
+ const phpProvider = new php_provider_1.PhpSubsystemProvider((0, node_path_1.resolve)(__dirname, '../php-subsystem/index.php'));
57
+ const out = await this.steps(new step_manager_1.StepManager())
58
+ .run(paths, new io_1.PromptsIO(), { php: phpProvider }, this.dry);
59
+ const errorMessages = out.messages.filter(m => m.type === 'error');
44
60
  this.log('\n\n');
45
- this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.green('Success! The following steps were completed:'))));
46
- completed.forEach(stepName => this.log(`- ${chalk_1.default.dim(stepName)}`));
61
+ if (out.succeeded && errorMessages.length === 0) {
62
+ this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.green('Success! The following steps were completed:'))));
63
+ }
64
+ else if (out.succeeded) {
65
+ this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.yellow('All steps completed, but with some errors:'))));
66
+ for (const message of errorMessages) {
67
+ this.log(chalk_1.default.dim(chalk_1.default.red(message.message)));
68
+ }
69
+ this.log(chalk_1.default.bold(chalk_1.default.yellow('The steps that completed were:')));
70
+ }
71
+ else if (out.error === 'EEXIT: 0') {
72
+ this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.red('Exiting.'))));
73
+ if (out.stepsRan.length > 0) {
74
+ this.log(chalk_1.default.bold(chalk_1.default.yellow('Before the exit, the following steps were completed:')));
75
+ }
76
+ }
77
+ else {
78
+ this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.red('Error occurred, and could not complete:'))));
79
+ this.log(chalk_1.default.red(out.error));
80
+ if (out.errorTrace) {
81
+ this.log(chalk_1.default.dim(chalk_1.default.red(out.errorTrace)));
82
+ }
83
+ if (out.stepsRan.length > 0) {
84
+ this.log('');
85
+ this.log(chalk_1.default.bold(chalk_1.default.yellow('Before the error, the following steps were completed:')));
86
+ }
87
+ }
88
+ for (const stepName of out.stepsRan)
89
+ this.log(`- ${chalk_1.default.dim(stepName)}`);
47
90
  this.log('');
91
+ const nonErrorMessages = out.messages.filter(m => m.type !== 'error');
92
+ if (nonErrorMessages.length > 0) {
93
+ this.log('');
94
+ this.log('The following messages were generated during execution:');
95
+ for (const message of nonErrorMessages) {
96
+ this.log(message.message);
97
+ }
98
+ }
99
+ if (!out.succeeded || errorMessages.length > 0) {
100
+ this.exit(1);
101
+ }
48
102
  const goodbyeMessage = this.goodbyeMessage();
49
103
  if (goodbyeMessage) {
50
104
  this.log(goodbyeMessage);
@@ -62,43 +116,77 @@ class BaseCommand extends command_1.Command {
62
116
  // ----------------------------------------------------------------
63
117
  // Confirmation
64
118
  // ----------------------------------------------------------------
119
+ monorepoPaths(options) {
120
+ try {
121
+ const monorepoConfig = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(process.cwd(), 'flarum-monorepo.json'));
122
+ const contents = JSON.parse(monorepoConfig.toString());
123
+ return [
124
+ ...(options.includeCore ? [contents.packages.core] : []),
125
+ ...(options.includeExtensions ? contents.packages.extensions : []),
126
+ ...(options.includePhpPackages ? contents.packages.composerPackages : []),
127
+ ...(options.includeJSPackages ? contents.packages.npmPackages : []),
128
+ ];
129
+ }
130
+ catch (_a) {
131
+ this.error('Could not run monorepo command: `flarum-monorepo.json` file is missing or invalid.');
132
+ }
133
+ }
134
+ isFlarumCore(path) {
135
+ try {
136
+ const composerJsonPath = (0, node_path_1.resolve)(path, 'composer.json');
137
+ const val = JSON.parse((0, node_fs_1.readFileSync)(composerJsonPath, 'utf8'));
138
+ return val.name === 'flarum/core';
139
+ }
140
+ catch (_a) {
141
+ return false;
142
+ }
143
+ }
65
144
  async getFlarumExtensionRoot(currDir) {
66
- let currPath = path_1.resolve(currDir);
145
+ let currPath = (0, node_path_1.resolve)(currDir);
67
146
  while (currPath !== '/') {
68
- if (fs_1.existsSync(path_1.resolve(currPath, 'composer.json')) && fs_1.existsSync(path_1.resolve(currPath, 'extend.php'))) {
69
- return currPath;
147
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(currPath, 'flarum-monorepo.json'))) {
148
+ return { path: currPath, type: LocationType.FLARUM_MONOREPO };
149
+ }
150
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(currPath, 'composer.json')) && (0, node_fs_1.existsSync)((0, node_path_1.resolve)(currPath, 'extend.php'))) {
151
+ return { path: currPath, type: LocationType.FLARUM_EXTENSION };
152
+ }
153
+ if (this.isFlarumCore(currPath)) {
154
+ return { path: currPath, type: LocationType.FLARUM_CORE };
70
155
  }
71
- currPath = path_1.resolve(currPath, '..');
156
+ currPath = (0, node_path_1.resolve)(currPath, '..');
72
157
  }
73
- this.error(`${path_1.resolve(currDir)} is not located in a valid Flarum extension! Flarum extensions must contain (at a minimum) 'extend.php' and 'composer.json' files.`);
158
+ this.error(`${(0, node_path_1.resolve)(currDir)} is not located in a valid Flarum package!
159
+ - Flarum extensions must contain (at a minimum) 'extend.php' and 'composer.json' files.
160
+ - Flarum core must contain a 'composer.json' file with the name 'flarum/core'.
161
+ - Flarum monorepos must have a valid 'flarum-monorepo.json' file`);
74
162
  }
75
163
  async confirmExtDir(extRoot) {
76
- const response = await prompts_1.default([
164
+ const response = await (0, prompts_1.default)([
77
165
  {
78
166
  name: 'verify',
79
167
  type: 'confirm',
80
- message: `Work in Flarum extension located at ${path_1.resolve(extRoot)}?`,
168
+ message: `Work in Flarum package located at ${(0, node_path_1.resolve)(extRoot)}?`,
81
169
  initial: true,
82
170
  },
83
- ], param_provider_1.PROMPTS_OPTIONS);
171
+ ], io_1.PROMPTS_OPTIONS);
84
172
  if (!response.verify)
85
173
  this.exit();
86
174
  }
87
175
  async ensureComposerInstallRan(extRoot) {
88
- if (fs_1.existsSync(path_1.resolve(extRoot, 'vendor/flarum/core/composer.json')))
176
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(extRoot, 'vendor/flarum/core/composer.json')))
89
177
  return;
90
178
  this.log("This command requires `composer install` to have been ran in your extension's root directory.");
91
- const response = await prompts_1.default([
179
+ const response = await (0, prompts_1.default)([
92
180
  {
93
181
  name: 'composer',
94
182
  type: 'confirm',
95
183
  message: 'Would you like me to take care of that for you?',
96
184
  initial: true,
97
185
  },
98
- ], param_provider_1.PROMPTS_OPTIONS);
186
+ ], io_1.PROMPTS_OPTIONS);
99
187
  if (response.composer) {
100
188
  cli_ux_1.default.action.start('Installing composer packages');
101
- child_process_1.execSync('composer install', { cwd: extRoot });
189
+ (0, node_child_process_1.execSync)('composer install', { cwd: extRoot });
102
190
  cli_ux_1.default.action.stop();
103
191
  }
104
192
  else {
@@ -111,29 +199,31 @@ class BaseCommand extends command_1.Command {
111
199
  * If user says no, will exit and not return anything.
112
200
  */
113
201
  async confirmOverrideFiles(dir, pattern, confirmationMessage) {
114
- const files = await globby_1.default(path_1.resolve(dir, pattern));
202
+ const paths = Array.isArray(pattern) ? pattern : [pattern];
203
+ const files = await (0, globby_1.default)(paths.map(p => (0, node_path_1.resolve)(dir, p)));
115
204
  const empty = files.length === 0 || (files.length === 1 && files[0] === '.git');
116
205
  if (empty)
117
206
  return false;
118
- const response = await prompts_1.default([
207
+ const response = await (0, prompts_1.default)([
119
208
  {
120
209
  name: 'overwrite',
121
210
  type: 'confirm',
122
211
  message: confirmationMessage,
123
212
  },
124
- ], param_provider_1.PROMPTS_OPTIONS);
213
+ ], io_1.PROMPTS_OPTIONS);
125
214
  if (response.overwrite === false)
126
215
  this.exit();
127
216
  return true;
128
217
  }
129
218
  async deleteFiles(dir, pattern) {
130
- const pathsToDelete = await globby_1.default(path_1.resolve(dir, pattern));
131
- pathsToDelete.forEach(fs_1.unlinkSync);
219
+ const pathsToDelete = await (0, globby_1.default)((0, node_path_1.resolve)(dir, pattern));
220
+ pathsToDelete.forEach(node_fs_1.unlinkSync);
132
221
  }
133
222
  }
134
223
  exports.default = BaseCommand;
135
224
  BaseCommand.flags = {
136
- help: command_1.flags.help({ char: 'h' }),
225
+ defaults: core_1.Flags.boolean({ char: 'd', description: 'Assume default responses to prompts where possible.', default: false }),
226
+ help: core_1.Flags.help({ char: 'h' }),
137
227
  };
138
228
  BaseCommand.args = [
139
229
  {