@wocker/core 1.0.4 → 1.0.5

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/README.md CHANGED
@@ -1 +1,29 @@
1
1
  # @wocker/core
2
+
3
+ ###### Docker workspace for web projects
4
+
5
+ ## Installation
6
+
7
+ **Note:** It is recommended to install Wocker globally to ensure accessibility from any directory in your terminal.
8
+
9
+ ```shell
10
+ npm i -g @wocker/ws
11
+ ```
12
+
13
+
14
+ ### Completion
15
+
16
+ Wocker comes with shell completion support to enhance your development workflow. To enable shell completion, run the following command:
17
+
18
+ ```bash
19
+ source <(ws completion script)
20
+ ```
21
+
22
+ This will enable tab completion for `ws` commands, providing a more convenient and efficient way to interact with the tool.
23
+
24
+
25
+ ## Documentation
26
+
27
+ Wocker is a powerful tool for managing your web project's Docker workspace. It provides a convenient and efficient way to set up and manage your Docker containers.
28
+
29
+ For more information and detailed usage, please refer to the [documentation](https://kearisp.github.io/wocker).
package/lib/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./decorators/Inject";
3
3
  export * from "./decorators/Injectable";
4
4
  export * from "./makes/Controller";
5
5
  export * from "./makes/DI";
6
+ export * from "./makes/FS";
6
7
  export * from "./makes/FSManager";
7
8
  export * from "./makes/Logger";
8
9
  export * from "./makes/Plugin";
package/lib/index.js CHANGED
@@ -21,6 +21,7 @@ __exportStar(require("./decorators/Inject"), exports);
21
21
  __exportStar(require("./decorators/Injectable"), exports);
22
22
  __exportStar(require("./makes/Controller"), exports);
23
23
  __exportStar(require("./makes/DI"), exports);
24
+ __exportStar(require("./makes/FS"), exports);
24
25
  __exportStar(require("./makes/FSManager"), exports);
25
26
  __exportStar(require("./makes/Logger"), exports);
26
27
  __exportStar(require("./makes/Plugin"), exports);
package/lib/makes/FS.d.ts CHANGED
@@ -1,7 +1,19 @@
1
1
  /// <reference types="node" />
2
- import { PathOrFileDescriptor } from "fs";
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ /// <reference types="node" />
5
+ import { Abortable } from "node:events";
6
+ import { PathLike, PathOrFileDescriptor, WriteFileOptions, RmOptions, MakeDirectoryOptions } from "fs";
7
+ type ReadFileOptions = Abortable & {
8
+ encoding?: BufferEncoding;
9
+ flag?: string;
10
+ };
3
11
  declare class FS {
4
- static readJSON(filePath: PathOrFileDescriptor): Promise<any>;
5
- static writeJSON(filePath: PathOrFileDescriptor, data: any): Promise<void>;
12
+ static mkdir(path: PathLike, options?: MakeDirectoryOptions): Promise<unknown>;
13
+ static readFile(filePath: PathOrFileDescriptor, options?: ReadFileOptions): Promise<string | Buffer>;
14
+ static writeFile(filePath: PathOrFileDescriptor, data: string | NodeJS.ArrayBufferView, options?: WriteFileOptions): Promise<unknown>;
15
+ static readJSON(...paths: string[]): Promise<any>;
16
+ static writeJSON(filePath: PathOrFileDescriptor, data: any, options?: WriteFileOptions): Promise<void>;
17
+ static rm(path: PathLike, options?: RmOptions): Promise<void>;
6
18
  }
7
19
  export { FS };
package/lib/makes/FS.js CHANGED
@@ -1,4 +1,27 @@
1
1
  "use strict";
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;
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
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -11,10 +34,57 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
34
  Object.defineProperty(exports, "__esModule", { value: true });
12
35
  exports.FS = void 0;
13
36
  const fs_1 = require("fs");
37
+ const Path = __importStar(require("path"));
14
38
  class FS {
15
- static readJSON(filePath) {
39
+ static mkdir(path, options) {
40
+ return __awaiter(this, void 0, void 0, function* () {
41
+ return new Promise((resolve, reject) => {
42
+ (0, fs_1.mkdir)(path, options, (err) => {
43
+ if (err) {
44
+ reject(err);
45
+ return;
46
+ }
47
+ resolve(undefined);
48
+ });
49
+ });
50
+ });
51
+ }
52
+ static readFile(filePath, options) {
53
+ return __awaiter(this, void 0, void 0, function* () {
54
+ return new Promise((resolve, reject) => {
55
+ (0, fs_1.readFile)(filePath, options, (err, res) => {
56
+ if (err) {
57
+ reject(err);
58
+ return;
59
+ }
60
+ resolve(res);
61
+ });
62
+ });
63
+ });
64
+ }
65
+ static writeFile(filePath, data, options) {
66
+ return __awaiter(this, void 0, void 0, function* () {
67
+ return new Promise((resolve, reject) => {
68
+ const callback = (err) => {
69
+ if (err) {
70
+ reject(err);
71
+ return;
72
+ }
73
+ resolve(undefined);
74
+ };
75
+ if (options) {
76
+ (0, fs_1.writeFile)(filePath, data, options, callback);
77
+ }
78
+ else {
79
+ (0, fs_1.writeFile)(filePath, data, callback);
80
+ }
81
+ });
82
+ });
83
+ }
84
+ static readJSON(...paths) {
16
85
  return __awaiter(this, void 0, void 0, function* () {
17
86
  const res = yield new Promise((resolve, reject) => {
87
+ const filePath = Path.join(...paths);
18
88
  (0, fs_1.readFile)(filePath, (err, data) => {
19
89
  if (err) {
20
90
  reject(err);
@@ -26,17 +96,42 @@ class FS {
26
96
  return JSON.parse(res.toString());
27
97
  });
28
98
  }
29
- static writeJSON(filePath, data) {
99
+ static writeJSON(filePath, data, options) {
30
100
  return __awaiter(this, void 0, void 0, function* () {
31
101
  const json = JSON.stringify(data, null, 4);
32
102
  return new Promise((resolve, reject) => {
33
- (0, fs_1.writeFile)(filePath, json, (err) => {
103
+ const callback = (err) => {
34
104
  if (err) {
35
105
  reject(err);
36
106
  return;
37
107
  }
38
108
  resolve(undefined);
39
- });
109
+ };
110
+ if (options) {
111
+ (0, fs_1.writeFile)(filePath, json, options, callback);
112
+ }
113
+ else {
114
+ (0, fs_1.writeFile)(filePath, json, callback);
115
+ }
116
+ });
117
+ });
118
+ }
119
+ static rm(path, options) {
120
+ return __awaiter(this, void 0, void 0, function* () {
121
+ return new Promise((resolve, reject) => {
122
+ const callback = (err) => {
123
+ if (err) {
124
+ reject(err);
125
+ return;
126
+ }
127
+ resolve(undefined);
128
+ };
129
+ if (options) {
130
+ (0, fs_1.rm)(path, options, callback);
131
+ }
132
+ else {
133
+ (0, fs_1.rm)(path, callback);
134
+ }
40
135
  });
41
136
  });
42
137
  }
@@ -3,7 +3,7 @@ declare class Logger {
3
3
  static install(di: DI): void;
4
4
  static log(...data: any[]): void;
5
5
  static info(...data: any[]): void;
6
- static warning(...data: any[]): void;
6
+ static warn(...data: any[]): void;
7
7
  static error(...data: any[]): void;
8
8
  }
9
9
  export { Logger };
@@ -13,8 +13,8 @@ class Logger {
13
13
  static info(...data) {
14
14
  _di.resolveService(LogService_1.LogService).info(...data);
15
15
  }
16
- static warning(...data) {
17
- _di.resolveService(LogService_1.LogService).warning(...data);
16
+ static warn(...data) {
17
+ _di.resolveService(LogService_1.LogService).warn(...data);
18
18
  }
19
19
  static error(...data) {
20
20
  _di.resolveService(LogService_1.LogService).error(...data);
@@ -17,14 +17,20 @@ declare class Project {
17
17
  scripts?: string[];
18
18
  buildArgs?: EnvConfig;
19
19
  env: EnvConfig;
20
- volumes?: string[];
21
20
  ports?: string[];
21
+ volumes?: string[];
22
+ metadata?: EnvConfig;
22
23
  static di?: DI;
23
24
  constructor(data: any);
25
+ get containerName(): string;
24
26
  hasEnv(name: string): boolean;
25
27
  getEnv(name: string, defaultValue?: string): string | undefined;
26
28
  setEnv(name: string, value: string | boolean): void;
27
29
  unsetEnv(name: string): void;
30
+ hasMeta(name: string): boolean;
31
+ getMeta<D = string | undefined>(name: string, defaultValue?: D): D;
32
+ setMeta(name: string, value: string | boolean): void;
33
+ unsetMeta(name: string): void;
28
34
  volumeMount(...volumes: string[]): void;
29
35
  getVolumeBySource(source: string): string | undefined;
30
36
  getVolumeByDestination(destination: string): string | undefined;
@@ -30,6 +30,10 @@ class Project {
30
30
  this.env = data.env || {};
31
31
  this.ports = data.ports;
32
32
  this.volumes = data.volumes;
33
+ this.metadata = data.metadata;
34
+ }
35
+ get containerName() {
36
+ return `${this.name}.workspace`;
33
37
  }
34
38
  hasEnv(name) {
35
39
  if (!this.env) {
@@ -51,6 +55,29 @@ class Project {
51
55
  delete this.env[name];
52
56
  }
53
57
  }
58
+ hasMeta(name) {
59
+ return !!this.metadata && this.metadata.hasOwnProperty(name);
60
+ }
61
+ getMeta(name, defaultValue) {
62
+ const { [name]: value = defaultValue } = this.metadata || {};
63
+ return value;
64
+ }
65
+ setMeta(name, value) {
66
+ if (!this.metadata) {
67
+ this.metadata = {};
68
+ }
69
+ this.metadata[name] = typeof value === "boolean"
70
+ ? (value ? "true" : "false")
71
+ : value;
72
+ }
73
+ unsetMeta(name) {
74
+ if (this.metadata && name in this.metadata) {
75
+ delete this.metadata[name];
76
+ }
77
+ if (this.metadata && Object.keys(this.metadata).length === 0) {
78
+ delete this.metadata;
79
+ }
80
+ }
54
81
  volumeMount(...volumes) {
55
82
  if (volumes.length === 0) {
56
83
  return;
@@ -1,7 +1,7 @@
1
1
  declare abstract class LogService {
2
2
  abstract log(...data: any[]): void;
3
3
  abstract info(...data: any[]): void;
4
- abstract warning(...data: any[]): void;
4
+ abstract warn(...data: any[]): void;
5
5
  abstract error(...data: any[]): void;
6
6
  }
7
7
  export { LogService };
@@ -1,3 +1,4 @@
1
+ import { Container } from "dockerode";
1
2
  import { Project } from "../models/Project";
2
3
  type SearchParams = Partial<{
3
4
  id: string;
@@ -7,6 +8,7 @@ type SearchParams = Partial<{
7
8
  declare abstract class ProjectService {
8
9
  abstract cdProject(name: string): Promise<void>;
9
10
  abstract get(): Promise<Project>;
11
+ abstract getContainer(): Promise<Container | null>;
10
12
  abstract start(project: Project): Promise<void>;
11
13
  abstract stop(project: Project): Promise<void>;
12
14
  abstract save(project: Project): Promise<void>;
package/package.json CHANGED
@@ -1,11 +1,22 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "author": "Kris Papercut <krispcut@gmail.com>",
5
- "description": "Wocker Core",
5
+ "description": "Core of wocker",
6
6
  "license": "MIT",
7
7
  "main": "lib/index.js",
8
8
  "types": "lib/index.d.ts",
9
+ "keywords": [
10
+ "wocker"
11
+ ],
12
+ "homepage": "https://kearisp.github.io/wocker",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/kearisp/wocker-core.git"
16
+ },
17
+ "bugs": {
18
+ "url": "https://github.com/kearisp/wocker-core/issues"
19
+ },
9
20
  "scripts": {
10
21
  "prepare": "npm run build",
11
22
  "watch": "tsc -w",
@@ -13,14 +24,14 @@
13
24
  "test": "echo \"Error: no test specified\" && exit 1"
14
25
  },
15
26
  "dependencies": {
16
- "@kearisp/cli": "^1.0.3",
27
+ "@kearisp/cli": "^1.0.5",
17
28
  "fs": "^0.0.1-security",
18
29
  "path": "^0.12.7",
19
- "reflect-metadata": "^0.1.13"
30
+ "reflect-metadata": "^0.2.1"
20
31
  },
21
32
  "devDependencies": {
22
33
  "@types/dockerode": "^3.3.23",
23
- "@types/node": "^20.8.9",
24
- "typescript": "^5.2.2"
34
+ "@types/node": "^20.11.7",
35
+ "typescript": "^5.3.3"
25
36
  }
26
37
  }