@kntic/kntic 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/package.json +1 -1
- package/src/commands/init.js +63 -1
- package/src/commands/start.js +1 -1
- package/src/commands/usage.js +1 -1
package/package.json
CHANGED
package/src/commands/init.js
CHANGED
|
@@ -7,9 +7,64 @@ const fs = require("fs");
|
|
|
7
7
|
const path = require("path");
|
|
8
8
|
const os = require("os");
|
|
9
9
|
|
|
10
|
+
const BOOTSTRAP_ARTIFACT_URL =
|
|
11
|
+
"https://minio.kommune7.wien/public/kntic-bootstrap-latest.artifact";
|
|
10
12
|
const BOOTSTRAP_URL =
|
|
11
13
|
"https://minio.kommune7.wien/public/kntic-bootstrap-latest.tar.gz";
|
|
12
14
|
|
|
15
|
+
/**
|
|
16
|
+
* Fetch a small text resource from a URL (follows redirects).
|
|
17
|
+
* Returns the response body as a trimmed string.
|
|
18
|
+
*/
|
|
19
|
+
function fetchText(url, maxRedirects = 5) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
if (maxRedirects <= 0) {
|
|
22
|
+
return reject(new Error("Too many redirects"));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const client = url.startsWith("https") ? https : http;
|
|
26
|
+
|
|
27
|
+
client
|
|
28
|
+
.get(url, (res) => {
|
|
29
|
+
if ([301, 302, 303, 307, 308].includes(res.statusCode)) {
|
|
30
|
+
const location = res.headers.location;
|
|
31
|
+
if (!location) {
|
|
32
|
+
return reject(new Error("Redirect with no Location header"));
|
|
33
|
+
}
|
|
34
|
+
res.resume();
|
|
35
|
+
return resolve(fetchText(location, maxRedirects - 1));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (res.statusCode !== 200) {
|
|
39
|
+
res.resume();
|
|
40
|
+
return reject(
|
|
41
|
+
new Error(`Fetch failed — HTTP ${res.statusCode}`)
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const chunks = [];
|
|
46
|
+
res.on("data", (chunk) => chunks.push(chunk));
|
|
47
|
+
res.on("end", () => resolve(Buffer.concat(chunks).toString("utf8").trim()));
|
|
48
|
+
res.on("error", reject);
|
|
49
|
+
})
|
|
50
|
+
.on("error", reject);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Extract semantic version from an artifact filename.
|
|
56
|
+
* E.g. "kntic-bootstrap-v0.0.10.tar.gz" → "0.0.10"
|
|
57
|
+
*/
|
|
58
|
+
function extractVersion(artifactFilename) {
|
|
59
|
+
const match = artifactFilename.match(/v(\d+\.\d+\.\d+)/);
|
|
60
|
+
if (!match) {
|
|
61
|
+
throw new Error(
|
|
62
|
+
`Unable to extract version from artifact filename: ${artifactFilename}`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
return match[1];
|
|
66
|
+
}
|
|
67
|
+
|
|
13
68
|
/**
|
|
14
69
|
* Follow redirects and download a URL to a local file path.
|
|
15
70
|
* Uses only Node built-ins (no external dependencies).
|
|
@@ -57,14 +112,21 @@ function download(url, dest, maxRedirects = 5) {
|
|
|
57
112
|
}
|
|
58
113
|
|
|
59
114
|
async function init() {
|
|
115
|
+
// Resolve current version from the artifact metadata file
|
|
116
|
+
const artifactFilename = await fetchText(BOOTSTRAP_ARTIFACT_URL);
|
|
117
|
+
const version = extractVersion(artifactFilename);
|
|
118
|
+
|
|
60
119
|
const tmpFile = path.join(os.tmpdir(), `kntic-bootstrap-${Date.now()}.tar.gz`);
|
|
61
120
|
|
|
62
|
-
console.log(
|
|
121
|
+
console.log(`Downloading KNTIC bootstrap archive… (v${version})`);
|
|
63
122
|
await download(BOOTSTRAP_URL, tmpFile);
|
|
64
123
|
|
|
65
124
|
console.log("Extracting into current directory…");
|
|
66
125
|
execSync(`tar xzf "${tmpFile}" -C .`, { stdio: "inherit" });
|
|
67
126
|
|
|
127
|
+
// Append version to .kntic.env (project root) — do not replace existing content
|
|
128
|
+
fs.appendFileSync(".kntic.env", `KNTIC_VERSION=${version}\n`);
|
|
129
|
+
|
|
68
130
|
// Clean up
|
|
69
131
|
fs.unlinkSync(tmpFile);
|
|
70
132
|
|
package/src/commands/start.js
CHANGED
|
@@ -4,7 +4,7 @@ const { execSync } = require("child_process");
|
|
|
4
4
|
|
|
5
5
|
function start() {
|
|
6
6
|
console.log("Starting KNTIC services…");
|
|
7
|
-
execSync("docker compose -f kntic.yml up", { stdio: "inherit" });
|
|
7
|
+
execSync("docker compose -f kntic.yml --env-file .kntic.env up --build", { stdio: "inherit" });
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
module.exports = start;
|
package/src/commands/usage.js
CHANGED
|
@@ -6,7 +6,7 @@ function usage() {
|
|
|
6
6
|
console.log("Available commands:\n");
|
|
7
7
|
console.log(" usage List all available sub-commands");
|
|
8
8
|
console.log(" init Download and extract the KNTIC bootstrap template into the current directory");
|
|
9
|
-
console.log(" start
|
|
9
|
+
console.log(" start Build and start KNTIC services via docker compose (uses kntic.yml + .kntic.env)");
|
|
10
10
|
console.log("");
|
|
11
11
|
}
|
|
12
12
|
|