@feathersjs/generators 5.0.13 → 5.0.15
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/CHANGELOG.md +12 -0
- package/lib/app/index.d.ts +19 -27
- package/lib/app/index.js +25 -30
- package/lib/app/index.js.map +1 -1
- package/lib/app/index.ts +17 -8
- package/lib/app/templates/app.test.tpl.d.ts +5 -2
- package/lib/app/templates/app.test.tpl.js +3 -7
- package/lib/app/templates/app.test.tpl.js.map +1 -1
- package/lib/app/templates/app.test.tpl.ts +4 -4
- package/lib/app/templates/app.tpl.d.ts +1 -1
- package/lib/app/templates/app.tpl.js +3 -7
- package/lib/app/templates/app.tpl.js.map +1 -1
- package/lib/app/templates/app.tpl.ts +4 -4
- package/lib/app/templates/channels.tpl.d.ts +1 -1
- package/lib/app/templates/channels.tpl.js +3 -7
- package/lib/app/templates/channels.tpl.js.map +1 -1
- package/lib/app/templates/channels.tpl.ts +4 -4
- package/lib/app/templates/client.test.tpl.d.ts +1 -1
- package/lib/app/templates/client.test.tpl.js +3 -7
- package/lib/app/templates/client.test.tpl.js.map +1 -1
- package/lib/app/templates/client.test.tpl.ts +4 -4
- package/lib/app/templates/client.tpl.d.ts +1 -1
- package/lib/app/templates/client.tpl.js +3 -7
- package/lib/app/templates/client.tpl.js.map +1 -1
- package/lib/app/templates/client.tpl.ts +4 -4
- package/lib/app/templates/configuration.tpl.d.ts +1 -1
- package/lib/app/templates/configuration.tpl.js +7 -11
- package/lib/app/templates/configuration.tpl.js.map +1 -1
- package/lib/app/templates/configuration.tpl.ts +4 -4
- package/lib/app/templates/declarations.tpl.d.ts +1 -1
- package/lib/app/templates/declarations.tpl.js +2 -6
- package/lib/app/templates/declarations.tpl.js.map +1 -1
- package/lib/app/templates/declarations.tpl.ts +3 -3
- package/lib/app/templates/index.html.tpl.d.ts +5 -2
- package/lib/app/templates/index.html.tpl.js +2 -6
- package/lib/app/templates/index.html.tpl.js.map +1 -1
- package/lib/app/templates/index.html.tpl.ts +3 -3
- package/lib/app/templates/index.tpl.d.ts +1 -1
- package/lib/app/templates/index.tpl.js +3 -7
- package/lib/app/templates/index.tpl.js.map +1 -1
- package/lib/app/templates/index.tpl.ts +4 -4
- package/lib/app/templates/logger.tpl.d.ts +1 -1
- package/lib/app/templates/logger.tpl.js +6 -10
- package/lib/app/templates/logger.tpl.js.map +1 -1
- package/lib/app/templates/logger.tpl.ts +4 -4
- package/lib/app/templates/package.json.tpl.d.ts +5 -2
- package/lib/app/templates/package.json.tpl.js +2 -6
- package/lib/app/templates/package.json.tpl.js.map +1 -1
- package/lib/app/templates/package.json.tpl.ts +3 -3
- package/lib/app/templates/prettierrc.tpl.d.ts +1 -1
- package/lib/app/templates/prettierrc.tpl.js +5 -9
- package/lib/app/templates/prettierrc.tpl.js.map +1 -1
- package/lib/app/templates/prettierrc.tpl.ts +4 -4
- package/lib/app/templates/readme.md.tpl.d.ts +5 -2
- package/lib/app/templates/readme.md.tpl.js +2 -6
- package/lib/app/templates/readme.md.tpl.js.map +1 -1
- package/lib/app/templates/readme.md.tpl.ts +3 -3
- package/lib/app/templates/services.tpl.d.ts +1 -1
- package/lib/app/templates/services.tpl.js +3 -7
- package/lib/app/templates/services.tpl.js.map +1 -1
- package/lib/app/templates/services.tpl.ts +4 -4
- package/lib/app/templates/tsconfig.json.tpl.d.ts +1 -1
- package/lib/app/templates/tsconfig.json.tpl.js +3 -7
- package/lib/app/templates/tsconfig.json.tpl.js.map +1 -1
- package/lib/app/templates/tsconfig.json.tpl.ts +3 -3
- package/lib/app/templates/validators.tpl.d.ts +1 -1
- package/lib/app/templates/validators.tpl.js +3 -7
- package/lib/app/templates/validators.tpl.js.map +1 -1
- package/lib/app/templates/validators.tpl.ts +4 -4
- package/lib/authentication/index.d.ts +10 -10
- package/lib/authentication/index.js +16 -19
- package/lib/authentication/index.js.map +1 -1
- package/lib/authentication/index.ts +65 -56
- package/lib/authentication/templates/authentication.tpl.d.ts +1 -1
- package/lib/authentication/templates/authentication.tpl.js +11 -15
- package/lib/authentication/templates/authentication.tpl.js.map +1 -1
- package/lib/authentication/templates/authentication.tpl.ts +5 -5
- package/lib/authentication/templates/client.test.tpl.d.ts +1 -1
- package/lib/authentication/templates/client.test.tpl.js +7 -11
- package/lib/authentication/templates/client.test.tpl.js.map +1 -1
- package/lib/authentication/templates/client.test.tpl.ts +5 -5
- package/lib/authentication/templates/config.tpl.d.ts +1 -1
- package/lib/authentication/templates/config.tpl.js +8 -15
- package/lib/authentication/templates/config.tpl.js.map +1 -1
- package/lib/authentication/templates/config.tpl.ts +3 -3
- package/lib/authentication/templates/declarations.tpl.d.ts +1 -1
- package/lib/authentication/templates/declarations.tpl.js +5 -9
- package/lib/authentication/templates/declarations.tpl.js.map +1 -1
- package/lib/authentication/templates/declarations.tpl.ts +3 -3
- package/lib/commons.d.ts +10 -2
- package/lib/commons.js +43 -76
- package/lib/commons.js.map +1 -1
- package/lib/commons.ts +22 -4
- package/lib/connection/index.d.ts +1 -1
- package/lib/connection/index.js +24 -30
- package/lib/connection/index.js.map +1 -1
- package/lib/connection/index.ts +10 -4
- package/lib/connection/templates/knex.tpl.d.ts +1 -1
- package/lib/connection/templates/knex.tpl.js +13 -20
- package/lib/connection/templates/knex.tpl.js.map +1 -1
- package/lib/connection/templates/knex.tpl.ts +4 -4
- package/lib/connection/templates/mongodb.tpl.d.ts +1 -1
- package/lib/connection/templates/mongodb.tpl.js +10 -14
- package/lib/connection/templates/mongodb.tpl.js.map +1 -1
- package/lib/connection/templates/mongodb.tpl.ts +4 -4
- package/lib/hook/index.d.ts +6 -6
- package/lib/hook/index.js +13 -17
- package/lib/hook/index.js.map +1 -1
- package/lib/hook/index.ts +7 -3
- package/lib/hook/templates/hook.tpl.d.ts +1 -1
- package/lib/hook/templates/hook.tpl.js +3 -7
- package/lib/hook/templates/hook.tpl.js.map +1 -1
- package/lib/hook/templates/hook.tpl.ts +4 -4
- package/lib/index.d.ts +7 -7
- package/lib/index.js +7 -36
- package/lib/index.js.map +1 -1
- package/lib/index.ts +7 -7
- package/lib/service/index.d.ts +1 -1
- package/lib/service/index.js +27 -31
- package/lib/service/index.js.map +1 -1
- package/lib/service/index.ts +94 -92
- package/lib/service/templates/client.tpl.d.ts +1 -1
- package/lib/service/templates/client.tpl.js +4 -8
- package/lib/service/templates/client.tpl.js.map +1 -1
- package/lib/service/templates/client.tpl.ts +4 -4
- package/lib/service/templates/schema.json.tpl.d.ts +1 -1
- package/lib/service/templates/schema.json.tpl.js +10 -14
- package/lib/service/templates/schema.json.tpl.js.map +1 -1
- package/lib/service/templates/schema.json.tpl.ts +4 -4
- package/lib/service/templates/schema.typebox.tpl.d.ts +1 -1
- package/lib/service/templates/schema.typebox.tpl.js +8 -12
- package/lib/service/templates/schema.typebox.tpl.js.map +1 -1
- package/lib/service/templates/schema.typebox.tpl.ts +4 -4
- package/lib/service/templates/service.tpl.d.ts +1 -1
- package/lib/service/templates/service.tpl.js +9 -14
- package/lib/service/templates/service.tpl.js.map +1 -1
- package/lib/service/templates/service.tpl.ts +4 -4
- package/lib/service/templates/shared.tpl.d.ts +1 -1
- package/lib/service/templates/shared.tpl.js +3 -7
- package/lib/service/templates/shared.tpl.js.map +1 -1
- package/lib/service/templates/shared.tpl.ts +4 -4
- package/lib/service/templates/test.tpl.d.ts +1 -1
- package/lib/service/templates/test.tpl.js +3 -7
- package/lib/service/templates/test.tpl.js.map +1 -1
- package/lib/service/templates/test.tpl.ts +4 -4
- package/lib/service/type/custom.tpl.d.ts +1 -1
- package/lib/service/type/custom.tpl.js +4 -9
- package/lib/service/type/custom.tpl.js.map +1 -1
- package/lib/service/type/custom.tpl.ts +4 -4
- package/lib/service/type/knex.tpl.d.ts +1 -1
- package/lib/service/type/knex.tpl.js +6 -11
- package/lib/service/type/knex.tpl.js.map +1 -1
- package/lib/service/type/knex.tpl.ts +4 -4
- package/lib/service/type/mongodb.tpl.d.ts +1 -1
- package/lib/service/type/mongodb.tpl.js +4 -9
- package/lib/service/type/mongodb.tpl.js.map +1 -1
- package/lib/service/type/mongodb.tpl.ts +4 -4
- package/package.json +31 -30
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mongodb.tpl.js","sourceRoot":"","sources":["../../../src/connection/templates/mongodb.tpl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mongodb.tpl.js","sourceRoot":"","sources":["../../../src/connection/templates/mongodb.tpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAEvE,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE7D,MAAM,QAAQ,GAAG,CAAC,EAChB,QAAQ,EACmB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;;;;;MAOrC,QAAQ;;;;eAIC,QAAQ;gCACS,QAAQ;;;;;aAK3B,QAAQ;;CAEpB,CAAA;AAED,MAAM,aAAa,GAAG,uDAAuD,CAAA;AAE7E,MAAM,eAAe,GAAG;2CACmB,CAAA;AAE3C,MAAM,cAAc,GAAG,CAAC,EAAE,QAAQ,EAA8B,EAAE,EAAE,CAClE,YAAY,QAAQ,cAAc,QAAQ,GAAG,CAAA;AAC/C,MAAM,iBAAiB,GAAG,CAAC,EAAE,QAAQ,EAA8B,EAAE,EAAE,CAAC,iBAAiB,QAAQ,GAAG,CAAA;AACpG,MAAM,SAAS,GAAG,MAAM,CAA6B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;AAC/E,MAAM,eAAe,GAAG,MAAM,CAA6B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC,CAAA;AAE5F,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAA+B,EAAE,EAAE,CAC1D,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;KACjB,IAAI,CACH,YAAY,CACV,QAAQ,EACR,MAAM,CAA6B,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,QAAQ,CAAC,CAAC,CAC3E,CACF;KACA,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,MAAM,CAAC,0BAA0B,CAAC,EAAE,SAAS,CAAC,CAAC;KACjF,IAAI,CAAC,YAAY,CAAC,iBAAiB,EAAE,MAAM,CAAC,yBAAyB,CAAC,EAAE,SAAS,CAAC,CAAC;KACnF,IAAI,CAAC,YAAY,CAAC,aAAa,EAAE,OAAO,EAAE,EAAE,eAAe,CAAC,CAAC;KAC7D,IAAI,CAAC,YAAY,CAAC,eAAe,EAAE,MAAM,EAAE,EAAE,eAAe,CAAC,CAAC,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ConnectionGeneratorContext } from '../index'
|
|
3
|
-
import { injectSource, renderSource } from '../../commons'
|
|
1
|
+
import { toFile, before, prepend, append } from '@featherscloud/pinion'
|
|
2
|
+
import { ConnectionGeneratorContext } from '../index.js'
|
|
3
|
+
import { injectSource, renderSource } from '../../commons.js'
|
|
4
4
|
|
|
5
5
|
const template = ({
|
|
6
6
|
database
|
|
@@ -37,7 +37,7 @@ const toAppFile = toFile<ConnectionGeneratorContext>(({ lib }) => [lib, 'app'])
|
|
|
37
37
|
const toValidatorFile = toFile<ConnectionGeneratorContext>(({ lib }) => [lib, 'validators'])
|
|
38
38
|
|
|
39
39
|
export const generate = (ctx: ConnectionGeneratorContext) =>
|
|
40
|
-
|
|
40
|
+
Promise.resolve(ctx)
|
|
41
41
|
.then(
|
|
42
42
|
renderSource(
|
|
43
43
|
template,
|
package/lib/hook/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FeathersBaseContext } from '../commons';
|
|
1
|
+
import { FeathersBaseContext } from '../commons.js';
|
|
2
2
|
export interface HookGeneratorContext extends FeathersBaseContext {
|
|
3
3
|
name: string;
|
|
4
4
|
camelName: string;
|
|
@@ -10,13 +10,13 @@ export declare const generate: (ctx: HookGeneratorContext) => Promise<{
|
|
|
10
10
|
camelName: string;
|
|
11
11
|
name: string;
|
|
12
12
|
type: 'regular' | 'around';
|
|
13
|
-
feathers: import("../commons").FeathersAppInfo;
|
|
14
|
-
pkg: import("../commons").AppPackageJson;
|
|
13
|
+
feathers: import("../commons.js").FeathersAppInfo;
|
|
14
|
+
pkg: import("../commons.js").AppPackageJson;
|
|
15
15
|
lib: string;
|
|
16
16
|
test: string;
|
|
17
17
|
language: "ts" | "js";
|
|
18
|
-
dependencyVersions?: import("../commons").DependencyVersions;
|
|
18
|
+
dependencyVersions?: import("../commons.js").DependencyVersions;
|
|
19
19
|
cwd: string;
|
|
20
|
-
|
|
21
|
-
pinion: import("@
|
|
20
|
+
argv: string[];
|
|
21
|
+
pinion: import("@featherscloud/pinion").Configuration;
|
|
22
22
|
}>;
|
package/lib/hook/index.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
.then((0, commons_1.initializeBaseContext)())
|
|
12
|
-
.then((0, commons_1.checkPreconditions)())
|
|
13
|
-
.then((0, pinion_1.prompt)(({ type, name }) => [
|
|
1
|
+
import { dirname } from 'path';
|
|
2
|
+
import { prompt, runGenerators } from '@featherscloud/pinion';
|
|
3
|
+
import _ from 'lodash';
|
|
4
|
+
import { checkPreconditions, initializeBaseContext } from '../commons.js';
|
|
5
|
+
// Set __dirname in es module
|
|
6
|
+
const __dirname = dirname(new URL(import.meta.url).pathname);
|
|
7
|
+
export const generate = (ctx) => Promise.resolve(ctx)
|
|
8
|
+
.then(initializeBaseContext())
|
|
9
|
+
.then(checkPreconditions())
|
|
10
|
+
.then(prompt(({ type, name }) => [
|
|
14
11
|
{
|
|
15
12
|
type: 'input',
|
|
16
13
|
name: 'name',
|
|
@@ -30,14 +27,13 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
30
27
|
]))
|
|
31
28
|
.then((ctx) => {
|
|
32
29
|
const { name } = ctx;
|
|
33
|
-
const kebabName =
|
|
34
|
-
const camelName =
|
|
30
|
+
const kebabName = _.kebabCase(name);
|
|
31
|
+
const camelName = _.camelCase(name);
|
|
35
32
|
return {
|
|
36
33
|
...ctx,
|
|
37
34
|
kebabName,
|
|
38
35
|
camelName
|
|
39
36
|
};
|
|
40
37
|
})
|
|
41
|
-
.then(
|
|
42
|
-
exports.generate = generate;
|
|
38
|
+
.then(runGenerators(__dirname, 'templates'));
|
|
43
39
|
//# sourceMappingURL=index.js.map
|
package/lib/hook/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hook/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hook/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAC7D,OAAO,CAAC,MAAM,QAAQ,CAAA;AACtB,OAAO,EAAE,kBAAkB,EAAuB,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAE9F,6BAA6B;AAC7B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAA;AAS5D,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAyB,EAAE,EAAE,CACpD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;KACjB,IAAI,CAAC,qBAAqB,EAAE,CAAC;KAC7B,IAAI,CAAC,kBAAkB,EAAE,CAAC;KAC1B,IAAI,CACH,MAAM,CAAuB,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;IAC/C;QACE,IAAI,EAAE,OAAO;QACb,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,+BAA+B;QACxC,IAAI,EAAE,CAAC,IAAI;KACZ;IACD;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,CAAC,IAAI;QACX,OAAO,EAAE,0BAA0B;QACnC,OAAO,EAAE;YACP,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE;YACnC,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,wBAAwB,EAAE;SACrD;KACF;CACF,CAAC,CACH;KACA,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;IACZ,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAA;IACpB,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACnC,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAEnC,OAAO;QACL,GAAG,GAAG;QACN,SAAS;QACT,SAAS;KACV,CAAA;AACH,CAAC,CAAC;KACD,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAA"}
|
package/lib/hook/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { dirname } from 'path'
|
|
2
|
+
import { prompt, runGenerators } from '@featherscloud/pinion'
|
|
2
3
|
import _ from 'lodash'
|
|
3
|
-
import { checkPreconditions, FeathersBaseContext, initializeBaseContext } from '../commons'
|
|
4
|
+
import { checkPreconditions, FeathersBaseContext, initializeBaseContext } from '../commons.js'
|
|
5
|
+
|
|
6
|
+
// Set __dirname in es module
|
|
7
|
+
const __dirname = dirname(new URL(import.meta.url).pathname)
|
|
4
8
|
|
|
5
9
|
export interface HookGeneratorContext extends FeathersBaseContext {
|
|
6
10
|
name: string
|
|
@@ -10,7 +14,7 @@ export interface HookGeneratorContext extends FeathersBaseContext {
|
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
export const generate = (ctx: HookGeneratorContext) =>
|
|
13
|
-
|
|
17
|
+
Promise.resolve(ctx)
|
|
14
18
|
.then(initializeBaseContext())
|
|
15
19
|
.then(checkPreconditions())
|
|
16
20
|
.then(
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { HookGeneratorContext } from '../index';
|
|
1
|
+
import { HookGeneratorContext } from '../index.js';
|
|
2
2
|
export declare const generate: (ctx: HookGeneratorContext) => Promise<HookGeneratorContext>;
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.generate = void 0;
|
|
4
|
-
const pinion_1 = require("@feathershq/pinion");
|
|
5
|
-
const commons_1 = require("../../commons");
|
|
1
|
+
import { toFile } from '@featherscloud/pinion';
|
|
2
|
+
import { renderSource } from '../../commons.js';
|
|
6
3
|
const aroundTemplate = ({ camelName, name }) => /* ts */ `// For more information about this file see https://dove.feathersjs.com/guides/cli/hook.html
|
|
7
4
|
import type { HookContext, NextFunction } from '../declarations'
|
|
8
5
|
|
|
@@ -17,6 +14,5 @@ import type { HookContext } from '../declarations'
|
|
|
17
14
|
export const ${camelName} = async (context: HookContext) => {
|
|
18
15
|
console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
|
|
19
16
|
}`;
|
|
20
|
-
const generate = (ctx) =>
|
|
21
|
-
exports.generate = generate;
|
|
17
|
+
export const generate = (ctx) => Promise.resolve(ctx).then(renderSource((ctx) => (ctx.type === 'around' ? aroundTemplate(ctx) : regularTemplate(ctx)), toFile(({ lib, kebabName }) => [lib, 'hooks', kebabName])));
|
|
22
18
|
//# sourceMappingURL=hook.tpl.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.tpl.js","sourceRoot":"","sources":["../../../src/hook/templates/hook.tpl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hook.tpl.js","sourceRoot":"","sources":["../../../src/hook/templates/hook.tpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAE9C,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAA;AAE/C,MAAM,cAAc,GAAG,CAAC,EACtB,SAAS,EACT,IAAI,EACiB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;eAGtB,SAAS;+BACO,IAAI;;;CAGlC,CAAA;AAED,MAAM,eAAe,GAAG,CAAC,EACvB,SAAS,EACT,IAAI,EACiB,EAAE,EAAE,CAAC,QAAQ,CAAC;;;eAGtB,SAAS;+BACO,IAAI;EACjC,CAAA;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAAyB,EAAE,EAAE,CACpD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,IAAI,CACvB,YAAY,CACV,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,EAC7E,MAAM,CAAuB,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAChF,CACF,CAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { HookGeneratorContext } from '../index'
|
|
3
|
-
import { renderSource } from '../../commons'
|
|
1
|
+
import { toFile } from '@featherscloud/pinion'
|
|
2
|
+
import { HookGeneratorContext } from '../index.js'
|
|
3
|
+
import { renderSource } from '../../commons.js'
|
|
4
4
|
|
|
5
5
|
const aroundTemplate = ({
|
|
6
6
|
camelName,
|
|
@@ -25,7 +25,7 @@ export const ${camelName} = async (context: HookContext) => {
|
|
|
25
25
|
}`
|
|
26
26
|
|
|
27
27
|
export const generate = (ctx: HookGeneratorContext) =>
|
|
28
|
-
|
|
28
|
+
Promise.resolve(ctx).then(
|
|
29
29
|
renderSource(
|
|
30
30
|
(ctx) => (ctx.type === 'around' ? aroundTemplate(ctx) : regularTemplate(ctx)),
|
|
31
31
|
toFile<HookGeneratorContext>(({ lib, kebabName }) => [lib, 'hooks', kebabName])
|
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export * from '@
|
|
2
|
-
export * from './commons';
|
|
3
|
-
export * as app from './app';
|
|
4
|
-
export * as authentication from './authentication';
|
|
5
|
-
export * as connection from './connection';
|
|
6
|
-
export * as hook from './hook';
|
|
7
|
-
export * as service from './service';
|
|
1
|
+
export * from '@featherscloud/pinion';
|
|
2
|
+
export * from './commons.js';
|
|
3
|
+
export * as app from './app/index.js';
|
|
4
|
+
export * as authentication from './authentication/index.js';
|
|
5
|
+
export * as connection from './connection/index.js';
|
|
6
|
+
export * as hook from './hook/index.js';
|
|
7
|
+
export * as service from './service/index.js';
|
package/lib/index.js
CHANGED
|
@@ -1,37 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
|
-
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
|
-
if (mod && mod.__esModule) return mod;
|
|
23
|
-
var result = {};
|
|
24
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
25
|
-
__setModuleDefault(result, mod);
|
|
26
|
-
return result;
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.service = exports.hook = exports.connection = exports.authentication = exports.app = void 0;
|
|
30
|
-
__exportStar(require("@feathershq/pinion"), exports);
|
|
31
|
-
__exportStar(require("./commons"), exports);
|
|
32
|
-
exports.app = __importStar(require("./app"));
|
|
33
|
-
exports.authentication = __importStar(require("./authentication"));
|
|
34
|
-
exports.connection = __importStar(require("./connection"));
|
|
35
|
-
exports.hook = __importStar(require("./hook"));
|
|
36
|
-
exports.service = __importStar(require("./service"));
|
|
1
|
+
export * from '@featherscloud/pinion';
|
|
2
|
+
export * from './commons.js';
|
|
3
|
+
export * as app from './app/index.js';
|
|
4
|
+
export * as authentication from './authentication/index.js';
|
|
5
|
+
export * as connection from './connection/index.js';
|
|
6
|
+
export * as hook from './hook/index.js';
|
|
7
|
+
export * as service from './service/index.js';
|
|
37
8
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AAErC,cAAc,cAAc,CAAA;AAC5B,OAAO,KAAK,GAAG,MAAM,gBAAgB,CAAA;AACrC,OAAO,KAAK,cAAc,MAAM,2BAA2B,CAAA;AAC3D,OAAO,KAAK,UAAU,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,IAAI,MAAM,iBAAiB,CAAA;AACvC,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAA"}
|
package/lib/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export * from '@
|
|
1
|
+
export * from '@featherscloud/pinion'
|
|
2
2
|
|
|
3
|
-
export * from './commons'
|
|
4
|
-
export * as app from './app'
|
|
5
|
-
export * as authentication from './authentication'
|
|
6
|
-
export * as connection from './connection'
|
|
7
|
-
export * as hook from './hook'
|
|
8
|
-
export * as service from './service'
|
|
3
|
+
export * from './commons.js'
|
|
4
|
+
export * as app from './app/index.js'
|
|
5
|
+
export * as authentication from './authentication/index.js'
|
|
6
|
+
export * as connection from './connection/index.js'
|
|
7
|
+
export * as hook from './hook/index.js'
|
|
8
|
+
export * as service from './service/index.js'
|
package/lib/service/index.d.ts
CHANGED
package/lib/service/index.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.
|
|
13
|
-
|
|
14
|
-
.then((0, pinion_1.prompt)(({ name, path, type, schema, authentication, isEntityService, feathers, lib, language }) => {
|
|
15
|
-
const sqlDisabled = commons_1.DATABASE_TYPES.every((name) => name === 'mongodb' || name === 'other' || !(0, commons_1.fileExists)(lib, `${name}.${language}`));
|
|
16
|
-
const mongodbDisabled = !(0, commons_1.fileExists)(lib, `mongodb.${language}`);
|
|
1
|
+
import { dirname } from 'path';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
import { runGenerator, runGenerators, prompt } from '@featherscloud/pinion';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
// Set __dirname in es module
|
|
6
|
+
const __dirname = dirname(new URL(import.meta.url).pathname);
|
|
7
|
+
import { checkPreconditions, DATABASE_TYPES, fileExists, getDatabaseAdapter, initializeBaseContext } from '../commons.js';
|
|
8
|
+
export const generate = (ctx) => Promise.resolve(ctx)
|
|
9
|
+
.then(initializeBaseContext())
|
|
10
|
+
.then(checkPreconditions())
|
|
11
|
+
.then(prompt(({ name, path, type, schema, authentication, isEntityService, feathers, lib, language }) => {
|
|
12
|
+
const sqlDisabled = DATABASE_TYPES.every((name) => name === 'mongodb' || name === 'other' || !fileExists(lib, `${name}.${language}`));
|
|
13
|
+
const mongodbDisabled = !fileExists(lib, `mongodb.${language}`);
|
|
17
14
|
return [
|
|
18
15
|
{
|
|
19
16
|
name: 'name',
|
|
@@ -32,7 +29,7 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
32
29
|
type: 'input',
|
|
33
30
|
when: !path,
|
|
34
31
|
message: 'Which path should the service be registered on?',
|
|
35
|
-
default: (answers) => `${
|
|
32
|
+
default: (answers) => `${_.kebabCase(answers.name)}`,
|
|
36
33
|
validate: (input) => {
|
|
37
34
|
if (!input || input === 'authentication') {
|
|
38
35
|
return 'Invalid service path';
|
|
@@ -51,16 +48,16 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
51
48
|
type: 'list',
|
|
52
49
|
when: !type,
|
|
53
50
|
message: 'What database is the service using?',
|
|
54
|
-
default:
|
|
51
|
+
default: getDatabaseAdapter(feathers === null || feathers === void 0 ? void 0 : feathers.database),
|
|
55
52
|
choices: [
|
|
56
53
|
{
|
|
57
54
|
value: 'knex',
|
|
58
|
-
name: `SQL${sqlDisabled ?
|
|
55
|
+
name: `SQL${sqlDisabled ? chalk.gray(' (connection not available)') : ''}`,
|
|
59
56
|
disabled: sqlDisabled
|
|
60
57
|
},
|
|
61
58
|
{
|
|
62
59
|
value: 'mongodb',
|
|
63
|
-
name: `MongoDB${mongodbDisabled ?
|
|
60
|
+
name: `MongoDB${mongodbDisabled ? chalk.gray(' (connection not available)') : ''}`,
|
|
64
61
|
disabled: mongodbDisabled
|
|
65
62
|
},
|
|
66
63
|
{
|
|
@@ -74,12 +71,12 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
74
71
|
type: 'list',
|
|
75
72
|
when: schema === undefined,
|
|
76
73
|
message: 'Which schema definition format do you want to use?',
|
|
77
|
-
suffix:
|
|
74
|
+
suffix: chalk.grey(' Schemas allow to type, validate, secure and populate data'),
|
|
78
75
|
default: feathers === null || feathers === void 0 ? void 0 : feathers.schema,
|
|
79
76
|
choices: (answers) => [
|
|
80
77
|
{
|
|
81
78
|
value: 'typebox',
|
|
82
|
-
name: `TypeBox ${
|
|
79
|
+
name: `TypeBox ${chalk.gray(' (recommended)')}`
|
|
83
80
|
},
|
|
84
81
|
{
|
|
85
82
|
value: 'json',
|
|
@@ -87,7 +84,7 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
87
84
|
},
|
|
88
85
|
{
|
|
89
86
|
value: false,
|
|
90
|
-
name: `No schema${answers.type !== 'custom' ?
|
|
87
|
+
name: `No schema${answers.type !== 'custom' ? chalk.gray(' (not recommended with a database)') : ''}`
|
|
91
88
|
}
|
|
92
89
|
]
|
|
93
90
|
}
|
|
@@ -95,14 +92,14 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
95
92
|
}))
|
|
96
93
|
.then(async (ctx) => {
|
|
97
94
|
const { name, path, type, authStrategies = [] } = ctx;
|
|
98
|
-
const kebabName =
|
|
99
|
-
const camelName =
|
|
100
|
-
const upperName =
|
|
95
|
+
const kebabName = _.kebabCase(name);
|
|
96
|
+
const camelName = _.camelCase(name);
|
|
97
|
+
const upperName = _.upperFirst(camelName);
|
|
101
98
|
const className = `${upperName}Service`;
|
|
102
99
|
const folder = path.split('/').filter((el) => el !== '');
|
|
103
100
|
const relative = ['', ...folder].map(() => '..').join('/');
|
|
104
|
-
const fileName =
|
|
105
|
-
const kebabPath =
|
|
101
|
+
const fileName = _.last(folder);
|
|
102
|
+
const kebabPath = _.kebabCase(path);
|
|
106
103
|
return {
|
|
107
104
|
name,
|
|
108
105
|
type,
|
|
@@ -119,7 +116,6 @@ const generate = (ctx) => (0, pinion_1.generator)(ctx)
|
|
|
119
116
|
...ctx
|
|
120
117
|
};
|
|
121
118
|
})
|
|
122
|
-
.then(
|
|
123
|
-
.then(
|
|
124
|
-
exports.generate = generate;
|
|
119
|
+
.then(runGenerators(__dirname, 'templates'))
|
|
120
|
+
.then(runGenerator(__dirname, 'type', ({ type }) => `${type}.tpl`));
|
|
125
121
|
//# sourceMappingURL=index.js.map
|
package/lib/service/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/service/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAC9B,OAAO,CAAC,MAAM,QAAQ,CAAA;AACtB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AAC3E,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,6BAA6B;AAC7B,MAAM,SAAS,GAAG,OAAO,CAAC,IAAI,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAA;AAE5D,OAAO,EACL,kBAAkB,EAClB,cAAc,EAEd,UAAU,EACV,kBAAkB,EAClB,qBAAqB,EACtB,MAAM,eAAe,CAAA;AAyEtB,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,GAA8B,EAAE,EAAE,CACzD,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC;KACjB,IAAI,CAAC,qBAAqB,EAAE,CAAC;KAC7B,IAAI,CAAC,kBAAkB,EAAE,CAAC;KAC1B,IAAI,CACH,MAAM,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,QAAQ,EAAE,GAAG,EAAE,QAAQ,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CAAA"}
|
package/lib/service/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
import { dirname } from 'path'
|
|
1
2
|
import _ from 'lodash'
|
|
2
|
-
import {
|
|
3
|
+
import { runGenerator, runGenerators, prompt } from '@featherscloud/pinion'
|
|
4
|
+
import chalk from 'chalk'
|
|
5
|
+
|
|
6
|
+
// Set __dirname in es module
|
|
7
|
+
const __dirname = dirname(new URL(import.meta.url).pathname)
|
|
3
8
|
|
|
4
9
|
import {
|
|
5
10
|
checkPreconditions,
|
|
@@ -8,8 +13,7 @@ import {
|
|
|
8
13
|
fileExists,
|
|
9
14
|
getDatabaseAdapter,
|
|
10
15
|
initializeBaseContext
|
|
11
|
-
} from '../commons'
|
|
12
|
-
import chalk from 'chalk'
|
|
16
|
+
} from '../commons.js'
|
|
13
17
|
|
|
14
18
|
export interface ServiceGeneratorContext extends FeathersBaseContext {
|
|
15
19
|
/**
|
|
@@ -83,104 +87,102 @@ export type ServiceGeneratorArguments = FeathersBaseContext &
|
|
|
83
87
|
>
|
|
84
88
|
|
|
85
89
|
export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
86
|
-
|
|
90
|
+
Promise.resolve(ctx)
|
|
87
91
|
.then(initializeBaseContext())
|
|
88
92
|
.then(checkPreconditions())
|
|
89
93
|
.then(
|
|
90
|
-
prompt
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
const mongodbDisabled = !fileExists(lib, `mongodb.${language}`)
|
|
96
|
-
|
|
97
|
-
return [
|
|
98
|
-
{
|
|
99
|
-
name: 'name',
|
|
100
|
-
type: 'input',
|
|
101
|
-
when: !name,
|
|
102
|
-
message: 'What is the name of your service?',
|
|
103
|
-
validate: (input) => {
|
|
104
|
-
if (!input || input === 'authentication') {
|
|
105
|
-
return 'Invalid service name'
|
|
106
|
-
}
|
|
94
|
+
prompt(({ name, path, type, schema, authentication, isEntityService, feathers, lib, language }) => {
|
|
95
|
+
const sqlDisabled = DATABASE_TYPES.every(
|
|
96
|
+
(name) => name === 'mongodb' || name === 'other' || !fileExists(lib, `${name}.${language}`)
|
|
97
|
+
)
|
|
98
|
+
const mongodbDisabled = !fileExists(lib, `mongodb.${language}`)
|
|
107
99
|
|
|
108
|
-
|
|
100
|
+
return [
|
|
101
|
+
{
|
|
102
|
+
name: 'name',
|
|
103
|
+
type: 'input',
|
|
104
|
+
when: !name,
|
|
105
|
+
message: 'What is the name of your service?',
|
|
106
|
+
validate: (input: any) => {
|
|
107
|
+
if (!input || input === 'authentication') {
|
|
108
|
+
return 'Invalid service name'
|
|
109
109
|
}
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
name: 'path',
|
|
113
|
-
type: 'input',
|
|
114
|
-
when: !path,
|
|
115
|
-
message: 'Which path should the service be registered on?',
|
|
116
|
-
default: (answers: ServiceGeneratorArguments) => `${_.kebabCase(answers.name)}`,
|
|
117
|
-
validate: (input) => {
|
|
118
|
-
if (!input || input === 'authentication') {
|
|
119
|
-
return 'Invalid service path'
|
|
120
|
-
}
|
|
121
110
|
|
|
122
|
-
|
|
111
|
+
return true
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
name: 'path',
|
|
116
|
+
type: 'input',
|
|
117
|
+
when: !path,
|
|
118
|
+
message: 'Which path should the service be registered on?',
|
|
119
|
+
default: (answers: ServiceGeneratorArguments) => `${_.kebabCase(answers.name)}`,
|
|
120
|
+
validate: (input: any) => {
|
|
121
|
+
if (!input || input === 'authentication') {
|
|
122
|
+
return 'Invalid service path'
|
|
123
123
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
name: 'authentication',
|
|
127
|
-
type: 'confirm',
|
|
128
|
-
when: authentication === undefined && !isEntityService,
|
|
129
|
-
message: 'Does this service require authentication?'
|
|
130
|
-
},
|
|
131
|
-
{
|
|
132
|
-
name: 'type',
|
|
133
|
-
type: 'list',
|
|
134
|
-
when: !type,
|
|
135
|
-
message: 'What database is the service using?',
|
|
136
|
-
default: getDatabaseAdapter(feathers?.database),
|
|
137
|
-
choices: [
|
|
138
|
-
{
|
|
139
|
-
value: 'knex',
|
|
140
|
-
name: `SQL${sqlDisabled ? chalk.gray(' (connection not available)') : ''}`,
|
|
141
|
-
disabled: sqlDisabled
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
value: 'mongodb',
|
|
145
|
-
name: `MongoDB${mongodbDisabled ? chalk.gray(' (connection not available)') : ''}`,
|
|
146
|
-
disabled: mongodbDisabled
|
|
147
|
-
},
|
|
148
|
-
{
|
|
149
|
-
value: 'custom',
|
|
150
|
-
name: 'A custom service'
|
|
151
|
-
}
|
|
152
|
-
]
|
|
153
|
-
},
|
|
154
|
-
{
|
|
155
|
-
name: 'schema',
|
|
156
|
-
type: 'list',
|
|
157
|
-
when: schema === undefined,
|
|
158
|
-
message: 'Which schema definition format do you want to use?',
|
|
159
|
-
suffix: chalk.grey(' Schemas allow to type, validate, secure and populate data'),
|
|
160
|
-
default: feathers?.schema,
|
|
161
|
-
choices: (answers: ServiceGeneratorContext) => [
|
|
162
|
-
{
|
|
163
|
-
value: 'typebox',
|
|
164
|
-
name: `TypeBox ${chalk.gray(' (recommended)')}`
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
value: 'json',
|
|
168
|
-
name: 'JSON schema'
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
value: false,
|
|
172
|
-
name: `No schema${
|
|
173
|
-
answers.type !== 'custom' ? chalk.gray(' (not recommended with a database)') : ''
|
|
174
|
-
}`
|
|
175
|
-
}
|
|
176
|
-
]
|
|
124
|
+
|
|
125
|
+
return true
|
|
177
126
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'authentication',
|
|
130
|
+
type: 'confirm',
|
|
131
|
+
when: authentication === undefined && !isEntityService,
|
|
132
|
+
message: 'Does this service require authentication?'
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: 'type',
|
|
136
|
+
type: 'list',
|
|
137
|
+
when: !type,
|
|
138
|
+
message: 'What database is the service using?',
|
|
139
|
+
default: getDatabaseAdapter(feathers?.database),
|
|
140
|
+
choices: [
|
|
141
|
+
{
|
|
142
|
+
value: 'knex',
|
|
143
|
+
name: `SQL${sqlDisabled ? chalk.gray(' (connection not available)') : ''}`,
|
|
144
|
+
disabled: sqlDisabled
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
value: 'mongodb',
|
|
148
|
+
name: `MongoDB${mongodbDisabled ? chalk.gray(' (connection not available)') : ''}`,
|
|
149
|
+
disabled: mongodbDisabled
|
|
150
|
+
},
|
|
151
|
+
{
|
|
152
|
+
value: 'custom',
|
|
153
|
+
name: 'A custom service'
|
|
154
|
+
}
|
|
155
|
+
]
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: 'schema',
|
|
159
|
+
type: 'list',
|
|
160
|
+
when: schema === undefined,
|
|
161
|
+
message: 'Which schema definition format do you want to use?',
|
|
162
|
+
suffix: chalk.grey(' Schemas allow to type, validate, secure and populate data'),
|
|
163
|
+
default: feathers?.schema,
|
|
164
|
+
choices: (answers: ServiceGeneratorContext) => [
|
|
165
|
+
{
|
|
166
|
+
value: 'typebox',
|
|
167
|
+
name: `TypeBox ${chalk.gray(' (recommended)')}`
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
value: 'json',
|
|
171
|
+
name: 'JSON schema'
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
value: false,
|
|
175
|
+
name: `No schema${
|
|
176
|
+
answers.type !== 'custom' ? chalk.gray(' (not recommended with a database)') : ''
|
|
177
|
+
}`
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
})
|
|
181
183
|
)
|
|
182
184
|
.then(async (ctx): Promise<ServiceGeneratorContext> => {
|
|
183
|
-
const { name, path, type, authStrategies = [] } = ctx
|
|
185
|
+
const { name, path, type, authStrategies = [] } = ctx as any as ServiceGeneratorContext
|
|
184
186
|
const kebabName = _.kebabCase(name)
|
|
185
187
|
const camelName = _.camelCase(name)
|
|
186
188
|
const upperName = _.upperFirst(camelName)
|
|
@@ -205,7 +207,7 @@ export const generate = (ctx: ServiceGeneratorArguments) =>
|
|
|
205
207
|
relative,
|
|
206
208
|
authStrategies,
|
|
207
209
|
...ctx
|
|
208
|
-
}
|
|
210
|
+
} as ServiceGeneratorContext
|
|
209
211
|
})
|
|
210
212
|
.then(runGenerators<ServiceGeneratorContext>(__dirname, 'templates'))
|
|
211
213
|
.then(runGenerator<ServiceGeneratorContext>(__dirname, 'type', ({ type }) => `${type}.tpl`))
|