@simplelocalize/cli 1.0.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 (2) hide show
  1. package/index.js +97 -0
  2. package/package.json +17 -0
package/index.js ADDED
@@ -0,0 +1,97 @@
1
+ #!/usr/bin/env node
2
+ const { execSync } = require("child_process");
3
+ const path = require("path");
4
+ const fs = require('fs');
5
+ const axios = require('axios');
6
+ const os = require('os');
7
+
8
+ const binaryPath = path.join(__dirname, 'bin', 'simplelocalize');
9
+
10
+ const isBinaryInstalled = () => {
11
+ try {
12
+ execSync(binaryPath + ' --version', { stdio: 'ignore' });
13
+ return true;
14
+ }
15
+ catch (error) {
16
+ return false;
17
+ }
18
+ }
19
+
20
+ const printBinaryVersion = () => {
21
+ try {
22
+ console.log(execSync(binaryPath + ' --version').toString());
23
+ }
24
+ catch (error) {
25
+ console.error('Error running SimpleLocalize CLI');
26
+ process.exit(1);
27
+ }
28
+ }
29
+
30
+ const buildDownloadBinaryUrl = (version) => {
31
+ let platform = "";
32
+ if (os.platform() === "win32") {
33
+ platform = "windows.exe"
34
+ }
35
+
36
+ if (os.platform() === "darwin") {
37
+ platform = "mac"
38
+ }
39
+
40
+ if (os.platform() === "linux") {
41
+ platform = "linux"
42
+ }
43
+
44
+ let arch = "";
45
+ if (os.arch() === "arm64") {
46
+ arch = "-arm64"
47
+ }
48
+ return `https://github.com/simplelocalize/simplelocalize-cli/releases/download/${version}/simplelocalize-cli-${platform}${arch}`
49
+ }
50
+
51
+ async function installBinary(version = "2.8.0") {
52
+ const downloadUrl = buildDownloadBinaryUrl(version);
53
+ if (!fs.existsSync(path.join(__dirname, 'bin'))) {
54
+ fs.mkdirSync(path.join(__dirname, 'bin'));
55
+ }
56
+ console.log(`Downloading ${downloadUrl}...`);
57
+ const response = await axios({
58
+ url: downloadUrl,
59
+ method: 'GET',
60
+ responseType: 'stream'
61
+ });
62
+
63
+ const writer = fs.createWriteStream(binaryPath);
64
+ response.data.pipe(writer);
65
+ await new Promise((resolve, reject) => {
66
+ writer.on('finish', resolve);
67
+ writer.on('error', reject);
68
+ });
69
+
70
+ console.log('SimpleLocalize CLI downloaded successfully!');
71
+
72
+ // Make it executable (only on Unix-based systems)
73
+ if (os.platform() !== 'win32') {
74
+ fs.chmodSync(binaryPath, 0o755);
75
+ }
76
+
77
+ console.log('Binary is now executable.');
78
+ }
79
+
80
+ const init = async () => {
81
+ console.log("Checking if SimpleLocalize CLI is installed...");
82
+ if (!isBinaryInstalled()) {
83
+ console.log("SimpleLocalize CLI not installed. Installing...");
84
+ await installBinary();
85
+ if (!isBinaryInstalled()) {
86
+ console.error('Error installing SimpleLocalize CLI');
87
+ process.exit(1);
88
+ }
89
+ console.log("SimpleLocalize CLI installed successfully!");
90
+ } else {
91
+ console.log("SimpleLocalize CLI already installed.");
92
+ }
93
+ printBinaryVersion();
94
+ process.exit(0);
95
+ }
96
+
97
+ await init();
package/package.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "name": "@simplelocalize/cli",
3
+ "version": "1.0.0",
4
+ "description": "SimpleLocalize CLI for NPM",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "start": "node index.js"
8
+ },
9
+ "bin": {
10
+ "simplelocalize": "./index.js"
11
+ },
12
+ "dependencies": {
13
+ "axios": "^1.8.3"
14
+ },
15
+ "author": "Jakub Pomykała",
16
+ "license": "MIT"
17
+ }