voinznext 0.3.2 → 0.5.0

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.
Files changed (3) hide show
  1. package/cli.js +147 -147
  2. package/install.js +1 -1
  3. package/package.json +42 -42
package/cli.js CHANGED
@@ -1,147 +1,147 @@
1
- #!/usr/bin/env node
2
- module.exports = { downloadLatest };
3
-
4
- const { spawnSync } = require("child_process");
5
- const { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync, renameSync } = require("fs");
6
- const https = require("https");
7
- const { join } = require("path");
8
- const { platform, arch } = require("process");
9
-
10
- const REPO = "VoinzzZ/VoinzNext";
11
- const APP = "voinznext";
12
- const CACHE_TTL = 3600000;
13
-
14
- const PLATFORM_MAP = { win32: "windows", darwin: "darwin", linux: "linux" };
15
- const ARCH_MAP = { x64: "amd64", arm64: "arm64" };
16
-
17
- function getBinaryName() {
18
- const p = PLATFORM_MAP[platform];
19
- const a = ARCH_MAP[arch];
20
- if (!p || !a) return null;
21
- const name = `${APP}-${p}-${a}`;
22
- return platform === "win32" ? `${name}.exe` : name;
23
- }
24
-
25
- function getBinaryPath() {
26
- return join(__dirname, "bin", platform === "win32" ? "voinznext.exe" : "voinznext");
27
- }
28
-
29
- function getVersionPath() {
30
- return join(__dirname, "bin", ".version");
31
- }
32
-
33
- function fetchJson(url) {
34
- return new Promise((resolve, reject) => {
35
- https.get(url, { headers: { "Accept": "application/vnd.github.v3+json", "User-Agent": "voinznext-updater" } }, (res) => {
36
- let data = "";
37
- res.on("data", (chunk) => (data += chunk));
38
- res.on("end", () => {
39
- try { resolve(JSON.parse(data)); }
40
- catch { reject(new Error("Failed to parse response")); }
41
- });
42
- }).on("error", reject);
43
- });
44
- }
45
-
46
- function download(url, dest) {
47
- return new Promise((resolve, reject) => {
48
- https.get(url, { headers: { "User-Agent": "voinznext-updater" } }, (res) => {
49
- if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
50
- download(res.headers.location, dest).then(resolve).catch(reject);
51
- return;
52
- }
53
- if (res.statusCode !== 200) {
54
- reject(new Error(`HTTP ${res.statusCode}`));
55
- return;
56
- }
57
- const file = createWriteStream(dest);
58
- res.pipe(file);
59
- file.on("finish", () => file.close(resolve));
60
- file.on("error", reject);
61
- }).on("error", reject);
62
- });
63
- }
64
-
65
- function readVersionCache() {
66
- try {
67
- const data = readFileSync(getVersionPath(), "utf8");
68
- return JSON.parse(data);
69
- } catch { return null; }
70
- }
71
-
72
- function writeVersionCache(tag) {
73
- try {
74
- mkdirSync(join(__dirname, "bin"), { recursive: true });
75
- writeFileSync(getVersionPath(), JSON.stringify({ tag, checked: Date.now() }));
76
- } catch {}
77
- }
78
-
79
- async function downloadLatest() {
80
- const binaryPath = getBinaryPath();
81
- const binaryName = getBinaryName();
82
- if (!binaryName) return;
83
-
84
- const release = await fetchJson(`https://api.github.com/repos/${REPO}/releases/latest`);
85
- const version = release.tag_name;
86
- const url = `https://github.com/${REPO}/releases/download/${version}/${binaryName}`;
87
- const tmpPath = binaryPath + ".new";
88
-
89
- mkdirSync(join(__dirname, "bin"), { recursive: true });
90
- await download(url, tmpPath);
91
- if (platform !== "win32") chmodSync(tmpPath, 0o755);
92
-
93
- try {
94
- if (platform === "win32") {
95
- renameSync(tmpPath, binaryPath);
96
- } else {
97
- if (existsSync(binaryPath)) unlinkSync(binaryPath);
98
- renameSync(tmpPath, binaryPath);
99
- }
100
- } catch (e) {}
101
- writeVersionCache(version);
102
- }
103
-
104
- async function ensureBinary() {
105
- const binaryPath = getBinaryPath();
106
- const cache = readVersionCache();
107
- const binaryExists = existsSync(binaryPath);
108
-
109
- if (!cache || !binaryExists) {
110
- console.log(" ● Downloading voinznext binary...");
111
- await downloadLatest();
112
- return;
113
- }
114
-
115
- if (Date.now() - cache.checked > CACHE_TTL) {
116
- try {
117
- const release = await fetchJson(`https://api.github.com/repos/${REPO}/releases/latest`);
118
- if (release.tag_name !== cache.tag) {
119
- console.log(" ● Updating voinznext binary...");
120
- await downloadLatest();
121
- return;
122
- }
123
- writeVersionCache(cache.tag);
124
- } catch {}
125
- }
126
- }
127
-
128
- async function main() {
129
- if (!process.env.VOINZNEXT_INSTALL) {
130
- await ensureBinary().catch(() => {});
131
- }
132
-
133
- if (process.env.VOINZNEXT_INSTALL) {
134
- process.exit(0);
135
- }
136
-
137
- const binaryPath = getBinaryPath();
138
- if (!existsSync(binaryPath)) {
139
- console.error(" ✘ Binary not found. Run `npm install -g voinznext@latest --force`.");
140
- process.exit(1);
141
- }
142
-
143
- const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
144
- process.exit(result.status);
145
- }
146
-
147
- if (require.main === module) main();
1
+ #!/usr/bin/env node
2
+ module.exports = { downloadLatest };
3
+
4
+ const { spawnSync } = require("child_process");
5
+ const { createWriteStream, existsSync, mkdirSync, readFileSync, writeFileSync, chmodSync, renameSync } = require("fs");
6
+ const https = require("https");
7
+ const { join } = require("path");
8
+ const { platform, arch } = require("process");
9
+
10
+ const REPO = "VoinzzZ/VoinzNext";
11
+ const APP = "voinznext";
12
+ const CACHE_TTL = 3600000;
13
+
14
+ const PLATFORM_MAP = { win32: "windows", darwin: "darwin", linux: "linux" };
15
+ const ARCH_MAP = { x64: "amd64", arm64: "arm64" };
16
+
17
+ function getBinaryName() {
18
+ const p = PLATFORM_MAP[platform];
19
+ const a = ARCH_MAP[arch];
20
+ if (!p || !a) return null;
21
+ const name = `${APP}-${p}-${a}`;
22
+ return platform === "win32" ? `${name}.exe` : name;
23
+ }
24
+
25
+ function getBinaryPath() {
26
+ return join(__dirname, "bin", platform === "win32" ? "voinznext.exe" : "voinznext");
27
+ }
28
+
29
+ function getVersionPath() {
30
+ return join(__dirname, "bin", ".version");
31
+ }
32
+
33
+ function fetchJson(url) {
34
+ return new Promise((resolve, reject) => {
35
+ https.get(url, { headers: { "Accept": "application/vnd.github.v3+json", "User-Agent": "voinznext-updater" } }, (res) => {
36
+ let data = "";
37
+ res.on("data", (chunk) => (data += chunk));
38
+ res.on("end", () => {
39
+ try { resolve(JSON.parse(data)); }
40
+ catch { reject(new Error("Failed to parse response")); }
41
+ });
42
+ }).on("error", reject);
43
+ });
44
+ }
45
+
46
+ function download(url, dest) {
47
+ return new Promise((resolve, reject) => {
48
+ https.get(url, { headers: { "User-Agent": "voinznext-updater" } }, (res) => {
49
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
50
+ download(res.headers.location, dest).then(resolve).catch(reject);
51
+ return;
52
+ }
53
+ if (res.statusCode !== 200) {
54
+ reject(new Error(`HTTP ${res.statusCode}`));
55
+ return;
56
+ }
57
+ const file = createWriteStream(dest);
58
+ res.pipe(file);
59
+ file.on("finish", () => file.close(resolve));
60
+ file.on("error", reject);
61
+ }).on("error", reject);
62
+ });
63
+ }
64
+
65
+ function readVersionCache() {
66
+ try {
67
+ const data = readFileSync(getVersionPath(), "utf8");
68
+ return JSON.parse(data);
69
+ } catch { return null; }
70
+ }
71
+
72
+ function writeVersionCache(tag) {
73
+ try {
74
+ mkdirSync(join(__dirname, "bin"), { recursive: true });
75
+ writeFileSync(getVersionPath(), JSON.stringify({ tag, checked: Date.now() }));
76
+ } catch {}
77
+ }
78
+
79
+ async function downloadLatest() {
80
+ const binaryPath = getBinaryPath();
81
+ const binaryName = getBinaryName();
82
+ if (!binaryName) return;
83
+
84
+ const release = await fetchJson(`https://api.github.com/repos/${REPO}/releases/latest`);
85
+ const version = release.tag_name;
86
+ const url = `https://github.com/${REPO}/releases/download/${version}/${binaryName}`;
87
+ const tmpPath = binaryPath + ".new";
88
+
89
+ mkdirSync(join(__dirname, "bin"), { recursive: true });
90
+ await download(url, tmpPath);
91
+ if (platform !== "win32") chmodSync(tmpPath, 0o755);
92
+
93
+ try {
94
+ if (platform === "win32") {
95
+ renameSync(tmpPath, binaryPath);
96
+ } else {
97
+ if (existsSync(binaryPath)) unlinkSync(binaryPath);
98
+ renameSync(tmpPath, binaryPath);
99
+ }
100
+ } catch (e) {}
101
+ writeVersionCache(version);
102
+ }
103
+
104
+ async function ensureBinary() {
105
+ const binaryPath = getBinaryPath();
106
+ const cache = readVersionCache();
107
+ const binaryExists = existsSync(binaryPath);
108
+
109
+ if (!cache || !binaryExists) {
110
+ console.log(" ● Downloading voinznext binary...");
111
+ await downloadLatest();
112
+ return;
113
+ }
114
+
115
+ if (Date.now() - cache.checked > CACHE_TTL) {
116
+ try {
117
+ const release = await fetchJson(`https://api.github.com/repos/${REPO}/releases/latest`);
118
+ if (release.tag_name !== cache.tag) {
119
+ console.log(" ● Updating voinznext binary...");
120
+ await downloadLatest();
121
+ return;
122
+ }
123
+ writeVersionCache(cache.tag);
124
+ } catch {}
125
+ }
126
+ }
127
+
128
+ async function main() {
129
+ if (!process.env.VOINZNEXT_INSTALL) {
130
+ await ensureBinary().catch(() => {});
131
+ }
132
+
133
+ if (process.env.VOINZNEXT_INSTALL) {
134
+ process.exit(0);
135
+ }
136
+
137
+ const binaryPath = getBinaryPath();
138
+ if (!existsSync(binaryPath)) {
139
+ console.error(" ✘ Binary not found. Run `npm install -g voinznext@latest --force`.");
140
+ process.exit(1);
141
+ }
142
+
143
+ const result = spawnSync(binaryPath, process.argv.slice(2), { stdio: "inherit" });
144
+ process.exit(result.status);
145
+ }
146
+
147
+ if (require.main === module) main();
package/install.js CHANGED
@@ -1,2 +1,2 @@
1
- process.env.VOINZNEXT_INSTALL = "1";
1
+ process.env.VOINZNEXT_INSTALL = "1";
2
2
  require("./cli.js").downloadLatest().catch(() => {});
package/package.json CHANGED
@@ -1,42 +1,42 @@
1
- {
2
- "name": "voinznext",
3
- "version": "0.3.2",
4
- "description": "Interactive CLI tool for scaffolding Next.js projects with your preferred tech stack",
5
- "keywords": [
6
- "nextjs",
7
- "scaffold",
8
- "cli",
9
- "starter",
10
- "generator"
11
- ],
12
- "homepage": "https://github.com/VoinzzZ/VoinzNext",
13
- "repository": {
14
- "type": "git",
15
- "url": "git+https://github.com/VoinzzZ/VoinzNext.git"
16
- },
17
- "license": "MIT",
18
- "author": "VoinzzZ",
19
- "bin": {
20
- "voinznext": "cli.js"
21
- },
22
- "scripts": {
23
- "postinstall": "node install.js",
24
- "postupdate": "node -e \"require('./cli.js').downloadLatest()\""
25
- },
26
- "files": [
27
- "cli.js",
28
- "install.js"
29
- ],
30
- "engines": {
31
- "node": ">=18"
32
- },
33
- "os": [
34
- "win32",
35
- "darwin",
36
- "linux"
37
- ],
38
- "cpu": [
39
- "x64",
40
- "arm64"
41
- ]
42
- }
1
+ {
2
+ "name": "voinznext",
3
+ "version": "0.5.0",
4
+ "description": "Interactive CLI tool for scaffolding Next.js projects with your preferred tech stack",
5
+ "keywords": [
6
+ "nextjs",
7
+ "scaffold",
8
+ "cli",
9
+ "starter",
10
+ "generator"
11
+ ],
12
+ "homepage": "https://github.com/VoinzzZ/VoinzNext",
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "git+https://github.com/VoinzzZ/VoinzNext.git"
16
+ },
17
+ "license": "MIT",
18
+ "author": "VoinzzZ",
19
+ "bin": {
20
+ "voinznext": "cli.js"
21
+ },
22
+ "scripts": {
23
+ "postinstall": "node install.js",
24
+ "postupdate": "node -e \"require('./cli.js').downloadLatest()\""
25
+ },
26
+ "files": [
27
+ "cli.js",
28
+ "install.js"
29
+ ],
30
+ "engines": {
31
+ "node": ">=18"
32
+ },
33
+ "os": [
34
+ "win32",
35
+ "darwin",
36
+ "linux"
37
+ ],
38
+ "cpu": [
39
+ "x64",
40
+ "arm64"
41
+ ]
42
+ }