@envodium/envodium-cli 0.1.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 +91 -1
- package/dist/core.js +88 -0
- package/dist/http.js +34 -0
- package/package.json +3 -1
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,11 +72,59 @@ 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;
|
|
36
118
|
}
|
|
37
|
-
|
|
119
|
+
if (cmd === "init") {
|
|
120
|
+
await (0, core_1.init)({ cwd });
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (cmd === "help" || cmd === "--help" || cmd === "-help" || cmd === "-h") {
|
|
124
|
+
showHelp();
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
showHelp();
|
|
38
128
|
}
|
|
39
129
|
catch (err) {
|
|
40
130
|
const e = err;
|
package/dist/core.js
CHANGED
|
@@ -5,6 +5,9 @@ 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;
|
|
10
|
+
exports.init = init;
|
|
8
11
|
exports.sync = sync;
|
|
9
12
|
const path_1 = __importDefault(require("path"));
|
|
10
13
|
const url_1 = require("url");
|
|
@@ -13,6 +16,7 @@ const http_1 = require("./http");
|
|
|
13
16
|
const files_1 = require("./files");
|
|
14
17
|
const util_1 = require("./util");
|
|
15
18
|
const browser_1 = require("./browser");
|
|
19
|
+
const adm_zip_1 = __importDefault(require("adm-zip"));
|
|
16
20
|
async function build(opts) {
|
|
17
21
|
const { cwd, addTestParam, headless, noBrowser } = opts;
|
|
18
22
|
const cfg = await (0, config_1.readProjectConfig)(cwd);
|
|
@@ -131,6 +135,74 @@ async function meta(opts) {
|
|
|
131
135
|
throw new Error(`HTTP ${res.statusCode}`);
|
|
132
136
|
}
|
|
133
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
|
+
}
|
|
134
206
|
function getLangFromFileName(name) {
|
|
135
207
|
const lower = name.toLowerCase();
|
|
136
208
|
if (lower.endsWith(".html") || lower.endsWith(".htm"))
|
|
@@ -166,6 +238,22 @@ function ensureExtension(name, fallbackExt = ".html") {
|
|
|
166
238
|
return name;
|
|
167
239
|
return name + (fallbackExt.startsWith(".") ? fallbackExt : "." + fallbackExt);
|
|
168
240
|
}
|
|
241
|
+
async function init(opts) {
|
|
242
|
+
const { cwd } = opts;
|
|
243
|
+
const zipUrl = `http://support.hr-appen.se/custom/cli/agents.zip?t=${Date.now()}`;
|
|
244
|
+
console.log("Laddar ner agents.zip...");
|
|
245
|
+
const buffer = await (0, http_1.httpDownload)(zipUrl);
|
|
246
|
+
console.log("Packar upp...");
|
|
247
|
+
const zip = new adm_zip_1.default(buffer);
|
|
248
|
+
zip.extractAllTo(cwd, true);
|
|
249
|
+
const entries = zip.getEntries();
|
|
250
|
+
for (const entry of entries) {
|
|
251
|
+
if (!entry.isDirectory) {
|
|
252
|
+
console.log(` ${entry.entryName}`);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
console.log(`\nInit klar – ${entries.filter(e => !e.isDirectory).length} filer extraherade.`);
|
|
256
|
+
}
|
|
169
257
|
async function sync(opts) {
|
|
170
258
|
const { cwd } = opts;
|
|
171
259
|
const cfg = await (0, config_1.readProjectConfig)(cwd);
|
package/dist/http.js
CHANGED
|
@@ -33,11 +33,45 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.httpDownload = httpDownload;
|
|
36
37
|
exports.httpSend = httpSend;
|
|
37
38
|
const http = __importStar(require("http"));
|
|
38
39
|
const https = __importStar(require("https"));
|
|
39
40
|
const dns = __importStar(require("dns"));
|
|
40
41
|
const url_1 = require("url");
|
|
42
|
+
function httpDownload(url) {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
const parsed = new url_1.URL(url);
|
|
45
|
+
const lib = parsed.protocol === "https:" ? https : http;
|
|
46
|
+
const req = lib.get({
|
|
47
|
+
hostname: parsed.hostname,
|
|
48
|
+
port: parsed.port ? Number(parsed.port) : undefined,
|
|
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
|
+
},
|
|
55
|
+
lookup: (hostname, options, callback) => {
|
|
56
|
+
dns.lookup(hostname, { ...options, family: 4 }, callback);
|
|
57
|
+
}
|
|
58
|
+
}, (res) => {
|
|
59
|
+
if (res.statusCode && res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
|
|
60
|
+
httpDownload(res.headers.location).then(resolve, reject);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) {
|
|
64
|
+
reject(new Error(`HTTP ${res.statusCode} vid nedladdning av ${url}`));
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
const chunks = [];
|
|
68
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
69
|
+
res.on("end", () => resolve(Buffer.concat(chunks)));
|
|
70
|
+
});
|
|
71
|
+
req.on("error", reject);
|
|
72
|
+
req.setTimeout(60000, () => req.destroy(new Error("Timeout (60s)")));
|
|
73
|
+
});
|
|
74
|
+
}
|
|
41
75
|
function httpSend(endpoint, method, headers, body) {
|
|
42
76
|
return new Promise((resolve, reject) => {
|
|
43
77
|
const url = new url_1.URL(endpoint);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envodium/envodium-cli",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "CLI for Envodium build, test, sync and meta commands",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"bin": {
|
|
@@ -22,10 +22,12 @@
|
|
|
22
22
|
],
|
|
23
23
|
"license": "MIT",
|
|
24
24
|
"devDependencies": {
|
|
25
|
+
"@types/adm-zip": "^0.5.7",
|
|
25
26
|
"@types/node": "^25.3.0",
|
|
26
27
|
"typescript": "^5.5.4"
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
30
|
+
"adm-zip": "^0.5.16",
|
|
29
31
|
"puppeteer": "^24.37.4"
|
|
30
32
|
}
|
|
31
33
|
}
|