@tsed/cli 6.6.3 → 7.0.0-alpha.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/esm/commands/add/AddCmd.js +16 -16
- package/lib/esm/commands/generate/GenerateCmd.js +69 -222
- package/lib/esm/commands/generate/mappers/mapGenerateContext.js +29 -0
- package/lib/esm/commands/init/InitCmd.js +190 -171
- package/lib/esm/commands/init/config/FeaturesPrompt.js +101 -3
- package/lib/esm/commands/init/mappers/mapToContext.js +4 -3
- package/lib/esm/commands/run/RunCmd.js +22 -26
- package/lib/esm/commands/update/UpdateCmd.js +9 -13
- package/lib/esm/fn/exec.js +5 -0
- package/lib/esm/fn/render.js +5 -0
- package/lib/esm/fn/taskOutput.js +7 -0
- package/lib/esm/index.js +7 -4
- package/lib/esm/interfaces/AlterPackageJson.js +1 -0
- package/lib/esm/interfaces/AlterProjectFiles.js +1 -0
- package/lib/esm/interfaces/AlterRenderFiles.js +1 -0
- package/lib/esm/interfaces/CliCommandHooks.js +1 -0
- package/lib/esm/interfaces/GenerateCmdContext.js +1 -0
- package/lib/esm/interfaces/InitCmdOptions.js +1 -0
- package/lib/esm/interfaces/RenderDataContext.js +1 -0
- package/lib/esm/interfaces/RuntimeTypes.js +1 -0
- package/lib/esm/interfaces/index.js +9 -0
- package/lib/esm/pipes/OutputFilePathPipe.js +40 -18
- package/lib/esm/pipes/RoutePipe.js +4 -8
- package/lib/esm/pipes/{ClassNamePipe.js → SymbolNamePipe.js} +14 -11
- package/lib/esm/pipes/index.js +1 -1
- package/lib/esm/platforms/{InitPlatformsModule.js → PlatformsModule.js} +4 -10
- package/lib/esm/platforms/supports/InitExpressPlatform.js +27 -10
- package/lib/esm/platforms/supports/InitFastifyPlatform.js +27 -10
- package/lib/esm/platforms/supports/InitKoaPlatform.js +16 -10
- package/lib/esm/processors/__fixtures__/createFakeProject.js +35 -0
- package/lib/esm/processors/transformBinFile.js +47 -0
- package/lib/esm/processors/transformConfigFile.js +105 -0
- package/lib/esm/processors/transformIndexFile.js +23 -0
- package/lib/esm/processors/transformServerFile.js +60 -0
- package/lib/esm/runtimes/RuntimesModule.js +7 -17
- package/lib/esm/runtimes/supports/BabelRuntime.js +5 -11
- package/lib/esm/runtimes/supports/BunRuntime.js +4 -10
- package/lib/esm/runtimes/supports/NodeRuntime.js +1 -1
- package/lib/esm/runtimes/supports/WebpackRuntime.js +1 -1
- package/lib/esm/services/CliProjectService.js +96 -0
- package/lib/esm/services/CliRunScript.js +4 -8
- package/lib/esm/services/CliTemplatesService.js +68 -0
- package/lib/esm/services/ProjectClient.js +161 -0
- package/lib/esm/services/mappers/mapDefaultTemplateOptions.js +30 -0
- package/lib/esm/templates/asyncFactory.template.js +38 -0
- package/lib/esm/templates/barrels.template.js +22 -0
- package/lib/esm/templates/command.template.js +56 -0
- package/lib/esm/templates/config.template.js +27 -0
- package/lib/esm/templates/controller.template.js +45 -0
- package/lib/esm/templates/decorator.template.js +182 -0
- package/lib/esm/templates/docker-compose.template.js +25 -0
- package/lib/esm/templates/dockerfile.template.js +236 -0
- package/lib/esm/templates/exception-filter.template.js +19 -0
- package/lib/esm/templates/factory.template.js +37 -0
- package/lib/esm/templates/index.command.template.js +18 -0
- package/lib/esm/templates/index.config.utils.template.js +17 -0
- package/{templates/init/src/controllers/pages/IndexController.ts.hbs → lib/esm/templates/index.controller.template.js} +14 -3
- package/lib/esm/templates/index.js +32 -0
- package/lib/esm/templates/index.logger.template.js +38 -0
- package/{templates/init/src/index.ts.hbs → lib/esm/templates/index.template.js} +17 -5
- package/lib/esm/templates/interceptor.template.js +31 -0
- package/lib/esm/templates/interface.template.js +13 -0
- package/lib/esm/templates/middleware.template.js +34 -0
- package/lib/esm/templates/model.template.js +16 -0
- package/lib/esm/templates/module.template.js +16 -0
- package/lib/esm/templates/pipe.template.js +19 -0
- package/lib/esm/templates/pm2.template.js +111 -0
- package/lib/esm/templates/prisma.service.template.js +23 -0
- package/{templates/init/README.md.hbs → lib/esm/templates/readme.template.js} +28 -13
- package/lib/esm/templates/repository.template.js +16 -0
- package/lib/esm/templates/response-filter.template.js +19 -0
- package/lib/esm/templates/server.template.js +37 -0
- package/lib/esm/templates/service.template.js +16 -0
- package/lib/esm/templates/tsconfig.spec.template.js +34 -0
- package/lib/esm/templates/tsconfig.template.js +31 -0
- package/lib/esm/templates/value.template.js +13 -0
- package/lib/esm/utils/defineTemplate.js +13 -0
- package/lib/tsconfig.esm.tsbuildinfo +1 -1
- package/lib/types/commands/add/AddCmd.d.ts +2 -2
- package/lib/types/commands/generate/GenerateCmd.d.ts +33 -87
- package/lib/types/commands/generate/mappers/mapGenerateContext.d.ts +2 -0
- package/lib/types/commands/init/InitCmd.d.ts +18 -20
- package/lib/types/commands/init/config/FeaturesPrompt.d.ts +11 -2
- package/lib/types/commands/init/mappers/mapToContext.d.ts +2 -2
- package/lib/types/commands/init/mappers/mapUniqFeatures.d.ts +1 -1
- package/lib/types/commands/init/prompts/getFeaturesPrompt.d.ts +1 -1
- package/lib/types/commands/update/UpdateCmd.d.ts +2 -2
- package/lib/types/fn/exec.d.ts +1 -0
- package/lib/types/fn/render.d.ts +2 -0
- package/lib/types/fn/taskOutput.d.ts +1 -0
- package/lib/types/index.d.ts +7 -4
- package/lib/types/interfaces/AlterGenerateTasks.d.ts +5 -0
- package/lib/types/interfaces/AlterInitSubTasks.d.ts +5 -0
- package/lib/types/interfaces/AlterPackageJson.d.ts +5 -0
- package/lib/types/interfaces/AlterProjectFiles.d.ts +5 -0
- package/lib/types/interfaces/AlterRenderFiles.d.ts +10 -0
- package/lib/types/interfaces/CliCommandHooks.d.ts +11 -0
- package/lib/types/interfaces/GenerateCmdContext.d.ts +19 -0
- package/lib/types/interfaces/InitCmdOptions.d.ts +8 -0
- package/lib/types/interfaces/PlatformType.d.ts +7 -0
- package/lib/types/interfaces/RenderDataContext.d.ts +61 -0
- package/lib/types/interfaces/RuntimeTypes.d.ts +8 -0
- package/lib/types/interfaces/index.d.ts +9 -0
- package/lib/types/pipes/OutputFilePathPipe.d.ts +7 -4
- package/lib/types/pipes/{ClassNamePipe.d.ts → SymbolNamePipe.d.ts} +3 -3
- package/lib/types/pipes/index.d.ts +1 -1
- package/lib/types/platforms/{InitPlatformsModule.d.ts → PlatformsModule.d.ts} +1 -1
- package/lib/types/platforms/supports/InitBasePlatform.d.ts +3 -0
- package/lib/types/platforms/supports/InitExpressPlatform.d.ts +2 -0
- package/lib/types/platforms/supports/InitFastifyPlatform.d.ts +2 -0
- package/lib/types/platforms/supports/InitKoaPlatform.d.ts +2 -0
- package/lib/types/processors/__fixtures__/createFakeProject.d.ts +5 -0
- package/lib/types/processors/transformBinFile.d.ts +3 -0
- package/lib/types/processors/transformConfigFile.d.ts +3 -0
- package/lib/types/processors/transformIndexFile.d.ts +3 -0
- package/lib/types/processors/transformServerFile.d.ts +3 -0
- package/lib/types/runtimes/RuntimesModule.d.ts +5 -5
- package/lib/types/services/CliProjectService.d.ts +16 -0
- package/lib/types/services/CliTemplatesService.d.ts +29 -0
- package/lib/types/services/ProjectClient.d.ts +40 -0
- package/lib/types/services/mappers/mapDefaultTemplateOptions.d.ts +11 -0
- package/lib/types/templates/asyncFactory.template.d.ts +2 -0
- package/lib/types/templates/barrels.template.d.ts +2 -0
- package/lib/types/templates/command.template.d.ts +2 -0
- package/lib/types/templates/config.template.d.ts +2 -0
- package/lib/types/templates/controller.template.d.ts +2 -0
- package/lib/types/templates/decorator.template.d.ts +2 -0
- package/lib/types/templates/docker-compose.template.d.ts +2 -0
- package/lib/types/templates/dockerfile.template.d.ts +1 -0
- package/lib/types/templates/exception-filter.template.d.ts +2 -0
- package/lib/types/templates/factory.template.d.ts +2 -0
- package/lib/types/templates/index.command.template.d.ts +2 -0
- package/lib/types/templates/index.config.utils.template.d.ts +2 -0
- package/lib/types/templates/index.controller.template.d.ts +2 -0
- package/lib/types/templates/index.d.ts +31 -0
- package/lib/types/templates/index.logger.template.d.ts +2 -0
- package/lib/types/templates/index.template.d.ts +2 -0
- package/lib/types/templates/interceptor.template.d.ts +2 -0
- package/lib/types/templates/interface.template.d.ts +2 -0
- package/lib/types/templates/middleware.template.d.ts +2 -0
- package/lib/types/templates/model.template.d.ts +2 -0
- package/lib/types/templates/module.template.d.ts +2 -0
- package/lib/types/templates/pipe.template.d.ts +2 -0
- package/lib/types/templates/pm2.template.d.ts +1 -0
- package/lib/types/templates/prisma.service.template.d.ts +2 -0
- package/lib/types/templates/readme.template.d.ts +2 -0
- package/lib/types/templates/repository.template.d.ts +2 -0
- package/lib/types/templates/response-filter.template.d.ts +2 -0
- package/lib/types/templates/server.template.d.ts +2 -0
- package/lib/types/templates/service.template.d.ts +2 -0
- package/lib/types/templates/tsconfig.spec.template.d.ts +2 -0
- package/lib/types/templates/tsconfig.template.d.ts +2 -0
- package/lib/types/templates/value.template.d.ts +2 -0
- package/lib/types/utils/defineTemplate.d.ts +39 -0
- package/package.json +14 -12
- package/templates/tsconfig.node.json +14 -0
- package/templates/webpack.config.js +55 -0
- package/lib/esm/commands/generate/ProviderTypes.js +0 -103
- package/lib/esm/commands/init/interfaces/InitOptions.js +0 -5
- package/lib/esm/services/ProvidersInfoService.js +0 -46
- package/lib/esm/services/Renderer.js +0 -162
- package/lib/esm/utils/fillImports.js +0 -38
- package/lib/esm/utils/hbs/array.js +0 -515
- package/lib/esm/utils/hbs/collection.js +0 -60
- package/lib/esm/utils/hbs/comparison.js +0 -431
- package/lib/esm/utils/hbs/index.js +0 -11
- package/lib/esm/utils/hbs/object.js +0 -236
- package/lib/esm/utils/hbs/switch.js +0 -10
- package/lib/esm/utils/renderer/insertAfter.js +0 -12
- package/lib/esm/utils/renderer/insertImport.js +0 -11
- package/lib/types/commands/generate/ProviderTypes.d.ts +0 -11
- package/lib/types/commands/init/interfaces/InitCmdContext.d.ts +0 -6
- package/lib/types/commands/init/interfaces/InitOptions.d.ts +0 -20
- package/lib/types/services/ProvidersInfoService.d.ts +0 -21
- package/lib/types/services/Renderer.d.ts +0 -44
- package/lib/types/utils/fillImports.d.ts +0 -1
- package/lib/types/utils/hbs/array.d.ts +0 -1
- package/lib/types/utils/hbs/collection.d.ts +0 -1
- package/lib/types/utils/hbs/comparison.d.ts +0 -1
- package/lib/types/utils/hbs/object.d.ts +0 -1
- package/lib/types/utils/hbs/switch.d.ts +0 -1
- package/lib/types/utils/renderer/insertAfter.d.ts +0 -1
- package/lib/types/utils/renderer/insertImport.d.ts +0 -1
- package/templates/generate/async.factory.hbs +0 -35
- package/templates/generate/command.hbs +0 -45
- package/templates/generate/controller.hbs +0 -10
- package/templates/generate/decorator.class.hbs +0 -14
- package/templates/generate/decorator.endpoint.hbs +0 -15
- package/templates/generate/decorator.generic.hbs +0 -19
- package/templates/generate/decorator.method.hbs +0 -16
- package/templates/generate/decorator.middleware.hbs +0 -26
- package/templates/generate/decorator.param.hbs +0 -15
- package/templates/generate/decorator.parameters.hbs +0 -9
- package/templates/generate/decorator.prop.hbs +0 -14
- package/templates/generate/decorator.property.hbs +0 -5
- package/templates/generate/exception-filter.hbs +0 -9
- package/templates/generate/factory.hbs +0 -11
- package/templates/generate/injectable.hbs +0 -6
- package/templates/generate/interceptor.hbs +0 -21
- package/templates/generate/interface.hbs +0 -3
- package/templates/generate/middleware.hbs +0 -9
- package/templates/generate/model.hbs +0 -6
- package/templates/generate/module.hbs +0 -6
- package/templates/generate/pipe.hbs +0 -9
- package/templates/generate/prisma.service.hbs +0 -13
- package/templates/generate/repository.hbs +0 -6
- package/templates/generate/response-filter.hbs +0 -9
- package/templates/generate/server/_partials/server-footer.hbs +0 -10
- package/templates/generate/server/_partials/server-header.hbs +0 -34
- package/templates/generate/server/express/server.hbs +0 -10
- package/templates/generate/server/fastify/server.hbs +0 -14
- package/templates/generate/server/koa/server.hbs +0 -8
- package/templates/generate/service.hbs +0 -6
- package/templates/generate/value.hbs +0 -3
- package/templates/init/.barrels.json.hbs +0 -9
- package/templates/init/.gitignore.hbs +0 -57
- package/templates/init/.npmrc.hbs +0 -2
- package/templates/init/docker/_partials/docker-body.hbs +0 -5
- package/templates/init/docker/_partials/docker-dev-tools.hbs +0 -2
- package/templates/init/docker/_partials/docker-header.hbs +0 -16
- package/templates/init/docker/bun/Dockerfile.hbs +0 -36
- package/templates/init/docker/npm/Dockerfile.hbs +0 -28
- package/templates/init/docker/pnpm/Dockerfile.hbs +0 -28
- package/templates/init/docker/yarn/Dockerfile.hbs +0 -28
- package/templates/init/docker/yarn_berry/Dockerfile.hbs +0 -31
- package/templates/init/docker-compose.yml.hbs +0 -14
- package/templates/init/pm2/bun/processes.config.cjs.hbs +0 -23
- package/templates/init/pm2/node-compiled/processes.config.cjs.hbs +0 -22
- package/templates/init/pm2/node-loader/processes.config.cjs.hbs +0 -24
- package/templates/init/src/bin/index.ts.hbs +0 -9
- package/templates/init/src/config/envs/index.ts.hbs +0 -7
- package/templates/init/src/config/index.ts.hbs +0 -38
- package/templates/init/src/config/logger/index.ts.hbs +0 -25
- package/templates/init/tsconfig.json.hbs +0 -16
- package/templates/init/tsconfig.node.json.hbs +0 -20
- package/templates/init/tsconfig.spec.json.hbs +0 -25
- package/templates/init/webpack.config.js.hbs +0 -65
- /package/lib/esm/{commands/init/interfaces/InitCmdContext.js → interfaces/AlterGenerateTasks.js} +0 -0
- /package/lib/{types/utils/hbs/index.d.ts → esm/interfaces/AlterInitSubTasks.js} +0 -0
- /package/templates/{init/.babelrc.hbs → .babelrc} +0 -0
- /package/templates/{init/.dockerignore.hbs → .dockerignore} +0 -0
- /package/templates/{init/.swcrc.hbs → .swcrc} +0 -0
- /package/templates/{init/.yarnrc.hbs → .yarnrc} +0 -0
- /package/templates/{init/nodemon.json.hbs → nodemon.json} +0 -0
- /package/templates/{init/tsconfig.base.json.hbs → tsconfig.base.json} +0 -0
- /package/templates/{init/views/swagger.ejs.hbs → views/swagger.ejs} +0 -0
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
import { __decorate } from "tslib";
|
|
2
|
-
import "../utils/hbs/index.js";
|
|
3
|
-
import { basename, dirname, join, relative } from "node:path";
|
|
4
|
-
import { CliFs } from "@tsed/cli-core";
|
|
5
|
-
import { isString } from "@tsed/core";
|
|
6
|
-
import { constant, inject, Injectable } from "@tsed/di";
|
|
7
|
-
import { normalizePath } from "@tsed/normalize-path";
|
|
8
|
-
import Consolidate from "consolidate";
|
|
9
|
-
import fs from "fs-extra";
|
|
10
|
-
import { globby } from "globby";
|
|
11
|
-
import handlebars from "handlebars";
|
|
12
|
-
import { Observable } from "rxjs";
|
|
13
|
-
import { insertAfter } from "../utils/renderer/insertAfter.js";
|
|
14
|
-
import { insertImport } from "../utils/renderer/insertImport.js";
|
|
15
|
-
export class Renderer {
|
|
16
|
-
constructor() {
|
|
17
|
-
this.templateDir = constant("templateDir", "");
|
|
18
|
-
this.fs = inject(CliFs);
|
|
19
|
-
this.cache = new Set();
|
|
20
|
-
}
|
|
21
|
-
async loadPartials(cwd) {
|
|
22
|
-
if (this.cache.has(cwd)) {
|
|
23
|
-
return;
|
|
24
|
-
}
|
|
25
|
-
const files = await globby("**/_partials/*.hbs", {
|
|
26
|
-
cwd
|
|
27
|
-
});
|
|
28
|
-
files.forEach((filename) => {
|
|
29
|
-
let template = this.fs.readFileSync(join(cwd, filename), "utf8");
|
|
30
|
-
const name = basename(filename).replace(".hbs", "");
|
|
31
|
-
handlebars.registerPartial(name, template);
|
|
32
|
-
});
|
|
33
|
-
this.cache.add(cwd);
|
|
34
|
-
}
|
|
35
|
-
async render(path, data, options = {}) {
|
|
36
|
-
const { output, templateDir, rootDir } = this.mapOptions(path, options);
|
|
37
|
-
let content = "";
|
|
38
|
-
const file = normalizePath(join(templateDir, path));
|
|
39
|
-
options.baseDir && (await this.loadPartials(join(templateDir, options.baseDir)));
|
|
40
|
-
if (path.endsWith(".hbs")) {
|
|
41
|
-
content = await Consolidate.handlebars(file, data);
|
|
42
|
-
}
|
|
43
|
-
else {
|
|
44
|
-
content = await this.fs.readFile(file, { encoding: "utf8" });
|
|
45
|
-
}
|
|
46
|
-
return this.write(content, { output, rootDir });
|
|
47
|
-
}
|
|
48
|
-
renderAll(paths, data, options = {}) {
|
|
49
|
-
let count = 0;
|
|
50
|
-
const mapOptions = (opts) => {
|
|
51
|
-
if (isString(opts)) {
|
|
52
|
-
return { ...options, path: opts };
|
|
53
|
-
}
|
|
54
|
-
return {
|
|
55
|
-
...options,
|
|
56
|
-
...opts
|
|
57
|
-
};
|
|
58
|
-
};
|
|
59
|
-
return new Observable((observer) => {
|
|
60
|
-
observer.next(`[${count}/${paths.length}] Rendering files...`);
|
|
61
|
-
const promises = paths
|
|
62
|
-
.filter(Boolean)
|
|
63
|
-
.map(mapOptions)
|
|
64
|
-
.map(async ({ path, ...opts }) => {
|
|
65
|
-
await this.render(path, data, opts);
|
|
66
|
-
count++;
|
|
67
|
-
observer.next(`[${count}/${paths.length}] Rendering files...`);
|
|
68
|
-
});
|
|
69
|
-
Promise.all(promises)
|
|
70
|
-
.then(() => {
|
|
71
|
-
observer.next(`[${count}/${paths.length}] Rendering files...`);
|
|
72
|
-
observer.complete();
|
|
73
|
-
})
|
|
74
|
-
.catch((err) => {
|
|
75
|
-
observer.error(err);
|
|
76
|
-
});
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
async write(content, options) {
|
|
80
|
-
const { output, rootDir = this.rootDir } = options;
|
|
81
|
-
const outputFile = join(...[rootDir, output].filter(Boolean));
|
|
82
|
-
await this.fs.ensureDir(dirname(outputFile));
|
|
83
|
-
return this.fs.writeFile(outputFile, content, { encoding: "utf8" });
|
|
84
|
-
}
|
|
85
|
-
templateExists(path, options = {}) {
|
|
86
|
-
const { templateDir } = this.mapOptions(path, options);
|
|
87
|
-
return fs.existsSync(join(templateDir, path));
|
|
88
|
-
}
|
|
89
|
-
async scan(pattern, options = {}) {
|
|
90
|
-
const result = await globby(pattern.map((s) => normalizePath(s)), {
|
|
91
|
-
...options,
|
|
92
|
-
objectMode: true,
|
|
93
|
-
cwd: this.rootDir
|
|
94
|
-
});
|
|
95
|
-
return result.map((entry) => entry.path);
|
|
96
|
-
}
|
|
97
|
-
relativeFrom(path) {
|
|
98
|
-
return relative(dirname(join(this.rootDir, path)), this.rootDir);
|
|
99
|
-
}
|
|
100
|
-
async update(path, actions) {
|
|
101
|
-
path = join(this.rootDir, path);
|
|
102
|
-
if (!this.fs.exists(path)) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
const content = actions.reduce((fileContent, action) => {
|
|
106
|
-
switch (action.type) {
|
|
107
|
-
case "import":
|
|
108
|
-
return insertImport(fileContent, action.content);
|
|
109
|
-
case "insert-after":
|
|
110
|
-
return insertAfter(fileContent, action.content, action.pattern);
|
|
111
|
-
default:
|
|
112
|
-
break;
|
|
113
|
-
}
|
|
114
|
-
return fileContent;
|
|
115
|
-
}, await this.fs.readFile(path, { encoding: "utf8" }));
|
|
116
|
-
return this.fs.writeFile(path, content, { encoding: "utf8" });
|
|
117
|
-
}
|
|
118
|
-
mapOptions(path, options) {
|
|
119
|
-
const { templateDir = this.templateDir, rootDir = this.rootDir } = options;
|
|
120
|
-
let { output = path } = options;
|
|
121
|
-
if (options.baseDir) {
|
|
122
|
-
output = normalizePath(join("/", relative(options.baseDir, path)));
|
|
123
|
-
}
|
|
124
|
-
if (options.basename) {
|
|
125
|
-
output = normalizePath(join(dirname(output), options.basename));
|
|
126
|
-
}
|
|
127
|
-
output = output.replace(/\.hbs$/, "");
|
|
128
|
-
if (options.replaces) {
|
|
129
|
-
options.replaces.filter(Boolean).forEach((replace) => {
|
|
130
|
-
output = output.replace(replace, "");
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
return { output, templateDir, rootDir };
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
let RootRendererService = class RootRendererService extends Renderer {
|
|
137
|
-
get rootDir() {
|
|
138
|
-
return constant("project.rootDir", "");
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
RootRendererService = __decorate([
|
|
142
|
-
Injectable()
|
|
143
|
-
], RootRendererService);
|
|
144
|
-
export { RootRendererService };
|
|
145
|
-
let SrcRendererService = class SrcRendererService extends Renderer {
|
|
146
|
-
get rootDir() {
|
|
147
|
-
return join(...[constant("project.rootDir"), constant("project.srcDir")].filter(Boolean));
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
SrcRendererService = __decorate([
|
|
151
|
-
Injectable()
|
|
152
|
-
], SrcRendererService);
|
|
153
|
-
export { SrcRendererService };
|
|
154
|
-
let ScriptsRendererService = class ScriptsRendererService extends Renderer {
|
|
155
|
-
get rootDir() {
|
|
156
|
-
return join(...[constant("project.rootDir"), constant("project.scriptsDir")].filter(Boolean));
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
ScriptsRendererService = __decorate([
|
|
160
|
-
Injectable()
|
|
161
|
-
], ScriptsRendererService);
|
|
162
|
-
export { ScriptsRendererService };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ArchitectureConvention, PlatformType } from "../interfaces/index.js";
|
|
2
|
-
export function fillImports(ctx) {
|
|
3
|
-
ctx = { ...ctx };
|
|
4
|
-
Object.values(PlatformType).forEach((type) => {
|
|
5
|
-
ctx[type] = ctx.platform === type;
|
|
6
|
-
});
|
|
7
|
-
const isFeature = ctx.architecture === ArchitectureConvention.FEATURE;
|
|
8
|
-
ctx.barrels = JSON.stringify([
|
|
9
|
-
isFeature ? "./src/rest" : "./src/controllers/rest",
|
|
10
|
-
ctx.swagger && (isFeature ? "./src/pages" : "./src/controllers/pages"),
|
|
11
|
-
ctx.oidc && "./src/interactions",
|
|
12
|
-
ctx.graphql && "./src/datasources",
|
|
13
|
-
ctx.graphql && "./src/resolvers"
|
|
14
|
-
].filter(Boolean));
|
|
15
|
-
ctx.imports = [
|
|
16
|
-
{ from: "@tsed/platform-log-request", comment: " // remove this import if you don't want log request" },
|
|
17
|
-
ctx.express && { from: "@tsed/platform-express", comment: " // /!\\ keep this import" },
|
|
18
|
-
ctx.koa && { from: "@tsed/platform-koa", comment: " // /!\\ keep this import" },
|
|
19
|
-
ctx.fastify && { from: "@tsed/platform-fastify", comment: " // /!\\ keep this import" },
|
|
20
|
-
{ from: "@tsed/ajv" },
|
|
21
|
-
ctx.swagger && { from: "@tsed/swagger" },
|
|
22
|
-
ctx.scalar && { from: "@tsed/scalar" },
|
|
23
|
-
ctx.mongoose && { from: "@tsed/mongoose" },
|
|
24
|
-
ctx.oidc && { from: "@tsed/oidc-provider" },
|
|
25
|
-
ctx.passportjs && { from: "@tsed/passport" },
|
|
26
|
-
ctx.graphql && { from: "@tsed/typegraphql" },
|
|
27
|
-
ctx.graphql && { from: "./datasources/index.js" },
|
|
28
|
-
ctx.graphql && { from: "./resolvers/index.js" },
|
|
29
|
-
{ symbols: "{config}", from: "./config/index.js" },
|
|
30
|
-
{ symbols: "* as rest", from: isFeature ? "./rest/index.js" : "./controllers/rest/index.js" },
|
|
31
|
-
(ctx.swagger || ctx.oidc) && {
|
|
32
|
-
symbols: "* as pages",
|
|
33
|
-
from: isFeature ? "./pages/index.js" : "./controllers/pages/index.js"
|
|
34
|
-
},
|
|
35
|
-
ctx.oidc && { symbols: "{InteractionsController}", from: "./controllers/oidc/InteractionsController.js" }
|
|
36
|
-
].filter(Boolean);
|
|
37
|
-
return ctx;
|
|
38
|
-
}
|
|
@@ -1,515 +0,0 @@
|
|
|
1
|
-
import { getValue, isArray, isNumber, isObject, isString } from "@tsed/core";
|
|
2
|
-
// @ts-ignore
|
|
3
|
-
import createFrame from "create-frame";
|
|
4
|
-
// @ts-ignore
|
|
5
|
-
import util from "handlebars-utils";
|
|
6
|
-
export const helpers = {};
|
|
7
|
-
/**
|
|
8
|
-
* Returns all of the items in an array after the specified index.
|
|
9
|
-
* Opposite of [before](#before).
|
|
10
|
-
*
|
|
11
|
-
* ```handlebars
|
|
12
|
-
* <!-- array: ['a', 'b', 'c'] -->
|
|
13
|
-
* {{after array 1}}
|
|
14
|
-
* <!-- results in: '["c"]' -->
|
|
15
|
-
* ```
|
|
16
|
-
* @param {Array} `array` Collection
|
|
17
|
-
* @param {Number} `n` Starting index (number of items to exclude)
|
|
18
|
-
* @return {Array} Array exluding `n` items.
|
|
19
|
-
* @api public
|
|
20
|
-
*/
|
|
21
|
-
helpers.after = function (array, n) {
|
|
22
|
-
if (util.isUndefined(array))
|
|
23
|
-
return "";
|
|
24
|
-
return array.slice(n);
|
|
25
|
-
};
|
|
26
|
-
/**
|
|
27
|
-
* Cast the given `value` to an array.
|
|
28
|
-
*
|
|
29
|
-
* ```handlebars
|
|
30
|
-
* {{arrayify "foo"}}
|
|
31
|
-
* <!-- results in: [ "foo" ] -->
|
|
32
|
-
* ```
|
|
33
|
-
* @param {any} `value`
|
|
34
|
-
* @return {Array}
|
|
35
|
-
* @api public
|
|
36
|
-
*/
|
|
37
|
-
helpers.arrayify = function (value) {
|
|
38
|
-
return value ? (isArray(value) ? value : [value]) : [];
|
|
39
|
-
};
|
|
40
|
-
/**
|
|
41
|
-
* Return all of the items in the collection before the specified
|
|
42
|
-
* count. Opposite of [after](#after).
|
|
43
|
-
*
|
|
44
|
-
* ```handlebars
|
|
45
|
-
* <!-- array: ['a', 'b', 'c'] -->
|
|
46
|
-
* {{before array 2}}
|
|
47
|
-
* <!-- results in: '["a", "b"]' -->
|
|
48
|
-
* ```
|
|
49
|
-
* @param {Array} `array`
|
|
50
|
-
* @param {Number} `n`
|
|
51
|
-
* @return {Array} Array excluding items after the given number.
|
|
52
|
-
* @api public
|
|
53
|
-
*/
|
|
54
|
-
helpers.before = function (array, n) {
|
|
55
|
-
if (util.isUndefined(array))
|
|
56
|
-
return "";
|
|
57
|
-
return array.slice(0, -n);
|
|
58
|
-
};
|
|
59
|
-
/**
|
|
60
|
-
* ```handlebars
|
|
61
|
-
* <!-- array: ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h'] -->
|
|
62
|
-
* {{#eachIndex array}}
|
|
63
|
-
* {{item}} is {{index}}
|
|
64
|
-
* {{/eachIndex}}
|
|
65
|
-
* ```
|
|
66
|
-
* @param {Array} `array`
|
|
67
|
-
* @param {Object} `options`
|
|
68
|
-
* @return {String}
|
|
69
|
-
* @block
|
|
70
|
-
* @api public
|
|
71
|
-
*/
|
|
72
|
-
helpers.eachIndex = function (array, options) {
|
|
73
|
-
let result = "";
|
|
74
|
-
for (let i = 0; i < array.length; i++) {
|
|
75
|
-
result += options.fn({ item: array[i], index: i });
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
};
|
|
79
|
-
/**
|
|
80
|
-
* Block helper that filters the given array and renders the block for values that
|
|
81
|
-
* evaluate to `true`, otherwise the inverse block is returned.
|
|
82
|
-
*
|
|
83
|
-
* ```handlebars
|
|
84
|
-
* <!-- array: ['a', 'b', 'c'] -->
|
|
85
|
-
* {{#filter array "foo"}}AAA{{else}}BBB{{/filter}}
|
|
86
|
-
* <!-- results in: 'BBB' -->
|
|
87
|
-
* ```
|
|
88
|
-
* @param {Array} `array`
|
|
89
|
-
* @param {any} `value`
|
|
90
|
-
* @param {Object} `options`
|
|
91
|
-
* @return {String}
|
|
92
|
-
* @block
|
|
93
|
-
* @api public
|
|
94
|
-
*/
|
|
95
|
-
helpers.filter = function (array, value, options) {
|
|
96
|
-
let content = "";
|
|
97
|
-
let results = [];
|
|
98
|
-
// filter on a specific property
|
|
99
|
-
const prop = options.hash && (options.hash.property || options.hash.prop);
|
|
100
|
-
if (prop) {
|
|
101
|
-
results = array.filter(function (val) {
|
|
102
|
-
return value === getValue(val, prop);
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
else {
|
|
106
|
-
// filter on a string value
|
|
107
|
-
results = array.filter(function (v) {
|
|
108
|
-
return value === v;
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
if (results && results.length > 0) {
|
|
112
|
-
for (let i = 0; i < results.length; i++) {
|
|
113
|
-
content += options.fn(results[i]);
|
|
114
|
-
}
|
|
115
|
-
return content;
|
|
116
|
-
}
|
|
117
|
-
return options.inverse(this);
|
|
118
|
-
};
|
|
119
|
-
/**
|
|
120
|
-
* Returns the first item, or first `n` items of an array.
|
|
121
|
-
*
|
|
122
|
-
* ```handlebars
|
|
123
|
-
* {{first "['a', 'b', 'c', 'd', 'e']" 2}}
|
|
124
|
-
* <!-- results in: '["a", "b"]' -->
|
|
125
|
-
* ```
|
|
126
|
-
* @param {Array} `array`
|
|
127
|
-
* @param {Number} `n` Number of items to return, starting at `0`.
|
|
128
|
-
* @return {Array}
|
|
129
|
-
* @api public
|
|
130
|
-
*/
|
|
131
|
-
helpers.first = function (array, n) {
|
|
132
|
-
if (array === undefined)
|
|
133
|
-
return "";
|
|
134
|
-
if (!isNumber(n)) {
|
|
135
|
-
return array[0];
|
|
136
|
-
}
|
|
137
|
-
return array.slice(0, n);
|
|
138
|
-
};
|
|
139
|
-
/**
|
|
140
|
-
* Iterates over each item in an array and exposes the current item
|
|
141
|
-
* in the array as context to the inner block. In addition to
|
|
142
|
-
* the current array item, the helper exposes the following variables
|
|
143
|
-
* to the inner block:
|
|
144
|
-
*
|
|
145
|
-
* - `index`
|
|
146
|
-
* - `total`
|
|
147
|
-
* - `isFirst`
|
|
148
|
-
* - `isLast`
|
|
149
|
-
*
|
|
150
|
-
* Also, `@index` is exposed as a private variable, and additional
|
|
151
|
-
* private variables may be defined as hash arguments.
|
|
152
|
-
*
|
|
153
|
-
* ```handlebars
|
|
154
|
-
* <!-- accounts = [
|
|
155
|
-
* {'name': 'John', 'email': 'john@example.com'},
|
|
156
|
-
* {'name': 'Malcolm', 'email': 'malcolm@example.com'},
|
|
157
|
-
* {'name': 'David', 'email': 'david@example.com'}
|
|
158
|
-
* ] -->
|
|
159
|
-
*
|
|
160
|
-
* {{#forEach accounts}}
|
|
161
|
-
* <a href="mailto:{{ email }}" title="Send an email to {{ name }}">
|
|
162
|
-
* {{ name }}
|
|
163
|
-
* </a>{{#unless isLast}}, {{/unless}}
|
|
164
|
-
* {{/forEach}}
|
|
165
|
-
* ```
|
|
166
|
-
* @source <http://stackoverflow.com/questions/13861007>
|
|
167
|
-
* @param {Array} `array`
|
|
168
|
-
* @return {String}
|
|
169
|
-
* @block
|
|
170
|
-
* @api public
|
|
171
|
-
*/
|
|
172
|
-
helpers.forEach = function (array, options) {
|
|
173
|
-
const data = createFrame(options, options.hash);
|
|
174
|
-
const len = array.length;
|
|
175
|
-
let buffer = "";
|
|
176
|
-
let i = -1;
|
|
177
|
-
while (++i < len) {
|
|
178
|
-
const item = array[i];
|
|
179
|
-
data.index = i;
|
|
180
|
-
item.index = i + 1;
|
|
181
|
-
item.total = len;
|
|
182
|
-
item.isFirst = i === 0;
|
|
183
|
-
item.isLast = i === len - 1;
|
|
184
|
-
buffer += options.fn(item, { data: data });
|
|
185
|
-
}
|
|
186
|
-
return buffer;
|
|
187
|
-
};
|
|
188
|
-
/**
|
|
189
|
-
* Block helper that renders the block if an array has the
|
|
190
|
-
* given `value`. Optionally specify an inverse block to render
|
|
191
|
-
* when the array does not have the given value.
|
|
192
|
-
*
|
|
193
|
-
* ```handlebars
|
|
194
|
-
* <!-- array: ['a', 'b', 'c'] -->
|
|
195
|
-
* {{#inArray array "d"}}
|
|
196
|
-
* foo
|
|
197
|
-
* {{else}}
|
|
198
|
-
* bar
|
|
199
|
-
* {{/inArray}}
|
|
200
|
-
* <!-- results in: 'bar' -->
|
|
201
|
-
* ```
|
|
202
|
-
* @param {Array} `array`
|
|
203
|
-
* @param {any} `value`
|
|
204
|
-
* @param {Object} `options`
|
|
205
|
-
* @return {String}
|
|
206
|
-
* @block
|
|
207
|
-
* @api public
|
|
208
|
-
*/
|
|
209
|
-
helpers.inArray = function (array, value, options) {
|
|
210
|
-
return util.value(util.indexOf(array, value) > -1, this, options);
|
|
211
|
-
};
|
|
212
|
-
/**
|
|
213
|
-
* Returns true if `value` is an es5 array.
|
|
214
|
-
*
|
|
215
|
-
* ```handlebars
|
|
216
|
-
* {{isArray "abc"}}
|
|
217
|
-
* <!-- results in: false -->
|
|
218
|
-
*
|
|
219
|
-
* <!-- array: [1, 2, 3] -->
|
|
220
|
-
* {{isArray array}}
|
|
221
|
-
* <!-- results in: true -->
|
|
222
|
-
* ```
|
|
223
|
-
* @param {any} `value` The value to test.
|
|
224
|
-
* @return {Boolean}
|
|
225
|
-
* @api public
|
|
226
|
-
*/
|
|
227
|
-
helpers.isArray = function (value) {
|
|
228
|
-
return Array.isArray(value);
|
|
229
|
-
};
|
|
230
|
-
/**
|
|
231
|
-
* Returns the item from `array` at index `idx`.
|
|
232
|
-
*
|
|
233
|
-
* ```handlebars
|
|
234
|
-
* <!-- array: ['a', 'b', 'c'] -->
|
|
235
|
-
* {{itemAt array 1}}
|
|
236
|
-
* <!-- results in: 'b' -->
|
|
237
|
-
* ```
|
|
238
|
-
* @param {Array} `array`
|
|
239
|
-
* @param {Number} `idx`
|
|
240
|
-
* @return {any} `value`
|
|
241
|
-
* @block
|
|
242
|
-
* @api public
|
|
243
|
-
*/
|
|
244
|
-
helpers.itemAt = function (array, idx) {
|
|
245
|
-
array = util.result(array);
|
|
246
|
-
if (isArray(array)) {
|
|
247
|
-
idx = isNumber(idx) ? +idx : 0;
|
|
248
|
-
if (idx < 0) {
|
|
249
|
-
return array[array.length + idx];
|
|
250
|
-
}
|
|
251
|
-
if (idx < array.length) {
|
|
252
|
-
return array[idx];
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
/**
|
|
257
|
-
* Join all elements of array into a string, optionally using a
|
|
258
|
-
* given separator.
|
|
259
|
-
*
|
|
260
|
-
* ```handlebars
|
|
261
|
-
* <!-- array: ['a', 'b', 'c'] -->
|
|
262
|
-
* {{join array}}
|
|
263
|
-
* <!-- results in: 'a, b, c' -->
|
|
264
|
-
*
|
|
265
|
-
* {{join array '-'}}
|
|
266
|
-
* <!-- results in: 'a-b-c' -->
|
|
267
|
-
* ```
|
|
268
|
-
* @param {Array} `array`
|
|
269
|
-
* @param {String} `separator` The separator to use. Defaults to `, `.
|
|
270
|
-
* @return {String}
|
|
271
|
-
* @api public
|
|
272
|
-
*/
|
|
273
|
-
helpers.join = function (array, separator) {
|
|
274
|
-
if (isString(array))
|
|
275
|
-
return array;
|
|
276
|
-
if (!isArray(array))
|
|
277
|
-
return "";
|
|
278
|
-
separator = util.isString(separator) ? separator : ", ";
|
|
279
|
-
return array.join(separator);
|
|
280
|
-
};
|
|
281
|
-
/**
|
|
282
|
-
* Returns true if the the length of the given `value` is equal
|
|
283
|
-
* to the given `length`. Can be used as a block or inline helper.
|
|
284
|
-
*
|
|
285
|
-
* @param {Array|String} `value`
|
|
286
|
-
* @param {Number} `length`
|
|
287
|
-
* @param {Object} `options`
|
|
288
|
-
* @return {String}
|
|
289
|
-
* @block
|
|
290
|
-
* @api public
|
|
291
|
-
*/
|
|
292
|
-
helpers.equalsLength = function (value, length, options) {
|
|
293
|
-
if (util.isOptions(length)) {
|
|
294
|
-
options = length;
|
|
295
|
-
length = 0;
|
|
296
|
-
}
|
|
297
|
-
let len = 0;
|
|
298
|
-
if (typeof value === "string" || Array.isArray(value)) {
|
|
299
|
-
len = value.length;
|
|
300
|
-
}
|
|
301
|
-
return util.value(len === length, this, options);
|
|
302
|
-
};
|
|
303
|
-
/**
|
|
304
|
-
* Returns the last item, or last `n` items of an array or string.
|
|
305
|
-
* Opposite of [first](#first).
|
|
306
|
-
*
|
|
307
|
-
* ```handlebars
|
|
308
|
-
* <!-- var value = ['a', 'b', 'c', 'd', 'e'] -->
|
|
309
|
-
*
|
|
310
|
-
* {{last value}}
|
|
311
|
-
* <!-- results in: ['e'] -->
|
|
312
|
-
*
|
|
313
|
-
* {{last value 2}}
|
|
314
|
-
* <!-- results in: ['d', 'e'] -->
|
|
315
|
-
*
|
|
316
|
-
* {{last value 3}}
|
|
317
|
-
* <!-- results in: ['c', 'd', 'e'] -->
|
|
318
|
-
* ```
|
|
319
|
-
* @param {Array|String} `value` Array or string.
|
|
320
|
-
* @param {Number} `n` Number of items to return from the end of the array.
|
|
321
|
-
* @return {Array}
|
|
322
|
-
* @api public
|
|
323
|
-
*/
|
|
324
|
-
helpers.last = function (value, n) {
|
|
325
|
-
if (!isArray(value) && typeof value !== "string") {
|
|
326
|
-
return "";
|
|
327
|
-
}
|
|
328
|
-
if (!isNumber(n)) {
|
|
329
|
-
return value[value.length - 1];
|
|
330
|
-
}
|
|
331
|
-
return value.slice(-Math.abs(n));
|
|
332
|
-
};
|
|
333
|
-
/**
|
|
334
|
-
* Returns the length of the given string or array.
|
|
335
|
-
*
|
|
336
|
-
* ```handlebars
|
|
337
|
-
* {{length '["a", "b", "c"]'}}
|
|
338
|
-
* <!-- results in: 3 -->
|
|
339
|
-
*
|
|
340
|
-
* <!-- results in: myArray = ['a', 'b', 'c', 'd', 'e']; -->
|
|
341
|
-
* {{length myArray}}
|
|
342
|
-
* <!-- results in: 5 -->
|
|
343
|
-
*
|
|
344
|
-
* <!-- results in: myObject = {'a': 'a', 'b': 'b'}; -->
|
|
345
|
-
* {{length myObject}}
|
|
346
|
-
* <!-- results in: 2 -->
|
|
347
|
-
* ```
|
|
348
|
-
* @param {Array|Object|String} `value`
|
|
349
|
-
* @return {Number} The length of the value.
|
|
350
|
-
* @api public
|
|
351
|
-
*/
|
|
352
|
-
helpers.length = function (value) {
|
|
353
|
-
if (isObject(value) && !util.isOptions(value)) {
|
|
354
|
-
value = Object.keys(value);
|
|
355
|
-
}
|
|
356
|
-
if (typeof value === "string" || Array.isArray(value)) {
|
|
357
|
-
return value.length;
|
|
358
|
-
}
|
|
359
|
-
return 0;
|
|
360
|
-
};
|
|
361
|
-
/**
|
|
362
|
-
* Returns a new array, created by calling `function` on each
|
|
363
|
-
* element of the given `array`. For example,
|
|
364
|
-
*
|
|
365
|
-
* ```handlebars
|
|
366
|
-
* <!-- array: ['a', 'b', 'c'], and "double" is a
|
|
367
|
-
* fictitious function that duplicates letters -->
|
|
368
|
-
* {{map array double}}
|
|
369
|
-
* <!-- results in: '["aa", "bb", "cc"]' -->
|
|
370
|
-
* ```
|
|
371
|
-
*
|
|
372
|
-
* @param {Array} `array`
|
|
373
|
-
* @param {Function} `fn`
|
|
374
|
-
* @return {String}
|
|
375
|
-
* @api public
|
|
376
|
-
*/
|
|
377
|
-
helpers.map = function (array, iter) {
|
|
378
|
-
if (!Array.isArray(array))
|
|
379
|
-
return "";
|
|
380
|
-
const len = array.length;
|
|
381
|
-
const res = new Array(len);
|
|
382
|
-
let i = -1;
|
|
383
|
-
if (typeof iter !== "function") {
|
|
384
|
-
return array;
|
|
385
|
-
}
|
|
386
|
-
while (++i < len) {
|
|
387
|
-
res[i] = iter(array[i], i, array);
|
|
388
|
-
}
|
|
389
|
-
return res;
|
|
390
|
-
};
|
|
391
|
-
/**
|
|
392
|
-
* Map over the given object or array or objects and create an array of values
|
|
393
|
-
* from the given `prop`. Dot-notation may be used (as a string) to get
|
|
394
|
-
* nested properties.
|
|
395
|
-
*
|
|
396
|
-
* ```handlebars
|
|
397
|
-
* // {{pluck items "data.title"}}
|
|
398
|
-
* <!-- results in: '["aa", "bb", "cc"]' -->
|
|
399
|
-
* ```
|
|
400
|
-
* @param {Array|Object} `collection`
|
|
401
|
-
* @param {Function} `prop`
|
|
402
|
-
* @return {String}
|
|
403
|
-
* @api public
|
|
404
|
-
*/
|
|
405
|
-
helpers.pluck = function (arr, prop) {
|
|
406
|
-
if (util.isUndefined(arr))
|
|
407
|
-
return "";
|
|
408
|
-
const res = [];
|
|
409
|
-
for (let i = 0; i < arr.length; i++) {
|
|
410
|
-
const val = getValue(arr[i], prop);
|
|
411
|
-
if (typeof val !== "undefined") {
|
|
412
|
-
res.push(val);
|
|
413
|
-
}
|
|
414
|
-
}
|
|
415
|
-
return res;
|
|
416
|
-
};
|
|
417
|
-
/**
|
|
418
|
-
* Reverse the elements in an array, or the characters in a string.
|
|
419
|
-
*
|
|
420
|
-
* ```handlebars
|
|
421
|
-
* <!-- value: 'abcd' -->
|
|
422
|
-
* {{reverse value}}
|
|
423
|
-
* <!-- results in: 'dcba' -->
|
|
424
|
-
* <!-- value: ['a', 'b', 'c', 'd'] -->
|
|
425
|
-
* {{reverse value}}
|
|
426
|
-
* <!-- results in: ['d', 'c', 'b', 'a'] -->
|
|
427
|
-
* ```
|
|
428
|
-
* @param {Array|String} `value`
|
|
429
|
-
* @return {Array|String} Returns the reversed string or array.
|
|
430
|
-
* @api public
|
|
431
|
-
*/
|
|
432
|
-
helpers.reverse = function (val) {
|
|
433
|
-
if (Array.isArray(val)) {
|
|
434
|
-
val.reverse();
|
|
435
|
-
return val;
|
|
436
|
-
}
|
|
437
|
-
if (val && isString(val)) {
|
|
438
|
-
return val.split("").reverse().join("");
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
/**
|
|
442
|
-
* Block helper that returns the block if the callback returns true
|
|
443
|
-
* for some value in the given array.
|
|
444
|
-
*
|
|
445
|
-
* ```handlebars
|
|
446
|
-
* <!-- array: [1, 'b', 3] -->
|
|
447
|
-
* {{#some array isString}}
|
|
448
|
-
* Render me if the array has a string.
|
|
449
|
-
* {{else}}
|
|
450
|
-
* Render me if it doesn't.
|
|
451
|
-
* {{/some}}
|
|
452
|
-
* <!-- results in: 'Render me if the array has a string.' -->
|
|
453
|
-
* ```
|
|
454
|
-
* @param {Array} `array`
|
|
455
|
-
* @param {Function} `iter` Iteratee
|
|
456
|
-
* @param {Options} Handlebars provided options object
|
|
457
|
-
* @return {String}
|
|
458
|
-
* @block
|
|
459
|
-
* @api public
|
|
460
|
-
*/
|
|
461
|
-
helpers.some = function (array, iter, options) {
|
|
462
|
-
if (Array.isArray(array)) {
|
|
463
|
-
for (let i = 0; i < array.length; i++) {
|
|
464
|
-
if (iter(array[i], i, array)) {
|
|
465
|
-
return options.fn(this);
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
return options.inverse(this);
|
|
470
|
-
};
|
|
471
|
-
/**
|
|
472
|
-
* Sort the given `array`. If an array of objects is passed,
|
|
473
|
-
* you may optionally pass a `key` to sort on as the second
|
|
474
|
-
* argument. You may alternatively pass a sorting function as
|
|
475
|
-
* the second argument.
|
|
476
|
-
*
|
|
477
|
-
* ```handlebars
|
|
478
|
-
* <!-- array: ['b', 'a', 'c'] -->
|
|
479
|
-
* {{sort array}}
|
|
480
|
-
* <!-- results in: '["a", "b", "c"]' -->
|
|
481
|
-
* ```
|
|
482
|
-
*
|
|
483
|
-
* @param {Array} `array` the array to sort.
|
|
484
|
-
* @param {String|Function} `key` The object key to sort by, or sorting function.
|
|
485
|
-
* @api public
|
|
486
|
-
*/
|
|
487
|
-
helpers.sort = function (array, options) {
|
|
488
|
-
if (!Array.isArray(array))
|
|
489
|
-
return "";
|
|
490
|
-
if (getValue(options, "hash.reverse")) {
|
|
491
|
-
return array.sort().reverse();
|
|
492
|
-
}
|
|
493
|
-
return array.sort();
|
|
494
|
-
};
|
|
495
|
-
/**
|
|
496
|
-
* Block helper that return an array with all duplicate
|
|
497
|
-
* values removed. Best used along with a [each](#each) helper.
|
|
498
|
-
*
|
|
499
|
-
* ```handlebars
|
|
500
|
-
* <!-- array: ['a', 'a', 'c', 'b', 'e', 'e'] -->
|
|
501
|
-
* {{#each (unique array)}}{{.}}{{/each}}
|
|
502
|
-
* <!-- results in: 'acbe' -->
|
|
503
|
-
* ```
|
|
504
|
-
* @param {Array} `array`
|
|
505
|
-
* @param {Object} `options`
|
|
506
|
-
* @return {Array}
|
|
507
|
-
* @api public
|
|
508
|
-
*/
|
|
509
|
-
helpers.unique = function (array) {
|
|
510
|
-
if (util.isUndefined(array))
|
|
511
|
-
return "";
|
|
512
|
-
return array.filter(function (item, index, arr) {
|
|
513
|
-
return arr.indexOf(item) === index;
|
|
514
|
-
});
|
|
515
|
-
};
|