@feathersjs/cli 4.6.2 → 5.0.0-pre.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/CHANGELOG.md +10 -917
  2. package/LICENSE +1 -1
  3. package/README.md +9 -34
  4. package/bin/feathers +9 -0
  5. package/lib/app/index.d.ts +29 -0
  6. package/lib/app/index.js +123 -0
  7. package/lib/app/index.js.map +1 -0
  8. package/lib/app/index.ts +198 -0
  9. package/lib/app/static/.gitignore +121 -0
  10. package/lib/app/templates/app.test.tpl.d.ts +2 -0
  11. package/lib/app/templates/app.test.tpl.js +48 -0
  12. package/lib/app/templates/app.test.tpl.js.map +1 -0
  13. package/lib/app/templates/app.test.tpl.ts +48 -0
  14. package/lib/app/templates/app.tpl.d.ts +2 -0
  15. package/lib/app/templates/app.tpl.js +110 -0
  16. package/lib/app/templates/app.tpl.js.map +1 -0
  17. package/lib/app/templates/app.tpl.ts +119 -0
  18. package/lib/app/templates/channels.tpl.d.ts +2 -0
  19. package/lib/app/templates/channels.tpl.js +76 -0
  20. package/lib/app/templates/channels.tpl.js.map +1 -0
  21. package/lib/app/templates/channels.tpl.ts +81 -0
  22. package/lib/app/templates/client.tpl.d.ts +2 -0
  23. package/lib/app/templates/client.tpl.js +22 -0
  24. package/lib/app/templates/client.tpl.js.map +1 -0
  25. package/lib/app/templates/client.tpl.ts +27 -0
  26. package/lib/app/templates/config.tpl.d.ts +2 -0
  27. package/lib/app/templates/config.tpl.js +21 -0
  28. package/lib/app/templates/config.tpl.js.map +1 -0
  29. package/lib/app/templates/config.tpl.ts +21 -0
  30. package/lib/app/templates/configuration.tpl.d.ts +2 -0
  31. package/lib/app/templates/configuration.tpl.js +36 -0
  32. package/lib/app/templates/configuration.tpl.js.map +1 -0
  33. package/lib/app/templates/configuration.tpl.ts +41 -0
  34. package/lib/app/templates/declarations.tpl.d.ts +2 -0
  35. package/lib/app/templates/declarations.tpl.js +23 -0
  36. package/lib/app/templates/declarations.tpl.js.map +1 -0
  37. package/lib/app/templates/declarations.tpl.ts +31 -0
  38. package/lib/app/templates/index.html.tpl.d.ts +2 -0
  39. package/lib/app/templates/index.html.tpl.js +85 -0
  40. package/lib/app/templates/index.html.tpl.js.map +1 -0
  41. package/lib/app/templates/index.html.tpl.ts +85 -0
  42. package/lib/app/templates/index.tpl.d.ts +2 -0
  43. package/lib/app/templates/index.tpl.js +18 -0
  44. package/lib/app/templates/index.tpl.js.map +1 -0
  45. package/lib/app/templates/index.tpl.ts +23 -0
  46. package/lib/app/templates/logger.tpl.d.ts +2 -0
  47. package/lib/app/templates/logger.tpl.js +33 -0
  48. package/lib/app/templates/logger.tpl.js.map +1 -0
  49. package/lib/app/templates/logger.tpl.ts +38 -0
  50. package/lib/app/templates/package.json.tpl.d.ts +2 -0
  51. package/lib/app/templates/package.json.tpl.js +53 -0
  52. package/lib/app/templates/package.json.tpl.js.map +1 -0
  53. package/lib/app/templates/package.json.tpl.ts +65 -0
  54. package/lib/app/templates/readme.md.tpl.d.ts +2 -0
  55. package/lib/app/templates/readme.md.tpl.js +50 -0
  56. package/lib/app/templates/readme.md.tpl.js.map +1 -0
  57. package/lib/app/templates/readme.md.tpl.ts +50 -0
  58. package/lib/app/templates/services.tpl.d.ts +2 -0
  59. package/lib/app/templates/services.tpl.js +14 -0
  60. package/lib/app/templates/services.tpl.js.map +1 -0
  61. package/lib/app/templates/services.tpl.ts +19 -0
  62. package/lib/app/templates/tsconfig.json.tpl.d.ts +2 -0
  63. package/lib/app/templates/tsconfig.json.tpl.js +20 -0
  64. package/lib/app/templates/tsconfig.json.tpl.js.map +1 -0
  65. package/lib/app/templates/tsconfig.json.tpl.ts +26 -0
  66. package/lib/authentication/index.d.ts +71 -0
  67. package/lib/authentication/index.js +94 -0
  68. package/lib/authentication/index.js.map +1 -0
  69. package/lib/authentication/index.ts +103 -0
  70. package/lib/authentication/templates/authentication.tpl.d.ts +2 -0
  71. package/lib/authentication/templates/authentication.tpl.js +40 -0
  72. package/lib/authentication/templates/authentication.tpl.js.map +1 -0
  73. package/lib/authentication/templates/authentication.tpl.ts +53 -0
  74. package/lib/authentication/templates/config.tpl.d.ts +2 -0
  75. package/lib/authentication/templates/config.tpl.js +46 -0
  76. package/lib/authentication/templates/config.tpl.js.map +1 -0
  77. package/lib/authentication/templates/config.tpl.ts +51 -0
  78. package/lib/authentication/templates/declarations.tpl.d.ts +2 -0
  79. package/lib/authentication/templates/declarations.tpl.js +19 -0
  80. package/lib/authentication/templates/declarations.tpl.js.map +1 -0
  81. package/lib/authentication/templates/declarations.tpl.ts +29 -0
  82. package/lib/authentication/templates/knex.tpl.d.ts +2 -0
  83. package/lib/authentication/templates/knex.tpl.js +41 -0
  84. package/lib/authentication/templates/knex.tpl.js.map +1 -0
  85. package/lib/authentication/templates/knex.tpl.ts +59 -0
  86. package/lib/authentication/templates/test.tpl.d.ts +2 -0
  87. package/lib/authentication/templates/test.tpl.js +43 -0
  88. package/lib/authentication/templates/test.tpl.js.map +1 -0
  89. package/lib/authentication/templates/test.tpl.ts +50 -0
  90. package/lib/authentication/templates/user.resolver.tpl.d.ts +2 -0
  91. package/lib/authentication/templates/user.resolver.tpl.js +96 -0
  92. package/lib/authentication/templates/user.resolver.tpl.js.map +1 -0
  93. package/lib/authentication/templates/user.resolver.tpl.ts +109 -0
  94. package/lib/authentication/templates/user.schema.tpl.d.ts +2 -0
  95. package/lib/authentication/templates/user.schema.tpl.js +85 -0
  96. package/lib/authentication/templates/user.schema.tpl.js.map +1 -0
  97. package/lib/authentication/templates/user.schema.tpl.ts +93 -0
  98. package/lib/commons.d.ts +120 -0
  99. package/lib/commons.js +137 -0
  100. package/lib/commons.js.map +1 -0
  101. package/lib/commons.ts +187 -0
  102. package/lib/connection/index.d.ts +53 -0
  103. package/lib/connection/index.js +86 -0
  104. package/lib/connection/index.js.map +1 -0
  105. package/lib/connection/index.ts +109 -0
  106. package/lib/connection/templates/knex.tpl.d.ts +2 -0
  107. package/lib/connection/templates/knex.tpl.js +59 -0
  108. package/lib/connection/templates/knex.tpl.js.map +1 -0
  109. package/lib/connection/templates/knex.tpl.ts +79 -0
  110. package/lib/connection/templates/mongodb.tpl.d.ts +2 -0
  111. package/lib/connection/templates/mongodb.tpl.js +39 -0
  112. package/lib/connection/templates/mongodb.tpl.js.map +1 -0
  113. package/lib/connection/templates/mongodb.tpl.ts +51 -0
  114. package/lib/hook/index.d.ts +22 -0
  115. package/lib/hook/index.js +40 -0
  116. package/lib/hook/index.js.map +1 -0
  117. package/lib/hook/index.ts +45 -0
  118. package/lib/hook/templates/hook.tpl.d.ts +2 -0
  119. package/lib/hook/templates/hook.tpl.js +21 -0
  120. package/lib/hook/templates/hook.tpl.js.map +1 -0
  121. package/lib/hook/templates/hook.tpl.ts +28 -0
  122. package/lib/index.d.ts +16 -0
  123. package/lib/index.js +24 -62
  124. package/lib/index.js.map +1 -0
  125. package/lib/index.ts +27 -0
  126. package/lib/service/index.d.ts +130 -0
  127. package/lib/service/index.js +84 -0
  128. package/lib/service/index.js.map +1 -0
  129. package/lib/service/index.ts +150 -0
  130. package/lib/service/templates/client.tpl.d.ts +2 -0
  131. package/lib/service/templates/client.tpl.js +16 -0
  132. package/lib/service/templates/client.tpl.js.map +1 -0
  133. package/lib/service/templates/client.tpl.ts +27 -0
  134. package/lib/service/templates/resolver.tpl.d.ts +2 -0
  135. package/lib/service/templates/resolver.tpl.js +73 -0
  136. package/lib/service/templates/resolver.tpl.js.map +1 -0
  137. package/lib/service/templates/resolver.tpl.ts +78 -0
  138. package/lib/service/templates/schema.tpl.d.ts +2 -0
  139. package/lib/service/templates/schema.tpl.js +75 -0
  140. package/lib/service/templates/schema.tpl.js.map +1 -0
  141. package/lib/service/templates/schema.tpl.ts +80 -0
  142. package/lib/service/templates/service.tpl.d.ts +2 -0
  143. package/lib/service/templates/service.tpl.js +92 -0
  144. package/lib/service/templates/service.tpl.js.map +1 -0
  145. package/lib/service/templates/service.tpl.ts +117 -0
  146. package/lib/service/templates/test.tpl.d.ts +2 -0
  147. package/lib/service/templates/test.tpl.js +24 -0
  148. package/lib/service/templates/test.tpl.js.map +1 -0
  149. package/lib/service/templates/test.tpl.ts +29 -0
  150. package/lib/service/type/custom.tpl.d.ts +4 -0
  151. package/lib/service/type/custom.tpl.js +79 -0
  152. package/lib/service/type/custom.tpl.js.map +1 -0
  153. package/lib/service/type/custom.tpl.ts +81 -0
  154. package/lib/service/type/knex.tpl.d.ts +5 -0
  155. package/lib/service/type/knex.tpl.js +50 -0
  156. package/lib/service/type/knex.tpl.js.map +1 -0
  157. package/lib/service/type/knex.tpl.ts +62 -0
  158. package/lib/service/type/mongodb.tpl.d.ts +4 -0
  159. package/lib/service/type/mongodb.tpl.js +29 -0
  160. package/lib/service/type/mongodb.tpl.js.map +1 -0
  161. package/lib/service/type/mongodb.tpl.ts +34 -0
  162. package/package.json +56 -36
  163. package/bin/feathers.js +0 -5
@@ -0,0 +1,79 @@
1
+ import { generator, toFile, inject, before, mergeJSON } from '@feathershq/pinion'
2
+ import { ConnectionGeneratorContext } from '../index'
3
+ import { getSource, renderSource } from '../../commons'
4
+
5
+ const template = ({ database }: ConnectionGeneratorContext) =>
6
+ `import knex from 'knex'
7
+ import type { Knex } from 'knex'
8
+ import type { Application } from './declarations'
9
+
10
+ declare module './declarations' {
11
+ interface Configuration {
12
+ ${database}Client: Knex
13
+ }
14
+ }
15
+
16
+ export const ${database} = (app: Application) => {
17
+ const config = app.get('${database}')
18
+ const db = knex(config!)
19
+
20
+ app.set('${database}Client', db);
21
+ }
22
+ `
23
+
24
+ const knexfile = ({ lib, language, database }: ConnectionGeneratorContext) => `
25
+ import { app } from './${lib}/app'
26
+
27
+ // Load our database connection info from the app configuration
28
+ const config = app.get('${database}')
29
+
30
+ ${language === 'js' ? 'export default config' : 'module.exports = config'}
31
+ `
32
+
33
+ const configurationTemplate = ({ database }: ConnectionGeneratorContext) => ` ${database}: {
34
+ type: 'object',
35
+ properties: {
36
+ client: { type: 'string' },
37
+ connection: { type: 'string' }
38
+ }
39
+ },`
40
+
41
+ const importTemplate = ({ database }: ConnectionGeneratorContext) =>
42
+ `import { ${database} } from './${database}'`
43
+ const configureTemplate = ({ database }: ConnectionGeneratorContext) => `app.configure(${database})`
44
+ const toAppFile = toFile<ConnectionGeneratorContext>(({ lib, language }) => [lib, `app.${language}`])
45
+
46
+ export const generate = (ctx: ConnectionGeneratorContext) =>
47
+ generator(ctx)
48
+ .then(
49
+ renderSource(
50
+ template,
51
+ toFile<ConnectionGeneratorContext>(({ lib, database }) => [lib, database])
52
+ )
53
+ )
54
+ .then(renderSource(knexfile, toFile('knexfile')))
55
+ .then(
56
+ mergeJSON<ConnectionGeneratorContext>(
57
+ {
58
+ scripts: {
59
+ migrate: 'knex migrate:latest',
60
+ 'migrate:create': 'knex migrate:create',
61
+ test: 'cross-env NODE_ENV=test npm run migrate && npm run mocha'
62
+ }
63
+ },
64
+ toFile('package.json')
65
+ )
66
+ )
67
+ .then(
68
+ inject(
69
+ configurationTemplate,
70
+ before('authentication: authenticationSettingsSchema'),
71
+ toFile<ConnectionGeneratorContext>(({ lib, language }) => [
72
+ lib,
73
+ 'schemas',
74
+ `configuration.schema.${language}`
75
+ ])
76
+ )
77
+ )
78
+ .then(inject(getSource(importTemplate), before('import { services } from'), toAppFile))
79
+ .then(inject(getSource(configureTemplate), before('app.configure(services)'), toAppFile))
@@ -0,0 +1,2 @@
1
+ import { ConnectionGeneratorContext } from '../index';
2
+ export declare const generate: (ctx: ConnectionGeneratorContext) => Promise<ConnectionGeneratorContext>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generate = void 0;
4
+ const pinion_1 = require("@feathershq/pinion");
5
+ const commons_1 = require("../../commons");
6
+ const template = ({}) => `import { MongoClient } from 'mongodb'
7
+ import type { Db } from 'mongodb'
8
+ import type { Application } from './declarations'
9
+
10
+ declare module './declarations' {
11
+ interface Configuration {
12
+ mongodbClient: Promise<Db>
13
+ }
14
+ }
15
+
16
+ export const mongodb = (app: Application) => {
17
+ const connection = app.get('mongodb') as string
18
+ const database = connection.substring(connection.lastIndexOf('/') + 1)
19
+ const mongoClient = MongoClient.connect(connection)
20
+ .then(client => client.db(database))
21
+
22
+ app.set('mongodbClient', mongoClient)
23
+ }
24
+ `;
25
+ const configurationTemplate = ({ database }) => ` ${database}: { type: 'string' },`;
26
+ const importTemplate = "import { mongodb } from './mongodb'";
27
+ const configureTemplate = 'app.configure(mongodb)';
28
+ const toAppFile = (0, pinion_1.toFile)(({ lib, language }) => [lib, `app.${language}`]);
29
+ const generate = (ctx) => (0, pinion_1.generator)(ctx)
30
+ .then((0, commons_1.renderSource)(template, (0, pinion_1.toFile)(({ lib }) => lib, 'mongodb')))
31
+ .then((0, pinion_1.inject)(configurationTemplate, (0, pinion_1.before)('authentication: authenticationSettingsSchema'), (0, pinion_1.toFile)(({ lib, language }) => [
32
+ lib,
33
+ 'schemas',
34
+ `configuration.schema.${language}`
35
+ ])))
36
+ .then((0, pinion_1.inject)((0, commons_1.getSource)(importTemplate), (0, pinion_1.before)('import { services } from'), toAppFile))
37
+ .then((0, pinion_1.inject)((0, commons_1.getSource)(configureTemplate), (0, pinion_1.before)('app.configure(services)'), toAppFile));
38
+ exports.generate = generate;
39
+ //# sourceMappingURL=mongodb.tpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mongodb.tpl.js","sourceRoot":"","sources":["../../../src/connection/templates/mongodb.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsE;AAEtE,2CAAuD;AAEvD,MAAM,QAAQ,GAAG,CAAC,EAA8B,EAAE,EAAE,CAClD;;;;;;;;;;;;;;;;;;CAkBD,CAAA;AACD,MAAM,qBAAqB,GAAG,CAAC,EAAE,QAAQ,EAA8B,EAAE,EAAE,CACzE,OAAO,QAAQ,uBAAuB,CAAA;AACxC,MAAM,cAAc,GAAG,qCAAqC,CAAA;AAC5D,MAAM,iBAAiB,GAAG,wBAAwB,CAAA;AAClD,MAAM,SAAS,GAAG,IAAA,eAAM,EAA6B,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,QAAQ,EAAE,CAAC,CAAC,CAAA;AAE9F,MAAM,QAAQ,GAAG,CAAC,GAA+B,EAAE,EAAE,CAC1D,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,sBAAY,EACV,QAAQ,EACR,IAAA,eAAM,EAA6B,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,EAAE,SAAS,CAAC,CAChE,CACF;KACA,IAAI,CACH,IAAA,eAAM,EACJ,qBAAqB,EACrB,IAAA,eAAM,EAAC,8CAA8C,CAAC,EACtD,IAAA,eAAM,EAA6B,CAAC,EAAE,GAAG,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;IACxD,GAAG;IACH,SAAS;IACT,wBAAwB,QAAQ,EAAE;CACnC,CAAC,CACH,CACF;KACA,IAAI,CAAC,IAAA,eAAM,EAAC,IAAA,mBAAS,EAAC,cAAc,CAAC,EAAE,IAAA,eAAM,EAAC,0BAA0B,CAAC,EAAE,SAAS,CAAC,CAAC;KACtF,IAAI,CAAC,IAAA,eAAM,EAAC,IAAA,mBAAS,EAAC,iBAAiB,CAAC,EAAE,IAAA,eAAM,EAAC,yBAAyB,CAAC,EAAE,SAAS,CAAC,CAAC,CAAA;AApBhF,QAAA,QAAQ,YAoBwE"}
@@ -0,0 +1,51 @@
1
+ import { generator, toFile, inject, before } from '@feathershq/pinion'
2
+ import { ConnectionGeneratorContext } from '../index'
3
+ import { getSource, renderSource } from '../../commons'
4
+
5
+ const template = ({}: ConnectionGeneratorContext) =>
6
+ `import { MongoClient } from 'mongodb'
7
+ import type { Db } from 'mongodb'
8
+ import type { Application } from './declarations'
9
+
10
+ declare module './declarations' {
11
+ interface Configuration {
12
+ mongodbClient: Promise<Db>
13
+ }
14
+ }
15
+
16
+ export const mongodb = (app: Application) => {
17
+ const connection = app.get('mongodb') as string
18
+ const database = connection.substring(connection.lastIndexOf('/') + 1)
19
+ const mongoClient = MongoClient.connect(connection)
20
+ .then(client => client.db(database))
21
+
22
+ app.set('mongodbClient', mongoClient)
23
+ }
24
+ `
25
+ const configurationTemplate = ({ database }: ConnectionGeneratorContext) =>
26
+ ` ${database}: { type: 'string' },`
27
+ const importTemplate = "import { mongodb } from './mongodb'"
28
+ const configureTemplate = 'app.configure(mongodb)'
29
+ const toAppFile = toFile<ConnectionGeneratorContext>(({ lib, language }) => [lib, `app.${language}`])
30
+
31
+ export const generate = (ctx: ConnectionGeneratorContext) =>
32
+ generator(ctx)
33
+ .then(
34
+ renderSource(
35
+ template,
36
+ toFile<ConnectionGeneratorContext>(({ lib }) => lib, 'mongodb')
37
+ )
38
+ )
39
+ .then(
40
+ inject(
41
+ configurationTemplate,
42
+ before('authentication: authenticationSettingsSchema'),
43
+ toFile<ConnectionGeneratorContext>(({ lib, language }) => [
44
+ lib,
45
+ 'schemas',
46
+ `configuration.schema.${language}`
47
+ ])
48
+ )
49
+ )
50
+ .then(inject(getSource(importTemplate), before('import { services } from'), toAppFile))
51
+ .then(inject(getSource(configureTemplate), before('app.configure(services)'), toAppFile))
@@ -0,0 +1,22 @@
1
+ import { FeathersBaseContext } from '../commons';
2
+ export interface HookGeneratorContext extends FeathersBaseContext {
3
+ name: string;
4
+ camelName: string;
5
+ kebabName: string;
6
+ type: 'regular' | 'around';
7
+ }
8
+ export declare const generate: (ctx: HookGeneratorContext) => Promise<{
9
+ kebabName: string;
10
+ camelName: string;
11
+ name: string;
12
+ type: 'regular' | 'around';
13
+ feathers: import("../commons").FeathersAppInfo;
14
+ pkg: import("../commons").AppPackageJson;
15
+ lib: string;
16
+ test: string;
17
+ language: "js" | "ts";
18
+ dependencyVersions?: import("../commons").DependencyVersions;
19
+ cwd: string;
20
+ _?: (string | number)[];
21
+ pinion: import("@feathershq/pinion").Configuration;
22
+ }>;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generate = void 0;
7
+ const pinion_1 = require("@feathershq/pinion");
8
+ const lodash_1 = __importDefault(require("lodash"));
9
+ const generate = (ctx) => (0, pinion_1.generator)(ctx)
10
+ .then((0, pinion_1.prompt)(({ type, name }) => [
11
+ {
12
+ type: 'input',
13
+ name: 'name',
14
+ message: 'What is the name of the hook?',
15
+ when: !name
16
+ },
17
+ {
18
+ name: 'type',
19
+ type: 'list',
20
+ when: !type,
21
+ message: 'What kind of hook is it?',
22
+ choices: [
23
+ { value: 'around', name: 'Around' },
24
+ { value: 'regular', name: 'Before, After or Error' }
25
+ ]
26
+ }
27
+ ]))
28
+ .then((ctx) => {
29
+ const { name } = ctx;
30
+ const kebabName = lodash_1.default.kebabCase(name);
31
+ const camelName = lodash_1.default.camelCase(name);
32
+ return {
33
+ ...ctx,
34
+ kebabName,
35
+ camelName
36
+ };
37
+ })
38
+ .then((0, pinion_1.runGenerators)(__dirname, 'templates'));
39
+ exports.generate = generate;
40
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hook/index.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAqE;AACrE,oDAAsB;AAUf,MAAM,QAAQ,GAAG,CAAC,GAAyB,EAAE,EAAE,CACpD,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CACH,IAAA,eAAM,EAAuB,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,gBAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACnC,MAAM,SAAS,GAAG,gBAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IAEnC,OAAO;QACL,GAAG,GAAG;QACN,SAAS;QACT,SAAS;KACV,CAAA;AACH,CAAC,CAAC;KACD,IAAI,CAAC,IAAA,sBAAa,EAAC,SAAS,EAAE,WAAW,CAAC,CAAC,CAAA;AAjCnC,QAAA,QAAQ,YAiC2B"}
@@ -0,0 +1,45 @@
1
+ import { generator, prompt, runGenerators } from '@feathershq/pinion'
2
+ import _ from 'lodash'
3
+ import { FeathersBaseContext } from '../commons'
4
+
5
+ export interface HookGeneratorContext extends FeathersBaseContext {
6
+ name: string
7
+ camelName: string
8
+ kebabName: string
9
+ type: 'regular' | 'around'
10
+ }
11
+
12
+ export const generate = (ctx: HookGeneratorContext) =>
13
+ generator(ctx)
14
+ .then(
15
+ prompt<HookGeneratorContext>(({ type, name }) => [
16
+ {
17
+ type: 'input',
18
+ name: 'name',
19
+ message: 'What is the name of the hook?',
20
+ when: !name
21
+ },
22
+ {
23
+ name: 'type',
24
+ type: 'list',
25
+ when: !type,
26
+ message: 'What kind of hook is it?',
27
+ choices: [
28
+ { value: 'around', name: 'Around' },
29
+ { value: 'regular', name: 'Before, After or Error' }
30
+ ]
31
+ }
32
+ ])
33
+ )
34
+ .then((ctx) => {
35
+ const { name } = ctx
36
+ const kebabName = _.kebabCase(name)
37
+ const camelName = _.camelCase(name)
38
+
39
+ return {
40
+ ...ctx,
41
+ kebabName,
42
+ camelName
43
+ }
44
+ })
45
+ .then(runGenerators(__dirname, 'templates'))
@@ -0,0 +1,2 @@
1
+ import { HookGeneratorContext } from '../index';
2
+ export declare const generate: (ctx: HookGeneratorContext) => Promise<HookGeneratorContext>;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generate = void 0;
4
+ const pinion_1 = require("@feathershq/pinion");
5
+ const commons_1 = require("../../commons");
6
+ const aroundTemplate = ({ camelName, name }) => `
7
+ import { HookContext, NextFunction } from '../declarations'
8
+
9
+ export const ${camelName} = async (context: HookContext, next: NextFunction) => {
10
+ console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
11
+ await next()
12
+ }
13
+ `;
14
+ const regularTemplate = ({ camelName }) => `import { HookContext } from '../declarations'
15
+
16
+ export const ${camelName} = async (context: HookContext) => {
17
+ console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
18
+ }`;
19
+ const generate = (ctx) => (0, pinion_1.generator)(ctx).then((0, commons_1.renderSource)((ctx) => (ctx.type === 'around' ? aroundTemplate(ctx) : regularTemplate(ctx)), (0, pinion_1.toFile)(({ lib, kebabName }) => [lib, 'hooks', kebabName])));
20
+ exports.generate = generate;
21
+ //# sourceMappingURL=hook.tpl.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.tpl.js","sourceRoot":"","sources":["../../../src/hook/templates/hook.tpl.ts"],"names":[],"mappings":";;;AAAA,+CAAsD;AAEtD,2CAA4C;AAE5C,MAAM,cAAc,GAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAwB,EAAE,EAAE,CAAC;;;eAGvD,SAAS;+BACO,IAAI;;;CAGlC,CAAA;AAED,MAAM,eAAe,GAAG,CAAC,EACvB,SAAS,EACY,EAAE,EAAE,CAAC;;eAEb,SAAS;+BACO,IAAI;EACjC,CAAA;AAEK,MAAM,QAAQ,GAAG,CAAC,GAAyB,EAAE,EAAE,CACpD,IAAA,kBAAS,EAAC,GAAG,CAAC,CAAC,IAAI,CACjB,IAAA,sBAAY,EACV,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,IAAA,eAAM,EAAuB,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAChF,CACF,CAAA;AANU,QAAA,QAAQ,YAMlB"}
@@ -0,0 +1,28 @@
1
+ import { generator, toFile } from '@feathershq/pinion'
2
+ import { HookGeneratorContext } from '../index'
3
+ import { renderSource } from '../../commons'
4
+
5
+ const aroundTemplate = ({ camelName, name }: HookGeneratorContext) => `
6
+ import { HookContext, NextFunction } from '../declarations'
7
+
8
+ export const ${camelName} = async (context: HookContext, next: NextFunction) => {
9
+ console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
10
+ await next()
11
+ }
12
+ `
13
+
14
+ const regularTemplate = ({
15
+ camelName
16
+ }: HookGeneratorContext) => `import { HookContext } from '../declarations'
17
+
18
+ export const ${camelName} = async (context: HookContext) => {
19
+ console.log(\`Running hook ${name} on \${context.path}\.\${context.method}\`)
20
+ }`
21
+
22
+ export const generate = (ctx: HookGeneratorContext) =>
23
+ generator(ctx).then(
24
+ renderSource(
25
+ (ctx) => (ctx.type === 'around' ? aroundTemplate(ctx) : regularTemplate(ctx)),
26
+ toFile<HookGeneratorContext>(({ lib, kebabName }) => [lib, 'hooks', kebabName])
27
+ )
28
+ )
package/lib/index.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ /// <reference types="yargs" />
2
+ import { Argv } from '@feathershq/pinion';
3
+ import { FeathersBaseContext } from './commons';
4
+ export declare const commandRunner: (yarg: any) => Promise<FeathersBaseContext & {
5
+ lib: string;
6
+ test: string;
7
+ language: "js" | "ts";
8
+ feathers: import("./commons").FeathersAppInfo;
9
+ }>;
10
+ export declare const generate: (ctx: FeathersBaseContext) => Promise<FeathersBaseContext & {
11
+ lib: string;
12
+ test: string;
13
+ language: "js" | "ts";
14
+ feathers: import("./commons").FeathersAppInfo;
15
+ }>;
16
+ export declare const command: (yargs: Argv) => Argv<{}>;
package/lib/index.js CHANGED
@@ -1,64 +1,26 @@
1
- const yeoman = require('yeoman-environment');
2
- const program = require('commander');
3
- const meta = require('generator-feathers/meta');
4
- const semver = require('semver');
5
- const updateNotifier = require('update-notifier');
6
- const { upgrade } = require('@feathersjs/tools');
7
-
8
- const env = yeoman.createEnv();
9
-
10
- const feathersGenerators = 'generator-feathers/generators';
11
-
12
- Object.keys(meta).concat('upgrade').forEach(name => {
13
- const moduleName = name === 'plugin' ? 'generator-feathers-plugin' : `${feathersGenerators}/${name}`;
14
- env.register(require.resolve(moduleName), `feathers:${name}`);
15
- });
16
-
17
- module.exports = function (argv, generatorOptions = {}) {
18
- const pkg = require('../package.json');
19
- let description = 'Run a generator. Type can be\n';
20
-
21
- Object.keys(meta).forEach(name => {
22
- description += `\t• ${name} - ${meta[name]}\n`;
23
- });
24
-
25
- updateNotifier({ pkg }).notify();
26
-
27
- program.version(pkg.version)
28
- .usage('upgrade <version>')
29
- .usage('generate [type]');
30
-
31
- if (!semver.satisfies(process.version, '>= 8.0.0')) {
32
- console.error('The Feathers CLI and generated application requires Node v8.0.0 or later.');
33
- return process.exit(1);
34
- }
35
-
36
- program.command('generate [type]')
37
- .alias('g')
38
- .description(description)
39
- .action(type => {
40
- if (!type) {
41
- program.help();
42
- } else {
43
- env.run(`feathers:${type}`, generatorOptions);
44
- }
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.command = exports.generate = exports.commandRunner = void 0;
4
+ const pinion_1 = require("@feathershq/pinion");
5
+ const commons_1 = require("./commons");
6
+ const commandRunner = (yarg) => {
7
+ const ctx = (0, pinion_1.getContext)({
8
+ ...yarg.argv
45
9
  });
46
-
47
- program.command('upgrade')
48
- .alias('u')
49
- .description('Try to automatically upgrade to the latest Feathers version')
50
- .action(version => {
51
- if (parseInt(version) === 3) {
52
- upgrade(process.cwd());
53
- } else {
54
- env.run('feathers:upgrade', generatorOptions);
55
- }
56
- });
57
-
58
- program.command('*').action(() => program.help());
59
- program.parse(argv);
60
-
61
- if (argv.length === 2) {
62
- program.help();
63
- }
10
+ return (0, exports.generate)(ctx);
64
11
  };
12
+ exports.commandRunner = commandRunner;
13
+ const generate = (ctx) => (0, pinion_1.generator)(ctx)
14
+ .then((0, commons_1.initializeBaseContext)())
15
+ .then((0, pinion_1.runGenerator)(__dirname, (ctx) => `${ctx._[1]}`, 'index'));
16
+ exports.generate = generate;
17
+ const command = (yargs) => yargs
18
+ .command('generate', 'Run a generator', (yarg) => yarg
19
+ .command('app', 'Generate a new app', exports.commandRunner)
20
+ .command('service', 'Generate a service', exports.commandRunner)
21
+ .command('connection', 'Connect to a different database', exports.commandRunner)
22
+ .command('hook', 'Generate a hook', exports.commandRunner))
23
+ .usage('Usage: $0 <command> [options]')
24
+ .help();
25
+ exports.command = command;
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,+CAA8E;AAC9E,uCAAsE;AAE/D,MAAM,aAAa,GAAG,CAAC,IAAS,EAAE,EAAE;IACzC,MAAM,GAAG,GAAG,IAAA,mBAAU,EAAsB;QAC1C,GAAG,IAAI,CAAC,IAAI;KACb,CAAC,CAAA;IAEF,OAAO,IAAA,gBAAQ,EAAC,GAAG,CAAC,CAAA;AACtB,CAAC,CAAA;AANY,QAAA,aAAa,iBAMzB;AAEM,MAAM,QAAQ,GAAG,CAAC,GAAwB,EAAE,EAAE,CACnD,IAAA,kBAAS,EAAC,GAAG,CAAC;KACX,IAAI,CAAC,IAAA,+BAAqB,GAAE,CAAC;KAC7B,IAAI,CAAC,IAAA,qBAAY,EAAC,SAAS,EAAE,CAAC,GAAwB,EAAE,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC,CAAA;AAH3E,QAAA,QAAQ,YAGmE;AAEjF,MAAM,OAAO,GAAG,CAAC,KAAW,EAAE,EAAE,CACrC,KAAK;KACF,OAAO,CAAC,UAAU,EAAE,iBAAiB,EAAE,CAAC,IAAI,EAAE,EAAE,CAC/C,IAAI;KACD,OAAO,CAAC,KAAK,EAAE,oBAAoB,EAAE,qBAAa,CAAC;KACnD,OAAO,CAAC,SAAS,EAAE,oBAAoB,EAAE,qBAAa,CAAC;KACvD,OAAO,CAAC,YAAY,EAAE,iCAAiC,EAAE,qBAAa,CAAC;KACvE,OAAO,CAAC,MAAM,EAAE,iBAAiB,EAAE,qBAAa,CAAC,CACrD;KACA,KAAK,CAAC,+BAA+B,CAAC;KACtC,IAAI,EAAE,CAAA;AAVE,QAAA,OAAO,WAUT"}
package/lib/index.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { Argv, generator, runGenerator, getContext } from '@feathershq/pinion'
2
+ import { FeathersBaseContext, initializeBaseContext } from './commons'
3
+
4
+ export const commandRunner = (yarg: any) => {
5
+ const ctx = getContext<FeathersBaseContext>({
6
+ ...yarg.argv
7
+ })
8
+
9
+ return generate(ctx)
10
+ }
11
+
12
+ export const generate = (ctx: FeathersBaseContext) =>
13
+ generator(ctx)
14
+ .then(initializeBaseContext())
15
+ .then(runGenerator(__dirname, (ctx: FeathersBaseContext) => `${ctx._[1]}`, 'index'))
16
+
17
+ export const command = (yargs: Argv) =>
18
+ yargs
19
+ .command('generate', 'Run a generator', (yarg) =>
20
+ yarg
21
+ .command('app', 'Generate a new app', commandRunner)
22
+ .command('service', 'Generate a service', commandRunner)
23
+ .command('connection', 'Connect to a different database', commandRunner)
24
+ .command('hook', 'Generate a hook', commandRunner)
25
+ )
26
+ .usage('Usage: $0 <command> [options]')
27
+ .help()
@@ -0,0 +1,130 @@
1
+ import { FeathersBaseContext } from '../commons';
2
+ export interface ServiceGeneratorContext extends FeathersBaseContext {
3
+ /**
4
+ * The chosen service name
5
+ */
6
+ name: string;
7
+ /**
8
+ * The path the service is registered on
9
+ */
10
+ path: string;
11
+ /**
12
+ * The list of subfolders this service is in
13
+ */
14
+ folder: string[];
15
+ /**
16
+ * The `camelCase` service name starting with a lowercase letter
17
+ */
18
+ camelName: string;
19
+ /**
20
+ * The `CamelCase` service name starting with an uppercase letter
21
+ */
22
+ upperName: string;
23
+ /**
24
+ * The service class name combined as `CamelCaseService`
25
+ */
26
+ className: string;
27
+ /**
28
+ * A kebab-cased (filename friendly) version of the service name
29
+ */
30
+ kebabName: string;
31
+ /**
32
+ * The actual filename (the last element of the path)
33
+ */
34
+ fileName: string;
35
+ /**
36
+ * Indicates how many file paths we should go up to import other things (e.g. `../../`)
37
+ */
38
+ relative: string;
39
+ /**
40
+ * The chosen service type
41
+ */
42
+ type: 'knex' | 'mongodb' | 'custom';
43
+ /**
44
+ * Wether this service uses authentication
45
+ */
46
+ authentication: boolean;
47
+ /**
48
+ * Set to true if this service is for an authentication entity
49
+ */
50
+ isEntityService?: boolean;
51
+ /**
52
+ * The name of the schema file
53
+ */
54
+ schemaPath: string;
55
+ /**
56
+ * The name of the resolver file
57
+ */
58
+ resolverPath: string;
59
+ }
60
+ /**
61
+ * Parameters the generator is called with
62
+ */
63
+ export declare type ServiceGeneratorArguments = FeathersBaseContext & Partial<Pick<ServiceGeneratorContext, 'name' | 'path' | 'type' | 'authentication' | 'isEntityService'>>;
64
+ export declare const generate: (ctx: ServiceGeneratorArguments) => Promise<{
65
+ /**
66
+ * The chosen service name
67
+ */
68
+ name: string;
69
+ /**
70
+ * The path the service is registered on
71
+ */
72
+ path: string;
73
+ /**
74
+ * The list of subfolders this service is in
75
+ */
76
+ folder: string[];
77
+ /**
78
+ * The `camelCase` service name starting with a lowercase letter
79
+ */
80
+ camelName: string;
81
+ /**
82
+ * The `CamelCase` service name starting with an uppercase letter
83
+ */
84
+ upperName: string;
85
+ /**
86
+ * The service class name combined as `CamelCaseService`
87
+ */
88
+ className: string;
89
+ /**
90
+ * A kebab-cased (filename friendly) version of the service name
91
+ */
92
+ kebabName: string;
93
+ /**
94
+ * The actual filename (the last element of the path)
95
+ */
96
+ fileName: string;
97
+ /**
98
+ * Indicates how many file paths we should go up to import other things (e.g. `../../`)
99
+ */
100
+ relative: string;
101
+ /**
102
+ * The chosen service type
103
+ */
104
+ type: 'knex' | 'mongodb' | 'custom';
105
+ /**
106
+ * Wether this service uses authentication
107
+ */
108
+ authentication: boolean;
109
+ /**
110
+ * Set to true if this service is for an authentication entity
111
+ */
112
+ isEntityService?: boolean;
113
+ /**
114
+ * The name of the schema file
115
+ */
116
+ schemaPath: string;
117
+ /**
118
+ * The name of the resolver file
119
+ */
120
+ resolverPath: string;
121
+ feathers: import("../commons").FeathersAppInfo;
122
+ pkg: import("../commons").AppPackageJson;
123
+ lib: string;
124
+ test: string;
125
+ language: "js" | "ts";
126
+ dependencyVersions?: import("../commons").DependencyVersions;
127
+ cwd: string;
128
+ _?: (string | number)[];
129
+ pinion: import("@feathershq/pinion").Configuration;
130
+ }>;