@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.
- package/lib/cjs/CliCore.js +97 -0
- package/lib/cjs/CliCore.js.map +1 -0
- package/lib/cjs/decorators/command.js +11 -0
- package/lib/cjs/decorators/command.js.map +1 -0
- package/lib/cjs/decorators/index.js +9 -0
- package/lib/cjs/decorators/index.js.map +1 -0
- package/lib/cjs/decorators/on.js +13 -0
- package/lib/cjs/decorators/on.js.map +1 -0
- package/lib/cjs/decorators/onAdd.js +10 -0
- package/lib/cjs/decorators/onAdd.js.map +1 -0
- package/lib/cjs/decorators/onExec.js +10 -0
- package/lib/cjs/decorators/onExec.js.map +1 -0
- package/lib/cjs/decorators/onPostInstall.js +10 -0
- package/lib/cjs/decorators/onPostInstall.js.map +1 -0
- package/lib/cjs/decorators/onPrompt.js +10 -0
- package/lib/cjs/decorators/onPrompt.js.map +1 -0
- package/lib/cjs/domains/CliError.js +14 -0
- package/lib/cjs/domains/CliError.js.map +1 -0
- package/lib/cjs/domains/CommandStoreKeys.js +12 -0
- package/lib/cjs/domains/CommandStoreKeys.js.map +1 -0
- package/lib/cjs/index.js +30 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/interfaces/CliDefaultOptions.js +3 -0
- package/lib/cjs/interfaces/CliDefaultOptions.js.map +1 -0
- package/lib/cjs/interfaces/CommandMetadata.js +3 -0
- package/lib/cjs/interfaces/CommandMetadata.js.map +1 -0
- package/lib/cjs/interfaces/CommandParameters.js +3 -0
- package/lib/cjs/interfaces/CommandParameters.js.map +1 -0
- package/lib/cjs/interfaces/CommandProvider.js +3 -0
- package/lib/cjs/interfaces/CommandProvider.js.map +1 -0
- package/lib/cjs/interfaces/PackageJson.js +3 -0
- package/lib/cjs/interfaces/PackageJson.js.map +1 -0
- package/lib/cjs/interfaces/ProjectPreferences.js +10 -0
- package/lib/cjs/interfaces/ProjectPreferences.js.map +1 -0
- package/lib/cjs/interfaces/Tasks.js +3 -0
- package/lib/cjs/interfaces/Tasks.js.map +1 -0
- package/lib/cjs/interfaces/index.js +11 -0
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/registries/CommandRegistry.js +13 -0
- package/lib/cjs/registries/CommandRegistry.js.map +1 -0
- package/lib/cjs/services/CliConfiguration.js +21 -0
- package/lib/cjs/services/CliConfiguration.js.map +1 -0
- package/lib/cjs/services/CliDockerComposeYaml.js +83 -0
- package/lib/cjs/services/CliDockerComposeYaml.js.map +1 -0
- package/lib/cjs/services/CliExeca.js +45 -0
- package/lib/cjs/services/CliExeca.js.map +1 -0
- package/lib/cjs/services/CliFs.js +55 -0
- package/lib/cjs/services/CliFs.js.map +1 -0
- package/lib/cjs/services/CliHooks.js +34 -0
- package/lib/cjs/services/CliHooks.js.map +1 -0
- package/lib/cjs/services/CliHttpClient.js +107 -0
- package/lib/cjs/services/CliHttpClient.js.map +1 -0
- package/lib/cjs/services/CliHttpLogClient.js +83 -0
- package/lib/cjs/services/CliHttpLogClient.js.map +1 -0
- package/lib/cjs/services/CliPackageJson.js +16 -0
- package/lib/cjs/services/CliPackageJson.js.map +1 -0
- package/lib/cjs/services/CliPlugins.js +78 -0
- package/lib/cjs/services/CliPlugins.js.map +1 -0
- package/lib/cjs/services/CliProxyAgent.js +87 -0
- package/lib/cjs/services/CliProxyAgent.js.map +1 -0
- package/lib/cjs/services/CliRunScript.js +31 -0
- package/lib/cjs/services/CliRunScript.js.map +1 -0
- package/lib/cjs/services/CliService.js +271 -0
- package/lib/cjs/services/CliService.js.map +1 -0
- package/lib/cjs/services/CliYaml.js +37 -0
- package/lib/cjs/services/CliYaml.js.map +1 -0
- package/lib/cjs/services/NpmRegistryClient.js +121 -0
- package/lib/cjs/services/NpmRegistryClient.js.map +1 -0
- package/lib/cjs/services/ProjectPackageJson.js +420 -0
- package/lib/cjs/services/ProjectPackageJson.js.map +1 -0
- package/lib/cjs/services/Renderer.js +154 -0
- package/lib/cjs/services/Renderer.js.map +1 -0
- package/lib/cjs/services/index.js +17 -0
- package/lib/cjs/services/index.js.map +1 -0
- package/lib/cjs/utils/createInjector.js +35 -0
- package/lib/cjs/utils/createInjector.js.map +1 -0
- package/lib/cjs/utils/createTasksRunner.js +75 -0
- package/lib/cjs/utils/createTasksRunner.js.map +1 -0
- package/lib/cjs/utils/getCommandMetadata.js +19 -0
- package/lib/cjs/utils/getCommandMetadata.js.map +1 -0
- package/lib/cjs/utils/getPackageJson.js +38 -0
- package/lib/cjs/utils/getPackageJson.js.map +1 -0
- package/lib/cjs/utils/hbs/array.js +522 -0
- package/lib/cjs/utils/hbs/array.js.map +1 -0
- package/lib/cjs/utils/hbs/collection.js +66 -0
- package/lib/cjs/utils/hbs/collection.js.map +1 -0
- package/lib/cjs/utils/hbs/comparison.js +437 -0
- package/lib/cjs/utils/hbs/comparison.js.map +1 -0
- package/lib/cjs/utils/hbs/index.js +15 -0
- package/lib/cjs/utils/hbs/index.js.map +1 -0
- package/lib/cjs/utils/hbs/object.js +245 -0
- package/lib/cjs/utils/hbs/object.js.map +1 -0
- package/lib/cjs/utils/hbs/switch.js +14 -0
- package/lib/cjs/utils/hbs/switch.js.map +1 -0
- package/lib/cjs/utils/index.js +14 -0
- package/lib/cjs/utils/index.js.map +1 -0
- package/lib/cjs/utils/isValidVersion.js +11 -0
- package/lib/cjs/utils/isValidVersion.js.map +1 -0
- package/lib/cjs/utils/loadPlugins.js +47 -0
- package/lib/cjs/utils/loadPlugins.js.map +1 -0
- package/lib/cjs/utils/logToCurl.js +19 -0
- package/lib/cjs/utils/logToCurl.js.map +1 -0
- package/lib/cjs/utils/mapCommanderArgs.js +40 -0
- package/lib/cjs/utils/mapCommanderArgs.js.map +1 -0
- package/lib/cjs/utils/mapCommanderOptions.js +16 -0
- package/lib/cjs/utils/mapCommanderOptions.js.map +1 -0
- package/lib/cjs/utils/normalizePath.js +19 -0
- package/lib/cjs/utils/normalizePath.js.map +1 -0
- package/lib/cjs/utils/parseOption.js +27 -0
- package/lib/cjs/utils/parseOption.js.map +1 -0
- package/lib/cjs/utils/patchCommander.js +58 -0
- package/lib/cjs/utils/patchCommander.js.map +1 -0
- package/lib/cjs/utils/renderer/insertAfter.js +17 -0
- package/lib/cjs/utils/renderer/insertAfter.js.map +1 -0
- package/lib/cjs/utils/renderer/insertImport.js +16 -0
- package/lib/cjs/utils/renderer/insertImport.js.map +1 -0
- package/lib/esm/CliCore.js +94 -0
- package/lib/esm/CliCore.js.map +1 -0
- package/lib/esm/decorators/command.js +7 -0
- package/lib/esm/decorators/command.js.map +1 -0
- package/lib/esm/decorators/index.js +6 -0
- package/lib/esm/decorators/index.js.map +1 -0
- package/lib/esm/decorators/on.js +9 -0
- package/lib/esm/decorators/on.js.map +1 -0
- package/lib/esm/decorators/onAdd.js +6 -0
- package/lib/esm/decorators/onAdd.js.map +1 -0
- package/lib/esm/decorators/onExec.js +6 -0
- package/lib/esm/decorators/onExec.js.map +1 -0
- package/lib/esm/decorators/onPostInstall.js +6 -0
- package/lib/esm/decorators/onPostInstall.js.map +1 -0
- package/lib/esm/decorators/onPrompt.js +6 -0
- package/lib/esm/decorators/onPrompt.js.map +1 -0
- package/lib/esm/domains/CliError.js +10 -0
- package/lib/esm/domains/CliError.js.map +1 -0
- package/lib/esm/domains/CommandStoreKeys.js +9 -0
- package/lib/esm/domains/CommandStoreKeys.js.map +1 -0
- package/lib/esm/index.js +12 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/CliDefaultOptions.js +2 -0
- package/lib/esm/interfaces/CliDefaultOptions.js.map +1 -0
- package/lib/esm/interfaces/CommandMetadata.js +2 -0
- package/lib/esm/interfaces/CommandMetadata.js.map +1 -0
- package/lib/esm/interfaces/CommandParameters.js +2 -0
- package/lib/esm/interfaces/CommandParameters.js.map +1 -0
- package/lib/esm/interfaces/CommandProvider.js +2 -0
- package/lib/esm/interfaces/CommandProvider.js.map +1 -0
- package/lib/esm/interfaces/PackageJson.js +2 -0
- package/lib/esm/interfaces/PackageJson.js.map +1 -0
- package/lib/esm/interfaces/ProjectPreferences.js +7 -0
- package/lib/esm/interfaces/ProjectPreferences.js.map +1 -0
- package/lib/esm/interfaces/Tasks.js +2 -0
- package/lib/esm/interfaces/Tasks.js.map +1 -0
- package/lib/esm/interfaces/index.js +8 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/registries/CommandRegistry.js +10 -0
- package/lib/esm/registries/CommandRegistry.js.map +1 -0
- package/lib/esm/services/CliConfiguration.js +18 -0
- package/lib/esm/services/CliConfiguration.js.map +1 -0
- package/lib/esm/services/CliDockerComposeYaml.js +80 -0
- package/lib/esm/services/CliDockerComposeYaml.js.map +1 -0
- package/lib/esm/services/CliExeca.js +42 -0
- package/lib/esm/services/CliExeca.js.map +1 -0
- package/lib/esm/services/CliFs.js +52 -0
- package/lib/esm/services/CliFs.js.map +1 -0
- package/lib/esm/services/CliHooks.js +31 -0
- package/lib/esm/services/CliHooks.js.map +1 -0
- package/lib/esm/services/CliHttpClient.js +104 -0
- package/lib/esm/services/CliHttpClient.js.map +1 -0
- package/lib/esm/services/CliHttpLogClient.js +80 -0
- package/lib/esm/services/CliHttpLogClient.js.map +1 -0
- package/lib/esm/services/CliPackageJson.js +12 -0
- package/lib/esm/services/CliPackageJson.js.map +1 -0
- package/lib/esm/services/CliPlugins.js +75 -0
- package/lib/esm/services/CliPlugins.js.map +1 -0
- package/lib/esm/services/CliProxyAgent.js +84 -0
- package/lib/esm/services/CliProxyAgent.js.map +1 -0
- package/lib/esm/services/CliRunScript.js +28 -0
- package/lib/esm/services/CliRunScript.js.map +1 -0
- package/lib/esm/services/CliService.js +268 -0
- package/lib/esm/services/CliService.js.map +1 -0
- package/lib/esm/services/CliYaml.js +34 -0
- package/lib/esm/services/CliYaml.js.map +1 -0
- package/lib/esm/services/NpmRegistryClient.js +117 -0
- package/lib/esm/services/NpmRegistryClient.js.map +1 -0
- package/lib/esm/services/ProjectPackageJson.js +417 -0
- package/lib/esm/services/ProjectPackageJson.js.map +1 -0
- package/lib/esm/services/Renderer.js +150 -0
- package/lib/esm/services/Renderer.js.map +1 -0
- package/lib/esm/services/index.js +14 -0
- package/lib/esm/services/index.js.map +1 -0
- package/lib/esm/utils/createInjector.js +30 -0
- package/lib/esm/utils/createInjector.js.map +1 -0
- package/lib/esm/utils/createTasksRunner.js +69 -0
- package/lib/esm/utils/createTasksRunner.js.map +1 -0
- package/lib/esm/utils/getCommandMetadata.js +15 -0
- package/lib/esm/utils/getCommandMetadata.js.map +1 -0
- package/lib/esm/utils/getPackageJson.js +33 -0
- package/lib/esm/utils/getPackageJson.js.map +1 -0
- package/lib/esm/utils/hbs/array.js +518 -0
- package/lib/esm/utils/hbs/array.js.map +1 -0
- package/lib/esm/utils/hbs/collection.js +62 -0
- package/lib/esm/utils/hbs/collection.js.map +1 -0
- package/lib/esm/utils/hbs/comparison.js +433 -0
- package/lib/esm/utils/hbs/comparison.js.map +1 -0
- package/lib/esm/utils/hbs/index.js +12 -0
- package/lib/esm/utils/hbs/index.js.map +1 -0
- package/lib/esm/utils/hbs/object.js +241 -0
- package/lib/esm/utils/hbs/object.js.map +1 -0
- package/lib/esm/utils/hbs/switch.js +11 -0
- package/lib/esm/utils/hbs/switch.js.map +1 -0
- package/lib/esm/utils/index.js +11 -0
- package/lib/esm/utils/index.js.map +1 -0
- package/lib/esm/utils/isValidVersion.js +6 -0
- package/lib/esm/utils/isValidVersion.js.map +1 -0
- package/lib/esm/utils/loadPlugins.js +42 -0
- package/lib/esm/utils/loadPlugins.js.map +1 -0
- package/lib/esm/utils/logToCurl.js +14 -0
- package/lib/esm/utils/logToCurl.js.map +1 -0
- package/lib/esm/utils/mapCommanderArgs.js +36 -0
- package/lib/esm/utils/mapCommanderArgs.js.map +1 -0
- package/lib/esm/utils/mapCommanderOptions.js +12 -0
- package/lib/esm/utils/mapCommanderOptions.js.map +1 -0
- package/lib/esm/utils/normalizePath.js +14 -0
- package/lib/esm/utils/normalizePath.js.map +1 -0
- package/lib/esm/utils/parseOption.js +23 -0
- package/lib/esm/utils/parseOption.js.map +1 -0
- package/lib/esm/utils/patchCommander.js +55 -0
- package/lib/esm/utils/patchCommander.js.map +1 -0
- package/lib/esm/utils/renderer/insertAfter.js +13 -0
- package/lib/esm/utils/renderer/insertAfter.js.map +1 -0
- package/lib/esm/utils/renderer/insertImport.js +12 -0
- package/lib/esm/utils/renderer/insertImport.js.map +1 -0
- package/lib/{CliCore.d.ts → types/CliCore.d.ts} +0 -0
- package/lib/{decorators → types/decorators}/command.d.ts +0 -0
- package/lib/{decorators → types/decorators}/index.d.ts +0 -0
- package/lib/{decorators → types/decorators}/on.d.ts +0 -0
- package/lib/{decorators → types/decorators}/onAdd.d.ts +0 -0
- package/lib/{decorators → types/decorators}/onExec.d.ts +0 -0
- package/lib/{decorators → types/decorators}/onPostInstall.d.ts +0 -0
- package/lib/{decorators → types/decorators}/onPrompt.d.ts +0 -0
- package/lib/{domains → types/domains}/CliError.d.ts +0 -0
- package/lib/{domains → types/domains}/CommandStoreKeys.d.ts +0 -0
- package/lib/{index.d.ts → types/index.d.ts} +0 -0
- package/lib/{interfaces → types/interfaces}/CliDefaultOptions.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/CommandMetadata.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/CommandParameters.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/CommandProvider.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/PackageJson.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/ProjectPreferences.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/Tasks.d.ts +0 -0
- package/lib/{interfaces → types/interfaces}/index.d.ts +0 -0
- package/lib/{registries → types/registries}/CommandRegistry.d.ts +0 -0
- package/lib/{services → types/services}/CliConfiguration.d.ts +0 -0
- package/lib/{services → types/services}/CliDockerComposeYaml.d.ts +0 -0
- package/lib/{services → types/services}/CliExeca.d.ts +1 -0
- package/lib/{services → types/services}/CliFs.d.ts +1 -0
- package/lib/{services → types/services}/CliHooks.d.ts +0 -0
- package/lib/{services → types/services}/CliHttpClient.d.ts +0 -0
- package/lib/{services → types/services}/CliHttpLogClient.d.ts +0 -0
- package/lib/{services → types/services}/CliPackageJson.d.ts +0 -0
- package/lib/{services → types/services}/CliPlugins.d.ts +0 -0
- package/lib/{services → types/services}/CliProxyAgent.d.ts +0 -0
- package/lib/{services → types/services}/CliRunScript.d.ts +0 -0
- package/lib/{services → types/services}/CliService.d.ts +0 -0
- package/lib/{services → types/services}/CliYaml.d.ts +0 -0
- package/lib/{services → types/services}/NpmRegistryClient.d.ts +0 -0
- package/lib/{services → types/services}/ProjectPackageJson.d.ts +0 -0
- package/lib/{services → types/services}/Renderer.d.ts +0 -0
- package/lib/{services → types/services}/index.d.ts +0 -0
- package/lib/{utils → types/utils}/createInjector.d.ts +0 -0
- package/lib/{utils → types/utils}/createTasksRunner.d.ts +0 -0
- package/lib/{utils → types/utils}/getCommandMetadata.d.ts +0 -0
- package/lib/{utils → types/utils}/getPackageJson.d.ts +0 -0
- package/lib/{utils → types/utils}/hbs/array.d.ts +0 -0
- package/lib/{utils → types/utils}/hbs/collection.d.ts +0 -0
- package/lib/{utils → types/utils}/hbs/comparison.d.ts +0 -0
- package/lib/{utils → types/utils}/hbs/index.d.ts +0 -0
- package/lib/{utils → types/utils}/hbs/object.d.ts +0 -0
- package/lib/{utils → types/utils}/hbs/switch.d.ts +0 -0
- package/lib/{utils → types/utils}/index.d.ts +0 -0
- package/lib/{utils → types/utils}/isValidVersion.d.ts +0 -0
- package/lib/{utils → types/utils}/loadPlugins.d.ts +0 -0
- package/lib/{utils → types/utils}/logToCurl.d.ts +0 -0
- package/lib/{utils → types/utils}/mapCommanderArgs.d.ts +0 -0
- package/lib/{utils → types/utils}/mapCommanderOptions.d.ts +0 -0
- package/lib/{utils → types/utils}/normalizePath.d.ts +0 -0
- package/lib/{utils → types/utils}/parseOption.d.ts +0 -0
- package/lib/{utils → types/utils}/patchCommander.d.ts +0 -0
- package/lib/{utils → types/utils}/renderer/insertAfter.d.ts +0 -0
- package/lib/{utils → types/utils}/renderer/insertImport.d.ts +0 -0
- package/package.json +19 -9
- package/tsconfig.compile.esm.json +12 -0
- package/lib/index.js +0 -3992
- package/lib/index.js.map +0 -1
- package/lib/index.modern.js +0 -3832
- package/lib/index.modern.js.map +0 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { InjectorService } from "@tsed/di";
|
|
2
|
+
import { Logger } from "@tsed/logger";
|
|
3
|
+
import { CliConfiguration } from "../services/CliConfiguration.js";
|
|
4
|
+
import { ProjectPackageJson } from "../services/ProjectPackageJson.js";
|
|
5
|
+
let logger;
|
|
6
|
+
export function getLogger() {
|
|
7
|
+
return logger;
|
|
8
|
+
}
|
|
9
|
+
function createConfiguration(injector) {
|
|
10
|
+
injector.addProvider(CliConfiguration);
|
|
11
|
+
return injector.invoke(CliConfiguration);
|
|
12
|
+
}
|
|
13
|
+
export function createInjector(settings = {}) {
|
|
14
|
+
var _a;
|
|
15
|
+
const injector = new InjectorService();
|
|
16
|
+
injector.settings = createConfiguration(injector);
|
|
17
|
+
logger = injector.logger = new Logger(settings.name || "CLI");
|
|
18
|
+
injector.addProvider(ProjectPackageJson);
|
|
19
|
+
injector.settings.set(settings);
|
|
20
|
+
/* istanbul ignore next */
|
|
21
|
+
if (injector.settings.env === "test") {
|
|
22
|
+
injector.logger.stop();
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
/* istanbul ignore next */
|
|
26
|
+
injector.logger.level = ((_a = injector.settings.logger) === null || _a === void 0 ? void 0 : _a.level) || "error";
|
|
27
|
+
}
|
|
28
|
+
return injector;
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=createInjector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createInjector.js","sourceRoot":"","sources":["../../../src/utils/createInjector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,eAAe,EAAC,MAAM,UAAU,CAAC;AACjE,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,gBAAgB,EAAC,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAC,kBAAkB,EAAC,MAAM,gCAAgC,CAAC;AAElE,IAAI,MAAc,CAAC;AAEnB,MAAM,UAAU,SAAS;IACvB,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,mBAAmB,CAAC,QAAyB;IACpD,QAAQ,CAAC,WAAW,CAAC,gBAAgB,CAAC,CAAC;IAEvC,OAAO,QAAQ,CAAC,MAAM,CAAwC,gBAAgB,CAAC,CAAC;AAClF,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,WAA4C,EAAE;;IAC3E,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;IACvC,QAAQ,CAAC,QAAQ,GAAG,mBAAmB,CAAC,QAAQ,CAAC,CAAC;IAClD,MAAM,GAAG,QAAQ,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,KAAK,CAAC,CAAC;IAE9D,QAAQ,CAAC,WAAW,CAAC,kBAAkB,CAAC,CAAC;IAEzC,QAAQ,CAAC,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAEhC,0BAA0B;IAC1B,IAAI,QAAQ,CAAC,QAAQ,CAAC,GAAG,KAAK,MAAM,EAAE;QACpC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;KACxB;SAAM;QACL,0BAA0B;QAC1B,QAAQ,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA,MAAA,QAAQ,CAAC,QAAQ,CAAC,MAAM,0CAAE,KAAK,KAAI,OAAO,CAAC;KACpE;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import {DIConfigurationOptions, InjectorService} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {CliConfiguration} from \"../services/CliConfiguration\";\nimport {ProjectPackageJson} from \"../services/ProjectPackageJson\";\n\nlet logger: Logger;\n\nexport function getLogger() {\n return logger;\n}\n\nfunction createConfiguration(injector: InjectorService): CliConfiguration & TsED.Configuration {\n injector.addProvider(CliConfiguration);\n\n return injector.invoke<CliConfiguration & TsED.Configuration>(CliConfiguration);\n}\n\nexport function createInjector(settings: Partial<DIConfigurationOptions> = {}) {\n const injector = new InjectorService();\n injector.settings = createConfiguration(injector);\n logger = injector.logger = new Logger(settings.name || \"CLI\");\n\n injector.addProvider(ProjectPackageJson);\n\n injector.settings.set(settings);\n\n /* istanbul ignore next */\n if (injector.settings.env === \"test\") {\n injector.logger.stop();\n } else {\n /* istanbul ignore next */\n injector.logger.level = injector.settings.logger?.level || \"error\";\n }\n\n return injector;\n}\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { Listr, Logger } from "listr2";
|
|
2
|
+
import { isFunction } from "@tsed/core";
|
|
3
|
+
import { getLogger } from "./createInjector.js";
|
|
4
|
+
class CustomLogger extends Logger {
|
|
5
|
+
fail(message) {
|
|
6
|
+
var _a;
|
|
7
|
+
(_a = getLogger()) === null || _a === void 0 ? void 0 : _a.error("[FAIL]", message);
|
|
8
|
+
}
|
|
9
|
+
skip(message) {
|
|
10
|
+
var _a;
|
|
11
|
+
(_a = getLogger()) === null || _a === void 0 ? void 0 : _a.info("[SKIP]", message);
|
|
12
|
+
}
|
|
13
|
+
success(message) {
|
|
14
|
+
var _a;
|
|
15
|
+
(_a = getLogger()) === null || _a === void 0 ? void 0 : _a.info("[SUCCESS]", message);
|
|
16
|
+
}
|
|
17
|
+
data(message) {
|
|
18
|
+
var _a;
|
|
19
|
+
(_a = getLogger()) === null || _a === void 0 ? void 0 : _a.info("[DATA]", message);
|
|
20
|
+
}
|
|
21
|
+
start(message) {
|
|
22
|
+
var _a;
|
|
23
|
+
(_a = getLogger()) === null || _a === void 0 ? void 0 : _a.info("[START]", message);
|
|
24
|
+
}
|
|
25
|
+
title(message) {
|
|
26
|
+
var _a;
|
|
27
|
+
(_a = getLogger()) === null || _a === void 0 ? void 0 : _a.info("[TITLE]", message);
|
|
28
|
+
}
|
|
29
|
+
retry(message) {
|
|
30
|
+
var _a;
|
|
31
|
+
(_a = getLogger()) === null || _a === void 0 ? void 0 : _a.info("[RETRY]", message);
|
|
32
|
+
}
|
|
33
|
+
rollback(message) {
|
|
34
|
+
var _a;
|
|
35
|
+
(_a = getLogger()) === null || _a === void 0 ? void 0 : _a.info("[ROLLBACK]", message);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
function getOptions(ctx) {
|
|
39
|
+
const useRawRenderer = !(!ctx.verbose && !process.env.CI);
|
|
40
|
+
const rendererOptions = useRawRenderer
|
|
41
|
+
? {
|
|
42
|
+
logger: CustomLogger
|
|
43
|
+
}
|
|
44
|
+
: {};
|
|
45
|
+
return {
|
|
46
|
+
...ctx,
|
|
47
|
+
rendererSilent: process.env.NODE_ENV === "test",
|
|
48
|
+
rendererFallback: useRawRenderer,
|
|
49
|
+
renderer: useRawRenderer ? "verbose" : "default",
|
|
50
|
+
nonTTYRendererOptions: rendererOptions,
|
|
51
|
+
rendererOptions
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
export function createTasks(tasks, ctx) {
|
|
55
|
+
return new Listr(tasks, getOptions(ctx));
|
|
56
|
+
}
|
|
57
|
+
export function createSubTasks(tasks, opts) {
|
|
58
|
+
opts = getOptions(opts);
|
|
59
|
+
return async (ctx, task) => {
|
|
60
|
+
if (isFunction(tasks)) {
|
|
61
|
+
tasks = await tasks(ctx, task);
|
|
62
|
+
}
|
|
63
|
+
return task.newListr(tasks, opts);
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
export function createTasksRunner(tasks, ctx) {
|
|
67
|
+
return createTasks(tasks, ctx).run(ctx);
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=createTasksRunner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTasksRunner.js","sourceRoot":"","sources":["../../../src/utils/createTasksRunner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAoB,MAAM,EAAC,MAAM,QAAQ,CAAC;AAEvD,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AACtC,OAAO,EAAC,SAAS,EAAC,MAAM,kBAAkB,CAAC;AAE3C,MAAM,YAAa,SAAQ,MAAM;IAC/B,IAAI,CAAC,OAAe;;QAClB,MAAA,SAAS,EAAE,0CAAE,KAAK,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,IAAI,CAAC,OAAe;;QAClB,MAAA,SAAS,EAAE,0CAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,OAAO,CAAC,OAAe;;QACrB,MAAA,SAAS,EAAE,0CAAE,IAAI,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,CAAC,OAAe;;QAClB,MAAA,SAAS,EAAE,0CAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;IACvC,CAAC;IAED,KAAK,CAAC,OAAe;;QACnB,MAAA,SAAS,EAAE,0CAAE,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,OAAe;;QACnB,MAAA,SAAS,EAAE,0CAAE,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,KAAK,CAAC,OAAe;;QACnB,MAAA,SAAS,EAAE,0CAAE,IAAI,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IAED,QAAQ,CAAC,OAAe;;QACtB,MAAA,SAAS,EAAE,0CAAE,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;IAC3C,CAAC;CACF;AAED,SAAS,UAAU,CAAC,GAAgB;IAClC,MAAM,cAAc,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC1D,MAAM,eAAe,GAAG,cAAc;QACpC,CAAC,CAAC;YACE,MAAM,EAAE,YAAY;SACrB;QACH,CAAC,CAAC,EAAE,CAAC;IACP,OAAO;QACL,GAAG,GAAG;QACN,cAAc,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;QAC/C,gBAAgB,EAAE,cAAc;QAChC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS;QAChD,qBAAqB,EAAE,eAAe;QACtC,eAAe;KAChB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAAY,EAAE,GAAgB;IACxD,OAAO,IAAI,KAAK,CAAC,KAAY,EAAE,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,KAAgE,EAAE,IAAiB;IAChH,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAExB,OAAO,KAAK,EAAE,GAAQ,EAAE,IAAgC,EAAE,EAAE;QAC1D,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE;YACrB,KAAK,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;SAChC;QAED,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IACpC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,iBAAiB,CAAC,KAAY,EAAE,GAAgB;IAC9D,OAAO,WAAW,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,GAAU,CAAC,CAAC;AACjD,CAAC","sourcesContent":["import {Listr, ListrTaskWrapper, Logger} from \"listr2\";\nimport type {TaskOptions, Tasks} from \"../interfaces/Tasks\";\nimport {isFunction} from \"@tsed/core\";\nimport {getLogger} from \"./createInjector\";\n\nclass CustomLogger extends Logger {\n fail(message: string) {\n getLogger()?.error(\"[FAIL]\", message);\n }\n\n skip(message: string) {\n getLogger()?.info(\"[SKIP]\", message);\n }\n\n success(message: string) {\n getLogger()?.info(\"[SUCCESS]\", message);\n }\n\n data(message: string) {\n getLogger()?.info(\"[DATA]\", message);\n }\n\n start(message: string) {\n getLogger()?.info(\"[START]\", message);\n }\n\n title(message: string) {\n getLogger()?.info(\"[TITLE]\", message);\n }\n\n retry(message: string) {\n getLogger()?.info(\"[RETRY]\", message);\n }\n\n rollback(message: string) {\n getLogger()?.info(\"[ROLLBACK]\", message);\n }\n}\n\nfunction getOptions(ctx: TaskOptions): any {\n const useRawRenderer = !(!ctx.verbose && !process.env.CI);\n const rendererOptions = useRawRenderer\n ? {\n logger: CustomLogger\n }\n : {};\n return {\n ...ctx,\n rendererSilent: process.env.NODE_ENV === \"test\",\n rendererFallback: useRawRenderer,\n renderer: useRawRenderer ? \"verbose\" : \"default\",\n nonTTYRendererOptions: rendererOptions,\n rendererOptions\n };\n}\n\nexport function createTasks(tasks: Tasks, ctx: TaskOptions) {\n return new Listr(tasks as any, getOptions(ctx));\n}\n\nexport function createSubTasks(tasks: Tasks | ((ctx: any, task: any) => Tasks | Promise<Tasks>), opts: TaskOptions) {\n opts = getOptions(opts);\n\n return async (ctx: any, task: ListrTaskWrapper<any, any>) => {\n if (isFunction(tasks)) {\n tasks = await tasks(ctx, task);\n }\n\n return task.newListr(tasks, opts);\n };\n}\n\nexport function createTasksRunner(tasks: Tasks, ctx: TaskOptions) {\n return createTasks(tasks, ctx).run(ctx as any);\n}\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Store } from "@tsed/core";
|
|
2
|
+
import { CommandStoreKeys } from "../domains/CommandStoreKeys.js";
|
|
3
|
+
export function getCommandMetadata(token) {
|
|
4
|
+
var _a;
|
|
5
|
+
const { name, alias, args = {}, allowUnknownOption, description, options = {} } = (_a = Store.from(token)) === null || _a === void 0 ? void 0 : _a.get(CommandStoreKeys.COMMAND);
|
|
6
|
+
return {
|
|
7
|
+
name,
|
|
8
|
+
alias,
|
|
9
|
+
args,
|
|
10
|
+
description,
|
|
11
|
+
options,
|
|
12
|
+
allowUnknownOption: !!allowUnknownOption
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=getCommandMetadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getCommandMetadata.js","sourceRoot":"","sources":["../../../src/utils/getCommandMetadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,KAAK,EAAO,MAAM,YAAY,CAAC;AACvC,OAAO,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAC;AAG7D,MAAM,UAAU,kBAAkB,CAAC,KAAgB;;IACjD,MAAM,EAAC,IAAI,EAAE,KAAK,EAAE,IAAI,GAAG,EAAE,EAAE,kBAAkB,EAAE,WAAW,EAAE,OAAO,GAAG,EAAE,EAAC,GAAG,MAAA,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,0CAAE,GAAG,CACpG,gBAAgB,CAAC,OAAO,CACJ,CAAC;IAEvB,OAAO;QACL,IAAI;QACJ,KAAK;QACL,IAAI;QACJ,WAAW;QACX,OAAO;QACP,kBAAkB,EAAE,CAAC,CAAC,kBAAkB;KACzC,CAAC;AACJ,CAAC","sourcesContent":["import {Store, Type} from \"@tsed/core\";\nimport {CommandStoreKeys} from \"../domains/CommandStoreKeys\";\nimport {CommandParameters} from \"../interfaces/CommandParameters\";\n\nexport function getCommandMetadata(token: Type<any>) {\n const {name, alias, args = {}, allowUnknownOption, description, options = {}} = Store.from(token)?.get(\n CommandStoreKeys.COMMAND\n ) as CommandParameters;\n\n return {\n name,\n alias,\n args,\n description,\n options,\n allowUnknownOption: !!allowUnknownOption\n };\n}\n"]}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import readPkgUp from "read-pkg-up";
|
|
2
|
+
import { dirname, join } from "path";
|
|
3
|
+
import Fs from "fs-extra";
|
|
4
|
+
function useReadPkgUp(configuration) {
|
|
5
|
+
var _a;
|
|
6
|
+
return !(process.argv.includes("init") && !Fs.existsSync(join(String((_a = configuration.project) === null || _a === void 0 ? void 0 : _a.rootDir), "package.json")));
|
|
7
|
+
}
|
|
8
|
+
function getEmptyPackageJson(configuration) {
|
|
9
|
+
return {
|
|
10
|
+
name: configuration.name,
|
|
11
|
+
version: "1.0.0",
|
|
12
|
+
description: "",
|
|
13
|
+
scripts: {},
|
|
14
|
+
dependencies: {},
|
|
15
|
+
devDependencies: {}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function getPackageJson(configuration) {
|
|
19
|
+
var _a;
|
|
20
|
+
if (useReadPkgUp(configuration)) {
|
|
21
|
+
const result = readPkgUp.sync({
|
|
22
|
+
cwd: (_a = configuration.project) === null || _a === void 0 ? void 0 : _a.rootDir
|
|
23
|
+
});
|
|
24
|
+
if (result && result.path) {
|
|
25
|
+
const pkgPath = dirname(result.path);
|
|
26
|
+
configuration.set("project.root", pkgPath);
|
|
27
|
+
const pkg = Fs.readJsonSync(result.path, { encoding: "utf8" });
|
|
28
|
+
return { ...getEmptyPackageJson(configuration), ...pkg };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return getEmptyPackageJson(configuration);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=getPackageJson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPackageJson.js","sourceRoot":"","sources":["../../../src/utils/getPackageJson.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,aAAa,CAAC;AACpC,OAAO,EAAC,OAAO,EAAE,IAAI,EAAC,MAAM,MAAM,CAAC;AACnC,OAAO,EAAE,MAAM,UAAU,CAAC;AAE1B,SAAS,YAAY,CAAC,aAA4B;;IAChD,OAAO,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,MAAA,aAAa,CAAC,OAAO,0CAAE,OAAO,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,CAAC;AAC1H,CAAC;AAED,SAAS,mBAAmB,CAAC,aAA4B;IACvD,OAAO;QACL,IAAI,EAAE,aAAa,CAAC,IAAI;QACxB,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE,EAAE;QACf,OAAO,EAAE,EAAE;QACX,YAAY,EAAE,EAAE;QAChB,eAAe,EAAE,EAAE;KACpB,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,cAAc,CAAC,aAA4B;;IACzD,IAAI,YAAY,CAAC,aAAa,CAAC,EAAE;QAC/B,MAAM,MAAM,GAAG,SAAS,CAAC,IAAI,CAAC;YAC5B,GAAG,EAAE,MAAA,aAAa,CAAC,OAAO,0CAAE,OAAO;SACpC,CAAC,CAAC;QAEH,IAAI,MAAM,IAAI,MAAM,CAAC,IAAI,EAAE;YACzB,MAAM,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAErC,aAAa,CAAC,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;YAE3C,MAAM,GAAG,GAAG,EAAE,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,EAAE,EAAC,QAAQ,EAAE,MAAM,EAAC,CAAC,CAAC;YAE7D,OAAO,EAAC,GAAG,mBAAmB,CAAC,aAAa,CAAC,EAAE,GAAG,GAAG,EAAQ,CAAC;SAC/D;KACF;IAED,OAAO,mBAAmB,CAAC,aAAa,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["import {Configuration} from \"@tsed/di\";\nimport readPkgUp from \"read-pkg-up\";\nimport {dirname, join} from \"path\";\nimport Fs from \"fs-extra\";\n\nfunction useReadPkgUp(configuration: Configuration) {\n return !(process.argv.includes(\"init\") && !Fs.existsSync(join(String(configuration.project?.rootDir), \"package.json\")));\n}\n\nfunction getEmptyPackageJson(configuration: Configuration) {\n return {\n name: configuration.name,\n version: \"1.0.0\",\n description: \"\",\n scripts: {},\n dependencies: {},\n devDependencies: {}\n };\n}\n\nexport function getPackageJson(configuration: Configuration) {\n if (useReadPkgUp(configuration)) {\n const result = readPkgUp.sync({\n cwd: configuration.project?.rootDir\n });\n\n if (result && result.path) {\n const pkgPath = dirname(result.path);\n\n configuration.set(\"project.root\", pkgPath);\n\n const pkg = Fs.readJsonSync(result.path, {encoding: \"utf8\"});\n\n return {...getEmptyPackageJson(configuration), ...pkg} as any;\n }\n }\n\n return getEmptyPackageJson(configuration);\n}\n"]}
|
|
@@ -0,0 +1,518 @@
|
|
|
1
|
+
import { getValue, isArray, isNumber, isObject, isString } from "@tsed/core";
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import createFrame from "create-frame";
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
import util from "handlebars-utils";
|
|
8
|
+
export const helpers = {};
|
|
9
|
+
/**
|
|
10
|
+
* Returns all of the items in an array after the specified index.
|
|
11
|
+
* Opposite of [before](#before).
|
|
12
|
+
*
|
|
13
|
+
* ```handlebars
|
|
14
|
+
* <!-- array: ['a', 'b', 'c'] -->
|
|
15
|
+
* {{after array 1}}
|
|
16
|
+
* <!-- results in: '["c"]' -->
|
|
17
|
+
* ```
|
|
18
|
+
* @param {Array} `array` Collection
|
|
19
|
+
* @param {Number} `n` Starting index (number of items to exclude)
|
|
20
|
+
* @return {Array} Array exluding `n` items.
|
|
21
|
+
* @api public
|
|
22
|
+
*/
|
|
23
|
+
helpers.after = function (array, n) {
|
|
24
|
+
if (util.isUndefined(array))
|
|
25
|
+
return "";
|
|
26
|
+
return array.slice(n);
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Cast the given `value` to an array.
|
|
30
|
+
*
|
|
31
|
+
* ```handlebars
|
|
32
|
+
* {{arrayify "foo"}}
|
|
33
|
+
* <!-- results in: [ "foo" ] -->
|
|
34
|
+
* ```
|
|
35
|
+
* @param {any} `value`
|
|
36
|
+
* @return {Array}
|
|
37
|
+
* @api public
|
|
38
|
+
*/
|
|
39
|
+
helpers.arrayify = function (value) {
|
|
40
|
+
return value ? (isArray(value) ? value : [value]) : [];
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Return all of the items in the collection before the specified
|
|
44
|
+
* count. Opposite of [after](#after).
|
|
45
|
+
*
|
|
46
|
+
* ```handlebars
|
|
47
|
+
* <!-- array: ['a', 'b', 'c'] -->
|
|
48
|
+
* {{before array 2}}
|
|
49
|
+
* <!-- results in: '["a", "b"]' -->
|
|
50
|
+
* ```
|
|
51
|
+
* @param {Array} `array`
|
|
52
|
+
* @param {Number} `n`
|
|
53
|
+
* @return {Array} Array excluding items after the given number.
|
|
54
|
+
* @api public
|
|
55
|
+
*/
|
|
56
|
+
helpers.before = function (array, n) {
|
|
57
|
+
if (util.isUndefined(array))
|
|
58
|
+
return "";
|
|
59
|
+
return array.slice(0, -n);
|
|
60
|
+
};
|
|
61
|
+
/**
|
|
62
|
+
* ```handlebars
|
|
63
|
+
* <!-- array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] -->
|
|
64
|
+
* {{#eachIndex array}}
|
|
65
|
+
* {{item}} is {{index}}
|
|
66
|
+
* {{/eachIndex}}
|
|
67
|
+
* ```
|
|
68
|
+
* @param {Array} `array`
|
|
69
|
+
* @param {Object} `options`
|
|
70
|
+
* @return {String}
|
|
71
|
+
* @block
|
|
72
|
+
* @api public
|
|
73
|
+
*/
|
|
74
|
+
helpers.eachIndex = function (array, options) {
|
|
75
|
+
let result = "";
|
|
76
|
+
for (let i = 0; i < array.length; i++) {
|
|
77
|
+
result += options.fn({ item: array[i], index: i });
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Block helper that filters the given array and renders the block for values that
|
|
83
|
+
* evaluate to `true`, otherwise the inverse block is returned.
|
|
84
|
+
*
|
|
85
|
+
* ```handlebars
|
|
86
|
+
* <!-- array: ['a', 'b', 'c'] -->
|
|
87
|
+
* {{#filter array "foo"}}AAA{{else}}BBB{{/filter}}
|
|
88
|
+
* <!-- results in: 'BBB' -->
|
|
89
|
+
* ```
|
|
90
|
+
* @param {Array} `array`
|
|
91
|
+
* @param {any} `value`
|
|
92
|
+
* @param {Object} `options`
|
|
93
|
+
* @return {String}
|
|
94
|
+
* @block
|
|
95
|
+
* @api public
|
|
96
|
+
*/
|
|
97
|
+
helpers.filter = function (array, value, options) {
|
|
98
|
+
let content = "";
|
|
99
|
+
let results = [];
|
|
100
|
+
// filter on a specific property
|
|
101
|
+
const prop = options.hash && (options.hash.property || options.hash.prop);
|
|
102
|
+
if (prop) {
|
|
103
|
+
results = array.filter(function (val) {
|
|
104
|
+
return value === getValue(val, prop);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
// filter on a string value
|
|
109
|
+
results = array.filter(function (v) {
|
|
110
|
+
return value === v;
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
if (results && results.length > 0) {
|
|
114
|
+
for (let i = 0; i < results.length; i++) {
|
|
115
|
+
content += options.fn(results[i]);
|
|
116
|
+
}
|
|
117
|
+
return content;
|
|
118
|
+
}
|
|
119
|
+
return options.inverse(this);
|
|
120
|
+
};
|
|
121
|
+
/**
|
|
122
|
+
* Returns the first item, or first `n` items of an array.
|
|
123
|
+
*
|
|
124
|
+
* ```handlebars
|
|
125
|
+
* {{first "['a', 'b', 'c', 'd', 'e']" 2}}
|
|
126
|
+
* <!-- results in: '["a", "b"]' -->
|
|
127
|
+
* ```
|
|
128
|
+
* @param {Array} `array`
|
|
129
|
+
* @param {Number} `n` Number of items to return, starting at `0`.
|
|
130
|
+
* @return {Array}
|
|
131
|
+
* @api public
|
|
132
|
+
*/
|
|
133
|
+
helpers.first = function (array, n) {
|
|
134
|
+
if (array === undefined)
|
|
135
|
+
return "";
|
|
136
|
+
if (!isNumber(n)) {
|
|
137
|
+
return array[0];
|
|
138
|
+
}
|
|
139
|
+
return array.slice(0, n);
|
|
140
|
+
};
|
|
141
|
+
/**
|
|
142
|
+
* Iterates over each item in an array and exposes the current item
|
|
143
|
+
* in the array as context to the inner block. In addition to
|
|
144
|
+
* the current array item, the helper exposes the following variables
|
|
145
|
+
* to the inner block:
|
|
146
|
+
*
|
|
147
|
+
* - `index`
|
|
148
|
+
* - `total`
|
|
149
|
+
* - `isFirst`
|
|
150
|
+
* - `isLast`
|
|
151
|
+
*
|
|
152
|
+
* Also, `@index` is exposed as a private variable, and additional
|
|
153
|
+
* private variables may be defined as hash arguments.
|
|
154
|
+
*
|
|
155
|
+
* ```handlebars
|
|
156
|
+
* <!-- accounts = [
|
|
157
|
+
* {'name': 'John', 'email': 'john@example.com'},
|
|
158
|
+
* {'name': 'Malcolm', 'email': 'malcolm@example.com'},
|
|
159
|
+
* {'name': 'David', 'email': 'david@example.com'}
|
|
160
|
+
* ] -->
|
|
161
|
+
*
|
|
162
|
+
* {{#forEach accounts}}
|
|
163
|
+
* <a href="mailto:{{ email }}" title="Send an email to {{ name }}">
|
|
164
|
+
* {{ name }}
|
|
165
|
+
* </a>{{#unless isLast}}, {{/unless}}
|
|
166
|
+
* {{/forEach}}
|
|
167
|
+
* ```
|
|
168
|
+
* @source <http://stackoverflow.com/questions/13861007>
|
|
169
|
+
* @param {Array} `array`
|
|
170
|
+
* @return {String}
|
|
171
|
+
* @block
|
|
172
|
+
* @api public
|
|
173
|
+
*/
|
|
174
|
+
helpers.forEach = function (array, options) {
|
|
175
|
+
const data = createFrame(options, options.hash);
|
|
176
|
+
const len = array.length;
|
|
177
|
+
let buffer = "";
|
|
178
|
+
let i = -1;
|
|
179
|
+
while (++i < len) {
|
|
180
|
+
const item = array[i];
|
|
181
|
+
data.index = i;
|
|
182
|
+
item.index = i + 1;
|
|
183
|
+
item.total = len;
|
|
184
|
+
item.isFirst = i === 0;
|
|
185
|
+
item.isLast = i === len - 1;
|
|
186
|
+
buffer += options.fn(item, { data: data });
|
|
187
|
+
}
|
|
188
|
+
return buffer;
|
|
189
|
+
};
|
|
190
|
+
/**
|
|
191
|
+
* Block helper that renders the block if an array has the
|
|
192
|
+
* given `value`. Optionally specify an inverse block to render
|
|
193
|
+
* when the array does not have the given value.
|
|
194
|
+
*
|
|
195
|
+
* ```handlebars
|
|
196
|
+
* <!-- array: ['a', 'b', 'c'] -->
|
|
197
|
+
* {{#inArray array "d"}}
|
|
198
|
+
* foo
|
|
199
|
+
* {{else}}
|
|
200
|
+
* bar
|
|
201
|
+
* {{/inArray}}
|
|
202
|
+
* <!-- results in: 'bar' -->
|
|
203
|
+
* ```
|
|
204
|
+
* @param {Array} `array`
|
|
205
|
+
* @param {any} `value`
|
|
206
|
+
* @param {Object} `options`
|
|
207
|
+
* @return {String}
|
|
208
|
+
* @block
|
|
209
|
+
* @api public
|
|
210
|
+
*/
|
|
211
|
+
helpers.inArray = function (array, value, options) {
|
|
212
|
+
return util.value(util.indexOf(array, value) > -1, this, options);
|
|
213
|
+
};
|
|
214
|
+
/**
|
|
215
|
+
* Returns true if `value` is an es5 array.
|
|
216
|
+
*
|
|
217
|
+
* ```handlebars
|
|
218
|
+
* {{isArray "abc"}}
|
|
219
|
+
* <!-- results in: false -->
|
|
220
|
+
*
|
|
221
|
+
* <!-- array: [1, 2, 3] -->
|
|
222
|
+
* {{isArray array}}
|
|
223
|
+
* <!-- results in: true -->
|
|
224
|
+
* ```
|
|
225
|
+
* @param {any} `value` The value to test.
|
|
226
|
+
* @return {Boolean}
|
|
227
|
+
* @api public
|
|
228
|
+
*/
|
|
229
|
+
helpers.isArray = function (value) {
|
|
230
|
+
return Array.isArray(value);
|
|
231
|
+
};
|
|
232
|
+
/**
|
|
233
|
+
* Returns the item from `array` at index `idx`.
|
|
234
|
+
*
|
|
235
|
+
* ```handlebars
|
|
236
|
+
* <!-- array: ['a', 'b', 'c'] -->
|
|
237
|
+
* {{itemAt array 1}}
|
|
238
|
+
* <!-- results in: 'b' -->
|
|
239
|
+
* ```
|
|
240
|
+
* @param {Array} `array`
|
|
241
|
+
* @param {Number} `idx`
|
|
242
|
+
* @return {any} `value`
|
|
243
|
+
* @block
|
|
244
|
+
* @api public
|
|
245
|
+
*/
|
|
246
|
+
helpers.itemAt = function (array, idx) {
|
|
247
|
+
array = util.result(array);
|
|
248
|
+
if (isArray(array)) {
|
|
249
|
+
idx = isNumber(idx) ? +idx : 0;
|
|
250
|
+
if (idx < 0) {
|
|
251
|
+
return array[array.length + idx];
|
|
252
|
+
}
|
|
253
|
+
if (idx < array.length) {
|
|
254
|
+
return array[idx];
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
/**
|
|
259
|
+
* Join all elements of array into a string, optionally using a
|
|
260
|
+
* given separator.
|
|
261
|
+
*
|
|
262
|
+
* ```handlebars
|
|
263
|
+
* <!-- array: ['a', 'b', 'c'] -->
|
|
264
|
+
* {{join array}}
|
|
265
|
+
* <!-- results in: 'a, b, c' -->
|
|
266
|
+
*
|
|
267
|
+
* {{join array '-'}}
|
|
268
|
+
* <!-- results in: 'a-b-c' -->
|
|
269
|
+
* ```
|
|
270
|
+
* @param {Array} `array`
|
|
271
|
+
* @param {String} `separator` The separator to use. Defaults to `, `.
|
|
272
|
+
* @return {String}
|
|
273
|
+
* @api public
|
|
274
|
+
*/
|
|
275
|
+
helpers.join = function (array, separator) {
|
|
276
|
+
if (isString(array))
|
|
277
|
+
return array;
|
|
278
|
+
if (!isArray(array))
|
|
279
|
+
return "";
|
|
280
|
+
separator = util.isString(separator) ? separator : ", ";
|
|
281
|
+
return array.join(separator);
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* Returns true if the the length of the given `value` is equal
|
|
285
|
+
* to the given `length`. Can be used as a block or inline helper.
|
|
286
|
+
*
|
|
287
|
+
* @param {Array|String} `value`
|
|
288
|
+
* @param {Number} `length`
|
|
289
|
+
* @param {Object} `options`
|
|
290
|
+
* @return {String}
|
|
291
|
+
* @block
|
|
292
|
+
* @api public
|
|
293
|
+
*/
|
|
294
|
+
helpers.equalsLength = function (value, length, options) {
|
|
295
|
+
if (util.isOptions(length)) {
|
|
296
|
+
options = length;
|
|
297
|
+
length = 0;
|
|
298
|
+
}
|
|
299
|
+
let len = 0;
|
|
300
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
301
|
+
len = value.length;
|
|
302
|
+
}
|
|
303
|
+
return util.value(len === length, this, options);
|
|
304
|
+
};
|
|
305
|
+
/**
|
|
306
|
+
* Returns the last item, or last `n` items of an array or string.
|
|
307
|
+
* Opposite of [first](#first).
|
|
308
|
+
*
|
|
309
|
+
* ```handlebars
|
|
310
|
+
* <!-- var value = ['a', 'b', 'c', 'd', 'e'] -->
|
|
311
|
+
*
|
|
312
|
+
* {{last value}}
|
|
313
|
+
* <!-- results in: ['e'] -->
|
|
314
|
+
*
|
|
315
|
+
* {{last value 2}}
|
|
316
|
+
* <!-- results in: ['d', 'e'] -->
|
|
317
|
+
*
|
|
318
|
+
* {{last value 3}}
|
|
319
|
+
* <!-- results in: ['c', 'd', 'e'] -->
|
|
320
|
+
* ```
|
|
321
|
+
* @param {Array|String} `value` Array or string.
|
|
322
|
+
* @param {Number} `n` Number of items to return from the end of the array.
|
|
323
|
+
* @return {Array}
|
|
324
|
+
* @api public
|
|
325
|
+
*/
|
|
326
|
+
helpers.last = function (value, n) {
|
|
327
|
+
if (!isArray(value) && typeof value !== "string") {
|
|
328
|
+
return "";
|
|
329
|
+
}
|
|
330
|
+
if (!isNumber(n)) {
|
|
331
|
+
return value[value.length - 1];
|
|
332
|
+
}
|
|
333
|
+
return value.slice(-Math.abs(n));
|
|
334
|
+
};
|
|
335
|
+
/**
|
|
336
|
+
* Returns the length of the given string or array.
|
|
337
|
+
*
|
|
338
|
+
* ```handlebars
|
|
339
|
+
* {{length '["a", "b", "c"]'}}
|
|
340
|
+
* <!-- results in: 3 -->
|
|
341
|
+
*
|
|
342
|
+
* <!-- results in: myArray = ['a', 'b', 'c', 'd', 'e']; -->
|
|
343
|
+
* {{length myArray}}
|
|
344
|
+
* <!-- results in: 5 -->
|
|
345
|
+
*
|
|
346
|
+
* <!-- results in: myObject = {'a': 'a', 'b': 'b'}; -->
|
|
347
|
+
* {{length myObject}}
|
|
348
|
+
* <!-- results in: 2 -->
|
|
349
|
+
* ```
|
|
350
|
+
* @param {Array|Object|String} `value`
|
|
351
|
+
* @return {Number} The length of the value.
|
|
352
|
+
* @api public
|
|
353
|
+
*/
|
|
354
|
+
helpers.length = function (value) {
|
|
355
|
+
if (isObject(value) && !util.isOptions(value)) {
|
|
356
|
+
value = Object.keys(value);
|
|
357
|
+
}
|
|
358
|
+
if (typeof value === "string" || Array.isArray(value)) {
|
|
359
|
+
return value.length;
|
|
360
|
+
}
|
|
361
|
+
return 0;
|
|
362
|
+
};
|
|
363
|
+
/**
|
|
364
|
+
* Returns a new array, created by calling `function` on each
|
|
365
|
+
* element of the given `array`. For example,
|
|
366
|
+
*
|
|
367
|
+
* ```handlebars
|
|
368
|
+
* <!-- array: ['a', 'b', 'c'], and "double" is a
|
|
369
|
+
* fictitious function that duplicates letters -->
|
|
370
|
+
* {{map array double}}
|
|
371
|
+
* <!-- results in: '["aa", "bb", "cc"]' -->
|
|
372
|
+
* ```
|
|
373
|
+
*
|
|
374
|
+
* @param {Array} `array`
|
|
375
|
+
* @param {Function} `fn`
|
|
376
|
+
* @return {String}
|
|
377
|
+
* @api public
|
|
378
|
+
*/
|
|
379
|
+
helpers.map = function (array, iter) {
|
|
380
|
+
if (!Array.isArray(array))
|
|
381
|
+
return "";
|
|
382
|
+
const len = array.length;
|
|
383
|
+
const res = new Array(len);
|
|
384
|
+
let i = -1;
|
|
385
|
+
if (typeof iter !== "function") {
|
|
386
|
+
return array;
|
|
387
|
+
}
|
|
388
|
+
while (++i < len) {
|
|
389
|
+
res[i] = iter(array[i], i, array);
|
|
390
|
+
}
|
|
391
|
+
return res;
|
|
392
|
+
};
|
|
393
|
+
/**
|
|
394
|
+
* Map over the given object or array or objects and create an array of values
|
|
395
|
+
* from the given `prop`. Dot-notation may be used (as a string) to get
|
|
396
|
+
* nested properties.
|
|
397
|
+
*
|
|
398
|
+
* ```handlebars
|
|
399
|
+
* // {{pluck items "data.title"}}
|
|
400
|
+
* <!-- results in: '["aa", "bb", "cc"]' -->
|
|
401
|
+
* ```
|
|
402
|
+
* @param {Array|Object} `collection`
|
|
403
|
+
* @param {Function} `prop`
|
|
404
|
+
* @return {String}
|
|
405
|
+
* @api public
|
|
406
|
+
*/
|
|
407
|
+
helpers.pluck = function (arr, prop) {
|
|
408
|
+
if (util.isUndefined(arr))
|
|
409
|
+
return "";
|
|
410
|
+
const res = [];
|
|
411
|
+
for (let i = 0; i < arr.length; i++) {
|
|
412
|
+
const val = getValue(arr[i], prop);
|
|
413
|
+
if (typeof val !== "undefined") {
|
|
414
|
+
res.push(val);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
return res;
|
|
418
|
+
};
|
|
419
|
+
/**
|
|
420
|
+
* Reverse the elements in an array, or the characters in a string.
|
|
421
|
+
*
|
|
422
|
+
* ```handlebars
|
|
423
|
+
* <!-- value: 'abcd' -->
|
|
424
|
+
* {{reverse value}}
|
|
425
|
+
* <!-- results in: 'dcba' -->
|
|
426
|
+
* <!-- value: ['a', 'b', 'c', 'd'] -->
|
|
427
|
+
* {{reverse value}}
|
|
428
|
+
* <!-- results in: ['d', 'c', 'b', 'a'] -->
|
|
429
|
+
* ```
|
|
430
|
+
* @param {Array|String} `value`
|
|
431
|
+
* @return {Array|String} Returns the reversed string or array.
|
|
432
|
+
* @api public
|
|
433
|
+
*/
|
|
434
|
+
helpers.reverse = function (val) {
|
|
435
|
+
if (Array.isArray(val)) {
|
|
436
|
+
val.reverse();
|
|
437
|
+
return val;
|
|
438
|
+
}
|
|
439
|
+
if (val && isString(val)) {
|
|
440
|
+
return val.split("").reverse().join("");
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
/**
|
|
444
|
+
* Block helper that returns the block if the callback returns true
|
|
445
|
+
* for some value in the given array.
|
|
446
|
+
*
|
|
447
|
+
* ```handlebars
|
|
448
|
+
* <!-- array: [1, 'b', 3] -->
|
|
449
|
+
* {{#some array isString}}
|
|
450
|
+
* Render me if the array has a string.
|
|
451
|
+
* {{else}}
|
|
452
|
+
* Render me if it doesn't.
|
|
453
|
+
* {{/some}}
|
|
454
|
+
* <!-- results in: 'Render me if the array has a string.' -->
|
|
455
|
+
* ```
|
|
456
|
+
* @param {Array} `array`
|
|
457
|
+
* @param {Function} `iter` Iteratee
|
|
458
|
+
* @param {Options} Handlebars provided options object
|
|
459
|
+
* @return {String}
|
|
460
|
+
* @block
|
|
461
|
+
* @api public
|
|
462
|
+
*/
|
|
463
|
+
helpers.some = function (array, iter, options) {
|
|
464
|
+
if (Array.isArray(array)) {
|
|
465
|
+
for (let i = 0; i < array.length; i++) {
|
|
466
|
+
if (iter(array[i], i, array)) {
|
|
467
|
+
return options.fn(this);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
return options.inverse(this);
|
|
472
|
+
};
|
|
473
|
+
/**
|
|
474
|
+
* Sort the given `array`. If an array of objects is passed,
|
|
475
|
+
* you may optionally pass a `key` to sort on as the second
|
|
476
|
+
* argument. You may alternatively pass a sorting function as
|
|
477
|
+
* the second argument.
|
|
478
|
+
*
|
|
479
|
+
* ```handlebars
|
|
480
|
+
* <!-- array: ['b', 'a', 'c'] -->
|
|
481
|
+
* {{sort array}}
|
|
482
|
+
* <!-- results in: '["a", "b", "c"]' -->
|
|
483
|
+
* ```
|
|
484
|
+
*
|
|
485
|
+
* @param {Array} `array` the array to sort.
|
|
486
|
+
* @param {String|Function} `key` The object key to sort by, or sorting function.
|
|
487
|
+
* @api public
|
|
488
|
+
*/
|
|
489
|
+
helpers.sort = function (array, options) {
|
|
490
|
+
if (!Array.isArray(array))
|
|
491
|
+
return "";
|
|
492
|
+
if (getValue(options, "hash.reverse")) {
|
|
493
|
+
return array.sort().reverse();
|
|
494
|
+
}
|
|
495
|
+
return array.sort();
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Block helper that return an array with all duplicate
|
|
499
|
+
* values removed. Best used along with a [each](#each) helper.
|
|
500
|
+
*
|
|
501
|
+
* ```handlebars
|
|
502
|
+
* <!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] -->
|
|
503
|
+
* {{#each (unique array)}}{{.}}{{/each}}
|
|
504
|
+
* <!-- results in: 'acbe' -->
|
|
505
|
+
* ```
|
|
506
|
+
* @param {Array} `array`
|
|
507
|
+
* @param {Object} `options`
|
|
508
|
+
* @return {Array}
|
|
509
|
+
* @api public
|
|
510
|
+
*/
|
|
511
|
+
helpers.unique = function (array) {
|
|
512
|
+
if (util.isUndefined(array))
|
|
513
|
+
return "";
|
|
514
|
+
return array.filter(function (item, index, arr) {
|
|
515
|
+
return arr.indexOf(item) === index;
|
|
516
|
+
});
|
|
517
|
+
};
|
|
518
|
+
//# sourceMappingURL=array.js.map
|