@flarum/cli 1.0.0 → 2.0.0-beta.4

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