@envodium/envodium-cli 0.2.0 → 0.2.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/dist/cli.js CHANGED
@@ -2,6 +2,48 @@
2
2
  "use strict";
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  const core_1 = require("./core");
5
+ async function readAllStdin() {
6
+ return new Promise((resolve, reject) => {
7
+ let data = "";
8
+ process.stdin.setEncoding("utf8");
9
+ process.stdin.on("data", (chunk) => {
10
+ data += chunk;
11
+ });
12
+ process.stdin.on("end", () => resolve(data));
13
+ process.stdin.on("error", reject);
14
+ });
15
+ }
16
+ function showHelp() {
17
+ const pkg = require("../package.json");
18
+ console.log(`
19
+ \x1b[36m ███████╗███╗ ██╗██╗ ██╗ ██████╗ ██████╗ ██╗██╗ ██╗███╗ ███╗
20
+ ██╔════╝████╗ ██║██║ ██║██╔═══██╗██╔══██╗██║██║ ██║████╗ ████║
21
+ █████╗ ██╔██╗ ██║██║ ██║██║ ██║██║ ██║██║██║ ██║██╔████╔██║
22
+ ██╔══╝ ██║╚██╗██║╚██╗ ██╔╝██║ ██║██║ ██║██║██║ ██║██║╚██╔╝██║
23
+ ███████╗██║ ╚████║ ╚████╔╝ ╚██████╔╝██████╔╝██║╚██████╔╝██║ ╚═╝ ██║
24
+ ╚══════╝╚═╝ ╚═══╝ ╚═══╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝\x1b[0m
25
+ `);
26
+ console.log(` \x1b[1mEnvodium CLI\x1b[0m v${pkg.version}\n`);
27
+ console.log(" \x1b[33mKommandon:\x1b[0m\n");
28
+ console.log(" \x1b[1mbuild\x1b[0m Bygg och publicera projektfiler till servern");
29
+ console.log(" \x1b[1mtest\x1b[0m Bygg och öppna webbläsaren för att testa");
30
+ console.log(" envodium test --no – returnera bara test-URL");
31
+ console.log(" envodium test -headless – kör i bakgrunden utan fönster");
32
+ console.log(" \x1b[1msync\x1b[0m Synka ner filer från servern till lokalt projekt");
33
+ console.log(" \x1b[1minit\x1b[0m Ladda ner och packa upp startfiler (agents.zip)");
34
+ console.log(" \x1b[1mmeta\x1b[0m <input> Hämta databasinfo från servern");
35
+ console.log(" envodium meta lookup – lista alla databaser");
36
+ console.log(" envodium meta <dbnamn> – hämta specifik databas");
37
+ console.log(" \x1b[1mread\x1b[0m <query> | --stdin Läs data från servern med /read <query> (kräver systemadmin)");
38
+ console.log(" \x1b[1mupdate\x1b[0m <query> | --stdin Uppdatera data på servern med /update <query> (kräver systemadmin)");
39
+ console.log(" \x1b[1mhelp\x1b[0m Visa denna hjälptext");
40
+ console.log(" \x1b[1m-v\x1b[0m Visa versionsnummer");
41
+ console.log();
42
+ console.log(" \x1b[33mTips (PowerShell):\x1b[0m");
43
+ console.log(" Använd --% för $-tecken: envodium read --% where $db='fordon'");
44
+ console.log(" Eller pipe via stdin: echo \"where $db='fordon'\" | envodium read --stdin");
45
+ console.log();
46
+ }
5
47
  async function main() {
6
48
  const cmd = (process.argv[2] || "").toLowerCase();
7
49
  const cwd = process.cwd();
@@ -30,6 +72,46 @@ async function main() {
30
72
  await (0, core_1.meta)({ cwd, input });
31
73
  return;
32
74
  }
75
+ if (cmd === "read") {
76
+ const stdinMode = process.argv.includes("--stdin") || process.argv.includes("-stdin");
77
+ let input = "";
78
+ if (stdinMode) {
79
+ input = (await readAllStdin()).trim();
80
+ }
81
+ else {
82
+ input = process.argv
83
+ .slice(3)
84
+ .filter((arg) => arg !== "--%")
85
+ .join(" ")
86
+ .trim();
87
+ }
88
+ if (!input) {
89
+ console.log("Usage: envodium read <query_input> | envodium read --stdin");
90
+ return;
91
+ }
92
+ await (0, core_1.read)({ cwd, input });
93
+ return;
94
+ }
95
+ if (cmd === "update") {
96
+ const stdinMode = process.argv.includes("--stdin") || process.argv.includes("-stdin");
97
+ let input = "";
98
+ if (stdinMode) {
99
+ input = (await readAllStdin()).trim();
100
+ }
101
+ else {
102
+ input = process.argv
103
+ .slice(3)
104
+ .filter((arg) => arg !== "--%")
105
+ .join(" ")
106
+ .trim();
107
+ }
108
+ if (!input) {
109
+ console.log("Usage: envodium update <query_input> | envodium update --stdin");
110
+ return;
111
+ }
112
+ await (0, core_1.update)({ cwd, input });
113
+ return;
114
+ }
33
115
  if (cmd === "sync") {
34
116
  await (0, core_1.sync)({ cwd });
35
117
  return;
@@ -38,7 +120,11 @@ async function main() {
38
120
  await (0, core_1.init)({ cwd });
39
121
  return;
40
122
  }
41
- console.log("Usage: envodium build | test | sync | meta <input> | init");
123
+ if (cmd === "help" || cmd === "--help" || cmd === "-help" || cmd === "-h") {
124
+ showHelp();
125
+ return;
126
+ }
127
+ showHelp();
42
128
  }
43
129
  catch (err) {
44
130
  const e = err;
package/dist/core.js CHANGED
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.build = build;
7
7
  exports.meta = meta;
8
+ exports.read = read;
9
+ exports.update = update;
8
10
  exports.init = init;
9
11
  exports.sync = sync;
10
12
  const path_1 = __importDefault(require("path"));
@@ -133,6 +135,74 @@ async function meta(opts) {
133
135
  throw new Error(`HTTP ${res.statusCode}`);
134
136
  }
135
137
  }
138
+ function buildCliReadUrl(endpoint) {
139
+ try {
140
+ const u = new url_1.URL(endpoint);
141
+ const guid = u.searchParams.get("guid");
142
+ if (!guid)
143
+ return null;
144
+ u.pathname = "/admin/cli/cli.aspx";
145
+ const params = new URLSearchParams();
146
+ params.set("guid", guid);
147
+ u.search = `?${params.toString()}`;
148
+ return u.toString();
149
+ }
150
+ catch {
151
+ return null;
152
+ }
153
+ }
154
+ async function read(opts) {
155
+ const { cwd, input } = opts;
156
+ const cfg = await (0, config_1.readProjectConfig)(cwd);
157
+ if (!cfg.endpoint)
158
+ throw new Error("Ingen endpoint hittad (vscode.js saknas eller saknar endpoint).");
159
+ const endpoint = buildCliReadUrl(cfg.endpoint);
160
+ if (!endpoint)
161
+ throw new Error("Kunde inte bygga read-endpoint från endpoint i vscode.js.");
162
+ const body = JSON.stringify({ query: `/read ${input}` });
163
+ const headers = {
164
+ "Content-Type": "application/json",
165
+ "Content-Length": String(Buffer.byteLength(body, "utf8"))
166
+ };
167
+ if (cfg.bearer)
168
+ headers["Authorization"] = `Bearer ${cfg.bearer}`;
169
+ const res = await (0, http_1.httpSend)(endpoint, "POST", headers, body);
170
+ console.log("Status:", res.statusCode);
171
+ if (res.statusCode !== 500 && res.body)
172
+ console.log(res.body);
173
+ if (res.statusCode < 200 || res.statusCode >= 300) {
174
+ if (res.statusCode === 500) {
175
+ throw new Error("Tips (PowerShell): använd --% för att bevara $-tecken, t.ex. envodium read --% where $db='' eller använd stdin: echo \"where $db=''\" | envodium read --stdin");
176
+ }
177
+ throw new Error(`HTTP ${res.statusCode}`);
178
+ }
179
+ }
180
+ async function update(opts) {
181
+ const { cwd, input } = opts;
182
+ const cfg = await (0, config_1.readProjectConfig)(cwd);
183
+ if (!cfg.endpoint)
184
+ throw new Error("Ingen endpoint hittad (vscode.js saknas eller saknar endpoint).");
185
+ const endpoint = buildCliReadUrl(cfg.endpoint);
186
+ if (!endpoint)
187
+ throw new Error("Kunde inte bygga update-endpoint från endpoint i vscode.js.");
188
+ const body = JSON.stringify({ query: `/update ${input}` });
189
+ const headers = {
190
+ "Content-Type": "application/json",
191
+ "Content-Length": String(Buffer.byteLength(body, "utf8"))
192
+ };
193
+ if (cfg.bearer)
194
+ headers["Authorization"] = `Bearer ${cfg.bearer}`;
195
+ const res = await (0, http_1.httpSend)(endpoint, "POST", headers, body);
196
+ console.log("Status:", res.statusCode);
197
+ if (res.statusCode !== 500 && res.body)
198
+ console.log(res.body);
199
+ if (res.statusCode < 200 || res.statusCode >= 300) {
200
+ if (res.statusCode === 500) {
201
+ throw new Error("Tips (PowerShell): använd --% för att bevara $-tecken, t.ex. envodium update --% where $db='' eller använd stdin: echo \"where $db=''\" | envodium update --stdin");
202
+ }
203
+ throw new Error(`HTTP ${res.statusCode}`);
204
+ }
205
+ }
136
206
  function getLangFromFileName(name) {
137
207
  const lower = name.toLowerCase();
138
208
  if (lower.endsWith(".html") || lower.endsWith(".htm"))
@@ -170,7 +240,7 @@ function ensureExtension(name, fallbackExt = ".html") {
170
240
  }
171
241
  async function init(opts) {
172
242
  const { cwd } = opts;
173
- const zipUrl = "http://support.hr-appen.se/custom/cli/agents.zip";
243
+ const zipUrl = `http://support.hr-appen.se/custom/cli/agents.zip?t=${Date.now()}`;
174
244
  console.log("Laddar ner agents.zip...");
175
245
  const buffer = await (0, http_1.httpDownload)(zipUrl);
176
246
  console.log("Packar upp...");
package/dist/http.js CHANGED
@@ -47,6 +47,11 @@ function httpDownload(url) {
47
47
  hostname: parsed.hostname,
48
48
  port: parsed.port ? Number(parsed.port) : undefined,
49
49
  path: parsed.pathname + parsed.search,
50
+ headers: {
51
+ "Cache-Control": "no-cache, no-store, must-revalidate",
52
+ "Pragma": "no-cache",
53
+ "If-None-Match": ""
54
+ },
50
55
  lookup: (hostname, options, callback) => {
51
56
  dns.lookup(hostname, { ...options, family: 4 }, callback);
52
57
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@envodium/envodium-cli",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "CLI for Envodium build, test, sync and meta commands",
5
5
  "type": "commonjs",
6
6
  "bin": {