@webbies.dev/dotenvify 0.3.4 → 0.3.7

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/README.md CHANGED
@@ -37,6 +37,26 @@ cd dotenvify && go build
37
37
  ```
38
38
  </details>
39
39
 
40
+ ## 🔄 Updating
41
+
42
+ Keep dotenvify up to date with the latest features and fixes:
43
+
44
+ ### Self-Update (Recommended)
45
+ ```bash
46
+ # Check for available updates
47
+ dotenvify -check-update
48
+
49
+ # Update to the latest version
50
+ dotenvify -update
51
+ ```
52
+
53
+ ### Via npm
54
+ ```bash
55
+ npm update -g @webbies.dev/dotenvify
56
+ ```
57
+
58
+ The self-update feature automatically downloads and installs the latest release from GitHub, making it easy to stay current regardless of how you installed dotenvify.
59
+
40
60
  ## 🔮 Usage
41
61
 
42
62
  ### Basic File Mode
@@ -98,6 +118,7 @@ Just make sure you're logged in with `az login` before running the tool.
98
118
  - 🔤 **Flexible**: Multiple output options
99
119
  - 💾 **Safe**: Auto-backup with incremental counters
100
120
  - 📦 **Easy Install**: npm
121
+ - 🔄 **Self-Updating**: Built-in update mechanism
101
122
 
102
123
  ## 📝 Supported Formats
103
124
 
package/bin/dotenvify ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { spawn } = require('child_process');
4
+ const path = require('path');
5
+ const fs = require('fs');
6
+
7
+ const isWindows = process.platform === 'win32';
8
+ const binaryName = isWindows ? 'dotenvify.exe' : 'dotenvify';
9
+ const binaryPath = path.join(__dirname, binaryName);
10
+
11
+ if (!fs.existsSync(binaryPath)) {
12
+ console.error('dotenvify binary not found. Try reinstalling:');
13
+ console.error(' npm uninstall -g @webbies.dev/dotenvify');
14
+ console.error(' npm install -g @webbies.dev/dotenvify');
15
+ process.exit(1);
16
+ }
17
+
18
+ const child = spawn(binaryPath, process.argv.slice(2), {
19
+ stdio: 'inherit',
20
+ windowsHide: true,
21
+ });
22
+
23
+ child.on('error', (err) => {
24
+ console.error('Failed to execute dotenvify:', err.message);
25
+ process.exit(1);
26
+ });
27
+
28
+ child.on('close', (code) => {
29
+ process.exit(code || 0);
30
+ });
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@webbies.dev/dotenvify",
3
- "version": "0.3.4",
3
+ "version": "0.3.7",
4
4
  "description": "A utility to convert environment variables from various sources into different formats",
5
5
  "bin": {
6
- "dotenvify": "./dotenvify"
6
+ "dotenvify": "./bin/dotenvify"
7
7
  },
8
8
  "scripts": {
9
- "test": "./dotenvify --help"
9
+ "postinstall": "node scripts/install.js",
10
+ "test": "node bin/dotenvify --help"
10
11
  },
11
12
  "keywords": [
12
13
  "dotenv",
@@ -23,9 +24,19 @@
23
24
  "url": "https://github.com/webb1es/dotenvify.git"
24
25
  },
25
26
  "files": [
26
- "dotenvify"
27
+ "bin/dotenvify",
28
+ "scripts/install.js"
29
+ ],
30
+ "os": [
31
+ "darwin",
32
+ "linux",
33
+ "win32"
34
+ ],
35
+ "cpu": [
36
+ "x64",
37
+ "arm64"
27
38
  ],
28
39
  "engines": {
29
- "node": ">=12"
40
+ "node": ">=14"
30
41
  }
31
42
  }
@@ -0,0 +1,154 @@
1
+ #!/usr/bin/env node
2
+
3
+ const { execSync } = require('child_process');
4
+ const fs = require('fs');
5
+ const path = require('path');
6
+ const https = require('https');
7
+ const { createWriteStream, mkdirSync, chmodSync, existsSync } = fs;
8
+
9
+ const REPO = 'webb1es/dotenvify';
10
+ const BINARY_NAME = 'dotenvify';
11
+
12
+ function getPlatformInfo() {
13
+ const platform = process.platform;
14
+ const arch = process.arch;
15
+
16
+ const platformMap = {
17
+ darwin: 'darwin',
18
+ linux: 'linux',
19
+ win32: 'windows',
20
+ };
21
+
22
+ const archMap = {
23
+ x64: 'amd64',
24
+ arm64: 'arm64',
25
+ };
26
+
27
+ const os = platformMap[platform];
28
+ const goArch = archMap[arch];
29
+
30
+ if (!os || !goArch) {
31
+ console.error(`Unsupported platform: ${platform} ${arch}`);
32
+ process.exit(1);
33
+ }
34
+
35
+ // Windows arm64 not supported
36
+ if (os === 'windows' && goArch === 'arm64') {
37
+ console.error('Windows arm64 is not supported');
38
+ process.exit(1);
39
+ }
40
+
41
+ return { os, arch: goArch, isWindows: platform === 'win32' };
42
+ }
43
+
44
+ function getPackageVersion() {
45
+ const packageJson = require('../package.json');
46
+ return packageJson.version;
47
+ }
48
+
49
+ function downloadFile(url, dest) {
50
+ return new Promise((resolve, reject) => {
51
+ const follow = (url) => {
52
+ https.get(url, (response) => {
53
+ if (response.statusCode === 302 || response.statusCode === 301) {
54
+ follow(response.headers.location);
55
+ return;
56
+ }
57
+
58
+ if (response.statusCode !== 200) {
59
+ reject(new Error(`Download failed: ${response.statusCode}`));
60
+ return;
61
+ }
62
+
63
+ const file = createWriteStream(dest);
64
+ response.pipe(file);
65
+ file.on('finish', () => {
66
+ file.close();
67
+ resolve();
68
+ });
69
+ file.on('error', (err) => {
70
+ fs.unlinkSync(dest);
71
+ reject(err);
72
+ });
73
+ }).on('error', reject);
74
+ };
75
+ follow(url);
76
+ });
77
+ }
78
+
79
+ async function extractTarGz(archive, dest) {
80
+ execSync(`tar -xzf "${archive}" -C "${dest}"`, { stdio: 'inherit' });
81
+ }
82
+
83
+ async function extractZip(archive, dest) {
84
+ if (process.platform === 'win32') {
85
+ execSync(`powershell -command "Expand-Archive -Path '${archive}' -DestinationPath '${dest}'"`, { stdio: 'inherit' });
86
+ } else {
87
+ execSync(`unzip -o "${archive}" -d "${dest}"`, { stdio: 'inherit' });
88
+ }
89
+ }
90
+
91
+ async function install() {
92
+ const { os, arch, isWindows } = getPlatformInfo();
93
+ const version = getPackageVersion();
94
+ const ext = isWindows ? 'zip' : 'tar.gz';
95
+ const binaryExt = isWindows ? '.exe' : '';
96
+
97
+ const archiveName = `${BINARY_NAME}_${version}_${os}_${arch}.${ext}`;
98
+ const downloadUrl = `https://github.com/${REPO}/releases/download/v${version}/${archiveName}`;
99
+
100
+ const binDir = path.join(__dirname, '..', 'bin');
101
+ const tmpDir = path.join(__dirname, '..', '.tmp');
102
+ const archivePath = path.join(tmpDir, archiveName);
103
+ const binaryDest = path.join(binDir, `${BINARY_NAME}${binaryExt}`);
104
+
105
+ // Create directories
106
+ if (!existsSync(binDir)) mkdirSync(binDir, { recursive: true });
107
+ if (!existsSync(tmpDir)) mkdirSync(tmpDir, { recursive: true });
108
+
109
+ console.log(`Downloading ${BINARY_NAME} v${version} for ${os}/${arch}...`);
110
+ console.log(`URL: ${downloadUrl}`);
111
+
112
+ try {
113
+ await downloadFile(downloadUrl, archivePath);
114
+ } catch (err) {
115
+ console.error(`Failed to download binary: ${err.message}`);
116
+ console.error('');
117
+ console.error('This may happen if:');
118
+ console.error(` - Version v${version} has not been released on GitHub yet`);
119
+ console.error(' - Your platform is not supported');
120
+ console.error('');
121
+ console.error('You can manually download from:');
122
+ console.error(` https://github.com/${REPO}/releases`);
123
+ process.exit(1);
124
+ }
125
+
126
+ console.log('Extracting...');
127
+ if (isWindows) {
128
+ await extractZip(archivePath, tmpDir);
129
+ } else {
130
+ await extractTarGz(archivePath, tmpDir);
131
+ }
132
+
133
+ // Find and move the binary
134
+ const extractedBinary = path.join(tmpDir, `${BINARY_NAME}${binaryExt}`);
135
+ if (existsSync(extractedBinary)) {
136
+ fs.renameSync(extractedBinary, binaryDest);
137
+ if (!isWindows) {
138
+ chmodSync(binaryDest, 0o755);
139
+ }
140
+ } else {
141
+ console.error('Binary not found in archive');
142
+ process.exit(1);
143
+ }
144
+
145
+ // Cleanup
146
+ fs.rmSync(tmpDir, { recursive: true, force: true });
147
+
148
+ console.log(`Successfully installed ${BINARY_NAME} to ${binaryDest}`);
149
+ }
150
+
151
+ install().catch((err) => {
152
+ console.error('Installation failed:', err);
153
+ process.exit(1);
154
+ });