@wocker/ws 1.0.2 → 1.0.3

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 (100) hide show
  1. package/README.md +1 -1
  2. package/lib/App.d.ts +4 -3
  3. package/lib/App.js +98 -77
  4. package/lib/controllers/ImageController.d.ts +2 -2
  5. package/lib/controllers/ImageController.js +27 -27
  6. package/lib/controllers/PluginController.d.ts +2 -2
  7. package/lib/controllers/PluginController.js +78 -56
  8. package/lib/controllers/PresetController.d.ts +3 -1
  9. package/lib/controllers/PresetController.js +155 -136
  10. package/lib/controllers/ProjectController.d.ts +5 -5
  11. package/lib/controllers/ProjectController.js +653 -603
  12. package/lib/controllers/ProxyController.d.ts +4 -1
  13. package/lib/controllers/ProxyController.js +269 -245
  14. package/lib/controllers/index.js +19 -58
  15. package/lib/env.js +33 -15
  16. package/lib/index.d.ts +2 -0
  17. package/lib/index.js +30 -16
  18. package/lib/makes/Controller.js +4 -8
  19. package/lib/makes/DI.d.ts +7 -0
  20. package/lib/makes/DI.js +27 -0
  21. package/lib/makes/Docker.js +298 -382
  22. package/lib/makes/FS.js +328 -304
  23. package/lib/makes/LineConvertStream.js +37 -40
  24. package/lib/makes/Logger.d.ts +9 -1
  25. package/lib/makes/Logger.js +22 -11
  26. package/lib/makes/Model.js +8 -12
  27. package/lib/makes/MySQL.js +6 -27
  28. package/lib/makes/Plugin.d.ts +1 -1
  29. package/lib/makes/Plugin.js +55 -37
  30. package/lib/makes/Preset.d.ts +46 -0
  31. package/lib/makes/Preset.js +33 -0
  32. package/lib/makes/Project.d.ts +45 -0
  33. package/lib/makes/Project.js +127 -0
  34. package/lib/makes/Repository.js +18 -21
  35. package/lib/makes/index.d.ts +3 -0
  36. package/lib/makes/index.js +23 -69
  37. package/lib/plugins/ElasticSearchPlugin.d.ts +3 -1
  38. package/lib/plugins/ElasticSearchPlugin.js +66 -66
  39. package/lib/plugins/LocaltunnelPlugin.d.ts +2 -2
  40. package/lib/plugins/LocaltunnelPlugin.js +256 -257
  41. package/lib/plugins/MaildevPlugin.d.ts +2 -2
  42. package/lib/plugins/MaildevPlugin.js +45 -44
  43. package/lib/plugins/MongodbPlugin.d.ts +2 -2
  44. package/lib/plugins/MongodbPlugin.js +303 -248
  45. package/lib/plugins/NgrokPlugin.d.ts +2 -2
  46. package/lib/plugins/NgrokPlugin.js +221 -231
  47. package/lib/plugins/PageKitePlugin.d.ts +2 -2
  48. package/lib/plugins/PageKitePlugin.js +150 -149
  49. package/lib/plugins/PostgresPlugin.d.ts +1 -1
  50. package/lib/plugins/PostgresPlugin.js +115 -89
  51. package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
  52. package/lib/plugins/ProxmoxPlugin.js +50 -38
  53. package/lib/plugins/RedisPlugin.d.ts +3 -1
  54. package/lib/plugins/RedisPlugin.js +73 -72
  55. package/lib/plugins/index.js +25 -103
  56. package/lib/services/AppConfigService.d.ts +3 -3
  57. package/lib/services/AppConfigService.js +162 -157
  58. package/lib/services/AppEventsService.js +26 -24
  59. package/lib/services/DockerService.d.ts +37 -2
  60. package/lib/services/DockerService.js +185 -205
  61. package/lib/services/LogService.d.ts +3 -2
  62. package/lib/services/LogService.js +33 -34
  63. package/lib/services/PluginService.d.ts +2 -1
  64. package/lib/services/PluginService.js +11 -14
  65. package/lib/services/PresetService.d.ts +8 -3
  66. package/lib/services/PresetService.js +60 -59
  67. package/lib/services/ProjectService.d.ts +11 -4
  68. package/lib/services/ProjectService.js +140 -129
  69. package/lib/services/index.js +21 -80
  70. package/lib/types/Config.d.ts +4 -3
  71. package/lib/types/Config.js +1 -4
  72. package/lib/types/EnvConfig.js +1 -4
  73. package/lib/types/index.js +16 -25
  74. package/lib/utils/buildOptions.js +5 -8
  75. package/lib/utils/demuxOutput.js +16 -20
  76. package/lib/utils/escapeRegExp.js +4 -7
  77. package/lib/utils/exec.js +38 -39
  78. package/lib/utils/fetch.js +46 -30
  79. package/lib/utils/followProgress.js +66 -77
  80. package/lib/utils/format-size-units.js +16 -16
  81. package/lib/utils/get-config.d.ts +1 -1
  82. package/lib/utils/get-config.js +13 -16
  83. package/lib/utils/get-cursor-position.js +22 -29
  84. package/lib/utils/image-build.js +35 -23
  85. package/lib/utils/index.js +32 -191
  86. package/lib/utils/injectVariables.js +10 -13
  87. package/lib/utils/parse-table.js +20 -23
  88. package/lib/utils/set-config.d.ts +1 -1
  89. package/lib/utils/set-config.js +12 -15
  90. package/lib/utils/spawn.js +17 -20
  91. package/lib/utils/tty.js +2 -6
  92. package/lib/utils/volumeFormat.js +5 -12
  93. package/lib/utils/volumeParse.js +10 -13
  94. package/package.json +13 -39
  95. package/presets/bun/Dockerfile +11 -0
  96. package/presets/bun/config.json +3 -0
  97. package/presets/node/Dockerfile +4 -2
  98. package/presets/php-apache/Dockerfile +3 -2
  99. package/.github/workflows/publish.yml +0 -31
  100. package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
@@ -1,79 +1,80 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.RedisPlugin = void 0;
7
- var _core = require("@wocker/core");
8
- class RedisPlugin extends _core.Plugin {
9
- container = "redis.workspace";
10
- commander = "redis-commander.workspace";
11
- constructor(di) {
12
- super();
13
- this.appConfigService = di.resolveService(_core.AppConfigService);
14
- this.dockerService = di.resolveService(_core.DockerService);
15
- this.fs = new _core.FSManager(this.appConfigService.pluginsPath("redis"), this.appConfigService.dataPath("plugins/redis"));
16
- }
17
- install(cli) {
18
- super.install(cli);
19
- cli.command("redis:start").action(() => this.up());
20
- cli.command("redis:stop").action(() => this.down());
21
- }
22
- async up() {
23
- console.log("Redis up...");
24
- await this.dockerService.pullImage("redis");
25
- let container = await this.dockerService.getContainer(this.container);
26
- if (!container) {
27
- await this.fs.mkdir("", {
28
- recursive: true
29
- });
30
- container = await this.dockerService.createContainer({
31
- name: this.container,
32
- image: "redis",
33
- restart: "always",
34
- env: {
35
- VIRTUAL_HOST: this.container
36
- },
37
- volumes: [`${this.fs.path()}:/data`],
38
- ports: ["6379:6379"]
39
- });
4
+ const core_1 = require("@wocker/core");
5
+ const makes_1 = require("../makes");
6
+ const services_1 = require("../services");
7
+ class RedisPlugin extends makes_1.Plugin {
8
+ constructor(di) {
9
+ super("redis");
10
+ this.container = "redis.workspace";
11
+ this.commander = "redis-commander.workspace";
12
+ this.appConfigService = di.resolveService(services_1.AppConfigService);
13
+ this.dockerService = di.resolveService(services_1.DockerService);
14
+ this.fs = new core_1.FSManager(this.appConfigService.pluginsPath("redis"), this.appConfigService.dataPath("plugins/redis"));
40
15
  }
41
- await container.start();
42
- await this.startCommander();
43
- }
44
- async startCommander() {
45
- console.info("RedisCommander starting...");
46
- let container = await this.dockerService.getContainer(this.commander);
47
- if (!container) {
48
- await this.dockerService.pullImage("rediscommander/redis-commander:latest");
49
- container = await this.dockerService.createContainer({
50
- name: this.commander,
51
- image: "rediscommander/redis-commander:latest",
52
- restart: "always",
53
- env: {
54
- VIRTUAL_HOST: this.commander,
55
- VIRTUAL_PORT: "8081",
56
- REDIS_HOSTS: this.container
16
+ install(cli) {
17
+ super.install(cli);
18
+ cli.command("redis:start")
19
+ .action(() => this.up());
20
+ cli.command("redis:stop")
21
+ .action(() => this.down());
22
+ }
23
+ async up() {
24
+ console.log("Redis up...");
25
+ await this.dockerService.pullImage("redis");
26
+ let container = await this.dockerService.getContainer(this.container);
27
+ if (!container) {
28
+ await this.fs.mkdir("", {
29
+ recursive: true
30
+ });
31
+ container = await this.dockerService.createContainer({
32
+ name: this.container,
33
+ image: "redis",
34
+ restart: "always",
35
+ env: {
36
+ VIRTUAL_HOST: this.container
37
+ },
38
+ volumes: [
39
+ `${this.fs.path()}:/data`
40
+ ],
41
+ ports: [
42
+ "6379:6379"
43
+ ]
44
+ });
45
+ }
46
+ await container.start();
47
+ await this.startCommander();
48
+ }
49
+ async startCommander() {
50
+ console.info("RedisCommander starting...");
51
+ let container = await this.dockerService.getContainer(this.commander);
52
+ if (!container) {
53
+ await this.dockerService.pullImage("rediscommander/redis-commander:latest");
54
+ container = await this.dockerService.createContainer({
55
+ name: this.commander,
56
+ image: "rediscommander/redis-commander:latest",
57
+ restart: "always",
58
+ env: {
59
+ VIRTUAL_HOST: this.commander,
60
+ VIRTUAL_PORT: "8081",
61
+ REDIS_HOSTS: this.container
62
+ }
63
+ });
57
64
  }
58
- });
65
+ const { State: { Status } } = await container.inspect();
66
+ if (Status === "created" || Status === "exited") {
67
+ await container.start();
68
+ }
69
+ }
70
+ async down() {
71
+ console.log("Redis down...");
72
+ await this.dockerService.removeContainer(this.container);
73
+ await this.stopCommander();
59
74
  }
60
- const {
61
- State: {
62
- Status
63
- }
64
- } = await container.inspect();
65
- if (Status === "created" || Status === "exited") {
66
- await container.start();
75
+ async stopCommander() {
76
+ console.info("RedisCommander stopping...");
77
+ await this.dockerService.removeContainer(this.commander);
67
78
  }
68
- }
69
- async down() {
70
- console.log("Redis down...");
71
- await this.dockerService.removeContainer(this.container);
72
- await this.stopCommander();
73
- }
74
- async stopCommander() {
75
- console.info("RedisCommander stopping...");
76
- await this.dockerService.removeContainer(this.commander);
77
- }
78
79
  }
79
- exports.RedisPlugin = RedisPlugin;
80
+ exports.RedisPlugin = RedisPlugin;
@@ -1,104 +1,26 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _ElasticSearchPlugin = require("./ElasticSearchPlugin");
7
- Object.keys(_ElasticSearchPlugin).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _ElasticSearchPlugin[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _ElasticSearchPlugin[key];
14
- }
15
- });
16
- });
17
- var _LocaltunnelPlugin = require("./LocaltunnelPlugin");
18
- Object.keys(_LocaltunnelPlugin).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _LocaltunnelPlugin[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _LocaltunnelPlugin[key];
25
- }
26
- });
27
- });
28
- var _MaildevPlugin = require("./MaildevPlugin");
29
- Object.keys(_MaildevPlugin).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _MaildevPlugin[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _MaildevPlugin[key];
36
- }
37
- });
38
- });
39
- var _MongodbPlugin = require("./MongodbPlugin");
40
- Object.keys(_MongodbPlugin).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _MongodbPlugin[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function () {
46
- return _MongodbPlugin[key];
47
- }
48
- });
49
- });
50
- var _NgrokPlugin = require("./NgrokPlugin");
51
- Object.keys(_NgrokPlugin).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _NgrokPlugin[key]) return;
54
- Object.defineProperty(exports, key, {
55
- enumerable: true,
56
- get: function () {
57
- return _NgrokPlugin[key];
58
- }
59
- });
60
- });
61
- var _PageKitePlugin = require("./PageKitePlugin");
62
- Object.keys(_PageKitePlugin).forEach(function (key) {
63
- if (key === "default" || key === "__esModule") return;
64
- if (key in exports && exports[key] === _PageKitePlugin[key]) return;
65
- Object.defineProperty(exports, key, {
66
- enumerable: true,
67
- get: function () {
68
- return _PageKitePlugin[key];
69
- }
70
- });
71
- });
72
- var _PostgresPlugin = require("./PostgresPlugin");
73
- Object.keys(_PostgresPlugin).forEach(function (key) {
74
- if (key === "default" || key === "__esModule") return;
75
- if (key in exports && exports[key] === _PostgresPlugin[key]) return;
76
- Object.defineProperty(exports, key, {
77
- enumerable: true,
78
- get: function () {
79
- return _PostgresPlugin[key];
80
- }
81
- });
82
- });
83
- var _ProxmoxPlugin = require("./ProxmoxPlugin");
84
- Object.keys(_ProxmoxPlugin).forEach(function (key) {
85
- if (key === "default" || key === "__esModule") return;
86
- if (key in exports && exports[key] === _ProxmoxPlugin[key]) return;
87
- Object.defineProperty(exports, key, {
88
- enumerable: true,
89
- get: function () {
90
- return _ProxmoxPlugin[key];
91
- }
92
- });
93
- });
94
- var _RedisPlugin = require("./RedisPlugin");
95
- Object.keys(_RedisPlugin).forEach(function (key) {
96
- if (key === "default" || key === "__esModule") return;
97
- if (key in exports && exports[key] === _RedisPlugin[key]) return;
98
- Object.defineProperty(exports, key, {
99
- enumerable: true,
100
- get: function () {
101
- return _RedisPlugin[key];
102
- }
103
- });
104
- });
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./ElasticSearchPlugin"), exports);
18
+ __exportStar(require("./LocaltunnelPlugin"), exports);
19
+ __exportStar(require("./MaildevPlugin"), exports);
20
+ __exportStar(require("./MongodbPlugin"), exports);
21
+ __exportStar(require("./NgrokPlugin"), exports);
22
+ __exportStar(require("./PageKitePlugin"), exports);
23
+ __exportStar(require("./PostgresPlugin"), exports);
24
+ __exportStar(require("./PostgresPlugin"), exports);
25
+ __exportStar(require("./ProxmoxPlugin"), exports);
26
+ __exportStar(require("./RedisPlugin"), exports);
@@ -1,8 +1,8 @@
1
- import { AppConfigService as CoreAppConfigService, AppConfig, EnvConfig } from "@wocker/core";
1
+ import { Config, EnvConfig } from "../types";
2
2
  type TypeMap = {
3
3
  [type: string]: string;
4
4
  };
5
- declare class AppConfigService extends CoreAppConfigService {
5
+ declare class AppConfigService {
6
6
  protected pwd: string;
7
7
  protected mapTypes: TypeMap;
8
8
  constructor();
@@ -10,7 +10,7 @@ declare class AppConfigService extends CoreAppConfigService {
10
10
  pluginsPath(...args: string[]): string;
11
11
  getPWD(): string;
12
12
  setPWD(pwd: string): void;
13
- getAppConfig(): Promise<AppConfig>;
13
+ getAppConfig(): Promise<Config>;
14
14
  private saveAppConfig;
15
15
  getMeta(name: string, defaultValue?: string): Promise<string>;
16
16
  setMeta(name: string, value?: string | number): Promise<void>;
@@ -1,162 +1,167 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
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;
5
17
  });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
6
26
  exports.AppConfigService = void 0;
7
- var _core = require("@wocker/core");
8
- var Path = _interopRequireWildcard(require("path"));
9
- var _env = require("../env");
10
- var _makes = require("../makes");
11
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
13
- class AppConfigService extends _core.AppConfigService {
14
- mapTypes = {
15
- image: "Image",
16
- dockerfile: "Dockerfile"
17
- };
18
- constructor() {
19
- super();
20
- this.pwd = process.cwd() || process.env.PWD;
21
- }
22
- dataPath(...args) {
23
- return Path.join(_env.DATA_DIR, ...args);
24
- }
25
- pluginsPath(...args) {
26
- return Path.join(_env.PLUGINS_DIR, ...args);
27
- }
28
- getPWD() {
29
- return this.pwd;
30
- }
31
- setPWD(pwd) {
32
- this.pwd = pwd;
33
- }
34
- async getAppConfig() {
35
- return _makes.FS.readJSON(_env.MAP_PATH);
36
- }
37
- async saveAppConfig(config) {
38
- await _makes.FS.writeJSON(_env.MAP_PATH, config);
39
- }
40
- async getMeta(name, defaultValue) {
41
- const config = await this.getAppConfig();
42
- const value = (config.meta || {})[name];
43
- if (!value) {
44
- return defaultValue;
45
- }
46
- return value;
47
- }
48
- async setMeta(name, value) {
49
- const config = await this.getAppConfig();
50
- if (!config.meta) {
51
- config.meta = {};
52
- }
53
- config.meta[name] = value ? value.toString() : undefined;
54
- await this.saveAppConfig(config);
55
- }
56
- async getAllEnvVariables() {
57
- const {
58
- env = {}
59
- } = await _makes.FS.readJSON(_env.MAP_PATH);
60
- return env;
61
- }
62
- async getEnvVariable(name, defaultValue) {
63
- const {
64
- [name]: value = defaultValue
65
- } = await this.getAllEnvVariables();
66
- if (value === null) {
67
- return defaultValue;
68
- }
69
- return value;
70
- }
71
- async setEnv(env) {
72
- const config = await _makes.FS.readJSON(_env.MAP_PATH);
73
- await _makes.FS.writeJSON(_env.MAP_PATH, {
74
- ...config,
75
- env: {
76
- ...(config.env || {}),
77
- ...env
78
- }
79
- });
80
- }
81
- async setEnvVariable(name, value) {
82
- const config = await _makes.FS.readJSON(_env.MAP_PATH);
83
- await _makes.FS.writeJSON(_env.MAP_PATH, {
84
- ...config,
85
- env: {
86
- ...(config.env || {}),
87
- [name]: value
88
- }
89
- });
90
- }
91
- async unsetEnv(...keys) {
92
- const config = await _makes.FS.readJSON(_env.MAP_PATH);
93
- await _makes.FS.writeJSON(_env.MAP_PATH, {
94
- ...config,
95
- env: Object.keys(config.env || {}).reduce((res, key) => {
96
- if (!keys.includes(key)) {
97
- res[key] = config.env[key];
27
+ const Path = __importStar(require("path"));
28
+ const env_1 = require("../env");
29
+ const makes_1 = require("../makes");
30
+ class AppConfigService {
31
+ constructor() {
32
+ this.mapTypes = {
33
+ image: "Image",
34
+ dockerfile: "Dockerfile"
35
+ };
36
+ this.pwd = (process.cwd() || process.env.PWD);
37
+ }
38
+ dataPath(...args) {
39
+ return Path.join(env_1.DATA_DIR, ...args);
40
+ }
41
+ pluginsPath(...args) {
42
+ return Path.join(env_1.PLUGINS_DIR, ...args);
43
+ }
44
+ getPWD() {
45
+ return this.pwd;
46
+ }
47
+ setPWD(pwd) {
48
+ this.pwd = pwd;
49
+ }
50
+ async getAppConfig() {
51
+ return makes_1.FS.readJSON(env_1.MAP_PATH);
52
+ }
53
+ async saveAppConfig(config) {
54
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, config);
55
+ }
56
+ async getMeta(name, defaultValue) {
57
+ const config = await this.getAppConfig();
58
+ const value = (config.meta || {})[name];
59
+ if (!value) {
60
+ return defaultValue;
61
+ }
62
+ return value;
63
+ }
64
+ async setMeta(name, value) {
65
+ const config = await this.getAppConfig();
66
+ if (!config.meta) {
67
+ config.meta = {};
68
+ }
69
+ config.meta[name] = value ? value.toString() : undefined;
70
+ await this.saveAppConfig(config);
71
+ }
72
+ async getAllEnvVariables() {
73
+ const { env = {} } = await makes_1.FS.readJSON(env_1.MAP_PATH);
74
+ return env;
75
+ }
76
+ async getEnvVariable(name, defaultValue) {
77
+ const { [name]: value = defaultValue } = await this.getAllEnvVariables();
78
+ if (value === null) {
79
+ return defaultValue;
80
+ }
81
+ return value;
82
+ }
83
+ async setEnv(env) {
84
+ const config = await makes_1.FS.readJSON(env_1.MAP_PATH);
85
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, {
86
+ ...config,
87
+ env: {
88
+ ...config.env || {},
89
+ ...env
90
+ }
91
+ });
92
+ }
93
+ async setEnvVariable(name, value) {
94
+ const config = await makes_1.FS.readJSON(env_1.MAP_PATH);
95
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, {
96
+ ...config,
97
+ env: {
98
+ ...config.env || {},
99
+ [name]: value
100
+ }
101
+ });
102
+ }
103
+ async unsetEnv(...keys) {
104
+ const config = await makes_1.FS.readJSON(env_1.MAP_PATH);
105
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, {
106
+ ...config,
107
+ env: Object.keys(config.env || {}).reduce((res, key) => {
108
+ if (!keys.includes(key)) {
109
+ res[key] = config.env[key];
110
+ }
111
+ return res;
112
+ }, {})
113
+ });
114
+ }
115
+ getProjectTypes() {
116
+ return this.mapTypes;
117
+ }
118
+ registerProjectType(name, title) {
119
+ this.mapTypes[name] = title || name;
120
+ }
121
+ async setProjectConfig(id, path) {
122
+ const { projects, ...rest } = await this.getAppConfig();
123
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, {
124
+ ...rest,
125
+ projects: [
126
+ ...(projects || []).filter((project) => {
127
+ return project.id !== id;
128
+ }).filter((project) => {
129
+ return project.src !== path;
130
+ }),
131
+ {
132
+ id: id,
133
+ src: path
134
+ }
135
+ ]
136
+ });
137
+ }
138
+ async activatePlugin(name) {
139
+ const { default: Plugin } = await Promise.resolve(`${name}`).then(s => __importStar(require(s)));
140
+ if (!Plugin) {
141
+ throw new Error("No plugin");
98
142
  }
99
- return res;
100
- }, {})
101
- });
102
- }
103
- getProjectTypes() {
104
- return this.mapTypes;
105
- }
106
- registerProjectType(name, title) {
107
- this.mapTypes[name] = title || name;
108
- }
109
- async setProjectConfig(id, path) {
110
- const {
111
- projects,
112
- ...rest
113
- } = await this.getAppConfig();
114
- await _makes.FS.writeJSON(_env.MAP_PATH, {
115
- ...rest,
116
- projects: [...(projects || []).filter(project => {
117
- return project.id !== id;
118
- }).filter(project => {
119
- return project.src !== path;
120
- }), {
121
- id: id,
122
- src: path
123
- }]
124
- });
125
- }
126
- async activatePlugin(name) {
127
- const {
128
- default: Plugin
129
- } = await (specifier => new Promise(r => r(`${specifier}`)).then(s => _interopRequireWildcard(require(s))))(name);
130
-
131
- // this.use
132
- if (!Plugin) {
133
- throw new Error("No plugin");
134
- }
135
- const {
136
- plugins = [],
137
- ...rest
138
- } = await this.getAppConfig();
139
- await _makes.FS.writeJSON(_env.MAP_PATH, {
140
- plugins: [...plugins.filter(plugin => {
141
- return plugin !== name;
142
- }), name],
143
- ...rest
144
- });
145
- }
146
- async deactivatePlugin(name) {
147
- const {
148
- plugins = [],
149
- ...rest
150
- } = await this.getAppConfig();
151
- if (!plugins.includes(name)) {
152
- return;
153
- }
154
- await _makes.FS.writeJSON(_env.MAP_PATH, {
155
- plugins: plugins.filter(plugin => {
156
- return plugin !== name;
157
- }),
158
- ...rest
159
- });
160
- }
143
+ const { plugins = [], ...rest } = await this.getAppConfig();
144
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, {
145
+ plugins: [
146
+ ...plugins.filter((plugin) => {
147
+ return plugin !== name;
148
+ }),
149
+ name
150
+ ],
151
+ ...rest
152
+ });
153
+ }
154
+ async deactivatePlugin(name) {
155
+ const { plugins = [], ...rest } = await this.getAppConfig();
156
+ if (!plugins.includes(name)) {
157
+ return;
158
+ }
159
+ await makes_1.FS.writeJSON(env_1.MAP_PATH, {
160
+ plugins: plugins.filter((plugin) => {
161
+ return plugin !== name;
162
+ }),
163
+ ...rest
164
+ });
165
+ }
161
166
  }
162
- exports.AppConfigService = AppConfigService;
167
+ exports.AppConfigService = AppConfigService;