@wocker/ws 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +155 -0
- package/bin/ws.js +13 -0
- package/lib/App.d.ts +13 -0
- package/lib/App.js +52 -0
- package/lib/controllers/ImageController.d.ts +8 -0
- package/lib/controllers/ImageController.js +29 -0
- package/lib/controllers/ProjectController.d.ts +64 -0
- package/lib/controllers/ProjectController.js +561 -0
- package/lib/controllers/index.d.ts +2 -0
- package/lib/controllers/index.js +27 -0
- package/lib/env.d.ts +7 -0
- package/lib/env.js +24 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +31 -0
- package/lib/makes/Controller.d.ts +5 -0
- package/lib/makes/Controller.js +12 -0
- package/lib/makes/Docker.d.ts +58 -0
- package/lib/makes/Docker.js +418 -0
- package/lib/makes/FS.d.ts +37 -0
- package/lib/makes/FS.js +317 -0
- package/lib/makes/LineConvertStream.d.ts +13 -0
- package/lib/makes/LineConvertStream.js +45 -0
- package/lib/makes/Logger.d.ts +7 -0
- package/lib/makes/Logger.js +39 -0
- package/lib/makes/Model.d.ts +5 -0
- package/lib/makes/Model.js +16 -0
- package/lib/makes/MySQL.d.ts +15 -0
- package/lib/makes/MySQL.js +31 -0
- package/lib/makes/Plugin.d.ts +13 -0
- package/lib/makes/Plugin.js +43 -0
- package/lib/makes/Repository.d.ts +11 -0
- package/lib/makes/Repository.js +25 -0
- package/lib/makes/index.d.ts +6 -0
- package/lib/makes/index.js +71 -0
- package/lib/models/Preset.d.ts +19 -0
- package/lib/models/Preset.js +60 -0
- package/lib/models/Project.d.ts +38 -0
- package/lib/models/Project.js +151 -0
- package/lib/models/index.d.ts +2 -0
- package/lib/models/index.js +27 -0
- package/lib/plugins/LocaltunnelPlugin.d.ts +36 -0
- package/lib/plugins/LocaltunnelPlugin.js +273 -0
- package/lib/plugins/MaildevPlugin.d.ts +10 -0
- package/lib/plugins/MaildevPlugin.js +45 -0
- package/lib/plugins/MariadbPlugin.d.ts +25 -0
- package/lib/plugins/MariadbPlugin.js +297 -0
- package/lib/plugins/MongodbPlugin.d.ts +20 -0
- package/lib/plugins/MongodbPlugin.js +271 -0
- package/lib/plugins/NgrokPlugin.d.ts +37 -0
- package/lib/plugins/NgrokPlugin.js +248 -0
- package/lib/plugins/PageKitePlugin.d.ts +31 -0
- package/lib/plugins/PageKitePlugin.js +158 -0
- package/lib/plugins/PostgresPlugin.d.ts +16 -0
- package/lib/plugins/PostgresPlugin.js +94 -0
- package/lib/plugins/PresetPlugin.d.ts +19 -0
- package/lib/plugins/PresetPlugin.js +164 -0
- package/lib/plugins/ProjectPlugin.d.ts +12 -0
- package/lib/plugins/ProjectPlugin.js +54 -0
- package/lib/plugins/ProxmoxPlugin.d.ts +9 -0
- package/lib/plugins/ProxmoxPlugin.js +55 -0
- package/lib/plugins/ProxyPlugin.d.ts +33 -0
- package/lib/plugins/ProxyPlugin.js +257 -0
- package/lib/plugins/RedisPlugin.d.ts +10 -0
- package/lib/plugins/RedisPlugin.js +42 -0
- package/lib/plugins/ServeoPlugin.d.ts +36 -0
- package/lib/plugins/ServeoPlugin.js +260 -0
- package/lib/plugins/TestPlugin.d.ts +10 -0
- package/lib/plugins/TestPlugin.js +75 -0
- package/lib/plugins/index.d.ts +14 -0
- package/lib/plugins/index.js +159 -0
- package/lib/services/AppConfigService.d.ts +18 -0
- package/lib/services/AppConfigService.js +77 -0
- package/lib/services/AppEventsService.d.ts +13 -0
- package/lib/services/AppEventsService.js +29 -0
- package/lib/services/ProjectService.d.ts +13 -0
- package/lib/services/ProjectService.js +91 -0
- package/lib/services/index.d.ts +3 -0
- package/lib/services/index.js +38 -0
- package/lib/types/Config.d.ts +11 -0
- package/lib/types/Config.js +5 -0
- package/lib/types/EnvConfig.d.ts +3 -0
- package/lib/types/EnvConfig.js +5 -0
- package/lib/types/index.d.ts +2 -0
- package/lib/types/index.js +27 -0
- package/lib/utils/buildOptions.d.ts +1 -0
- package/lib/utils/buildOptions.js +12 -0
- package/lib/utils/demuxOutput.d.ts +2 -0
- package/lib/utils/demuxOutput.js +25 -0
- package/lib/utils/escapeRegExp.d.ts +2 -0
- package/lib/utils/escapeRegExp.js +10 -0
- package/lib/utils/exec.d.ts +2 -0
- package/lib/utils/exec.js +44 -0
- package/lib/utils/fetch.d.ts +5 -0
- package/lib/utils/fetch.js +37 -0
- package/lib/utils/followProgress.d.ts +6 -0
- package/lib/utils/followProgress.js +80 -0
- package/lib/utils/format-size-units.d.ts +1 -0
- package/lib/utils/format-size-units.js +19 -0
- package/lib/utils/get-config.d.ts +2 -0
- package/lib/utils/get-config.js +20 -0
- package/lib/utils/get-cursor-position.d.ts +4 -0
- package/lib/utils/get-cursor-position.js +34 -0
- package/lib/utils/image-build.d.ts +13 -0
- package/lib/utils/image-build.js +34 -0
- package/lib/utils/index.d.ts +21 -0
- package/lib/utils/index.js +236 -0
- package/lib/utils/injectVariables.d.ts +5 -0
- package/lib/utils/injectVariables.js +17 -0
- package/lib/utils/parse-table.d.ts +2 -0
- package/lib/utils/parse-table.js +27 -0
- package/lib/utils/promptConfirm.d.ts +6 -0
- package/lib/utils/promptConfirm.js +21 -0
- package/lib/utils/promptGroup.d.ts +16 -0
- package/lib/utils/promptGroup.js +39 -0
- package/lib/utils/promptSelect.d.ts +12 -0
- package/lib/utils/promptSelect.js +47 -0
- package/lib/utils/promptText.d.ts +13 -0
- package/lib/utils/promptText.js +53 -0
- package/lib/utils/set-config.d.ts +2 -0
- package/lib/utils/set-config.js +18 -0
- package/lib/utils/spawn.d.ts +2 -0
- package/lib/utils/spawn.js +24 -0
- package/lib/utils/tty.d.ts +2 -0
- package/lib/utils/tty.js +10 -0
- package/lib/utils/volumeFormat.d.ts +6 -0
- package/lib/utils/volumeFormat.js +15 -0
- package/lib/utils/volumeParse.d.ts +2 -0
- package/lib/utils/volumeParse.js +16 -0
- package/package.json +90 -0
- package/plugins/localtunnel/Dockerfile +37 -0
- package/plugins/localtunnel/Ubuntu.dockerfile +34 -0
- package/plugins/localtunnel/config.json +3 -0
- package/plugins/maildev/Dockerfile +5 -0
- package/plugins/maildev/config.json +3 -0
- package/plugins/mariadb/admin/conf/config.user.inc.php +9 -0
- package/plugins/ngrok/Dockerfile +2 -0
- package/plugins/pagekite/Dockerfile +3 -0
- package/plugins/proxmox/Dockerfile +35 -0
- package/plugins/proxy/Dockerfile +7 -0
- package/plugins/proxy/config.json +3 -0
- package/plugins/serveo/Dockerfile +17 -0
- package/presets/apache/.docker/apache2/apache2.conf +230 -0
- package/presets/apache/.docker/apache2/mods-available/mpm_prefork.conf +16 -0
- package/presets/apache/.docker/apache2/sites-available/000-default.conf.conf +21 -0
- package/presets/apache/Dockerfile +110 -0
- package/presets/apache/bin/compare-version +3 -0
- package/presets/apache/config.json +47 -0
- package/presets/go/Dockerfile +19 -0
- package/presets/go/config.json +13 -0
- package/presets/node/Dockerfile +37 -0
- package/presets/node/config.json +36 -0
- package/presets/php-apache/Dockerfile +133 -0
- package/presets/php-apache/bin/compare-version +3 -0
- package/presets/php-apache/config.json +56 -0
- package/presets/php-apache/etc/apache2/apache2.conf +230 -0
- package/presets/php-apache/etc/apache2/mods-available/mpm_prefork.conf +16 -0
- package/presets/php-apache/etc/apache2/sites-available/000-default.conf +21 -0
- package/presets/shopify/Dockerfile +160 -0
- package/presets/shopify/bin/compare-version +3 -0
- package/presets/shopify/config.json +24 -0
- package/presets/shopify/etc/apache2/apache2.conf +230 -0
- package/presets/shopify/etc/apache2/mods-available/mpm_prefork.conf +16 -0
- package/presets/shopify/etc/apache2/sites-available/000-default.conf +21 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Preset = void 0;
|
|
7
|
+
var Path = _interopRequireWildcard(require("path"));
|
|
8
|
+
var _md = _interopRequireDefault(require("md5"));
|
|
9
|
+
var _env = require("../env");
|
|
10
|
+
var _makes = require("../makes");
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
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); }
|
|
13
|
+
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; }
|
|
14
|
+
class Preset {
|
|
15
|
+
constructor(data) {
|
|
16
|
+
if (data) {
|
|
17
|
+
for (const i in data) {
|
|
18
|
+
this[i] = data[i];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
getImageArgs(project) {
|
|
23
|
+
if (!this.buildArgsOptions) {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
return Object.keys(this.buildArgsOptions).reduce((buildArgs, key) => {
|
|
27
|
+
buildArgs[key] = project.buildArgs[key];
|
|
28
|
+
return buildArgs;
|
|
29
|
+
}, {});
|
|
30
|
+
}
|
|
31
|
+
getImageName(buildArgs) {
|
|
32
|
+
const rawValues = [];
|
|
33
|
+
const hashValues = [];
|
|
34
|
+
Object.keys(buildArgs).forEach(key => {
|
|
35
|
+
const {
|
|
36
|
+
[key]: {
|
|
37
|
+
hash = true
|
|
38
|
+
} = {}
|
|
39
|
+
} = this.buildArgsOptions || {};
|
|
40
|
+
const value = buildArgs[key];
|
|
41
|
+
if (hash) {
|
|
42
|
+
hashValues.push(value);
|
|
43
|
+
} else {
|
|
44
|
+
rawValues.push(value);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
const version = [...rawValues, (0, _md.default)(hashValues.join(",")).substr(0, 6)].filter(value => {
|
|
48
|
+
return !!value;
|
|
49
|
+
}).join("-");
|
|
50
|
+
return `ws-preset-${this.name}:${version}`;
|
|
51
|
+
}
|
|
52
|
+
static async get(name) {
|
|
53
|
+
const data = await _makes.FS.readJSON(Path.join(_env.PRESETS_DIR, name, "config.json"));
|
|
54
|
+
return new Preset({
|
|
55
|
+
name,
|
|
56
|
+
...data
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.Preset = Preset;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { EnvConfig } from "src/types";
|
|
2
|
+
type SearchOptions = {
|
|
3
|
+
id: string;
|
|
4
|
+
name: string;
|
|
5
|
+
src: string;
|
|
6
|
+
};
|
|
7
|
+
export declare class Project {
|
|
8
|
+
id: string;
|
|
9
|
+
type: string;
|
|
10
|
+
name: string;
|
|
11
|
+
path: string;
|
|
12
|
+
dockerfile?: string;
|
|
13
|
+
imageName?: string;
|
|
14
|
+
buildArgs?: EnvConfig;
|
|
15
|
+
env?: EnvConfig;
|
|
16
|
+
domains?: string[];
|
|
17
|
+
volumes?: string[];
|
|
18
|
+
meta?: {
|
|
19
|
+
[key: string]: string;
|
|
20
|
+
};
|
|
21
|
+
setEnv(name: string, value: string | boolean): void;
|
|
22
|
+
getEnv(name: string, defaultValue?: string): string;
|
|
23
|
+
unsetEnv(name: string): void;
|
|
24
|
+
getMeta(name: string, defaultValue?: string): string | undefined;
|
|
25
|
+
setMeta(name: string, value: string): void;
|
|
26
|
+
volumeMount(...volumes: string[]): void;
|
|
27
|
+
getVolumeBySource(source: string): string | undefined;
|
|
28
|
+
getVolumeByDestination(destination: string): string | undefined;
|
|
29
|
+
volumeUnmount(...volumes: string[]): void;
|
|
30
|
+
static get(id: string): Promise<void>;
|
|
31
|
+
save(): Promise<void>;
|
|
32
|
+
static fromObject(data: any): Project;
|
|
33
|
+
static search(params?: Partial<SearchOptions>): Promise<Project[]>;
|
|
34
|
+
static searchOne(params?: Partial<SearchOptions>): Promise<Project | null>;
|
|
35
|
+
}
|
|
36
|
+
export declare const PROJECT_TYPE_DOCKERFILE = "dockerfile";
|
|
37
|
+
export declare const PROJECT_TYPE_IMAGE = "image";
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Project = exports.PROJECT_TYPE_IMAGE = exports.PROJECT_TYPE_DOCKERFILE = void 0;
|
|
7
|
+
var Path = _interopRequireWildcard(require("path"));
|
|
8
|
+
var _makes = require("../makes");
|
|
9
|
+
var _utils = require("../utils");
|
|
10
|
+
var _env = require("../env");
|
|
11
|
+
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); }
|
|
12
|
+
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; }
|
|
13
|
+
class Project {
|
|
14
|
+
setEnv(name, value) {
|
|
15
|
+
this.env = {
|
|
16
|
+
...(this.env || {}),
|
|
17
|
+
[name]: typeof value === "boolean" ? value ? "true" : "false" : value
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
getEnv(name, defaultValue) {
|
|
21
|
+
const {
|
|
22
|
+
[name]: value = defaultValue
|
|
23
|
+
} = this.env || {};
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
unsetEnv(name) {
|
|
27
|
+
if (this.env && this.env[name]) {
|
|
28
|
+
delete this.env[name];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
getMeta(name, defaultValue) {
|
|
32
|
+
const {
|
|
33
|
+
[name]: value = defaultValue
|
|
34
|
+
} = this.meta || {};
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
37
|
+
setMeta(name, value) {
|
|
38
|
+
if (!this.meta) {
|
|
39
|
+
this.meta = {};
|
|
40
|
+
}
|
|
41
|
+
this.meta[name] = value;
|
|
42
|
+
}
|
|
43
|
+
volumeMount(...volumes) {
|
|
44
|
+
if (volumes.length === 0) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const [volume, ...restVolumes] = volumes;
|
|
48
|
+
const {
|
|
49
|
+
destination
|
|
50
|
+
} = (0, _utils.volumeParse)(volume);
|
|
51
|
+
this.volumes = [...(this.volumes || []).filter(v => {
|
|
52
|
+
return v !== this.getVolumeByDestination(destination);
|
|
53
|
+
}), volume];
|
|
54
|
+
this.volumeMount(...restVolumes);
|
|
55
|
+
}
|
|
56
|
+
getVolumeBySource(source) {
|
|
57
|
+
return (this.volumes || []).find(volume => {
|
|
58
|
+
return (0, _utils.volumeParse)(volume).source === source;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
getVolumeByDestination(destination) {
|
|
62
|
+
return (this.volumes || []).find(volume => {
|
|
63
|
+
return (0, _utils.volumeParse)(volume).destination === destination;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
volumeUnmount(...volumes) {
|
|
67
|
+
this.volumes = this.volumes.filter(mounted => {
|
|
68
|
+
return !volumes.includes(mounted);
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
static async get(id) {
|
|
72
|
+
//
|
|
73
|
+
}
|
|
74
|
+
async save() {
|
|
75
|
+
if (!this.name) {
|
|
76
|
+
throw new Error("Project should has a name");
|
|
77
|
+
}
|
|
78
|
+
if (!this.path) {
|
|
79
|
+
throw new Error("Project should has a path");
|
|
80
|
+
}
|
|
81
|
+
if (!this.id) {
|
|
82
|
+
this.id = this.name;
|
|
83
|
+
}
|
|
84
|
+
const projectDirPath = Path.join(_env.DATA_DIR, "projects", this.name);
|
|
85
|
+
if (!_makes.FS.existsSync(projectDirPath)) {
|
|
86
|
+
await _makes.FS.mkdir(projectDirPath);
|
|
87
|
+
}
|
|
88
|
+
const configPath = Path.join(_env.DATA_DIR, "projects", this.id, "config.json");
|
|
89
|
+
await _makes.FS.writeJSON(configPath, this);
|
|
90
|
+
const config = await (0, _utils.getConfig)();
|
|
91
|
+
await (0, _utils.setConfig)({
|
|
92
|
+
...config,
|
|
93
|
+
projects: [...(config.projects || []).filter(project => {
|
|
94
|
+
return project.id !== this.id;
|
|
95
|
+
}).filter(project => {
|
|
96
|
+
return project.src !== this.path;
|
|
97
|
+
}), {
|
|
98
|
+
id: this.id,
|
|
99
|
+
src: this.path
|
|
100
|
+
}]
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
static fromObject(data) {
|
|
104
|
+
const project = new Project();
|
|
105
|
+
for (const i in data) {
|
|
106
|
+
project[i] = data[i];
|
|
107
|
+
}
|
|
108
|
+
return project;
|
|
109
|
+
}
|
|
110
|
+
static async search(params = {}) {
|
|
111
|
+
const {
|
|
112
|
+
id,
|
|
113
|
+
name,
|
|
114
|
+
src
|
|
115
|
+
} = params;
|
|
116
|
+
const map = await _makes.FS.readJSON(_env.MAP_PATH);
|
|
117
|
+
const mapProjects = map.projects.filter(config => {
|
|
118
|
+
if (id) {
|
|
119
|
+
return config.id === id;
|
|
120
|
+
}
|
|
121
|
+
return true;
|
|
122
|
+
}).filter(config => {
|
|
123
|
+
if (src) {
|
|
124
|
+
return config.src === src;
|
|
125
|
+
}
|
|
126
|
+
return true;
|
|
127
|
+
});
|
|
128
|
+
const projects = [];
|
|
129
|
+
for (const i in mapProjects) {
|
|
130
|
+
const projectConfig = await _makes.FS.readJSON(Path.join(_env.DATA_DIR, "projects", mapProjects[i].id, "config.json"));
|
|
131
|
+
const project = Project.fromObject({
|
|
132
|
+
...projectConfig,
|
|
133
|
+
id: projectConfig.id
|
|
134
|
+
});
|
|
135
|
+
if (name && project.name !== name) {
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
projects.push(project);
|
|
139
|
+
}
|
|
140
|
+
return projects;
|
|
141
|
+
}
|
|
142
|
+
static async searchOne(params = {}) {
|
|
143
|
+
const [project] = await Project.search(params);
|
|
144
|
+
return project || null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
exports.Project = Project;
|
|
148
|
+
const PROJECT_TYPE_DOCKERFILE = "dockerfile";
|
|
149
|
+
exports.PROJECT_TYPE_DOCKERFILE = PROJECT_TYPE_DOCKERFILE;
|
|
150
|
+
const PROJECT_TYPE_IMAGE = "image";
|
|
151
|
+
exports.PROJECT_TYPE_IMAGE = PROJECT_TYPE_IMAGE;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
var _Preset = require("./Preset");
|
|
7
|
+
Object.keys(_Preset).forEach(function (key) {
|
|
8
|
+
if (key === "default" || key === "__esModule") return;
|
|
9
|
+
if (key in exports && exports[key] === _Preset[key]) return;
|
|
10
|
+
Object.defineProperty(exports, key, {
|
|
11
|
+
enumerable: true,
|
|
12
|
+
get: function () {
|
|
13
|
+
return _Preset[key];
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
var _Project = require("./Project");
|
|
18
|
+
Object.keys(_Project).forEach(function (key) {
|
|
19
|
+
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (key in exports && exports[key] === _Project[key]) return;
|
|
21
|
+
Object.defineProperty(exports, key, {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function () {
|
|
24
|
+
return _Project[key];
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Cli } from "@kearisp/cli";
|
|
2
|
+
import { Plugin } from "src/makes";
|
|
3
|
+
import { Project } from "src/models";
|
|
4
|
+
import { AppConfigService, AppEventsService, ProjectService } from "src/services";
|
|
5
|
+
type InitOptions = {
|
|
6
|
+
name?: string;
|
|
7
|
+
};
|
|
8
|
+
type StartOptions = {
|
|
9
|
+
name?: string;
|
|
10
|
+
detach?: boolean;
|
|
11
|
+
};
|
|
12
|
+
type StopOptions = {
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
15
|
+
type LogsOptions = {
|
|
16
|
+
name?: string;
|
|
17
|
+
detach?: boolean;
|
|
18
|
+
};
|
|
19
|
+
declare class LocaltunnelPlugin extends Plugin {
|
|
20
|
+
protected appConfigService: AppConfigService;
|
|
21
|
+
protected appEventsService: AppEventsService;
|
|
22
|
+
protected projectService: ProjectService;
|
|
23
|
+
constructor(appConfigService: AppConfigService, appEventsService: AppEventsService, projectService: ProjectService);
|
|
24
|
+
install(cli: Cli): void;
|
|
25
|
+
getIp(): Promise<string>;
|
|
26
|
+
onProjectStart(project: Project): Promise<void>;
|
|
27
|
+
onProjectStop(project: Project): Promise<void>;
|
|
28
|
+
build(): Promise<void>;
|
|
29
|
+
rebuild(): Promise<void>;
|
|
30
|
+
init(options: InitOptions): Promise<void>;
|
|
31
|
+
start(options: StartOptions): Promise<void>;
|
|
32
|
+
stop(options: StopOptions): Promise<void>;
|
|
33
|
+
restart(options: StartOptions): Promise<void>;
|
|
34
|
+
logs(options: LogsOptions): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
export { LocaltunnelPlugin };
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.LocaltunnelPlugin = void 0;
|
|
7
|
+
var _axios = _interopRequireDefault(require("axios"));
|
|
8
|
+
var _makes = require("../makes");
|
|
9
|
+
var _utils = require("../utils");
|
|
10
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
+
class LocaltunnelPlugin extends _makes.Plugin {
|
|
12
|
+
constructor(appConfigService, appEventsService, projectService) {
|
|
13
|
+
super("localtunnel");
|
|
14
|
+
this.appConfigService = appConfigService;
|
|
15
|
+
this.appEventsService = appEventsService;
|
|
16
|
+
this.projectService = projectService;
|
|
17
|
+
}
|
|
18
|
+
install(cli) {
|
|
19
|
+
super.install(cli);
|
|
20
|
+
this.appEventsService.on("project:start", project => this.onProjectStart(project));
|
|
21
|
+
this.appEventsService.on("project:stop", project => this.onProjectStop(project));
|
|
22
|
+
cli.command("localtunnel:init").option("name", {
|
|
23
|
+
alias: "n",
|
|
24
|
+
type: "string",
|
|
25
|
+
description: "Project name"
|
|
26
|
+
}).action(options => this.init(options));
|
|
27
|
+
cli.command("localtunnel:start").option("name", {
|
|
28
|
+
alias: "n",
|
|
29
|
+
type: "string",
|
|
30
|
+
description: "Project name"
|
|
31
|
+
}).option("detach", {
|
|
32
|
+
type: "boolean",
|
|
33
|
+
alias: "d",
|
|
34
|
+
description: "Detach"
|
|
35
|
+
}).action(options => this.start(options));
|
|
36
|
+
cli.command("localtunnel:restart").option("name", {
|
|
37
|
+
alias: "n",
|
|
38
|
+
type: "string",
|
|
39
|
+
description: "Project name"
|
|
40
|
+
}).option("detach", {
|
|
41
|
+
type: "boolean",
|
|
42
|
+
alias: "d",
|
|
43
|
+
description: "Detach"
|
|
44
|
+
}).action(options => this.restart(options));
|
|
45
|
+
cli.command("localtunnel:stop").option("name", {
|
|
46
|
+
alias: "n",
|
|
47
|
+
type: "string",
|
|
48
|
+
description: "Project name"
|
|
49
|
+
}).action(options => this.stop(options));
|
|
50
|
+
cli.command("localtunnel:build").action(() => this.build());
|
|
51
|
+
cli.command("localtunnel:rebuild").action(() => this.rebuild());
|
|
52
|
+
cli.command("localtunnel:logs").option("name", {
|
|
53
|
+
alias: "n",
|
|
54
|
+
type: "string",
|
|
55
|
+
description: "Project name"
|
|
56
|
+
}).option("detach", {
|
|
57
|
+
type: "boolean",
|
|
58
|
+
alias: "d",
|
|
59
|
+
description: "Detach"
|
|
60
|
+
}).action(options => this.logs(options));
|
|
61
|
+
}
|
|
62
|
+
async getIp() {
|
|
63
|
+
const res = await _axios.default.get("https://ipv4.icanhazip.com");
|
|
64
|
+
return res.data.replace("\n", "");
|
|
65
|
+
}
|
|
66
|
+
async onProjectStart(project) {
|
|
67
|
+
if (!project || project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
let container = await _makes.Docker.getContainer(`localtunnel-${project.name}`);
|
|
71
|
+
if (container) {
|
|
72
|
+
const {
|
|
73
|
+
State: {
|
|
74
|
+
Running
|
|
75
|
+
}
|
|
76
|
+
} = await container.inspect();
|
|
77
|
+
if (Running) {
|
|
78
|
+
console.info("Localtunnel is already running");
|
|
79
|
+
return;
|
|
80
|
+
} else {
|
|
81
|
+
await _makes.Docker.removeContainer(`localtunnel-${project.name}`);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
console.info("Localtunnel starting...");
|
|
85
|
+
_makes.Logger.info(`Localtunnel start: ${project.name}`);
|
|
86
|
+
await this.build();
|
|
87
|
+
const subdomain = project.getEnv("LOCALTUNNEL_SUBDOMAIN", project.name);
|
|
88
|
+
container = await _makes.Docker.createContainer({
|
|
89
|
+
name: `localtunnel-${project.name}`,
|
|
90
|
+
image: "ws-localtunnel",
|
|
91
|
+
// tty: true,
|
|
92
|
+
restart: "always",
|
|
93
|
+
networkMode: "host",
|
|
94
|
+
cmd: ["lt", `--port=80`,
|
|
95
|
+
// `--local-host=${project.name}.workspace`,
|
|
96
|
+
`--subdomain=${subdomain}`, "--print-requests"]
|
|
97
|
+
});
|
|
98
|
+
const stream = await container.attach({
|
|
99
|
+
logs: true,
|
|
100
|
+
stream: true,
|
|
101
|
+
hijack: true,
|
|
102
|
+
stdin: true,
|
|
103
|
+
stdout: true,
|
|
104
|
+
stderr: true
|
|
105
|
+
});
|
|
106
|
+
stream.setEncoding("utf8");
|
|
107
|
+
await container.start();
|
|
108
|
+
const link = await new Promise((resolve, reject) => {
|
|
109
|
+
let res = "";
|
|
110
|
+
stream.on("data", data => {
|
|
111
|
+
const regLink = /(https?):\/\/(\w[\w.-]+[a-z]|\d+\.\d+\.\d+\.\d+)(?::(\d+))?/;
|
|
112
|
+
if (regLink.test(data.toString())) {
|
|
113
|
+
const [link] = regLink.exec(data.toString());
|
|
114
|
+
if (link.includes(".loca.lt")) {
|
|
115
|
+
res = link;
|
|
116
|
+
stream.end();
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
stream.on("end", () => resolve(res));
|
|
121
|
+
stream.on("error", reject);
|
|
122
|
+
});
|
|
123
|
+
_makes.Logger.info(`${project.name} localtunnel forwarding: ${link}`);
|
|
124
|
+
const ip = await this.getIp();
|
|
125
|
+
console.info(`IP: ${ip}`);
|
|
126
|
+
console.info(`Forwarding: ${link}`);
|
|
127
|
+
if (project.getEnv("LOCALTUNNEL_AUTO_CONFIRM", "false") === "true") {
|
|
128
|
+
console.info("Skipping IP confirmation...");
|
|
129
|
+
const res = await _axios.default.get(link, {
|
|
130
|
+
headers: {
|
|
131
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"
|
|
132
|
+
},
|
|
133
|
+
validateStatus: () => true
|
|
134
|
+
});
|
|
135
|
+
const [path] = /\/continue\/[\w.]+/.exec(res.data) || [];
|
|
136
|
+
if (path) {
|
|
137
|
+
const sendData = new URLSearchParams({
|
|
138
|
+
endpoint: ip
|
|
139
|
+
});
|
|
140
|
+
const res = await _axios.default.post(`${link}${path}`, sendData.toString(), {
|
|
141
|
+
headers: {
|
|
142
|
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36",
|
|
143
|
+
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8"
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
if (res.status === 200) {
|
|
147
|
+
console.info("IP confirmed");
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
async onProjectStop(project) {
|
|
153
|
+
if (!project || project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
console.info("Localtunnel stopping...");
|
|
157
|
+
await _makes.Docker.removeContainer(`localtunnel-${project.name}`);
|
|
158
|
+
}
|
|
159
|
+
async build() {
|
|
160
|
+
const exists = await _makes.Docker.imageExists("ws-localtunnel");
|
|
161
|
+
if (!exists) {
|
|
162
|
+
await _makes.Docker.imageBuild({
|
|
163
|
+
tag: "ws-localtunnel",
|
|
164
|
+
context: this.pluginPath(),
|
|
165
|
+
src: "./Dockerfile"
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
async rebuild() {
|
|
170
|
+
try {
|
|
171
|
+
await _makes.Docker.imageRm("ws-localtunnel");
|
|
172
|
+
} catch (err) {
|
|
173
|
+
console.info(err.message);
|
|
174
|
+
}
|
|
175
|
+
await this.build();
|
|
176
|
+
}
|
|
177
|
+
async init(options) {
|
|
178
|
+
const {
|
|
179
|
+
name
|
|
180
|
+
} = options;
|
|
181
|
+
if (name) {
|
|
182
|
+
await this.projectService.cdProject(name);
|
|
183
|
+
}
|
|
184
|
+
const project = await this.projectService.get();
|
|
185
|
+
const enabled = await (0, _utils.promptConfirm)({
|
|
186
|
+
message: "Enable localtunnel?",
|
|
187
|
+
default: project.getEnv("LOCALTUNNEL_ENABLE", "false") === "true"
|
|
188
|
+
});
|
|
189
|
+
if (enabled) {
|
|
190
|
+
const subdomain = await (0, _utils.promptText)({
|
|
191
|
+
message: "Subdomain",
|
|
192
|
+
prefix: "https://",
|
|
193
|
+
suffix: ".loca.lt",
|
|
194
|
+
default: project.getEnv("LOCALTUNNEL_SUBDOMAIN")
|
|
195
|
+
});
|
|
196
|
+
if (!subdomain) {
|
|
197
|
+
throw new Error("Subdomain can't be empty");
|
|
198
|
+
}
|
|
199
|
+
const autoConfirmIP = await (0, _utils.promptConfirm)({
|
|
200
|
+
message: "Do you want to skip the IP confirmation form automatically?",
|
|
201
|
+
default: project.getEnv("LOCALTUNNEL_AUTO_CONFIRM", "true") === "true"
|
|
202
|
+
});
|
|
203
|
+
project.setEnv("LOCALTUNNEL_ENABLE", "true");
|
|
204
|
+
project.setEnv("LOCALTUNNEL_SUBDOMAIN", subdomain);
|
|
205
|
+
project.setEnv("LOCALTUNNEL_AUTO_CONFIRM", autoConfirmIP ? "true" : "false");
|
|
206
|
+
} else {
|
|
207
|
+
project.setEnv("LOCALTUNNEL_ENABLE", "false");
|
|
208
|
+
}
|
|
209
|
+
await project.save();
|
|
210
|
+
}
|
|
211
|
+
async start(options) {
|
|
212
|
+
const {
|
|
213
|
+
name,
|
|
214
|
+
detach
|
|
215
|
+
} = options;
|
|
216
|
+
if (name) {
|
|
217
|
+
await this.projectService.cdProject(name);
|
|
218
|
+
}
|
|
219
|
+
const project = await this.projectService.get();
|
|
220
|
+
if (project.getEnv("LOCALTUNNEL_ENABLE", "false") !== "true") {
|
|
221
|
+
throw new Error(`Localtunnel is not initialized. Run "ws localtunnel:init${name ? ` -n=${name}` : ""}" first.`);
|
|
222
|
+
}
|
|
223
|
+
await this.onProjectStart(project);
|
|
224
|
+
if (!detach) {
|
|
225
|
+
await this.logs({
|
|
226
|
+
name
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
async stop(options) {
|
|
231
|
+
const {
|
|
232
|
+
name
|
|
233
|
+
} = options;
|
|
234
|
+
if (name) {
|
|
235
|
+
await this.projectService.cdProject(name);
|
|
236
|
+
}
|
|
237
|
+
const project = await this.projectService.get();
|
|
238
|
+
await this.onProjectStop(project);
|
|
239
|
+
}
|
|
240
|
+
async restart(options) {
|
|
241
|
+
const {
|
|
242
|
+
name
|
|
243
|
+
} = options;
|
|
244
|
+
await this.stop({
|
|
245
|
+
name
|
|
246
|
+
});
|
|
247
|
+
await this.start(options);
|
|
248
|
+
}
|
|
249
|
+
async logs(options) {
|
|
250
|
+
const {
|
|
251
|
+
name
|
|
252
|
+
// detach
|
|
253
|
+
} = options;
|
|
254
|
+
if (name) {
|
|
255
|
+
await this.projectService.cdProject(name);
|
|
256
|
+
}
|
|
257
|
+
const project = await this.projectService.get();
|
|
258
|
+
const container = await _makes.Docker.getContainer(`localtunnel-${project.name}`);
|
|
259
|
+
const stream = await container.logs({
|
|
260
|
+
follow: true,
|
|
261
|
+
stderr: true,
|
|
262
|
+
stdout: true,
|
|
263
|
+
tail: 5
|
|
264
|
+
});
|
|
265
|
+
stream.on("data", data => {
|
|
266
|
+
process.stdout.write(data);
|
|
267
|
+
});
|
|
268
|
+
stream.on("error", data => {
|
|
269
|
+
process.stderr.write(data);
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
exports.LocaltunnelPlugin = LocaltunnelPlugin;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Cli } from "@kearisp/cli";
|
|
2
|
+
import { Plugin } from "src/makes";
|
|
3
|
+
declare class MaildevPlugin extends Plugin {
|
|
4
|
+
protected containerName: string;
|
|
5
|
+
constructor();
|
|
6
|
+
install(cli: Cli): void;
|
|
7
|
+
start(): Promise<void>;
|
|
8
|
+
stop(): Promise<void>;
|
|
9
|
+
}
|
|
10
|
+
export { MaildevPlugin };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.MaildevPlugin = void 0;
|
|
7
|
+
var _makes = require("../makes");
|
|
8
|
+
class MaildevPlugin extends _makes.Plugin {
|
|
9
|
+
containerName = "maildev.workspace";
|
|
10
|
+
constructor() {
|
|
11
|
+
super("maildev");
|
|
12
|
+
}
|
|
13
|
+
install(cli) {
|
|
14
|
+
super.install(cli);
|
|
15
|
+
cli.command("maildev:start").action(() => this.start());
|
|
16
|
+
cli.command("maildev:stop").action(() => this.stop());
|
|
17
|
+
}
|
|
18
|
+
async start() {
|
|
19
|
+
console.log("Maildev starting...");
|
|
20
|
+
const imageName = "ws-maildev";
|
|
21
|
+
if (!(await _makes.Docker.imageExists(imageName))) {
|
|
22
|
+
await _makes.Docker.imageBuild({
|
|
23
|
+
tag: "ws-maildev",
|
|
24
|
+
buildArgs: {},
|
|
25
|
+
labels: {},
|
|
26
|
+
context: this.pluginPath(),
|
|
27
|
+
src: "./Dockerfile"
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
await _makes.Docker.containerRun({
|
|
31
|
+
name: this.containerName,
|
|
32
|
+
restart: "always",
|
|
33
|
+
env: {
|
|
34
|
+
VIRTUAL_HOST: "maildev.workspace"
|
|
35
|
+
},
|
|
36
|
+
ports: ["25:25"],
|
|
37
|
+
image: imageName
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
async stop() {
|
|
41
|
+
console.log("Maildev stopping...");
|
|
42
|
+
await _makes.Docker.removeContainer(this.containerName);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
exports.MaildevPlugin = MaildevPlugin;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Cli } from "@kearisp/cli";
|
|
2
|
+
import { Plugin } from "src/makes";
|
|
3
|
+
declare class MariadbPlugin extends Plugin {
|
|
4
|
+
protected dbDir: string;
|
|
5
|
+
protected user: string;
|
|
6
|
+
protected password: string;
|
|
7
|
+
constructor();
|
|
8
|
+
install(cli: Cli): void;
|
|
9
|
+
protected getDatabases(): Promise<string[]>;
|
|
10
|
+
protected getDumpDatabases(): Promise<string[]>;
|
|
11
|
+
protected getDumpFiles(database?: string): Promise<string[]>;
|
|
12
|
+
start(): Promise<void>;
|
|
13
|
+
protected startMariadb(): Promise<void>;
|
|
14
|
+
protected startAdmin(): Promise<void>;
|
|
15
|
+
stop(): Promise<void>;
|
|
16
|
+
protected stopMariadb(): Promise<void>;
|
|
17
|
+
protected stopAdmin(): Promise<void>;
|
|
18
|
+
exec(options: any, command: string[]): Promise<void>;
|
|
19
|
+
backup(database?: string): Promise<void>;
|
|
20
|
+
deleteBackup(options: any, database?: string, filename?: string): Promise<void>;
|
|
21
|
+
restore(options: any, database?: string, filename?: string): Promise<void>;
|
|
22
|
+
dump(options: any, database?: string): Promise<void>;
|
|
23
|
+
import(options: any, database?: string): Promise<void>;
|
|
24
|
+
}
|
|
25
|
+
export { MariadbPlugin };
|