@simplelocalize/cli 1.0.7 → 2.9.0-r1

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 ADDED
@@ -0,0 +1,52 @@
1
+ # SimpleLocalize CLI via npm
2
+
3
+ The main goal of this project is to give fronted developers
4
+ an easier way to use [SimpleLocalize CLI](https://github.com/simplelocalize/simplelocalize-cli)
5
+ in their workflows.
6
+
7
+ ## Installation
8
+
9
+ ```
10
+ npm install @simplelocalize/cli@2.9.0
11
+ ```
12
+
13
+ After installing the package, it should automatically choose the right binary for
14
+ your system and install it into `node_modules/.bin` directory, to make it available for your
15
+ scripts in `package.json`.
16
+
17
+ ## Usage
18
+
19
+ Package SimpleLocalize CLI in your project and makes it available in `package.json` scripts.
20
+
21
+
22
+ ```
23
+ {
24
+ "name": "My project",
25
+ "version": "1.0.0",
26
+ "private": true,
27
+ "dependencies": {
28
+ "@simplelocalize/cli": "^2.9.0",
29
+ },
30
+ "scripts": {
31
+ "start": "react-scripts start",
32
+ "sl:download": "simplelocalize download",
33
+ "sl:upload": "simplelocalize upload",
34
+ "sl:autotranslate": "simplelocalize auto-translate"
35
+ },
36
+ }
37
+ ```
38
+
39
+ Learn more about [SimpleLocalize CLI commands](https://github.com/simplelocalize/simplelocalize-cli)
40
+
41
+ ## Versioning explanation
42
+
43
+ `@simplelocalize/cli` versioning is synced with https://github.com/simplelocalize/simplelocalize-cli versioning.
44
+
45
+ `@simplelocalize/cli@{CLI_VERSION}-release.{NPM_VERSION}` is the versioning scheme used in this package.
46
+ Where `CLI_VERSION` is the version of SimpleLocalize CLI and `NPM_VERSION` is the version of this npm package.
47
+
48
+ `@simplelocalize/cli@2.9.0+1` will install SimpleLocalize CLI 2.9.0 and this npm package version is 1.
49
+ `@simplelocalize/cli@2.9.0+2` will install SimpleLocalize CLI 2.9.0 and this npm package version is 2.
50
+
51
+ By using this versioning scheme, we can release new versions of this npm package
52
+ without changing the SimpleLocalize CLI version, for example, to fix bugs in this package.
package/index.cjs CHANGED
@@ -1,114 +1,150 @@
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
- let binaryPath = path.join(__dirname, 'bin', 'simplelocalize');
9
- if (os.platform() === 'win32') {
10
- binaryPath += '.exe';
11
- }
12
-
13
- const isBinaryInstalled = () => {
14
- try {
15
- execSync(binaryPath + ' --version', { stdio: 'ignore' });
16
- return true;
17
- }
18
- catch (error) {
19
- return false;
20
- }
21
- }
22
-
23
- const printBinaryVersion = () => {
24
- try {
25
- console.log(execSync(binaryPath + ' --version').toString());
26
- }
27
- catch (error) {
28
- console.error('Error running SimpleLocalize CLI');
29
- process.exit(1);
30
- }
31
- }
32
-
33
- const buildDownloadBinaryUrl = (version) => {
34
- let platform = "";
35
- if (os.platform() === "win32") {
36
- platform = "windows.exe"
37
- }
38
-
39
- if (os.platform() === "darwin") {
40
- platform = "mac"
41
- }
42
-
43
- if (os.platform() === "linux") {
44
- platform = "linux"
45
- }
46
-
47
- let arch = "";
48
- if (os.arch() === "arm64") {
49
- arch = "-arm64"
50
- }
51
- console.log(`Downloading SimpleLocalize CLI ${version} for ${platform}${arch}...`);
52
- return `https://github.com/simplelocalize/simplelocalize-cli/releases/download/${version}/simplelocalize-cli-${platform}${arch}`
53
- }
54
-
55
- async function installBinary() {
56
- const cliVersion = "2.8.0";
57
- const downloadUrl = buildDownloadBinaryUrl(cliVersion);
58
- if (!fs.existsSync(path.join(__dirname, 'bin'))) {
59
- fs.mkdirSync(path.join(__dirname, 'bin'));
60
- }
61
-
62
- const response = await axios({
63
- url: downloadUrl,
64
- method: 'GET',
65
- responseType: 'stream'
66
- });
67
-
68
- const writer = fs.createWriteStream(binaryPath);
69
- response.data.pipe(writer);
70
- await new Promise((resolve, reject) => {
71
- writer.on('finish', resolve);
72
- writer.on('error', reject);
73
- });
74
-
75
- // Make it executable (only on Unix-based systems)
76
- if (os.platform() !== 'win32') {
77
- console.log('Making binary executable...');
78
- fs.chmodSync(binaryPath, 0o755);
79
- }
80
- }
81
-
82
- const linkToNodeModulesBin = () => {
83
- let nodeModulesBinPath = path.join(__dirname, '..', '..', '.bin', 'simplelocalize');
84
-
85
- if (os.platform() === 'win32') {
86
- nodeModulesBinPath += '.exe';
87
- }
88
-
89
- if (fs.existsSync(nodeModulesBinPath)) {
90
- fs.unlinkSync(nodeModulesBinPath);
91
- }
92
- fs.symlinkSync(binaryPath, nodeModulesBinPath);
93
- console.log('Link to node_modules/.bin created.');
94
- }
95
-
96
- const init = async () => {
97
- console.log("Checking if SimpleLocalize CLI is installed...");
98
- if (!isBinaryInstalled()) {
99
- console.log("SimpleLocalize CLI not installed. Installing...");
100
- await installBinary();
101
- if (!isBinaryInstalled()) {
102
- console.error('Error installing SimpleLocalize CLI');
103
- process.exit(1);
104
- }
105
- console.log("SimpleLocalize CLI installed successfully!");
106
- } else {
107
- console.log("SimpleLocalize CLI already installed.");
108
- }
109
- printBinaryVersion();
110
- linkToNodeModulesBin();
111
- process.exit(0);
112
- }
113
-
114
- init();
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
+ let binaryPath = path.join(__dirname, 'bin', 'simplelocalize');
9
+ if (os.platform() === 'win32') {
10
+ binaryPath += '.exe';
11
+ }
12
+
13
+ const getExpectedCliVersion = () => {
14
+ const packageVersion = require('./package.json').version;
15
+ return packageVersion.split('+')[0];
16
+ };
17
+
18
+ const isBinaryInstalled = () => {
19
+ try {
20
+ const output = execSync(binaryPath + ' --version').toString().trim();
21
+ const expectedVersion = getExpectedCliVersion();
22
+ return output.includes(expectedVersion);
23
+ }
24
+ catch (error) {
25
+ return false;
26
+ }
27
+ }
28
+
29
+ const printBinaryVersion = () => {
30
+ try {
31
+ console.log(execSync(binaryPath + ' --version').toString());
32
+ }
33
+ catch (error) {
34
+ console.error('Error running SimpleLocalize CLI');
35
+ process.exit(1);
36
+ }
37
+ }
38
+
39
+ const buildDownloadBinaryUrl = (version) => {
40
+ let platform = "";
41
+ if (os.platform() === "win32") {
42
+ platform = "windows.exe"
43
+ }
44
+
45
+ if (os.platform() === "darwin") {
46
+ platform = "mac"
47
+ }
48
+
49
+ if (os.platform() === "linux") {
50
+ platform = "linux"
51
+ }
52
+
53
+ let arch = "";
54
+ if (os.arch() === "arm64") {
55
+ arch = "-arm64"
56
+ }
57
+ console.log(`Downloading SimpleLocalize CLI ${version} for ${platform}${arch}...`);
58
+ return `https://get.simplelocalize.io/binaries/${version}/simplelocalize-cli-${platform}${arch}`
59
+ }
60
+
61
+ async function installBinary() {
62
+ const packageVersion = require('./package.json').version;
63
+ const cliVersion = packageVersion.split('-')[0];
64
+ const downloadUrl = buildDownloadBinaryUrl(cliVersion);
65
+ if (!fs.existsSync(path.join(__dirname, 'bin'))) {
66
+ fs.mkdirSync(path.join(__dirname, 'bin'));
67
+ }
68
+
69
+ const response = await axios({
70
+ url: downloadUrl,
71
+ method: 'GET',
72
+ responseType: 'stream'
73
+ });
74
+
75
+ const writer = fs.createWriteStream(binaryPath);
76
+ response.data.pipe(writer);
77
+ await new Promise((resolve, reject) => {
78
+ writer.on('finish', resolve);
79
+ writer.on('error', reject);
80
+ });
81
+
82
+ // Make it executable (only on Unix-based systems)
83
+ if (os.platform() !== 'win32') {
84
+ console.log('Making binary executable...');
85
+ fs.chmodSync(binaryPath, 0o755);
86
+ }
87
+ }
88
+
89
+ const linkToNodeModulesBin = () => {
90
+ let nodeModulesBinPath = path.join(__dirname, '..', '..', '.bin', 'simplelocalize');
91
+
92
+ if (os.platform() === 'win32') {
93
+ nodeModulesBinPath += '.exe';
94
+ }
95
+
96
+ // Ensure the .bin directory exists
97
+ const binDir = path.dirname(nodeModulesBinPath);
98
+ if (!fs.existsSync(binDir)) {
99
+ fs.mkdirSync(binDir, { recursive: true });
100
+ }
101
+
102
+ if (fs.existsSync(nodeModulesBinPath)) {
103
+ fs.unlinkSync(nodeModulesBinPath);
104
+ }
105
+ fs.symlinkSync(binaryPath, nodeModulesBinPath);
106
+ console.log('Link to node_modules/.bin created.');
107
+ }
108
+
109
+ const init = async () => {
110
+ console.log("Checking if SimpleLocalize CLI is installed...");
111
+ if (!isBinaryInstalled()) {
112
+ console.log("SimpleLocalize CLI not installed. Installing...");
113
+ await installBinary();
114
+ if (!isBinaryInstalled()) {
115
+ console.error('Error installing SimpleLocalize CLI');
116
+ process.exit(1);
117
+ }
118
+ console.log("SimpleLocalize CLI installed successfully!");
119
+ } else {
120
+ console.log("SimpleLocalize CLI already installed.");
121
+ }
122
+ printBinaryVersion();
123
+ linkToNodeModulesBin();
124
+ process.exit(0);
125
+ }
126
+
127
+ // Only run install logic if called with 'install' argument (for postinstall)
128
+ if (process.argv[2] === 'install') {
129
+ (async () => {
130
+ await init();
131
+ })();
132
+ } else {
133
+ // Forward all other CLI commands to the downloaded binary
134
+ if (!isBinaryInstalled()) {
135
+ console.error('SimpleLocalize CLI binary is not installed. Please run: npm install');
136
+ process.exit(1);
137
+ }
138
+ // Build the command to forward
139
+ const args = process.argv.slice(2).map(arg => {
140
+ // Quote arguments with spaces for safety
141
+ if (/\s/.test(arg)) return `"${arg}"`;
142
+ return arg;
143
+ }).join(' ');
144
+ try {
145
+ execSync(`${binaryPath} ${args}`, { stdio: 'inherit' });
146
+ process.exit(0);
147
+ } catch (error) {
148
+ process.exit(error.status || 1);
149
+ }
150
+ }
package/package.json CHANGED
@@ -1,20 +1,22 @@
1
- {
2
- "name": "@simplelocalize/cli",
3
- "version": "1.0.7",
4
- "description": "SimpleLocalize CLI for NPM",
5
- "main": "index.cjs",
6
- "type": "module",
7
- "scripts": {
8
- "start": "node index.cjs",
9
- "postinstall": "node index.cjs install"
10
- },
11
- "bin": {
12
- "install": "index.cjs",
13
- "simplelocalize": "bin/simplelocalize"
14
- },
15
- "dependencies": {
16
- "axios": "^1.8.3"
17
- },
18
- "author": "Jakub Pomykała",
19
- "license": "MIT"
20
- }
1
+ {
2
+ "name": "@simplelocalize/cli",
3
+ "version": "2.9.0-r1",
4
+ "description": "SimpleLocalize CLI for NPM",
5
+ "main": "index.cjs",
6
+ "type": "module",
7
+ "scripts": {
8
+ "postinstall": "node index.cjs install"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/simplelocalize/simplelicalize-cli-npm.git"
13
+ },
14
+ "bin": {
15
+ "simplelocalize": "index.cjs"
16
+ },
17
+ "dependencies": {
18
+ "axios": "^1.8.3"
19
+ },
20
+ "author": "Jakub Pomykała",
21
+ "license": "MIT"
22
+ }
Binary file