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