@simplelocalize/cli 1.0.8 → 2.9.0-r2
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 +18 -7
- package/index.cjs +46 -5
- package/package.json +2 -4
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# SimpleLocalize CLI via npm
|
|
1
|
+
# SimpleLocalize CLI via npm
|
|
2
2
|
|
|
3
3
|
The main goal of this project is to give fronted developers
|
|
4
4
|
an easier way to use [SimpleLocalize CLI](https://github.com/simplelocalize/simplelocalize-cli)
|
|
@@ -7,15 +7,13 @@ in their workflows.
|
|
|
7
7
|
## Installation
|
|
8
8
|
|
|
9
9
|
```
|
|
10
|
-
npm install @simplelocalize/cli@
|
|
10
|
+
npm install @simplelocalize/cli@2.9.0-r1
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
After installing the package, it should automatically choose the right binary for
|
|
14
14
|
your system and install it into `node_modules/.bin` directory, to make it available for your
|
|
15
15
|
scripts in `package.json`.
|
|
16
16
|
|
|
17
|
-
> The work on this package is in progress, and at time of writing this documentation, the plugin installs the newest version of the CLI, which is 2.8.0
|
|
18
|
-
|
|
19
17
|
## Usage
|
|
20
18
|
|
|
21
19
|
Package SimpleLocalize CLI in your project and makes it available in `package.json` scripts.
|
|
@@ -27,15 +25,28 @@ Package SimpleLocalize CLI in your project and makes it available in `package.js
|
|
|
27
25
|
"version": "1.0.0",
|
|
28
26
|
"private": true,
|
|
29
27
|
"dependencies": {
|
|
30
|
-
"@simplelocalize/cli": "^
|
|
28
|
+
"@simplelocalize/cli": "^2.9.0-r1",
|
|
31
29
|
},
|
|
32
30
|
"scripts": {
|
|
33
31
|
"start": "react-scripts start",
|
|
34
|
-
"sl:download": "simplelocalize
|
|
32
|
+
"sl:download": "simplelocalize download",
|
|
35
33
|
"sl:upload": "simplelocalize upload",
|
|
36
|
-
"sl:autotranslate": "simplelocalize
|
|
34
|
+
"sl:autotranslate": "simplelocalize auto-translate"
|
|
37
35
|
},
|
|
38
36
|
}
|
|
39
37
|
```
|
|
40
38
|
|
|
41
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-r1` will install SimpleLocalize CLI 2.9.0 and this npm package version is 1.
|
|
49
|
+
`@simplelocalize/cli@2.9.0-r2` 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
|
@@ -10,10 +10,16 @@ if (os.platform() === 'win32') {
|
|
|
10
10
|
binaryPath += '.exe';
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
const getExpectedCliVersion = () => {
|
|
14
|
+
const packageVersion = require('./package.json').version;
|
|
15
|
+
return packageVersion.split('-')[0];
|
|
16
|
+
};
|
|
17
|
+
|
|
13
18
|
const isBinaryInstalled = () => {
|
|
14
19
|
try {
|
|
15
|
-
execSync(binaryPath + ' --version'
|
|
16
|
-
|
|
20
|
+
const output = execSync(binaryPath + ' --version').toString().trim();
|
|
21
|
+
const expectedVersion = getExpectedCliVersion();
|
|
22
|
+
return output.includes(expectedVersion);
|
|
17
23
|
}
|
|
18
24
|
catch (error) {
|
|
19
25
|
return false;
|
|
@@ -49,11 +55,12 @@ const buildDownloadBinaryUrl = (version) => {
|
|
|
49
55
|
arch = "-arm64"
|
|
50
56
|
}
|
|
51
57
|
console.log(`Downloading SimpleLocalize CLI ${version} for ${platform}${arch}...`);
|
|
52
|
-
return `https://
|
|
58
|
+
return `https://get.simplelocalize.io/binaries/${version}/simplelocalize-cli-${platform}${arch}`
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
async function installBinary() {
|
|
56
|
-
const
|
|
62
|
+
const packageVersion = require('./package.json').version;
|
|
63
|
+
const cliVersion = packageVersion.split('-')[0];
|
|
57
64
|
const downloadUrl = buildDownloadBinaryUrl(cliVersion);
|
|
58
65
|
if (!fs.existsSync(path.join(__dirname, 'bin'))) {
|
|
59
66
|
fs.mkdirSync(path.join(__dirname, 'bin'));
|
|
@@ -77,6 +84,11 @@ async function installBinary() {
|
|
|
77
84
|
console.log('Making binary executable...');
|
|
78
85
|
fs.chmodSync(binaryPath, 0o755);
|
|
79
86
|
}
|
|
87
|
+
|
|
88
|
+
// Ensure binary exists and is executable before continuing
|
|
89
|
+
if (!fs.existsSync(binaryPath)) {
|
|
90
|
+
throw new Error('Binary file was not created!');
|
|
91
|
+
}
|
|
80
92
|
}
|
|
81
93
|
|
|
82
94
|
const linkToNodeModulesBin = () => {
|
|
@@ -86,6 +98,12 @@ const linkToNodeModulesBin = () => {
|
|
|
86
98
|
nodeModulesBinPath += '.exe';
|
|
87
99
|
}
|
|
88
100
|
|
|
101
|
+
// Ensure the .bin directory exists
|
|
102
|
+
const binDir = path.dirname(nodeModulesBinPath);
|
|
103
|
+
if (!fs.existsSync(binDir)) {
|
|
104
|
+
fs.mkdirSync(binDir, { recursive: true });
|
|
105
|
+
}
|
|
106
|
+
|
|
89
107
|
if (fs.existsSync(nodeModulesBinPath)) {
|
|
90
108
|
fs.unlinkSync(nodeModulesBinPath);
|
|
91
109
|
}
|
|
@@ -111,4 +129,27 @@ const init = async () => {
|
|
|
111
129
|
process.exit(0);
|
|
112
130
|
}
|
|
113
131
|
|
|
114
|
-
|
|
132
|
+
// Only run install logic if called with 'install' argument (for postinstall)
|
|
133
|
+
if (process.argv[2] === 'install') {
|
|
134
|
+
(async () => {
|
|
135
|
+
await init();
|
|
136
|
+
})();
|
|
137
|
+
} else {
|
|
138
|
+
// Forward all other CLI commands to the downloaded binary
|
|
139
|
+
if (!isBinaryInstalled()) {
|
|
140
|
+
console.error('SimpleLocalize CLI binary is not installed. Please run: npm install');
|
|
141
|
+
process.exit(1);
|
|
142
|
+
}
|
|
143
|
+
// Build the command to forward
|
|
144
|
+
const args = process.argv.slice(2).map(arg => {
|
|
145
|
+
// Quote arguments with spaces for safety
|
|
146
|
+
if (/\s/.test(arg)) return `"${arg}"`;
|
|
147
|
+
return arg;
|
|
148
|
+
}).join(' ');
|
|
149
|
+
try {
|
|
150
|
+
execSync(`${binaryPath} ${args}`, { stdio: 'inherit' });
|
|
151
|
+
process.exit(0);
|
|
152
|
+
} catch (error) {
|
|
153
|
+
process.exit(error.status || 1);
|
|
154
|
+
}
|
|
155
|
+
}
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@simplelocalize/cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.9.0-r2",
|
|
4
4
|
"description": "SimpleLocalize CLI for NPM",
|
|
5
5
|
"main": "index.cjs",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"start": "node index.cjs",
|
|
9
8
|
"postinstall": "node index.cjs install"
|
|
10
9
|
},
|
|
11
10
|
"repository": {
|
|
@@ -13,8 +12,7 @@
|
|
|
13
12
|
"url": "https://github.com/simplelocalize/simplelicalize-cli-npm.git"
|
|
14
13
|
},
|
|
15
14
|
"bin": {
|
|
16
|
-
"
|
|
17
|
-
"simplelocalize": "bin/simplelocalize"
|
|
15
|
+
"simplelocalize": "index.cjs"
|
|
18
16
|
},
|
|
19
17
|
"dependencies": {
|
|
20
18
|
"axios": "^1.8.3"
|