@kununu/phraseapp-cli 2.0.1 → 3.0.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/package.json CHANGED
@@ -1,40 +1,17 @@
1
1
  {
2
2
  "name": "@kununu/phraseapp-cli",
3
- "version": "2.0.1",
3
+ "version": "3.0.0-beta.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
- "bin": {
7
- "wat": "src/cli.js"
8
- },
9
6
  "author": "kununu",
10
7
  "license": "MIT",
11
- "scripts": {
12
- "test": "ava ./tests",
13
- "build": "rimraf ./dist && pkg . --out-path ./dist",
14
- "build:tux": "rimraf ./dist && pkg . --output ./dist/phraseapp-cli-linux -t node8-linux-x64",
15
- "release": "npm run build && dlvr release auto -f"
16
- },
8
+ "scripts": {},
17
9
  "dependencies": {
18
- "argparse": "1.0.10",
19
10
  "colors": "1.3.3",
20
11
  "dotenv": "8.0.0",
21
- "gettext-parser": "4.0.0",
22
- "mkdirp": "1.0.4",
23
- "node-async-loop": "1.2.2",
24
12
  "request": "2.88.0"
25
13
  },
26
14
  "devDependencies": {
27
- "@kununu/eslint-config": "1.0.7",
28
- "ava": "1.4.1",
29
- "babel-eslint": "10.0.1",
30
- "eslint": "5.16.0",
31
- "eslint-import-resolver-alias": "1.1.2",
32
- "eslint-plugin-babel": "5.3.0",
33
- "eslint-plugin-import": "2.17.2",
34
- "eslint-plugin-jsx-a11y": "6.2.1",
35
- "eslint-plugin-react": "7.13.0",
36
- "pkg": "4.3.8",
37
- "prettier": "1.17.0",
38
- "rimraf": "2.6.3"
15
+ "@kununu/eslint-config": "2.2.0"
39
16
  }
40
17
  }
package/.dlvr DELETED
@@ -1,19 +0,0 @@
1
- {
2
- "dotenv": ".env",
3
- "preRun": "npm run build:tux",
4
- "logfilter": ".*#",
5
- "remote": "origin",
6
- "githost": {
7
- "provider": "github",
8
- "repo": "kununu/phraseapp-cli",
9
- "release": {
10
- "assets": [
11
- {
12
- "file": "./dist/phraseapp-cli-linux",
13
- "name": "phraseapp-cli-linux"
14
- }
15
- ]
16
- }
17
- },
18
- "npmpublish": false
19
- }
package/src/argparser.js DELETED
@@ -1,71 +0,0 @@
1
- const {ArgumentParser} = require('argparse');
2
-
3
- const pkg = require('../package.json');
4
-
5
- const {SUPPORTED_FORMATS} = require('./constants');
6
-
7
- const parsedArgs = () => {
8
- const parser = new ArgumentParser({
9
- version: pkg.version,
10
- addHelp: true,
11
- description: 'phraseapp-cli',
12
- });
13
-
14
- const subparsers = parser.addSubparsers({
15
- title: 'subcommands',
16
- dest: 'subcmd',
17
- });
18
-
19
- const cmdMain = subparsers.addParser('download', {
20
- addHelp: true,
21
- help: 'Download',
22
- });
23
-
24
- cmdMain.addArgument(['-d', '--directory'], {
25
- action: 'store',
26
- help: 'Download Directory',
27
- metavar: 'directory',
28
- });
29
-
30
- cmdMain.addArgument(['-p', '--projectname'], {
31
- action: 'store',
32
- help: 'Projectname',
33
- metavar: 'projectname',
34
- });
35
-
36
- cmdMain.addArgument(['-i', '--projectid'], {
37
- action: 'store',
38
- help: 'Project ID',
39
- metavar: 'projectid',
40
- });
41
-
42
- cmdMain.addArgument(['--token'], {
43
- action: 'store',
44
- help: 'API Access Token',
45
- metavar: 'token',
46
- });
47
-
48
- cmdMain.addArgument(['--tag'], {
49
- action: 'store',
50
- help: 'Tagname',
51
- metavar: 'tag',
52
- });
53
-
54
- cmdMain.addArgument(['-f', '--format'], {
55
- action: 'store',
56
- help: `Format of the locales, Supported: ${SUPPORTED_FORMATS}`,
57
- metavar: 'format',
58
- required: true,
59
- });
60
-
61
- cmdMain.addArgument(['-l', '--locales'], {
62
- action: 'store',
63
- help: 'Comma seperated list of locale IDs (de_DE,en_US)',
64
- metavar: 'format',
65
- required: true,
66
- });
67
-
68
- return parser.parseArgs();
69
- };
70
-
71
- module.exports = parsedArgs;
package/src/cli.js DELETED
@@ -1,20 +0,0 @@
1
- require('dotenv').config();
2
-
3
- const parsedArgs = require('./argparser');
4
- const {cmdDownload} = require('./commands');
5
- const {quitError, quitSuccess, mkConfig} = require('./helpers/utils');
6
- const {MESSAGES} = require('./constants');
7
-
8
- const args = parsedArgs();
9
-
10
- if (args.subcmd === 'download') {
11
- mkConfig(args)
12
- .then((config) => {
13
- cmdDownload(config).then(() => {
14
- quitSuccess(MESSAGES.SUCCESS);
15
- });
16
- })
17
- .catch((e) => {
18
- quitError(e);
19
- });
20
- }
package/src/commands.js DELETED
@@ -1,50 +0,0 @@
1
- const asyncLoop = require('node-async-loop');
2
-
3
- const {writeLocaleFile, quitError} = require('./helpers/utils');
4
- const {getProject, fetchLocale} = require('./helpers/api');
5
-
6
- const fetchAndSave = (config, projectID) => (
7
- new Promise((resolve, reject) => {
8
- asyncLoop(
9
- config.LOCALES,
10
- (locale, next) => {
11
- fetchLocale(config, projectID, locale)
12
- .then((data) => {
13
- writeLocaleFile(locale, config, data)
14
- .then(() => {
15
- next();
16
- })
17
- .catch((e) => {
18
- next(e);
19
- });
20
- })
21
- .catch((e) => {
22
- next(e);
23
- });
24
- },
25
- (err) => {
26
- if (err) {
27
- reject(err);
28
- }
29
- resolve();
30
- },
31
- );
32
- })
33
- );
34
-
35
- const cmdDownload = async (config) => { // eslint-disable-line consistent-return
36
- try {
37
- const projectID = config.PROJECT_NAME ?
38
- await getProject(config) :
39
- config.PROJECT_ID;
40
-
41
- await fetchAndSave(config, projectID);
42
- return true;
43
- } catch (e) {
44
- quitError(e);
45
- }
46
- };
47
-
48
- module.exports = {
49
- cmdDownload,
50
- };
package/src/constants.js DELETED
@@ -1,44 +0,0 @@
1
- const path = require('path');
2
-
3
- const PHRASEAPP_BASEURL = 'api.phraseapp.com/api/v2';
4
- const DEFAULT_DOWNLOAD_DIR = path.join(process.cwd(), './phraseapp');
5
- const FORMATS = [
6
- {
7
- format: 'react_simple_json',
8
- ext: '.json',
9
- },
10
- {
11
- format: 'yml_symphony',
12
- ext: '.yml',
13
- },
14
- {
15
- format: 'gettext',
16
- ext: '.po',
17
- },
18
- {
19
- format: 'simple_json',
20
- ext: '.json',
21
- },
22
- ];
23
-
24
- const SUPPORTED_FORMATS = FORMATS.map(item => item.format);
25
-
26
- const MESSAGES = {
27
- SUCCESS: 'phraseapp-cli: Successfully downloaded locales',
28
- UNKNOWN_ERROR: 'phraseapp-cli Error: Unknown Error',
29
- INVALID_TOKEN: 'phraseapp-cli Error: No Phraseapp Token given',
30
- NO_PROJECT: 'phraseapp-cli Error: No Project given',
31
- PROJECT_NOT_FOUND: 'phraseapp-cli Error: Project not found',
32
- WRONG_TOKEN: 'phraseapp-cli Error: Phraseapp Token is invalid',
33
- WRONG_FORMAT: `phraseapp-cli Error: Format not Supported, Supported Formats: ${
34
- SUPPORTED_FORMATS
35
- }`,
36
- };
37
-
38
- module.exports = {
39
- PHRASEAPP_BASEURL,
40
- DEFAULT_DOWNLOAD_DIR,
41
- SUPPORTED_FORMATS,
42
- MESSAGES,
43
- FORMATS,
44
- };
@@ -1,78 +0,0 @@
1
- const request = require('request');
2
-
3
- const {PHRASEAPP_BASEURL} = require('../constants');
4
- const {MESSAGES} = require('../constants');
5
-
6
- const getPhraseAppApiEndpoint = (endpoint, token) => ({
7
- json: true,
8
- url: `https://${token}@${PHRASEAPP_BASEURL}/${endpoint}`,
9
- });
10
-
11
- const getProject = config => (
12
- new Promise((resolve, reject) => {
13
- request.get(getPhraseAppApiEndpoint('projects', config.TOKEN), (err, res, body) => {
14
- if (err) {
15
- reject(err);
16
- }
17
-
18
- if (res.statusCode === 401) {
19
- reject(new Error(MESSAGES.INVALID_TOKEN));
20
- }
21
-
22
- if (res.statusCode === 200) {
23
- const projectID = body
24
- .filter(item => item.name === config.PROJECT_NAME)
25
- .map(item => item.id);
26
-
27
- if (projectID.length < 1) {
28
- reject(new Error(MESSAGES.PROJECT_NOT_FOUND));
29
- }
30
-
31
- resolve(projectID[0]);
32
- }
33
- });
34
- })
35
- );
36
-
37
- const fetchLocale = (config, projectID, locale) => (
38
- new Promise((resolve, reject) => {
39
- const tag = config.TAG ? `&tag=${config.TAG}` : '';
40
-
41
- // If there is a fallback specified, include_empty_translations also needs to be set to true
42
- const fallback = config.FALLBACK_LOCALE_ID ? `&include_empty_translations&fallback_locale_id=${config.FALLBACK_LOCALE_ID}` : '';
43
- const localeEndpoint = getPhraseAppApiEndpoint(
44
- `projects/${projectID}/locales/${locale}/download?file_format=${config.FORMAT}${tag}${fallback}`, // eslint-disable-line
45
- config.TOKEN,
46
- );
47
-
48
- request.get(localeEndpoint, (err, res, body) => {
49
- if (err) {
50
- reject(err);
51
- }
52
-
53
- if (res.statusCode === 404) {
54
- reject(new Error(MESSAGES.PROJECT_NOT_FOUND));
55
- }
56
-
57
- if (res.statusCode === 401) {
58
- reject(new Error(MESSAGES.WRONG_TOKEN));
59
- }
60
-
61
- if (res.statusCode === 200) {
62
- resolve(body);
63
- } else {
64
- reject(
65
- new Error(
66
- `${MESSAGES.UNKNOWN_ERROR} \n ${JSON.stringify(body, null, 2)}`,
67
- ),
68
- );
69
- }
70
- });
71
- })
72
- );
73
-
74
- module.exports = {
75
- fetchLocale,
76
- getPhraseAppApiEndpoint,
77
- getProject,
78
- };
@@ -1,84 +0,0 @@
1
- /* eslint-disable no-console */
2
-
3
- const fs = require('fs');
4
- const path = require('path');
5
-
6
- const mkdirp = require('mkdirp');
7
-
8
- const {
9
- DEFAULT_DOWNLOAD_DIR,
10
- MESSAGES,
11
- FORMATS,
12
- SUPPORTED_FORMATS,
13
- } = require('../constants');
14
-
15
- const quitError = (err, code = 1) => {
16
- console.log(err.message);
17
- process.exit(code);
18
- };
19
-
20
- const quitSuccess = (msg) => {
21
- console.log(msg);
22
- process.exit(0);
23
- };
24
-
25
- const mkConfig = args => (
26
- new Promise((resolve, reject) => {
27
- const config = {
28
- TOKEN: args.token || process.env.PHRASEAPP_ACCESS_TOKEN,
29
- PROJECT_NAME: args.projectname || process.env.PHRASEAPP_PROJECT_NAME,
30
- PROJECT_ID: args.projectid || process.env.PHRASEAPP_PROJECT_ID,
31
- DIR: args.directory || DEFAULT_DOWNLOAD_DIR,
32
- FORMAT: args.format,
33
- TAG: args.tag || false,
34
- FALLBACK_LOCALE_ID: args.fallback_locale_id || false,
35
- LOCALES: args.locales ? args.locales.split(',') : [],
36
- };
37
-
38
- if (SUPPORTED_FORMATS.indexOf(config.FORMAT) < 0) {
39
- reject(new Error(MESSAGES.WRONG_FORMAT));
40
- }
41
-
42
- if (!config.TOKEN) {
43
- reject(new Error(MESSAGES.INVALID_TOKEN));
44
- }
45
-
46
- if (!config.PROJECT_NAME && !config.PROJECT_ID) {
47
- reject(new Error(MESSAGES.NO_PROJECT));
48
- }
49
-
50
- resolve(config);
51
- })
52
- );
53
-
54
- const writeLocaleFile = (locale, config, data) => (
55
- new Promise((resolve, reject) => {
56
- const fileExt = FORMATS.filter(item => item.format === config.FORMAT).map(
57
- item => item.ext,
58
- )[0];
59
- const file = path.join(config.DIR, `${locale}${fileExt}`);
60
-
61
- mkdirp(config.DIR, (err) => {
62
- if (err) {
63
- reject(err);
64
- }
65
-
66
- const writeData =
67
- typeof data === 'object' ? JSON.stringify(data, null, 2) : data;
68
-
69
- fs.writeFile(file, writeData, (writeErr) => {
70
- if (writeErr) {
71
- reject(writeErr);
72
- }
73
- resolve(`Written: ${file}`);
74
- });
75
- });
76
- })
77
- );
78
-
79
- module.exports = {
80
- mkConfig,
81
- quitError,
82
- quitSuccess,
83
- writeLocaleFile,
84
- };
package/tests/api.spec.js DELETED
@@ -1,10 +0,0 @@
1
- const test = require('ava');
2
- const api = require('../src/helpers/api');
3
-
4
- test('Will generate valid request opt for endpoint', t => {
5
- const f = api.endpoint('mahendpoint', 'mahtoken');
6
- t.deepEqual(f, {
7
- json: true,
8
- url: 'https://mahtoken@api.phraseapp.com/api/v2/mahendpoint'
9
- });
10
- });