@flarum/cli 1.0.0 → 2.0.0-beta.12

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 (193) hide show
  1. package/README.md +2 -2
  2. package/bin/run +5 -3
  3. package/boilerplate/skeleton/extension/.gitattributes +17 -3
  4. package/boilerplate/skeleton/extension/.github/workflows/backend.yml +15 -0
  5. package/boilerplate/skeleton/extension/.github/workflows/frontend.yml +20 -0
  6. package/boilerplate/skeleton/extension/.styleci.yml +14 -0
  7. package/boilerplate/skeleton/extension/LICENSE.md +1 -0
  8. package/boilerplate/skeleton/extension/README.md +7 -7
  9. package/boilerplate/skeleton/extension/composer.json +11 -9
  10. package/boilerplate/skeleton/extension/extend.php +10 -10
  11. package/boilerplate/skeleton/extension/gitignore +12 -0
  12. package/boilerplate/skeleton/extension/js/.bundlewatch.config.json +8 -0
  13. package/boilerplate/skeleton/extension/js/admin.js +2 -1
  14. package/boilerplate/skeleton/extension/js/admin.ts +2 -0
  15. package/boilerplate/skeleton/extension/js/forum.js +2 -1
  16. package/boilerplate/skeleton/extension/js/forum.ts +2 -0
  17. package/boilerplate/skeleton/extension/js/gitignore +9 -0
  18. package/boilerplate/skeleton/extension/js/package.json +13 -9
  19. package/boilerplate/skeleton/extension/js/src/admin/index.js +4 -2
  20. package/boilerplate/skeleton/extension/js/src/admin/index.ts +5 -0
  21. package/boilerplate/skeleton/extension/js/src/common/index.js +5 -0
  22. package/boilerplate/skeleton/extension/js/src/common/index.ts +5 -0
  23. package/boilerplate/skeleton/extension/js/src/forum/index.js +4 -2
  24. package/boilerplate/skeleton/extension/js/src/forum/index.ts +5 -0
  25. package/boilerplate/skeleton/extension/js/tsconfig.json +6 -1
  26. package/boilerplate/skeleton/extension/locale/en.yml +1 -1
  27. package/boilerplate/stubs/migration.php +1 -1
  28. package/lib/base-command.d.ts +29 -6
  29. package/lib/base-command.js +145 -59
  30. package/lib/boilersmith/exposed-param-manager.d.ts +8 -0
  31. package/lib/boilersmith/exposed-param-manager.js +31 -0
  32. package/lib/boilersmith/io.d.ts +54 -0
  33. package/lib/boilersmith/io.js +97 -0
  34. package/lib/boilersmith/paths.d.ts +22 -0
  35. package/lib/boilersmith/paths.js +29 -0
  36. package/lib/boilersmith/scaffolding/audit-step-factory.d.ts +5 -0
  37. package/lib/boilersmith/scaffolding/audit-step-factory.js +61 -0
  38. package/lib/boilersmith/scaffolding/infra-step-factory.d.ts +5 -0
  39. package/lib/boilersmith/scaffolding/infra-step-factory.js +34 -0
  40. package/lib/boilersmith/scaffolding/init-step-factory.d.ts +5 -0
  41. package/lib/boilersmith/scaffolding/init-step-factory.js +34 -0
  42. package/lib/boilersmith/scaffolding/module.d.ts +82 -0
  43. package/lib/boilersmith/scaffolding/module.js +116 -0
  44. package/lib/boilersmith/scaffolding/scaffolder.d.ts +32 -0
  45. package/lib/boilersmith/scaffolding/scaffolder.js +203 -0
  46. package/lib/boilersmith/scaffolding/template-param.d.ts +23 -0
  47. package/lib/boilersmith/scaffolding/template-param.js +46 -0
  48. package/lib/boilersmith/step-manager.d.ts +85 -0
  49. package/lib/boilersmith/step-manager.js +234 -0
  50. package/lib/boilersmith/steps/stub-base.d.ts +53 -0
  51. package/lib/boilersmith/steps/stub-base.js +54 -0
  52. package/lib/{utils → boilersmith/utils}/clone-and-fill.d.ts +0 -0
  53. package/lib/{utils → boilersmith/utils}/clone-and-fill.js +2 -2
  54. package/lib/boilersmith/utils/cond-format.d.ts +1 -0
  55. package/lib/boilersmith/utils/cond-format.js +8 -0
  56. package/lib/boilersmith/utils/json-leaf-paths.d.ts +7 -0
  57. package/lib/boilersmith/utils/json-leaf-paths.js +17 -0
  58. package/lib/boilersmith/utils/read-tpl.d.ts +2 -0
  59. package/lib/boilersmith/utils/read-tpl.js +10 -0
  60. package/lib/boilersmith/utils/rename-keys.d.ts +1 -0
  61. package/lib/boilersmith/utils/rename-keys.js +7 -0
  62. package/lib/commands/audit/infra.d.ts +16 -0
  63. package/lib/commands/audit/infra.js +27 -0
  64. package/lib/commands/infra.d.ts +20 -0
  65. package/lib/commands/infra.js +55 -0
  66. package/lib/commands/init.d.ts +4 -3
  67. package/lib/commands/init.js +8 -6
  68. package/lib/commands/make/backend/api-controller.d.ts +4 -3
  69. package/lib/commands/make/backend/api-controller.js +3 -2
  70. package/lib/commands/make/backend/api-serializer-attributes.d.ts +4 -3
  71. package/lib/commands/make/backend/api-serializer-attributes.js +1 -1
  72. package/lib/commands/make/backend/api-serializer.d.ts +4 -3
  73. package/lib/commands/make/backend/api-serializer.js +3 -2
  74. package/lib/commands/make/backend/command.d.ts +4 -3
  75. package/lib/commands/make/backend/command.js +3 -2
  76. package/lib/commands/make/backend/event-listener.d.ts +4 -3
  77. package/lib/commands/make/backend/event-listener.js +3 -2
  78. package/lib/commands/make/backend/handler.d.ts +4 -3
  79. package/lib/commands/make/backend/handler.js +4 -3
  80. package/lib/commands/make/backend/integration-test.d.ts +4 -3
  81. package/lib/commands/make/backend/integration-test.js +3 -2
  82. package/lib/commands/make/backend/job.d.ts +4 -3
  83. package/lib/commands/make/backend/job.js +3 -2
  84. package/lib/commands/make/backend/migration.d.ts +4 -3
  85. package/lib/commands/make/backend/migration.js +3 -2
  86. package/lib/commands/make/backend/model.d.ts +4 -3
  87. package/lib/commands/make/backend/model.js +22 -21
  88. package/lib/commands/make/backend/policy.d.ts +4 -3
  89. package/lib/commands/make/backend/policy.js +3 -2
  90. package/lib/commands/make/backend/repository.d.ts +4 -3
  91. package/lib/commands/make/backend/repository.js +3 -2
  92. package/lib/commands/make/backend/route.d.ts +4 -3
  93. package/lib/commands/make/backend/route.js +1 -1
  94. package/lib/commands/make/backend/service-provider.d.ts +4 -3
  95. package/lib/commands/make/backend/service-provider.js +3 -2
  96. package/lib/commands/make/backend/validator.d.ts +4 -3
  97. package/lib/commands/make/backend/validator.js +3 -2
  98. package/lib/commands/make/frontend/component.d.ts +4 -3
  99. package/lib/commands/make/frontend/component.js +3 -2
  100. package/lib/commands/make/frontend/modal.d.ts +4 -3
  101. package/lib/commands/make/frontend/modal.js +3 -2
  102. package/lib/commands/make/frontend/model.d.ts +4 -3
  103. package/lib/commands/make/frontend/model.js +3 -2
  104. package/lib/commands/update/js-imports.d.ts +4 -3
  105. package/lib/commands/update/js-imports.js +1 -1
  106. package/lib/help.d.ts +5 -6
  107. package/lib/help.js +5 -4
  108. package/lib/index.d.ts +1 -1
  109. package/lib/index.js +3 -2
  110. package/lib/providers/index.d.ts +5 -0
  111. package/lib/providers/index.js +2 -0
  112. package/lib/{provider → providers}/php-provider.d.ts +0 -0
  113. package/lib/{provider → providers}/php-provider.js +2 -2
  114. package/lib/steps/extenders/api-serializer.js +2 -3
  115. package/lib/steps/extenders/base.d.ts +10 -10
  116. package/lib/steps/extenders/base.js +11 -11
  117. package/lib/steps/extenders/console-command.js +2 -3
  118. package/lib/steps/extenders/event.js +2 -3
  119. package/lib/steps/extenders/policy.js +2 -3
  120. package/lib/steps/extenders/route.js +2 -3
  121. package/lib/steps/extenders/service-provider.js +2 -3
  122. package/lib/steps/gen-ext-scaffolder.d.ts +6 -0
  123. package/lib/steps/gen-ext-scaffolder.js +594 -0
  124. package/lib/steps/js/base.d.ts +9 -9
  125. package/lib/steps/js/base.js +13 -12
  126. package/lib/steps/js/model.d.ts +5 -5
  127. package/lib/steps/js/model.js +8 -13
  128. package/lib/steps/misc/composer.d.ts +5 -6
  129. package/lib/steps/misc/composer.js +3 -3
  130. package/lib/steps/misc/git.d.ts +11 -0
  131. package/lib/steps/misc/git.js +20 -0
  132. package/lib/steps/misc/yarn.d.ts +5 -6
  133. package/lib/steps/misc/yarn.js +3 -3
  134. package/lib/steps/stubs/backend/api-controller.d.ts +1 -8
  135. package/lib/steps/stubs/backend/api-controller.js +2 -3
  136. package/lib/steps/stubs/backend/api-serializer.d.ts +4 -9
  137. package/lib/steps/stubs/backend/api-serializer.js +4 -4
  138. package/lib/steps/stubs/backend/command.d.ts +0 -5
  139. package/lib/steps/stubs/backend/command.js +1 -1
  140. package/lib/steps/stubs/backend/event-listener.d.ts +0 -5
  141. package/lib/steps/stubs/backend/event-listener.js +1 -1
  142. package/lib/steps/stubs/backend/handler-command.js +1 -1
  143. package/lib/steps/stubs/backend/handler.js +1 -1
  144. package/lib/steps/stubs/backend/migration.d.ts +4 -5
  145. package/lib/steps/stubs/backend/migration.js +8 -8
  146. package/lib/steps/stubs/backend/model.d.ts +4 -4
  147. package/lib/steps/stubs/backend/model.js +4 -4
  148. package/lib/steps/stubs/backend/policy.d.ts +0 -5
  149. package/lib/steps/stubs/backend/policy.js +1 -1
  150. package/lib/steps/stubs/backend/repository.d.ts +0 -5
  151. package/lib/steps/stubs/backend/repository.js +1 -1
  152. package/lib/steps/stubs/flarum-base.d.ts +9 -0
  153. package/lib/steps/stubs/flarum-base.js +10 -0
  154. package/lib/steps/stubs/frontend/component.js +0 -1
  155. package/lib/steps/stubs/frontend/modal.js +0 -1
  156. package/lib/steps/stubs/frontend/model.d.ts +4 -4
  157. package/lib/steps/stubs/frontend/model.js +3 -3
  158. package/lib/steps/stubs/js-base.d.ts +6 -7
  159. package/lib/steps/stubs/js-base.js +11 -16
  160. package/lib/steps/stubs/php-base.d.ts +7 -8
  161. package/lib/steps/stubs/php-base.js +12 -20
  162. package/lib/steps/update/js-imports.d.ts +5 -6
  163. package/lib/steps/update/js-imports.js +16 -19
  164. package/lib/utils/composer.d.ts +64 -0
  165. package/lib/utils/composer.js +8 -0
  166. package/lib/utils/migration.js +3 -3
  167. package/lib/utils/model-name.js +6 -6
  168. package/lib/utils/validation.d.ts +10 -7
  169. package/lib/utils/validation.js +9 -6
  170. package/oclif.manifest.json +1 -1
  171. package/package.json +55 -36
  172. package/php-subsystem/src/NodeVisitors/AddExtender.php +2 -1
  173. package/boilerplate/skeleton/extension/.github/workflows/build.yml +0 -32
  174. package/boilerplate/skeleton/extension/.github/workflows/lint.yml +0 -32
  175. package/boilerplate/skeleton/extension/.github/workflows/test.yml +0 -78
  176. package/lib/commands/infra/backend-testing.d.ts +0 -14
  177. package/lib/commands/infra/backend-testing.js +0 -26
  178. package/lib/provider/param-provider.d.ts +0 -15
  179. package/lib/provider/param-provider.js +0 -39
  180. package/lib/provider/path-provider.d.ts +0 -19
  181. package/lib/provider/path-provider.js +0 -24
  182. package/lib/steps/infra/backend-testing.d.ts +0 -8
  183. package/lib/steps/infra/backend-testing.js +0 -22
  184. package/lib/steps/infra/base.d.ts +0 -20
  185. package/lib/steps/infra/base.js +0 -36
  186. package/lib/steps/init/extension-skeleton.d.ts +0 -12
  187. package/lib/steps/init/extension-skeleton.js +0 -142
  188. package/lib/steps/step-manager.d.ts +0 -71
  189. package/lib/steps/step-manager.js +0 -173
  190. package/lib/steps/stubs/base.d.ts +0 -49
  191. package/lib/steps/stubs/base.js +0 -58
  192. package/lib/utils/extension-metadata.d.ts +0 -2
  193. package/lib/utils/extension-metadata.js +0 -21
@@ -1,25 +1,36 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocationType = void 0;
3
4
  const tslib_1 = require("tslib");
4
- const command_1 = require("@oclif/command");
5
- const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
6
- const path_1 = require("path");
7
- const prompts_1 = tslib_1.__importDefault(require("prompts"));
8
- const globby_1 = tslib_1.__importDefault(require("globby"));
9
- const child_process_1 = require("child_process");
10
- const fs_1 = require("fs");
11
- const param_provider_1 = require("./provider/param-provider");
12
- const step_manager_1 = require("./steps/step-manager");
13
- const path_provider_1 = require("./provider/path-provider");
14
- const php_provider_1 = require("./provider/php-provider");
15
- const chalk_1 = tslib_1.__importDefault(require("chalk"));
16
- class BaseCommand extends command_1.Command {
5
+ const core_1 = require("@oclif/core");
6
+ const cli_ux_1 = (0, tslib_1.__importDefault)(require("cli-ux"));
7
+ const node_path_1 = require("node:path");
8
+ const globby_1 = (0, tslib_1.__importDefault)(require("globby"));
9
+ const node_child_process_1 = require("node:child_process");
10
+ const node_fs_1 = require("node:fs");
11
+ const io_1 = require("boilersmith/io");
12
+ const step_manager_1 = require("boilersmith/step-manager");
13
+ const paths_1 = require("boilersmith/paths");
14
+ const php_provider_1 = require("./providers/php-provider");
15
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
16
+ const errors_1 = require("@oclif/errors");
17
+ var LocationType;
18
+ (function (LocationType) {
19
+ LocationType[LocationType["FLARUM_EXTENSION"] = 0] = "FLARUM_EXTENSION";
20
+ LocationType[LocationType["FLARUM_CORE"] = 1] = "FLARUM_CORE";
21
+ LocationType[LocationType["FLARUM_MONOREPO"] = 2] = "FLARUM_MONOREPO";
22
+ })(LocationType = exports.LocationType || (exports.LocationType = {}));
23
+ class BaseCommand extends core_1.Command {
17
24
  constructor() {
18
25
  super(...arguments);
26
+ this.STUB_PATH = (0, node_path_1.resolve)(__dirname, '../boilerplate/stubs/');
27
+ this.dry = false;
19
28
  this.requireExistingExtension = true;
20
29
  }
21
30
  async run() {
22
- const { args } = this.parse(this.constructor);
31
+ const { args, flags } = await this.parse(this.constructor);
32
+ this.args = args;
33
+ this.flags = flags;
23
34
  const path = args.path;
24
35
  const welcomeMessage = this.welcomeMessage();
25
36
  if (welcomeMessage) {
@@ -27,24 +38,65 @@ class BaseCommand extends command_1.Command {
27
38
  }
28
39
  let extRoot;
29
40
  if (this.requireExistingExtension) {
30
- extRoot = await this.getFlarumExtensionRoot(path || process.cwd());
41
+ const rootData = await this.getFlarumExtensionRoot(path || process.cwd());
42
+ extRoot = rootData.path;
43
+ this.locationType = rootData.type;
31
44
  await this.confirmExtDir(extRoot);
32
45
  }
33
46
  else {
34
47
  extRoot = path || process.cwd();
35
48
  }
36
49
  await this.additionalPreRunChecks(extRoot);
37
- const pathProvider = new path_provider_1.PathFsProvider({
50
+ const paths = new paths_1.NodePaths({
38
51
  requestedDir: path,
39
- ext: extRoot,
52
+ package: extRoot,
40
53
  });
41
- const phpProvider = new php_provider_1.PhpSubsystemProvider(path_1.resolve(__dirname, '../php-subsystem/index.php'));
42
- const completed = await this.steps(new step_manager_1.StepManager())
43
- .run(pathProvider, param_provider_1.paramProviderFactory, phpProvider);
54
+ const phpProvider = new php_provider_1.PhpSubsystemProvider((0, node_path_1.resolve)(__dirname, '../php-subsystem/index.php'));
55
+ const out = await this.steps(new step_manager_1.StepManager())
56
+ .run(paths, this.genIO(), { php: phpProvider }, this.dry);
57
+ const errorMessages = out.messages.filter(m => m.type === 'error');
44
58
  this.log('\n\n');
45
- this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.green('Success! The following steps were completed:'))));
46
- completed.forEach(stepName => this.log(`- ${chalk_1.default.dim(stepName)}`));
59
+ if (out.succeeded && errorMessages.length === 0) {
60
+ this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.green('Success! The following steps were completed:'))));
61
+ }
62
+ else if (out.succeeded) {
63
+ this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.yellow('All steps completed, but with some errors:'))));
64
+ for (const message of errorMessages) {
65
+ this.log(chalk_1.default.dim(chalk_1.default.red(message.message)));
66
+ }
67
+ this.log(chalk_1.default.bold(chalk_1.default.yellow('The steps that completed were:')));
68
+ }
69
+ else if (out.error === 'EEXIT: 0') {
70
+ this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.red('Exiting.'))));
71
+ if (out.stepsRan.length > 0) {
72
+ this.log(chalk_1.default.bold(chalk_1.default.yellow('Before the exit, the following steps were completed:')));
73
+ }
74
+ }
75
+ else {
76
+ this.log(chalk_1.default.bold(chalk_1.default.underline(chalk_1.default.red('Error occurred, and could not complete:'))));
77
+ this.log(chalk_1.default.red(out.error));
78
+ if (out.errorTrace) {
79
+ this.log(chalk_1.default.dim(chalk_1.default.red(out.errorTrace)));
80
+ }
81
+ if (out.stepsRan.length > 0) {
82
+ this.log('');
83
+ this.log(chalk_1.default.bold(chalk_1.default.yellow('Before the error, the following steps were completed:')));
84
+ }
85
+ }
86
+ for (const stepName of out.stepsRan)
87
+ this.log(`- ${chalk_1.default.dim(stepName)}`);
47
88
  this.log('');
89
+ const nonErrorMessages = out.messages.filter(m => m.type !== 'error');
90
+ if (nonErrorMessages.length > 0) {
91
+ this.log('');
92
+ this.log('The following messages were generated during execution:');
93
+ for (const message of nonErrorMessages) {
94
+ this.log(message.message);
95
+ }
96
+ }
97
+ if (!out.succeeded || errorMessages.length > 0) {
98
+ this.exit(1);
99
+ }
48
100
  const goodbyeMessage = this.goodbyeMessage();
49
101
  if (goodbyeMessage) {
50
102
  this.log(goodbyeMessage);
@@ -62,43 +114,76 @@ class BaseCommand extends command_1.Command {
62
114
  // ----------------------------------------------------------------
63
115
  // Confirmation
64
116
  // ----------------------------------------------------------------
117
+ genIO() {
118
+ return new io_1.PromptsIO({}, [], this.flags['no-interaction'], errors_1.exit);
119
+ }
120
+ monorepoPaths(options) {
121
+ 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
+ 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 : []),
129
+ ];
130
+ }
131
+ catch (_a) {
132
+ this.error('Could not run monorepo command: `flarum-monorepo.json` file is missing or invalid.');
133
+ }
134
+ }
135
+ isFlarumCore(path) {
136
+ try {
137
+ const composerJsonPath = (0, node_path_1.resolve)(path, 'composer.json');
138
+ const val = JSON.parse((0, node_fs_1.readFileSync)(composerJsonPath, 'utf8'));
139
+ return val.name === 'flarum/core';
140
+ }
141
+ catch (_a) {
142
+ return false;
143
+ }
144
+ }
65
145
  async getFlarumExtensionRoot(currDir) {
66
- let currPath = path_1.resolve(currDir);
146
+ let currPath = (0, node_path_1.resolve)(currDir);
67
147
  while (currPath !== '/') {
68
- if (fs_1.existsSync(path_1.resolve(currPath, 'composer.json')) && fs_1.existsSync(path_1.resolve(currPath, 'extend.php'))) {
69
- return currPath;
148
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(currPath, 'flarum-monorepo.json'))) {
149
+ return { path: currPath, type: LocationType.FLARUM_MONOREPO };
150
+ }
151
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(currPath, 'composer.json')) && (0, node_fs_1.existsSync)((0, node_path_1.resolve)(currPath, 'extend.php'))) {
152
+ return { path: currPath, type: LocationType.FLARUM_EXTENSION };
153
+ }
154
+ if (this.isFlarumCore(currPath)) {
155
+ return { path: currPath, type: LocationType.FLARUM_CORE };
70
156
  }
71
- currPath = path_1.resolve(currPath, '..');
157
+ currPath = (0, node_path_1.resolve)(currPath, '..');
72
158
  }
73
- this.error(`${path_1.resolve(currDir)} is not located in a valid Flarum extension! Flarum extensions must contain (at a minimum) 'extend.php' and 'composer.json' files.`);
159
+ this.error(`${(0, node_path_1.resolve)(currDir)} is not located in a valid Flarum package!
160
+ - Flarum extensions must contain (at a minimum) 'extend.php' and 'composer.json' files.
161
+ - Flarum core must contain a 'composer.json' file with the name 'flarum/core'.
162
+ - Flarum monorepos must have a valid 'flarum-monorepo.json' file`);
74
163
  }
75
164
  async confirmExtDir(extRoot) {
76
- const response = await prompts_1.default([
77
- {
78
- name: 'verify',
79
- type: 'confirm',
80
- message: `Work in Flarum extension located at ${path_1.resolve(extRoot)}?`,
81
- initial: true,
82
- },
83
- ], param_provider_1.PROMPTS_OPTIONS);
84
- if (!response.verify)
165
+ const verify = await this.genIO().getParam({
166
+ name: 'verify',
167
+ type: 'confirm',
168
+ message: `Work in Flarum package located at ${(0, node_path_1.resolve)(extRoot)}?`,
169
+ initial: true,
170
+ });
171
+ if (!verify)
85
172
  this.exit();
86
173
  }
87
174
  async ensureComposerInstallRan(extRoot) {
88
- if (fs_1.existsSync(path_1.resolve(extRoot, 'vendor/flarum/core/composer.json')))
175
+ if ((0, node_fs_1.existsSync)((0, node_path_1.resolve)(extRoot, 'vendor/flarum/core/composer.json')))
89
176
  return;
90
177
  this.log("This command requires `composer install` to have been ran in your extension's root directory.");
91
- const response = await prompts_1.default([
92
- {
93
- name: 'composer',
94
- type: 'confirm',
95
- message: 'Would you like me to take care of that for you?',
96
- initial: true,
97
- },
98
- ], param_provider_1.PROMPTS_OPTIONS);
99
- if (response.composer) {
178
+ const composer = await this.genIO().getParam({
179
+ name: 'composer',
180
+ type: 'confirm',
181
+ message: 'Would you like me to take care of that for you?',
182
+ initial: true,
183
+ });
184
+ if (composer) {
100
185
  cli_ux_1.default.action.start('Installing composer packages');
101
- child_process_1.execSync('composer install', { cwd: extRoot });
186
+ (0, node_child_process_1.execSync)('composer install', { cwd: extRoot });
102
187
  cli_ux_1.default.action.stop();
103
188
  }
104
189
  else {
@@ -111,29 +196,30 @@ class BaseCommand extends command_1.Command {
111
196
  * If user says no, will exit and not return anything.
112
197
  */
113
198
  async confirmOverrideFiles(dir, pattern, confirmationMessage) {
114
- const files = await globby_1.default(path_1.resolve(dir, pattern));
199
+ 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)));
115
201
  const empty = files.length === 0 || (files.length === 1 && files[0] === '.git');
116
202
  if (empty)
117
203
  return false;
118
- const response = await prompts_1.default([
119
- {
120
- name: 'overwrite',
121
- type: 'confirm',
122
- message: confirmationMessage,
123
- },
124
- ], param_provider_1.PROMPTS_OPTIONS);
125
- if (response.overwrite === false)
204
+ const overwrite = await this.genIO().getParam({
205
+ name: 'overwrite',
206
+ type: 'confirm',
207
+ message: confirmationMessage,
208
+ initial: true,
209
+ });
210
+ if (overwrite === false)
126
211
  this.exit();
127
212
  return true;
128
213
  }
129
214
  async deleteFiles(dir, pattern) {
130
- const pathsToDelete = await globby_1.default(path_1.resolve(dir, pattern));
131
- pathsToDelete.forEach(fs_1.unlinkSync);
215
+ const pathsToDelete = await (0, globby_1.default)((0, node_path_1.resolve)(dir, pattern));
216
+ pathsToDelete.forEach(node_fs_1.unlinkSync);
132
217
  }
133
218
  }
134
219
  exports.default = BaseCommand;
135
220
  BaseCommand.flags = {
136
- help: command_1.flags.help({ char: 'h' }),
221
+ 'no-interaction': core_1.Flags.boolean({ char: 'n', description: 'Do not ask any interactive questions, assume defaults. When impossible, error.', default: false }),
222
+ help: core_1.Flags.help({ char: 'h' }),
137
223
  };
138
224
  BaseCommand.args = [
139
225
  {
@@ -0,0 +1,8 @@
1
+ export declare class ExposedParamManager {
2
+ protected stepsRan: Set<string>;
3
+ protected exposedParams: Map<string, unknown>;
4
+ stepRan(stepName: string, packagePath?: string): boolean;
5
+ has(stepName: string, paramName: string, packagePath?: string): boolean;
6
+ get<T = unknown>(stepName: string, paramName: string, packagePath?: string): T;
7
+ add(stepName: string, params: Record<string, unknown>, packagePath?: string): void;
8
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExposedParamManager = void 0;
4
+ function ranKey(stepName, packagePath = '') {
5
+ return JSON.stringify([stepName, packagePath]);
6
+ }
7
+ function paramKey(stepName, paramName, packagePath = '') {
8
+ return JSON.stringify([stepName, paramName, packagePath]);
9
+ }
10
+ class ExposedParamManager {
11
+ constructor() {
12
+ this.stepsRan = new Set();
13
+ this.exposedParams = new Map();
14
+ }
15
+ stepRan(stepName, packagePath) {
16
+ return this.stepsRan.has(ranKey(stepName, packagePath));
17
+ }
18
+ has(stepName, paramName, packagePath) {
19
+ return this.exposedParams.has(paramKey(stepName, paramName, packagePath));
20
+ }
21
+ get(stepName, paramName, packagePath) {
22
+ return this.exposedParams.get(paramKey(stepName, paramName, packagePath));
23
+ }
24
+ add(stepName, params, packagePath) {
25
+ this.stepsRan.add(ranKey(stepName, packagePath));
26
+ Object.entries(params).forEach(([paramName, value]) => {
27
+ this.exposedParams.set(paramKey(stepName, paramName, packagePath), value);
28
+ });
29
+ }
30
+ }
31
+ exports.ExposedParamManager = ExposedParamManager;
@@ -0,0 +1,54 @@
1
+ import { PromptObject } from 'prompts';
2
+ export declare type ParamDef<N extends string = string> = Omit<PromptObject<N>, 'name'> & {
3
+ name: N;
4
+ };
5
+ export declare type Message = {
6
+ type: 'info' | 'warning' | 'error';
7
+ message: string;
8
+ };
9
+ export interface IO {
10
+ supportsAnsiColor: boolean;
11
+ /**
12
+ * Prompt the user for some input data.
13
+ */
14
+ getParam<T>(param: ParamDef): Promise<T>;
15
+ /**
16
+ * Check if some data has already been prompted for.
17
+ */
18
+ hasCached(name: string): boolean;
19
+ /**
20
+ * Get all cached params.
21
+ */
22
+ cached(): Record<string, unknown>;
23
+ info(message: string, immediate: boolean): void;
24
+ warning(message: string, immediate: boolean): void;
25
+ error(message: string, immediate: boolean): void;
26
+ /**
27
+ * Get all messages that have been logged non-immediately.
28
+ */
29
+ getOutput(): Message[];
30
+ newInstance(cache: Record<string, unknown>, messages: Message[]): IO;
31
+ }
32
+ declare type OnCancel = () => void;
33
+ export declare class PromptsIO implements IO {
34
+ supportsAnsiColor: boolean;
35
+ private cache;
36
+ private messages;
37
+ private noInteraction;
38
+ private onCancel?;
39
+ private prev?;
40
+ constructor(initial?: Record<string, unknown>, messages?: Message[], noInteraction?: boolean, onCancel?: OnCancel);
41
+ getParam<T>(paramDef: ParamDef): Promise<T>;
42
+ hasCached(name: string): boolean;
43
+ /**
44
+ * @internal
45
+ */
46
+ cached(): Record<string, unknown>;
47
+ info(message: string, immediate: boolean): void;
48
+ warning(message: string, immediate: boolean): void;
49
+ error(message: string, immediate: false): void;
50
+ error(message: string, immediate: true): never;
51
+ getOutput(): Message[];
52
+ newInstance(cache: Record<string, unknown>, messages: Message[]): PromptsIO;
53
+ }
54
+ export {};
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PromptsIO = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const prompts_1 = (0, tslib_1.__importDefault)(require("prompts"));
6
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
7
+ class PromptsIO {
8
+ constructor(initial = {}, messages = [], noInteraction = false, onCancel = () => {
9
+ throw new Error('EEXIT: 0');
10
+ }) {
11
+ this.supportsAnsiColor = true;
12
+ this.cache = new Map();
13
+ this.cache = new Map(Object.entries(initial));
14
+ this.messages = messages;
15
+ this.noInteraction = noInteraction;
16
+ this.onCancel = onCancel;
17
+ }
18
+ async getParam(paramDef) {
19
+ var _a, _b, _c;
20
+ const paramName = paramDef.name;
21
+ if (this.cache.has(paramName)) {
22
+ return this.cache.get(paramName);
23
+ }
24
+ let resValue;
25
+ if (this.noInteraction) {
26
+ if (paramDef.initial && paramDef.initial instanceof Function) {
27
+ resValue = paramDef.initial((_a = this.prev) === null || _a === void 0 ? void 0 : _a.val, this.cache, (_b = this.prev) === null || _b === void 0 ? void 0 : _b.prompt);
28
+ }
29
+ else if (paramDef.type === 'confirm' || paramDef.type === 'toggle') {
30
+ resValue = ((_c = paramDef.initial) !== null && _c !== void 0 ? _c : false);
31
+ }
32
+ else if ('initial' in paramDef) {
33
+ resValue = paramDef.initial;
34
+ }
35
+ else {
36
+ return this.error(`No-Interaction mode is on, but input is required for param "${paramName}".`, true);
37
+ }
38
+ }
39
+ else {
40
+ const res = (await (0, prompts_1.default)(paramDef, {
41
+ onCancel: this.onCancel,
42
+ }));
43
+ resValue = res[paramName];
44
+ }
45
+ this.cache.set(paramName, resValue);
46
+ this.prev = {
47
+ val: resValue,
48
+ prompt: paramDef,
49
+ };
50
+ return resValue;
51
+ }
52
+ hasCached(name) {
53
+ return this.cache.has(name);
54
+ }
55
+ /**
56
+ * @internal
57
+ */
58
+ cached() {
59
+ return [...this.cache].reduce((obj, [key, value]) => {
60
+ obj[key] = value;
61
+ return obj;
62
+ }, {});
63
+ }
64
+ info(message, immediate) {
65
+ if (immediate) {
66
+ console.log(message);
67
+ }
68
+ else {
69
+ this.messages.push({ type: 'info', message });
70
+ }
71
+ }
72
+ warning(message, immediate) {
73
+ const formatted = `${chalk_1.default.yellow('Warning:')} ${message}`;
74
+ if (immediate) {
75
+ console.log(formatted);
76
+ }
77
+ else {
78
+ this.messages.push({ type: 'warning', message: formatted });
79
+ }
80
+ }
81
+ error(message, immediate) {
82
+ const formatted = `${chalk_1.default.red('Error:')} ${message}`;
83
+ if (immediate) {
84
+ throw new Error(message);
85
+ }
86
+ else {
87
+ this.messages.push({ type: 'error', message: formatted });
88
+ }
89
+ }
90
+ getOutput() {
91
+ return this.messages;
92
+ }
93
+ newInstance(cache, messages) {
94
+ return new PromptsIO(cache, messages, this.noInteraction, this.onCancel);
95
+ }
96
+ }
97
+ exports.PromptsIO = PromptsIO;
@@ -0,0 +1,22 @@
1
+ export interface Paths {
2
+ cwd(...path: string[]): string;
3
+ package(...path: string[]): string;
4
+ requestedDir(...path: string[]): string | null;
5
+ monorepo(...path: string[]): string | null;
6
+ onMonorepoSub(packagePath: string): Paths;
7
+ }
8
+ declare type InternalPaths = {
9
+ package: string;
10
+ monorepo?: string | null;
11
+ requestedDir?: string | null;
12
+ };
13
+ export declare class NodePaths implements Paths {
14
+ protected paths: InternalPaths;
15
+ constructor(paths: InternalPaths);
16
+ cwd(...path: string[]): string;
17
+ package(...path: string[]): string;
18
+ requestedDir(...path: string[]): string | null;
19
+ monorepo(...path: string[]): string | null;
20
+ onMonorepoSub(packagePath: string): NodePaths;
21
+ }
22
+ export {};
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NodePaths = void 0;
4
+ const node_path_1 = require("node:path");
5
+ class NodePaths {
6
+ constructor(paths) {
7
+ this.paths = paths;
8
+ }
9
+ cwd(...path) {
10
+ return (0, node_path_1.resolve)(process.cwd(), ...path);
11
+ }
12
+ package(...path) {
13
+ return (0, node_path_1.resolve)(this.paths.package, ...path);
14
+ }
15
+ requestedDir(...path) {
16
+ if (!this.paths.requestedDir)
17
+ return null;
18
+ return (0, node_path_1.resolve)(this.paths.requestedDir, ...path);
19
+ }
20
+ monorepo(...path) {
21
+ if (!this.paths.monorepo)
22
+ return null;
23
+ return (0, node_path_1.resolve)(this.paths.monorepo, ...path);
24
+ }
25
+ onMonorepoSub(packagePath) {
26
+ return new NodePaths(Object.assign(Object.assign({}, this.paths), { monorepo: this.paths.package, package: packagePath }));
27
+ }
28
+ }
29
+ exports.NodePaths = NodePaths;
@@ -0,0 +1,5 @@
1
+ import { DefaultProviders, Step } from '../step-manager';
2
+ import { Module, ModuleStatusCache } from './module';
3
+ import { TemplateParam } from './template-param';
4
+ import { ExcludeScaffoldingFunc } from './scaffolder';
5
+ export declare function auditStepFactory<MN extends string, Providers extends DefaultProviders>(dry: boolean, scaffoldDir: string, modules: Module<MN>[], templateParams: TemplateParam[], excludeScaffoldingFunc?: ExcludeScaffoldingFunc, moduleStatusCache?: ModuleStatusCache<MN>): Step<Providers>;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.auditStepFactory = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const mem_fs_1 = require("mem-fs");
6
+ const rename_keys_1 = require("../utils/rename-keys");
7
+ const module_1 = require("./module");
8
+ const template_param_1 = require("./template-param");
9
+ const cond_format_1 = require("boilersmith/utils/cond-format");
10
+ const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
11
+ const node_fs_1 = require("node:fs");
12
+ function auditStepFactory(dry, scaffoldDir, modules, templateParams, excludeScaffoldingFunc, moduleStatusCache) {
13
+ let modulesEnabled;
14
+ return {
15
+ type: 'Audit for outdated infrastructure files or config.',
16
+ composable: true,
17
+ async run(_fs, paths, io, _providers) {
18
+ const paramVals = await (0, template_param_1.currParamValues)(templateParams, _fs, paths, io);
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);
22
+ for (const m of modules) {
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);
25
+ }
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);
28
+ }
29
+ }
30
+ for (const m of actionableModules) {
31
+ const fs = dry ? (0, mem_fs_1.create)() : _fs;
32
+ const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : [];
33
+ (0, module_1.applyModule)(m, modulesEnabled, paramVals, scaffoldDir, fs, paths, excludeScaffolding, true);
34
+ if (dry) {
35
+ const filesWithChanges = fs
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()); });
39
+ if (filesWithChanges.length > 0) {
40
+ io.error(`Module ${m.name} has ${filesWithChanges.length} changed files: ${filesWithChanges
41
+ .map(f => f.path.replace(paths.package() + '/', ''))
42
+ .join(', ')}`, false);
43
+ }
44
+ }
45
+ }
46
+ if (!dry) {
47
+ for (const m of modules) {
48
+ if (moduleStatusCache && m.updatable && (actionableModules.includes(m) || m.togglable)) {
49
+ (0, module_1.setModuleValue)(m, actionableModules.includes(m), _fs, paths, moduleStatusCache);
50
+ }
51
+ }
52
+ }
53
+ return _fs;
54
+ },
55
+ exposes: modules.map(m => `modules.${m.name}`),
56
+ getExposed(_paths, _paramProvider) {
57
+ return (0, rename_keys_1.renameKeys)(modulesEnabled, k => `modules.${k}`);
58
+ },
59
+ };
60
+ }
61
+ exports.auditStepFactory = auditStepFactory;
@@ -0,0 +1,5 @@
1
+ import { DefaultProviders, Step } from '../step-manager';
2
+ import { Module, ModuleStatusCache } from './module';
3
+ import { TemplateParam } from './template-param';
4
+ import { ExcludeScaffoldingFunc } from './scaffolder';
5
+ export declare function infraStepFactory<MN extends string, Providers extends DefaultProviders>(scaffoldDir: string, moduleName: string, modules: Module<MN>[], templateParams: TemplateParam[], excludeScaffoldingFunc?: ExcludeScaffoldingFunc, moduleStatusCache?: ModuleStatusCache<MN>): Step<Providers>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.infraStepFactory = void 0;
4
+ const module_1 = require("./module");
5
+ const template_param_1 = require("./template-param");
6
+ function infraStepFactory(scaffoldDir, moduleName, modules, templateParams, excludeScaffoldingFunc, moduleStatusCache) {
7
+ const module = modules.find(m => m.name === moduleName);
8
+ if (!module) {
9
+ throw new Error(`Module ${moduleName} not found`);
10
+ }
11
+ return {
12
+ type: module.shortDescription,
13
+ composable: true,
14
+ async run(fs, paths, io, _providers) {
15
+ const paramVals = await (0, template_param_1.currParamValues)(templateParams, fs, paths, io);
16
+ const modulesEnabled = await (0, module_1.currModulesEnabled)(modules, fs, paths, moduleStatusCache);
17
+ if (!module.updatable) {
18
+ io.error(`${module.name} is not updatable.`, true);
19
+ }
20
+ const excludeScaffolding = excludeScaffoldingFunc ? excludeScaffoldingFunc(fs, paths) : [];
21
+ const initializing = !modulesEnabled[module.name];
22
+ (0, module_1.applyModule)(module, Object.assign(Object.assign({}, modulesEnabled), { [module.name]: true }), paramVals, scaffoldDir, fs, paths, excludeScaffolding, initializing);
23
+ if (moduleStatusCache) {
24
+ (0, module_1.setModuleValue)(module, true, fs, paths, moduleStatusCache);
25
+ }
26
+ return fs;
27
+ },
28
+ exposes: [],
29
+ getExposed(_paths, _paramProvider) {
30
+ return {};
31
+ },
32
+ };
33
+ }
34
+ exports.infraStepFactory = infraStepFactory;
@@ -0,0 +1,5 @@
1
+ import { DefaultProviders, Step } from '../step-manager';
2
+ import { Module, ModuleStatusCache } from './module';
3
+ import { TemplateParam } from './template-param';
4
+ import { ExcludeScaffoldingFunc } from './scaffolder';
5
+ export declare function initStepFactory<MN extends string, Providers extends DefaultProviders>(scaffoldDir: string, modules: Module<MN>[], templateParams: TemplateParam[], excludeScaffoldingFunc?: ExcludeScaffoldingFunc, moduleStatusCache?: ModuleStatusCache<MN>): Step<Providers>;