@flarum/cli 2.0.0-beta.11 → 2.0.0-beta.14
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 +176 -43
- package/boilerplate/skeleton/extension/.gitattributes +1 -0
- package/boilerplate/skeleton/extension/.github/workflows/backend.yml +1 -1
- package/boilerplate/skeleton/extension/.github/workflows/frontend.yml +3 -1
- package/boilerplate/skeleton/extension/LICENSE.md +1 -1
- package/boilerplate/skeleton/extension/composer.json +4 -2
- package/boilerplate/skeleton/extension/extend.php +2 -2
- package/boilerplate/skeleton/extension/js/package.json +4 -1
- package/boilerplate/skeleton/extension/tests/phpunit.integration.xml +1 -0
- package/lib/base-command.d.ts +3 -1
- package/lib/base-command.js +27 -14
- package/lib/boilersmith/io.d.ts +28 -8
- package/lib/boilersmith/io.js +4 -2
- package/lib/boilersmith/paths.d.ts +2 -2
- package/lib/boilersmith/paths.js +2 -2
- package/lib/boilersmith/scaffolding/audit-step-factory.js +10 -10
- package/lib/boilersmith/scaffolding/infra-step-factory.js +2 -2
- package/lib/boilersmith/scaffolding/init-step-factory.js +5 -5
- package/lib/boilersmith/scaffolding/module.d.ts +19 -8
- package/lib/boilersmith/scaffolding/module.js +30 -17
- package/lib/boilersmith/scaffolding/scaffolder.d.ts +4 -1
- package/lib/boilersmith/scaffolding/scaffolder.js +29 -29
- package/lib/boilersmith/scaffolding/template-param.d.ts +1 -1
- package/lib/boilersmith/scaffolding/template-param.js +2 -2
- package/lib/boilersmith/step-manager.d.ts +0 -1
- package/lib/boilersmith/step-manager.js +10 -20
- package/lib/boilersmith/steps/stub-base.js +1 -1
- package/lib/boilersmith/utils/clone-and-fill.js +1 -1
- package/lib/boilersmith/utils/commit-async.d.ts +2 -0
- package/lib/boilersmith/utils/commit-async.js +15 -0
- package/lib/commands/audit/infra.d.ts +1 -1
- package/lib/commands/audit/infra.js +30 -8
- package/lib/commands/infra.d.ts +2 -2
- package/lib/commands/infra.js +18 -12
- package/lib/commands/init.d.ts +1 -1
- package/lib/commands/init.js +4 -2
- package/lib/commands/make/backend/api-controller.js +1 -2
- package/lib/commands/make/backend/api-serializer-attributes.js +1 -2
- package/lib/commands/make/backend/command.js +1 -2
- package/lib/commands/make/backend/event-listener.js +1 -2
- package/lib/commands/make/backend/handler.js +2 -5
- package/lib/commands/make/backend/integration-test.js +2 -4
- package/lib/commands/make/backend/migration.js +1 -2
- package/lib/commands/make/backend/model.js +1 -2
- package/lib/commands/make/backend/policy.js +1 -2
- package/lib/commands/make/backend/route.js +1 -2
- package/lib/commands/make/backend/service-provider.js +1 -2
- package/lib/commands/make/frontend/model.js +2 -5
- package/lib/commands/monorepo/create.d.ts +15 -0
- package/lib/commands/monorepo/create.js +20 -0
- package/lib/commands/update/js-imports.js +1 -2
- package/lib/help.js +1 -1
- package/lib/steps/gen-ext-scaffolder.d.ts +2 -2
- package/lib/steps/gen-ext-scaffolder.js +144 -46
- package/lib/steps/js/base.js +2 -4
- package/lib/steps/js/model.js +4 -4
- package/lib/steps/misc/git.d.ts +1 -1
- package/lib/steps/misc/git.js +2 -2
- package/lib/steps/misc/npm.d.ts +11 -0
- package/lib/steps/misc/npm.js +19 -0
- package/lib/steps/monorepo/create.d.ts +17 -0
- package/lib/steps/monorepo/create.js +181 -0
- package/lib/steps/stubs/backend/api-controller.d.ts +1 -1
- package/lib/steps/stubs/backend/api-controller.js +3 -0
- package/lib/steps/stubs/backend/api-serializer.d.ts +1 -1
- package/lib/steps/stubs/backend/api-serializer.js +3 -0
- package/lib/steps/stubs/backend/command.d.ts +0 -5
- package/lib/steps/stubs/backend/command.js +1 -0
- package/lib/steps/stubs/backend/event-listener.d.ts +1 -1
- package/lib/steps/stubs/backend/event-listener.js +2 -0
- package/lib/steps/stubs/backend/handler-command.d.ts +1 -1
- package/lib/steps/stubs/backend/handler-command.js +1 -0
- package/lib/steps/stubs/backend/handler.d.ts +1 -1
- package/lib/steps/stubs/backend/handler.js +4 -0
- package/lib/steps/stubs/backend/integration-test.d.ts +1 -1
- package/lib/steps/stubs/backend/integration-test.js +2 -0
- package/lib/steps/stubs/backend/job.d.ts +1 -1
- package/lib/steps/stubs/backend/job.js +1 -0
- package/lib/steps/stubs/backend/migration.js +4 -1
- package/lib/steps/stubs/backend/model.d.ts +1 -1
- package/lib/steps/stubs/backend/model.js +1 -0
- package/lib/steps/stubs/backend/policy.d.ts +1 -1
- package/lib/steps/stubs/backend/policy.js +2 -0
- package/lib/steps/stubs/backend/repository.d.ts +1 -1
- package/lib/steps/stubs/backend/repository.js +2 -0
- package/lib/steps/stubs/backend/service-provider.d.ts +1 -1
- package/lib/steps/stubs/backend/service-provider.js +1 -0
- package/lib/steps/stubs/backend/validator.d.ts +1 -1
- package/lib/steps/stubs/backend/validator.js +1 -0
- package/lib/steps/stubs/flarum-base.js +1 -1
- package/lib/steps/stubs/frontend/component.d.ts +0 -5
- package/lib/steps/stubs/frontend/component.js +1 -0
- package/lib/steps/stubs/frontend/modal.d.ts +0 -5
- package/lib/steps/stubs/frontend/modal.js +1 -0
- package/lib/steps/stubs/frontend/model.d.ts +0 -5
- package/lib/steps/stubs/frontend/model.js +1 -0
- package/lib/steps/stubs/js-base.js +8 -5
- package/lib/steps/stubs/php-base.js +10 -8
- package/lib/steps/update/js-imports.js +8 -2
- package/lib/utils/composer.d.ts +1 -0
- package/lib/utils/migration.js +3 -1
- package/lib/utils/monorepo.d.ts +24 -0
- package/lib/utils/monorepo.js +24 -0
- package/lib/utils/validation.d.ts +2 -0
- package/lib/utils/validation.js +6 -0
- package/oclif.manifest.json +1 -1
- package/package.json +10 -5
- package/php-subsystem/composer.json +9 -9
- package/php-subsystem/composer.lock +64 -71
- package/php-subsystem/vendor/composer/installed.json +54 -61
- package/php-subsystem/vendor/nikic/php-parser/README.md +55 -59
- package/php-subsystem/vendor/nikic/php-parser/composer.json +39 -39
- 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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<!-- tocstop -->
|
|
14
|
+
- [Introduction](#introduction)
|
|
15
|
+
- [Installation](#installation)
|
|
16
|
+
- [Updating](#updating)
|
|
17
|
+
- [Usage](#usage)
|
|
18
|
+
- [Commands](#commands)
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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.
|
|
54
|
+
@flarum/cli/2.0.0-beta.14 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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
+

|
|
142
|
+

|
|
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
|
|
136
|
-
-
|
|
137
|
-
-
|
|
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.
|
|
@@ -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
|
-
|
|
1
|
+
<%- params.licenseText %>
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"type": "flarum-extension",
|
|
8
8
|
"license": "<%= params.licenseType %>",
|
|
9
9
|
"require": {
|
|
10
|
-
"flarum/core": "^1.
|
|
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
|
}
|
|
@@ -14,10 +14,10 @@ namespace <%= params.packageNamespace %>;
|
|
|
14
14
|
use Flarum\Extend;
|
|
15
15
|
|
|
16
16
|
return [
|
|
17
|
-
<% if (modules.
|
|
17
|
+
<% if (modules.forum) { %>(new Extend\Frontend('forum'))
|
|
18
18
|
<% if (modules.js) { %>->js(__DIR__.'/js/dist/forum.js')<% if (!modules.css) { %>,<% } %><% } %>
|
|
19
19
|
<% if (modules.css) { %>->css(__DIR__.'/less/forum.less'),<% } %><% } %>
|
|
20
|
-
<% if (modules.
|
|
20
|
+
<% if (modules.admin) { %>(new Extend\Frontend('admin'))
|
|
21
21
|
<% if (modules.js) { %>->js(__DIR__.'/js/dist/admin.js')<% if (!modules.css) { %>,<% } %><% } %>
|
|
22
22
|
<% if (modules.css) { %>->css(__DIR__.'/less/admin.less'),<% } %><% } %>
|
|
23
23
|
<% if (modules.locale) { %>new Extend\Locales(__DIR__.'/locale'),<% } %>
|
|
@@ -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
|
|
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
|
}
|
package/lib/base-command.d.ts
CHANGED
|
@@ -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
|
|
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;
|
package/lib/base-command.js
CHANGED
|
@@ -14,6 +14,8 @@ 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";
|
|
@@ -52,9 +54,8 @@ class BaseCommand extends core_1.Command {
|
|
|
52
54
|
package: extRoot,
|
|
53
55
|
});
|
|
54
56
|
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
|
-
|
|
57
|
-
const errorMessages = out.messages.filter(m => m.type === 'error');
|
|
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
|
|
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,20 +119,23 @@ 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,
|
|
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 ? [
|
|
126
|
-
...(options.includeExtensions ?
|
|
127
|
-
...(options.includePhpPackages ?
|
|
128
|
-
...(options.includeJSPackages ?
|
|
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 (
|
|
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, node_fs_1.existsSync)((0, node_path_1.resolve)(path, 'flarum-monorepo.json'));
|
|
138
|
+
}
|
|
135
139
|
isFlarumCore(path) {
|
|
136
140
|
try {
|
|
137
141
|
const composerJsonPath = (0, node_path_1.resolve)(path, 'composer.json');
|
|
@@ -142,6 +146,11 @@ class BaseCommand extends core_1.Command {
|
|
|
142
146
|
return false;
|
|
143
147
|
}
|
|
144
148
|
}
|
|
149
|
+
jsPackageManager(currDir) {
|
|
150
|
+
if (!(0, node_fs_1.existsSync)((0, node_path_1.resolve)(currDir, 'js')))
|
|
151
|
+
return null;
|
|
152
|
+
return (0, node_fs_1.existsSync)((0, node_path_1.resolve)(currDir, 'js/yarn.lock')) ? 'yarn' : 'npm';
|
|
153
|
+
}
|
|
145
154
|
async getFlarumExtensionRoot(currDir) {
|
|
146
155
|
let currPath = (0, node_path_1.resolve)(currDir);
|
|
147
156
|
while (currPath !== '/') {
|
|
@@ -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, node_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;
|
|
@@ -218,7 +227,11 @@ class BaseCommand extends core_1.Command {
|
|
|
218
227
|
}
|
|
219
228
|
exports.default = BaseCommand;
|
|
220
229
|
BaseCommand.flags = {
|
|
221
|
-
'no-interaction': core_1.Flags.boolean({
|
|
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 = [
|
package/lib/boilersmith/io.d.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
package/lib/boilersmith/io.js
CHANGED
|
@@ -15,7 +15,7 @@ class PromptsIO {
|
|
|
15
15
|
this.noInteraction = noInteraction;
|
|
16
16
|
this.onCancel = onCancel;
|
|
17
17
|
}
|
|
18
|
-
async getParam(paramDef) {
|
|
18
|
+
async getParam(paramDef, noCache = false) {
|
|
19
19
|
var _a, _b, _c;
|
|
20
20
|
const paramName = paramDef.name;
|
|
21
21
|
if (this.cache.has(paramName)) {
|
|
@@ -42,7 +42,9 @@ class PromptsIO {
|
|
|
42
42
|
}));
|
|
43
43
|
resValue = res[paramName];
|
|
44
44
|
}
|
|
45
|
-
|
|
45
|
+
if (!noCache) {
|
|
46
|
+
this.cache.set(paramName, resValue);
|
|
47
|
+
}
|
|
46
48
|
this.prev = {
|
|
47
49
|
val: resValue,
|
|
48
50
|
prompt: paramDef,
|
|
@@ -3,7 +3,7 @@ export interface Paths {
|
|
|
3
3
|
package(...path: string[]): string;
|
|
4
4
|
requestedDir(...path: string[]): string | null;
|
|
5
5
|
monorepo(...path: string[]): string | null;
|
|
6
|
-
onMonorepoSub(packagePath: string): Paths;
|
|
6
|
+
onMonorepoSub(packagePath: string, monorepoPath?: string): Paths;
|
|
7
7
|
}
|
|
8
8
|
declare type InternalPaths = {
|
|
9
9
|
package: string;
|
|
@@ -17,6 +17,6 @@ export declare class NodePaths implements Paths {
|
|
|
17
17
|
package(...path: string[]): string;
|
|
18
18
|
requestedDir(...path: string[]): string | null;
|
|
19
19
|
monorepo(...path: string[]): string | null;
|
|
20
|
-
onMonorepoSub(packagePath: string): NodePaths;
|
|
20
|
+
onMonorepoSub(packagePath: string, monorepoPath?: string): NodePaths;
|
|
21
21
|
}
|
|
22
22
|
export {};
|
package/lib/boilersmith/paths.js
CHANGED
|
@@ -22,8 +22,8 @@ class NodePaths {
|
|
|
22
22
|
return null;
|
|
23
23
|
return (0, node_path_1.resolve)(this.paths.monorepo, ...path);
|
|
24
24
|
}
|
|
25
|
-
onMonorepoSub(packagePath) {
|
|
26
|
-
return new NodePaths(Object.assign(Object.assign({}, this.paths), { monorepo: this.paths.package, package: packagePath }));
|
|
25
|
+
onMonorepoSub(packagePath, monorepoPath) {
|
|
26
|
+
return new NodePaths(Object.assign(Object.assign({}, this.paths), { monorepo: monorepoPath !== null && monorepoPath !== void 0 ? monorepoPath : this.paths.package, package: packagePath }));
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
exports.NodePaths = NodePaths;
|