@involvex/fresh-editor 0.1.76

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.
@@ -0,0 +1,86 @@
1
+ const https = require('https');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const { execSync } = require('child_process');
5
+ const { getBinaryInfo } = require('./binary');
6
+
7
+ const VERSION = require('./package.json').version;
8
+ const REPO = 'sinelaw/fresh';
9
+
10
+ function download(url, dest) {
11
+ return new Promise((resolve, reject) => {
12
+ const file = fs.createWriteStream(dest);
13
+ file.on('error', (err) => {
14
+ file.close();
15
+ reject(err);
16
+ });
17
+ https.get(url, (response) => {
18
+ if (response.statusCode === 302 || response.statusCode === 301) {
19
+ file.close(() => {
20
+ download(response.headers.location, dest).then(resolve).catch(reject);
21
+ });
22
+ return;
23
+ }
24
+ if (response.statusCode !== 200) {
25
+ file.close();
26
+ reject(new Error(`Failed to download: ${response.statusCode}`));
27
+ return;
28
+ }
29
+ response.pipe(file);
30
+ file.on('finish', () => { file.close(); resolve(); });
31
+ }).on('error', (err) => {
32
+ file.close();
33
+ reject(err);
34
+ });
35
+ });
36
+ }
37
+
38
+ async function install() {
39
+ const info = getBinaryInfo();
40
+ const archiveName = `fresh-editor-${info.target}.${info.ext}`;
41
+ const url = `https://github.com/${REPO}/releases/download/v${VERSION}/${archiveName}`;
42
+ const archivePath = path.join(__dirname, archiveName);
43
+ const binDir = path.join(__dirname, 'bin');
44
+ const binaryPath = path.join(binDir, info.binaryName);
45
+
46
+ console.log(`Downloading ${url}...`);
47
+ await download(url, archivePath);
48
+
49
+ // Verify download succeeded
50
+ const stats = fs.statSync(archivePath);
51
+ if (stats.size === 0) {
52
+ throw new Error(`Downloaded file is empty: ${archivePath}`);
53
+ }
54
+ console.log(`Downloaded ${stats.size} bytes`);
55
+
56
+ fs.mkdirSync(binDir, { recursive: true });
57
+
58
+ if (info.ext === 'tar.xz') {
59
+ execSync(`tar -xJf "${archivePath}" -C "${binDir}" --strip-components=1`, { stdio: 'inherit' });
60
+ } else if (info.ext === 'zip') {
61
+ if (process.platform === 'win32') {
62
+ execSync(`powershell -Command "Expand-Archive -Path '${archivePath}' -DestinationPath '${binDir}' -Force"`, { stdio: 'inherit' });
63
+ // Move files from nested directory
64
+ const nested = path.join(binDir, `fresh-editor-${info.target}`);
65
+ if (fs.existsSync(nested)) {
66
+ fs.readdirSync(nested).forEach(f => {
67
+ fs.renameSync(path.join(nested, f), path.join(binDir, f));
68
+ });
69
+ fs.rmdirSync(nested);
70
+ }
71
+ } else {
72
+ execSync(`unzip -o "${archivePath}" -d "${binDir}"`, { stdio: 'inherit' });
73
+ }
74
+ }
75
+
76
+ fs.unlinkSync(archivePath);
77
+
78
+ // Verify binary exists
79
+ if (!fs.existsSync(binaryPath)) {
80
+ throw new Error(`Installation failed: binary not found at ${binaryPath}`);
81
+ }
82
+
83
+ console.log('fresh-editor installed successfully!');
84
+ }
85
+
86
+ module.exports = { install };
package/binary.js ADDED
@@ -0,0 +1,28 @@
1
+ const os = require('os');
2
+
3
+ function getBinaryInfo() {
4
+ const platform = os.platform();
5
+ const arch = os.arch();
6
+
7
+ const targets = {
8
+ 'darwin-x64': { target: 'x86_64-apple-darwin', ext: 'tar.xz' },
9
+ 'darwin-arm64': { target: 'aarch64-apple-darwin', ext: 'tar.xz' },
10
+ 'linux-x64': { target: 'x86_64-unknown-linux-gnu', ext: 'tar.xz' },
11
+ 'linux-arm64': { target: 'aarch64-unknown-linux-gnu', ext: 'tar.xz' },
12
+ 'win32-x64': { target: 'x86_64-pc-windows-msvc', ext: 'zip' }
13
+ };
14
+
15
+ const key = `${platform}-${arch}`;
16
+ const info = targets[key];
17
+
18
+ if (!info) {
19
+ throw new Error(`Unsupported platform: ${platform}-${arch}`);
20
+ }
21
+
22
+ return {
23
+ ...info,
24
+ binaryName: platform === 'win32' ? 'fresh.exe' : 'fresh'
25
+ };
26
+ }
27
+
28
+ module.exports = { getBinaryInfo };
package/install.js ADDED
@@ -0,0 +1,2 @@
1
+ const { install } = require('./binary-install');
2
+ install().catch(err => { console.error(err); process.exit(1); });
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@involvex/fresh-editor",
3
+ "version": "0.1.76",
4
+ "description": "A modern terminal-based text editor with plugin support",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/involvex/fresh.git"
8
+ },
9
+ "license": "Apache-2.0",
10
+ "bin": {
11
+ "fresh": "run-fresh.js"
12
+ },
13
+ "scripts": {
14
+ "postinstall": "node install.js",
15
+ "start": "node run-fresh.js",
16
+ "dev": "node run-fresh.js -- --dev"
17
+ },
18
+ "files": [
19
+ "binary.js",
20
+ "binary-install.js",
21
+ "install.js",
22
+ "run-fresh.js",
23
+ "plugins/**/*",
24
+ "themes/**/*",
25
+ "README.md",
26
+ "LICENSE",
27
+ "CHANGELOG.md"
28
+ ],
29
+ "os": ["darwin", "linux", "win32"],
30
+ "cpu": ["x64", "arm64"],
31
+ "keywords": ["editor", "terminal", "cli", "text-editor", "vim"],
32
+ "engines": {
33
+ "node": ">=18"
34
+ }
35
+ }
package/run-fresh.js ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const path = require('path');
4
+ const { getBinaryInfo } = require('./binary');
5
+
6
+ const info = getBinaryInfo();
7
+ const binPath = path.join(__dirname, 'bin', info.binaryName);
8
+
9
+ const child = spawn(binPath, process.argv.slice(2), { stdio: 'inherit' });
10
+ child.on('exit', (code) => process.exit(code || 0));