@kununu/phraseapp-cli 1.4.0-beta.2 → 1.5.0-beta.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/.eslintrc CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "extends": "@kununu",
2
+ "extends": "@kununu/eslint-config",
3
3
  "rules": {
4
4
  "no-restricted-syntax": ["off", ["ForOfStatement"]]
5
5
  }
@@ -0,0 +1,26 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "composer"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
7
+ day: "saturday"
8
+ labels:
9
+ - "dependencies"
10
+ # Disable automatic rebasing to prevent overloading our CICD system
11
+ rebase-strategy: "disabled"
12
+ versioning-strategy: auto
13
+
14
+ - package-ecosystem: "npm"
15
+ directory: "/"
16
+ schedule:
17
+ interval: "weekly"
18
+ day: "saturday"
19
+ labels:
20
+ - "dependencies"
21
+ # Disable automatic rebasing to prevent overloading our CICD system
22
+ rebase-strategy: "disabled"
23
+ versioning-strategy: auto
24
+ # By default Dependabot has a limit of the number of open PR for version updates
25
+ # and security updates.
26
+ # See other defaults in here: https://docs.github.com/en/github/administering-a-repository/configuration-options-for-dependency-updates
package/SECURITY.md ADDED
@@ -0,0 +1,20 @@
1
+ # Security Policy
2
+
3
+
4
+ ## Reporting a Vulnerability
5
+
6
+ Jira is our entrypoint to report security vulnerabilities. Having this mind a KUNSECU user story (type Vulnerability) needs to be created.
7
+
8
+ ### How to fill the user story?
9
+
10
+ Follow this [documentation](https://confluence.xing.hh/pages/viewpage.action?pageId=381133070).
11
+
12
+
13
+ ### To which team do I assign the user story?
14
+
15
+ Follow the [component ownership matrix](https://confluence.xing.hh/display/kununu/Component+ownership+and+support) and assign it to the corresponding team.
16
+
17
+
18
+ ## Reporting the update of dependencies
19
+
20
+ This is the benefit of having Dependabot. It will open pull requests for security and version updates. For more information check the Github [documentation](https://docs.github.com/en/github/administering-a-repository/managing-pull-requests-for-dependency-updates).
package/index.js CHANGED
@@ -1,8 +1,9 @@
1
1
  #! /usr/bin/env node
2
2
 
3
- /* eslint-disable no-console */
3
+ /* eslint-disable */
4
4
 
5
5
  const fs = require('fs');
6
+
6
7
  require('dotenv').config();
7
8
 
8
9
  const request = require('request');
@@ -15,6 +16,7 @@ function logErrorsAndExitProcess (errors) {
15
16
 
16
17
  function loadConfig () {
17
18
  const configPath = `${process.cwd()}/.phraseapp.json`;
19
+
18
20
  if (!fs.existsSync(configPath)) {
19
21
  logErrorsAndExitProcess(['Error: pharaseapp config file doesn\'t exist.']);
20
22
  }
@@ -49,10 +51,10 @@ function loadConfig () {
49
51
  return logErrorsAndExitProcess(errors);
50
52
  }
51
53
 
52
- function getPhraseAppQueryParams (tag, fallbackLocale, branch) {
54
+ function getPhraseAppQueryParams (tags, fallbackLocale, branch) {
53
55
  const queryParams = {
54
56
  file_format: 'react_simple_json',
55
- tag,
57
+ tags: tags.join(','),
56
58
  };
57
59
 
58
60
  if (fallbackLocale) {
@@ -78,42 +80,39 @@ async function loadLocale (phrase) {
78
80
  file = JSON.parse(fs.readFileSync(filepath));
79
81
  }
80
82
 
81
- const tags = locale.tags || [false];
82
-
83
- for (const tag of tags) {
84
- await new Promise((resolve, reject) => {
85
- const url = `https://${
86
- phrase.access_token
87
- }@api.phraseapp.com/api/v2/projects/${phrase.project_id}/locales/${
88
- locale.locale_id
89
- }/download?${getPhraseAppQueryParams(tag, locale.fallback_locale_id, phrase.branch)}`;
90
- request.get(url, (error, response, body) => {
91
- if (!error && response.statusCode === 200) {
92
- fs.writeFileSync(
93
- filepath,
94
- JSON.stringify(Object.assign(file, JSON.parse(body)), null, '\t'),
83
+ await new Promise((resolve, reject) => {
84
+ const url = `https://${
85
+ phrase.access_token
86
+ }@api.phraseapp.com/api/v2/projects/${phrase.project_id}/locales/${
87
+ locale.locale_id
88
+ }/download?${getPhraseAppQueryParams(tags, locale.fallback_locale_id, phrase.branch)}`;
89
+
90
+ request.get(url, (error, response, body) => {
91
+ if (!error && response.statusCode === 200) {
92
+ fs.writeFileSync(
93
+ filepath,
94
+ JSON.stringify(Object.assign(file, JSON.parse(body)), null, '\t'),
95
+ );
96
+ console.info(
97
+ `Success: locale file [${locale.locale_id}.json]${
98
+ tag ? ` for tag ${tag} ` : ' '
99
+ }was updated`.green.bold,
100
+ );
101
+ resolve();
102
+ } else {
103
+ if (response.statusCode !== 401) {
104
+ console.error(
105
+ `Error: locale file [${locale.locale_id}.json] error message: ${
106
+ JSON.parse(body).message
107
+ }`.red.bold,
95
108
  );
96
- console.info(
97
- `Success: locale file [${locale.locale_id}.json]${
98
- tag ? ` for tag ${tag} ` : ' '
99
- }was updated`.green.bold,
100
- );
101
- resolve();
102
109
  } else {
103
- if (response.statusCode !== 401) {
104
- console.error(
105
- `Error: locale file [${locale.locale_id}.json] error message: ${
106
- JSON.parse(body).message
107
- }`.red.bold,
108
- );
109
- } else {
110
- console.error('Error: Please check your access_token'.red.bold);
111
- }
112
- reject(response);
110
+ console.error('Error: Please check your access_token'.red.bold);
113
111
  }
114
- });
112
+ reject(response);
113
+ }
115
114
  });
116
- }
115
+ });
117
116
  }
118
117
  }
119
118
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kununu/phraseapp-cli",
3
- "version": "1.4.0-beta.2",
3
+ "version": "1.5.0-beta.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "bin": {
package/src/argparser.js CHANGED
@@ -1,4 +1,4 @@
1
- const ArgumentParser = require('argparse').ArgumentParser;
1
+ const {ArgumentParser} = require('argparse');
2
2
 
3
3
  const pkg = require('../package.json');
4
4
 
package/src/commands.js CHANGED
@@ -1,40 +1,42 @@
1
1
  const asyncLoop = require('node-async-loop');
2
+
2
3
  const {writeLocaleFile, quitError} = require('./helpers/utils');
3
4
  const {getProject, fetchLocale} = require('./helpers/api');
4
5
 
5
- const fetchAndSave = (config, projectID) =>
6
+ const fetchAndSave = (config, projectID) => (
6
7
  new Promise((resolve, reject) => {
7
8
  asyncLoop(
8
9
  config.LOCALES,
9
10
  (locale, next) => {
10
11
  fetchLocale(config, projectID, locale)
11
- .then(data => {
12
+ .then((data) => {
12
13
  writeLocaleFile(locale, config, data)
13
- .then(data => {
14
+ .then(() => {
14
15
  next();
15
16
  })
16
- .catch(e => {
17
+ .catch((e) => {
17
18
  next(e);
18
19
  });
19
20
  })
20
- .catch(e => {
21
+ .catch((e) => {
21
22
  next(e);
22
23
  });
23
24
  },
24
- err => {
25
+ (err) => {
25
26
  if (err) {
26
27
  reject(err);
27
28
  }
28
29
  resolve();
29
- }
30
+ },
30
31
  );
31
- });
32
+ })
33
+ );
32
34
 
33
- const cmdDownload = async config => {
35
+ const cmdDownload = async (config) => { // eslint-disable-line consistent-return
34
36
  try {
35
- const projectID = config.PROJECT_NAME
36
- ? await getProject(config)
37
- : config.PROJECT_ID;
37
+ const projectID = config.PROJECT_NAME ?
38
+ await getProject(config) :
39
+ config.PROJECT_ID;
38
40
 
39
41
  await fetchAndSave(config, projectID);
40
42
  return true;
@@ -44,5 +46,5 @@ const cmdDownload = async config => {
44
46
  };
45
47
 
46
48
  module.exports = {
47
- cmdDownload
49
+ cmdDownload,
48
50
  };
@@ -4,11 +4,11 @@ const {PHRASEAPP_BASEURL} = require('../constants');
4
4
  const {MESSAGES} = require('../constants');
5
5
 
6
6
  const getPhraseAppApiEndpoint = (endpoint, token) => ({
7
- url: `https://${token}@${PHRASEAPP_BASEURL}/${endpoint}`,
8
7
  json: true,
8
+ url: `https://${token}@${PHRASEAPP_BASEURL}/${endpoint}`,
9
9
  });
10
10
 
11
- const getProject = config =>
11
+ const getProject = config => (
12
12
  new Promise((resolve, reject) => {
13
13
  request.get(getPhraseAppApiEndpoint('projects', config.TOKEN), (err, res, body) => {
14
14
  if (err) {
@@ -23,6 +23,7 @@ const getProject = config =>
23
23
  const projectID = body
24
24
  .filter(item => item.name === config.PROJECT_NAME)
25
25
  .map(item => item.id);
26
+
26
27
  if (projectID.length < 1) {
27
28
  reject(new Error(MESSAGES.PROJECT_NOT_FOUND));
28
29
  }
@@ -30,9 +31,10 @@ const getProject = config =>
30
31
  resolve(projectID[0]);
31
32
  }
32
33
  });
33
- });
34
+ })
35
+ );
34
36
 
35
- const fetchLocale = (config, projectID, locale) =>
37
+ const fetchLocale = (config, projectID, locale) => (
36
38
  new Promise((resolve, reject) => {
37
39
  const tag = config.TAG ? `&tag=${config.TAG}` : '';
38
40
 
@@ -66,10 +68,11 @@ const fetchLocale = (config, projectID, locale) =>
66
68
  );
67
69
  }
68
70
  });
69
- });
71
+ })
72
+ );
70
73
 
71
74
  module.exports = {
72
- getProject,
73
75
  fetchLocale,
74
76
  getPhraseAppApiEndpoint,
77
+ getProject,
75
78
  };
@@ -22,7 +22,7 @@ const quitSuccess = (msg) => {
22
22
  process.exit(0);
23
23
  };
24
24
 
25
- const mkConfig = args =>
25
+ const mkConfig = args => (
26
26
  new Promise((resolve, reject) => {
27
27
  const config = {
28
28
  TOKEN: args.token || process.env.PHRASEAPP_ACCESS_TOKEN,
@@ -48,9 +48,10 @@ const mkConfig = args =>
48
48
  }
49
49
 
50
50
  resolve(config);
51
- });
51
+ })
52
+ );
52
53
 
53
- const writeLocaleFile = (locale, config, data) =>
54
+ const writeLocaleFile = (locale, config, data) => (
54
55
  new Promise((resolve, reject) => {
55
56
  const fileExt = FORMATS.filter(item => item.format === config.FORMAT).map(
56
57
  item => item.ext,
@@ -72,11 +73,12 @@ const writeLocaleFile = (locale, config, data) =>
72
73
  resolve(`Written: ${file}`);
73
74
  });
74
75
  });
75
- });
76
+ })
77
+ );
76
78
 
77
79
  module.exports = {
78
- quitSuccess,
79
- quitError,
80
80
  mkConfig,
81
+ quitError,
82
+ quitSuccess,
81
83
  writeLocaleFile,
82
84
  };