@kununu/phraseapp-cli 3.1.0-beta.1 → 3.1.0-beta.2
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/index.js +29 -19
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -90,14 +90,13 @@ const getFilePath = (path, filePrefix, localeId) =>
|
|
|
90
90
|
`${path}${getFileName(filePrefix, localeId)}`;
|
|
91
91
|
|
|
92
92
|
function getPhraseAppDownloadUrl(
|
|
93
|
-
accessToken,
|
|
94
93
|
projectId,
|
|
95
94
|
localeId,
|
|
96
95
|
tags,
|
|
97
96
|
fallbackLocaleId,
|
|
98
97
|
branch,
|
|
99
98
|
) {
|
|
100
|
-
return `https
|
|
99
|
+
return `https://api.phraseapp.com/api/v2/projects/${projectId}/locales/${localeId}/download?${getPhraseAppQueryParams(tags, fallbackLocaleId, branch)}`;
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
function downloadLocaleFile(phrase, locale) {
|
|
@@ -120,7 +119,6 @@ function downloadLocaleFile(phrase, locale) {
|
|
|
120
119
|
|
|
121
120
|
return new Promise((resolve, reject) => {
|
|
122
121
|
const url = getPhraseAppDownloadUrl(
|
|
123
|
-
accessToken,
|
|
124
122
|
projectId,
|
|
125
123
|
localeId,
|
|
126
124
|
tags,
|
|
@@ -128,27 +126,39 @@ function downloadLocaleFile(phrase, locale) {
|
|
|
128
126
|
branch,
|
|
129
127
|
);
|
|
130
128
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
129
|
+
const headers = new Headers({
|
|
130
|
+
Authorization: `Basic ${btoa(accessToken)}`,
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
fetch(url, {headers})
|
|
134
|
+
.then(response => {
|
|
135
|
+
if (!response.ok) {
|
|
136
|
+
throw new Error(response);
|
|
137
|
+
}
|
|
138
|
+
return response.json();
|
|
139
|
+
})
|
|
140
|
+
.then(data => {
|
|
141
|
+
// Handle the JSON response
|
|
142
|
+
fs.writeFileSync(filepath, JSON.stringify(data));
|
|
134
143
|
console.info(
|
|
135
144
|
`Success: locale file ${getFileName(filePrefix, localeId)} was updated`
|
|
136
145
|
.green.bold,
|
|
137
146
|
);
|
|
138
147
|
return resolve();
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
148
|
+
})
|
|
149
|
+
.catch(error => {
|
|
150
|
+
if (error.status === 401) {
|
|
151
|
+
console.error('Error: Please check your access_token'.red.bold);
|
|
152
|
+
} else {
|
|
153
|
+
// Handle any errors
|
|
154
|
+
console.error(
|
|
155
|
+
`Error: locale file ${getFileName(filePrefix, localeId)}. Message: ${error.json()}`
|
|
156
|
+
.red,
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return reject();
|
|
161
|
+
});
|
|
152
162
|
});
|
|
153
163
|
}
|
|
154
164
|
|