@nocobase/server 0.7.0-alpha.9 → 0.7.1-alpha.6

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 (130) hide show
  1. package/lib/acl/available-action.js +37 -35
  2. package/lib/acl/index.js +45 -21
  3. package/lib/app-manager.d.ts +3 -3
  4. package/lib/app-manager.js +151 -72
  5. package/lib/application.d.ts +16 -4
  6. package/lib/application.js +414 -152
  7. package/lib/commands/console.d.ts +2 -3
  8. package/lib/commands/console.js +33 -24
  9. package/lib/commands/db-auth.d.ts +3 -0
  10. package/lib/commands/db-auth.js +26 -0
  11. package/lib/commands/db-clean.d.ts +3 -0
  12. package/lib/commands/db-clean.js +27 -0
  13. package/lib/commands/db-sync.d.ts +2 -4
  14. package/lib/commands/db-sync.js +25 -23
  15. package/lib/commands/index.d.ts +1 -2
  16. package/lib/commands/index.js +31 -29
  17. package/lib/commands/install.d.ts +2 -4
  18. package/lib/commands/install.js +66 -20
  19. package/lib/commands/migrator.d.ts +3 -0
  20. package/lib/commands/migrator.js +27 -0
  21. package/lib/commands/start.d.ts +2 -4
  22. package/lib/commands/start.js +28 -22
  23. package/lib/commands/upgrade.d.ts +6 -0
  24. package/lib/commands/upgrade.js +39 -0
  25. package/lib/helper.js +132 -61
  26. package/lib/index.d.ts +1 -0
  27. package/lib/index.js +100 -33
  28. package/lib/middlewares/data-wrapping.js +65 -55
  29. package/lib/middlewares/index.js +30 -14
  30. package/lib/middlewares/table2resource.js +89 -52
  31. package/lib/migration.d.ts +7 -0
  32. package/lib/migration.js +29 -0
  33. package/lib/plugin-manager.js +124 -55
  34. package/lib/plugin.d.ts +1 -0
  35. package/lib/plugin.js +67 -45
  36. package/lib/read-config.js +159 -64
  37. package/package.json +13 -14
  38. package/esm/acl/available-action.d.ts +0 -5
  39. package/esm/acl/available-action.js +0 -36
  40. package/esm/acl/available-action.js.map +0 -1
  41. package/esm/acl/index.d.ts +0 -2
  42. package/esm/acl/index.js +0 -19
  43. package/esm/acl/index.js.map +0 -1
  44. package/esm/app-manager.d.ts +0 -19
  45. package/esm/app-manager.js +0 -69
  46. package/esm/app-manager.js.map +0 -1
  47. package/esm/application.d.ts +0 -97
  48. package/esm/application.js +0 -156
  49. package/esm/application.js.map +0 -1
  50. package/esm/commands/console.d.ts +0 -4
  51. package/esm/commands/console.js +0 -25
  52. package/esm/commands/console.js.map +0 -1
  53. package/esm/commands/create-plugin/create-plugin.d.ts +0 -2
  54. package/esm/commands/create-plugin/create-plugin.js +0 -29
  55. package/esm/commands/create-plugin/create-plugin.js.map +0 -1
  56. package/esm/commands/create-plugin/index.d.ts +0 -5
  57. package/esm/commands/create-plugin/index.js +0 -6
  58. package/esm/commands/create-plugin/index.js.map +0 -1
  59. package/esm/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
  60. package/esm/commands/create-plugin/resources/templates/package-json.js +0 -11
  61. package/esm/commands/create-plugin/resources/templates/package-json.js.map +0 -1
  62. package/esm/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
  63. package/esm/commands/create-plugin/resources/templates/plugin.js +0 -12
  64. package/esm/commands/create-plugin/resources/templates/plugin.js.map +0 -1
  65. package/esm/commands/db-sync.d.ts +0 -5
  66. package/esm/commands/db-sync.js +0 -25
  67. package/esm/commands/db-sync.js.map +0 -1
  68. package/esm/commands/index.d.ts +0 -3
  69. package/esm/commands/index.js +0 -26
  70. package/esm/commands/index.js.map +0 -1
  71. package/esm/commands/install.d.ts +0 -5
  72. package/esm/commands/install.js +0 -23
  73. package/esm/commands/install.js.map +0 -1
  74. package/esm/commands/start.d.ts +0 -5
  75. package/esm/commands/start.js +0 -23
  76. package/esm/commands/start.js.map +0 -1
  77. package/esm/helper.d.ts +0 -7
  78. package/esm/helper.js +0 -59
  79. package/esm/helper.js.map +0 -1
  80. package/esm/index.d.ts +0 -7
  81. package/esm/index.js +0 -9
  82. package/esm/index.js.map +0 -1
  83. package/esm/middlewares/data-wrapping.d.ts +0 -3
  84. package/esm/middlewares/data-wrapping.js +0 -54
  85. package/esm/middlewares/data-wrapping.js.map +0 -1
  86. package/esm/middlewares/index.d.ts +0 -2
  87. package/esm/middlewares/index.js +0 -3
  88. package/esm/middlewares/index.js.map +0 -1
  89. package/esm/middlewares/table2resource.d.ts +0 -6
  90. package/esm/middlewares/table2resource.js +0 -51
  91. package/esm/middlewares/table2resource.js.map +0 -1
  92. package/esm/plugin-manager.d.ts +0 -23
  93. package/esm/plugin-manager.js +0 -57
  94. package/esm/plugin-manager.js.map +0 -1
  95. package/esm/plugin.d.ts +0 -32
  96. package/esm/plugin.js +0 -43
  97. package/esm/plugin.js.map +0 -1
  98. package/esm/read-config.d.ts +0 -8
  99. package/esm/read-config.js +0 -63
  100. package/esm/read-config.js.map +0 -1
  101. package/lib/acl/available-action.js.map +0 -1
  102. package/lib/acl/index.js.map +0 -1
  103. package/lib/app-manager.js.map +0 -1
  104. package/lib/application.js.map +0 -1
  105. package/lib/commands/console.js.map +0 -1
  106. package/lib/commands/create-plugin/create-plugin.d.ts +0 -2
  107. package/lib/commands/create-plugin/create-plugin.js +0 -31
  108. package/lib/commands/create-plugin/create-plugin.js.map +0 -1
  109. package/lib/commands/create-plugin/index.d.ts +0 -5
  110. package/lib/commands/create-plugin/index.js +0 -8
  111. package/lib/commands/create-plugin/index.js.map +0 -1
  112. package/lib/commands/create-plugin/resources/templates/package-json.d.ts +0 -11
  113. package/lib/commands/create-plugin/resources/templates/package-json.js +0 -13
  114. package/lib/commands/create-plugin/resources/templates/package-json.js.map +0 -1
  115. package/lib/commands/create-plugin/resources/templates/plugin.d.ts +0 -4
  116. package/lib/commands/create-plugin/resources/templates/plugin.js +0 -33
  117. package/lib/commands/create-plugin/resources/templates/plugin.js.map +0 -1
  118. package/lib/commands/db-sync.js.map +0 -1
  119. package/lib/commands/index.js.map +0 -1
  120. package/lib/commands/install.js.map +0 -1
  121. package/lib/commands/start.js.map +0 -1
  122. package/lib/helper.js.map +0 -1
  123. package/lib/index.js.map +0 -1
  124. package/lib/middlewares/data-wrapping.js.map +0 -1
  125. package/lib/middlewares/index.js.map +0 -1
  126. package/lib/middlewares/table2resource.js.map +0 -1
  127. package/lib/plugin-manager.js.map +0 -1
  128. package/lib/plugin.js.map +0 -1
  129. package/lib/read-config.js.map +0 -1
  130. package/tsconfig.build.json +0 -9
package/esm/acl/index.js DELETED
@@ -1,19 +0,0 @@
1
- import { ACL } from '@nocobase/acl';
2
- import { availableActions } from './available-action';
3
- const configureResources = [
4
- 'roles',
5
- 'collections',
6
- 'roles.collections',
7
- 'roles.resources',
8
- 'rolesResourcesScopes',
9
- 'availableActions',
10
- ];
11
- export function createACL() {
12
- const acl = new ACL();
13
- for (const [actionName, actionParams] of Object.entries(availableActions)) {
14
- acl.setAvailableAction(actionName, actionParams);
15
- }
16
- acl.registerConfigResources(configureResources);
17
- return acl;
18
- }
19
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/acl/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,kBAAkB,GAAG;IACzB,OAAO;IACP,aAAa;IACb,mBAAmB;IACnB,iBAAiB;IACjB,sBAAsB;IACtB,kBAAkB;CACnB,CAAC;AAEF,MAAM,UAAU,SAAS;IACvB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAE,CAAC;IAEtB,KAAK,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE;QACzE,GAAG,CAAC,kBAAkB,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;KAClD;IAED,GAAG,CAAC,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;IAEhD,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["import { ACL } from '@nocobase/acl';\nimport { availableActions } from './available-action';\n\nconst configureResources = [\n 'roles',\n 'collections',\n 'roles.collections',\n 'roles.resources',\n 'rolesResourcesScopes',\n 'availableActions',\n];\n\nexport function createACL() {\n const acl = new ACL();\n\n for (const [actionName, actionParams] of Object.entries(availableActions)) {\n acl.setAvailableAction(actionName, actionParams);\n }\n\n acl.registerConfigResources(configureResources);\n\n return acl;\n}\n"]}
@@ -1,19 +0,0 @@
1
- /// <reference types="node" />
2
- import Application, { ApplicationOptions } from './application';
3
- import http, { IncomingMessage } from 'http';
4
- import EventEmitter from 'events';
5
- declare type AppSelector = (req: IncomingMessage) => Application | string | undefined | null;
6
- export declare class AppManager extends EventEmitter {
7
- private app;
8
- applications: Map<string, Application>;
9
- constructor(app: Application);
10
- appSelector: AppSelector;
11
- createApplication(name: string, options: ApplicationOptions): Application;
12
- removeApplication(name: string): Promise<void>;
13
- setAppSelector(selector: AppSelector): void;
14
- listen(...args: any[]): http.Server;
15
- getApplication(appName: string): Promise<null | Application>;
16
- callback(): (req: any, res: any) => Promise<void>;
17
- emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
18
- }
19
- export {};
@@ -1,69 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import Application from './application';
11
- import http from 'http';
12
- import EventEmitter from 'events';
13
- import { applyMixins, AsyncEmitter } from '@nocobase/utils';
14
- export class AppManager extends EventEmitter {
15
- constructor(app) {
16
- super();
17
- this.app = app;
18
- this.applications = new Map();
19
- this.appSelector = (req) => this.app;
20
- app.on('beforeStop', (mainApp, options) => __awaiter(this, void 0, void 0, function* () {
21
- return yield Promise.all([...this.applications.values()].map((application) => application.stop(options)));
22
- }));
23
- app.on('afterDestroy', (mainApp, options) => __awaiter(this, void 0, void 0, function* () {
24
- return yield Promise.all([...this.applications.values()].map((application) => application.destroy(options)));
25
- }));
26
- }
27
- createApplication(name, options) {
28
- const application = new Application(options);
29
- this.applications.set(name, application);
30
- return application;
31
- }
32
- removeApplication(name) {
33
- return __awaiter(this, void 0, void 0, function* () {
34
- const application = this.applications.get(name);
35
- if (!application) {
36
- return;
37
- }
38
- yield application.destroy();
39
- this.applications.delete(name);
40
- });
41
- }
42
- setAppSelector(selector) {
43
- this.appSelector = selector;
44
- }
45
- listen(...args) {
46
- const server = http.createServer(this.callback());
47
- return server.listen(...args);
48
- }
49
- getApplication(appName) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- yield this.emitAsync('beforeGetApplication', {
52
- appManager: this,
53
- name: appName,
54
- });
55
- return this.applications.get(appName);
56
- });
57
- }
58
- callback() {
59
- return (req, res) => __awaiter(this, void 0, void 0, function* () {
60
- let handleApp = this.appSelector(req) || this.app;
61
- if (typeof handleApp === 'string') {
62
- handleApp = (yield this.getApplication(handleApp)) || this.app;
63
- }
64
- handleApp.callback()(req, res);
65
- });
66
- }
67
- }
68
- applyMixins(AppManager, [AsyncEmitter]);
69
- //# sourceMappingURL=app-manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"app-manager.js","sourceRoot":"","sources":["../src/app-manager.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,WAAmC,MAAM,eAAe,CAAC;AAChE,OAAO,IAAyB,MAAM,MAAM,CAAC;AAC7C,OAAO,YAAY,MAAM,QAAQ,CAAC;AAClC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI5D,MAAM,OAAO,UAAW,SAAQ,YAAY;IAG1C,YAAoB,GAAgB;QAClC,KAAK,EAAE,CAAC;QADU,QAA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C,CAAC;QACjC,CAAC;KAAA;IAED,cAAc,CAAC,QAAqB;QAClC,IAAI,CAAC,WAAW,GAAG,QAAQ,CAAC;IAC9B,CAAC;IAED,MAAM,CAAC,GAAG,IAAI;QACZ,MAAM,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QAClD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;IAChC,CAAC;IAEK,cAAc,CAAC,OAAe;;YAClC,MAAM,IAAI,CAAC,SAAS,CAAC,sBAAsB,EAAE;gBAC3C,UAAU,EAAE,IAAI;gBAChB,IAAI,EAAE,OAAO;aACd,CAAC,CAAC;YAEH,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QACxC,CAAC;KAAA;IAED,QAAQ;QACN,OAAO,CAAO,GAAG,EAAE,GAAG,EAAE,EAAE;YACxB,IAAI,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC;YAElD,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE;gBACjC,SAAS,GAAG,CAAC,MAAM,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC;aAChE;YAED,SAAS,CAAC,QAAQ,EAAE,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;QACjC,CAAC,CAAA,CAAC;IACJ,CAAC;CAGF;AAED,WAAW,CAAC,UAAU,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC","sourcesContent":["import Application, { ApplicationOptions } from './application';\nimport http, { IncomingMessage } from 'http';\nimport EventEmitter from 'events';\nimport { applyMixins, AsyncEmitter } from '@nocobase/utils';\n\ntype AppSelector = (req: IncomingMessage) => Application | string | undefined | null;\n\nexport class AppManager extends EventEmitter {\n public applications: Map<string, Application> = new Map<string, Application>();\n\n constructor(private app: Application) {\n super();\n\n app.on('beforeStop', async (mainApp, options) => {\n return await Promise.all(\n [...this.applications.values()].map((application: Application) => application.stop(options)),\n );\n });\n\n app.on('afterDestroy', async (mainApp, options) => {\n return await Promise.all(\n [...this.applications.values()].map((application: Application) => application.destroy(options)),\n );\n });\n }\n\n appSelector: AppSelector = (req: IncomingMessage) => this.app;\n\n createApplication(name: string, options: ApplicationOptions): Application {\n const application = new Application(options);\n this.applications.set(name, application);\n return application;\n }\n\n async removeApplication(name: string) {\n const application = this.applications.get(name);\n if (!application) {\n return;\n }\n\n await application.destroy();\n\n this.applications.delete(name);\n }\n\n setAppSelector(selector: AppSelector) {\n this.appSelector = selector;\n }\n\n listen(...args) {\n const server = http.createServer(this.callback());\n return server.listen(...args);\n }\n\n async getApplication(appName: string): Promise<null | Application> {\n await this.emitAsync('beforeGetApplication', {\n appManager: this,\n name: appName,\n });\n\n return this.applications.get(appName);\n }\n\n callback() {\n return async (req, res) => {\n let handleApp = this.appSelector(req) || this.app;\n\n if (typeof handleApp === 'string') {\n handleApp = (await this.getApplication(handleApp)) || this.app;\n }\n\n handleApp.callback()(req, res);\n };\n }\n\n emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;\n}\n\napplyMixins(AppManager, [AsyncEmitter]);\n"]}
@@ -1,97 +0,0 @@
1
- /// <reference types="node" />
2
- /// <reference types="koa-bodyparser" />
3
- import { ACL } from '@nocobase/acl';
4
- import Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';
5
- import Resourcer, { ResourceOptions } from '@nocobase/resourcer';
6
- import { AsyncEmitter } from '@nocobase/utils';
7
- import { Command, CommandOptions } from 'commander';
8
- import { Server } from 'http';
9
- import { i18n, InitOptions } from 'i18next';
10
- import Koa from 'koa';
11
- import { AppManager } from './app-manager';
12
- import { Plugin } from './plugin';
13
- import { InstallOptions, PluginManager } from './plugin-manager';
14
- export declare type PluginConfiguration = string | [string, any];
15
- export declare type PluginsConfigurations = Array<PluginConfiguration>;
16
- export interface ResourcerOptions {
17
- prefix?: string;
18
- }
19
- export interface ApplicationOptions {
20
- database?: IDatabaseOptions | Database;
21
- resourcer?: ResourcerOptions;
22
- bodyParser?: any;
23
- cors?: any;
24
- dataWrapping?: boolean;
25
- registerActions?: boolean;
26
- i18n?: i18n | InitOptions;
27
- plugins?: PluginsConfigurations;
28
- }
29
- interface DefaultState {
30
- currentUser?: any;
31
- [key: string]: any;
32
- }
33
- interface DefaultContext {
34
- db: Database;
35
- resourcer: Resourcer;
36
- [key: string]: any;
37
- }
38
- interface MiddlewareOptions {
39
- name?: string;
40
- resourceName?: string;
41
- resourceNames?: string[];
42
- insertBefore?: string;
43
- insertAfter?: string;
44
- }
45
- interface ActionsOptions {
46
- resourceName?: string;
47
- resourceNames?: string[];
48
- }
49
- interface ListenOptions {
50
- port?: number | undefined;
51
- host?: string | undefined;
52
- backlog?: number | undefined;
53
- path?: string | undefined;
54
- exclusive?: boolean | undefined;
55
- readableAll?: boolean | undefined;
56
- writableAll?: boolean | undefined;
57
- /**
58
- * @default false
59
- */
60
- ipv6Only?: boolean | undefined;
61
- signal?: AbortSignal | undefined;
62
- }
63
- interface StartOptions {
64
- cliArgs?: any[];
65
- listen?: ListenOptions;
66
- }
67
- export declare class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {
68
- options: ApplicationOptions;
69
- readonly db: Database;
70
- readonly resourcer: Resourcer;
71
- readonly cli: Command;
72
- readonly i18n: i18n;
73
- readonly pm: PluginManager;
74
- readonly acl: ACL;
75
- readonly appManager: AppManager;
76
- protected plugins: Map<string, Plugin<any>>;
77
- listenServer: Server;
78
- constructor(options: ApplicationOptions);
79
- plugin<O = any>(pluginClass: any, options?: O): Plugin<O>;
80
- loadPluginConfig(pluginsConfigurations: PluginsConfigurations): void;
81
- use<NewStateT = {}, NewContextT = {}>(middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>, options?: MiddlewareOptions): Koa<Koa.DefaultState & StateT & NewStateT, Koa.DefaultContext & ContextT & NewContextT>;
82
- collection(options: CollectionOptions): import("@nocobase/database").Collection<any, any>;
83
- resource(options: ResourceOptions): import("@nocobase/resourcer").Resource;
84
- actions(handlers: any, options?: ActionsOptions): void;
85
- command(name: string, desc?: string, opts?: CommandOptions): Command;
86
- findCommand(name: string): Command;
87
- load(): Promise<void>;
88
- getPlugin<P extends Plugin>(name: string): P;
89
- parse(argv?: string[]): Promise<Command>;
90
- start(options?: StartOptions): Promise<void>;
91
- listen(...args: any[]): Server;
92
- stop(options?: any): Promise<void>;
93
- destroy(options?: any): Promise<void>;
94
- install(options?: InstallOptions): Promise<void>;
95
- emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;
96
- }
97
- export default Application;
@@ -1,156 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { registerActions } from '@nocobase/actions';
11
- import { applyMixins, AsyncEmitter } from '@nocobase/utils';
12
- import Koa from 'koa';
13
- import { isBoolean } from 'lodash';
14
- import { createACL } from './acl';
15
- import { AppManager } from './app-manager';
16
- import { createCli } from './commands';
17
- import { createDatabase, createI18n, createResourcer, registerMiddlewares } from './helper';
18
- import { PluginManager } from './plugin-manager';
19
- export class Application extends Koa {
20
- constructor(options) {
21
- super();
22
- this.options = options;
23
- this.plugins = new Map();
24
- this.acl = createACL();
25
- this.db = createDatabase(options);
26
- this.resourcer = createResourcer(options);
27
- this.cli = createCli(this);
28
- this.i18n = createI18n(options);
29
- this.pm = new PluginManager({
30
- app: this,
31
- });
32
- this.appManager = new AppManager(this);
33
- registerMiddlewares(this, options);
34
- if (options.registerActions !== false) {
35
- registerActions(this);
36
- }
37
- this.loadPluginConfig(options.plugins || []);
38
- }
39
- plugin(pluginClass, options) {
40
- return this.pm.add(pluginClass, options);
41
- }
42
- loadPluginConfig(pluginsConfigurations) {
43
- for (let pluginConfiguration of pluginsConfigurations) {
44
- if (typeof pluginConfiguration == 'string') {
45
- pluginConfiguration = [pluginConfiguration, {}];
46
- }
47
- const plugin = PluginManager.resolvePlugin(pluginConfiguration[0]);
48
- const pluginOptions = pluginConfiguration[1];
49
- this.plugin(plugin, pluginOptions);
50
- }
51
- }
52
- use(middleware, options) {
53
- // @ts-ignore
54
- return super.use(middleware);
55
- }
56
- collection(options) {
57
- return this.db.collection(options);
58
- }
59
- resource(options) {
60
- return this.resourcer.define(options);
61
- }
62
- actions(handlers, options) {
63
- return this.resourcer.registerActions(handlers);
64
- }
65
- command(name, desc, opts) {
66
- return this.cli.command(name, desc, opts);
67
- }
68
- findCommand(name) {
69
- return this.cli._findCommand(name);
70
- }
71
- load() {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- yield this.pm.load();
74
- });
75
- }
76
- getPlugin(name) {
77
- return this.pm.get(name);
78
- }
79
- parse(argv = process.argv) {
80
- return __awaiter(this, void 0, void 0, function* () {
81
- yield this.load();
82
- return this.cli.parseAsync(argv);
83
- });
84
- }
85
- start(options) {
86
- var _a;
87
- return __awaiter(this, void 0, void 0, function* () {
88
- // reconnect database
89
- if (this.db.closed()) {
90
- yield this.db.reconnect();
91
- }
92
- yield this.emitAsync('beforeStart', this, options);
93
- if ((_a = options === null || options === void 0 ? void 0 : options.listen) === null || _a === void 0 ? void 0 : _a.port) {
94
- const listen = () => new Promise((resolve) => {
95
- const Server = this.listen(options === null || options === void 0 ? void 0 : options.listen, () => {
96
- resolve(Server);
97
- });
98
- });
99
- // @ts-ignore
100
- this.listenServer = yield listen();
101
- }
102
- yield this.emitAsync('afterStart', this, options);
103
- });
104
- }
105
- listen(...args) {
106
- return this.appManager.listen(...args);
107
- }
108
- stop(options) {
109
- return __awaiter(this, void 0, void 0, function* () {
110
- yield this.emitAsync('beforeStop', this, options);
111
- try {
112
- // close database connection
113
- // silent if database already closed
114
- yield this.db.close();
115
- }
116
- catch (e) {
117
- console.log(e);
118
- }
119
- // close http server
120
- if (this.listenServer) {
121
- const closeServer = () => new Promise((resolve, reject) => {
122
- this.listenServer.close((err) => {
123
- if (err) {
124
- return reject(err);
125
- }
126
- this.listenServer = null;
127
- resolve(true);
128
- });
129
- });
130
- yield closeServer();
131
- }
132
- yield this.emitAsync('afterStop', this, options);
133
- });
134
- }
135
- destroy(options) {
136
- return __awaiter(this, void 0, void 0, function* () {
137
- yield this.emitAsync('beforeDestroy', this, options);
138
- yield this.stop(options);
139
- yield this.emitAsync('afterDestroy', this, options);
140
- });
141
- }
142
- install(options) {
143
- return __awaiter(this, void 0, void 0, function* () {
144
- yield this.emitAsync('beforeInstall', this, options);
145
- if (options === null || options === void 0 ? void 0 : options.clean) {
146
- yield this.db.clean(isBoolean(options.clean) ? { drop: options.clean } : options.clean);
147
- }
148
- yield this.db.sync(options === null || options === void 0 ? void 0 : options.sync);
149
- yield this.pm.install(options);
150
- yield this.emitAsync('afterInstall', this, options);
151
- });
152
- }
153
- }
154
- applyMixins(Application, [AsyncEmitter]);
155
- export default Application;
156
- //# sourceMappingURL=application.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGpD,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI5D,OAAO,GAAG,MAAM,KAAK,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AACnC,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAC3C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AAK,CAAC,CAAC;aACzF;YAED,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,IAAI,CAAC,CAAC;YAClC,MAAM,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;YAC/B,MAAM,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;QACtD,CAAC;KAAA;CAGF;AAED,WAAW,CAAC,WAAW,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;AAEzC,eAAe,WAAW,CAAC","sourcesContent":["import { ACL } from '@nocobase/acl';\nimport { registerActions } from '@nocobase/actions';\nimport Database, { CollectionOptions, IDatabaseOptions } from '@nocobase/database';\nimport Resourcer, { ResourceOptions } from '@nocobase/resourcer';\nimport { applyMixins, AsyncEmitter } from '@nocobase/utils';\nimport { Command, CommandOptions } from 'commander';\nimport { Server } from 'http';\nimport { i18n, InitOptions } from 'i18next';\nimport Koa from 'koa';\nimport { isBoolean } from 'lodash';\nimport { createACL } from './acl';\nimport { AppManager } from './app-manager';\nimport { createCli } from './commands';\nimport { createDatabase, createI18n, createResourcer, registerMiddlewares } from './helper';\nimport { Plugin } from './plugin';\nimport { InstallOptions, PluginManager } from './plugin-manager';\n\nexport type PluginConfiguration = string | [string, any];\nexport type PluginsConfigurations = Array<PluginConfiguration>;\n\nexport interface ResourcerOptions {\n prefix?: string;\n}\n\nexport interface ApplicationOptions {\n database?: IDatabaseOptions | Database;\n resourcer?: ResourcerOptions;\n bodyParser?: any;\n cors?: any;\n dataWrapping?: boolean;\n registerActions?: boolean;\n i18n?: i18n | InitOptions;\n plugins?: PluginsConfigurations;\n}\n\ninterface DefaultState {\n currentUser?: any;\n [key: string]: any;\n}\n\ninterface DefaultContext {\n db: Database;\n resourcer: Resourcer;\n [key: string]: any;\n}\n\ninterface MiddlewareOptions {\n name?: string;\n resourceName?: string;\n resourceNames?: string[];\n insertBefore?: string;\n insertAfter?: string;\n}\n\ninterface ActionsOptions {\n resourceName?: string;\n resourceNames?: string[];\n}\n\ninterface ListenOptions {\n port?: number | undefined;\n host?: string | undefined;\n backlog?: number | undefined;\n path?: string | undefined;\n exclusive?: boolean | undefined;\n readableAll?: boolean | undefined;\n writableAll?: boolean | undefined;\n /**\n * @default false\n */\n ipv6Only?: boolean | undefined;\n signal?: AbortSignal | undefined;\n}\n\ninterface StartOptions {\n cliArgs?: any[];\n listen?: ListenOptions;\n}\n\nexport class Application<StateT = DefaultState, ContextT = DefaultContext> extends Koa implements AsyncEmitter {\n public readonly db: Database;\n\n public readonly resourcer: Resourcer;\n\n public readonly cli: Command;\n\n public readonly i18n: i18n;\n\n public readonly pm: PluginManager;\n\n public readonly acl: ACL;\n\n public readonly appManager: AppManager;\n\n protected plugins = new Map<string, Plugin>();\n\n public listenServer: Server;\n\n constructor(public options: ApplicationOptions) {\n super();\n\n this.acl = createACL();\n this.db = createDatabase(options);\n this.resourcer = createResourcer(options);\n this.cli = createCli(this);\n this.i18n = createI18n(options);\n\n this.pm = new PluginManager({\n app: this,\n });\n\n this.appManager = new AppManager(this);\n\n registerMiddlewares(this, options);\n\n if (options.registerActions !== false) {\n registerActions(this);\n }\n\n this.loadPluginConfig(options.plugins || []);\n }\n\n plugin<O = any>(pluginClass: any, options?: O): Plugin<O> {\n return this.pm.add(pluginClass, options);\n }\n\n loadPluginConfig(pluginsConfigurations: PluginsConfigurations) {\n for (let pluginConfiguration of pluginsConfigurations) {\n if (typeof pluginConfiguration == 'string') {\n pluginConfiguration = [pluginConfiguration, {}];\n }\n\n const plugin = PluginManager.resolvePlugin(pluginConfiguration[0]);\n const pluginOptions = pluginConfiguration[1];\n\n this.plugin(plugin, pluginOptions);\n }\n }\n\n use<NewStateT = {}, NewContextT = {}>(\n middleware: Koa.Middleware<StateT & NewStateT, ContextT & NewContextT>,\n options?: MiddlewareOptions,\n ) {\n // @ts-ignore\n return super.use(middleware);\n }\n\n collection(options: CollectionOptions) {\n return this.db.collection(options);\n }\n\n resource(options: ResourceOptions) {\n return this.resourcer.define(options);\n }\n\n actions(handlers: any, options?: ActionsOptions) {\n return this.resourcer.registerActions(handlers);\n }\n\n command(name: string, desc?: string, opts?: CommandOptions): Command {\n return this.cli.command(name, desc, opts);\n }\n\n findCommand(name: string): Command {\n return (<any>this.cli)._findCommand(name);\n }\n\n async load() {\n await this.pm.load();\n }\n\n getPlugin<P extends Plugin>(name: string) {\n return this.pm.get(name) as P;\n }\n\n async parse(argv = process.argv) {\n await this.load();\n return this.cli.parseAsync(argv);\n }\n\n async start(options?: StartOptions) {\n // reconnect database\n if (this.db.closed()) {\n await this.db.reconnect();\n }\n\n await this.emitAsync('beforeStart', this, options);\n\n if (options?.listen?.port) {\n const listen = () =>\n new Promise((resolve) => {\n const Server = this.listen(options?.listen, () => {\n resolve(Server);\n });\n });\n\n // @ts-ignore\n this.listenServer = await listen();\n }\n\n await this.emitAsync('afterStart', this, options);\n }\n\n listen(...args): Server {\n return this.appManager.listen(...args);\n }\n\n async stop(options?: any) {\n await this.emitAsync('beforeStop', this, options);\n\n try {\n // close database connection\n // silent if database already closed\n await this.db.close();\n } catch (e) {\n console.log(e);\n }\n\n // close http server\n if (this.listenServer) {\n const closeServer = () =>\n new Promise((resolve, reject) => {\n this.listenServer.close((err) => {\n if (err) {\n return reject(err);\n }\n this.listenServer = null;\n resolve(true);\n });\n });\n\n await closeServer();\n }\n\n await this.emitAsync('afterStop', this, options);\n }\n\n async destroy(options?: any) {\n await this.emitAsync('beforeDestroy', this, options);\n await this.stop(options);\n await this.emitAsync('afterDestroy', this, options);\n }\n\n async install(options?: InstallOptions) {\n await this.emitAsync('beforeInstall', this, options);\n\n if (options?.clean) {\n await this.db.clean(isBoolean(options.clean) ? { drop: options.clean } : options.clean);\n }\n\n await this.db.sync(options?.sync);\n await this.pm.install(options);\n await this.emitAsync('afterInstall', this, options);\n }\n\n emitAsync: (event: string | symbol, ...args: any[]) => Promise<boolean>;\n}\n\napplyMixins(Application, [AsyncEmitter]);\n\nexport default Application;\n"]}
@@ -1,4 +0,0 @@
1
- declare const _default: ({ app }: {
2
- app: any;
3
- }) => Promise<void>;
4
- export default _default;
@@ -1,25 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- const REPL = require('repl');
11
- export default ({ app }) => __awaiter(void 0, void 0, void 0, function* () {
12
- yield app.start();
13
- const repl = (REPL.start('nocobase > ').context.app = app);
14
- repl.on('exit', function (err) {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- if (err) {
17
- console.log(err);
18
- process.exit(1);
19
- }
20
- yield app.stop();
21
- process.exit(0);
22
- });
23
- });
24
- });
25
- //# sourceMappingURL=console.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"console.js","sourceRoot":"","sources":["../../src/commands/console.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAE7B,eAAe,CAAO,EAAE,GAAG,EAAE,EAAE,EAAE;IAC/B,MAAM,GAAG,CAAC,KAAK,EAAE,CAAC;IAClB,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG,GAAG,CAAC,CAAC;IAE3D,IAAI,CAAC,EAAE,CAAC,MAAM,EAAE,UAAgB,GAAG;;YACjC,IAAI,GAAG,EAAE;gBACP,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;aACjB;YAED,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YACjB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC;KAAA,CAAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["const REPL = require('repl');\n\nexport default async ({ app }) => {\n await app.start();\n const repl = (REPL.start('nocobase > ').context.app = app);\n\n repl.on('exit', async function (err) {\n if (err) {\n console.log(err);\n process.exit(1);\n }\n\n await app.stop();\n process.exit(0);\n });\n};\n"]}
@@ -1,2 +0,0 @@
1
- declare const _default: (name: any) => Promise<void>;
2
- export default _default;
@@ -1,29 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- const chalk = require('chalk');
11
- const fse = require('fs-extra');
12
- const { join } = require('path');
13
- const createPackageJson = require('./resources/templates/package-json');
14
- const createPluginClass = require('./resources/templates/plugin');
15
- export default (name) => __awaiter(void 0, void 0, void 0, function* () {
16
- const pluginName = `plugin-${name}`;
17
- const pluginPath = join(process.cwd(), `packages/${pluginName}`);
18
- const resourcePath = join(__dirname, 'resources');
19
- console.log(`Creating a new NocoBase plugin at ${chalk.green(pluginPath)}.`);
20
- yield fse.copy(join(resourcePath, 'files'), pluginPath);
21
- yield fse.outputFile(join(pluginPath, 'src/server/index.ts'), createPluginClass({ name }));
22
- // write server package.json
23
- yield fse.writeJson(join(pluginPath, 'package.json'), createPackageJson({
24
- name: pluginName,
25
- }), {
26
- spaces: 2,
27
- });
28
- });
29
- //# sourceMappingURL=create-plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create-plugin.js","sourceRoot":"","sources":["../../../src/commands/create-plugin/create-plugin.ts"],"names":[],"mappings":";;;;;;;;;AAAA,MAAM,KAAK,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;AAC/B,MAAM,GAAG,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAChC,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AACjC,MAAM,iBAAiB,GAAG,OAAO,CAAC,oCAAoC,CAAC,CAAC;AACxE,MAAM,iBAAiB,GAAG,OAAO,CAAC,8BAA8B,CAAC,CAAC;AAElE,eAAe,CAAO,IAAI,EAAE,EAAE;IAC5B,MAAM,UAAU,GAAG,UAAU,IAAI,EAAE,CAAC;IAEpC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,YAAY,UAAU,EAAE,CAAC,CAAC;IACjE,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,CAAC,CAAC;IAElD,OAAO,CAAC,GAAG,CAAC,qCAAqC,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAC7E,MAAM,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,UAAU,CAAC,CAAC;IAExD,MAAM,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,UAAU,EAAE,qBAAqB,CAAC,EAAE,iBAAiB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE3F,4BAA4B;IAC5B,MAAM,GAAG,CAAC,SAAS,CACjB,IAAI,CAAC,UAAU,EAAE,cAAc,CAAC,EAChC,iBAAiB,CAAC;QAChB,IAAI,EAAE,UAAU;KACjB,CAAC,EACF;QACE,MAAM,EAAE,CAAC;KACV,CACF,CAAC;AACJ,CAAC,CAAA,CAAC","sourcesContent":["const chalk = require('chalk');\nconst fse = require('fs-extra');\nconst { join } = require('path');\nconst createPackageJson = require('./resources/templates/package-json');\nconst createPluginClass = require('./resources/templates/plugin');\n\nexport default async (name) => {\n const pluginName = `plugin-${name}`;\n\n const pluginPath = join(process.cwd(), `packages/${pluginName}`);\n const resourcePath = join(__dirname, 'resources');\n\n console.log(`Creating a new NocoBase plugin at ${chalk.green(pluginPath)}.`);\n await fse.copy(join(resourcePath, 'files'), pluginPath);\n\n await fse.outputFile(join(pluginPath, 'src/server/index.ts'), createPluginClass({ name }));\n\n // write server package.json\n await fse.writeJson(\n join(pluginPath, 'package.json'),\n createPackageJson({\n name: pluginName,\n }),\n {\n spaces: 2,\n },\n );\n};\n"]}
@@ -1,5 +0,0 @@
1
- declare const _default: ({ app, cliArgs }: {
2
- app: any;
3
- cliArgs: any;
4
- }) => void;
5
- export default _default;
@@ -1,6 +0,0 @@
1
- const createPlugin = require('./create-plugin');
2
- export default ({ app, cliArgs }) => {
3
- const name = cliArgs[0];
4
- createPlugin(name);
5
- };
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/create-plugin/index.ts"],"names":[],"mappings":"AAAA,MAAM,YAAY,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAChD,eAAe,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACxB,YAAY,CAAC,IAAI,CAAC,CAAC;AACrB,CAAC,CAAC","sourcesContent":["const createPlugin = require('./create-plugin');\nexport default ({ app, cliArgs }) => {\n const name = cliArgs[0];\n createPlugin(name);\n};\n"]}
@@ -1,11 +0,0 @@
1
- declare const _default: ({ name }: {
2
- name: any;
3
- }) => {
4
- name: any;
5
- version: string;
6
- main: string;
7
- dependencies: {
8
- '@nocobase/server': string;
9
- };
10
- };
11
- export default _default;
@@ -1,11 +0,0 @@
1
- export default ({ name }) => {
2
- return {
3
- name: name,
4
- version: '0.1.0',
5
- main: 'server.js',
6
- dependencies: {
7
- '@nocobase/server': '^0.6.0-alpha.0',
8
- },
9
- };
10
- };
11
- //# sourceMappingURL=package-json.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"package-json.js","sourceRoot":"","sources":["../../../../../src/commands/create-plugin/resources/templates/package-json.ts"],"names":[],"mappings":"AAAA,eAAe,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC1B,OAAO;QACL,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,OAAO;QAChB,IAAI,EAAE,WAAW;QACjB,YAAY,EAAE;YACZ,kBAAkB,EAAE,gBAAgB;SACrC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["export default ({ name }) => {\n return {\n name: name,\n version: '0.1.0',\n main: 'server.js',\n dependencies: {\n '@nocobase/server': '^0.6.0-alpha.0',\n },\n };\n};\n"]}
@@ -1,4 +0,0 @@
1
- declare const _default: ({ name }: {
2
- name: any;
3
- }) => string;
4
- export default _default;
@@ -1,12 +0,0 @@
1
- import * as _ from 'lodash';
2
- import * as fs from 'fs';
3
- import * as path from 'path';
4
- export default ({ name }) => {
5
- const tmpl = fs.readFileSync(path.join(__dirname, 'plugin-class.template'), { encoding: 'utf-8' });
6
- const compile = _.template(tmpl);
7
- return compile({
8
- name,
9
- className: _.startCase(_.camelCase(name)),
10
- });
11
- };
12
- //# sourceMappingURL=plugin.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../../../src/commands/create-plugin/resources/templates/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,QAAQ,CAAC;AAC5B,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,eAAe,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE;IAC1B,MAAM,IAAI,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,uBAAuB,CAAC,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC;IACnG,MAAM,OAAO,GAAG,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IAEjC,OAAO,OAAO,CAAC;QACb,IAAI;QACJ,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KAC1C,CAAC,CAAC;AACL,CAAC,CAAC","sourcesContent":["import * as _ from 'lodash';\nimport * as fs from 'fs';\nimport * as path from 'path';\n\nexport default ({ name }) => {\n const tmpl = fs.readFileSync(path.join(__dirname, 'plugin-class.template'), { encoding: 'utf-8' });\n const compile = _.template(tmpl);\n\n return compile({\n name,\n className: _.startCase(_.camelCase(name)),\n });\n};\n"]}
@@ -1,5 +0,0 @@
1
- declare const _default: ({ app, cliArgs }: {
2
- app: any;
3
- cliArgs: any;
4
- }) => Promise<void>;
5
- export default _default;
@@ -1,25 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- export default ({ app, cliArgs }) => __awaiter(void 0, void 0, void 0, function* () {
11
- const [opts] = cliArgs;
12
- console.log('db sync...');
13
- yield app.db.sync(opts.force
14
- ? {
15
- force: true,
16
- alter: {
17
- drop: true,
18
- },
19
- }
20
- : {});
21
- yield app.stop({
22
- cliArgs,
23
- });
24
- });
25
- //# sourceMappingURL=db-sync.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"db-sync.js","sourceRoot":"","sources":["../../src/commands/db-sync.ts"],"names":[],"mappings":";;;;;;;;;AAAA,eAAe,CAAO,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE;IACxC,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC;IACvB,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC1B,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CACf,IAAI,CAAC,KAAK;QACR,CAAC,CAAC;YACE,KAAK,EAAE,IAAI;YACX,KAAK,EAAE;gBACL,IAAI,EAAE,IAAI;aACX;SACF;QACH,CAAC,CAAC,EAAE,CACP,CAAC;IACF,MAAM,GAAG,CAAC,IAAI,CAAC;QACb,OAAO;KACR,CAAC,CAAC;AACL,CAAC,CAAA,CAAC","sourcesContent":["export default async ({ app, cliArgs }) => {\n const [opts] = cliArgs;\n console.log('db sync...');\n await app.db.sync(\n opts.force\n ? {\n force: true,\n alter: {\n drop: true,\n },\n }\n : {},\n );\n await app.stop({\n cliArgs,\n });\n};\n"]}
@@ -1,3 +0,0 @@
1
- import Application from '../application';
2
- import { Command } from 'commander';
3
- export declare function createCli(app: Application): Command;
@@ -1,26 +0,0 @@
1
- import { Command } from 'commander';
2
- export function createCli(app) {
3
- const program = new Command();
4
- const runSubCommand = (name) => (...cliArgs) => {
5
- const command = require(`./${name}`).default;
6
- Promise.resolve()
7
- .then(() => {
8
- return command({ app, cliArgs });
9
- })
10
- .catch((error) => {
11
- console.error(error);
12
- process.exit(1);
13
- });
14
- };
15
- program.command('start').description('start NocoBase application').action(runSubCommand('start'));
16
- program.command('install').option('-f, --force').option('-c, --clean').action(runSubCommand('install'));
17
- program.command('db:sync').option('-f, --force').action(runSubCommand('db-sync'));
18
- program.command('console').action(runSubCommand('console'));
19
- program
20
- .command('create-plugin')
21
- .argument('<name>', 'name of plugin')
22
- .description('create NocoBase plugin')
23
- .action(runSubCommand('create-plugin'));
24
- return program;
25
- }
26
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/commands/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,MAAM,UAAU,SAAS,CAAC,GAAgB;IACxC,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,MAAM,aAAa,GACjB,CAAC,IAAI,EAAE,EAAE,CACT,CAAC,GAAG,OAAO,EAAE,EAAE;QACb,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC;QAE7C,OAAO,CAAC,OAAO,EAAE;aACd,IAAI,CAAC,GAAG,EAAE;YACT,OAAO,OAAO,CAAC,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;YACf,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YACrB,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QAClB,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IAEJ,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,WAAW,CAAC,4BAA4B,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC;IAClG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IACxG,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAClF,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;IAE5D,OAAO;SACJ,OAAO,CAAC,eAAe,CAAC;SACxB,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;SACpC,WAAW,CAAC,wBAAwB,CAAC;SACrC,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC,CAAC;IAE1C,OAAO,OAAO,CAAC;AACjB,CAAC","sourcesContent":["import Application from '../application';\nimport { Command } from 'commander';\n\nexport function createCli(app: Application) {\n const program = new Command();\n\n const runSubCommand =\n (name) =>\n (...cliArgs) => {\n const command = require(`./${name}`).default;\n\n Promise.resolve()\n .then(() => {\n return command({ app, cliArgs });\n })\n .catch((error) => {\n console.error(error);\n process.exit(1);\n });\n };\n\n program.command('start').description('start NocoBase application').action(runSubCommand('start'));\n program.command('install').option('-f, --force').option('-c, --clean').action(runSubCommand('install'));\n program.command('db:sync').option('-f, --force').action(runSubCommand('db-sync'));\n program.command('console').action(runSubCommand('console'));\n\n program\n .command('create-plugin')\n .argument('<name>', 'name of plugin')\n .description('create NocoBase plugin')\n .action(runSubCommand('create-plugin'));\n\n return program;\n}\n"]}