@flarum/cli 2.0.0-beta.13 → 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.
Files changed (112) hide show
  1. package/README.md +136 -39
  2. package/boilerplate/skeleton/extension/.gitattributes +1 -0
  3. package/boilerplate/skeleton/extension/.github/workflows/backend.yml +1 -1
  4. package/boilerplate/skeleton/extension/.github/workflows/frontend.yml +3 -1
  5. package/boilerplate/skeleton/extension/LICENSE.md +1 -1
  6. package/boilerplate/skeleton/extension/composer.json +4 -2
  7. package/boilerplate/skeleton/extension/js/package.json +4 -1
  8. package/boilerplate/skeleton/extension/tests/phpunit.integration.xml +1 -0
  9. package/lib/base-command.d.ts +3 -1
  10. package/lib/base-command.js +27 -14
  11. package/lib/boilersmith/io.d.ts +28 -8
  12. package/lib/boilersmith/io.js +4 -2
  13. package/lib/boilersmith/paths.d.ts +2 -2
  14. package/lib/boilersmith/paths.js +2 -2
  15. package/lib/boilersmith/scaffolding/audit-step-factory.js +10 -10
  16. package/lib/boilersmith/scaffolding/infra-step-factory.js +2 -2
  17. package/lib/boilersmith/scaffolding/init-step-factory.js +5 -5
  18. package/lib/boilersmith/scaffolding/module.d.ts +19 -8
  19. package/lib/boilersmith/scaffolding/module.js +30 -17
  20. package/lib/boilersmith/scaffolding/scaffolder.d.ts +4 -1
  21. package/lib/boilersmith/scaffolding/scaffolder.js +29 -29
  22. package/lib/boilersmith/scaffolding/template-param.d.ts +1 -1
  23. package/lib/boilersmith/scaffolding/template-param.js +2 -2
  24. package/lib/boilersmith/step-manager.d.ts +0 -1
  25. package/lib/boilersmith/step-manager.js +10 -20
  26. package/lib/boilersmith/steps/stub-base.js +1 -1
  27. package/lib/boilersmith/utils/clone-and-fill.js +1 -1
  28. package/lib/boilersmith/utils/commit-async.d.ts +2 -0
  29. package/lib/boilersmith/utils/commit-async.js +15 -0
  30. package/lib/commands/audit/infra.d.ts +1 -1
  31. package/lib/commands/audit/infra.js +30 -8
  32. package/lib/commands/infra.d.ts +2 -2
  33. package/lib/commands/infra.js +18 -12
  34. package/lib/commands/init.d.ts +1 -1
  35. package/lib/commands/init.js +4 -2
  36. package/lib/commands/make/backend/api-controller.js +1 -2
  37. package/lib/commands/make/backend/api-serializer-attributes.js +1 -2
  38. package/lib/commands/make/backend/command.js +1 -2
  39. package/lib/commands/make/backend/event-listener.js +1 -2
  40. package/lib/commands/make/backend/handler.js +2 -5
  41. package/lib/commands/make/backend/integration-test.js +2 -4
  42. package/lib/commands/make/backend/migration.js +1 -2
  43. package/lib/commands/make/backend/model.js +1 -2
  44. package/lib/commands/make/backend/policy.js +1 -2
  45. package/lib/commands/make/backend/route.js +1 -2
  46. package/lib/commands/make/backend/service-provider.js +1 -2
  47. package/lib/commands/make/frontend/model.js +2 -5
  48. package/lib/commands/monorepo/create.d.ts +15 -0
  49. package/lib/commands/monorepo/create.js +20 -0
  50. package/lib/commands/update/js-imports.js +1 -2
  51. package/lib/help.js +1 -1
  52. package/lib/steps/gen-ext-scaffolder.d.ts +1 -1
  53. package/lib/steps/gen-ext-scaffolder.js +94 -38
  54. package/lib/steps/js/base.js +2 -4
  55. package/lib/steps/js/model.js +4 -4
  56. package/lib/steps/misc/git.d.ts +1 -1
  57. package/lib/steps/misc/git.js +2 -2
  58. package/lib/steps/misc/npm.d.ts +11 -0
  59. package/lib/steps/misc/npm.js +19 -0
  60. package/lib/steps/monorepo/create.d.ts +17 -0
  61. package/lib/steps/monorepo/create.js +181 -0
  62. package/lib/steps/stubs/backend/api-controller.d.ts +1 -1
  63. package/lib/steps/stubs/backend/api-controller.js +3 -0
  64. package/lib/steps/stubs/backend/api-serializer.d.ts +1 -1
  65. package/lib/steps/stubs/backend/api-serializer.js +3 -0
  66. package/lib/steps/stubs/backend/command.d.ts +0 -5
  67. package/lib/steps/stubs/backend/command.js +1 -0
  68. package/lib/steps/stubs/backend/event-listener.d.ts +1 -1
  69. package/lib/steps/stubs/backend/event-listener.js +2 -0
  70. package/lib/steps/stubs/backend/handler-command.d.ts +1 -1
  71. package/lib/steps/stubs/backend/handler-command.js +1 -0
  72. package/lib/steps/stubs/backend/handler.d.ts +1 -1
  73. package/lib/steps/stubs/backend/handler.js +4 -0
  74. package/lib/steps/stubs/backend/integration-test.d.ts +1 -1
  75. package/lib/steps/stubs/backend/integration-test.js +2 -0
  76. package/lib/steps/stubs/backend/job.d.ts +1 -1
  77. package/lib/steps/stubs/backend/job.js +1 -0
  78. package/lib/steps/stubs/backend/migration.js +4 -1
  79. package/lib/steps/stubs/backend/model.d.ts +1 -1
  80. package/lib/steps/stubs/backend/model.js +1 -0
  81. package/lib/steps/stubs/backend/policy.d.ts +1 -1
  82. package/lib/steps/stubs/backend/policy.js +2 -0
  83. package/lib/steps/stubs/backend/repository.d.ts +1 -1
  84. package/lib/steps/stubs/backend/repository.js +2 -0
  85. package/lib/steps/stubs/backend/service-provider.d.ts +1 -1
  86. package/lib/steps/stubs/backend/service-provider.js +1 -0
  87. package/lib/steps/stubs/backend/validator.d.ts +1 -1
  88. package/lib/steps/stubs/backend/validator.js +1 -0
  89. package/lib/steps/stubs/flarum-base.js +1 -1
  90. package/lib/steps/stubs/frontend/component.d.ts +0 -5
  91. package/lib/steps/stubs/frontend/component.js +1 -0
  92. package/lib/steps/stubs/frontend/modal.d.ts +0 -5
  93. package/lib/steps/stubs/frontend/modal.js +1 -0
  94. package/lib/steps/stubs/frontend/model.d.ts +0 -5
  95. package/lib/steps/stubs/frontend/model.js +1 -0
  96. package/lib/steps/stubs/js-base.js +8 -5
  97. package/lib/steps/stubs/php-base.js +10 -8
  98. package/lib/steps/update/js-imports.js +8 -2
  99. package/lib/utils/composer.d.ts +1 -0
  100. package/lib/utils/migration.js +3 -1
  101. package/lib/utils/monorepo.d.ts +24 -0
  102. package/lib/utils/monorepo.js +24 -0
  103. package/lib/utils/validation.d.ts +2 -0
  104. package/lib/utils/validation.js +6 -0
  105. package/oclif.manifest.json +1 -1
  106. package/package.json +7 -3
  107. package/php-subsystem/composer.json +9 -9
  108. package/php-subsystem/composer.lock +64 -71
  109. package/php-subsystem/vendor/composer/installed.json +54 -61
  110. package/php-subsystem/vendor/nikic/php-parser/README.md +55 -59
  111. package/php-subsystem/vendor/nikic/php-parser/composer.json +39 -39
  112. 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.13 linux-x64 node-v16.13.0
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,32 +73,117 @@ or
59
73
  flarum-cli --help
60
74
  ```
61
75
 
62
- # Commands
63
- * `flarum-cli help [COMMAND]`
64
- * `flarum-cli init [PATH]`
65
- * `flarum-cli infra [MODULE] [PATH]`
66
- * `flarum-cli audit infra [--monorepo] [--fix]`
67
- * `flarum-cli make backend api-controller [PATH]`
68
- * `flarum-cli make backend api-serializer [PATH]`
69
- * `flarum-cli make backend api-serializer-attributes [PATH]`
70
- * `flarum-cli make backend command [PATH]`
71
- * `flarum-cli make backend event-listener [PATH]`
72
- * `flarum-cli make backend handler [PATH]`
73
- * `flarum-cli make backend integration-test [PATH]`
74
- * `flarum-cli make backend job [PATH]`
75
- * `flarum-cli make backend migration [PATH]`
76
- * `flarum-cli make backend model [PATH]`
77
- * `flarum-cli make backend policy [PATH]`
78
- * `flarum-cli make backend repository [PATH]`
79
- * `flarum-cli make backend route [PATH]`
80
- * `flarum-cli make backend service-provider [PATH]`
81
- * `flarum-cli make backend validator [PATH]`
82
- * `flarum-cli make frontend component [PATH]`
83
- * `flarum-cli make frontend modal [PATH]`
84
- * `flarum-cli make frontend model [PATH]`
85
- * `flarum-cli update js-imports [PATH]`
86
-
87
- All commands can use a `--no-interaction` flag to proceed with defaults when possible.
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
+ ```
88
187
 
89
188
  ## For Maintainers
90
189
 
@@ -163,7 +262,6 @@ Sharing parameters is done via the following process:
163
262
  - What the param is consumed at
164
263
  - If the param value is falsy, should the consumer step run at all? Useful for variable dependencies.
165
264
 
166
-
167
265
  For example:
168
266
 
169
267
  ```ts
@@ -199,7 +297,6 @@ For example:
199
297
  .run(new Paths({...}), new PromptsIO(), {php: new PhpProvider(...)});
200
298
  ```
201
299
 
202
-
203
300
  #### Step Composability and Atomic Groups
204
301
 
205
302
  As noted above, steps should work by modifying and returning an in-memory filesystem.
@@ -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;
@@ -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
- .run(paths, this.genIO(), { php: phpProvider }, this.dry);
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 === '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,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, 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, 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({ 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
@@ -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
- this.cache.set(paramName, resValue);
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 {};
@@ -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;
@@ -17,28 +17,28 @@ function auditStepFactory(dry, scaffoldDir, modules, templateParams, excludeScaf
17
17
  async run(_fs, paths, io, _providers) {
18
18
  const paramVals = await (0, template_param_1.currParamValues)(templateParams, _fs, paths, io);
19
19
  modulesEnabled = await (0, module_1.currModulesEnabled)(modules, _fs, paths, moduleStatusCache);
20
- const actionableModules = modules.filter(m => m.updatable && modulesEnabled[m.name] && (!m.togglable || !m.dependsOn.some(dep => !modulesEnabled[dep])));
21
- io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, m => chalk_1.default.yellow(chalk_1.default.bold(chalk_1.default.underline(m))), `Auditing infrastructure for ${actionableModules.length} enabled modules:`), true);
20
+ const actionableModules = modules.filter((m) => m.updatable && modulesEnabled[m.name] && (!m.togglable || !m.dependsOn.some((dep) => !modulesEnabled[dep])));
21
+ io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, (m) => chalk_1.default.yellow(chalk_1.default.bold(chalk_1.default.underline(m))), `Auditing infrastructure for ${actionableModules.length} enabled modules:`), true);
22
22
  for (const m of modules) {
23
23
  if (actionableModules.includes(m)) {
24
- io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, m => chalk_1.default.dim(chalk_1.default.green(m)), `✓ ${m.name}: ${m.shortDescription}`), true);
24
+ io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, (m) => chalk_1.default.dim(chalk_1.default.green(m)), `✓ ${m.name}: ${m.shortDescription}`), true);
25
25
  }
26
26
  else if (m.updatable) {
27
- io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, m => chalk_1.default.dim(chalk_1.default.red(m)), `𐄂 ${m.name}: ${m.shortDescription} (disabled)`), true);
27
+ io.info((0, cond_format_1.condFormat)(io.supportsAnsiColor, (m) => chalk_1.default.dim(chalk_1.default.red(m)), `𐄂 ${m.name}: ${m.shortDescription} (disabled)`), true);
28
28
  }
29
29
  }
30
30
  for (const m of actionableModules) {
31
31
  const fs = dry ? (0, mem_fs_1.create)() : _fs;
32
- const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : [];
32
+ const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : { files: [], configKeys: {} };
33
33
  (0, module_1.applyModule)(m, modulesEnabled, paramVals, scaffoldDir, fs, paths, excludeScaffolding, true);
34
34
  if (dry) {
35
35
  const filesWithChanges = fs
36
36
  .all()
37
- .filter(f => f.state && f.state !== 'deleted')
38
- .filter(f => { var _a; return !(0, node_fs_1.existsSync)(f.path) || (0, node_fs_1.readFileSync)(f.path, 'utf8').toString() !== ((_a = f.contents) === null || _a === void 0 ? void 0 : _a.toString()); });
37
+ .filter((f) => f.state && f.state !== 'deleted')
38
+ .filter((f) => { var _a; return !(0, node_fs_1.existsSync)(f.path) || (0, node_fs_1.readFileSync)(f.path, 'utf8').toString() !== ((_a = f.contents) === null || _a === void 0 ? void 0 : _a.toString()); });
39
39
  if (filesWithChanges.length > 0) {
40
40
  io.error(`Module ${m.name} has ${filesWithChanges.length} changed files: ${filesWithChanges
41
- .map(f => f.path.replace(paths.package() + '/', ''))
41
+ .map((f) => f.path.replace(paths.package() + '/', ''))
42
42
  .join(', ')}`, false);
43
43
  }
44
44
  }
@@ -52,9 +52,9 @@ function auditStepFactory(dry, scaffoldDir, modules, templateParams, excludeScaf
52
52
  }
53
53
  return _fs;
54
54
  },
55
- exposes: modules.map(m => `modules.${m.name}`),
55
+ exposes: modules.map((m) => `modules.${m.name}`),
56
56
  getExposed(_paths, _paramProvider) {
57
- return (0, rename_keys_1.renameKeys)(modulesEnabled, k => `modules.${k}`);
57
+ return (0, rename_keys_1.renameKeys)(modulesEnabled, (k) => `modules.${k}`);
58
58
  },
59
59
  };
60
60
  }
@@ -4,7 +4,7 @@ exports.infraStepFactory = void 0;
4
4
  const module_1 = require("./module");
5
5
  const template_param_1 = require("./template-param");
6
6
  function infraStepFactory(scaffoldDir, moduleName, modules, templateParams, excludeScaffoldingFunc, moduleStatusCache) {
7
- const module = modules.find(m => m.name === moduleName);
7
+ const module = modules.find((m) => m.name === moduleName);
8
8
  if (!module) {
9
9
  throw new Error(`Module ${moduleName} not found`);
10
10
  }
@@ -17,7 +17,7 @@ function infraStepFactory(scaffoldDir, moduleName, modules, templateParams, excl
17
17
  if (!module.updatable) {
18
18
  io.error(`${module.name} is not updatable.`, true);
19
19
  }
20
- const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : [];
20
+ const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : { files: [], configKeys: {} };
21
21
  const initializing = !modulesEnabled[module.name];
22
22
  (0, module_1.applyModule)(module, Object.assign(Object.assign({}, modulesEnabled), { [module.name]: true }), paramVals, scaffoldDir, fs, paths, excludeScaffolding, initializing);
23
23
  if (moduleStatusCache) {
@@ -12,22 +12,22 @@ function initStepFactory(scaffoldDir, modules, templateParams, excludeScaffoldin
12
12
  async run(fs, paths, io, _providers) {
13
13
  const paramVals = await (0, template_param_1.promptParamValues)(templateParams, paths, io);
14
14
  modulesEnabled = await (0, module_1.promptModulesEnabled)(modules, io);
15
- const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : [];
15
+ const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : { files: [], configKeys: {} };
16
16
  for (const m of modules) {
17
- if (modulesEnabled[m.name] && (!m.togglable || !m.dependsOn.some(dep => !modulesEnabled[dep]))) {
17
+ if (modulesEnabled[m.name] && (!m.togglable || !m.dependsOn.some((dep) => !modulesEnabled[dep]))) {
18
18
  (0, module_1.applyModule)(m, modulesEnabled, paramVals, scaffoldDir, fs, paths, excludeScaffolding, true);
19
19
  }
20
20
  }
21
21
  if (moduleStatusCache) {
22
- modules.forEach(m => {
22
+ modules.forEach((m) => {
23
23
  (0, module_1.setModuleValue)(m, modulesEnabled[m.name], fs, paths, moduleStatusCache);
24
24
  });
25
25
  }
26
26
  return fs;
27
27
  },
28
- exposes: modules.map(m => `modules.${m.name}`),
28
+ exposes: modules.map((m) => `modules.${m.name}`),
29
29
  getExposed(_paths, _paramProvider) {
30
- return (0, rename_keys_1.renameKeys)(modulesEnabled, k => `modules.${k}`);
30
+ return (0, rename_keys_1.renameKeys)(modulesEnabled, (k) => `modules.${k}`);
31
31
  },
32
32
  };
33
33
  }