@flarum/cli 2.0.0-beta.12 → 2.0.0-beta.15

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 (123) hide show
  1. package/README.md +176 -43
  2. package/bin/run +2 -1
  3. package/bin/splitsh-lite-darwin +0 -0
  4. package/bin/splitsh-lite-linux +0 -0
  5. package/boilerplate/skeleton/extension/.gitattributes +1 -0
  6. package/boilerplate/skeleton/extension/.github/workflows/backend.yml +1 -1
  7. package/boilerplate/skeleton/extension/.github/workflows/frontend.yml +3 -1
  8. package/boilerplate/skeleton/extension/LICENSE.md +1 -1
  9. package/boilerplate/skeleton/extension/composer.json +4 -2
  10. package/boilerplate/skeleton/extension/js/package.json +4 -1
  11. package/boilerplate/skeleton/extension/tests/phpunit.integration.xml +1 -0
  12. package/lib/base-command.d.ts +3 -1
  13. package/lib/base-command.js +44 -31
  14. package/lib/boilersmith/io.d.ts +28 -8
  15. package/lib/boilersmith/io.js +4 -2
  16. package/lib/boilersmith/paths.d.ts +2 -2
  17. package/lib/boilersmith/paths.js +7 -7
  18. package/lib/boilersmith/scaffolding/audit-step-factory.js +11 -11
  19. package/lib/boilersmith/scaffolding/infra-step-factory.js +2 -2
  20. package/lib/boilersmith/scaffolding/init-step-factory.js +5 -5
  21. package/lib/boilersmith/scaffolding/module.d.ts +19 -8
  22. package/lib/boilersmith/scaffolding/module.js +32 -19
  23. package/lib/boilersmith/scaffolding/scaffolder.d.ts +4 -1
  24. package/lib/boilersmith/scaffolding/scaffolder.js +32 -32
  25. package/lib/boilersmith/scaffolding/template-param.d.ts +1 -1
  26. package/lib/boilersmith/scaffolding/template-param.js +2 -2
  27. package/lib/boilersmith/step-manager.d.ts +0 -1
  28. package/lib/boilersmith/step-manager.js +10 -20
  29. package/lib/boilersmith/steps/stub-base.js +3 -3
  30. package/lib/boilersmith/utils/clone-and-fill.js +1 -1
  31. package/lib/boilersmith/utils/commit-async.d.ts +2 -0
  32. package/lib/boilersmith/utils/commit-async.js +15 -0
  33. package/lib/boilersmith/utils/read-tpl.js +2 -2
  34. package/lib/commands/audit/infra.d.ts +1 -1
  35. package/lib/commands/audit/infra.js +30 -8
  36. package/lib/commands/infra.d.ts +2 -2
  37. package/lib/commands/infra.js +18 -12
  38. package/lib/commands/init.d.ts +1 -1
  39. package/lib/commands/init.js +4 -2
  40. package/lib/commands/make/backend/api-controller.js +1 -2
  41. package/lib/commands/make/backend/api-serializer-attributes.js +1 -2
  42. package/lib/commands/make/backend/command.js +1 -2
  43. package/lib/commands/make/backend/event-listener.js +1 -2
  44. package/lib/commands/make/backend/handler.js +2 -5
  45. package/lib/commands/make/backend/integration-test.js +2 -4
  46. package/lib/commands/make/backend/migration.js +1 -2
  47. package/lib/commands/make/backend/model.js +1 -2
  48. package/lib/commands/make/backend/policy.js +1 -2
  49. package/lib/commands/make/backend/route.js +1 -2
  50. package/lib/commands/make/backend/service-provider.js +1 -2
  51. package/lib/commands/make/frontend/model.js +2 -5
  52. package/lib/commands/monorepo/create.d.ts +15 -0
  53. package/lib/commands/monorepo/create.js +20 -0
  54. package/lib/commands/monorepo/split.d.ts +15 -0
  55. package/lib/commands/monorepo/split.js +19 -0
  56. package/lib/commands/update/js-imports.js +1 -2
  57. package/lib/help.js +1 -1
  58. package/lib/providers/php-provider.js +2 -2
  59. package/lib/steps/gen-ext-scaffolder.d.ts +1 -1
  60. package/lib/steps/gen-ext-scaffolder.js +109 -53
  61. package/lib/steps/js/base.js +2 -4
  62. package/lib/steps/js/model.js +4 -4
  63. package/lib/steps/misc/composer.js +2 -2
  64. package/lib/steps/misc/git.d.ts +1 -1
  65. package/lib/steps/misc/git.js +2 -2
  66. package/lib/steps/misc/npm.d.ts +11 -0
  67. package/lib/steps/misc/npm.js +19 -0
  68. package/lib/steps/misc/yarn.js +2 -2
  69. package/lib/steps/monorepo/create.d.ts +17 -0
  70. package/lib/steps/monorepo/create.js +186 -0
  71. package/lib/steps/monorepo/split.d.ts +12 -0
  72. package/lib/steps/monorepo/split.js +75 -0
  73. package/lib/steps/stubs/backend/api-controller.d.ts +1 -1
  74. package/lib/steps/stubs/backend/api-controller.js +3 -0
  75. package/lib/steps/stubs/backend/api-serializer.d.ts +1 -1
  76. package/lib/steps/stubs/backend/api-serializer.js +3 -0
  77. package/lib/steps/stubs/backend/command.d.ts +0 -5
  78. package/lib/steps/stubs/backend/command.js +1 -0
  79. package/lib/steps/stubs/backend/event-listener.d.ts +1 -1
  80. package/lib/steps/stubs/backend/event-listener.js +2 -0
  81. package/lib/steps/stubs/backend/handler-command.d.ts +1 -1
  82. package/lib/steps/stubs/backend/handler-command.js +1 -0
  83. package/lib/steps/stubs/backend/handler.d.ts +1 -1
  84. package/lib/steps/stubs/backend/handler.js +4 -0
  85. package/lib/steps/stubs/backend/integration-test.d.ts +1 -1
  86. package/lib/steps/stubs/backend/integration-test.js +2 -0
  87. package/lib/steps/stubs/backend/job.d.ts +1 -1
  88. package/lib/steps/stubs/backend/job.js +1 -0
  89. package/lib/steps/stubs/backend/migration.js +6 -3
  90. package/lib/steps/stubs/backend/model.d.ts +1 -1
  91. package/lib/steps/stubs/backend/model.js +1 -0
  92. package/lib/steps/stubs/backend/policy.d.ts +1 -1
  93. package/lib/steps/stubs/backend/policy.js +2 -0
  94. package/lib/steps/stubs/backend/repository.d.ts +1 -1
  95. package/lib/steps/stubs/backend/repository.js +2 -0
  96. package/lib/steps/stubs/backend/service-provider.d.ts +1 -1
  97. package/lib/steps/stubs/backend/service-provider.js +1 -0
  98. package/lib/steps/stubs/backend/validator.d.ts +1 -1
  99. package/lib/steps/stubs/backend/validator.js +1 -0
  100. package/lib/steps/stubs/flarum-base.js +1 -1
  101. package/lib/steps/stubs/frontend/component.d.ts +0 -5
  102. package/lib/steps/stubs/frontend/component.js +1 -0
  103. package/lib/steps/stubs/frontend/modal.d.ts +0 -5
  104. package/lib/steps/stubs/frontend/modal.js +1 -0
  105. package/lib/steps/stubs/frontend/model.d.ts +0 -5
  106. package/lib/steps/stubs/frontend/model.js +1 -0
  107. package/lib/steps/stubs/js-base.js +8 -5
  108. package/lib/steps/stubs/php-base.js +10 -8
  109. package/lib/steps/update/js-imports.js +8 -2
  110. package/lib/utils/composer.d.ts +1 -0
  111. package/lib/utils/migration.js +3 -1
  112. package/lib/utils/monorepo.d.ts +24 -0
  113. package/lib/utils/monorepo.js +24 -0
  114. package/lib/utils/validation.d.ts +2 -0
  115. package/lib/utils/validation.js +6 -0
  116. package/oclif.manifest.json +1 -1
  117. package/package.json +10 -5
  118. package/php-subsystem/composer.json +9 -9
  119. package/php-subsystem/composer.lock +64 -71
  120. package/php-subsystem/vendor/composer/installed.json +54 -61
  121. package/php-subsystem/vendor/nikic/php-parser/README.md +55 -59
  122. package/php-subsystem/vendor/nikic/php-parser/composer.json +39 -39
  123. package/php-subsystem/vendor/nikic/php-parser/grammar/README.md +17 -20
package/README.md CHANGED
@@ -11,33 +11,47 @@ A CLI for developing Flarum extensions</p>
11
11
  <img width=720 src="https://sycho9.github.io/flarum-cli.svg" alt="terminal_example">
12
12
  </p>
13
13
 
14
- <!-- toc -->
15
- * [Introduction](#introduction)
16
- * [Installation](#installation)
17
- * [Usage](#usage)
18
- * [Commands](#commands)
19
- <!-- tocstop -->
14
+ - [Introduction](#introduction)
15
+ - [Installation](#installation)
16
+ - [Updating](#updating)
17
+ - [Usage](#usage)
18
+ - [Commands](#commands)
20
19
 
21
- # Introduction
22
- One of our core values is ***Framework First***, Flarum is as much a framework for extension development as it is a forum platform.
20
+ ## Introduction
21
+
22
+ One of our core values is **_Framework First_**, Flarum is as much a framework for extension development as it is a forum platform.
23
23
 
24
24
  This tool was built to simplify the development of Flarum extensions by automating some repetitive and menial tasks. It allows to generate boilerplate skeleton for a new extension, common backend classes and frontend components, extenders, as well as other maintenance tasks.
25
25
 
26
- # Installation
26
+ ## Installation
27
+
27
28
  <!-- installation -->
29
+
28
30
  ```sh-session
29
31
  $ npm install -g @flarum/cli
30
32
  ```
33
+
31
34
  <!-- installationstop -->
32
35
 
33
- # Usage
36
+ ## Updating
37
+
38
+ <!-- updating -->
39
+
40
+ ```sh-session
41
+ $ npm update -g @flarum/cli
42
+ ```
43
+
44
+ <!-- updatingstop -->
45
+
46
+ ## Usage
47
+
34
48
  <!-- usage -->
35
49
  ```sh-session
36
50
  $ npm install -g @flarum/cli
37
51
  $ flarum-cli COMMAND
38
52
  running command...
39
53
  $ flarum-cli (-v|--version|version)
40
- @flarum/cli/2.0.0-beta.12 linux-x64 node-v16.13.0
54
+ @flarum/cli/2.0.0-beta.15 linux-x64 node-v16.14.0
41
55
  $ flarum-cli --help [COMMAND]
42
56
  USAGE
43
57
  $ flarum-cli COMMAND
@@ -59,29 +73,117 @@ or
59
73
  flarum-cli --help
60
74
  ```
61
75
 
62
- # Commands
63
- * `flarum-cli help [COMMAND]`
64
- * `flarum-cli infra backend-testing [PATH]`
65
- * `flarum-cli init [PATH]`
66
- * `flarum-cli make backend api-controller [PATH]`
67
- * `flarum-cli make backend api-serializer [PATH]`
68
- * `flarum-cli make backend api-serializer-attributes [PATH]`
69
- * `flarum-cli make backend command [PATH]`
70
- * `flarum-cli make backend event-listener [PATH]`
71
- * `flarum-cli make backend handler [PATH]`
72
- * `flarum-cli make backend integration-test [PATH]`
73
- * `flarum-cli make backend job [PATH]`
74
- * `flarum-cli make backend migration [PATH]`
75
- * `flarum-cli make backend model [PATH]`
76
- * `flarum-cli make backend policy [PATH]`
77
- * `flarum-cli make backend repository [PATH]`
78
- * `flarum-cli make backend route [PATH]`
79
- * `flarum-cli make backend service-provider [PATH]`
80
- * `flarum-cli make backend validator [PATH]`
81
- * `flarum-cli make frontend component [PATH]`
82
- * `flarum-cli make frontend modal [PATH]`
83
- * `flarum-cli make frontend model [PATH]`
84
- * `flarum-cli update js-imports [PATH]`
76
+ ## Commands
77
+
78
+ The CLI has different types of commands for different tasks:
79
+
80
+ **Initialisation**
81
+
82
+ - `flarum-cli init [PATH]`: Generates a blank extension skeleton, including all recommended infrastructure.
83
+
84
+ **Infrastructure**: See the [infrastructure](#infrastructure-modules) section for more information.
85
+
86
+ - `flarum-cli infra [MODULE] [PATH]`: Adds (or updates) infrastructure for some part of extension infrastructure. You can see all available modules by running `fl-dev infra --help`.
87
+
88
+ **Audit**: These commands help you make sure your extension is up to date.
89
+
90
+ - `flarum-cli audit infra [--monorepo] [--fix]` Check that infrastructure files are up to date for all enabled modules.
91
+
92
+ **Backend Boilerplate Generation**: Generates different types of backend classes and/or extenders, ready to be used.
93
+
94
+ - `flarum-cli make backend api-controller [PATH]`
95
+ - `flarum-cli make backend api-serializer [PATH]`
96
+ - `flarum-cli make backend api-serializer-attributes [PATH]`
97
+ - `flarum-cli make backend command [PATH]`
98
+ - `flarum-cli make backend event-listener [PATH]`
99
+ - `flarum-cli make backend handler [PATH]`
100
+ - `flarum-cli make backend integration-test [PATH]`
101
+ - `flarum-cli make backend job [PATH]`
102
+ - `flarum-cli make backend migration [PATH]`
103
+ - `flarum-cli make backend model [PATH]`
104
+ - `flarum-cli make backend policy [PATH]`
105
+ - `flarum-cli make backend repository [PATH]`
106
+ - `flarum-cli make backend route [PATH]`
107
+ - `flarum-cli make backend service-provider [PATH]`
108
+ - `flarum-cli make backend validator [PATH]`
109
+
110
+ **Frontend Boilerplate Generation**: Generate frontend components/classes, ready to be used.
111
+
112
+ - `flarum-cli make frontend component [PATH]`
113
+ - `flarum-cli make frontend modal [PATH]`
114
+ - `flarum-cli make frontend model [PATH]`
115
+
116
+ **Code Updates**: These commands help update extensions for newer versions of Flarum.
117
+
118
+ - `flarum-cli update js-imports [PATH]`: Adds admin/forum/common namespaces to all JS imports from flarum core.
119
+
120
+ _And of course, you can always use the help command to see a list of all available commands with their descriptions:_
121
+
122
+ - `flarum-cli help [COMMAND]`
123
+
124
+ All commands can use a `--no-interaction` flag to proceed with default values for prompts when possible.
125
+
126
+ ## 🔥 The Most Powerful Commands
127
+
128
+ Of all the aforementioned commands, the two most powerful ones that will make a huge difference, are the extension initialisation command and the backend **model** generation command. The former obviously allows to kickstart the extension with the recommended skeleton from the Core Dev team, while the latter not only creates the backend model, it allows to create all the classes related to the model, from just its name:
129
+
130
+ - Table migration
131
+ - Policy
132
+ - API Serializer
133
+ - CRUD API Controllers
134
+ - CRUD Handlers
135
+ - Repository
136
+ - Validator
137
+ - Routes
138
+ - Related Extenders
139
+
140
+ [center]
141
+ ![terminal_example](https://sycho9.github.io/flarum-cli.svg)
142
+ ![example_project_with_model_command](https://lh3.googleusercontent.com/-fUnfqQ7rwyo/YQVwwm0sa0I/AAAAAAAAFfE/-o9B30M2gE8y6d3NWaVgBhYa8xEwqLuNwCLcBGAsYHQ/s16000/Screenshot%2Bfrom%2B2021-07-31%2B16-46-38.png)
143
+ [/center]
144
+
145
+ ## Infrastructure Modules
146
+
147
+ If you maintain more than just a few extensions, keeping the infrastructure up to date can be very tedious.
148
+ We heavily value developer experience, and make it a point to support automated testing, static analysis, formatting, and other tools
149
+ that help you work more happily and efficiently. However, all this means that there's a lot of config files to keep track of.
150
+
151
+ The idea behind Flarum CLI's infrastructure modules is simple: the config for some feature is associated with a "module".
152
+ For example, the "typescript" module includes:
153
+
154
+ - The `js/tsconfig.json` file
155
+ - Dependency reqs for `typescript`, `typescript-coverage-report`, and `flarum-tsconfig` in the `package.json` file.
156
+ - Script configuration to check type safety and type coverage in the `package.json` file.
157
+
158
+ So to enable the `typescript` module, all Flarum CLI has to do is update those files and JSON config keys to the latest version.
159
+
160
+ Please note that running `flarum-cli infra` or `flarum-cli audit infra --fix` will only add new files/keys and overwrite existing ones; it will not delete old files or config keys.
161
+
162
+ Also, we strongly recommend carefully looking over the changes made by these commands before committing them: they should work the vast majority of the time, but there could be some corner cases.
163
+
164
+ ### Excluding Files
165
+
166
+ Sometimes, you'll want to customize some of these configuration files, and prevent `flarum-cli infra [MODULE]` or `flarum-cli audit infra --fix` from overriding your changes. You can also exclude any files from these updates by adding their relative path to the "extra.flarum-cli.excludeScaffolding" key's array in your extension's `composer.json` file. For example, if you wanted to exclude your tsconfig file from any updates by the infra system, your `composer.json` should look as follows:
167
+
168
+ ```json
169
+ {
170
+ ...
171
+ "extra": {
172
+ "flarum-cli": {
173
+ "excludeScaffolding": [
174
+ "js/tsconfig.json"
175
+ ],
176
+ "excludeScaffoldingConfigKeys": {
177
+ "composer.json": [
178
+ "scripts.test:setup"
179
+ ],
180
+ ...
181
+ },
182
+ ...
183
+ }
184
+ ...
185
+ }
186
+ ```
85
187
 
86
188
  ## For Maintainers
87
189
 
@@ -99,7 +201,7 @@ The base command is implemented at [src/base-command.ts](https://github.com/flar
99
201
  3. Confirm we are in the right directory
100
202
  4. Confirm that files will be overwritten / clear files as needed
101
203
  5. Run a set of registered steps
102
- 6. Tell the user which steps ran
204
+ 6. Tell the user which steps ran, or display any errors
103
205
  7. Show a goodbye message
104
206
 
105
207
  Actual functionality is implemented at the step layer.
@@ -117,7 +219,7 @@ More documentation (and functionality!) will be added later.
117
219
 
118
220
  #### What are steps?
119
221
 
120
- Steps represent granular operations. Some are bigger and some are smaller, but they include:
222
+ Steps represent meaningful, granular operations. Some are bigger and some are smaller, but they include:
121
223
 
122
224
  - Initializing an extension from boilerplate
123
225
  - Updating some part of an extension from boilerplate (like adding backend testing)
@@ -132,9 +234,10 @@ If some subtask might be needed by multiple commands, that should be a step too.
132
234
  The actual logic of a step is implemented in the async `run` method. This method takes:
133
235
 
134
236
  - An in-memory filesystem object (through `mem-fs`)
135
- - A path provider, which is a class that can be used to get paths relative to the extension root, the working directory, the requested directory, and the CLI's boilerplate directory
136
- - A param provider, which can be used to prompt the user for parameters. We'll discuss this more soon.
137
- - A "php provider", which can be used to interact with the PHP subsystem to add extenders to extend.php.
237
+ - A paths object, which is a class that can be used to get paths relative to the extension root, the working directory, the requested directory (if the command was run with the `path` arg specified), and the monorepo directory (if in a subdirectory of a monorepo).
238
+ - An `io` instance, which can be used to prompt the user for input or display outputs / errors.
239
+ - An object of "providers", which represent additional functionality. For Flarum commands, these are:
240
+ - A "php provider", which can be used to interact with the PHP subsystem to add extenders to extend.php.
138
241
 
139
242
  Steps should modify the in-memory filesystem with their changes and return it.
140
243
 
@@ -159,7 +262,6 @@ Sharing parameters is done via the following process:
159
262
  - What the param is consumed at
160
263
  - If the param value is falsy, should the consumer step run at all? Useful for variable dependencies.
161
264
 
162
-
163
265
  For example:
164
266
 
165
267
  ```ts
@@ -195,7 +297,6 @@ For example:
195
297
  .run(new Paths({...}), new PromptsIO(), {php: new PhpProvider(...)});
196
298
  ```
197
299
 
198
-
199
300
  #### Step Composability and Atomic Groups
200
301
 
201
302
  As noted above, steps should work by modifying and returning an in-memory filesystem.
@@ -214,8 +315,6 @@ Steps for generating extenders should use `src/steps/extenders/base`, where all
214
315
 
215
316
  Steps for generating templates from php stubs should use `src/steps/stubs/php-base`, where they just need to describe what stub file they use, which params they need, and a recommended namespace where the generated file should be placed.
216
317
 
217
- Steps for `infra` operations (copying over some portion of the default skeleton, for operations like adding/updating backend testing or TypeScript config) shouls use `src/steps/infra/base`, where all they need to indicate is a list of files from the boilerplate they copy over, and an object describing which JSON config keys should be copied from the boilerplate to the extension for various JSON files.
218
-
219
318
  ### Testing
220
319
 
221
320
  Most of this architecture was driven by TDD and BDD development, allowing for a highly decoupled system.
@@ -225,3 +324,37 @@ Any additions of steps, modifications of providers, or changes of functionality
225
324
  The 3 base step types actually provide a simple interface to generate test cases. See the relevant test files for more info.
226
325
 
227
326
  Since commands directly affect the filesystem, unit tests for them aren't really possible. It would also be quite complex to unit test all commands in addition to all steps. For this reason, commands should be manually tested, but unit tests are not currently required.
327
+
328
+ ### Monorepo Support
329
+
330
+ Flarum CLI was designed with monorepos in mind.
331
+ When registering a step, you can provide it an array of subdirectories to run it in.
332
+ For each of these subdirectories, an instance of the step will run with the `paths` object returning the subdirectory as `package()`, and the original root directory as `monorepo()`.
333
+
334
+ A monorepo should have a `flarum-monorepo.json` file in the root directory with the following (optional) keys:
335
+
336
+ - `packages.core`: a path to Flarum Core, if present.
337
+ - `packages.extensions`: an array of paths to Flarum extensions.
338
+ - `packages.composer`: an array of paths to non-extension PHP Composer packages published on Packagist.
339
+ - `packages.npm`: an array of paths to non-extension JS/TS packages published on NPM.
340
+
341
+ ### Scaffolding Generation
342
+
343
+ One powerful use-case of Flarum CLI is creating new extensions, and keeping infrastructure in sync for existing extensions.
344
+ For example, if managing 100 extensions, making sure the prettier config is consistent for all of them can be very tedious. Additionally, it can be annoying to have to add TypeScript config to every extension, and it's easy to make mistakes.
345
+
346
+ For this purpose, Flarum CLI's `Scaffolder` system formalizes the concepts of initializing and updating extension infrastructure.
347
+
348
+ At the core level, there's a boilerplate directory (`boilerplate/skeleton/extension`) that contains the scaffolding for a new extension.
349
+
350
+ The scaffolder receives a set of modules, which represent some aspect of infrastructure (e.g. JS, TypeScript, Backend Testing, etc).
351
+ Modules can be updatable (e.g. TypeScript) or not (e.g. the core setup of an `extend.php` file).
352
+ They can also be togglable (e.g. JS), or not, in which case they are always on.
353
+
354
+ Modules own files in the scaffolding directory, as well as keys in JSON config files. Every file and key must belong to at least one module. If any keys in a JSON config file belong to a module, all keys must belong to a module; if no keys are owned, the config file is treated like any other file.
355
+
356
+ Modules also have template params, which are used as variables in the scaffolding.
357
+
358
+ There's a lot more features and guaruntees than that, see the `Module` interface for more information.
359
+
360
+ The main benefit to this system is that given this scaffolding / module setup, it is possible to generate steps to initialize a new extension, update/add a module to an existing extension, or audit an extension for any outdated infrastructure. This is how the `init`, `infra`, and `audit infra` commands are implemented.
package/bin/run CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
+ const { resolve } = require('path');
2
3
 
3
- require('module-alias').addAlias('boilersmith', `${__dirname}/../lib/boilersmith`);
4
+ require('module-alias').addAlias('boilersmith', resolve(__dirname, '..', 'lib', 'boilersmith'));
4
5
 
5
6
  const oclif = require('@oclif/core');
6
7
 
Binary file
Binary file
@@ -14,5 +14,6 @@ js/dist/* -diff
14
14
  js/dist/* linguist-generated
15
15
  js/dist-typings/* linguist-generated
16
16
  js/yarn.lock -diff
17
+ js/package-lock.json -diff
17
18
 
18
19
  * text=auto eol=lf
@@ -12,4 +12,4 @@ jobs:
12
12
  with:
13
13
  enable_backend_testing: <%= modules.backendTesting %>
14
14
 
15
- backend_directory: <%= params.backendDirectory %>
15
+ backend_directory: <%= params.backendDirectory %>
@@ -15,6 +15,8 @@ jobs:
15
15
  enable_typescript: <%= modules.typescript %>
16
16
 
17
17
  frontend_directory: <%= params.frontendDirectory %>
18
+ backend_directory: <%= params.backendDirectory %>
19
+ js_package_manager: <%= params.jsPackageManager %>
18
20
  main_git_branch: <%= params.mainGitBranch %>
19
21
  secrets:
20
- bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
22
+ bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
@@ -1 +1 @@
1
- <%= params.licenseText %>
1
+ <%- params.licenseText %>
@@ -7,7 +7,7 @@
7
7
  "type": "flarum-extension",
8
8
  "license": "<%= params.licenseType %>",
9
9
  "require": {
10
- "flarum/core": "^1.0.0"
10
+ "flarum/core": "^1.2.0"
11
11
  },
12
12
  "require-dev": {
13
13
  "flarum/testing": "^1.0.0"
@@ -56,5 +56,7 @@
56
56
  "test:unit": "Runs all unit tests.",
57
57
  "test:integration": "Runs all integration tests.",
58
58
  "test:setup": "Sets up a database for use with integration tests. Execute this only once."
59
- }
59
+ },
60
+ "minimum-stability": "dev",
61
+ "prefer-stable": true
60
62
  }
@@ -17,9 +17,12 @@
17
17
  "scripts": {
18
18
  "dev": "webpack --mode development --watch",
19
19
  "build": "webpack --mode production",
20
- "analyze": "cross-env ANALYZER=true yarn build",
20
+ "analyze": "cross-env ANALYZER=true <%= params.jsPackageManager %> run build",
21
21
  "format": "prettier --write src",
22
22
  "format-check": "prettier --check src",
23
+ "clean-typings": "npx rimraf dist-typings && mkdir dist-typings",
24
+ "build-typings": "<%= params.jsPackageManager %> run clean-typings && [ -e src/@types ] && cp -r src/@types dist-typings/@types && tsc && <%= params.jsPackageManager %> run post-build-typings",
25
+ "post-build-typings": "find dist-typings -type f -name '*.d.ts' -print0 | xargs -0 sed -i 's,../src/@types,@types,g'",
23
26
  "check-typings": "tsc --noEmit --emitDeclarationOnly false",
24
27
  "check-typings-coverage": "typescript-coverage-report"
25
28
  }
@@ -19,6 +19,7 @@
19
19
  <testsuites>
20
20
  <testsuite name="Flarum Integration Tests">
21
21
  <directory suffix="Test.php">./integration</directory>
22
+ <exclude>./integration/tmp</exclude>
22
23
  </testsuite>
23
24
  </testsuites>
24
25
  </phpunit>
@@ -23,7 +23,7 @@ export default abstract class BaseCommand extends Command {
23
23
  protected welcomeMessage(): string;
24
24
  protected goodbyeMessage(): string;
25
25
  protected additionalPreRunChecks(_extRoot: string): Promise<void>;
26
- protected abstract steps(stepManager: StepManager<FlarumProviders>): StepManager<FlarumProviders>;
26
+ protected abstract steps(stepManager: StepManager<FlarumProviders>, extRoot: string): StepManager<FlarumProviders>;
27
27
  protected genIO(): IO;
28
28
  protected monorepoPaths(options: {
29
29
  includeCore: boolean;
@@ -31,7 +31,9 @@ export default abstract class BaseCommand extends Command {
31
31
  includePhpPackages: boolean;
32
32
  includeJSPackages: boolean;
33
33
  }): string[];
34
+ protected isFlarumMonorepo(path: string): boolean;
34
35
  protected isFlarumCore(path: string): boolean;
36
+ protected jsPackageManager(currDir: string): 'yarn' | 'npm' | null;
35
37
  protected getFlarumExtensionRoot(currDir: string): Promise<{
36
38
  path: string;
37
39
  type: LocationType;
@@ -4,16 +4,18 @@ exports.LocationType = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const core_1 = require("@oclif/core");
6
6
  const cli_ux_1 = (0, tslib_1.__importDefault)(require("cli-ux"));
7
- const node_path_1 = require("node:path");
7
+ const path_1 = require("path");
8
8
  const globby_1 = (0, tslib_1.__importDefault)(require("globby"));
9
- const node_child_process_1 = require("node:child_process");
10
- const node_fs_1 = require("node:fs");
9
+ const child_process_1 = require("child_process");
10
+ const fs_1 = require("fs");
11
11
  const io_1 = require("boilersmith/io");
12
12
  const step_manager_1 = require("boilersmith/step-manager");
13
13
  const paths_1 = require("boilersmith/paths");
14
14
  const php_provider_1 = require("./providers/php-provider");
15
15
  const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
16
16
  const errors_1 = require("@oclif/errors");
17
+ const monorepo_1 = require("./utils/monorepo");
18
+ const mem_fs_1 = require("mem-fs");
17
19
  var LocationType;
18
20
  (function (LocationType) {
19
21
  LocationType[LocationType["FLARUM_EXTENSION"] = 0] = "FLARUM_EXTENSION";
@@ -23,7 +25,7 @@ var LocationType;
23
25
  class BaseCommand extends core_1.Command {
24
26
  constructor() {
25
27
  super(...arguments);
26
- this.STUB_PATH = (0, node_path_1.resolve)(__dirname, '../boilerplate/stubs/');
28
+ this.STUB_PATH = (0, path_1.resolve)(__dirname, '../boilerplate/stubs/');
27
29
  this.dry = false;
28
30
  this.requireExistingExtension = true;
29
31
  }
@@ -51,10 +53,9 @@ class BaseCommand extends core_1.Command {
51
53
  requestedDir: path,
52
54
  package: extRoot,
53
55
  });
54
- const phpProvider = new php_provider_1.PhpSubsystemProvider((0, node_path_1.resolve)(__dirname, '../php-subsystem/index.php'));
55
- const out = await this.steps(new step_manager_1.StepManager())
56
- .run(paths, this.genIO(), { php: phpProvider }, this.dry);
57
- const errorMessages = out.messages.filter(m => m.type === 'error');
56
+ const phpProvider = new php_provider_1.PhpSubsystemProvider((0, path_1.resolve)(__dirname, '../php-subsystem/index.php'));
57
+ const out = await this.steps(new step_manager_1.StepManager(), extRoot).run(paths, this.genIO(), { php: phpProvider }, this.dry);
58
+ const errorMessages = out.messages.filter((m) => m.type === 'error');
58
59
  this.log('\n\n');
59
60
  if (out.succeeded && errorMessages.length === 0) {
60
61
  this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.green('Success! The following steps were completed:'))));
@@ -66,7 +67,7 @@ class BaseCommand extends core_1.Command {
66
67
  }
67
68
  this.log(chalk_1.default.bold(chalk_1.default.yellow('The steps that completed were:')));
68
69
  }
69
- else if (out.error === 'EEXIT: 0') {
70
+ else if (out.error.startsWith('EEXIT:')) {
70
71
  this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.red('Exiting.'))));
71
72
  if (out.stepsRan.length > 0) {
72
73
  this.log(chalk_1.default.bold(chalk_1.default.yellow('Before the exit, the following steps were completed:')));
@@ -86,7 +87,7 @@ class BaseCommand extends core_1.Command {
86
87
  for (const stepName of out.stepsRan)
87
88
  this.log(`- ${chalk_1.default.dim(stepName)}`);
88
89
  this.log('');
89
- const nonErrorMessages = out.messages.filter(m => m.type !== 'error');
90
+ const nonErrorMessages = out.messages.filter((m) => m.type !== 'error');
90
91
  if (nonErrorMessages.length > 0) {
91
92
  this.log('');
92
93
  this.log('The following messages were generated during execution:');
@@ -118,45 +119,53 @@ class BaseCommand extends core_1.Command {
118
119
  return new io_1.PromptsIO({}, [], this.flags['no-interaction'], errors_1.exit);
119
120
  }
120
121
  monorepoPaths(options) {
122
+ var _a, _b;
121
123
  try {
122
- const monorepoConfig = (0, node_fs_1.readFileSync)((0, node_path_1.resolve)(process.cwd(), 'flarum-monorepo.json'));
123
- const contents = JSON.parse(monorepoConfig.toString());
124
+ const monorepoConfig = (0, monorepo_1.getMonorepoConf)((0, mem_fs_1.create)(), new paths_1.NodePaths({ package: process.cwd() }));
124
125
  return [
125
- ...(options.includeCore ? [contents.packages.core] : []),
126
- ...(options.includeExtensions ? contents.packages.extensions : []),
127
- ...(options.includePhpPackages ? contents.packages.composerPackages : []),
128
- ...(options.includeJSPackages ? contents.packages.npmPackages : []),
126
+ ...(options.includeCore && monorepoConfig.packages.core ? [(0, monorepo_1.corePath)(monorepoConfig.packages.core.name)] : []),
127
+ ...(options.includeExtensions ? monorepoConfig.packages.extensions : []).map((ext) => (0, monorepo_1.extensionPath)(ext.name)),
128
+ ...(options.includePhpPackages ? (_a = monorepoConfig.packages.composer) !== null && _a !== void 0 ? _a : [] : []).map((lib) => (0, monorepo_1.composerPath)(lib.name)),
129
+ ...(options.includeJSPackages ? (_b = monorepoConfig.packages.npm) !== null && _b !== void 0 ? _b : [] : []).map((lib) => (0, monorepo_1.npmPath)(lib.name)),
129
130
  ];
130
131
  }
131
- catch (_a) {
132
+ catch (_c) {
132
133
  this.error('Could not run monorepo command: `flarum-monorepo.json` file is missing or invalid.');
133
134
  }
134
135
  }
136
+ isFlarumMonorepo(path) {
137
+ return (0, fs_1.existsSync)((0, path_1.resolve)(path, 'flarum-monorepo.json'));
138
+ }
135
139
  isFlarumCore(path) {
136
140
  try {
137
- const composerJsonPath = (0, node_path_1.resolve)(path, 'composer.json');
138
- const val = JSON.parse((0, node_fs_1.readFileSync)(composerJsonPath, 'utf8'));
141
+ const composerJsonPath = (0, path_1.resolve)(path, 'composer.json');
142
+ const val = JSON.parse((0, fs_1.readFileSync)(composerJsonPath, 'utf8'));
139
143
  return val.name === 'flarum/core';
140
144
  }
141
145
  catch (_a) {
142
146
  return false;
143
147
  }
144
148
  }
149
+ jsPackageManager(currDir) {
150
+ if (!(0, fs_1.existsSync)((0, path_1.resolve)(currDir, 'js')))
151
+ return null;
152
+ return (0, fs_1.existsSync)((0, path_1.resolve)(currDir, 'js/yarn.lock')) ? 'yarn' : 'npm';
153
+ }
145
154
  async getFlarumExtensionRoot(currDir) {
146
- let currPath = (0, node_path_1.resolve)(currDir);
155
+ let currPath = (0, path_1.resolve)(currDir);
147
156
  while (currPath !== '/') {
148
- if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(currPath, 'flarum-monorepo.json'))) {
157
+ if ((0, fs_1.existsSync)((0, path_1.resolve)(currPath, 'flarum-monorepo.json'))) {
149
158
  return { path: currPath, type: LocationType.FLARUM_MONOREPO };
150
159
  }
151
- 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'))) {
160
+ if ((0, fs_1.existsSync)((0, path_1.resolve)(currPath, 'composer.json')) && (0, fs_1.existsSync)((0, path_1.resolve)(currPath, 'extend.php'))) {
152
161
  return { path: currPath, type: LocationType.FLARUM_EXTENSION };
153
162
  }
154
163
  if (this.isFlarumCore(currPath)) {
155
164
  return { path: currPath, type: LocationType.FLARUM_CORE };
156
165
  }
157
- currPath = (0, node_path_1.resolve)(currPath, '..');
166
+ currPath = (0, path_1.resolve)(currPath, '..');
158
167
  }
159
- this.error(`${(0, node_path_1.resolve)(currDir)} is not located in a valid Flarum package!
168
+ this.error(`${(0, path_1.resolve)(currDir)} is not located in a valid Flarum package!
160
169
  - Flarum extensions must contain (at a minimum) 'extend.php' and 'composer.json' files.
161
170
  - Flarum core must contain a 'composer.json' file with the name 'flarum/core'.
162
171
  - Flarum monorepos must have a valid 'flarum-monorepo.json' file`);
@@ -165,14 +174,14 @@ class BaseCommand extends core_1.Command {
165
174
  const verify = await this.genIO().getParam({
166
175
  name: 'verify',
167
176
  type: 'confirm',
168
- message: `Work in Flarum package located at ${(0, node_path_1.resolve)(extRoot)}?`,
177
+ message: `Work in Flarum package located at ${(0, path_1.resolve)(extRoot)}?`,
169
178
  initial: true,
170
179
  });
171
180
  if (!verify)
172
181
  this.exit();
173
182
  }
174
183
  async ensureComposerInstallRan(extRoot) {
175
- if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(extRoot, 'vendor/flarum/core/composer.json')))
184
+ if ((0, fs_1.existsSync)((0, path_1.resolve)(extRoot, 'vendor/flarum/core/composer.json')))
176
185
  return;
177
186
  this.log("This command requires `composer install` to have been ran in your extension's root directory.");
178
187
  const composer = await this.genIO().getParam({
@@ -183,7 +192,7 @@ class BaseCommand extends core_1.Command {
183
192
  });
184
193
  if (composer) {
185
194
  cli_ux_1.default.action.start('Installing composer packages');
186
- (0, node_child_process_1.execSync)('composer install', { cwd: extRoot });
195
+ (0, child_process_1.execSync)('composer install', { cwd: extRoot });
187
196
  cli_ux_1.default.action.stop();
188
197
  }
189
198
  else {
@@ -197,7 +206,7 @@ class BaseCommand extends core_1.Command {
197
206
  */
198
207
  async confirmOverrideFiles(dir, pattern, confirmationMessage) {
199
208
  const paths = Array.isArray(pattern) ? pattern : [pattern];
200
- const files = await (0, globby_1.default)(paths.map(p => (0, node_path_1.resolve)(dir, p)));
209
+ const files = await (0, globby_1.default)(paths.map((p) => (0, path_1.resolve)(dir, p)));
201
210
  const empty = files.length === 0 || (files.length === 1 && files[0] === '.git');
202
211
  if (empty)
203
212
  return false;
@@ -212,13 +221,17 @@ class BaseCommand extends core_1.Command {
212
221
  return true;
213
222
  }
214
223
  async deleteFiles(dir, pattern) {
215
- const pathsToDelete = await (0, globby_1.default)((0, node_path_1.resolve)(dir, pattern));
216
- pathsToDelete.forEach(node_fs_1.unlinkSync);
224
+ const pathsToDelete = await (0, globby_1.default)((0, path_1.resolve)(dir, pattern));
225
+ pathsToDelete.forEach(fs_1.unlinkSync);
217
226
  }
218
227
  }
219
228
  exports.default = BaseCommand;
220
229
  BaseCommand.flags = {
221
- 'no-interaction': core_1.Flags.boolean({ char: 'n', description: 'Do not ask any interactive questions, assume defaults. When impossible, error.', default: false }),
230
+ 'no-interaction': core_1.Flags.boolean({
231
+ char: 'n',
232
+ description: 'Do not ask any interactive questions, assume defaults. When impossible, error.',
233
+ default: false,
234
+ }),
222
235
  help: core_1.Flags.help({ char: 'h' }),
223
236
  };
224
237
  BaseCommand.args = [
@@ -1,6 +1,11 @@
1
- import { PromptObject } from 'prompts';
1
+ import { PromptObject, PromptType } from 'prompts';
2
+ declare type BooleanPromptType = PromptType & ('confirm' | 'toggle');
3
+ declare type StringPromptType = PromptType & ('text' | 'password' | 'invisible' | 'autocomplete');
4
+ declare type DatePromptType = PromptType & 'date';
5
+ declare type ListPromptType = PromptType & 'list';
2
6
  export declare type ParamDef<N extends string = string> = Omit<PromptObject<N>, 'name'> & {
3
7
  name: N;
8
+ message: string;
4
9
  };
5
10
  export declare type Message = {
6
11
  type: 'info' | 'warning' | 'error';
@@ -11,7 +16,19 @@ export interface IO {
11
16
  /**
12
17
  * Prompt the user for some input data.
13
18
  */
14
- getParam<T>(param: ParamDef): Promise<T>;
19
+ getParam(param: ParamDef & {
20
+ type: BooleanPromptType;
21
+ }, noCache?: boolean): Promise<boolean>;
22
+ getParam(param: ParamDef & {
23
+ type: StringPromptType;
24
+ }, noCache?: boolean): Promise<string>;
25
+ getParam(param: ParamDef & {
26
+ type: DatePromptType;
27
+ }, noCache?: boolean): Promise<Date>;
28
+ getParam(param: ParamDef & {
29
+ type: ListPromptType;
30
+ }, noCache?: boolean): Promise<string[]>;
31
+ getParam<T>(param: ParamDef, noCache?: boolean): Promise<T>;
15
32
  /**
16
33
  * Check if some data has already been prompted for.
17
34
  */
@@ -32,13 +49,16 @@ export interface IO {
32
49
  declare type OnCancel = () => void;
33
50
  export declare class PromptsIO implements IO {
34
51
  supportsAnsiColor: boolean;
35
- private cache;
36
- private messages;
37
- private noInteraction;
38
- private onCancel?;
39
- private prev?;
52
+ protected cache: Map<string, unknown>;
53
+ protected messages: Message[];
54
+ protected noInteraction: boolean;
55
+ protected onCancel?: OnCancel;
56
+ protected prev?: {
57
+ val: any;
58
+ prompt: ParamDef;
59
+ };
40
60
  constructor(initial?: Record<string, unknown>, messages?: Message[], noInteraction?: boolean, onCancel?: OnCancel);
41
- getParam<T>(paramDef: ParamDef): Promise<T>;
61
+ getParam<T>(paramDef: ParamDef, noCache?: boolean): Promise<T>;
42
62
  hasCached(name: string): boolean;
43
63
  /**
44
64
  * @internal