i18nexus-cli 3.0.0 → 3.1.0
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 +25 -0
- package/bin/index.js +23 -0
- package/commands/addNamespace.js +31 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -225,3 +225,28 @@ A personal access token that you have generated in your i18nexus account (Can al
|
|
|
225
225
|
|
|
226
226
|
`--overwrite`
|
|
227
227
|
If any keys already exist in the target namespace, overwrite the values with the imported values.
|
|
228
|
+
|
|
229
|
+
## Adding new namespaces
|
|
230
|
+
|
|
231
|
+
`i18nexus add-namespace <namespaceTitle>`
|
|
232
|
+
|
|
233
|
+
```sh
|
|
234
|
+
i18nexus add-namespace common -k <PROJECT_API_KEY> -t <YOUR_PERSONAL_ACCESS_TOKEN>
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
The above snippet will create a new namespace in your i18nexus project with the title `common`.
|
|
238
|
+
|
|
239
|
+
### Options
|
|
240
|
+
|
|
241
|
+
| Option | Required? |
|
|
242
|
+
| ------------------- | --------- |
|
|
243
|
+
| `--api-key` or `-k` | ✔ |
|
|
244
|
+
| `--pat` or `-t` | ✔ |
|
|
245
|
+
|
|
246
|
+
### Notes
|
|
247
|
+
|
|
248
|
+
`--api-key`
|
|
249
|
+
Your project API key (Can also be set using environment variable `I18NEXUS_API_KEY`)
|
|
250
|
+
|
|
251
|
+
`--pat`
|
|
252
|
+
A personal access token that you have generated in your i18nexus account (Can also be set using environment variable `I18NEXUS_PERSONAL_ACCESS_TOKEN`)
|
package/bin/index.js
CHANGED
|
@@ -7,6 +7,7 @@ const addString = require('../commands/addString');
|
|
|
7
7
|
const updateString = require('../commands/updateString');
|
|
8
8
|
const deleteString = require('../commands/deleteString');
|
|
9
9
|
const importJson = require('../commands/importJson');
|
|
10
|
+
const addNamespace = require('../commands/addNamespace');
|
|
10
11
|
|
|
11
12
|
// Using Next's env variable loader because
|
|
12
13
|
// Next supports more than just one .env file
|
|
@@ -193,4 +194,26 @@ program
|
|
|
193
194
|
});
|
|
194
195
|
});
|
|
195
196
|
|
|
197
|
+
program
|
|
198
|
+
.command('add-namespace <namespaceTitle>')
|
|
199
|
+
.alias('a-ns')
|
|
200
|
+
.description('Add a new namespace to your project')
|
|
201
|
+
.requiredOption(
|
|
202
|
+
'-k, --api-key <apiKey>',
|
|
203
|
+
'The API key for your project',
|
|
204
|
+
process.env.I18NEXUS_API_KEY
|
|
205
|
+
)
|
|
206
|
+
.requiredOption(
|
|
207
|
+
'-t, --pat <personalAccessToken>',
|
|
208
|
+
'A personal access token generated for your account in i18nexus',
|
|
209
|
+
process.env.I18NEXUS_PERSONAL_ACCESS_TOKEN
|
|
210
|
+
)
|
|
211
|
+
.action((namespaceTitle, options) => {
|
|
212
|
+
addNamespace({
|
|
213
|
+
title: namespaceTitle,
|
|
214
|
+
apiKey: options.apiKey,
|
|
215
|
+
pat: options.pat
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
196
219
|
program.parse(process.argv);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const colors = require('colors');
|
|
2
|
+
const handleError = require('../handleError');
|
|
3
|
+
const handleFetch = require('../handleFetch');
|
|
4
|
+
const baseUrl = require('../baseUrl');
|
|
5
|
+
|
|
6
|
+
const addNamespace = async opt => {
|
|
7
|
+
let url = `${baseUrl}/project_resources/namespaces.json`;
|
|
8
|
+
|
|
9
|
+
url += `?api_key=${opt.apiKey}`;
|
|
10
|
+
|
|
11
|
+
const response = await handleFetch(url, {
|
|
12
|
+
method: 'POST',
|
|
13
|
+
body: JSON.stringify({
|
|
14
|
+
title: opt.title
|
|
15
|
+
}),
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${opt.pat}`,
|
|
18
|
+
'Content-Type': 'application/json'
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
if (response.status !== 200) {
|
|
23
|
+
return handleError(response);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
await response.json();
|
|
27
|
+
|
|
28
|
+
console.log(colors.green(`New namespace added: "${opt.title}"`));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
module.exports = addNamespace;
|