@flarum/cli 2.0.0-beta.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +181 -49
- package/bin/run +2 -1
- package/bin/splitsh-lite-darwin +0 -0
- package/bin/splitsh-lite-linux +0 -0
- package/boilerplate/skeleton/extension/.gitattributes +16 -14
- package/boilerplate/skeleton/extension/.github/workflows/backend.yml +2 -6
- package/boilerplate/skeleton/extension/.github/workflows/frontend.yml +4 -6
- package/boilerplate/skeleton/extension/LICENSE.md +1 -1
- package/boilerplate/skeleton/extension/README.md +1 -1
- package/boilerplate/skeleton/extension/composer.json +6 -4
- package/boilerplate/skeleton/extension/extend.php +2 -2
- package/boilerplate/skeleton/extension/js/admin.ts +2 -0
- package/boilerplate/skeleton/extension/js/forum.ts +2 -0
- package/boilerplate/skeleton/extension/js/package.json +5 -1
- package/boilerplate/skeleton/extension/js/src/admin/index.ts +5 -0
- package/boilerplate/skeleton/extension/js/src/common/index.ts +5 -0
- package/boilerplate/skeleton/extension/js/src/forum/index.ts +5 -0
- package/boilerplate/skeleton/extension/js/tsconfig.json +10 -2
- package/boilerplate/skeleton/extension/locale/en.yml +1 -1
- package/boilerplate/skeleton/extension/tests/phpunit.integration.xml +1 -0
- package/lib/base-command.d.ts +3 -1
- package/lib/base-command.js +44 -31
- 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 +7 -7
- package/lib/boilersmith/scaffolding/audit-step-factory.js +11 -11
- 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 +28 -8
- package/lib/boilersmith/scaffolding/module.js +59 -17
- package/lib/boilersmith/scaffolding/scaffolder.d.ts +4 -1
- package/lib/boilersmith/scaffolding/scaffolder.js +32 -32
- 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 +3 -3
- 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/boilersmith/utils/read-tpl.js +2 -2
- 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/monorepo/split.d.ts +15 -0
- package/lib/commands/monorepo/split.js +19 -0
- package/lib/commands/update/js-imports.js +1 -2
- package/lib/help.js +1 -1
- package/lib/providers/php-provider.js +2 -2
- package/lib/steps/gen-ext-scaffolder.d.ts +2 -2
- package/lib/steps/gen-ext-scaffolder.js +185 -51
- package/lib/steps/js/base.js +2 -4
- package/lib/steps/js/model.js +4 -4
- package/lib/steps/misc/composer.js +2 -2
- 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/misc/yarn.js +2 -2
- package/lib/steps/monorepo/create.d.ts +17 -0
- package/lib/steps/monorepo/create.js +186 -0
- package/lib/steps/monorepo/split.d.ts +14 -0
- package/lib/steps/monorepo/split.js +99 -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 +6 -3
- 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 +11 -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/LICENSE
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
The MIT License (MIT)
|
|
2
2
|
|
|
3
|
-
Copyright (c) 2021 Stichting Flarum (Flarum Foundation)
|
|
3
|
+
Copyright (c) 2021-2022 Stichting Flarum (Flarum Foundation)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
package/README.md
CHANGED
|
@@ -3,41 +3,54 @@
|
|
|
3
3
|
A CLI for developing Flarum extensions</p>
|
|
4
4
|
|
|
5
5
|
<p align=center>
|
|
6
|
-
<a href="https://oclif.io"><img alt"oclif" src="https://img.shields.io/badge/cli-oclif-brightgreen.svg"></a>
|
|
7
|
-
<a href="https://npmjs.org/package/@flarum/cli"><img alt"Version" src="https://img.shields.io/npm/v/@flarum/cli.svg"></a>
|
|
8
|
-
<a href="https://npmjs.org/package/@flarum/cli"><img alt"Downloads/week" src="https://img.shields.io/npm/dw/@flarum/cli.svg"></a>
|
|
9
|
-
<a href="https://github.com/flarum/cli/blob/master/package.json"><img alt"License" src="https://img.shields.io/npm/l/@flarum/cli.svg"></a>
|
|
6
|
+
<a href="https://oclif.io"><img alt="oclif" src="https://img.shields.io/badge/cli-oclif-brightgreen.svg"></a>
|
|
7
|
+
<a href="https://npmjs.org/package/@flarum/cli"><img alt="Version" src="https://img.shields.io/npm/v/@flarum/cli.svg"></a>
|
|
8
|
+
<a href="https://npmjs.org/package/@flarum/cli"><img alt="Downloads/week" src="https://img.shields.io/npm/dw/@flarum/cli.svg"></a>
|
|
9
|
+
<a href="https://github.com/flarum/cli/blob/master/package.json"><img alt="License" src="https://img.shields.io/npm/l/@flarum/cli.svg"></a>
|
|
10
10
|
<br>
|
|
11
|
-
<img width=720 src="https://sycho9.github.io/flarum-cli.svg" alt="terminal_example">
|
|
12
11
|
</p>
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
<!-- tocstop -->
|
|
13
|
+
- [Introduction](#introduction)
|
|
14
|
+
- [Installation](#installation)
|
|
15
|
+
- [Updating](#updating)
|
|
16
|
+
- [Usage](#usage)
|
|
17
|
+
- [Commands](#commands)
|
|
20
18
|
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
## Introduction
|
|
20
|
+
|
|
21
|
+
One of our core values is **_Framework First_**, Flarum is as much a framework for extension development as it is a forum platform.
|
|
23
22
|
|
|
24
23
|
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
24
|
|
|
26
|
-
|
|
25
|
+
## Installation
|
|
26
|
+
|
|
27
27
|
<!-- installation -->
|
|
28
|
+
|
|
28
29
|
```sh-session
|
|
29
|
-
$ npm install -g @flarum/cli
|
|
30
|
+
$ npm install -g @flarum/cli@^2.0.0
|
|
30
31
|
```
|
|
32
|
+
|
|
31
33
|
<!-- installationstop -->
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
## Updating
|
|
36
|
+
|
|
37
|
+
<!-- updating -->
|
|
38
|
+
|
|
39
|
+
```sh-session
|
|
40
|
+
$ npm update -g @flarum/cli
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
<!-- updatingstop -->
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
34
47
|
<!-- usage -->
|
|
35
48
|
```sh-session
|
|
36
49
|
$ npm install -g @flarum/cli
|
|
37
50
|
$ flarum-cli COMMAND
|
|
38
51
|
running command...
|
|
39
52
|
$ flarum-cli (-v|--version|version)
|
|
40
|
-
@flarum/cli/2.0.0
|
|
53
|
+
@flarum/cli/2.0.0 linux-x64 node-v18.19.1
|
|
41
54
|
$ flarum-cli --help [COMMAND]
|
|
42
55
|
USAGE
|
|
43
56
|
$ flarum-cli COMMAND
|
|
@@ -59,29 +72,117 @@ or
|
|
|
59
72
|
flarum-cli --help
|
|
60
73
|
```
|
|
61
74
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
75
|
+
## Commands
|
|
76
|
+
|
|
77
|
+
The CLI has different types of commands for different tasks:
|
|
78
|
+
|
|
79
|
+
**Initialisation**
|
|
80
|
+
|
|
81
|
+
- `flarum-cli init [PATH]`: Generates a blank extension skeleton, including all recommended infrastructure.
|
|
82
|
+
|
|
83
|
+
**Infrastructure**: See the [infrastructure](#infrastructure-modules) section for more information.
|
|
84
|
+
|
|
85
|
+
- `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`.
|
|
86
|
+
|
|
87
|
+
**Audit**: These commands help you make sure your extension is up to date.
|
|
88
|
+
|
|
89
|
+
- `flarum-cli audit infra [--monorepo] [--fix]` Check that infrastructure files are up to date for all enabled modules.
|
|
90
|
+
|
|
91
|
+
**Backend Boilerplate Generation**: Generates different types of backend classes and/or extenders, ready to be used.
|
|
92
|
+
|
|
93
|
+
- `flarum-cli make backend api-controller [PATH]`
|
|
94
|
+
- `flarum-cli make backend api-serializer [PATH]`
|
|
95
|
+
- `flarum-cli make backend api-serializer-attributes [PATH]`
|
|
96
|
+
- `flarum-cli make backend command [PATH]`
|
|
97
|
+
- `flarum-cli make backend event-listener [PATH]`
|
|
98
|
+
- `flarum-cli make backend handler [PATH]`
|
|
99
|
+
- `flarum-cli make backend integration-test [PATH]`
|
|
100
|
+
- `flarum-cli make backend job [PATH]`
|
|
101
|
+
- `flarum-cli make backend migration [PATH]`
|
|
102
|
+
- `flarum-cli make backend model [PATH]`
|
|
103
|
+
- `flarum-cli make backend policy [PATH]`
|
|
104
|
+
- `flarum-cli make backend repository [PATH]`
|
|
105
|
+
- `flarum-cli make backend route [PATH]`
|
|
106
|
+
- `flarum-cli make backend service-provider [PATH]`
|
|
107
|
+
- `flarum-cli make backend validator [PATH]`
|
|
108
|
+
|
|
109
|
+
**Frontend Boilerplate Generation**: Generate frontend components/classes, ready to be used.
|
|
110
|
+
|
|
111
|
+
- `flarum-cli make frontend component [PATH]`
|
|
112
|
+
- `flarum-cli make frontend modal [PATH]`
|
|
113
|
+
- `flarum-cli make frontend model [PATH]`
|
|
114
|
+
|
|
115
|
+
**Code Updates**: These commands help update extensions for newer versions of Flarum.
|
|
116
|
+
|
|
117
|
+
- `flarum-cli update js-imports [PATH]`: Adds admin/forum/common namespaces to all JS imports from flarum core.
|
|
118
|
+
|
|
119
|
+
_And of course, you can always use the help command to see a list of all available commands with their descriptions:_
|
|
120
|
+
|
|
121
|
+
- `flarum-cli help [COMMAND]`
|
|
122
|
+
|
|
123
|
+
All commands can use a `--no-interaction` flag to proceed with default values for prompts when possible.
|
|
124
|
+
|
|
125
|
+
## 🔥 The Most Powerful Commands
|
|
126
|
+
|
|
127
|
+
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:
|
|
128
|
+
|
|
129
|
+
- Table migration
|
|
130
|
+
- Policy
|
|
131
|
+
- API Serializer
|
|
132
|
+
- CRUD API Controllers
|
|
133
|
+
- CRUD Handlers
|
|
134
|
+
- Repository
|
|
135
|
+
- Validator
|
|
136
|
+
- Routes
|
|
137
|
+
- Related Extenders
|
|
138
|
+
|
|
139
|
+
[center]
|
|
140
|
+

|
|
141
|
+

|
|
142
|
+
[/center]
|
|
143
|
+
|
|
144
|
+
## Infrastructure Modules
|
|
145
|
+
|
|
146
|
+
If you maintain more than just a few extensions, keeping the infrastructure up to date can be very tedious.
|
|
147
|
+
We heavily value developer experience, and make it a point to support automated testing, static analysis, formatting, and other tools
|
|
148
|
+
that help you work more happily and efficiently. However, all this means that there's a lot of config files to keep track of.
|
|
149
|
+
|
|
150
|
+
The idea behind Flarum CLI's infrastructure modules is simple: the config for some feature is associated with a "module".
|
|
151
|
+
For example, the "typescript" module includes:
|
|
152
|
+
|
|
153
|
+
- The `js/tsconfig.json` file
|
|
154
|
+
- Dependency reqs for `typescript`, `typescript-coverage-report`, and `flarum-tsconfig` in the `package.json` file.
|
|
155
|
+
- Script configuration to check type safety and type coverage in the `package.json` file.
|
|
156
|
+
|
|
157
|
+
So to enable the `typescript` module, all Flarum CLI has to do is update those files and JSON config keys to the latest version.
|
|
158
|
+
|
|
159
|
+
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.
|
|
160
|
+
|
|
161
|
+
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.
|
|
162
|
+
|
|
163
|
+
### Excluding Files
|
|
164
|
+
|
|
165
|
+
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:
|
|
166
|
+
|
|
167
|
+
```json
|
|
168
|
+
{
|
|
169
|
+
...
|
|
170
|
+
"extra": {
|
|
171
|
+
"flarum-cli": {
|
|
172
|
+
"excludeScaffolding": [
|
|
173
|
+
"js/tsconfig.json"
|
|
174
|
+
],
|
|
175
|
+
"excludeScaffoldingConfigKeys": {
|
|
176
|
+
"composer.json": [
|
|
177
|
+
"scripts.test:setup"
|
|
178
|
+
],
|
|
179
|
+
...
|
|
180
|
+
},
|
|
181
|
+
...
|
|
182
|
+
}
|
|
183
|
+
...
|
|
184
|
+
}
|
|
185
|
+
```
|
|
85
186
|
|
|
86
187
|
## For Maintainers
|
|
87
188
|
|
|
@@ -99,7 +200,7 @@ The base command is implemented at [src/base-command.ts](https://github.com/flar
|
|
|
99
200
|
3. Confirm we are in the right directory
|
|
100
201
|
4. Confirm that files will be overwritten / clear files as needed
|
|
101
202
|
5. Run a set of registered steps
|
|
102
|
-
6. Tell the user which steps ran
|
|
203
|
+
6. Tell the user which steps ran, or display any errors
|
|
103
204
|
7. Show a goodbye message
|
|
104
205
|
|
|
105
206
|
Actual functionality is implemented at the step layer.
|
|
@@ -117,7 +218,7 @@ More documentation (and functionality!) will be added later.
|
|
|
117
218
|
|
|
118
219
|
#### What are steps?
|
|
119
220
|
|
|
120
|
-
Steps represent granular operations. Some are bigger and some are smaller, but they include:
|
|
221
|
+
Steps represent meaningful, granular operations. Some are bigger and some are smaller, but they include:
|
|
121
222
|
|
|
122
223
|
- Initializing an extension from boilerplate
|
|
123
224
|
- Updating some part of an extension from boilerplate (like adding backend testing)
|
|
@@ -132,9 +233,10 @@ If some subtask might be needed by multiple commands, that should be a step too.
|
|
|
132
233
|
The actual logic of a step is implemented in the async `run` method. This method takes:
|
|
133
234
|
|
|
134
235
|
- An in-memory filesystem object (through `mem-fs`)
|
|
135
|
-
- A
|
|
136
|
-
-
|
|
137
|
-
-
|
|
236
|
+
- 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).
|
|
237
|
+
- An `io` instance, which can be used to prompt the user for input or display outputs / errors.
|
|
238
|
+
- An object of "providers", which represent additional functionality. For Flarum commands, these are:
|
|
239
|
+
- A "php provider", which can be used to interact with the PHP subsystem to add extenders to extend.php.
|
|
138
240
|
|
|
139
241
|
Steps should modify the in-memory filesystem with their changes and return it.
|
|
140
242
|
|
|
@@ -159,7 +261,6 @@ Sharing parameters is done via the following process:
|
|
|
159
261
|
- What the param is consumed at
|
|
160
262
|
- If the param value is falsy, should the consumer step run at all? Useful for variable dependencies.
|
|
161
263
|
|
|
162
|
-
|
|
163
264
|
For example:
|
|
164
265
|
|
|
165
266
|
```ts
|
|
@@ -195,7 +296,6 @@ For example:
|
|
|
195
296
|
.run(new Paths({...}), new PromptsIO(), {php: new PhpProvider(...)});
|
|
196
297
|
```
|
|
197
298
|
|
|
198
|
-
|
|
199
299
|
#### Step Composability and Atomic Groups
|
|
200
300
|
|
|
201
301
|
As noted above, steps should work by modifying and returning an in-memory filesystem.
|
|
@@ -214,8 +314,6 @@ Steps for generating extenders should use `src/steps/extenders/base`, where all
|
|
|
214
314
|
|
|
215
315
|
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
316
|
|
|
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
317
|
### Testing
|
|
220
318
|
|
|
221
319
|
Most of this architecture was driven by TDD and BDD development, allowing for a highly decoupled system.
|
|
@@ -225,3 +323,37 @@ Any additions of steps, modifications of providers, or changes of functionality
|
|
|
225
323
|
The 3 base step types actually provide a simple interface to generate test cases. See the relevant test files for more info.
|
|
226
324
|
|
|
227
325
|
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.
|
|
326
|
+
|
|
327
|
+
### Monorepo Support
|
|
328
|
+
|
|
329
|
+
Flarum CLI was designed with monorepos in mind.
|
|
330
|
+
When registering a step, you can provide it an array of subdirectories to run it in.
|
|
331
|
+
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()`.
|
|
332
|
+
|
|
333
|
+
A monorepo should have a `flarum-monorepo.json` file in the root directory with the following (optional) keys:
|
|
334
|
+
|
|
335
|
+
- `packages.core`: a path to Flarum Core, if present.
|
|
336
|
+
- `packages.extensions`: an array of paths to Flarum extensions.
|
|
337
|
+
- `packages.composer`: an array of paths to non-extension PHP Composer packages published on Packagist.
|
|
338
|
+
- `packages.npm`: an array of paths to non-extension JS/TS packages published on NPM.
|
|
339
|
+
|
|
340
|
+
### Scaffolding Generation
|
|
341
|
+
|
|
342
|
+
One powerful use-case of Flarum CLI is creating new extensions, and keeping infrastructure in sync for existing extensions.
|
|
343
|
+
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.
|
|
344
|
+
|
|
345
|
+
For this purpose, Flarum CLI's `Scaffolder` system formalizes the concepts of initializing and updating extension infrastructure.
|
|
346
|
+
|
|
347
|
+
At the core level, there's a boilerplate directory (`boilerplate/skeleton/extension`) that contains the scaffolding for a new extension.
|
|
348
|
+
|
|
349
|
+
The scaffolder receives a set of modules, which represent some aspect of infrastructure (e.g. JS, TypeScript, Backend Testing, etc).
|
|
350
|
+
Modules can be updatable (e.g. TypeScript) or not (e.g. the core setup of an `extend.php` file).
|
|
351
|
+
They can also be togglable (e.g. JS), or not, in which case they are always on.
|
|
352
|
+
|
|
353
|
+
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.
|
|
354
|
+
|
|
355
|
+
Modules also have template params, which are used as variables in the scaffolding.
|
|
356
|
+
|
|
357
|
+
There's a lot more features and guaruntees than that, see the `Module` interface for more information.
|
|
358
|
+
|
|
359
|
+
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',
|
|
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
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
9
9
|
|
|
10
|
-
phpunit.xml export-ignore
|
|
11
|
-
tests export-ignore
|
|
10
|
+
**/phpunit.xml export-ignore
|
|
11
|
+
**/tests export-ignore
|
|
12
12
|
|
|
13
|
-
js/dist
|
|
14
|
-
js/dist
|
|
15
|
-
js/dist-typings
|
|
16
|
-
js/
|
|
13
|
+
**/js/dist/**/* -diff
|
|
14
|
+
**/js/dist/**/* linguist-generated
|
|
15
|
+
**/js/dist-typings/**/* -diff
|
|
16
|
+
**/js/dist-typings/**/* linguist-generated
|
|
17
|
+
**/js/yarn.lock -diff
|
|
18
|
+
**/js/package-lock.json -diff
|
|
17
19
|
|
|
18
20
|
* text=auto eol=lf
|
|
@@ -2,14 +2,10 @@ name: <%= params.extensionName %> PHP
|
|
|
2
2
|
|
|
3
3
|
on: [workflow_dispatch, push, pull_request]
|
|
4
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
5
|
jobs:
|
|
10
6
|
run:
|
|
11
|
-
uses: flarum/.github
|
|
7
|
+
uses: flarum/framework/.github/workflows/REUSABLE_backend.yml@main
|
|
12
8
|
with:
|
|
13
9
|
enable_backend_testing: <%= modules.backendTesting %>
|
|
14
10
|
|
|
15
|
-
backend_directory: <%= params.backendDirectory %>
|
|
11
|
+
backend_directory: <%= params.backendDirectory %>
|
|
@@ -2,19 +2,17 @@ name: <%= params.extensionName %> JS
|
|
|
2
2
|
|
|
3
3
|
on: [workflow_dispatch, push, pull_request]
|
|
4
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
5
|
jobs:
|
|
10
6
|
run:
|
|
11
|
-
uses: flarum/.github
|
|
7
|
+
uses: flarum/framework/.github/workflows/REUSABLE_frontend.yml@main
|
|
12
8
|
with:
|
|
13
9
|
enable_bundlewatch: <%= modules.bundlewatch %>
|
|
14
10
|
enable_prettier: <%= modules.prettier %>
|
|
15
11
|
enable_typescript: <%= modules.typescript %>
|
|
16
12
|
|
|
17
13
|
frontend_directory: <%= params.frontendDirectory %>
|
|
14
|
+
backend_directory: <%= params.backendDirectory %>
|
|
15
|
+
js_package_manager: <%= params.jsPackageManager %>
|
|
18
16
|
main_git_branch: <%= params.mainGitBranch %>
|
|
19
17
|
secrets:
|
|
20
|
-
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
|
|
18
|
+
bundlewatch_github_token: ${{ secrets.BUNDLEWATCH_GITHUB_TOKEN }}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
<%- params.licenseText %>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
 [](https://packagist.org/packages/<%= params.packageName %>) [](https://packagist.org/packages/<%= params.packageName %>)
|
|
4
4
|
|
|
5
|
-
A [Flarum](
|
|
5
|
+
A [Flarum](https://flarum.org) extension. <%= params.packageDescription %>
|
|
6
6
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
@@ -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"
|
|
@@ -22,13 +22,13 @@
|
|
|
22
22
|
<% if (params.packageNamespace) { %>
|
|
23
23
|
"autoload": {
|
|
24
24
|
"psr-4": {
|
|
25
|
-
"<%= params.
|
|
25
|
+
"<%= params.packageNamespace %>\\": "src/"
|
|
26
26
|
}
|
|
27
27
|
},
|
|
28
28
|
<% } %>
|
|
29
29
|
"autoload-dev": {
|
|
30
30
|
"psr-4": {
|
|
31
|
-
"<%= params.
|
|
31
|
+
"<%= params.packageNamespace %>\\Tests\\": "tests/"
|
|
32
32
|
}
|
|
33
33
|
},
|
|
34
34
|
"extra": {
|
|
@@ -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'),<% } %>
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@<%= params.packageName %>",
|
|
3
3
|
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
4
5
|
"prettier": "@flarum/prettier-config",
|
|
5
6
|
"dependencies": {
|
|
6
7
|
},
|
|
@@ -17,9 +18,12 @@
|
|
|
17
18
|
"scripts": {
|
|
18
19
|
"dev": "webpack --mode development --watch",
|
|
19
20
|
"build": "webpack --mode production",
|
|
20
|
-
"analyze": "cross-env ANALYZER=true
|
|
21
|
+
"analyze": "cross-env ANALYZER=true <%= params.jsPackageManager %> run build",
|
|
21
22
|
"format": "prettier --write src",
|
|
22
23
|
"format-check": "prettier --check src",
|
|
24
|
+
"clean-typings": "npx rimraf dist-typings && mkdir dist-typings",
|
|
25
|
+
"build-typings": "<%= params.jsPackageManager %> run clean-typings && ([ -e src/@types ] && cp -r src/@types dist-typings/@types || true) && tsc && <%= params.jsPackageManager %> run post-build-typings",
|
|
26
|
+
"post-build-typings": "find dist-typings -type f -name '*.d.ts' -print0 | xargs -0 sed -i 's,../src/@types,@types,g'",
|
|
23
27
|
"check-typings": "tsc --noEmit --emitDeclarationOnly false",
|
|
24
28
|
"check-typings-coverage": "typescript-coverage-report"
|
|
25
29
|
}
|
|
@@ -4,13 +4,21 @@
|
|
|
4
4
|
// This will match all .ts, .tsx, .d.ts, .js, .jsx files in your `src` folder
|
|
5
5
|
// and also tells your Typescript server to read core's global typings for
|
|
6
6
|
// access to `dayjs` and `$` in the global namespace.
|
|
7
|
-
"include": [
|
|
7
|
+
"include": [
|
|
8
|
+
"src/**/*",
|
|
9
|
+
"../vendor/*/*/js/dist-typings/@types/**/*",
|
|
10
|
+
// <CUSTOM-1>
|
|
11
|
+
// </CUSTOM-1>
|
|
12
|
+
"@types/**/*"
|
|
13
|
+
],
|
|
8
14
|
"compilerOptions": {
|
|
9
15
|
// This will output typings to `dist-typings`
|
|
10
16
|
"declarationDir": "./dist-typings",
|
|
11
17
|
"baseUrl": ".",
|
|
12
18
|
"paths": {
|
|
13
|
-
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"]
|
|
19
|
+
"flarum/*": ["../vendor/flarum/core/js/dist-typings/*"],
|
|
20
|
+
// <CUSTOM-2>
|
|
21
|
+
// </CUSTOM-2>
|
|
14
22
|
}
|
|
15
23
|
}
|
|
16
24
|
}
|
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;
|