@wocker/ws 1.0.1 → 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 (136) hide show
  1. package/README.md +11 -137
  2. package/bin/ws.js +7 -3
  3. package/lib/App.d.ts +10 -7
  4. package/lib/App.js +99 -44
  5. package/lib/controllers/ImageController.d.ts +4 -2
  6. package/lib/controllers/ImageController.js +27 -25
  7. package/lib/controllers/PluginController.d.ts +14 -0
  8. package/lib/controllers/PluginController.js +84 -0
  9. package/lib/controllers/PresetController.d.ts +21 -0
  10. package/lib/controllers/PresetController.js +169 -0
  11. package/lib/controllers/ProjectController.d.ts +11 -3
  12. package/lib/controllers/ProjectController.js +653 -536
  13. package/lib/{plugins/ProxyPlugin.d.ts → controllers/ProxyController.d.ts} +12 -11
  14. package/lib/controllers/ProxyController.js +273 -0
  15. package/lib/controllers/index.d.ts +3 -0
  16. package/lib/controllers/index.js +19 -25
  17. package/lib/env.js +33 -22
  18. package/lib/index.d.ts +2 -0
  19. package/lib/index.js +29 -28
  20. package/lib/makes/Controller.js +4 -8
  21. package/lib/makes/DI.d.ts +7 -0
  22. package/lib/makes/DI.js +27 -0
  23. package/lib/makes/Docker.js +299 -397
  24. package/lib/makes/FS.d.ts +1 -1
  25. package/lib/makes/FS.js +328 -301
  26. package/lib/makes/LineConvertStream.js +37 -40
  27. package/lib/makes/Logger.d.ts +5 -3
  28. package/lib/makes/Logger.js +18 -34
  29. package/lib/makes/Model.js +8 -12
  30. package/lib/makes/MySQL.js +6 -27
  31. package/lib/makes/Plugin.d.ts +1 -1
  32. package/lib/makes/Plugin.js +55 -37
  33. package/lib/makes/Preset.d.ts +46 -0
  34. package/lib/makes/Preset.js +33 -0
  35. package/lib/{models → makes}/Project.d.ts +23 -16
  36. package/lib/makes/Project.js +127 -0
  37. package/lib/makes/Repository.js +18 -21
  38. package/lib/makes/index.d.ts +3 -0
  39. package/lib/makes/index.js +23 -69
  40. package/lib/plugins/ElasticSearchPlugin.d.ts +18 -0
  41. package/lib/plugins/ElasticSearchPlugin.js +72 -0
  42. package/lib/plugins/LocaltunnelPlugin.d.ts +4 -4
  43. package/lib/plugins/LocaltunnelPlugin.js +256 -255
  44. package/lib/plugins/MaildevPlugin.d.ts +4 -2
  45. package/lib/plugins/MaildevPlugin.js +45 -41
  46. package/lib/plugins/MongodbPlugin.d.ts +6 -4
  47. package/lib/plugins/MongodbPlugin.js +303 -254
  48. package/lib/plugins/NgrokPlugin.d.ts +3 -4
  49. package/lib/plugins/NgrokPlugin.js +221 -230
  50. package/lib/plugins/PageKitePlugin.d.ts +3 -4
  51. package/lib/plugins/PageKitePlugin.js +150 -147
  52. package/lib/plugins/PostgresPlugin.d.ts +1 -1
  53. package/lib/plugins/PostgresPlugin.js +115 -88
  54. package/lib/plugins/ProxmoxPlugin.d.ts +1 -1
  55. package/lib/plugins/ProxmoxPlugin.js +50 -38
  56. package/lib/plugins/RedisPlugin.d.ts +10 -2
  57. package/lib/plugins/RedisPlugin.js +77 -39
  58. package/lib/plugins/index.d.ts +2 -6
  59. package/lib/plugins/index.js +25 -158
  60. package/lib/services/AppConfigService.d.ts +13 -3
  61. package/lib/services/AppConfigService.js +161 -71
  62. package/lib/services/AppEventsService.d.ts +5 -8
  63. package/lib/services/AppEventsService.js +26 -25
  64. package/lib/services/DockerService.d.ts +51 -0
  65. package/lib/services/DockerService.js +200 -0
  66. package/lib/services/LogService.d.ts +12 -0
  67. package/lib/services/LogService.js +38 -0
  68. package/lib/services/PluginService.d.ts +11 -0
  69. package/lib/services/PluginService.js +15 -0
  70. package/lib/services/PresetService.d.ts +14 -0
  71. package/lib/services/PresetService.js +64 -0
  72. package/lib/services/ProjectService.d.ts +12 -4
  73. package/lib/services/ProjectService.js +141 -78
  74. package/lib/services/index.d.ts +4 -0
  75. package/lib/services/index.js +21 -36
  76. package/lib/types/Config.d.ts +4 -3
  77. package/lib/types/Config.js +1 -4
  78. package/lib/types/EnvConfig.js +1 -4
  79. package/lib/types/index.js +16 -25
  80. package/lib/utils/buildOptions.js +5 -8
  81. package/lib/utils/demuxOutput.js +16 -22
  82. package/lib/utils/escapeRegExp.js +4 -7
  83. package/lib/utils/exec.d.ts +1 -1
  84. package/lib/utils/exec.js +38 -40
  85. package/lib/utils/fetch.js +45 -30
  86. package/lib/utils/followProgress.js +66 -77
  87. package/lib/utils/format-size-units.js +16 -16
  88. package/lib/utils/get-config.d.ts +1 -1
  89. package/lib/utils/get-config.js +13 -16
  90. package/lib/utils/get-cursor-position.js +22 -29
  91. package/lib/utils/image-build.js +35 -23
  92. package/lib/utils/index.d.ts +0 -4
  93. package/lib/utils/index.js +32 -235
  94. package/lib/utils/injectVariables.js +10 -13
  95. package/lib/utils/parse-table.js +20 -23
  96. package/lib/utils/set-config.d.ts +1 -1
  97. package/lib/utils/set-config.js +12 -15
  98. package/lib/utils/spawn.js +17 -20
  99. package/lib/utils/tty.js +2 -6
  100. package/lib/utils/volumeFormat.js +5 -12
  101. package/lib/utils/volumeParse.js +10 -13
  102. package/package.json +21 -47
  103. package/presets/bun/Dockerfile +11 -0
  104. package/presets/bun/config.json +3 -0
  105. package/presets/node/Dockerfile +4 -2
  106. package/presets/node/config.json +9 -7
  107. package/presets/php-apache/Dockerfile +40 -38
  108. package/presets/php-apache/config.json +10 -15
  109. package/presets/php-fpm/Dockerfile +21 -0
  110. package/presets/php-fpm/config.json +25 -0
  111. package/lib/models/Preset.d.ts +0 -19
  112. package/lib/models/Preset.js +0 -60
  113. package/lib/models/Project.js +0 -151
  114. package/lib/models/index.d.ts +0 -2
  115. package/lib/models/index.js +0 -27
  116. package/lib/plugins/MariadbPlugin.d.ts +0 -25
  117. package/lib/plugins/MariadbPlugin.js +0 -297
  118. package/lib/plugins/PresetPlugin.d.ts +0 -19
  119. package/lib/plugins/PresetPlugin.js +0 -164
  120. package/lib/plugins/ProjectPlugin.d.ts +0 -12
  121. package/lib/plugins/ProjectPlugin.js +0 -54
  122. package/lib/plugins/ProxyPlugin.js +0 -257
  123. package/lib/plugins/ServeoPlugin.d.ts +0 -36
  124. package/lib/plugins/ServeoPlugin.js +0 -260
  125. package/lib/plugins/TestPlugin.d.ts +0 -10
  126. package/lib/plugins/TestPlugin.js +0 -75
  127. package/lib/utils/promptConfirm.d.ts +0 -6
  128. package/lib/utils/promptConfirm.js +0 -21
  129. package/lib/utils/promptGroup.d.ts +0 -16
  130. package/lib/utils/promptGroup.js +0 -39
  131. package/lib/utils/promptSelect.d.ts +0 -12
  132. package/lib/utils/promptSelect.js +0 -47
  133. package/lib/utils/promptText.d.ts +0 -13
  134. package/lib/utils/promptText.js +0 -53
  135. package/plugins/mariadb/admin/conf/config.user.inc.php +0 -9
  136. package/plugins/serveo/Dockerfile +0 -17
@@ -1,91 +1,154 @@
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.ProjectService = void 0;
7
- var Path = _interopRequireWildcard(require("path"));
8
- var _makes = require("../makes");
9
- var _models = require("../models");
10
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
11
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
+ const Path = __importStar(require("path"));
28
+ const makes_1 = require("../makes");
29
+ const services_1 = require("../services");
12
30
  class ProjectService {
13
- constructor(appConfigService, appEventsService) {
14
- this.appConfigService = appConfigService;
15
- this.appEventsService = appEventsService;
16
- }
17
- async cdProject(name) {
18
- const project = await _models.Project.searchOne({
19
- name
20
- });
21
- if (!project) {
22
- throw new Error("Project not found");
31
+ constructor(di) {
32
+ this.appConfigService = di.resolveService(services_1.AppConfigService);
33
+ this.appEventsService = di.resolveService(services_1.AppEventsService);
34
+ this.dockerService = di.resolveService(services_1.DockerService);
23
35
  }
24
- this.appConfigService.setPWD(project.path);
25
- }
26
- async get() {
27
- const project = await _models.Project.searchOne({
28
- src: this.appConfigService.getPWD()
29
- });
30
- if (!project) {
31
- throw new Error("Project not found");
36
+ async cdProject(name) {
37
+ const project = await makes_1.Project.searchOne({
38
+ name
39
+ });
40
+ if (!project) {
41
+ throw new Error("Project not found");
42
+ }
43
+ this.appConfigService.setPWD(project.path);
32
44
  }
33
- return project;
34
- }
35
- async start() {
36
- const project = await this.get();
37
- if (project.type === "dockerfile") {
38
- project.imageName = `project-${project.name}:develop`;
39
- const images = await _makes.Docker.imageLs({
40
- tag: project.imageName
41
- });
42
- if (images.length === 0) {
43
- await _makes.Docker.imageBuild2({
44
- tag: project.imageName,
45
- context: this.appConfigService.getPWD(),
46
- src: project.dockerfile
45
+ async get() {
46
+ const project = await makes_1.Project.searchOne({
47
+ path: this.appConfigService.getPWD()
47
48
  });
48
- }
49
+ if (!project) {
50
+ throw new Error("Project not found");
51
+ }
52
+ return project;
49
53
  }
50
- await this.appEventsService.emit("project:beforeStart", project);
51
- const containerName = `${project.name}.workspace`;
52
- let container = await _makes.Docker.getContainer(containerName);
53
- if (!container) {
54
- container = await _makes.Docker.createContainer({
55
- name: containerName,
56
- image: project.imageName,
57
- env: {
58
- ...(await this.appConfigService.getAllEnvVariables()),
59
- ...(project.env || {})
60
- },
61
- volumes: (project.volumes || []).map(volume => {
62
- const regVolume = /^([^:]+):([^:]+)(?::([^:]+))?$/;
63
- const [, source, destination, options] = regVolume.exec(volume);
64
- return `${Path.join(this.appConfigService.getPWD(), source)}:${destination}` + (options ? `:${options}` : "");
65
- })
66
- });
67
- } else {
68
- process.stdout.write("Container already exists\n");
54
+ async getContainer() {
55
+ const project = await this.get();
56
+ return this.dockerService.getContainer(project.containerName);
69
57
  }
70
- if (container) {
71
- const {
72
- State: {
73
- Status
58
+ async start() {
59
+ const project = await this.get();
60
+ if (project.type === "dockerfile") {
61
+ project.imageName = `project-${project.name}:develop`;
62
+ const images = await makes_1.Docker.imageLs({
63
+ tag: project.imageName
64
+ });
65
+ if (images.length === 0) {
66
+ await makes_1.Docker.imageBuild2({
67
+ tag: project.imageName,
68
+ context: this.appConfigService.getPWD(),
69
+ src: project.dockerfile
70
+ });
71
+ }
72
+ }
73
+ await this.appEventsService.emit("project:beforeStart", project);
74
+ let container = await this.dockerService.getContainer(project.containerName);
75
+ if (!container) {
76
+ container = await makes_1.Docker.createContainer({
77
+ name: project.containerName,
78
+ image: project.imageName,
79
+ env: {
80
+ ...await this.appConfigService.getAllEnvVariables(),
81
+ ...project.env || {}
82
+ },
83
+ volumes: (project.volumes || []).map((volume) => {
84
+ const regVolume = /^([^:]+):([^:]+)(?::([^:]+))?$/;
85
+ const [, source, destination, options] = regVolume.exec(volume);
86
+ return `${Path.join(this.appConfigService.getPWD(), source)}:${destination}` + (options ? `:${options}` : "");
87
+ }),
88
+ ports: project.ports || []
89
+ });
90
+ }
91
+ else {
92
+ process.stdout.write("Container already exists\n");
93
+ }
94
+ if (container) {
95
+ const { State: { Status } } = await container.inspect();
96
+ if (Status === "created" || Status === "exited") {
97
+ await container.start();
98
+ await this.appEventsService.emit("project:start", project);
99
+ }
74
100
  }
75
- } = await container.inspect();
76
- if (Status === "created" || Status === "exited") {
77
- await container.start();
78
- await this.appEventsService.emit("project:start", project);
79
- }
80
101
  }
81
- }
82
- async stop() {
83
- const project = await this.get();
84
- const container = await _makes.Docker.getContainer(`${project.name}.workspace`);
85
- if (container) {
86
- await this.appEventsService.emit("project:stop", project);
87
- await _makes.Docker.removeContainer(`${project.name}.workspace`);
102
+ async stop() {
103
+ const project = await this.get();
104
+ const container = await makes_1.Docker.getContainer(project.containerName);
105
+ if (container) {
106
+ await this.appEventsService.emit("project:stop", project);
107
+ await makes_1.Docker.removeContainer(`${project.name}.workspace`);
108
+ }
109
+ }
110
+ async save(project) {
111
+ if (!project.name) {
112
+ throw new Error("Project should has a name");
113
+ }
114
+ if (!project.path) {
115
+ throw new Error("Project should has a path");
116
+ }
117
+ if (!project.id) {
118
+ project.id = project.name;
119
+ }
120
+ const projectDirPath = this.appConfigService.dataPath("projects", project.id);
121
+ const configPath = this.appConfigService.dataPath("projects", project.id, "config.json");
122
+ if (!makes_1.FS.existsSync(projectDirPath)) {
123
+ await makes_1.FS.mkdir(projectDirPath, {
124
+ recursive: true
125
+ });
126
+ }
127
+ await this.appConfigService.setProjectConfig(project.id, project.path);
128
+ await makes_1.FS.writeJSON(configPath, project);
129
+ }
130
+ async search(params = {}) {
131
+ const { id, name, path } = params;
132
+ const { projects: configs } = await this.appConfigService.getAppConfig();
133
+ const projects = [];
134
+ for (const config of configs) {
135
+ if (id && config.id !== id) {
136
+ continue;
137
+ }
138
+ if (path && config.src !== path) {
139
+ continue;
140
+ }
141
+ const projectData = await makes_1.FS.readJSON(this.appConfigService.dataPath("projects", config.id, "config.json"));
142
+ if (name && projectData.name !== name) {
143
+ continue;
144
+ }
145
+ const project = makes_1.Project.fromObject({
146
+ id: config.id,
147
+ ...projectData
148
+ });
149
+ projects.push(project);
150
+ }
151
+ return projects;
88
152
  }
89
- }
90
153
  }
91
- exports.ProjectService = ProjectService;
154
+ exports.ProjectService = ProjectService;
@@ -1,3 +1,7 @@
1
1
  export * from "./AppConfigService";
2
2
  export * from "./AppEventsService";
3
+ export * from "./DockerService";
4
+ export * from "./LogService";
5
+ export * from "./PluginService";
6
+ export * from "./PresetService";
3
7
  export * from "./ProjectService";
@@ -1,38 +1,23 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _AppConfigService = require("./AppConfigService");
7
- Object.keys(_AppConfigService).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _AppConfigService[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _AppConfigService[key];
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]; } };
14
7
  }
15
- });
16
- });
17
- var _AppEventsService = require("./AppEventsService");
18
- Object.keys(_AppEventsService).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _AppEventsService[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _AppEventsService[key];
25
- }
26
- });
27
- });
28
- var _ProjectService = require("./ProjectService");
29
- Object.keys(_ProjectService).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _ProjectService[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function () {
35
- return _ProjectService[key];
36
- }
37
- });
38
- });
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("./AppConfigService"), exports);
18
+ __exportStar(require("./AppEventsService"), exports);
19
+ __exportStar(require("./DockerService"), exports);
20
+ __exportStar(require("./LogService"), exports);
21
+ __exportStar(require("./PluginService"), exports);
22
+ __exportStar(require("./PresetService"), exports);
23
+ __exportStar(require("./ProjectService"), exports);
@@ -1,8 +1,9 @@
1
+ import { EnvConfig } from "./EnvConfig";
1
2
  export type Config = {
2
3
  debug?: boolean;
3
- env: {
4
- [key: string]: string;
5
- };
4
+ meta: EnvConfig;
5
+ env: EnvConfig;
6
+ plugins: string[];
6
7
  projects: {
7
8
  id: string;
8
9
  name?: string;
@@ -1,5 +1,2 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +1,2 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,27 +1,18 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _Config = require("./Config");
7
- Object.keys(_Config).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _Config[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function () {
13
- return _Config[key];
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]; } };
14
7
  }
15
- });
16
- });
17
- var _EnvConfig = require("./EnvConfig");
18
- Object.keys(_EnvConfig).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _EnvConfig[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function () {
24
- return _EnvConfig[key];
25
- }
26
- });
27
- });
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("./Config"), exports);
18
+ __exportStar(require("./EnvConfig"), exports);
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.buildOptions = void 0;
7
4
  const buildOptions = (name, options) => {
8
- return Object.keys(options).map(key => {
9
- return `--${name} ${key}=${options[key]}`;
10
- }).join(" ");
5
+ return Object.keys(options).map((key) => {
6
+ return `--${name} ${key}=${options[key]}`;
7
+ }).join(" ");
11
8
  };
12
- exports.buildOptions = buildOptions;
9
+ exports.buildOptions = buildOptions;
@@ -1,25 +1,19 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.demuxOutput = void 0;
7
- const demuxOutput = buffer => {
8
- let nextDataLength = null,
9
- output = Buffer.from([]);
10
- while (buffer.length > 0) {
11
- // Logger.info(buffer.length, buffer.toString("utf8"));
12
-
13
- const header = bufferSlice(8);
14
- nextDataLength = header.readUInt32BE(4);
15
- const content = bufferSlice(nextDataLength);
16
- output = Buffer.concat([output, content]);
17
- }
18
- function bufferSlice(end) {
19
- const out = buffer.slice(0, end);
20
- buffer = Buffer.from(buffer.slice(end, buffer.length));
21
- return out;
22
- }
23
- return output;
4
+ const demuxOutput = (buffer) => {
5
+ let nextDataLength = null, output = Buffer.from([]);
6
+ while (buffer.length > 0) {
7
+ const header = bufferSlice(8);
8
+ nextDataLength = header.readUInt32BE(4);
9
+ const content = bufferSlice(nextDataLength);
10
+ output = Buffer.concat([output, content]);
11
+ }
12
+ function bufferSlice(end) {
13
+ const out = buffer.slice(0, end);
14
+ buffer = Buffer.from(buffer.slice(end, buffer.length));
15
+ return out;
16
+ }
17
+ return output;
24
18
  };
25
- exports.demuxOutput = demuxOutput;
19
+ exports.demuxOutput = demuxOutput;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.escapeRegExp = void 0;
7
- const escapeRegExp = string => {
8
- return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4
+ const escapeRegExp = (string) => {
5
+ return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
9
6
  };
10
- exports.escapeRegExp = escapeRegExp;
7
+ exports.escapeRegExp = escapeRegExp;
@@ -1,2 +1,2 @@
1
- declare const exec: (command: any) => Promise<unknown>;
1
+ declare const exec: (command: string) => Promise<unknown>;
2
2
  export { exec };
package/lib/utils/exec.js CHANGED
@@ -1,44 +1,42 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
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
6
  exports.exec = void 0;
7
- var _child_process = require("child_process");
8
- var _chalk = _interopRequireDefault(require("chalk"));
9
- var _Logger = require("../makes/Logger");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- const exec = async command => {
12
- _Logger.Logger.info(` > ${command.trim().replace(/\s+/g, " ")}`);
13
- return new Promise((resolve, reject) => {
14
- const worker = (0, _child_process.exec)(command, {
15
- maxBuffer: Infinity
16
- }, (err, stdout, stderr) => {
17
- if (err) {
18
- return reject(err);
19
- }
20
- return resolve({
21
- stdout,
22
- stderr
23
- });
24
- });
25
- if (worker.stdout) {
26
- worker.stdout.on("data", data => {
27
- process.stdout.write(data);
28
- });
29
- }
30
- if (worker.stderr) {
31
- worker.stderr.on("data", data => {
32
- // process.stdout.write(chalk.red(data));
33
- process.stderr.write(data);
34
- });
35
- }
36
- worker.on("close", code => {
37
- _Logger.Logger.info("close", _chalk.default.red(code));
38
- });
39
- worker.on("exit", code => {
40
- _Logger.Logger.info("exit", _chalk.default.red(code));
7
+ const core_1 = require("@wocker/core");
8
+ const child_process_1 = require("child_process");
9
+ const chalk_1 = __importDefault(require("chalk"));
10
+ const exec = async (command) => {
11
+ core_1.Logger.info(` > ${command.trim().replace(/\s+/g, " ")}`);
12
+ return new Promise((resolve, reject) => {
13
+ const worker = (0, child_process_1.exec)(command, {
14
+ maxBuffer: Infinity
15
+ }, (err, stdout, stderr) => {
16
+ if (err) {
17
+ return reject(err);
18
+ }
19
+ return resolve({
20
+ stdout,
21
+ stderr
22
+ });
23
+ });
24
+ if (worker.stdout) {
25
+ worker.stdout.on("data", (data) => {
26
+ process.stdout.write(data);
27
+ });
28
+ }
29
+ if (worker.stderr) {
30
+ worker.stderr.on("data", (data) => {
31
+ process.stderr.write(data);
32
+ });
33
+ }
34
+ worker.on("close", (code) => {
35
+ core_1.Logger.info("close", chalk_1.default.red(code));
36
+ });
37
+ worker.on("exit", (code) => {
38
+ core_1.Logger.info("exit", chalk_1.default.red(code));
39
+ });
41
40
  });
42
- });
43
41
  };
44
- exports.exec = exec;
42
+ exports.exec = exec;
@@ -1,37 +1,52 @@
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.fetch = void 0;
7
- var https = _interopRequireWildcard(require("https"));
8
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
9
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
+ const https = __importStar(require("https"));
10
28
  const fetch = async (url, options) => {
11
- const {
12
- method = "GET"
13
- } = options || {};
14
- const target = new URL(url);
15
- const params = {
16
- method,
17
- protocol: target.protocol,
18
- hostname: target.hostname,
19
- port: target.port,
20
- path: target.pathname
21
- };
22
- return new Promise((resolve, reject) => {
23
- const req = https.request(params, res => {
24
- let body = "";
25
- res.on("data", data => {
26
- body += data;
27
- });
28
- res.on("end", () => {
29
- resolve(body);
30
- });
29
+ const { method = "GET" } = options || {};
30
+ const target = new URL(url);
31
+ const params = {
32
+ method,
33
+ protocol: target.protocol,
34
+ hostname: target.hostname,
35
+ port: target.port,
36
+ path: target.pathname
37
+ };
38
+ return new Promise((resolve, reject) => {
39
+ const req = https.request(params, (res) => {
40
+ let body = "";
41
+ res.on("data", (data) => {
42
+ body += data;
43
+ });
44
+ res.on("end", () => {
45
+ resolve(body);
46
+ });
47
+ });
48
+ req.on("error", reject);
49
+ req.end();
31
50
  });
32
- req.on("error", reject);
33
- req.end();
34
- });
35
51
  };
36
52
  exports.fetch = fetch;
37
- class Response {}