@simplelocalize/cli 1.0.7 → 1.0.8
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 +41 -0
- package/index.cjs +114 -114
- package/package.json +24 -20
- package/bin/simplelocalize.exe +0 -0
package/README.md
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# SimpleLocalize CLI via npm (work in progress)
|
|
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@1.0.8
|
|
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
|
+
> 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
|
+
## Usage
|
|
20
|
+
|
|
21
|
+
Package SimpleLocalize CLI in your project and makes it available in `package.json` scripts.
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
{
|
|
26
|
+
"name": "My project",
|
|
27
|
+
"version": "1.0.0",
|
|
28
|
+
"private": true,
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@simplelocalize/cli": "^1.0.8",
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"start": "react-scripts start",
|
|
34
|
+
"sl:download": "simplelocalize downlaod",
|
|
35
|
+
"sl:upload": "simplelocalize upload",
|
|
36
|
+
"sl:autotranslate": "simplelocalize autotranslate"
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Learn more about [SimpleLocalize CLI commands](https://github.com/simplelocalize/simplelocalize-cli)
|
package/index.cjs
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
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 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();
|
package/package.json
CHANGED
|
@@ -1,20 +1,24 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@simplelocalize/cli",
|
|
3
|
-
"version": "1.0.
|
|
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
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
},
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
"
|
|
20
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@simplelocalize/cli",
|
|
3
|
+
"version": "1.0.8",
|
|
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
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "https://github.com/simplelocalize/simplelicalize-cli-npm.git"
|
|
14
|
+
},
|
|
15
|
+
"bin": {
|
|
16
|
+
"install": "index.cjs",
|
|
17
|
+
"simplelocalize": "bin/simplelocalize"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"axios": "^1.8.3"
|
|
21
|
+
},
|
|
22
|
+
"author": "Jakub Pomykała",
|
|
23
|
+
"license": "MIT"
|
|
24
|
+
}
|
package/bin/simplelocalize.exe
DELETED
|
Binary file
|