@tsed/cli-core 3.20.16 → 3.21.0-rc.2

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 (298) hide show
  1. package/lib/cjs/CliCore.js +97 -0
  2. package/lib/cjs/CliCore.js.map +1 -0
  3. package/lib/cjs/decorators/command.js +11 -0
  4. package/lib/cjs/decorators/command.js.map +1 -0
  5. package/lib/cjs/decorators/index.js +9 -0
  6. package/lib/cjs/decorators/index.js.map +1 -0
  7. package/lib/cjs/decorators/on.js +13 -0
  8. package/lib/cjs/decorators/on.js.map +1 -0
  9. package/lib/cjs/decorators/onAdd.js +10 -0
  10. package/lib/cjs/decorators/onAdd.js.map +1 -0
  11. package/lib/cjs/decorators/onExec.js +10 -0
  12. package/lib/cjs/decorators/onExec.js.map +1 -0
  13. package/lib/cjs/decorators/onPostInstall.js +10 -0
  14. package/lib/cjs/decorators/onPostInstall.js.map +1 -0
  15. package/lib/cjs/decorators/onPrompt.js +10 -0
  16. package/lib/cjs/decorators/onPrompt.js.map +1 -0
  17. package/lib/cjs/domains/CliError.js +14 -0
  18. package/lib/cjs/domains/CliError.js.map +1 -0
  19. package/lib/cjs/domains/CommandStoreKeys.js +12 -0
  20. package/lib/cjs/domains/CommandStoreKeys.js.map +1 -0
  21. package/lib/cjs/index.js +30 -0
  22. package/lib/cjs/index.js.map +1 -0
  23. package/lib/cjs/interfaces/CliDefaultOptions.js +3 -0
  24. package/lib/cjs/interfaces/CliDefaultOptions.js.map +1 -0
  25. package/lib/cjs/interfaces/CommandMetadata.js +3 -0
  26. package/lib/cjs/interfaces/CommandMetadata.js.map +1 -0
  27. package/lib/cjs/interfaces/CommandParameters.js +3 -0
  28. package/lib/cjs/interfaces/CommandParameters.js.map +1 -0
  29. package/lib/cjs/interfaces/CommandProvider.js +3 -0
  30. package/lib/cjs/interfaces/CommandProvider.js.map +1 -0
  31. package/lib/cjs/interfaces/PackageJson.js +3 -0
  32. package/lib/cjs/interfaces/PackageJson.js.map +1 -0
  33. package/lib/cjs/interfaces/ProjectPreferences.js +10 -0
  34. package/lib/cjs/interfaces/ProjectPreferences.js.map +1 -0
  35. package/lib/cjs/interfaces/Tasks.js +3 -0
  36. package/lib/cjs/interfaces/Tasks.js.map +1 -0
  37. package/lib/cjs/interfaces/index.js +11 -0
  38. package/lib/cjs/interfaces/index.js.map +1 -0
  39. package/lib/cjs/package.json +3 -0
  40. package/lib/cjs/registries/CommandRegistry.js +13 -0
  41. package/lib/cjs/registries/CommandRegistry.js.map +1 -0
  42. package/lib/cjs/services/CliConfiguration.js +21 -0
  43. package/lib/cjs/services/CliConfiguration.js.map +1 -0
  44. package/lib/cjs/services/CliDockerComposeYaml.js +83 -0
  45. package/lib/cjs/services/CliDockerComposeYaml.js.map +1 -0
  46. package/lib/cjs/services/CliExeca.js +45 -0
  47. package/lib/cjs/services/CliExeca.js.map +1 -0
  48. package/lib/cjs/services/CliFs.js +55 -0
  49. package/lib/cjs/services/CliFs.js.map +1 -0
  50. package/lib/cjs/services/CliHooks.js +34 -0
  51. package/lib/cjs/services/CliHooks.js.map +1 -0
  52. package/lib/cjs/services/CliHttpClient.js +107 -0
  53. package/lib/cjs/services/CliHttpClient.js.map +1 -0
  54. package/lib/cjs/services/CliHttpLogClient.js +83 -0
  55. package/lib/cjs/services/CliHttpLogClient.js.map +1 -0
  56. package/lib/cjs/services/CliPackageJson.js +16 -0
  57. package/lib/cjs/services/CliPackageJson.js.map +1 -0
  58. package/lib/cjs/services/CliPlugins.js +78 -0
  59. package/lib/cjs/services/CliPlugins.js.map +1 -0
  60. package/lib/cjs/services/CliProxyAgent.js +87 -0
  61. package/lib/cjs/services/CliProxyAgent.js.map +1 -0
  62. package/lib/cjs/services/CliRunScript.js +31 -0
  63. package/lib/cjs/services/CliRunScript.js.map +1 -0
  64. package/lib/cjs/services/CliService.js +271 -0
  65. package/lib/cjs/services/CliService.js.map +1 -0
  66. package/lib/cjs/services/CliYaml.js +37 -0
  67. package/lib/cjs/services/CliYaml.js.map +1 -0
  68. package/lib/cjs/services/NpmRegistryClient.js +121 -0
  69. package/lib/cjs/services/NpmRegistryClient.js.map +1 -0
  70. package/lib/cjs/services/ProjectPackageJson.js +420 -0
  71. package/lib/cjs/services/ProjectPackageJson.js.map +1 -0
  72. package/lib/cjs/services/Renderer.js +154 -0
  73. package/lib/cjs/services/Renderer.js.map +1 -0
  74. package/lib/cjs/services/index.js +17 -0
  75. package/lib/cjs/services/index.js.map +1 -0
  76. package/lib/cjs/utils/createInjector.js +35 -0
  77. package/lib/cjs/utils/createInjector.js.map +1 -0
  78. package/lib/cjs/utils/createTasksRunner.js +75 -0
  79. package/lib/cjs/utils/createTasksRunner.js.map +1 -0
  80. package/lib/cjs/utils/getCommandMetadata.js +19 -0
  81. package/lib/cjs/utils/getCommandMetadata.js.map +1 -0
  82. package/lib/cjs/utils/getPackageJson.js +38 -0
  83. package/lib/cjs/utils/getPackageJson.js.map +1 -0
  84. package/lib/cjs/utils/hbs/array.js +522 -0
  85. package/lib/cjs/utils/hbs/array.js.map +1 -0
  86. package/lib/cjs/utils/hbs/collection.js +66 -0
  87. package/lib/cjs/utils/hbs/collection.js.map +1 -0
  88. package/lib/cjs/utils/hbs/comparison.js +437 -0
  89. package/lib/cjs/utils/hbs/comparison.js.map +1 -0
  90. package/lib/cjs/utils/hbs/index.js +15 -0
  91. package/lib/cjs/utils/hbs/index.js.map +1 -0
  92. package/lib/cjs/utils/hbs/object.js +245 -0
  93. package/lib/cjs/utils/hbs/object.js.map +1 -0
  94. package/lib/cjs/utils/hbs/switch.js +14 -0
  95. package/lib/cjs/utils/hbs/switch.js.map +1 -0
  96. package/lib/cjs/utils/index.js +14 -0
  97. package/lib/cjs/utils/index.js.map +1 -0
  98. package/lib/cjs/utils/isValidVersion.js +11 -0
  99. package/lib/cjs/utils/isValidVersion.js.map +1 -0
  100. package/lib/cjs/utils/loadPlugins.js +47 -0
  101. package/lib/cjs/utils/loadPlugins.js.map +1 -0
  102. package/lib/cjs/utils/logToCurl.js +19 -0
  103. package/lib/cjs/utils/logToCurl.js.map +1 -0
  104. package/lib/cjs/utils/mapCommanderArgs.js +40 -0
  105. package/lib/cjs/utils/mapCommanderArgs.js.map +1 -0
  106. package/lib/cjs/utils/mapCommanderOptions.js +16 -0
  107. package/lib/cjs/utils/mapCommanderOptions.js.map +1 -0
  108. package/lib/cjs/utils/normalizePath.js +19 -0
  109. package/lib/cjs/utils/normalizePath.js.map +1 -0
  110. package/lib/cjs/utils/parseOption.js +27 -0
  111. package/lib/cjs/utils/parseOption.js.map +1 -0
  112. package/lib/cjs/utils/patchCommander.js +58 -0
  113. package/lib/cjs/utils/patchCommander.js.map +1 -0
  114. package/lib/cjs/utils/renderer/insertAfter.js +17 -0
  115. package/lib/cjs/utils/renderer/insertAfter.js.map +1 -0
  116. package/lib/cjs/utils/renderer/insertImport.js +16 -0
  117. package/lib/cjs/utils/renderer/insertImport.js.map +1 -0
  118. package/lib/esm/CliCore.js +94 -0
  119. package/lib/esm/CliCore.js.map +1 -0
  120. package/lib/esm/decorators/command.js +7 -0
  121. package/lib/esm/decorators/command.js.map +1 -0
  122. package/lib/esm/decorators/index.js +6 -0
  123. package/lib/esm/decorators/index.js.map +1 -0
  124. package/lib/esm/decorators/on.js +9 -0
  125. package/lib/esm/decorators/on.js.map +1 -0
  126. package/lib/esm/decorators/onAdd.js +6 -0
  127. package/lib/esm/decorators/onAdd.js.map +1 -0
  128. package/lib/esm/decorators/onExec.js +6 -0
  129. package/lib/esm/decorators/onExec.js.map +1 -0
  130. package/lib/esm/decorators/onPostInstall.js +6 -0
  131. package/lib/esm/decorators/onPostInstall.js.map +1 -0
  132. package/lib/esm/decorators/onPrompt.js +6 -0
  133. package/lib/esm/decorators/onPrompt.js.map +1 -0
  134. package/lib/esm/domains/CliError.js +10 -0
  135. package/lib/esm/domains/CliError.js.map +1 -0
  136. package/lib/esm/domains/CommandStoreKeys.js +9 -0
  137. package/lib/esm/domains/CommandStoreKeys.js.map +1 -0
  138. package/lib/esm/index.js +12 -0
  139. package/lib/esm/index.js.map +1 -0
  140. package/lib/esm/interfaces/CliDefaultOptions.js +2 -0
  141. package/lib/esm/interfaces/CliDefaultOptions.js.map +1 -0
  142. package/lib/esm/interfaces/CommandMetadata.js +2 -0
  143. package/lib/esm/interfaces/CommandMetadata.js.map +1 -0
  144. package/lib/esm/interfaces/CommandParameters.js +2 -0
  145. package/lib/esm/interfaces/CommandParameters.js.map +1 -0
  146. package/lib/esm/interfaces/CommandProvider.js +2 -0
  147. package/lib/esm/interfaces/CommandProvider.js.map +1 -0
  148. package/lib/esm/interfaces/PackageJson.js +2 -0
  149. package/lib/esm/interfaces/PackageJson.js.map +1 -0
  150. package/lib/esm/interfaces/ProjectPreferences.js +7 -0
  151. package/lib/esm/interfaces/ProjectPreferences.js.map +1 -0
  152. package/lib/esm/interfaces/Tasks.js +2 -0
  153. package/lib/esm/interfaces/Tasks.js.map +1 -0
  154. package/lib/esm/interfaces/index.js +8 -0
  155. package/lib/esm/interfaces/index.js.map +1 -0
  156. package/lib/esm/package.json +3 -0
  157. package/lib/esm/registries/CommandRegistry.js +10 -0
  158. package/lib/esm/registries/CommandRegistry.js.map +1 -0
  159. package/lib/esm/services/CliConfiguration.js +18 -0
  160. package/lib/esm/services/CliConfiguration.js.map +1 -0
  161. package/lib/esm/services/CliDockerComposeYaml.js +80 -0
  162. package/lib/esm/services/CliDockerComposeYaml.js.map +1 -0
  163. package/lib/esm/services/CliExeca.js +42 -0
  164. package/lib/esm/services/CliExeca.js.map +1 -0
  165. package/lib/esm/services/CliFs.js +52 -0
  166. package/lib/esm/services/CliFs.js.map +1 -0
  167. package/lib/esm/services/CliHooks.js +31 -0
  168. package/lib/esm/services/CliHooks.js.map +1 -0
  169. package/lib/esm/services/CliHttpClient.js +104 -0
  170. package/lib/esm/services/CliHttpClient.js.map +1 -0
  171. package/lib/esm/services/CliHttpLogClient.js +80 -0
  172. package/lib/esm/services/CliHttpLogClient.js.map +1 -0
  173. package/lib/esm/services/CliPackageJson.js +12 -0
  174. package/lib/esm/services/CliPackageJson.js.map +1 -0
  175. package/lib/esm/services/CliPlugins.js +75 -0
  176. package/lib/esm/services/CliPlugins.js.map +1 -0
  177. package/lib/esm/services/CliProxyAgent.js +84 -0
  178. package/lib/esm/services/CliProxyAgent.js.map +1 -0
  179. package/lib/esm/services/CliRunScript.js +28 -0
  180. package/lib/esm/services/CliRunScript.js.map +1 -0
  181. package/lib/esm/services/CliService.js +268 -0
  182. package/lib/esm/services/CliService.js.map +1 -0
  183. package/lib/esm/services/CliYaml.js +34 -0
  184. package/lib/esm/services/CliYaml.js.map +1 -0
  185. package/lib/esm/services/NpmRegistryClient.js +117 -0
  186. package/lib/esm/services/NpmRegistryClient.js.map +1 -0
  187. package/lib/esm/services/ProjectPackageJson.js +417 -0
  188. package/lib/esm/services/ProjectPackageJson.js.map +1 -0
  189. package/lib/esm/services/Renderer.js +150 -0
  190. package/lib/esm/services/Renderer.js.map +1 -0
  191. package/lib/esm/services/index.js +14 -0
  192. package/lib/esm/services/index.js.map +1 -0
  193. package/lib/esm/utils/createInjector.js +30 -0
  194. package/lib/esm/utils/createInjector.js.map +1 -0
  195. package/lib/esm/utils/createTasksRunner.js +69 -0
  196. package/lib/esm/utils/createTasksRunner.js.map +1 -0
  197. package/lib/esm/utils/getCommandMetadata.js +15 -0
  198. package/lib/esm/utils/getCommandMetadata.js.map +1 -0
  199. package/lib/esm/utils/getPackageJson.js +33 -0
  200. package/lib/esm/utils/getPackageJson.js.map +1 -0
  201. package/lib/esm/utils/hbs/array.js +518 -0
  202. package/lib/esm/utils/hbs/array.js.map +1 -0
  203. package/lib/esm/utils/hbs/collection.js +62 -0
  204. package/lib/esm/utils/hbs/collection.js.map +1 -0
  205. package/lib/esm/utils/hbs/comparison.js +433 -0
  206. package/lib/esm/utils/hbs/comparison.js.map +1 -0
  207. package/lib/esm/utils/hbs/index.js +12 -0
  208. package/lib/esm/utils/hbs/index.js.map +1 -0
  209. package/lib/esm/utils/hbs/object.js +241 -0
  210. package/lib/esm/utils/hbs/object.js.map +1 -0
  211. package/lib/esm/utils/hbs/switch.js +11 -0
  212. package/lib/esm/utils/hbs/switch.js.map +1 -0
  213. package/lib/esm/utils/index.js +11 -0
  214. package/lib/esm/utils/index.js.map +1 -0
  215. package/lib/esm/utils/isValidVersion.js +6 -0
  216. package/lib/esm/utils/isValidVersion.js.map +1 -0
  217. package/lib/esm/utils/loadPlugins.js +42 -0
  218. package/lib/esm/utils/loadPlugins.js.map +1 -0
  219. package/lib/esm/utils/logToCurl.js +14 -0
  220. package/lib/esm/utils/logToCurl.js.map +1 -0
  221. package/lib/esm/utils/mapCommanderArgs.js +36 -0
  222. package/lib/esm/utils/mapCommanderArgs.js.map +1 -0
  223. package/lib/esm/utils/mapCommanderOptions.js +12 -0
  224. package/lib/esm/utils/mapCommanderOptions.js.map +1 -0
  225. package/lib/esm/utils/normalizePath.js +14 -0
  226. package/lib/esm/utils/normalizePath.js.map +1 -0
  227. package/lib/esm/utils/parseOption.js +23 -0
  228. package/lib/esm/utils/parseOption.js.map +1 -0
  229. package/lib/esm/utils/patchCommander.js +55 -0
  230. package/lib/esm/utils/patchCommander.js.map +1 -0
  231. package/lib/esm/utils/renderer/insertAfter.js +13 -0
  232. package/lib/esm/utils/renderer/insertAfter.js.map +1 -0
  233. package/lib/esm/utils/renderer/insertImport.js +12 -0
  234. package/lib/esm/utils/renderer/insertImport.js.map +1 -0
  235. package/lib/{CliCore.d.ts → types/CliCore.d.ts} +0 -0
  236. package/lib/{decorators → types/decorators}/command.d.ts +0 -0
  237. package/lib/{decorators → types/decorators}/index.d.ts +0 -0
  238. package/lib/{decorators → types/decorators}/on.d.ts +0 -0
  239. package/lib/{decorators → types/decorators}/onAdd.d.ts +0 -0
  240. package/lib/{decorators → types/decorators}/onExec.d.ts +0 -0
  241. package/lib/{decorators → types/decorators}/onPostInstall.d.ts +0 -0
  242. package/lib/{decorators → types/decorators}/onPrompt.d.ts +0 -0
  243. package/lib/{domains → types/domains}/CliError.d.ts +0 -0
  244. package/lib/{domains → types/domains}/CommandStoreKeys.d.ts +0 -0
  245. package/lib/{index.d.ts → types/index.d.ts} +0 -0
  246. package/lib/{interfaces → types/interfaces}/CliDefaultOptions.d.ts +0 -0
  247. package/lib/{interfaces → types/interfaces}/CommandMetadata.d.ts +0 -0
  248. package/lib/{interfaces → types/interfaces}/CommandParameters.d.ts +0 -0
  249. package/lib/{interfaces → types/interfaces}/CommandProvider.d.ts +0 -0
  250. package/lib/{interfaces → types/interfaces}/PackageJson.d.ts +0 -0
  251. package/lib/{interfaces → types/interfaces}/ProjectPreferences.d.ts +0 -0
  252. package/lib/{interfaces → types/interfaces}/Tasks.d.ts +0 -0
  253. package/lib/{interfaces → types/interfaces}/index.d.ts +0 -0
  254. package/lib/{registries → types/registries}/CommandRegistry.d.ts +0 -0
  255. package/lib/{services → types/services}/CliConfiguration.d.ts +0 -0
  256. package/lib/{services → types/services}/CliDockerComposeYaml.d.ts +0 -0
  257. package/lib/{services → types/services}/CliExeca.d.ts +1 -0
  258. package/lib/{services → types/services}/CliFs.d.ts +1 -0
  259. package/lib/{services → types/services}/CliHooks.d.ts +0 -0
  260. package/lib/{services → types/services}/CliHttpClient.d.ts +0 -0
  261. package/lib/{services → types/services}/CliHttpLogClient.d.ts +0 -0
  262. package/lib/{services → types/services}/CliPackageJson.d.ts +0 -0
  263. package/lib/{services → types/services}/CliPlugins.d.ts +0 -0
  264. package/lib/{services → types/services}/CliProxyAgent.d.ts +0 -0
  265. package/lib/{services → types/services}/CliRunScript.d.ts +0 -0
  266. package/lib/{services → types/services}/CliService.d.ts +0 -0
  267. package/lib/{services → types/services}/CliYaml.d.ts +0 -0
  268. package/lib/{services → types/services}/NpmRegistryClient.d.ts +0 -0
  269. package/lib/{services → types/services}/ProjectPackageJson.d.ts +0 -0
  270. package/lib/{services → types/services}/Renderer.d.ts +0 -0
  271. package/lib/{services → types/services}/index.d.ts +0 -0
  272. package/lib/{utils → types/utils}/createInjector.d.ts +0 -0
  273. package/lib/{utils → types/utils}/createTasksRunner.d.ts +0 -0
  274. package/lib/{utils → types/utils}/getCommandMetadata.d.ts +0 -0
  275. package/lib/{utils → types/utils}/getPackageJson.d.ts +0 -0
  276. package/lib/{utils → types/utils}/hbs/array.d.ts +0 -0
  277. package/lib/{utils → types/utils}/hbs/collection.d.ts +0 -0
  278. package/lib/{utils → types/utils}/hbs/comparison.d.ts +0 -0
  279. package/lib/{utils → types/utils}/hbs/index.d.ts +0 -0
  280. package/lib/{utils → types/utils}/hbs/object.d.ts +0 -0
  281. package/lib/{utils → types/utils}/hbs/switch.d.ts +0 -0
  282. package/lib/{utils → types/utils}/index.d.ts +0 -0
  283. package/lib/{utils → types/utils}/isValidVersion.d.ts +0 -0
  284. package/lib/{utils → types/utils}/loadPlugins.d.ts +0 -0
  285. package/lib/{utils → types/utils}/logToCurl.d.ts +0 -0
  286. package/lib/{utils → types/utils}/mapCommanderArgs.d.ts +0 -0
  287. package/lib/{utils → types/utils}/mapCommanderOptions.d.ts +0 -0
  288. package/lib/{utils → types/utils}/normalizePath.d.ts +0 -0
  289. package/lib/{utils → types/utils}/parseOption.d.ts +0 -0
  290. package/lib/{utils → types/utils}/patchCommander.d.ts +0 -0
  291. package/lib/{utils → types/utils}/renderer/insertAfter.d.ts +0 -0
  292. package/lib/{utils → types/utils}/renderer/insertImport.d.ts +0 -0
  293. package/package.json +19 -9
  294. package/tsconfig.compile.esm.json +12 -0
  295. package/lib/index.js +0 -3992
  296. package/lib/index.js.map +0 -1
  297. package/lib/index.modern.js +0 -3832
  298. package/lib/index.modern.js.map +0 -1
package/lib/index.js DELETED
@@ -1,3992 +0,0 @@
1
- var Inquirer = require('inquirer');
2
- var core = require('@tsed/core');
3
- var logger$1 = require('@tsed/logger');
4
- var di = require('@tsed/di');
5
- var tslib = require('tslib');
6
- var commander = require('commander');
7
- var listr2 = require('listr2');
8
- var path = require('path');
9
- var rxjs = require('rxjs');
10
- var operators = require('rxjs/operators');
11
- var semver$1 = require('semver');
12
- var execa = require('execa');
13
- var Fs = require('fs-extra');
14
- var readPkgUp = require('read-pkg-up');
15
- var axios = require('axios');
16
- var querystring = require('querystring');
17
- var tunnel = require('tunnel');
18
- var changeCase = require('change-case');
19
- var parse = require('url-parse');
20
- var chalk = require('chalk');
21
- var url = require('url');
22
- var Consolidate = require('consolidate');
23
- var globby = require('globby');
24
- var handlebars = require('handlebars');
25
- var JsYaml = require('js-yaml');
26
- var updateNotifier = require('update-notifier');
27
-
28
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
29
-
30
- function _interopNamespace(e) {
31
- if (e && e.__esModule) return e;
32
- var n = Object.create(null);
33
- if (e) {
34
- Object.keys(e).forEach(function (k) {
35
- if (k !== 'default') {
36
- var d = Object.getOwnPropertyDescriptor(e, k);
37
- Object.defineProperty(n, k, d.get ? d : {
38
- enumerable: true,
39
- get: function () {
40
- return e[k];
41
- }
42
- });
43
- }
44
- });
45
- }
46
- n['default'] = e;
47
- return n;
48
- }
49
-
50
- var Inquirer__default = /*#__PURE__*/_interopDefaultLegacy(Inquirer);
51
- var semver__default = /*#__PURE__*/_interopDefaultLegacy(semver$1);
52
- var execa__default = /*#__PURE__*/_interopDefaultLegacy(execa);
53
- var Fs__default = /*#__PURE__*/_interopDefaultLegacy(Fs);
54
- var readPkgUp__default = /*#__PURE__*/_interopDefaultLegacy(readPkgUp);
55
- var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
56
- var querystring__default = /*#__PURE__*/_interopDefaultLegacy(querystring);
57
- var tunnel__default = /*#__PURE__*/_interopDefaultLegacy(tunnel);
58
- var parse__default = /*#__PURE__*/_interopDefaultLegacy(parse);
59
- var chalk__default = /*#__PURE__*/_interopDefaultLegacy(chalk);
60
- var url__default = /*#__PURE__*/_interopDefaultLegacy(url);
61
- var Consolidate__default = /*#__PURE__*/_interopDefaultLegacy(Consolidate);
62
- var globby__default = /*#__PURE__*/_interopDefaultLegacy(globby);
63
- var handlebars__default = /*#__PURE__*/_interopDefaultLegacy(handlebars);
64
- var JsYaml__default = /*#__PURE__*/_interopDefaultLegacy(JsYaml);
65
- var updateNotifier__default = /*#__PURE__*/_interopDefaultLegacy(updateNotifier);
66
-
67
- exports.PackageManager = void 0;
68
-
69
- (function (PackageManager) {
70
- PackageManager["YARN"] = "yarn";
71
- PackageManager["NPM"] = "npm";
72
- PackageManager["PNPM"] = "pnpm";
73
- })(exports.PackageManager || (exports.PackageManager = {}));
74
-
75
- var CommandStoreKeys;
76
-
77
- (function (CommandStoreKeys) {
78
- CommandStoreKeys["COMMAND"] = "command";
79
- CommandStoreKeys["ADD"] = "$onAdd";
80
- CommandStoreKeys["EXEC_HOOKS"] = "$onExec";
81
- CommandStoreKeys["POST_INSTALL_HOOKS"] = "$onPostInstall";
82
- CommandStoreKeys["PROMPT_HOOKS"] = "$onPrompt";
83
- })(CommandStoreKeys || (CommandStoreKeys = {}));
84
-
85
- const PROVIDER_TYPE_COMMAND = "command";
86
- /**
87
- *
88
- * @type {Registry<Provider<any>, IProvider<any>>}
89
- */
90
- // tslint:disable-next-line: variable-name
91
-
92
- di.GlobalProviders.createRegistry(PROVIDER_TYPE_COMMAND, di.Provider);
93
- const registerCommand = di.GlobalProviders.createRegisterFn(PROVIDER_TYPE_COMMAND);
94
-
95
- function Command(options) {
96
- return core.useDecorators(registerCommand, core.StoreSet(CommandStoreKeys.COMMAND, options));
97
- }
98
-
99
- function On(hookName, name) {
100
- return (target, propertyKey) => {
101
- core.StoreMerge(hookName, {
102
- [name]: [propertyKey]
103
- })(target);
104
- };
105
- }
106
-
107
- function OnAdd(cliPlugin) {
108
- return On(CommandStoreKeys.ADD, cliPlugin);
109
- }
110
-
111
- function OnExec(cmdName) {
112
- return On(CommandStoreKeys.EXEC_HOOKS, cmdName);
113
- }
114
-
115
- function OnPostInstall(cmdName) {
116
- return On(CommandStoreKeys.POST_INSTALL_HOOKS, cmdName);
117
- }
118
-
119
- function OnPrompt(cmdName) {
120
- return On(CommandStoreKeys.PROMPT_HOOKS, cmdName);
121
- }
122
-
123
- exports.CliConfiguration = class CliConfiguration extends di.DIConfiguration {
124
- constructor() {
125
- super({
126
- project: {
127
- root: process.cwd(),
128
- srcDir: "src"
129
- }
130
- });
131
- }
132
-
133
- };
134
- exports.CliConfiguration = tslib.__decorate([di.Injectable(), tslib.__metadata("design:paramtypes", [])], exports.CliConfiguration);
135
-
136
- function _extends() {
137
- _extends = Object.assign || function (target) {
138
- for (var i = 1; i < arguments.length; i++) {
139
- var source = arguments[i];
140
-
141
- for (var key in source) {
142
- if (Object.prototype.hasOwnProperty.call(source, key)) {
143
- target[key] = source[key];
144
- }
145
- }
146
- }
147
-
148
- return target;
149
- };
150
-
151
- return _extends.apply(this, arguments);
152
- }
153
-
154
- function _objectWithoutPropertiesLoose(source, excluded) {
155
- if (source == null) return {};
156
- var target = {};
157
- var sourceKeys = Object.keys(source);
158
- var key, i;
159
-
160
- for (i = 0; i < sourceKeys.length; i++) {
161
- key = sourceKeys[i];
162
- if (excluded.indexOf(key) >= 0) continue;
163
- target[key] = source[key];
164
- }
165
-
166
- return target;
167
- }
168
-
169
- require("any-observable/register/rxjs-all");
170
-
171
- const streamToObservable = require("@samverschueren/stream-to-observable");
172
-
173
- const split = require("split");
174
-
175
- exports.CliExeca = class CliExeca {
176
- constructor() {
177
- this.raw = execa__default['default'];
178
- }
179
-
180
- /**
181
- *
182
- * @param cmd
183
- * @param args
184
- * @param opts
185
- */
186
- run(cmd, args, opts) {
187
- const cp = this.raw(cmd, args, opts);
188
- const stdout = streamToObservable(cp.stdout.pipe(split()), {
189
- await: cp
190
- });
191
- const stderr = streamToObservable(cp.stderr.pipe(split()), {
192
- await: cp
193
- });
194
- return stdout.pipe(operators.merge(stderr)).pipe(operators.filter(Boolean));
195
- }
196
-
197
- runSync(cmd, args, opts) {
198
- return this.raw.sync(cmd, args, opts);
199
- }
200
-
201
- async getAsync(cmd, args, opts) {
202
- return (await this.raw(cmd, args, opts)).stdout;
203
- }
204
-
205
- get(cmd, args, opts) {
206
- return this.raw.sync(cmd, args, opts).stdout;
207
- }
208
-
209
- };
210
- exports.CliExeca = tslib.__decorate([di.Injectable()], exports.CliExeca);
211
-
212
- const fixPath = require("normalize-path");
213
-
214
- function normalizePath$1(item, ...paths) {
215
- if (core.isString(item)) {
216
- const path$1 = path.join(item, ...paths);
217
- return fixPath(path$1);
218
- }
219
-
220
- if (core.isArray(item)) {
221
- return item.map(item => normalizePath$1(item));
222
- }
223
-
224
- return item;
225
- }
226
-
227
- exports.CliFs = class CliFs {
228
- constructor() {
229
- this.raw = Fs__default['default'];
230
- }
231
-
232
- exists(path) {
233
- return this.raw.existsSync(path);
234
- }
235
-
236
- join(...args) {
237
- return normalizePath$1(path.join(...args));
238
- }
239
-
240
- async readFile(file, encoding) {
241
- return this.raw.readFile(file, encoding);
242
- }
243
-
244
- writeFileSync(path, data, options) {
245
- return this.raw.writeFileSync(path, data, options);
246
- }
247
-
248
- writeFile(file, data, options) {
249
- return this.raw.writeFile(file, data, options);
250
- }
251
-
252
- ensureDir(path, options) {
253
- return this.raw.ensureDir(path, options);
254
- }
255
-
256
- ensureDirSync(path, options) {
257
- return this.raw.ensureDirSync(path, options);
258
- }
259
-
260
- findUpFile(root, file) {
261
- return [path.join(root, file), path.join(root, "..", file), path.join(root, "..", "..", file), path.join(root, "..", "..", "..", file)].find(path => this.exists(path));
262
- }
263
-
264
- async importModule(mod, root = process.cwd()) {
265
- try {
266
- if (process.env.NODE_ENV === "development") {
267
- return await Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(mod)); });
268
- }
269
- } catch (er) {}
270
-
271
- const path$1 = this.findUpFile(root, path.join("node_modules", mod));
272
-
273
- if (path$1) {
274
- return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(path$1)); });
275
- }
276
-
277
- return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require(mod)); });
278
- }
279
-
280
- };
281
- exports.CliFs = tslib.__decorate([di.Injectable()], exports.CliFs);
282
-
283
- function isValidVersion(version) {
284
- version = version.replace(/[~>=<]/gi, "");
285
- return !!semver__default['default'].valid(version);
286
- }
287
-
288
- function useReadPkgUp(configuration) {
289
- var _configuration$projec;
290
-
291
- return !(process.argv.includes("init") && !Fs__default['default'].existsSync(path.join(String((_configuration$projec = configuration.project) == null ? void 0 : _configuration$projec.rootDir), "package.json")));
292
- }
293
-
294
- function getEmptyPackageJson(configuration) {
295
- return {
296
- name: configuration.name,
297
- version: "1.0.0",
298
- description: "",
299
- scripts: {},
300
- dependencies: {},
301
- devDependencies: {}
302
- };
303
- }
304
-
305
- function getPackageJson(configuration) {
306
- if (useReadPkgUp(configuration)) {
307
- var _configuration$projec2;
308
-
309
- const result = readPkgUp__default['default'].sync({
310
- cwd: (_configuration$projec2 = configuration.project) == null ? void 0 : _configuration$projec2.rootDir
311
- });
312
-
313
- if (result && result.path) {
314
- const pkgPath = path.dirname(result.path);
315
- configuration.set("project.root", pkgPath);
316
- const pkg = Fs__default['default'].readJsonSync(result.path, {
317
- encoding: "utf8"
318
- });
319
- return _extends({}, getEmptyPackageJson(configuration), pkg);
320
- }
321
- }
322
-
323
- return getEmptyPackageJson(configuration);
324
- }
325
-
326
- function mapPackagesWithInvalidVersion(deps) {
327
- const toString = info => {
328
- return info[1] === "latest" ? info[0] : info.join("@");
329
- };
330
-
331
- return Object.entries(deps).filter(([, version]) => !semver__default['default'].valid(version)).map(toString);
332
- }
333
-
334
- function sortKeys(obj) {
335
- return Object.entries(obj).sort((k1, k2) => {
336
- return k1[0] < k2[0] ? -1 : 1;
337
- }).reduce((obj, [key, value]) => {
338
- return _extends({}, obj, {
339
- [key]: value
340
- });
341
- }, {});
342
- }
343
-
344
- function mapPackagesWithValidVersion(deps) {
345
- return Object.entries(deps).reduce((deps, [key, version]) => {
346
- if (isValidVersion(version)) {
347
- return _extends({}, deps, {
348
- [key]: version
349
- });
350
- }
351
-
352
- return deps;
353
- }, {});
354
- }
355
-
356
- function defaultPreferences(pkg) {
357
- let packageManager = exports.PackageManager.YARN;
358
-
359
- if (core.getValue(pkg, "scripts.build", "").includes("pnpm ")) {
360
- packageManager = exports.PackageManager.PNPM;
361
- } else if (core.getValue(pkg, "scripts.build", "").includes("npm ")) {
362
- packageManager = exports.PackageManager.NPM;
363
- }
364
-
365
- return {
366
- packageManager
367
- };
368
- }
369
-
370
- exports.ProjectPackageJson = class ProjectPackageJson {
371
- constructor(configuration) {
372
- this.configuration = void 0;
373
- this.rewrite = false;
374
- this.reinstall = false;
375
- this.cliExeca = void 0;
376
- this.fs = void 0;
377
- this.GH_TOKEN = void 0;
378
- this.raw = void 0;
379
- this.configuration = configuration;
380
- this.setRaw({
381
- name: "",
382
- version: "1.0.0",
383
- description: "",
384
- scripts: {},
385
- dependencies: {},
386
- devDependencies: {}
387
- });
388
- this.read();
389
- }
390
-
391
- get path() {
392
- return path.join(this.dir, "package.json");
393
- }
394
-
395
- get dir() {
396
- var _this$configuration$p;
397
-
398
- return String((_this$configuration$p = this.configuration.project) == null ? void 0 : _this$configuration$p.rootDir);
399
- }
400
-
401
- set dir(dir) {
402
- this.configuration.project.rootDir = dir;
403
- this.read();
404
- }
405
-
406
- get name() {
407
- return this.raw.name;
408
- }
409
-
410
- set name(name) {
411
- this.raw.name = name;
412
- this.rewrite = true;
413
- }
414
-
415
- get version() {
416
- return this.raw.version;
417
- }
418
-
419
- get description() {
420
- return this.raw.description;
421
- }
422
-
423
- get scripts() {
424
- return this.raw.scripts;
425
- }
426
-
427
- get dependencies() {
428
- return this.raw.dependencies;
429
- }
430
-
431
- get devDependencies() {
432
- return this.raw.devDependencies;
433
- }
434
-
435
- get allDependencies() {
436
- return _extends({}, this.dependencies || {}, this.devDependencies || {});
437
- }
438
-
439
- get preferences() {
440
- return this.raw[this.configuration.name];
441
- }
442
-
443
- toJSON() {
444
- return this.raw;
445
- }
446
-
447
- read() {
448
- const pkg = this.getPackageJson();
449
- this.setRaw(pkg);
450
- return this;
451
- }
452
-
453
- setRaw(pkg) {
454
- const projectPreferences = this.configuration.defaultProjectPreferences;
455
- const preferences = core.getValue(pkg, this.configuration.name);
456
- this.raw = _extends({}, pkg, {
457
- [this.configuration.name]: _extends({}, defaultPreferences(pkg), projectPreferences && projectPreferences(pkg), preferences)
458
- });
459
- }
460
-
461
- getRunCmd() {
462
- switch (this.preferences.packageManager) {
463
- case "npm":
464
- return "npm run";
465
-
466
- case "pnpm":
467
- return "pnpm run";
468
-
469
- default:
470
- return "yarn run";
471
- }
472
- }
473
-
474
- addDevDependency(pkg, version) {
475
- this.devDependencies[pkg] = version;
476
- this.reinstall = true;
477
- this.rewrite = true;
478
- return this;
479
- }
480
-
481
- addDevDependencies(modules, scope = {}) {
482
- const replacer = (match, key) => core.getValue(key, scope);
483
-
484
- Object.entries(modules).forEach(([pkg, version]) => {
485
- this.addDevDependency(pkg, (version || "").replace(/{{([\w.]+)}}/gi, replacer));
486
- });
487
- return this;
488
- }
489
-
490
- addDependency(pkg, version) {
491
- this.dependencies[pkg] = version;
492
- this.reinstall = true;
493
- this.rewrite = true;
494
- return this;
495
- }
496
-
497
- addDependencies(modules, ctx = {}) {
498
- const replacer = (match, key) => core.getValue(key, ctx);
499
-
500
- Object.entries(modules).forEach(([pkg, version]) => {
501
- this.addDependency(pkg, (version || "").replace("{{tsedVersion}}", ctx.tsedVersion).replace(/{{([\w.]+)}}/gi, replacer));
502
- });
503
- return this;
504
- }
505
-
506
- addScript(task, cmd) {
507
- this.scripts[task] = cmd;
508
- this.rewrite = true;
509
- return this;
510
- }
511
-
512
- addScripts(scripts) {
513
- Object.entries(scripts).forEach(([task, cmd]) => {
514
- this.addScript(task, cmd);
515
- });
516
- return this;
517
- }
518
-
519
- add(key, data) {
520
- this.raw[key] = data;
521
- this.rewrite = true;
522
- return this;
523
- }
524
-
525
- setPreference(key, value) {
526
- core.setValue(this.raw, `${this.configuration.name}.${key}`, value);
527
- this.rewrite = true;
528
- return;
529
- }
530
-
531
- set(key, value) {
532
- this.raw[key] = value;
533
- this.rewrite = true;
534
-
535
- if (["dependencies", "devDependencies", "peerDependencies"].includes(key)) {
536
- this.reinstall = true;
537
- }
538
- }
539
-
540
- get(key) {
541
- return this.raw[key];
542
- }
543
-
544
- write() {
545
- const originalPkg = this.getPackageJson();
546
- this.rewrite = false;
547
- this.raw = _extends({}, originalPkg, this.raw, {
548
- scripts: _extends({}, originalPkg.scripts || {}, this.raw.scripts || {}),
549
- dependencies: sortKeys(_extends({}, originalPkg.dependencies, mapPackagesWithValidVersion(this.raw.dependencies))),
550
- devDependencies: sortKeys(_extends({}, originalPkg.devDependencies, mapPackagesWithValidVersion(this.raw.devDependencies))),
551
- readme: undefined,
552
- _id: undefined
553
- });
554
- this.fs.writeFileSync(this.path, JSON.stringify(this.raw, null, 2), {
555
- encoding: "utf8"
556
- });
557
- return this;
558
- }
559
-
560
- hasYarn() {
561
- try {
562
- this.cliExeca.runSync(exports.PackageManager.YARN, ["--version"]);
563
- return true;
564
- } catch (er) {
565
- return false;
566
- }
567
- }
568
-
569
- install(options = {}) {
570
- const packageManager = this.getPackageManager(options.packageManager);
571
- let tasks;
572
-
573
- switch (packageManager) {
574
- case "pnpm":
575
- tasks = this.installWithPnpm(options);
576
- break;
577
-
578
- case "npm":
579
- tasks = this.installWithNpm(options);
580
- break;
581
-
582
- default:
583
- tasks = this.installWithYarn(options);
584
- }
585
-
586
- return [{
587
- title: "Write package.json",
588
- enabled: () => this.rewrite,
589
- task: () => {
590
- this.write();
591
- }
592
- }, ...tasks, {
593
- title: "Clean",
594
- task: () => {
595
- this.reinstall = false;
596
- this.rewrite = false;
597
- this.read();
598
- }
599
- }];
600
- }
601
- /**
602
- * Import a module from the project workspace
603
- * @param mod
604
- */
605
-
606
-
607
- async importModule(mod) {
608
- return this.fs.importModule(mod, this.dir);
609
- }
610
-
611
- runScript(npmTask, ignoreError = false) {
612
- const options = {
613
- cwd: this.dir
614
- };
615
-
616
- const errorPipe = () => operators.catchError(error => {
617
- if (ignoreError) {
618
- return rxjs.EMPTY;
619
- }
620
-
621
- return rxjs.throwError(error);
622
- });
623
-
624
- return this.cliExeca.run(this.getPackageManager(), ["run", npmTask], options).pipe(errorPipe());
625
- }
626
-
627
- getPackageManager(packageManager) {
628
- if (this.preferences.packageManager) {
629
- packageManager = this.preferences.packageManager;
630
- }
631
-
632
- packageManager = packageManager || exports.PackageManager.YARN;
633
-
634
- if (packageManager === exports.PackageManager.YARN && !this.hasYarn()) {
635
- packageManager = exports.PackageManager.NPM;
636
- }
637
-
638
- return packageManager;
639
- }
640
-
641
- setGhToken(GH_TOKEN) {
642
- this.GH_TOKEN = GH_TOKEN;
643
- }
644
-
645
- installWithYarn({
646
- verbose
647
- }) {
648
- const devDeps = mapPackagesWithInvalidVersion(this.devDependencies);
649
- const deps = mapPackagesWithInvalidVersion(this.dependencies);
650
- const options = {
651
- cwd: this.dir,
652
- env: _extends({}, process.env, {
653
- GH_TOKEN: this.GH_TOKEN
654
- })
655
- };
656
-
657
- const errorPipe = () => operators.catchError(error => {
658
- if (error.stderr.startsWith("error Your lockfile needs to be updated")) {
659
- return rxjs.throwError(new Error("yarn.lock file is outdated. Run yarn, commit the updated lockfile and try again."));
660
- }
661
-
662
- return rxjs.throwError(error);
663
- });
664
-
665
- return [{
666
- title: "Installing dependencies using Yarn",
667
- skip: () => !this.reinstall,
668
- task: () => this.cliExeca.run(exports.PackageManager.YARN, ["install", "--production=false", verbose && "--verbose", "--ignore-engines"].filter(Boolean), options).pipe(errorPipe())
669
- }, {
670
- title: "Add dependencies using Yarn",
671
- skip: () => !deps.length,
672
- task: () => this.cliExeca.run(exports.PackageManager.YARN, ["add", verbose && "--verbose", "--ignore-engines", ...deps].filter(Boolean), options).pipe(errorPipe())
673
- }, {
674
- title: "Add devDependencies using Yarn",
675
- skip: () => !devDeps.length,
676
- task: () => this.cliExeca.run(exports.PackageManager.YARN, ["add", "-D", verbose && "--verbose", "--ignore-engines", ...devDeps].filter(Boolean), options).pipe(errorPipe())
677
- }];
678
- }
679
-
680
- installWithNpm({
681
- verbose
682
- }) {
683
- const devDeps = mapPackagesWithInvalidVersion(this.devDependencies);
684
- const deps = mapPackagesWithInvalidVersion(this.dependencies);
685
- const options = {
686
- cwd: this.dir,
687
- env: _extends({}, process.env, {
688
- GH_TOKEN: this.GH_TOKEN
689
- })
690
- };
691
- return [{
692
- title: "Installing dependencies using npm",
693
- skip: () => {
694
- return !this.reinstall;
695
- },
696
- task: () => {
697
- return this.cliExeca.run(exports.PackageManager.NPM, ["install", "--no-production", "--legacy-peer-deps", verbose && "--verbose"].filter(Boolean), options);
698
- }
699
- }, {
700
- title: "Add dependencies using npm",
701
- skip: () => !deps.length,
702
- task: () => this.cliExeca.run(exports.PackageManager.NPM, ["install", "--save", "--legacy-peer-deps", verbose && "--verbose", ...deps].filter(Boolean), options)
703
- }, {
704
- title: "Add devDependencies using npm",
705
- skip: () => !devDeps.length,
706
- task: () => this.cliExeca.run(exports.PackageManager.NPM, ["install", "--save-dev", "--legacy-peer-deps", verbose && "--verbose", ...devDeps].filter(Boolean), options)
707
- }];
708
- }
709
-
710
- installWithPnpm({
711
- verbose
712
- }) {
713
- const devDeps = mapPackagesWithInvalidVersion(this.devDependencies);
714
- const deps = mapPackagesWithInvalidVersion(this.dependencies);
715
- const options = {
716
- cwd: this.dir,
717
- env: _extends({}, process.env, {
718
- GH_TOKEN: this.GH_TOKEN
719
- })
720
- };
721
- return [{
722
- title: "Installing dependencies using pnpm",
723
- skip: () => {
724
- return !this.reinstall;
725
- },
726
- task: () => this.cliExeca.run(exports.PackageManager.PNPM, ["install", "--dev", verbose && "--verbose"].filter(Boolean), options)
727
- }, {
728
- title: "Add dependencies using pnpm",
729
- skip: () => !deps.length,
730
- task: () => this.cliExeca.run(exports.PackageManager.PNPM, ["add", "--save-prod", verbose && "--verbose", ...deps].filter(Boolean), options)
731
- }, {
732
- title: "Add devDependencies using pnpm",
733
- skip: () => !devDeps.length,
734
- task: () => this.cliExeca.run(exports.PackageManager.PNPM, ["add", "--save-dev", verbose && "--verbose", ...devDeps].filter(Boolean), options)
735
- }];
736
- }
737
-
738
- getPackageJson() {
739
- return getPackageJson(this.configuration);
740
- }
741
-
742
- };
743
-
744
- tslib.__decorate([di.Inject(exports.CliExeca), tslib.__metadata("design:type", exports.CliExeca)], exports.ProjectPackageJson.prototype, "cliExeca", void 0);
745
-
746
- tslib.__decorate([di.Inject(exports.CliFs), tslib.__metadata("design:type", exports.CliFs)], exports.ProjectPackageJson.prototype, "fs", void 0);
747
-
748
- exports.ProjectPackageJson = tslib.__decorate([di.Injectable(), tslib.__param(0, di.Configuration()), tslib.__metadata("design:paramtypes", [Object])], exports.ProjectPackageJson);
749
-
750
- let logger;
751
- function getLogger() {
752
- return logger;
753
- }
754
-
755
- function createConfiguration(injector) {
756
- injector.addProvider(exports.CliConfiguration);
757
- return injector.invoke(exports.CliConfiguration);
758
- }
759
-
760
- function createInjector(settings = {}) {
761
- const injector = new di.InjectorService();
762
- injector.settings = createConfiguration(injector);
763
- logger = injector.logger = new logger$1.Logger(settings.name || "CLI");
764
- injector.addProvider(exports.ProjectPackageJson);
765
- injector.settings.set(settings);
766
- /* istanbul ignore next */
767
-
768
- if (injector.settings.env === "test") {
769
- injector.logger.stop();
770
- } else {
771
- var _injector$settings$lo;
772
-
773
- /* istanbul ignore next */
774
- injector.logger.level = ((_injector$settings$lo = injector.settings.logger) == null ? void 0 : _injector$settings$lo.level) || "error";
775
- }
776
-
777
- return injector;
778
- }
779
-
780
- class CustomLogger extends listr2.Logger {
781
- fail(message) {
782
- var _getLogger;
783
-
784
- (_getLogger = getLogger()) == null ? void 0 : _getLogger.error("[FAIL]", message);
785
- }
786
-
787
- skip(message) {
788
- var _getLogger2;
789
-
790
- (_getLogger2 = getLogger()) == null ? void 0 : _getLogger2.info("[SKIP]", message);
791
- }
792
-
793
- success(message) {
794
- var _getLogger3;
795
-
796
- (_getLogger3 = getLogger()) == null ? void 0 : _getLogger3.info("[SUCCESS]", message);
797
- }
798
-
799
- data(message) {
800
- var _getLogger4;
801
-
802
- (_getLogger4 = getLogger()) == null ? void 0 : _getLogger4.info("[DATA]", message);
803
- }
804
-
805
- start(message) {
806
- var _getLogger5;
807
-
808
- (_getLogger5 = getLogger()) == null ? void 0 : _getLogger5.info("[START]", message);
809
- }
810
-
811
- title(message) {
812
- var _getLogger6;
813
-
814
- (_getLogger6 = getLogger()) == null ? void 0 : _getLogger6.info("[TITLE]", message);
815
- }
816
-
817
- retry(message) {
818
- var _getLogger7;
819
-
820
- (_getLogger7 = getLogger()) == null ? void 0 : _getLogger7.info("[RETRY]", message);
821
- }
822
-
823
- rollback(message) {
824
- var _getLogger8;
825
-
826
- (_getLogger8 = getLogger()) == null ? void 0 : _getLogger8.info("[ROLLBACK]", message);
827
- }
828
-
829
- }
830
-
831
- function getOptions(ctx) {
832
- const useRawRenderer = !(!ctx.verbose && !process.env.CI);
833
- const rendererOptions = useRawRenderer ? {
834
- logger: CustomLogger
835
- } : {};
836
- return _extends({}, ctx, {
837
- rendererSilent: process.env.NODE_ENV === "test",
838
- rendererFallback: useRawRenderer,
839
- renderer: useRawRenderer ? "verbose" : "default",
840
- nonTTYRendererOptions: rendererOptions,
841
- rendererOptions
842
- });
843
- }
844
-
845
- function createTasks(tasks, ctx) {
846
- return new listr2.Listr(tasks, getOptions(ctx));
847
- }
848
- function createSubTasks(tasks, opts) {
849
- opts = getOptions(opts);
850
- return async (ctx, task) => {
851
- if (core.isFunction(tasks)) {
852
- tasks = await tasks(ctx, task);
853
- }
854
-
855
- return task.newListr(tasks, opts);
856
- };
857
- }
858
- function createTasksRunner(tasks, ctx) {
859
- return createTasks(tasks, ctx).run(ctx);
860
- }
861
-
862
- function getCommandMetadata(token) {
863
- var _Store$from;
864
-
865
- const {
866
- name,
867
- alias,
868
- args = {},
869
- allowUnknownOption,
870
- description,
871
- options = {}
872
- } = (_Store$from = core.Store.from(token)) == null ? void 0 : _Store$from.get(CommandStoreKeys.COMMAND);
873
- return {
874
- name,
875
- alias,
876
- args,
877
- description,
878
- options,
879
- allowUnknownOption: !!allowUnknownOption
880
- };
881
- }
882
-
883
- function mapValue(value, {
884
- type,
885
- itemType
886
- }) {
887
- if (!value) {
888
- return value;
889
- }
890
-
891
- switch (type) {
892
- case String:
893
- value = String(value);
894
- break;
895
-
896
- case Number:
897
- value = parseFloat(value);
898
- break;
899
-
900
- case Boolean:
901
- value = value === "true";
902
- break;
903
-
904
- case Array:
905
- value = String(value).split(",").map(value => mapValue(value, {
906
- type: itemType
907
- }));
908
- break;
909
- }
910
-
911
- return value;
912
- }
913
-
914
- function mapCommanderArgs(args, commandArgs) {
915
- commandArgs = commandArgs.filter(arg => !core.isClass(arg)).filter(arg => !core.isArray(arg));
916
- let index = 0;
917
- return Object.entries(args).reduce((options, [arg, {
918
- defaultValue,
919
- type,
920
- itemType
921
- }]) => {
922
- const value = commandArgs[index] || defaultValue;
923
- index++;
924
- return _extends({}, options, {
925
- [arg]: mapValue(value, {
926
- type,
927
- itemType
928
- })
929
- });
930
- }, {});
931
- }
932
-
933
- function mapCommanderOptions(commands) {
934
- const options = {};
935
- commands.forEach(command => {
936
- Object.entries(command.opts()).filter(([key]) => !key.startsWith("_") && !["commands", "options", "parent", "rawArgs", "args"].includes(key)).forEach(([key, value]) => {
937
- options[key] = value;
938
- });
939
- });
940
- return options;
941
- }
942
-
943
- function parseOption(value, options) {
944
- const {
945
- type,
946
- itemType,
947
- customParser
948
- } = options;
949
-
950
- if (type) {
951
- switch (type) {
952
- case String:
953
- value = String(value);
954
- break;
955
-
956
- case Boolean:
957
- // the flag is added
958
- return true;
959
-
960
- case Number:
961
- value = +value;
962
- break;
963
-
964
- case Array:
965
- value = value.split(",").map(value => parseOption(value, {
966
- type: itemType,
967
- customParser
968
- }));
969
- break;
970
- }
971
- }
972
-
973
- if (options.customParser) {
974
- value = options.customParser(value);
975
- }
976
-
977
- return value;
978
- }
979
-
980
- let CliHooks = class CliHooks {
981
- constructor() {
982
- this.injector = void 0;
983
- }
984
-
985
- async emit(hookName, cmd, ...args) {
986
- const providers = this.injector.getProviders();
987
- let results = [];
988
-
989
- for (const provider of providers) {
990
- if (provider.useClass) {
991
- const instance = this.injector.get(provider.token);
992
-
993
- if (provider.store.has(hookName)) {
994
- const props = provider.store.get(hookName)[cmd];
995
-
996
- if (props) {
997
- for (const propertyKey of props) {
998
- results = results.concat(await instance[propertyKey](...args));
999
- }
1000
- }
1001
- }
1002
- }
1003
- }
1004
-
1005
- return results.filter(o => o !== undefined);
1006
- }
1007
-
1008
- };
1009
-
1010
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", di.InjectorService)], CliHooks.prototype, "injector", void 0);
1011
-
1012
- CliHooks = tslib.__decorate([di.Injectable()], CliHooks);
1013
-
1014
- const _excluded$2 = ["description", "required", "customParser", "defaultValue"];
1015
- Inquirer__default['default'].registerPrompt("autocomplete", require("inquirer-autocomplete-prompt"));
1016
- exports.CliService = class CliService {
1017
- constructor() {
1018
- this.program = new commander.Command();
1019
- this.reinstallAfterRun = false;
1020
- this.pkg = void 0;
1021
- this.injector = void 0;
1022
- this.hooks = void 0;
1023
- this.projectPkg = void 0;
1024
- this.commands = new Map();
1025
- }
1026
-
1027
- $onInit() {
1028
- if (this.injector.logger.level !== "off") {
1029
- this.injector.logger.appenders.set("stdout", {
1030
- type: "stdout",
1031
- layout: {
1032
- type: "pattern",
1033
- pattern: "[%d{hh:mm:ss}] %m"
1034
- },
1035
- levels: ["info", "debug"]
1036
- }).set("stderr", {
1037
- type: "stderr",
1038
- layout: {
1039
- type: "pattern",
1040
- pattern: "[%d{hh:mm:ss}][%p] %m"
1041
- },
1042
- levels: ["trace", "fatal", "error", "warn"]
1043
- });
1044
- }
1045
- }
1046
- /**
1047
- * Parse process.argv and runLifecycle action
1048
- * @param argv
1049
- */
1050
-
1051
-
1052
- async parseArgs(argv) {
1053
- const {
1054
- program
1055
- } = this;
1056
- program.version(this.pkg.version);
1057
- this.load();
1058
- await program.parseAsync(argv);
1059
- }
1060
- /**
1061
- * Run lifecycle
1062
- * @param cmdName
1063
- * @param data
1064
- */
1065
-
1066
-
1067
- async runLifecycle(cmdName, data = {}) {
1068
- data = await this.beforePrompt(cmdName, data);
1069
- data = await this.prompt(cmdName, data);
1070
-
1071
- try {
1072
- await this.exec(cmdName, data);
1073
- } catch (er) {
1074
- await this.injector.emit("$onFinish", er);
1075
- await this.injector.destroy();
1076
- throw er;
1077
- }
1078
-
1079
- await this.injector.emit("$onFinish");
1080
- await this.injector.destroy();
1081
- }
1082
-
1083
- async exec(cmdName, ctx) {
1084
- const initialTasks = await this.getTasks(cmdName, ctx);
1085
-
1086
- if (initialTasks.length) {
1087
- const tasks = [...initialTasks, {
1088
- title: "Install dependencies",
1089
- enabled: () => this.reinstallAfterRun && (this.projectPkg.rewrite || this.projectPkg.reinstall),
1090
- task: createSubTasks(() => this.projectPkg.install(ctx), _extends({}, ctx, {
1091
- concurrent: false
1092
- }))
1093
- }, ...(await this.getPostInstallTasks(cmdName, ctx))];
1094
- return createTasksRunner(tasks, this.mapContext(cmdName, ctx));
1095
- }
1096
- }
1097
- /**
1098
- * Run prompt for a given command
1099
- * @param cmdName
1100
- * @param ctx Initial data
1101
- */
1102
-
1103
-
1104
- async beforePrompt(cmdName, ctx = {}) {
1105
- const provider = this.commands.get(cmdName);
1106
- const instance = this.injector.get(provider.useClass);
1107
- const verbose = ctx.verbose;
1108
-
1109
- if (instance.$beforePrompt) {
1110
- ctx = await instance.$beforePrompt(JSON.parse(JSON.stringify(ctx)));
1111
- ctx.verbose = verbose;
1112
- }
1113
-
1114
- return ctx;
1115
- }
1116
- /**
1117
- * Run prompt for a given command
1118
- * @param cmdName
1119
- * @param ctx Initial data
1120
- */
1121
-
1122
-
1123
- async prompt(cmdName, ctx = {}) {
1124
- const provider = this.commands.get(cmdName);
1125
- const instance = this.injector.get(provider.useClass);
1126
-
1127
- if (instance.$prompt) {
1128
- const questions = [...(await instance.$prompt(ctx)), ...(await this.hooks.emit(CommandStoreKeys.PROMPT_HOOKS, cmdName, ctx))];
1129
-
1130
- if (questions.length) {
1131
- ctx = _extends({}, ctx, await Inquirer__default['default'].prompt(questions));
1132
- }
1133
- }
1134
-
1135
- return ctx;
1136
- }
1137
- /**
1138
- * Run lifecycle
1139
- * @param cmdName
1140
- * @param ctx
1141
- */
1142
-
1143
-
1144
- async getTasks(cmdName, ctx) {
1145
- const provider = this.commands.get(cmdName);
1146
- const instance = this.injector.get(provider.token);
1147
- ctx = this.mapContext(cmdName, ctx);
1148
-
1149
- if (instance.$beforeExec) {
1150
- await instance.$beforeExec(ctx);
1151
- }
1152
-
1153
- return [...(await instance.$exec(ctx)), ...(await this.hooks.emit(CommandStoreKeys.EXEC_HOOKS, cmdName, ctx))];
1154
- }
1155
-
1156
- async getPostInstallTasks(cmdName, ctx) {
1157
- const provider = this.commands.get(cmdName);
1158
- const instance = this.injector.get(provider.useClass);
1159
- ctx = this.mapContext(cmdName, ctx);
1160
- return [...(instance.$postInstall ? await instance.$postInstall(ctx) : []), ...(await this.hooks.emit(CommandStoreKeys.POST_INSTALL_HOOKS, cmdName, ctx))];
1161
- }
1162
-
1163
- createCommand(metadata) {
1164
- const {
1165
- args,
1166
- name,
1167
- options,
1168
- description,
1169
- alias,
1170
- allowUnknownOption
1171
- } = metadata;
1172
-
1173
- if (this.commands.has(name)) {
1174
- return this.commands.get(name).command;
1175
- }
1176
-
1177
- let cmd = this.program.command(name);
1178
-
1179
- const onAction = (...commanderArgs) => {
1180
- const [, ...rawArgs] = cmd.args;
1181
-
1182
- const data = _extends({
1183
- verbose: !!this.program.opts().verbose
1184
- }, mapCommanderArgs(args, commanderArgs), mapCommanderOptions(this.program.commands), {
1185
- rawArgs
1186
- });
1187
-
1188
- return this.runLifecycle(name, data);
1189
- };
1190
-
1191
- if (alias) {
1192
- cmd = cmd.alias(alias);
1193
- }
1194
-
1195
- cmd = cmd.description(description);
1196
- cmd = this.buildArguments(cmd, args);
1197
- cmd = cmd.action(onAction);
1198
-
1199
- if (options) {
1200
- cmd = this.buildOption(cmd, options, !!allowUnknownOption);
1201
- }
1202
-
1203
- return cmd;
1204
- }
1205
-
1206
- load() {
1207
- this.injector.getProviders(PROVIDER_TYPE_COMMAND).forEach(provider => this.build(provider));
1208
- }
1209
-
1210
- mapContext(cmdName, ctx) {
1211
- const provider = this.commands.get(cmdName);
1212
- const instance = this.injector.get(provider.useClass);
1213
- const verbose = ctx.verbose;
1214
-
1215
- if (instance.$mapContext) {
1216
- ctx = instance.$mapContext(JSON.parse(JSON.stringify(ctx)));
1217
- ctx.verbose = verbose;
1218
- }
1219
-
1220
- if (ctx.verbose) {
1221
- this.injector.logger.level = "debug";
1222
- } else {
1223
- this.injector.logger.level = "info";
1224
- }
1225
-
1226
- return ctx;
1227
- }
1228
- /**
1229
- * Build command and sub-commands
1230
- * @param provider
1231
- */
1232
-
1233
-
1234
- build(provider) {
1235
- const metadata = getCommandMetadata(provider.useClass);
1236
-
1237
- if (metadata.name) {
1238
- if (this.commands.has(metadata.name)) {
1239
- throw Error(`The ${metadata.name} command is already registered. Change your command name used by the class ${core.classOf(provider.useClass)}`);
1240
- }
1241
-
1242
- provider.command = this.createCommand(metadata);
1243
- this.commands.set(metadata.name, provider);
1244
- }
1245
- }
1246
- /**
1247
- * Build sub-command options
1248
- * @param subCommand
1249
- * @param options
1250
- * @param allowUnknownOptions
1251
- */
1252
-
1253
-
1254
- buildOption(subCommand, options, allowUnknownOptions) {
1255
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
1256
- Object.entries(options).reduce((subCommand, [flags, _ref]) => {
1257
- let {
1258
- description,
1259
- required,
1260
- defaultValue
1261
- } = _ref,
1262
- options = _objectWithoutPropertiesLoose(_ref, _excluded$2);
1263
-
1264
- const fn = v => parseOption(v, options);
1265
-
1266
- if (options.type === Boolean) {
1267
- defaultValue = false;
1268
- }
1269
-
1270
- return required ? subCommand.requiredOption(flags, description, fn, defaultValue) : subCommand.option(flags, description, fn, defaultValue);
1271
- }, subCommand);
1272
- subCommand.option("-r, --root-dir <path>", "Project root directory");
1273
- subCommand.option("--verbose", "Verbose mode", () => true);
1274
-
1275
- if (allowUnknownOptions) {
1276
- subCommand.allowUnknownOption(true);
1277
- }
1278
-
1279
- return subCommand;
1280
- }
1281
-
1282
- buildArguments(cmd, args) {
1283
- return Object.entries(args).reduce((cmd, [key, {
1284
- description,
1285
- required,
1286
- defaultValue
1287
- }]) => {
1288
- const argument = new commander.Argument(required ? `<${key}>` : `[${key}]`, description);
1289
-
1290
- if (defaultValue !== undefined) {
1291
- argument.default(defaultValue);
1292
- }
1293
-
1294
- return cmd.addArgument(argument);
1295
- }, cmd);
1296
- }
1297
-
1298
- };
1299
-
1300
- tslib.__decorate([di.Constant("project.reinstallAfterRun", false), tslib.__metadata("design:type", Object)], exports.CliService.prototype, "reinstallAfterRun", void 0);
1301
-
1302
- tslib.__decorate([di.Constant("pkg", {
1303
- version: "1.0.0"
1304
- }), tslib.__metadata("design:type", Object)], exports.CliService.prototype, "pkg", void 0);
1305
-
1306
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", di.InjectorService)], exports.CliService.prototype, "injector", void 0);
1307
-
1308
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", CliHooks)], exports.CliService.prototype, "hooks", void 0);
1309
-
1310
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.ProjectPackageJson)], exports.CliService.prototype, "projectPkg", void 0);
1311
-
1312
- exports.CliService = tslib.__decorate([di.Injectable()], exports.CliService);
1313
-
1314
- function CliPackageJson() {
1315
- return di.Inject(CliPackageJson);
1316
- }
1317
- di.registerProvider({
1318
- provide: CliPackageJson,
1319
- deps: [di.Configuration],
1320
-
1321
- useFactory(configuration) {
1322
- return configuration.pkg || {};
1323
- }
1324
-
1325
- });
1326
-
1327
- function cast(value) {
1328
- if (["undefined"].includes(value)) {
1329
- return undefined;
1330
- }
1331
-
1332
- if (["null"].includes(value)) {
1333
- return null;
1334
- }
1335
-
1336
- if (["false"].includes(value)) {
1337
- return false;
1338
- }
1339
-
1340
- if (["true"].includes(value)) {
1341
- return false;
1342
- }
1343
-
1344
- return value;
1345
- }
1346
-
1347
- let CliProxyAgent = class CliProxyAgent {
1348
- constructor() {
1349
- this.proxySettings = void 0;
1350
- this.cliExeca = void 0;
1351
- }
1352
-
1353
- hasProxy() {
1354
- return !!this.proxySettings.url;
1355
- }
1356
-
1357
- get(type) {
1358
- if (this.hasProxy()) {
1359
- const {
1360
- strictSsl = true
1361
- } = this.proxySettings;
1362
- const url = new URL(this.proxySettings.url);
1363
- const protocol = url.protocol.replace(":", "");
1364
- const options = {
1365
- proxy: {
1366
- host: url.hostname,
1367
- port: url.port ? +url.port : undefined,
1368
- proxyAuth: url.username && url.password ? `${url.username}:${url.password}` : undefined,
1369
- rejectUnauthorized: strictSsl
1370
- }
1371
- };
1372
- const method = changeCase.camelCase([type, "over", protocol].join(" "));
1373
-
1374
- if (tunnel__default['default'][method]) {
1375
- return tunnel__default['default'][method](options);
1376
- }
1377
- }
1378
-
1379
- return null;
1380
- }
1381
-
1382
- async resolveProxySettings() {
1383
- if (this.hasProxy()) {
1384
- return;
1385
- }
1386
-
1387
- const result = await Promise.all([this.cliExeca.getAsync("npm", ["config", "get", "proxy"]), this.cliExeca.getAsync("npm", ["config", "get", "http-proxy"]), this.cliExeca.getAsync("npm", ["config", "get", "https-proxy"]), this.cliExeca.getAsync("npm", ["config", "get", "strict-ssl"])]);
1388
- const [proxy, httpProxy, httpsProxy, strictSsl] = result.map(cast);
1389
- const url = httpsProxy || httpProxy || proxy;
1390
-
1391
- if (url) {
1392
- this.proxySettings = {
1393
- url,
1394
- strictSsl: cast(strictSsl) !== false
1395
- };
1396
- }
1397
- }
1398
-
1399
- };
1400
-
1401
- tslib.__decorate([di.Value("proxy", {}), tslib.__metadata("design:type", Object)], CliProxyAgent.prototype, "proxySettings", void 0);
1402
-
1403
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.CliExeca)], CliProxyAgent.prototype, "cliExeca", void 0);
1404
-
1405
- CliProxyAgent = tslib.__decorate([di.Injectable(), di.Configuration({
1406
- proxy: {
1407
- url: process.env.HTTPS_PROXY || process.env.HTTP_PROXY,
1408
- strictSsl: process.env.NODE_TLS_REJECT_UNAUTHORIZED !== undefined ? process.env.NODE_TLS_REJECT_UNAUTHORIZED !== "0" : true
1409
- }
1410
- })], CliProxyAgent);
1411
-
1412
- function logToCurl({
1413
- url,
1414
- method,
1415
- params,
1416
- query,
1417
- data,
1418
- headers = {}
1419
- }) {
1420
- const request = parse__default['default'](url, true);
1421
-
1422
- if (params) {
1423
- request.set("query", Object.assign(params, query));
1424
- }
1425
-
1426
- let curl = `curl -X ${method.toUpperCase()} '${request.toString()}'`;
1427
-
1428
- if (data) {
1429
- curl += ` -d '${JSON.stringify(data)}'`;
1430
- }
1431
-
1432
- curl += Object.entries(headers).reduce((curlHeaders, [key, value]) => `${curlHeaders} -H '${key}: ${value}'`, "");
1433
- return curl;
1434
- }
1435
-
1436
- let CliHttpLogClient = class CliHttpLogClient {
1437
- constructor(options = {}) {
1438
- this.callee = void 0;
1439
- this.logger = void 0;
1440
- this.callee = options.callee || "http";
1441
- }
1442
-
1443
- onSuccess(options) {
1444
- return this.logger.debug(_extends({}, this.formatLog(options), {
1445
- status: "OK"
1446
- }));
1447
- }
1448
-
1449
- onError(error, options) {
1450
- const origin = this.errorMapper(error);
1451
- this.logger.warn(_extends({}, this.formatLog(options), {
1452
- status: "KO",
1453
- callee_code: origin.code,
1454
- callee_error: origin.message,
1455
- callee_request_qs: options.params && querystring__default['default'].stringify(options.params),
1456
- callee_request_headers: options.headers,
1457
- callee_request_body: options.data && JSON.stringify(options.data),
1458
- callee_response_headers: origin.headers,
1459
- callee_response_body: origin.body && JSON.stringify(origin.body),
1460
- callee_response_request_id: origin.x_request_id,
1461
- curl: this.logToCurl(options)
1462
- }));
1463
- }
1464
-
1465
- logToCurl(options) {
1466
- return logToCurl(options);
1467
- }
1468
-
1469
- getStatusCodeFromError(error) {
1470
- return core.getValue(error, "response.status", core.getValue(error, "response.statusCode", core.getValue(error, "status")));
1471
- }
1472
-
1473
- getHeadersFromError(error) {
1474
- return core.getValue(error, "response.headers", core.getValue(error, "headers"));
1475
- }
1476
-
1477
- getResponseBodyFromError(error) {
1478
- return core.getValue(error, "response.data", core.getValue(error, "data"));
1479
- }
1480
-
1481
- formatLog(options) {
1482
- const {
1483
- startTime,
1484
- url,
1485
- method
1486
- } = options;
1487
- const {
1488
- callee
1489
- } = this;
1490
- const duration = new Date().getTime() - startTime;
1491
- return {
1492
- callee,
1493
- url,
1494
- method,
1495
- callee_qs: options.params && querystring__default['default'].stringify(options.params),
1496
- duration: isNaN(duration) ? undefined : duration
1497
- };
1498
- }
1499
-
1500
- errorMapper(error) {
1501
- const statusCode = this.getStatusCodeFromError(error);
1502
- const headers = this.getHeadersFromError(error);
1503
- const body = this.getResponseBodyFromError(error);
1504
- return {
1505
- message: error.message || statusCode,
1506
- code: statusCode,
1507
- headers,
1508
- body,
1509
- x_request_id: core.getValue(error, "response.headers.x-request-id", core.getValue(error, "headers.x-request-id"))
1510
- };
1511
- }
1512
-
1513
- };
1514
-
1515
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", logger$1.Logger)], CliHttpLogClient.prototype, "logger", void 0);
1516
-
1517
- CliHttpLogClient = tslib.__decorate([tslib.__param(0, di.Opts), tslib.__metadata("design:paramtypes", [Object])], CliHttpLogClient);
1518
-
1519
- var CliHttpClient_1;
1520
- exports.CliHttpClient = CliHttpClient_1 = class CliHttpClient extends CliHttpLogClient {
1521
- constructor(...args) {
1522
- super(...args);
1523
- this.cliProxyAgent = void 0;
1524
- this.host = void 0;
1525
- }
1526
-
1527
- static getParamsSerializer(params) {
1528
- return querystring.stringify(core.cleanObject(params));
1529
- }
1530
-
1531
- async $onInit() {
1532
- await this.cliProxyAgent.resolveProxySettings();
1533
- }
1534
-
1535
- async head(endpoint, options = {}) {
1536
- const {
1537
- headers
1538
- } = await axios__default['default'](this.getRequestParameters("HEAD", endpoint, options));
1539
- return headers;
1540
- }
1541
-
1542
- async get(endpoint, options = {}) {
1543
- const result = await this.send(this.getRequestParameters("GET", endpoint, options));
1544
- return this.mapResponse(result, options);
1545
- }
1546
-
1547
- async post(endpoint, options = {}) {
1548
- const result = await this.send(this.getRequestParameters("POST", endpoint, options));
1549
- return this.mapResponse(result, options);
1550
- }
1551
-
1552
- async put(endpoint, options = {}) {
1553
- const result = await this.send(this.getRequestParameters("PUT", endpoint, options));
1554
- return this.mapResponse(result, options);
1555
- }
1556
-
1557
- async patch(endpoint, options = {}) {
1558
- const result = await this.send(this.getRequestParameters("PATCH", endpoint, options));
1559
- return this.mapResponse(result, options);
1560
- }
1561
-
1562
- async delete(endpoint, options = {}) {
1563
- const result = await this.send(this.getRequestParameters("DELETE", endpoint, options));
1564
- return this.mapResponse(result, options);
1565
- }
1566
-
1567
- getRequestParameters(method, endpoint, options) {
1568
- options = _extends({
1569
- method,
1570
- url: (this.host || "") + endpoint.replace(this.host || "", "")
1571
- }, options, {
1572
- params: options.params || options.qs,
1573
- data: options.data,
1574
- headers: _extends({
1575
- "Content-Type": "application/json",
1576
- Accept: "application/json"
1577
- }, options.headers || {})
1578
- });
1579
- this.configureProxy(endpoint, options);
1580
- return options;
1581
- }
1582
-
1583
- configureProxy(endpoint, options) {
1584
- const url = new URL(endpoint);
1585
-
1586
- if (this.cliProxyAgent.hasProxy()) {
1587
- const protocol = url.protocol.replace(":", "");
1588
-
1589
- switch (protocol) {
1590
- case "https":
1591
- options.httpsAgent = this.cliProxyAgent.get(protocol);
1592
- options.proxy = false;
1593
- break;
1594
-
1595
- case "http":
1596
- options.httpAgent = this.cliProxyAgent.get(protocol);
1597
- options.proxy = false;
1598
- break;
1599
- }
1600
- }
1601
- }
1602
-
1603
- async send(options) {
1604
- const startTime = new Date().getTime();
1605
-
1606
- try {
1607
- const response = await axios__default['default'](_extends({
1608
- paramsSerializer: CliHttpClient_1.getParamsSerializer
1609
- }, options));
1610
- this.onSuccess(_extends({
1611
- startTime
1612
- }, options));
1613
- return response;
1614
- } catch (error) {
1615
- this.onError(error, _extends({
1616
- startTime
1617
- }, options));
1618
- throw error;
1619
- }
1620
- }
1621
-
1622
- mapResponse(result, options) {
1623
- const {
1624
- withHeaders
1625
- } = options;
1626
- const data = !withHeaders ? result == null ? void 0 : result.data : result;
1627
- return withHeaders ? {
1628
- data,
1629
- headers: result == null ? void 0 : result.headers
1630
- } : data;
1631
- }
1632
-
1633
- };
1634
-
1635
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", CliProxyAgent)], exports.CliHttpClient.prototype, "cliProxyAgent", void 0);
1636
-
1637
- exports.CliHttpClient = CliHttpClient_1 = tslib.__decorate([di.Injectable()], exports.CliHttpClient);
1638
-
1639
- const all = promises => Promise.all(promises);
1640
-
1641
- async function loadPlugins(injector) {
1642
- const name = injector.settings.get("name");
1643
- const rootDir = injector.settings.get("project.rootDir");
1644
- const projectPackageJson = injector.invoke(exports.ProjectPackageJson);
1645
- const fs = injector.invoke(exports.CliFs);
1646
- const promises = Object.keys(projectPackageJson.allDependencies).filter(mod => mod.startsWith(`@${name}/cli-plugin`) || mod.includes(`${name}-cli-plugin`)).map(async mod => {
1647
- try {
1648
- const {
1649
- default: plugin
1650
- } = await fs.importModule(mod, rootDir);
1651
-
1652
- if (!injector.has(plugin)) {
1653
- var _GlobalProviders$get;
1654
-
1655
- const provider = (_GlobalProviders$get = di.GlobalProviders.get(plugin)) == null ? void 0 : _GlobalProviders$get.clone();
1656
-
1657
- if (provider != null && provider.imports.length) {
1658
- await all(provider.imports.map(async token => {
1659
- var _GlobalProviders$get2;
1660
-
1661
- injector.add(token, (_GlobalProviders$get2 = di.GlobalProviders.get(token)) == null ? void 0 : _GlobalProviders$get2.clone());
1662
-
1663
- if (injector.settings.get("loaded")) {
1664
- await injector.invoke(token);
1665
- }
1666
- }));
1667
- }
1668
-
1669
- injector.add(plugin, provider);
1670
-
1671
- if (injector.settings.get("loaded")) {
1672
- await injector.invoke(plugin);
1673
- }
1674
- }
1675
-
1676
- injector.logger.info(chalk__default['default'].green(listr2.figures.tick), mod, "module loaded");
1677
- } catch (er) {
1678
- injector.logger.warn(chalk__default['default'].red(listr2.figures.cross), "Fail to load plugin", mod);
1679
- }
1680
- });
1681
- await all(promises);
1682
- }
1683
-
1684
- var NpmRegistryClient_1;
1685
-
1686
- const HOST = require("registry-url")();
1687
-
1688
- const REGEX_REGISTRY_ENFORCED_HTTPS = /^https?:\/\/([^\/]+\.)?(yarnpkg\.com|npmjs\.(org|com))(\/|$)/;
1689
- const REGEX_REGISTRY_PREFIX = /^(https?:)?\/\//i;
1690
- function addSuffix(pattern, suffix) {
1691
- if (!pattern.endsWith(suffix)) {
1692
- return pattern + suffix;
1693
- }
1694
-
1695
- return pattern;
1696
- }
1697
- const SCOPE_SEPARATOR = "%2f";
1698
- exports.NpmRegistryClient = NpmRegistryClient_1 = class NpmRegistryClient {
1699
- constructor() {
1700
- this.httpClient = void 0;
1701
- }
1702
-
1703
- static escapeName(name) {
1704
- // scoped packages contain slashes and the npm registry expects them to be escaped
1705
- return name.replace("/", SCOPE_SEPARATOR);
1706
- }
1707
-
1708
- async request(pathname, opts = {}) {
1709
- const registry = opts.registry || HOST;
1710
- const requestUrl = this.getRequestUrl(registry, pathname);
1711
-
1712
- const headers = _extends({
1713
- Accept: opts.unfiltered ? "application/json" : "application/vnd.npm.install-v1+json; q=1.0, application/json; q=0.8, */*"
1714
- }, opts.headers);
1715
-
1716
- try {
1717
- return await this.httpClient.get(requestUrl, _extends({}, opts, {
1718
- headers
1719
- }));
1720
- } catch (error) {
1721
- if (opts.retry) {
1722
- await new Promise(resolve => setTimeout(resolve, 200));
1723
- opts.retry -= 1;
1724
- opts.unfiltered = true;
1725
- return this.request(NpmRegistryClient_1.escapeName(pathname), opts);
1726
- }
1727
-
1728
- throw error;
1729
- }
1730
- }
1731
-
1732
- getRequestUrl(registry, pathname) {
1733
- let resolved = pathname;
1734
-
1735
- if (!REGEX_REGISTRY_PREFIX.test(pathname)) {
1736
- resolved = url__default['default'].resolve(addSuffix(registry, "/"), pathname);
1737
- }
1738
-
1739
- if (REGEX_REGISTRY_ENFORCED_HTTPS.test(resolved)) {
1740
- resolved = resolved.replace(/^http:\/\//, "https://");
1741
- }
1742
-
1743
- return resolved;
1744
- }
1745
- /**
1746
- * Search a module on npm registry
1747
- * @param text
1748
- * @param options
1749
- */
1750
-
1751
-
1752
- async search(text, options = {}) {
1753
- const {
1754
- objects: result
1755
- } = await this.request(`-/v1/search`, {
1756
- headers: {
1757
- "Accept-Encoding": "gzip"
1758
- },
1759
- qs: _extends({
1760
- text,
1761
- size: 100,
1762
- from: 0,
1763
- quality: 0.65,
1764
- popularity: 0.98,
1765
- maintenance: 0.5
1766
- }, options)
1767
- });
1768
- return result;
1769
- }
1770
-
1771
- async info(packageName, retry = 0) {
1772
- try {
1773
- return await this.request(packageName, {
1774
- headers: {
1775
- "Accept-Encoding": "gzip"
1776
- },
1777
- unfiltered: false,
1778
- retry
1779
- });
1780
- } catch (er) {
1781
- return retry == 0 ? this.fallback(packageName) : null;
1782
- }
1783
- }
1784
-
1785
- async fallback(packageName) {
1786
- const [{
1787
- package: pkg
1788
- }] = await this.search(packageName);
1789
- return _extends({}, pkg, {
1790
- "dist-tags": {
1791
- latest: pkg.version
1792
- },
1793
- versions: {
1794
- [pkg.version]: {
1795
- name: packageName,
1796
- version: pkg.version,
1797
- dependencies: {},
1798
- devDependencies: {}
1799
- }
1800
- }
1801
- });
1802
- }
1803
-
1804
- };
1805
-
1806
- tslib.__decorate([di.Inject(exports.CliHttpClient), tslib.__metadata("design:type", exports.CliHttpClient)], exports.NpmRegistryClient.prototype, "httpClient", void 0);
1807
-
1808
- exports.NpmRegistryClient = NpmRegistryClient_1 = tslib.__decorate([di.Injectable()], exports.NpmRegistryClient);
1809
-
1810
- const _excluded$1 = ["name", "description"];
1811
-
1812
- function mapPlugins(_ref) {
1813
- let {
1814
- package: {
1815
- name,
1816
- description = ""
1817
- }
1818
- } = _ref,
1819
- otherProps = _objectWithoutPropertiesLoose(_ref.package, _excluded$1);
1820
-
1821
- return _extends({
1822
- name: `${name} ${description}`.trim(),
1823
- value: name
1824
- }, otherProps);
1825
- }
1826
-
1827
- exports.CliPlugins = class CliPlugins {
1828
- constructor() {
1829
- this.name = void 0;
1830
- this.npmRegistryClient = void 0;
1831
- this.injector = void 0;
1832
- this.cliHooks = void 0;
1833
- this.packageJson = void 0;
1834
- }
1835
-
1836
- async searchPlugins(keyword = "", options = {}) {
1837
- const result = await this.npmRegistryClient.search(this.getKeyword(keyword), options);
1838
- return result.filter(({
1839
- package: {
1840
- name
1841
- }
1842
- }) => this.isPlugin(name)).map(mapPlugins);
1843
- }
1844
-
1845
- async loadPlugins() {
1846
- return loadPlugins(this.injector);
1847
- }
1848
-
1849
- addPluginsDependencies(ctx) {
1850
- const plugins = Object.keys(this.packageJson.devDependencies).filter(name => this.isPlugin(name));
1851
- const tasks = plugins.map(plugin => {
1852
- return {
1853
- title: `Run plugin '${chalk__default['default'].cyan(plugin)}'`,
1854
- task: () => this.cliHooks.emit(CommandStoreKeys.ADD, plugin, ctx)
1855
- };
1856
- });
1857
- return [...tasks, {
1858
- title: "Install",
1859
- task: createSubTasks(() => this.packageJson.install(ctx), _extends({}, ctx, {
1860
- concurrent: false
1861
- }))
1862
- }];
1863
- }
1864
-
1865
- getKeyword(keyword) {
1866
- return `@${this.name}/cli-plugin-${this.cleanKeyword(keyword)}`;
1867
- }
1868
-
1869
- cleanKeyword(keyword) {
1870
- return keyword.replace(this.name, "").replace("@", "").replace("/", "").replace("cli-plugin-", "");
1871
- }
1872
-
1873
- isPlugin(name) {
1874
- return name.startsWith(`@${this.name}/cli-plugin`) || name.includes(`${this.name}-cli-plugin`);
1875
- }
1876
-
1877
- };
1878
-
1879
- tslib.__decorate([di.Constant("name"), tslib.__metadata("design:type", String)], exports.CliPlugins.prototype, "name", void 0);
1880
-
1881
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.NpmRegistryClient)], exports.CliPlugins.prototype, "npmRegistryClient", void 0);
1882
-
1883
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", di.InjectorService)], exports.CliPlugins.prototype, "injector", void 0);
1884
-
1885
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", CliHooks)], exports.CliPlugins.prototype, "cliHooks", void 0);
1886
-
1887
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.ProjectPackageJson)], exports.CliPlugins.prototype, "packageJson", void 0);
1888
-
1889
- exports.CliPlugins = tslib.__decorate([di.Injectable()], exports.CliPlugins);
1890
-
1891
- const runScript = require("@npmcli/run-script");
1892
-
1893
- exports.CliRunScript = class CliRunScript {
1894
- constructor() {
1895
- this.projectPackageJson = void 0;
1896
- }
1897
-
1898
- run(cmd, args, options = {}) {
1899
- return runScript(_extends({
1900
- event: "run"
1901
- }, options, {
1902
- cmd: `${cmd} ${args.join(" ")}`,
1903
- path: options.cwd || this.projectPackageJson.dir,
1904
- env: options.env || {},
1905
- stdio: options.stdio || "inherit",
1906
- banner: false
1907
- }));
1908
- }
1909
-
1910
- };
1911
-
1912
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.ProjectPackageJson)], exports.CliRunScript.prototype, "projectPackageJson", void 0);
1913
-
1914
- exports.CliRunScript = tslib.__decorate([di.Injectable()], exports.CliRunScript);
1915
-
1916
- const util$3 = require("handlebars-utils");
1917
-
1918
- const helpers$4 = {};
1919
-
1920
- const contains = (val, obj, start) => {
1921
- if (val == null || obj == null || !core.isNumber(val.length)) {
1922
- return false;
1923
- }
1924
-
1925
- return val.indexOf(obj, start) !== -1;
1926
- };
1927
- /**
1928
- * Helper that renders the block if **both** of the given values
1929
- * are truthy. If an inverse block is specified it will be rendered
1930
- * when falsy. Works as a block helper, inline helper or
1931
- * subexpression.
1932
- *
1933
- * ```handlebars
1934
- * <!-- {great: true, magnificent: true} -->
1935
- * {{#and great magnificent}}A{{else}}B{{/and}}
1936
- * <!-- results in: 'A' -->
1937
- * ```
1938
- * @param {any} `a`
1939
- * @param {any} `b`
1940
- * @param {Object} `options` Handlebars provided options object
1941
- * @return {String}
1942
- * @block
1943
- * @api public
1944
- */
1945
-
1946
-
1947
- helpers$4.and = (...args) => {
1948
- const len = args.length - 1;
1949
- const options = args[len];
1950
- let val = true;
1951
-
1952
- for (let i = 0; i < len; i++) {
1953
- if (!args[i]) {
1954
- val = false;
1955
- break;
1956
- }
1957
- }
1958
-
1959
- return util$3.value(val, undefined, options);
1960
- };
1961
- /**
1962
- * Render a block when a comparison of the first and third
1963
- * arguments returns true. The second argument is
1964
- * the [arithemetic operator][operators] to use. You may also
1965
- * optionally specify an inverse block to render when falsy.
1966
- *
1967
- * @param `a`
1968
- * @param `operator` The operator to use. Operators must be enclosed in quotes: `">"`, `"="`, `"<="`, and so on.
1969
- * @param `b`
1970
- * @param {Object} `options` Handlebars provided options object
1971
- * @return {String} Block, or if specified the inverse block is rendered if falsey.
1972
- * @block
1973
- * @api public
1974
- */
1975
-
1976
-
1977
- helpers$4.compare = function (a, operator, b, options) {
1978
- /*eslint eqeqeq: 0*/
1979
- if (arguments.length < 4) {
1980
- throw new Error("handlebars Helper {{compare}} expects 4 arguments");
1981
- }
1982
-
1983
- let result;
1984
-
1985
- switch (operator) {
1986
- case "==":
1987
- result = a == b;
1988
- break;
1989
-
1990
- case "===":
1991
- result = a === b;
1992
- break;
1993
-
1994
- case "!=":
1995
- result = a != b;
1996
- break;
1997
-
1998
- case "!==":
1999
- result = a !== b;
2000
- break;
2001
-
2002
- case "<":
2003
- result = a < b;
2004
- break;
2005
-
2006
- case ">":
2007
- result = a > b;
2008
- break;
2009
-
2010
- case "<=":
2011
- result = a <= b;
2012
- break;
2013
-
2014
- case ">=":
2015
- result = a >= b;
2016
- break;
2017
-
2018
- case "typeof":
2019
- result = typeof a === b;
2020
- break;
2021
-
2022
- default:
2023
- {
2024
- throw new Error("helper {{compare}}: invalid operator: `" + operator + "`");
2025
- }
2026
- }
2027
-
2028
- return util$3.value(result, this, options);
2029
- };
2030
- /**
2031
- * Block helper that renders the block if `collection` has the
2032
- * given `value`, using strict equality (`===`) for comparison,
2033
- * otherwise the inverse block is rendered (if specified). If a
2034
- * `startIndex` is specified and is negative, it is used as the
2035
- * offset from the end of the collection.
2036
- *
2037
- * ```handlebars
2038
- * <!-- array = ['a', 'b', 'c'] -->
2039
- * {{#contains array "d"}}
2040
- * This will not be rendered.
2041
- * {{else}}
2042
- * This will be rendered.
2043
- * {{/contains}}
2044
- * ```
2045
- * @param {Array|Object|String} `collection` The collection to iterate over.
2046
- * @param {any} `value` The value to check for.
2047
- * @param {Number} `[startIndex=0]` Optionally define the starting index.
2048
- * @param {Object} `options` Handlebars provided options object.
2049
- * @block
2050
- * @api public
2051
- */
2052
-
2053
-
2054
- helpers$4.contains = function (collection, value, startIndex, options) {
2055
- if (typeof startIndex === "object") {
2056
- options = startIndex;
2057
- startIndex = undefined;
2058
- }
2059
-
2060
- const val = contains(collection, value, startIndex);
2061
- return util$3.value(val, this, options);
2062
- };
2063
- /**
2064
- * Returns the first value that is not undefined, otherwise the "default" value is returned.
2065
- *
2066
- * @param {any} `value`
2067
- * @param {any} `defaultValue`
2068
- * @return {String}
2069
- * @alias .or
2070
- * @api public
2071
- */
2072
-
2073
-
2074
- helpers$4.default = (...args) => {
2075
- for (let i = 0; i < args.length - 1; i++) {
2076
- if (args[i] != null) return args[i];
2077
- }
2078
-
2079
- return "";
2080
- };
2081
- /**
2082
- * Block helper that renders a block if `a` is **equal to** `b`.
2083
- * If an inverse block is specified it will be rendered when falsy.
2084
- * You may optionally use the `compare=""` hash argument for the
2085
- * second value.
2086
- *
2087
- * @param {String} `a`
2088
- * @param {String} `b`
2089
- * @param {Object} `options` Handlebars provided options object
2090
- * @return {String} Block, or inverse block if specified and falsey.
2091
- * @alias is
2092
- * @block
2093
- * @api public
2094
- */
2095
-
2096
-
2097
- helpers$4.eq = function (a, b, options) {
2098
- if (arguments.length === 2) {
2099
- options = b;
2100
- b = options.hash.compare;
2101
- }
2102
-
2103
- return util$3.value(a === b, this, options);
2104
- };
2105
- /**
2106
- * Block helper that renders a block if `a` is **greater than** `b`.
2107
- *
2108
- * If an inverse block is specified it will be rendered when falsy.
2109
- * You may optionally use the `compare=""` hash argument for the
2110
- * second value.
2111
- *
2112
- * @param {String} `a`
2113
- * @param {String} `b`
2114
- * @param {Object} `options` Handlebars provided options object
2115
- * @return {String} Block, or inverse block if specified and falsey.
2116
- * @block
2117
- * @api public
2118
- */
2119
-
2120
-
2121
- helpers$4.gt = function (a, b, options) {
2122
- if (arguments.length === 2) {
2123
- options = b;
2124
- b = options.hash.compare;
2125
- }
2126
-
2127
- return util$3.value(a > b, this, options);
2128
- };
2129
- /**
2130
- * Block helper that renders a block if `a` is **greater than or
2131
- * equal to** `b`.
2132
- *
2133
- * If an inverse block is specified it will be rendered when falsy.
2134
- * You may optionally use the `compare=""` hash argument for the
2135
- * second value.
2136
- *
2137
- * @param {String} `a`
2138
- * @param {String} `b`
2139
- * @param {Object} `options` Handlebars provided options object
2140
- * @return {String} Block, or inverse block if specified and falsey.
2141
- * @block
2142
- * @api public
2143
- */
2144
-
2145
-
2146
- helpers$4.gte = function (a, b, options) {
2147
- if (arguments.length === 2) {
2148
- options = b;
2149
- b = options.hash.compare;
2150
- }
2151
-
2152
- return util$3.value(a >= b, this, options);
2153
- };
2154
- /**
2155
- * Block helper that renders a block if `a` is **equal to** `b`.
2156
- * If an inverse block is specified it will be rendered when falsy.
2157
- * Similar to [eq](#eq) but does not do strict equality.
2158
- *
2159
- * @param {any} `a`
2160
- * @param {any} `b`
2161
- * @param {Object} `options` Handlebars provided options object
2162
- * @return {String}
2163
- * @block
2164
- * @api public
2165
- */
2166
-
2167
-
2168
- helpers$4.is = function (a, b, options) {
2169
- if (arguments.length === 2) {
2170
- options = b;
2171
- b = options.hash.compare;
2172
- }
2173
-
2174
- return util$3.value(a == b, this, options);
2175
- };
2176
- /**
2177
- * Block helper that renders a block if `a` is **not equal to** `b`.
2178
- * If an inverse block is specified it will be rendered when falsy.
2179
- * Similar to [unlessEq](#unlesseq) but does not use strict equality for
2180
- * comparisons.
2181
- *
2182
- * @param {String} `a`
2183
- * @param {String} `b`
2184
- * @param {Object} `options` Handlebars provided options object
2185
- * @return {String}
2186
- * @block
2187
- * @api public
2188
- */
2189
-
2190
-
2191
- helpers$4.isnt = function (a, b, options) {
2192
- if (arguments.length === 2) {
2193
- options = b;
2194
- b = options.hash.compare;
2195
- }
2196
-
2197
- return util$3.value(a != b, this, options);
2198
- };
2199
- /**
2200
- * Block helper that renders a block if `a` is **less than** `b`.
2201
- *
2202
- * If an inverse block is specified it will be rendered when falsy.
2203
- * You may optionally use the `compare=""` hash argument for the
2204
- * second value.
2205
- *
2206
- * @param {Object} `context`
2207
- * @param {Object} `options` Handlebars provided options object
2208
- * @return {String} Block, or inverse block if specified and falsey.
2209
- * @block
2210
- * @api public
2211
- */
2212
-
2213
-
2214
- helpers$4.lt = function (a, b, options) {
2215
- if (arguments.length === 2) {
2216
- options = b;
2217
- b = options.hash.compare;
2218
- }
2219
-
2220
- return util$3.value(a < b, this, options);
2221
- };
2222
- /**
2223
- * Block helper that renders a block if `a` is **less than or
2224
- * equal to** `b`.
2225
- *
2226
- * If an inverse block is specified it will be rendered when falsy.
2227
- * You may optionally use the `compare=""` hash argument for the
2228
- * second value.
2229
- *
2230
- * @param {Sring} `a`
2231
- * @param {Sring} `b`
2232
- * @param {Object} `options` Handlebars provided options object
2233
- * @return {String} Block, or inverse block if specified and falsey.
2234
- * @block
2235
- * @api public
2236
- */
2237
-
2238
-
2239
- helpers$4.lte = function (a, b, options) {
2240
- if (arguments.length === 2) {
2241
- options = b;
2242
- b = options.hash.compare;
2243
- }
2244
-
2245
- return util$3.value(a <= b, this, options);
2246
- };
2247
- /**
2248
- * Block helper that renders a block if **neither of** the given values
2249
- * are truthy. If an inverse block is specified it will be rendered
2250
- * when falsy.
2251
- *
2252
- * @param {any} `a`
2253
- * @param {any} `b`
2254
- * @param `options` Handlebars options object
2255
- * @return {String} Block, or inverse block if specified and falsey.
2256
- * @block
2257
- * @api public
2258
- */
2259
-
2260
-
2261
- helpers$4.neither = function (a, b, options) {
2262
- return util$3.value(!a && !b, this, options);
2263
- };
2264
- /**
2265
- * Returns true if `val` is falsey. Works as a block or inline helper.
2266
- *
2267
- * @param {String} `val`
2268
- * @param {Object} `options` Handlebars provided options object
2269
- * @return {String}
2270
- * @block
2271
- * @api public
2272
- */
2273
-
2274
-
2275
- helpers$4.not = function (val, options) {
2276
- return util$3.value(!val, this, options);
2277
- };
2278
- /**
2279
- * Block helper that renders a block if **any of** the given values
2280
- * is truthy. If an inverse block is specified it will be rendered
2281
- * when falsy.
2282
- *
2283
- * ```handlebars
2284
- * {{#or a b c}}
2285
- * If any value is true this will be rendered.
2286
- * {{/or}}
2287
- * ```
2288
- *
2289
- * @param {...any} `arguments` Variable number of arguments
2290
- * @param {Object} `options` Handlebars options object
2291
- * @return {String} Block, or inverse block if specified and falsey.
2292
- * @block
2293
- * @api public
2294
- */
2295
-
2296
-
2297
- helpers$4.or = function (...args) {
2298
- const len = args.length - 1;
2299
- const options = args[len];
2300
- let val = false;
2301
-
2302
- for (let i = 0; i < len; i++) {
2303
- if (args[i]) {
2304
- val = true;
2305
- break;
2306
- }
2307
- }
2308
-
2309
- return util$3.value(val, this, options);
2310
- };
2311
- /**
2312
- * Block helper that always renders the inverse block **unless `a` is
2313
- * is equal to `b`**.
2314
- *
2315
- * @param {String} `a`
2316
- * @param {String} `b`
2317
- * @param {Object} `options` Handlebars provided options object
2318
- * @return {String} Inverse block by default, or block if falsey.
2319
- * @block
2320
- * @api public
2321
- */
2322
-
2323
-
2324
- helpers$4.unlessEq = function (a, b, options) {
2325
- if (util$3.isOptions(b)) {
2326
- options = b;
2327
- b = options.hash.compare;
2328
- }
2329
-
2330
- return util$3.value(a !== b, this, options);
2331
- };
2332
- /**
2333
- * Block helper that always renders the inverse block **unless `a` is
2334
- * is greater than `b`**.
2335
- *
2336
- * @param {Object} `a` The default value
2337
- * @param {Object} `b` The value to compare
2338
- * @param {Object} `options` Handlebars provided options object
2339
- * @return {String} Inverse block by default, or block if falsey.
2340
- * @block
2341
- * @api public
2342
- */
2343
-
2344
-
2345
- helpers$4.unlessGt = function (a, b, options) {
2346
- if (util$3.isOptions(b)) {
2347
- options = b;
2348
- b = options.hash.compare;
2349
- }
2350
-
2351
- return util$3.value(a <= b, this, options);
2352
- };
2353
- /**
2354
- * Block helper that always renders the inverse block **unless `a` is
2355
- * is less than `b`**.
2356
- *
2357
- * @param {Object} `a` The default value
2358
- * @param {Object} `b` The value to compare
2359
- * @param {Object} `options` Handlebars provided options object
2360
- * @return {String} Block, or inverse block if specified and falsey.
2361
- * @block
2362
- * @api public
2363
- */
2364
-
2365
-
2366
- helpers$4.unlessLt = function (a, b, options) {
2367
- if (util$3.isOptions(b)) {
2368
- options = b;
2369
- b = options.hash.compare;
2370
- }
2371
-
2372
- return util$3.value(a >= b, this, options);
2373
- };
2374
- /**
2375
- * Block helper that always renders the inverse block **unless `a` is
2376
- * is greater than or equal to `b`**.
2377
- *
2378
- * @param {any} `a`
2379
- * @param {any} `b`
2380
- * @param {Object} `options` Handlebars provided options object
2381
- * @return {String} Block, or inverse block if specified and falsey.
2382
- * @block
2383
- * @api public
2384
- */
2385
-
2386
-
2387
- helpers$4.unlessGteq = function (a, b, options) {
2388
- if (util$3.isOptions(b)) {
2389
- options = b;
2390
- b = options.hash.compare;
2391
- }
2392
-
2393
- return util$3.value(a < b, this, options);
2394
- };
2395
- /**
2396
- * Block helper that always renders the inverse block **unless `a` is
2397
- * is less than or equal to `b`**.
2398
- *
2399
- * @param {any} `a`
2400
- * @param {any} `b`
2401
- * @param {Object} `options` Handlebars provided options object
2402
- * @return {String} Block, or inverse block if specified and falsey.
2403
- * @block
2404
- * @api public
2405
- */
2406
-
2407
-
2408
- helpers$4.unlessLteq = function (a, b, options) {
2409
- if (util$3.isOptions(b)) {
2410
- options = b;
2411
- b = options.hash.compare;
2412
- }
2413
-
2414
- return util$3.value(a > b, this, options);
2415
- };
2416
-
2417
- const createFrame$1 = require("create-frame");
2418
-
2419
- const util$2 = require("handlebars-utils");
2420
-
2421
- const helpers$3 = {};
2422
- /**
2423
- * Returns all of the items in an array after the specified index.
2424
- * Opposite of [before](#before).
2425
- *
2426
- * ```handlebars
2427
- * <!-- array: ['a', 'b', 'c'] -->
2428
- * {{after array 1}}
2429
- * <!-- results in: '["c"]' -->
2430
- * ```
2431
- * @param {Array} `array` Collection
2432
- * @param {Number} `n` Starting index (number of items to exclude)
2433
- * @return {Array} Array exluding `n` items.
2434
- * @api public
2435
- */
2436
-
2437
- helpers$3.after = function (array, n) {
2438
- if (util$2.isUndefined(array)) return "";
2439
- return array.slice(n);
2440
- };
2441
- /**
2442
- * Cast the given `value` to an array.
2443
- *
2444
- * ```handlebars
2445
- * {{arrayify "foo"}}
2446
- * <!-- results in: [ "foo" ] -->
2447
- * ```
2448
- * @param {any} `value`
2449
- * @return {Array}
2450
- * @api public
2451
- */
2452
-
2453
-
2454
- helpers$3.arrayify = function (value) {
2455
- return value ? core.isArray(value) ? value : [value] : [];
2456
- };
2457
- /**
2458
- * Return all of the items in the collection before the specified
2459
- * count. Opposite of [after](#after).
2460
- *
2461
- * ```handlebars
2462
- * <!-- array: ['a', 'b', 'c'] -->
2463
- * {{before array 2}}
2464
- * <!-- results in: '["a", "b"]' -->
2465
- * ```
2466
- * @param {Array} `array`
2467
- * @param {Number} `n`
2468
- * @return {Array} Array excluding items after the given number.
2469
- * @api public
2470
- */
2471
-
2472
-
2473
- helpers$3.before = function (array, n) {
2474
- if (util$2.isUndefined(array)) return "";
2475
- return array.slice(0, -n);
2476
- };
2477
- /**
2478
- * ```handlebars
2479
- * <!-- array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] -->
2480
- * {{#eachIndex array}}
2481
- * {{item}} is {{index}}
2482
- * {{/eachIndex}}
2483
- * ```
2484
- * @param {Array} `array`
2485
- * @param {Object} `options`
2486
- * @return {String}
2487
- * @block
2488
- * @api public
2489
- */
2490
-
2491
-
2492
- helpers$3.eachIndex = function (array, options) {
2493
- let result = "";
2494
-
2495
- for (let i = 0; i < array.length; i++) {
2496
- result += options.fn({
2497
- item: array[i],
2498
- index: i
2499
- });
2500
- }
2501
-
2502
- return result;
2503
- };
2504
- /**
2505
- * Block helper that filters the given array and renders the block for values that
2506
- * evaluate to `true`, otherwise the inverse block is returned.
2507
- *
2508
- * ```handlebars
2509
- * <!-- array: ['a', 'b', 'c'] -->
2510
- * {{#filter array "foo"}}AAA{{else}}BBB{{/filter}}
2511
- * <!-- results in: 'BBB' -->
2512
- * ```
2513
- * @param {Array} `array`
2514
- * @param {any} `value`
2515
- * @param {Object} `options`
2516
- * @return {String}
2517
- * @block
2518
- * @api public
2519
- */
2520
-
2521
-
2522
- helpers$3.filter = function (array, value, options) {
2523
- let content = "";
2524
- let results = []; // filter on a specific property
2525
-
2526
- const prop = options.hash && (options.hash.property || options.hash.prop);
2527
-
2528
- if (prop) {
2529
- results = array.filter(function (val) {
2530
- return value === core.getValue(val, prop);
2531
- });
2532
- } else {
2533
- // filter on a string value
2534
- results = array.filter(function (v) {
2535
- return value === v;
2536
- });
2537
- }
2538
-
2539
- if (results && results.length > 0) {
2540
- for (let i = 0; i < results.length; i++) {
2541
- content += options.fn(results[i]);
2542
- }
2543
-
2544
- return content;
2545
- }
2546
-
2547
- return options.inverse(this);
2548
- };
2549
- /**
2550
- * Returns the first item, or first `n` items of an array.
2551
- *
2552
- * ```handlebars
2553
- * {{first "['a', 'b', 'c', 'd', 'e']" 2}}
2554
- * <!-- results in: '["a", "b"]' -->
2555
- * ```
2556
- * @param {Array} `array`
2557
- * @param {Number} `n` Number of items to return, starting at `0`.
2558
- * @return {Array}
2559
- * @api public
2560
- */
2561
-
2562
-
2563
- helpers$3.first = function (array, n) {
2564
- if (array === undefined) return "";
2565
-
2566
- if (!core.isNumber(n)) {
2567
- return array[0];
2568
- }
2569
-
2570
- return array.slice(0, n);
2571
- };
2572
- /**
2573
- * Iterates over each item in an array and exposes the current item
2574
- * in the array as context to the inner block. In addition to
2575
- * the current array item, the helper exposes the following variables
2576
- * to the inner block:
2577
- *
2578
- * - `index`
2579
- * - `total`
2580
- * - `isFirst`
2581
- * - `isLast`
2582
- *
2583
- * Also, `@index` is exposed as a private variable, and additional
2584
- * private variables may be defined as hash arguments.
2585
- *
2586
- * ```handlebars
2587
- * <!-- accounts = [
2588
- * {'name': 'John', 'email': 'john@example.com'},
2589
- * {'name': 'Malcolm', 'email': 'malcolm@example.com'},
2590
- * {'name': 'David', 'email': 'david@example.com'}
2591
- * ] -->
2592
- *
2593
- * {{#forEach accounts}}
2594
- * <a href="mailto:{{ email }}" title="Send an email to {{ name }}">
2595
- * {{ name }}
2596
- * </a>{{#unless isLast}}, {{/unless}}
2597
- * {{/forEach}}
2598
- * ```
2599
- * @source <http://stackoverflow.com/questions/13861007>
2600
- * @param {Array} `array`
2601
- * @return {String}
2602
- * @block
2603
- * @api public
2604
- */
2605
-
2606
-
2607
- helpers$3.forEach = function (array, options) {
2608
- const data = createFrame$1(options, options.hash);
2609
- const len = array.length;
2610
- let buffer = "";
2611
- let i = -1;
2612
-
2613
- while (++i < len) {
2614
- const item = array[i];
2615
- data.index = i;
2616
- item.index = i + 1;
2617
- item.total = len;
2618
- item.isFirst = i === 0;
2619
- item.isLast = i === len - 1;
2620
- buffer += options.fn(item, {
2621
- data: data
2622
- });
2623
- }
2624
-
2625
- return buffer;
2626
- };
2627
- /**
2628
- * Block helper that renders the block if an array has the
2629
- * given `value`. Optionally specify an inverse block to render
2630
- * when the array does not have the given value.
2631
- *
2632
- * ```handlebars
2633
- * <!-- array: ['a', 'b', 'c'] -->
2634
- * {{#inArray array "d"}}
2635
- * foo
2636
- * {{else}}
2637
- * bar
2638
- * {{/inArray}}
2639
- * <!-- results in: 'bar' -->
2640
- * ```
2641
- * @param {Array} `array`
2642
- * @param {any} `value`
2643
- * @param {Object} `options`
2644
- * @return {String}
2645
- * @block
2646
- * @api public
2647
- */
2648
-
2649
-
2650
- helpers$3.inArray = function (array, value, options) {
2651
- return util$2.value(util$2.indexOf(array, value) > -1, this, options);
2652
- };
2653
- /**
2654
- * Returns true if `value` is an es5 array.
2655
- *
2656
- * ```handlebars
2657
- * {{isArray "abc"}}
2658
- * <!-- results in: false -->
2659
- *
2660
- * <!-- array: [1, 2, 3] -->
2661
- * {{isArray array}}
2662
- * <!-- results in: true -->
2663
- * ```
2664
- * @param {any} `value` The value to test.
2665
- * @return {Boolean}
2666
- * @api public
2667
- */
2668
-
2669
-
2670
- helpers$3.isArray = function (value) {
2671
- return Array.isArray(value);
2672
- };
2673
- /**
2674
- * Returns the item from `array` at index `idx`.
2675
- *
2676
- * ```handlebars
2677
- * <!-- array: ['a', 'b', 'c'] -->
2678
- * {{itemAt array 1}}
2679
- * <!-- results in: 'b' -->
2680
- * ```
2681
- * @param {Array} `array`
2682
- * @param {Number} `idx`
2683
- * @return {any} `value`
2684
- * @block
2685
- * @api public
2686
- */
2687
-
2688
-
2689
- helpers$3.itemAt = function (array, idx) {
2690
- array = util$2.result(array);
2691
-
2692
- if (core.isArray(array)) {
2693
- idx = core.isNumber(idx) ? +idx : 0;
2694
-
2695
- if (idx < 0) {
2696
- return array[array.length + idx];
2697
- }
2698
-
2699
- if (idx < array.length) {
2700
- return array[idx];
2701
- }
2702
- }
2703
- };
2704
- /**
2705
- * Join all elements of array into a string, optionally using a
2706
- * given separator.
2707
- *
2708
- * ```handlebars
2709
- * <!-- array: ['a', 'b', 'c'] -->
2710
- * {{join array}}
2711
- * <!-- results in: 'a, b, c' -->
2712
- *
2713
- * {{join array '-'}}
2714
- * <!-- results in: 'a-b-c' -->
2715
- * ```
2716
- * @param {Array} `array`
2717
- * @param {String} `separator` The separator to use. Defaults to `, `.
2718
- * @return {String}
2719
- * @api public
2720
- */
2721
-
2722
-
2723
- helpers$3.join = function (array, separator) {
2724
- if (core.isString(array)) return array;
2725
- if (!core.isArray(array)) return "";
2726
- separator = util$2.isString(separator) ? separator : ", ";
2727
- return array.join(separator);
2728
- };
2729
- /**
2730
- * Returns true if the the length of the given `value` is equal
2731
- * to the given `length`. Can be used as a block or inline helper.
2732
- *
2733
- * @param {Array|String} `value`
2734
- * @param {Number} `length`
2735
- * @param {Object} `options`
2736
- * @return {String}
2737
- * @block
2738
- * @api public
2739
- */
2740
-
2741
-
2742
- helpers$3.equalsLength = function (value, length, options) {
2743
- if (util$2.isOptions(length)) {
2744
- options = length;
2745
- length = 0;
2746
- }
2747
-
2748
- let len = 0;
2749
-
2750
- if (typeof value === "string" || Array.isArray(value)) {
2751
- len = value.length;
2752
- }
2753
-
2754
- return util$2.value(len === length, this, options);
2755
- };
2756
- /**
2757
- * Returns the last item, or last `n` items of an array or string.
2758
- * Opposite of [first](#first).
2759
- *
2760
- * ```handlebars
2761
- * <!-- var value = ['a', 'b', 'c', 'd', 'e'] -->
2762
- *
2763
- * {{last value}}
2764
- * <!-- results in: ['e'] -->
2765
- *
2766
- * {{last value 2}}
2767
- * <!-- results in: ['d', 'e'] -->
2768
- *
2769
- * {{last value 3}}
2770
- * <!-- results in: ['c', 'd', 'e'] -->
2771
- * ```
2772
- * @param {Array|String} `value` Array or string.
2773
- * @param {Number} `n` Number of items to return from the end of the array.
2774
- * @return {Array}
2775
- * @api public
2776
- */
2777
-
2778
-
2779
- helpers$3.last = function (value, n) {
2780
- if (!core.isArray(value) && typeof value !== "string") {
2781
- return "";
2782
- }
2783
-
2784
- if (!core.isNumber(n)) {
2785
- return value[value.length - 1];
2786
- }
2787
-
2788
- return value.slice(-Math.abs(n));
2789
- };
2790
- /**
2791
- * Returns the length of the given string or array.
2792
- *
2793
- * ```handlebars
2794
- * {{length '["a", "b", "c"]'}}
2795
- * <!-- results in: 3 -->
2796
- *
2797
- * <!-- results in: myArray = ['a', 'b', 'c', 'd', 'e']; -->
2798
- * {{length myArray}}
2799
- * <!-- results in: 5 -->
2800
- *
2801
- * <!-- results in: myObject = {'a': 'a', 'b': 'b'}; -->
2802
- * {{length myObject}}
2803
- * <!-- results in: 2 -->
2804
- * ```
2805
- * @param {Array|Object|String} `value`
2806
- * @return {Number} The length of the value.
2807
- * @api public
2808
- */
2809
-
2810
-
2811
- helpers$3.length = function (value) {
2812
- if (core.isObject(value) && !util$2.isOptions(value)) {
2813
- value = Object.keys(value);
2814
- }
2815
-
2816
- if (typeof value === "string" || Array.isArray(value)) {
2817
- return value.length;
2818
- }
2819
-
2820
- return 0;
2821
- };
2822
- /**
2823
- * Returns a new array, created by calling `function` on each
2824
- * element of the given `array`. For example,
2825
- *
2826
- * ```handlebars
2827
- * <!-- array: ['a', 'b', 'c'], and "double" is a
2828
- * fictitious function that duplicates letters -->
2829
- * {{map array double}}
2830
- * <!-- results in: '["aa", "bb", "cc"]' -->
2831
- * ```
2832
- *
2833
- * @param {Array} `array`
2834
- * @param {Function} `fn`
2835
- * @return {String}
2836
- * @api public
2837
- */
2838
-
2839
-
2840
- helpers$3.map = function (array, iter) {
2841
- if (!Array.isArray(array)) return "";
2842
- const len = array.length;
2843
- const res = new Array(len);
2844
- let i = -1;
2845
-
2846
- if (typeof iter !== "function") {
2847
- return array;
2848
- }
2849
-
2850
- while (++i < len) {
2851
- res[i] = iter(array[i], i, array);
2852
- }
2853
-
2854
- return res;
2855
- };
2856
- /**
2857
- * Map over the given object or array or objects and create an array of values
2858
- * from the given `prop`. Dot-notation may be used (as a string) to get
2859
- * nested properties.
2860
- *
2861
- * ```handlebars
2862
- * // {{pluck items "data.title"}}
2863
- * <!-- results in: '["aa", "bb", "cc"]' -->
2864
- * ```
2865
- * @param {Array|Object} `collection`
2866
- * @param {Function} `prop`
2867
- * @return {String}
2868
- * @api public
2869
- */
2870
-
2871
-
2872
- helpers$3.pluck = function (arr, prop) {
2873
- if (util$2.isUndefined(arr)) return "";
2874
- const res = [];
2875
-
2876
- for (let i = 0; i < arr.length; i++) {
2877
- const val = core.getValue(arr[i], prop);
2878
-
2879
- if (typeof val !== "undefined") {
2880
- res.push(val);
2881
- }
2882
- }
2883
-
2884
- return res;
2885
- };
2886
- /**
2887
- * Reverse the elements in an array, or the characters in a string.
2888
- *
2889
- * ```handlebars
2890
- * <!-- value: 'abcd' -->
2891
- * {{reverse value}}
2892
- * <!-- results in: 'dcba' -->
2893
- * <!-- value: ['a', 'b', 'c', 'd'] -->
2894
- * {{reverse value}}
2895
- * <!-- results in: ['d', 'c', 'b', 'a'] -->
2896
- * ```
2897
- * @param {Array|String} `value`
2898
- * @return {Array|String} Returns the reversed string or array.
2899
- * @api public
2900
- */
2901
-
2902
-
2903
- helpers$3.reverse = function (val) {
2904
- if (Array.isArray(val)) {
2905
- val.reverse();
2906
- return val;
2907
- }
2908
-
2909
- if (val && core.isString(val)) {
2910
- return val.split("").reverse().join("");
2911
- }
2912
- };
2913
- /**
2914
- * Block helper that returns the block if the callback returns true
2915
- * for some value in the given array.
2916
- *
2917
- * ```handlebars
2918
- * <!-- array: [1, 'b', 3] -->
2919
- * {{#some array isString}}
2920
- * Render me if the array has a string.
2921
- * {{else}}
2922
- * Render me if it doesn't.
2923
- * {{/some}}
2924
- * <!-- results in: 'Render me if the array has a string.' -->
2925
- * ```
2926
- * @param {Array} `array`
2927
- * @param {Function} `iter` Iteratee
2928
- * @param {Options} Handlebars provided options object
2929
- * @return {String}
2930
- * @block
2931
- * @api public
2932
- */
2933
-
2934
-
2935
- helpers$3.some = function (array, iter, options) {
2936
- if (Array.isArray(array)) {
2937
- for (let i = 0; i < array.length; i++) {
2938
- if (iter(array[i], i, array)) {
2939
- return options.fn(this);
2940
- }
2941
- }
2942
- }
2943
-
2944
- return options.inverse(this);
2945
- };
2946
- /**
2947
- * Sort the given `array`. If an array of objects is passed,
2948
- * you may optionally pass a `key` to sort on as the second
2949
- * argument. You may alternatively pass a sorting function as
2950
- * the second argument.
2951
- *
2952
- * ```handlebars
2953
- * <!-- array: ['b', 'a', 'c'] -->
2954
- * {{sort array}}
2955
- * <!-- results in: '["a", "b", "c"]' -->
2956
- * ```
2957
- *
2958
- * @param {Array} `array` the array to sort.
2959
- * @param {String|Function} `key` The object key to sort by, or sorting function.
2960
- * @api public
2961
- */
2962
-
2963
-
2964
- helpers$3.sort = function (array, options) {
2965
- if (!Array.isArray(array)) return "";
2966
-
2967
- if (core.getValue(options, "hash.reverse")) {
2968
- return array.sort().reverse();
2969
- }
2970
-
2971
- return array.sort();
2972
- };
2973
- /**
2974
- * Block helper that return an array with all duplicate
2975
- * values removed. Best used along with a [each](#each) helper.
2976
- *
2977
- * ```handlebars
2978
- * <!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] -->
2979
- * {{#each (unique array)}}{{.}}{{/each}}
2980
- * <!-- results in: 'acbe' -->
2981
- * ```
2982
- * @param {Array} `array`
2983
- * @param {Object} `options`
2984
- * @return {Array}
2985
- * @api public
2986
- */
2987
-
2988
-
2989
- helpers$3.unique = function (array) {
2990
- if (util$2.isUndefined(array)) return "";
2991
- return array.filter(function (item, index, arr) {
2992
- return arr.indexOf(item) === index;
2993
- });
2994
- };
2995
-
2996
- const hasOwn = Object.hasOwnProperty;
2997
-
2998
- const util$1 = require("handlebars-utils");
2999
-
3000
- const createFrame = require("create-frame");
3001
-
3002
- const helpers$2 = {};
3003
- /**
3004
- * Extend the context with the properties of other objects.
3005
- * A shallow merge is performed to avoid mutating the context.
3006
- *
3007
- * @param {Object} `objects` One or more objects to extend.
3008
- * @return {Object}
3009
- * @api public
3010
- */
3011
-
3012
- helpers$2.extend = function ()
3013
- /*objects*/
3014
- {
3015
- // eslint-disable-next-line prefer-rest-params
3016
- const args = [].slice.call(arguments);
3017
- let opts = {};
3018
-
3019
- if (util$1.isOptions(args[args.length - 1])) {
3020
- // remove handlebars options object
3021
- opts = args.pop().hash; // re-add handlebars options.hash object
3022
-
3023
- args.push(opts);
3024
- }
3025
-
3026
- const context = {};
3027
-
3028
- for (let i = 0; i < args.length; i++) {
3029
- const obj = args[i];
3030
-
3031
- if (util$1.isObject(obj)) {
3032
- const keys = Object.keys(obj);
3033
-
3034
- for (let j = 0; j < keys.length; j++) {
3035
- const key = keys[j];
3036
- context[key] = obj[key];
3037
- }
3038
- }
3039
- }
3040
-
3041
- return context;
3042
- };
3043
- /**
3044
- * Block helper that iterates over the properties of
3045
- * an object, exposing each key and value on the context.
3046
- *
3047
- * @param {Object} `context`
3048
- * @param {Object} `options`
3049
- * @return {String}
3050
- * @block
3051
- * @api public
3052
- */
3053
-
3054
-
3055
- helpers$2.forIn = function (obj, options) {
3056
- if (!util$1.isOptions(options)) {
3057
- return obj.inverse(this);
3058
- }
3059
-
3060
- const data = createFrame(options, options.hash);
3061
- let result = "";
3062
-
3063
- for (const key in obj) {
3064
- data.key = key;
3065
- result += options.fn(obj[key], {
3066
- data: data
3067
- });
3068
- }
3069
-
3070
- return result;
3071
- };
3072
- /**
3073
- * Block helper that iterates over the **own** properties of
3074
- * an object, exposing each key and value on the context.
3075
- *
3076
- * @param {Object} `obj` The object to iterate over.
3077
- * @param {Object} `options`
3078
- * @return {String}
3079
- * @block
3080
- * @api public
3081
- */
3082
-
3083
-
3084
- helpers$2.forOwn = function (obj, options) {
3085
- if (!util$1.isOptions(options)) {
3086
- return obj.inverse(this);
3087
- }
3088
-
3089
- const data = createFrame(options, options.hash);
3090
- let result = "";
3091
-
3092
- for (const key in obj) {
3093
- if (obj.hasOwnProperty(key)) {
3094
- data.key = key;
3095
- result += options.fn(obj[key], {
3096
- data: data
3097
- });
3098
- }
3099
- }
3100
-
3101
- return result;
3102
- };
3103
- /**
3104
- * Take arguments and, if they are string or number, convert them to a dot-delineated object property path.
3105
- *
3106
- * @param {String|Number} `prop` The property segments to assemble (can be multiple).
3107
- * @return {String}
3108
- * @api public
3109
- */
3110
-
3111
-
3112
- helpers$2.toPath = function (...args) {
3113
- const prop = [];
3114
-
3115
- for (let i = 0; i < arguments.length; i++) {
3116
- if (typeof args[i] === "string" || typeof args[i] === "number") {
3117
- prop.push(args[i]);
3118
- }
3119
- }
3120
-
3121
- return prop.join(".");
3122
- };
3123
- /**
3124
- * Use property paths (`a.b.c`) to get a value or nested value from
3125
- * the context. Works as a regular helper or block helper.
3126
- *
3127
- * @param {String} `prop` The property to get, optionally using dot notation for nested properties.
3128
- * @param {Object} `context` The context object
3129
- * @param {Object} `options` The handlebars options object, if used as a block helper.
3130
- * @return {String}
3131
- * @block
3132
- * @api public
3133
- */
3134
-
3135
-
3136
- helpers$2.get = function (prop, context, options) {
3137
- const val = core.getValue(context, prop);
3138
-
3139
- if (options && options.fn) {
3140
- return val ? options.fn(val) : options.inverse(context);
3141
- }
3142
-
3143
- return val;
3144
- };
3145
- /**
3146
- * Return true if `key` is an own, enumerable property
3147
- * of the given `context` object.
3148
- *
3149
- * ```handlebars
3150
- * {{hasOwn context key}}
3151
- * ```
3152
- *
3153
- * @param {String} `key`
3154
- * @param {Object} `context` The context object.
3155
- * @return {Boolean}
3156
- * @api public
3157
- */
3158
-
3159
-
3160
- helpers$2.hasOwn = function (context, key) {
3161
- return hasOwn.call(context, key);
3162
- };
3163
- /**
3164
- * Return true if `value` is an object.
3165
- *
3166
- * ```handlebars
3167
- * {{isObject "foo"}}
3168
- * //=> false
3169
- * ```
3170
- * @param {String} `value`
3171
- * @return {Boolean}
3172
- * @api public
3173
- */
3174
-
3175
-
3176
- helpers$2.isObject = core.isObject;
3177
- /**
3178
- * Parses the given string using `JSON.parse`.
3179
- *
3180
- * ```handlebars
3181
- * <!-- string: '{"foo": "bar"}' -->
3182
- * {{JSONparse string}}
3183
- * <!-- results in: { foo: 'bar' } -->
3184
- * ```
3185
- * @param {String} `string` The string to parse
3186
- * @contributor github.com/keeganstreet
3187
- * @block
3188
- * @api public
3189
- */
3190
-
3191
- helpers$2.JSONparse = function (str) {
3192
- return JSON.parse(str);
3193
- };
3194
- /**
3195
- * Stringify an object using `JSON.stringify`.
3196
- *
3197
- * ```handlebars
3198
- * <!-- object: { foo: 'bar' } -->
3199
- * {{JSONstringify object}}
3200
- * <!-- results in: '{"foo": "bar"}' -->
3201
- * ```
3202
- * @param {Object} `obj` Object to stringify
3203
- * @return {String}
3204
- * @api public
3205
- */
3206
-
3207
-
3208
- helpers$2.JSONstringify = function (obj, indent) {
3209
- if (!core.isNumber(indent)) {
3210
- indent = 0;
3211
- }
3212
-
3213
- return JSON.stringify(obj, null, indent);
3214
- };
3215
- /**
3216
- * Deeply merge the properties of the given `objects` with the
3217
- * context object.
3218
- *
3219
- * @param {Object} `object` The target object. Pass an empty object to shallow clone.
3220
- * @param {Object} `objects`
3221
- * @return {Object}
3222
- * @api public
3223
- */
3224
-
3225
-
3226
- helpers$2.merge = function (...args1) {
3227
- // eslint-disable-next-line prefer-rest-params
3228
- const args = [].slice.call(args1);
3229
- let opts = {};
3230
-
3231
- if (util$1.isOptions(args[args.length - 1])) {
3232
- // remove handlebars options object
3233
- opts = args.pop().hash; // re-add options.hash
3234
-
3235
- args.push(opts);
3236
- }
3237
-
3238
- return Object.assign.apply(null, args);
3239
- };
3240
- /**
3241
- * Alias for parseJSON. this will be
3242
- * deprecated in a future release
3243
- */
3244
-
3245
-
3246
- helpers$2.parseJSON = helpers$2.JSONparse;
3247
- /**
3248
- * Pick properties from the context object.
3249
- *
3250
- * @param {Array|String} `properties` One or more properties to pick.
3251
- * @param {Object} `context`
3252
- * @param {Object} `options` Handlebars options object.
3253
- * @return {Object} Returns an object with the picked values. If used as a block helper, the values are passed as context to the inner block. If no values are found, the context is passed to the inverse block.
3254
- * @block
3255
- * @api public
3256
- */
3257
-
3258
- helpers$2.pick = function (props, context, options) {
3259
- const keys = helpers$3.arrayify(props);
3260
- const len = keys.length;
3261
- let i = -1;
3262
- let result = {};
3263
-
3264
- while (++i < len) {
3265
- result = helpers$2.extend({}, result, core.getValue(context, keys[i]));
3266
- }
3267
-
3268
- if (options.fn) {
3269
- if (Object.keys(result).length) {
3270
- return options.fn(result);
3271
- }
3272
-
3273
- return options.inverse(context);
3274
- }
3275
-
3276
- return result;
3277
- };
3278
- /**
3279
- * Alias for JSONstringify. this will be
3280
- * deprecated in a future release
3281
- */
3282
-
3283
-
3284
- helpers$2.stringify = helpers$2.JSONstringify;
3285
-
3286
- const util = require("handlebars-utils");
3287
- const forEach = helpers$3.forEach;
3288
- const forOwn = helpers$2.forOwn;
3289
- const helpers$1 = {};
3290
- /**
3291
- * Inline, subexpression, or block helper that returns true (or the block)
3292
- * if the given collection is empty, or false (or the inverse block, if
3293
- * supplied) if the colleciton is not empty.
3294
- *
3295
- * ```handlebars
3296
- * <!-- array: [] -->
3297
- * {{#isEmpty array}}AAA{{else}}BBB{{/isEmpty}}
3298
- * <!-- results in: 'AAA' -->
3299
- *
3300
- * <!-- array: [] -->
3301
- * {{isEmpty array}}
3302
- * <!-- results in: true -->
3303
- * ```
3304
- * @param {Object} `collection`
3305
- * @param {Object} `options`
3306
- * @return {String}
3307
- * @block
3308
- * @api public
3309
- */
3310
-
3311
- helpers$1.isEmpty = function (collection, options) {
3312
- if (!util.isOptions(options)) {
3313
- options = collection;
3314
- return util.fn(true, this, options);
3315
- }
3316
-
3317
- if (Array.isArray(collection) && !collection.length) {
3318
- return util.fn(true, this, options);
3319
- }
3320
-
3321
- const keys = Object.keys(collection);
3322
- const isEmpty = typeof collection === "object" && !keys.length;
3323
- return util.value(isEmpty, this, options);
3324
- };
3325
- /**
3326
- * Block helper that iterates over an array or object. If
3327
- * an array is given, `.forEach` is called, or if an object
3328
- * is given, `.forOwn` is called, otherwise the inverse block
3329
- * is returned.
3330
- *
3331
- * @param {Object|Array} `collection` The collection to iterate over
3332
- * @param {Object} `options`
3333
- * @return {String}
3334
- * @block
3335
- * @api public
3336
- */
3337
-
3338
-
3339
- helpers$1.iterate = function (collection, options) {
3340
- if (Array.isArray(collection)) {
3341
- return forEach.apply(null, [collection, options]);
3342
- }
3343
-
3344
- if (util.isObject(collection)) {
3345
- return forOwn.apply(null, [collection, options]);
3346
- }
3347
-
3348
- return options.inverse(this);
3349
- };
3350
-
3351
- const helpers = {};
3352
-
3353
- helpers.switch = function (value, options) {
3354
- this.switch_value = value;
3355
- return options.fn(this);
3356
- };
3357
-
3358
- helpers.case = function (value, options) {
3359
- if (value == this.switch_value) {
3360
- return options.fn(this);
3361
- }
3362
- };
3363
-
3364
- handlebars__default['default'].registerHelper(helpers$3);
3365
- handlebars__default['default'].registerHelper(helpers$2);
3366
- handlebars__default['default'].registerHelper(helpers$1);
3367
- handlebars__default['default'].registerHelper(helpers$4);
3368
- handlebars__default['default'].registerHelper(helpers);
3369
-
3370
- function insertImport(fileContent, content) {
3371
- const lines = fileContent.split("\n");
3372
- const index = lines.findIndex(line => {
3373
- if (line.startsWith("#!")) {
3374
- return false;
3375
- }
3376
-
3377
- return !line.startsWith("import ");
3378
- });
3379
- lines[index] = content + "\n" + lines[index];
3380
- return lines.join("\n");
3381
- }
3382
-
3383
- function insertAfter(fileContent, content, pattern) {
3384
- const lines = fileContent.split("\n");
3385
- const index = lines.findIndex(line => {
3386
- return line.match(pattern);
3387
- });
3388
- const indent = lines[index].replace(lines[index].trim(), "");
3389
- lines[index] = lines[index] + "\n" + indent + content;
3390
-
3391
- if (!["]", "}"].includes(lines[index + 1].trim()) && lines[index - 1].slice(-1) === ",") {
3392
- lines[index] += ",";
3393
- }
3394
-
3395
- return lines.join("\n");
3396
- }
3397
-
3398
- const _excluded = ["path"];
3399
-
3400
- const normalizePath = require("normalize-path");
3401
-
3402
- class Renderer {
3403
- constructor() {
3404
- this.configuration = void 0;
3405
- this.templateDir = void 0;
3406
- this.fs = void 0;
3407
- }
3408
-
3409
- async render(path$1, data, options = {}) {
3410
- const {
3411
- output,
3412
- templateDir,
3413
- rootDir
3414
- } = this.mapOptions(path$1, options);
3415
- let content = "";
3416
- const file = normalizePath(path.join(templateDir, path$1));
3417
-
3418
- if (path$1.endsWith(".hbs")) {
3419
- content = await Consolidate__default['default'].handlebars(file, data);
3420
- } else {
3421
- content = await this.fs.readFile(file, {
3422
- encoding: "utf8"
3423
- });
3424
- }
3425
-
3426
- return this.write(content, {
3427
- output,
3428
- rootDir
3429
- });
3430
- }
3431
-
3432
- async renderAll(paths, data, options = {}) {
3433
- let count = 0;
3434
-
3435
- const mapOptions = opts => {
3436
- if (core.isString(opts)) {
3437
- return _extends({}, options, {
3438
- path: opts
3439
- });
3440
- }
3441
-
3442
- return _extends({}, options, opts);
3443
- };
3444
-
3445
- return new rxjs.Observable(observer => {
3446
- observer.next(`[${count}/${paths.length}] Rendering files...`);
3447
- const promises = paths.filter(Boolean).map(mapOptions).map(async _ref => {
3448
- let {
3449
- path
3450
- } = _ref,
3451
- opts = _objectWithoutPropertiesLoose(_ref, _excluded);
3452
-
3453
- await this.render(path, data, opts);
3454
- count++;
3455
- observer.next(`[${count}/${paths.length}] Rendering files...`);
3456
- });
3457
- Promise.all(promises).then(() => {
3458
- observer.next(`[${count}/${paths.length}] Rendering files...`);
3459
- observer.complete();
3460
- }).catch(err => {
3461
- observer.error(err);
3462
- });
3463
- });
3464
- }
3465
-
3466
- async write(content, options) {
3467
- const {
3468
- output,
3469
- rootDir = this.rootDir
3470
- } = options;
3471
- const outputFile = path.join(...[rootDir, output].filter(Boolean));
3472
- await this.fs.ensureDir(path.dirname(outputFile));
3473
- return this.fs.writeFile(outputFile, content, {
3474
- encoding: "utf8"
3475
- });
3476
- }
3477
-
3478
- templateExists(path$1, options = {}) {
3479
- const {
3480
- templateDir
3481
- } = this.mapOptions(path$1, options);
3482
- return Fs.existsSync(path.join(templateDir, path$1));
3483
- }
3484
-
3485
- scan(pattern, options = {}) {
3486
- return globby__default['default'](pattern.map(s => normalizePath(s)), _extends({}, options, {
3487
- cwd: this.rootDir
3488
- }));
3489
- }
3490
-
3491
- relativeFrom(path$1) {
3492
- return path.relative(path.dirname(path.join(this.rootDir, path$1)), this.rootDir);
3493
- }
3494
-
3495
- async update(path$1, actions) {
3496
- path$1 = path.join(this.rootDir, path$1);
3497
-
3498
- if (!this.fs.exists(path$1)) {
3499
- return;
3500
- }
3501
-
3502
- const content = actions.reduce((fileContent, action) => {
3503
- switch (action.type) {
3504
- case "import":
3505
- return insertImport(fileContent, action.content);
3506
-
3507
- case "insert-after":
3508
- return insertAfter(fileContent, action.content, action.pattern);
3509
- }
3510
-
3511
- return fileContent;
3512
- }, await this.fs.readFile(path$1, {
3513
- encoding: "utf8"
3514
- }));
3515
- return this.fs.writeFile(path$1, content, {
3516
- encoding: "utf8"
3517
- });
3518
- }
3519
-
3520
- mapOptions(path$1, options) {
3521
- const {
3522
- templateDir = this.templateDir,
3523
- rootDir = this.rootDir
3524
- } = options;
3525
- let {
3526
- output = path$1
3527
- } = options;
3528
-
3529
- if (options.baseDir) {
3530
- output = normalizePath(path.join("/", path.relative(options.baseDir, path$1)));
3531
- }
3532
-
3533
- if (options.basename) {
3534
- output = normalizePath(path.join(path.dirname(output), options.basename));
3535
- }
3536
-
3537
- output = output.replace(/\.hbs$/, "");
3538
- return {
3539
- output,
3540
- templateDir,
3541
- rootDir
3542
- };
3543
- }
3544
-
3545
- }
3546
-
3547
- tslib.__decorate([di.Configuration(), tslib.__metadata("design:type", Object)], Renderer.prototype, "configuration", void 0);
3548
-
3549
- tslib.__decorate([di.Constant("templateDir"), tslib.__metadata("design:type", String)], Renderer.prototype, "templateDir", void 0);
3550
-
3551
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.CliFs)], Renderer.prototype, "fs", void 0);
3552
-
3553
- exports.RootRendererService = class RootRendererService extends Renderer {
3554
- get rootDir() {
3555
- var _this$configuration$p;
3556
-
3557
- return (_this$configuration$p = this.configuration.project) == null ? void 0 : _this$configuration$p.rootDir;
3558
- }
3559
-
3560
- };
3561
- exports.RootRendererService = tslib.__decorate([di.Injectable()], exports.RootRendererService);
3562
- exports.SrcRendererService = class SrcRendererService extends Renderer {
3563
- get rootDir() {
3564
- var _this$configuration$p2, _this$configuration$p3;
3565
-
3566
- return path.join(...[(_this$configuration$p2 = this.configuration.project) == null ? void 0 : _this$configuration$p2.rootDir, (_this$configuration$p3 = this.configuration.project) == null ? void 0 : _this$configuration$p3.srcDir].filter(Boolean));
3567
- }
3568
-
3569
- };
3570
- exports.SrcRendererService = tslib.__decorate([di.Injectable()], exports.SrcRendererService);
3571
- exports.ScriptsRendererService = class ScriptsRendererService extends Renderer {
3572
- get rootDir() {
3573
- var _this$configuration$p4, _this$configuration$p5;
3574
-
3575
- return path.join(...[(_this$configuration$p4 = this.configuration.project) == null ? void 0 : _this$configuration$p4.rootDir, (_this$configuration$p5 = this.configuration.project) == null ? void 0 : _this$configuration$p5.scriptsDir].filter(Boolean));
3576
- }
3577
-
3578
- };
3579
- exports.ScriptsRendererService = tslib.__decorate([di.Injectable()], exports.ScriptsRendererService);
3580
-
3581
- exports.CliYaml = class CliYaml {
3582
- constructor() {
3583
- this.projectPackageJson = void 0;
3584
- this.fs = void 0;
3585
- }
3586
-
3587
- async read(path) {
3588
- const file = !this.fs.exists(path) ? this.fs.findUpFile(this.projectPackageJson.dir, path) : path;
3589
-
3590
- if (file) {
3591
- const content = await this.fs.readFile(file, {
3592
- encoding: "utf8"
3593
- });
3594
- return JsYaml__default['default'].load(content);
3595
- }
3596
-
3597
- return {};
3598
- }
3599
-
3600
- async write(path$1, obj) {
3601
- const content = JsYaml__default['default'].dump(obj);
3602
- const file = this.fs.findUpFile(this.projectPackageJson.dir, path$1) || path.join(this.projectPackageJson.dir, path$1);
3603
- return this.fs.writeFile(file, content, {
3604
- encoding: "utf8"
3605
- });
3606
- }
3607
-
3608
- };
3609
-
3610
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.ProjectPackageJson)], exports.CliYaml.prototype, "projectPackageJson", void 0);
3611
-
3612
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.CliFs)], exports.CliYaml.prototype, "fs", void 0);
3613
-
3614
- exports.CliYaml = tslib.__decorate([di.Injectable()], exports.CliYaml);
3615
-
3616
- exports.CliDockerComposeYaml = class CliDockerComposeYaml {
3617
- constructor() {
3618
- this.cliYaml = void 0;
3619
- }
3620
-
3621
- async read() {
3622
- return this.cliYaml.read("docker-compose.yml");
3623
- }
3624
-
3625
- async write(obj) {
3626
- return this.cliYaml.write("docker-compose.yml", obj);
3627
- }
3628
-
3629
- async addDatabaseService(name, database) {
3630
- const dockerCompose = await this.read();
3631
-
3632
- if (dockerCompose) {
3633
- let value;
3634
-
3635
- switch (database) {
3636
- case "mysql":
3637
- case "mariadb":
3638
- value = {
3639
- image: database === "mysql" ? "mysql:8.0.28-oracle" : "mariadb:10.7.3",
3640
- ports: ["3306:3306"],
3641
- environment: {
3642
- MYSQL_ROOT_PASSWORD: "admin",
3643
- MYSQL_USER: "test",
3644
- MYSQL_PASSWORD: "test",
3645
- MYSQL_DATABASE: "test"
3646
- }
3647
- };
3648
- break;
3649
-
3650
- case "postgres":
3651
- value = {
3652
- image: "postgres:9.6.1",
3653
- ports: ["5432:5432"],
3654
- environment: {
3655
- POSTGRES_USER: "test",
3656
- POSTGRES_PASSWORD: "test",
3657
- POSTGRES_DB: "test"
3658
- }
3659
- };
3660
- break;
3661
-
3662
- case "cockroachdb":
3663
- value = {
3664
- image: "cockroachdb/cockroach:v2.1.4",
3665
- command: "start --insecure",
3666
- ports: ["26257:26257"]
3667
- };
3668
- break;
3669
-
3670
- case "mssql":
3671
- value = {
3672
- image: "mcr.microsoft.com/mssql/server:2017-latest",
3673
- command: "start --insecure",
3674
- ports: ["1433:1433"],
3675
- environment: {
3676
- SA_PASSWORD: "Admin12345",
3677
- ACCEPT_EULA: "Y"
3678
- }
3679
- };
3680
- break;
3681
-
3682
- case "mongodb":
3683
- value = {
3684
- image: "mongo:4.1",
3685
- ports: ["27017:27017"]
3686
- };
3687
- break;
3688
- }
3689
-
3690
- core.setValue(dockerCompose, `services.${changeCase.snakeCase(name)}`, value);
3691
- await this.write(dockerCompose);
3692
- }
3693
- }
3694
-
3695
- };
3696
-
3697
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.CliYaml)], exports.CliDockerComposeYaml.prototype, "cliYaml", void 0);
3698
-
3699
- exports.CliDockerComposeYaml = tslib.__decorate([di.Injectable()], exports.CliDockerComposeYaml);
3700
-
3701
- class CliError extends Error {
3702
- constructor({
3703
- cli,
3704
- origin
3705
- }) {
3706
- super(origin.message);
3707
- this.name = "CLI_ERROR";
3708
- this.cli = void 0;
3709
- this.origin = void 0;
3710
- this.cli = cli;
3711
- this.origin = origin;
3712
- this.stack = origin.stack;
3713
- }
3714
-
3715
- }
3716
-
3717
- var CliCore_1;
3718
-
3719
- const semver = require("semver");
3720
-
3721
- function isHelpManual(argv) {
3722
- return argv.includes("-h") || argv.includes("--help");
3723
- }
3724
-
3725
- exports.CliCore = CliCore_1 = class CliCore {
3726
- constructor() {
3727
- this.injector = void 0;
3728
- this.cliService = void 0;
3729
- }
3730
-
3731
- static checkNodeVersion(wanted, id) {
3732
- if (!semver.satisfies(process.version, wanted)) {
3733
- console.log(chalk__default['default'].red("You are using Node " + process.version + ", but this version of " + id + " requires Node " + wanted + ".\nPlease upgrade your Node version."));
3734
- process.exit(1);
3735
- }
3736
-
3737
- return this;
3738
- }
3739
-
3740
- static async bootstrap(settings, module = CliCore_1) {
3741
- const injector = this.createInjector(settings);
3742
- settings.plugins && (await loadPlugins(injector));
3743
- await this.loadInjector(injector, module);
3744
- await injector.emit("$onReady");
3745
- const cli = injector.get(CliCore_1);
3746
-
3747
- try {
3748
- await cli.cliService.parseArgs(injector.settings.get("argv"));
3749
- } catch (er) {
3750
- throw new CliError({
3751
- origin: er,
3752
- cli
3753
- });
3754
- }
3755
-
3756
- return cli;
3757
- }
3758
-
3759
- static async loadInjector(injector, module = CliCore_1) {
3760
- await injector.emit("$beforeInit");
3761
- const container = di.createContainer();
3762
- await injector.load(container, module);
3763
- await injector.emit("$afterInit");
3764
- injector.settings.set("loaded", true);
3765
- }
3766
-
3767
- static updateNotifier(pkg) {
3768
- updateNotifier__default['default']({
3769
- pkg,
3770
- updateCheckInterval: 0
3771
- }).notify();
3772
- return this;
3773
- }
3774
-
3775
- static createInjector(settings) {
3776
- const argv = settings.argv || process.argv;
3777
- return createInjector(_extends({}, settings, {
3778
- name: settings.name || "tsed",
3779
- argv,
3780
- project: _extends({
3781
- rootDir: this.getProjectRoot(argv),
3782
- srcDir: "src",
3783
- scriptsDir: "scripts"
3784
- }, settings.project || {})
3785
- }));
3786
- }
3787
-
3788
- static getProjectRoot(argv) {
3789
- if (!isHelpManual(argv)) {
3790
- const projectRoot = new commander.Command().option("-r, --root-dir <path>", "Project root directory").allowUnknownOption(true).parse(argv).opts().rootDir || "";
3791
- return path.resolve(path.join(process.cwd(), projectRoot));
3792
- }
3793
-
3794
- return process.cwd();
3795
- }
3796
-
3797
- };
3798
-
3799
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", di.InjectorService)], exports.CliCore.prototype, "injector", void 0);
3800
-
3801
- tslib.__decorate([di.Inject(), tslib.__metadata("design:type", exports.CliService)], exports.CliCore.prototype, "cliService", void 0);
3802
-
3803
- exports.CliCore = CliCore_1 = tslib.__decorate([di.Module({
3804
- imports: [CliPackageJson, exports.ProjectPackageJson, exports.CliService, exports.CliConfiguration]
3805
- })], exports.CliCore);
3806
-
3807
- function at(n) {
3808
- // ToInteger() abstract op
3809
- n = Math.trunc(n) || 0; // Allow negative indexing from the end
3810
-
3811
- if (n < 0) n += this.length; // OOB access is guaranteed to return undefined
3812
-
3813
- if (n < 0 || n >= this.length) return undefined; // Otherwise, this is just normal property access
3814
-
3815
- return this[n];
3816
- }
3817
-
3818
- const TypedArray = Reflect.getPrototypeOf(Int8Array);
3819
-
3820
- for (const C of [Array, String, TypedArray]) {
3821
- if (C) {
3822
- Object.defineProperty(C.prototype, "at", {
3823
- value: at,
3824
- writable: true,
3825
- enumerable: false,
3826
- configurable: true
3827
- });
3828
- }
3829
- }
3830
-
3831
- const helpInformation = commander.Command.prototype.helpInformation;
3832
-
3833
- function colorizeSection(str, section) {
3834
- // eslint-disable-next-line prefer-const
3835
- let [before, after] = str.split(section);
3836
- after = after.split("\n").map(line => {
3837
- if (!line.match(/(\w+):$/)) {
3838
- const [cmd, ...rest] = line.trim().split(" ");
3839
-
3840
- if (!cmd.startsWith("-")) {
3841
- return [" ", chalk__default['default'].bold(chalk__default['default'].blue(cmd)), ...rest].join(" ");
3842
- }
3843
- }
3844
-
3845
- return line;
3846
- }).join("\n");
3847
- return [before, after].join(chalk__default['default'].green(section));
3848
- }
3849
-
3850
- commander.Command.prototype.helpInformation = function help() {
3851
- let str = helpInformation.call(this);
3852
-
3853
- if (str.includes("Commands:")) {
3854
- str = colorizeSection(str, "Commands:");
3855
- }
3856
-
3857
- if (str.includes("Arguments:")) {
3858
- str = colorizeSection(str, "Arguments:");
3859
- }
3860
-
3861
- return "\n" + str.replace("Usage:", chalk__default['default'].green("Usage:")).replace("Options:", chalk__default['default'].green("Options:")).replace(/<(\w+)>/gi, `<${chalk__default['default'].yellow("$1")}>`).replace(/\[(\w+)]/gi, `[${chalk__default['default'].cyan("$1")}]`) + "\n";
3862
- };
3863
-
3864
- Object.defineProperty(exports, 'Inquirer', {
3865
- enumerable: true,
3866
- get: function () {
3867
- return Inquirer__default['default'];
3868
- }
3869
- });
3870
- Object.defineProperty(exports, 'Configuration', {
3871
- enumerable: true,
3872
- get: function () {
3873
- return di.Configuration;
3874
- }
3875
- });
3876
- Object.defineProperty(exports, 'Constant', {
3877
- enumerable: true,
3878
- get: function () {
3879
- return di.Constant;
3880
- }
3881
- });
3882
- Object.defineProperty(exports, 'Container', {
3883
- enumerable: true,
3884
- get: function () {
3885
- return di.Container;
3886
- }
3887
- });
3888
- Object.defineProperty(exports, 'DITest', {
3889
- enumerable: true,
3890
- get: function () {
3891
- return di.DITest;
3892
- }
3893
- });
3894
- Object.defineProperty(exports, 'Inject', {
3895
- enumerable: true,
3896
- get: function () {
3897
- return di.Inject;
3898
- }
3899
- });
3900
- Object.defineProperty(exports, 'Injectable', {
3901
- enumerable: true,
3902
- get: function () {
3903
- return di.Injectable;
3904
- }
3905
- });
3906
- Object.defineProperty(exports, 'InjectorService', {
3907
- enumerable: true,
3908
- get: function () {
3909
- return di.InjectorService;
3910
- }
3911
- });
3912
- Object.defineProperty(exports, 'LocalsContainer', {
3913
- enumerable: true,
3914
- get: function () {
3915
- return di.LocalsContainer;
3916
- }
3917
- });
3918
- Object.defineProperty(exports, 'Module', {
3919
- enumerable: true,
3920
- get: function () {
3921
- return di.Module;
3922
- }
3923
- });
3924
- Object.defineProperty(exports, 'Opts', {
3925
- enumerable: true,
3926
- get: function () {
3927
- return di.Opts;
3928
- }
3929
- });
3930
- Object.defineProperty(exports, 'OverrideProvider', {
3931
- enumerable: true,
3932
- get: function () {
3933
- return di.OverrideProvider;
3934
- }
3935
- });
3936
- Object.defineProperty(exports, 'UseOpts', {
3937
- enumerable: true,
3938
- get: function () {
3939
- return di.UseOpts;
3940
- }
3941
- });
3942
- Object.defineProperty(exports, 'Value', {
3943
- enumerable: true,
3944
- get: function () {
3945
- return di.Value;
3946
- }
3947
- });
3948
- Object.defineProperty(exports, 'registerProvider', {
3949
- enumerable: true,
3950
- get: function () {
3951
- return di.registerProvider;
3952
- }
3953
- });
3954
- exports.CliPackageJson = CliPackageJson;
3955
- exports.Command = Command;
3956
- exports.OnAdd = OnAdd;
3957
- exports.OnExec = OnExec;
3958
- exports.OnPostInstall = OnPostInstall;
3959
- exports.OnPrompt = OnPrompt;
3960
- exports.Renderer = Renderer;
3961
- exports.SCOPE_SEPARATOR = SCOPE_SEPARATOR;
3962
- exports.addSuffix = addSuffix;
3963
- exports.createInjector = createInjector;
3964
- exports.createSubTasks = createSubTasks;
3965
- exports.createTasks = createTasks;
3966
- exports.createTasksRunner = createTasksRunner;
3967
- exports.getCommandMetadata = getCommandMetadata;
3968
- exports.getLogger = getLogger;
3969
- exports.getPackageJson = getPackageJson;
3970
- exports.loadPlugins = loadPlugins;
3971
- exports.logToCurl = logToCurl;
3972
- exports.mapCommanderArgs = mapCommanderArgs;
3973
- exports.mapCommanderOptions = mapCommanderOptions;
3974
- exports.normalizePath = normalizePath$1;
3975
- exports.parseOption = parseOption;
3976
- Object.keys(core).forEach(function (k) {
3977
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
3978
- enumerable: true,
3979
- get: function () {
3980
- return core[k];
3981
- }
3982
- });
3983
- });
3984
- Object.keys(logger$1).forEach(function (k) {
3985
- if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
3986
- enumerable: true,
3987
- get: function () {
3988
- return logger$1[k];
3989
- }
3990
- });
3991
- });
3992
- //# sourceMappingURL=index.js.map