@kununu/phraseapp-cli 3.1.0-beta.1 → 3.1.0-beta.3
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 +29 -30
- package/index.js +35 -20
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -1,59 +1,58 @@
|
|
|
1
1
|
# phraseapp-cli
|
|
2
|
-
>
|
|
2
|
+
>
|
|
3
|
+
> phraseapp-cli for <https://phraseapp.com/>
|
|
3
4
|
|
|
4
5
|
## Installation
|
|
5
6
|
|
|
7
|
+
### Add `@kununu/phraseapp-cli` to your project
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @kununu/phraseapp-cli --save
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Add `update-translations` to your project
|
|
14
|
+
|
|
6
15
|
Add to ```package.json```
|
|
16
|
+
|
|
7
17
|
```json
|
|
8
|
-
"
|
|
9
|
-
```
|
|
10
|
-
```sh
|
|
11
|
-
$ npm i
|
|
12
|
-
```
|
|
13
|
-
```sh
|
|
14
|
-
$ npm link
|
|
18
|
+
"update-translations": "node ./node_modules/@kununu/phraseapp-cli/index.js",
|
|
15
19
|
```
|
|
20
|
+
|
|
21
|
+
### Add env vars
|
|
22
|
+
|
|
23
|
+
Make sure PHRASEAPP_PROJECT_ID and PHRASEAPP_ACCESS_TOKEN are properly configured.
|
|
24
|
+
|
|
16
25
|
## Configuration file
|
|
17
26
|
|
|
18
|
-
You have to
|
|
27
|
+
You have to add the ```.phraseapp.json``` file
|
|
19
28
|
|
|
20
29
|
**For example**:
|
|
30
|
+
|
|
21
31
|
```json
|
|
22
32
|
{
|
|
23
|
-
"access_token": "YOUR_ACCESS_TOKEN",
|
|
24
33
|
"project_id": "YOUR_PROJECT_ID",
|
|
25
34
|
"path": "YOUR_TRANSLATIONS_PATH",
|
|
26
|
-
"locales":[
|
|
35
|
+
"locales": [
|
|
27
36
|
{
|
|
28
|
-
"locale_id": "
|
|
29
|
-
"tags":[
|
|
37
|
+
"locale_id": "de_DE",
|
|
38
|
+
"tags": [
|
|
30
39
|
"TAG1",
|
|
31
40
|
"TAG2",
|
|
32
41
|
"TAG3"
|
|
33
42
|
]
|
|
34
43
|
},
|
|
35
44
|
{
|
|
36
|
-
"locale_id": "
|
|
37
|
-
|
|
45
|
+
"locale_id": "de_AT",
|
|
46
|
+
"tags": [
|
|
47
|
+
(...)
|
|
48
|
+
],
|
|
49
|
+
"fallback_locale_id": "de_DE"
|
|
50
|
+
},
|
|
51
|
+
(...)
|
|
38
52
|
]
|
|
39
53
|
}
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
## Config parameters
|
|
43
|
-
- locale_id (**required**) - for example **pl_PL**
|
|
44
|
-
- tags (*optional array*) - project tag
|
|
45
|
-
## Usage
|
|
46
|
-
|
|
47
|
-
```js
|
|
48
|
-
phraseapp-cli
|
|
49
54
|
```
|
|
50
55
|
|
|
51
|
-
|
|
52
56
|
## License
|
|
53
57
|
|
|
54
58
|
Apache-2.0 © [kununu](https://kununu.com)
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
[npm-image]: https://badge.fury.io/js/kununu.svg
|
|
58
|
-
[npm-url]: https://npmjs.org/package/kununu
|
|
59
|
-
[phraseapp-config]: https://phraseapp.com/docs/developers/cli/configuration/
|
package/index.js
CHANGED
|
@@ -36,11 +36,16 @@ function loadConfig() {
|
|
|
36
36
|
try {
|
|
37
37
|
const phrase = JSON.parse(fs.readFileSync(configPath));
|
|
38
38
|
|
|
39
|
-
// override
|
|
39
|
+
// override access token with env var, if available
|
|
40
40
|
if (process.env.PHRASEAPP_ACCESS_TOKEN) {
|
|
41
41
|
phrase.access_token = process.env.PHRASEAPP_ACCESS_TOKEN;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
// override project id with env var, if available
|
|
45
|
+
if (process.env.PHRASEAPP_PROJECT_ID) {
|
|
46
|
+
phrase.project_id = process.env.PHRASEAPP_PROJECT_ID;
|
|
47
|
+
}
|
|
48
|
+
|
|
44
49
|
if (!phrase.locales) {
|
|
45
50
|
errors.push(
|
|
46
51
|
'Error: please provide locales in config file ( for example: locales: "pl_PL" ).',
|
|
@@ -90,14 +95,13 @@ const getFilePath = (path, filePrefix, localeId) =>
|
|
|
90
95
|
`${path}${getFileName(filePrefix, localeId)}`;
|
|
91
96
|
|
|
92
97
|
function getPhraseAppDownloadUrl(
|
|
93
|
-
accessToken,
|
|
94
98
|
projectId,
|
|
95
99
|
localeId,
|
|
96
100
|
tags,
|
|
97
101
|
fallbackLocaleId,
|
|
98
102
|
branch,
|
|
99
103
|
) {
|
|
100
|
-
return `https
|
|
104
|
+
return `https://api.phraseapp.com/api/v2/projects/${projectId}/locales/${localeId}/download?${getPhraseAppQueryParams(tags, fallbackLocaleId, branch)}`;
|
|
101
105
|
}
|
|
102
106
|
|
|
103
107
|
function downloadLocaleFile(phrase, locale) {
|
|
@@ -120,7 +124,6 @@ function downloadLocaleFile(phrase, locale) {
|
|
|
120
124
|
|
|
121
125
|
return new Promise((resolve, reject) => {
|
|
122
126
|
const url = getPhraseAppDownloadUrl(
|
|
123
|
-
accessToken,
|
|
124
127
|
projectId,
|
|
125
128
|
localeId,
|
|
126
129
|
tags,
|
|
@@ -128,27 +131,39 @@ function downloadLocaleFile(phrase, locale) {
|
|
|
128
131
|
branch,
|
|
129
132
|
);
|
|
130
133
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
const headers = new Headers({
|
|
135
|
+
Authorization: `Basic ${btoa(accessToken)}`,
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
fetch(url, {headers})
|
|
139
|
+
.then(response => {
|
|
140
|
+
if (!response.ok) {
|
|
141
|
+
throw new Error(response);
|
|
142
|
+
}
|
|
143
|
+
return response.json();
|
|
144
|
+
})
|
|
145
|
+
.then(data => {
|
|
146
|
+
// Handle the JSON response
|
|
147
|
+
fs.writeFileSync(filepath, JSON.stringify(data));
|
|
134
148
|
console.info(
|
|
135
149
|
`Success: locale file ${getFileName(filePrefix, localeId)} was updated`
|
|
136
150
|
.green.bold,
|
|
137
151
|
);
|
|
138
152
|
return resolve();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
153
|
+
})
|
|
154
|
+
.catch(error => {
|
|
155
|
+
if (error.status === 401) {
|
|
156
|
+
console.error('Error: Please check your access_token'.red.bold);
|
|
157
|
+
} else {
|
|
158
|
+
// Handle any errors
|
|
159
|
+
console.error(
|
|
160
|
+
`Error: locale file ${getFileName(filePrefix, localeId)}. Message: ${error.json()}`
|
|
161
|
+
.red,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return reject();
|
|
166
|
+
});
|
|
152
167
|
});
|
|
153
168
|
}
|
|
154
169
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kununu/phraseapp-cli",
|
|
3
|
-
"version": "3.1.0-beta.
|
|
3
|
+
"version": "3.1.0-beta.3",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "kununu",
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
"dotenv": "16.4.5"
|
|
14
14
|
},
|
|
15
15
|
"devDependencies": {
|
|
16
|
-
"@babel/eslint-plugin": "7.23.5",
|
|
17
16
|
"@kununu/eslint-config": "5.0.1"
|
|
18
17
|
}
|
|
19
18
|
}
|