@wocker/core 1.1.3 → 1.1.4-beta.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.
@@ -1,5 +1,5 @@
1
1
  import { FileSystem } from "./FileSystem";
2
- import { EnvConfig, PackageManagerType, PluginRef, PresetRef, ProjectRef, ProjectOldRef, PresetSource } from "../types";
2
+ import { EnvConfig, PackageManagerType, PluginRef, PresetRef, ProjectRef, ProjectOldRef } from "../types";
3
3
  export declare abstract class AppConfig {
4
4
  debug?: boolean;
5
5
  pm?: PackageManagerType;
@@ -16,8 +16,8 @@ export declare abstract class AppConfig {
16
16
  getProjectByPath(path: string): ProjectRef | undefined;
17
17
  addProject(name: string, path: string): void;
18
18
  removeProject(name: string): void;
19
- registerPreset(name: string, source: PresetSource, path?: string): void;
20
- unregisterPreset(name: string): void;
19
+ registerPreset(presetRef: PresetRef): void;
20
+ unregisterPreset(path: string): void;
21
21
  hasMeta(name: string): boolean;
22
22
  getMeta(name: string, defaultValue?: string): string | undefined;
23
23
  getMeta(name: string, defaultValue: string): string;
@@ -12,7 +12,6 @@ var __rest = (this && this.__rest) || function (s, e) {
12
12
  };
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.AppConfig = void 0;
15
- const types_1 = require("../types");
16
15
  class AppConfig {
17
16
  constructor(data) {
18
17
  const { plugins = [], presets = [], projects = [] } = data, rest = __rest(data, ["plugins", "presets", "projects"]);
@@ -86,37 +85,30 @@ class AppConfig {
86
85
  return projectData.name !== name;
87
86
  });
88
87
  }
89
- registerPreset(name, source, path) {
90
- if (source === types_1.PresetSource.INTERNAL) {
88
+ registerPreset(presetRef) {
89
+ const { name, path } = presetRef;
90
+ if (!path) {
91
91
  return;
92
92
  }
93
93
  let presetData = this.presets.find((preset) => {
94
- if (source === types_1.PresetSource.EXTERNAL && preset.path === path) {
95
- return true;
96
- }
97
- return preset.name === name;
94
+ return preset.path === path;
98
95
  });
99
96
  if (!presetData) {
100
97
  presetData = {
101
98
  name,
102
- source
99
+ path
103
100
  };
104
101
  this.presets.push(presetData);
105
102
  }
106
- presetData.source = source;
107
- if (presetData.source === types_1.PresetSource.EXTERNAL) {
108
- presetData.path = path;
109
- }
110
- else if (presetData.path) {
111
- delete presetData.path;
112
- }
103
+ presetData.name = name;
104
+ presetData.path = path;
113
105
  }
114
- unregisterPreset(name) {
106
+ unregisterPreset(path) {
115
107
  if (this.presets.length === 0) {
116
108
  return;
117
109
  }
118
110
  this.presets = this.presets.filter((preset) => {
119
- return preset.name !== name;
111
+ return preset.path !== path;
120
112
  });
121
113
  }
122
114
  hasMeta(name) {
package/lib/makes/File.js CHANGED
@@ -103,7 +103,7 @@ class File {
103
103
  throw new Error("Line number must be a non-zero");
104
104
  }
105
105
  const bufferSize = 1024, isForward = line > 0, targetLine = Math.abs(line), stats = this.stat();
106
- let position = isForward ? 0 : stats.size, currentLine = 0, currentOffset = isForward ? 0 : stats.size + 1, stump = "";
106
+ let position = isForward ? 0 : stats.size, currentLine = 0, currentOffset = isForward ? 0 : stats.size + 1, stump = "", isFirstChunk = true;
107
107
  while (isForward ? position < stats.size : position > 0) {
108
108
  const readSize = isForward
109
109
  ? Math.min(bufferSize, stats.size - position)
@@ -115,6 +115,11 @@ class File {
115
115
  if (isForward) {
116
116
  position += readSize;
117
117
  }
118
+ if (!isForward && isFirstChunk && lines[lines.length - 1] === "") {
119
+ lines.pop();
120
+ currentOffset -= 1;
121
+ }
122
+ isFirstChunk = false;
118
123
  if (isForward ? position === stats.size : position === 0) {
119
124
  stump = "";
120
125
  }
@@ -1,6 +1,8 @@
1
+ import { Version } from "./Version";
1
2
  import { VersionRule } from "./VersionRule";
2
3
  export declare class VersionRange {
3
4
  protected rules: VersionRule[][];
4
5
  constructor(rules: VersionRule[][]);
6
+ match(version: string | Version, withTag?: boolean): boolean;
5
7
  static parse(range: string): VersionRange;
6
8
  }
@@ -1,17 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VersionRange = void 0;
4
+ const Version_1 = require("./Version");
4
5
  const VersionRule_1 = require("./VersionRule");
5
6
  class VersionRange {
6
7
  constructor(rules) {
7
8
  this.rules = rules;
8
9
  }
9
- static parse(range) {
10
- const rules = range.split("||").map((range) => {
11
- return range.split(" ").map((rule) => {
12
- return VersionRule_1.VersionRule.parse(rule);
10
+ match(version, withTag) {
11
+ if (typeof version === "string") {
12
+ version = Version_1.Version.parse(version);
13
+ }
14
+ return this.rules.some((rules) => {
15
+ return rules.every((rule) => {
16
+ return rule.match(version, withTag);
13
17
  });
14
18
  });
19
+ }
20
+ static parse(range) {
21
+ const rules = range.split("||").map((group) => {
22
+ return group
23
+ .trim()
24
+ .split(/\s+/)
25
+ .filter((rule) => rule.length > 0)
26
+ .map((rule) => VersionRule_1.VersionRule.parse(rule));
27
+ });
15
28
  return new VersionRange(rules);
16
29
  }
17
30
  }
@@ -53,5 +53,6 @@ export declare namespace ContainerService {
53
53
  };
54
54
  type LogsParams = {
55
55
  signal?: AbortSignal;
56
+ tail?: number;
56
57
  };
57
58
  }
@@ -1,19 +1,34 @@
1
1
  import { PickProperties, PresetSource } from "../../../types";
2
- type TextOption = {
2
+ export type PresetVariableCondition = {
3
+ variable: string;
4
+ equals?: string;
5
+ notEquals?: string;
6
+ in?: string[];
7
+ notIn?: string[];
8
+ contains?: string;
9
+ includes?: string | string[];
10
+ };
11
+ type BaseVariableConfig = {
12
+ when?: PresetVariableCondition;
13
+ };
14
+ type TextOption = BaseVariableConfig & {
3
15
  type: "text" | "string" | "number" | "int" | "password";
4
16
  message?: string;
5
17
  default?: string | number;
6
18
  };
7
- type ConfirmOption = {
19
+ type ConfirmOption = BaseVariableConfig & {
8
20
  type: "boolean";
9
21
  message?: string;
10
22
  required?: boolean;
11
23
  default?: boolean;
12
24
  };
13
- type SelectOption = {
25
+ export type PresetSelectMode = "flags" | "variable";
26
+ type SelectOption = BaseVariableConfig & {
14
27
  type: "select";
15
28
  required?: boolean;
16
29
  multiple?: boolean;
30
+ mode?: PresetSelectMode;
31
+ delimiter?: string;
17
32
  options: string[] | {
18
33
  label?: string;
19
34
  value: string;
@@ -27,8 +42,8 @@ export type PresetVariableConfig = TextOption | ConfirmOption | SelectOption;
27
42
  export type PresetProperties = PickProperties<Preset>;
28
43
  export declare abstract class Preset {
29
44
  name: string;
30
- source?: PresetSource;
31
45
  version: string;
46
+ source?: PresetSource;
32
47
  type?: string;
33
48
  image?: string;
34
49
  dockerfile?: string;
@@ -3,6 +3,7 @@ import { Preset } from "../makes/Preset";
3
3
  type SearchOptions = Partial<{
4
4
  name: string;
5
5
  source: string;
6
+ version: string;
6
7
  path: string;
7
8
  }>;
8
9
  declare abstract class PresetService {
@@ -67,10 +67,21 @@ let AppConfigService = class AppConfigService {
67
67
  this.appService.removePlugin(name);
68
68
  }
69
69
  registerPreset(name, source, path) {
70
- this.appService.registerPreset(name, source, path);
70
+ if (!path) {
71
+ return;
72
+ }
73
+ this.appService.registerPreset({
74
+ name,
75
+ source,
76
+ path
77
+ });
71
78
  }
72
79
  unregisterPreset(name) {
73
- this.appService.unregisterPreset(name);
80
+ const preset = this.appService.config.presets.find(p => p.name === name);
81
+ if (!preset || !preset.path) {
82
+ return;
83
+ }
84
+ this.appService.unregisterPreset(preset.path);
74
85
  }
75
86
  getEnv(key, byDefault) {
76
87
  return this.appService.getEnv(key, byDefault);
@@ -2,7 +2,7 @@ import { AppConfig } from "../makes/AppConfig";
2
2
  import { AppFileSystemService } from "./AppFileSystemService";
3
3
  import { ProcessService } from "./ProcessService";
4
4
  import { LogService } from "./LogService";
5
- import { ProjectRef, PluginRef, PresetRef, PresetSource } from "../types";
5
+ import { ProjectRef, PluginRef, PresetRef } from "../types";
6
6
  type TypeMap = {
7
7
  [type: string]: string;
8
8
  };
@@ -28,8 +28,8 @@ export declare class AppService {
28
28
  removeProject(name: string): void;
29
29
  addPlugin(name: string, env?: PluginRef["env"]): void;
30
30
  removePlugin(name: string): void;
31
- registerPreset(name: string, source: PresetSource, path?: string): void;
32
- unregisterPreset(name: string): void;
31
+ registerPreset(presetRef: PresetRef): void;
32
+ unregisterPreset(path: string): void;
33
33
  getEnv(key: string, byDefault?: string): string | undefined;
34
34
  getEnv(key: string, byDefault: string): string;
35
35
  setEnv(key: string, value: string): void;
@@ -85,12 +85,12 @@ let AppService = class AppService {
85
85
  this.config.removePlugin(name);
86
86
  this.config.save();
87
87
  }
88
- registerPreset(name, source, path) {
89
- this.config.registerPreset(name, source, path);
88
+ registerPreset(presetRef) {
89
+ this.config.registerPreset(presetRef);
90
90
  this.config.save();
91
91
  }
92
- unregisterPreset(name) {
93
- this.config.unregisterPreset(name);
92
+ unregisterPreset(path) {
93
+ this.config.unregisterPreset(path);
94
94
  this.config.save();
95
95
  }
96
96
  getEnv(key, byDefault) {
@@ -119,6 +119,7 @@ let AppService = class AppService {
119
119
  return [
120
120
  "projectComposeType",
121
121
  "buildKit",
122
+ "presetV2",
122
123
  "dns"
123
124
  ];
124
125
  }
@@ -38,10 +38,13 @@ let LogService = class LogService {
38
38
  const logData = data.map((item) => {
39
39
  return typeof item !== "string" ? JSON.stringify(item) : item;
40
40
  }).join(" ");
41
+ const escapedLogData = logData
42
+ .replace(/\\/g, "\\\\")
43
+ .replace(/\r\n|\r|\n/g, "\\n");
41
44
  if (!this.fs.exists(this.logName)) {
42
45
  this.fs.writeFile(this.logName, "");
43
46
  }
44
- this.fs.appendFile(this.logName, `[${time}] ${type}: ${logData}\n`);
47
+ this.fs.appendFile(this.logName, `[${time}] ${type}: ${escapedLogData}\n`);
45
48
  }
46
49
  debug(...data) {
47
50
  this._log(types_1.LogLevel.DEBUG, ...data);
@@ -1,6 +1,7 @@
1
1
  import { PresetSource } from "./PresetSource";
2
2
  export type PresetRef = {
3
3
  name: string;
4
- source: PresetSource;
4
+ /** @deprecated */
5
+ source?: PresetSource;
5
6
  path?: string;
6
7
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@wocker/core",
3
3
  "type": "commonjs",
4
- "version": "1.1.3",
4
+ "version": "1.1.4-beta.1",
5
5
  "author": "Kris Papercut <krispcut@gmail.com>",
6
6
  "description": "Core of the Wocker",
7
7
  "license": "MIT",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/docker-modem": "^3.0.6",
40
- "@types/dockerode": "^3.3.23",
40
+ "@types/dockerode": "^4.0.1",
41
41
  "@types/jest": "^30.0.0",
42
42
  "@types/node": "^24.5.2",
43
43
  "jest": "^30.1.3",