Skip to content

Commit

Permalink
Merge pull request #3 from 2gis/update-packages
Browse files Browse the repository at this point in the history
Update packages
  • Loading branch information
ktoto authored Jan 30, 2023
2 parents b3e77a3 + 0d8218d commit f73c8d7
Show file tree
Hide file tree
Showing 27 changed files with 3,315 additions and 3,718 deletions.
29 changes: 29 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module.exports = {
parserOptions: {
tsconfigRootDir: __dirname,
project: ['./tsconfig.json'],
},
extends: ['plugin:@typescript-eslint/recommended'],
plugins: ['functional'],
overrides: [
{
files: ['*.spec.tsx', '*.spec.ts', '*.stories.tsx'],
rules: {
'no-unused-expressions': 'off',
'functional/immutable-data': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
],
rules: {
'import/no-anonymous-default-export': 'off',
'no-useless-rename': 'error',
'object-shorthand': ['error', 'always'],
'@typescript-eslint/ban-ts-comment': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-loss-of-precision': 'off',
'@typescript-eslint/no-unused-vars': 'off',
'@typescript-eslint/no-var-requires': 'off',
},
};
10 changes: 10 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"printWidth": 100,
"useTabs": false,
"tabWidth": 2,
"semi": true,
"singleQuote": true,
"trailingComma": "all",
"bracketSpacing": true,
"arrowParens": "always"
}
2 changes: 1 addition & 1 deletion bin/pojson
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#!/usr/bin/env node
require('../dist/index.js')
require('../dist/cli.js');
1 change: 1 addition & 0 deletions dist/cli.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
109 changes: 109 additions & 0 deletions dist/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
"use strict";
exports.__esModule = true;
var fs_1 = require("fs");
var yargs_1 = require("yargs");
var getStdin = require("get-stdin");
var convert_1 = require("./convert");
var yargsInstance = (0, yargs_1["default"])(process.argv.slice(2))
.usage('i18n PO -> JSON converter')
.help()
.options({
src: {
alias: 's',
description: 'Define input JSON file name. Defaults to stdin.',
type: 'string',
"default": '__stdin'
},
output: {
alias: 'o',
description: 'Define output POT file name. If a file already ' +
'exists, it s contents will be overwritten. Defaults to stdout.',
type: 'string',
"default": '__stdout'
},
withOccurences: {
alias: 'n',
description: 'Include occurences info into JSON file, ' + 'parsed from "#: ..." comments.',
type: 'boolean',
"default": false
},
withComments: {
alias: 'c',
description: 'Include comments into JSON file, parsed ' + 'from "#. ..." comments.',
type: 'boolean',
"default": false
},
withMeta: {
alias: 'm',
description: 'Include parsed PO header or plural form ' +
'into JSON file. Add all header values' +
'without any params provided. Possable values "" | "full" | "plural"',
type: 'string',
"default": undefined
},
prettify: {
alias: 'p',
description: 'Pretty-print JSON output.',
type: 'boolean',
"default": false
}
});
var yargOpts = yargsInstance.parseSync();
if (yargOpts.help) {
yargsInstance.showHelp();
process.exit(0);
}
console.warn('Running conversion for file: ', yargOpts.src);
var parsedOptions = {
withOccurences: yargOpts.withOccurences,
withComments: yargOpts.withComments,
withMeta: false
};
if (yargOpts.withMeta === '' || yargOpts.withMeta === 'full') {
parsedOptions.withMeta = 'full';
}
else {
if (yargOpts.withMeta === 'plural') {
parsedOptions.withMeta = 'plural';
}
}
if (yargOpts.src === '__stdin') {
getStdin().then(function (data) {
try {
makeOutput((0, convert_1.convert)(data, parsedOptions), yargOpts.output, yargOpts.prettify);
}
catch (e) {
console.error(e);
process.exit(1);
}
});
}
else {
(0, fs_1.readFile)(yargOpts.src, { encoding: 'utf-8' }, function (err, data) {
if (err) {
console.error(err);
process.exit(1);
}
try {
makeOutput((0, convert_1.convert)(data, parsedOptions), yargOpts.output, yargOpts.prettify);
}
catch (e) {
console.error(e);
process.exit(1);
}
});
}
function makeOutput(data, output, prettify) {
if (output === '__stdout') {
console.log(JSON.stringify(data, undefined, prettify ? ' ' : undefined));
}
else {
(0, fs_1.writeFile)(output, JSON.stringify(data, undefined, prettify ? ' ' : undefined), function (e) {
if (e) {
console.error(e);
process.exit(1);
}
process.exit(0); // success
});
}
}
17 changes: 17 additions & 0 deletions dist/convert.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { I18NEntry, TranslationJson, TranslationMeta } from 'i18n-proto';
import { PoOptions } from './types';
export declare function splitInTwo(src: string, separator?: string): [string, string];
export declare function convert(data: string, opts: PoOptions): TranslationJson;
export declare function parseHeader(headerString: string, opts: PoOptions): TranslationMeta | undefined;
export declare function parseEntry(entry: string, withComments: boolean, withOccurences: boolean): I18NEntry | undefined;
type _ParseRetval = {
comments: string[];
occurences: string[];
context?: string;
msgid?: string;
msgidPlural?: string;
msgStr?: string;
msgStrPlural: string[];
};
export declare function _parse(entries: string[], withComments: boolean, withOccurences: boolean): _ParseRetval;
export {};
Loading

0 comments on commit f73c8d7

Please sign in to comment.