🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more →

react-intl-cra

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-intl-cra - npm Package Compare versions

Comparing version

to
0.3.0

@@ -7,22 +7,52 @@ #!/usr/bin/env node

const { spawnSync } = require('child_process');
const chalk = require('chalk');
const pkg = require('../package.json');
const extract = require('../src/index');
const srcPattern = process.argv[2];
const desPath = process.argv[3];
// CLI Arguments
const { _: [pattern], outFile } = require('yargs')
.usage(
`Usage: ${chalk.green('$0')} <pattern> [options]\n
<pattern>\t Glob pattern to specify files.
\t Needs to be surrounded with quotes to prevent shell globbing.
\t Guide to globs: https://github.com/isaacs/node-glob`
)
.demandCommand(1, 1, 'Missing <pattern>')
.strict()
.option('o', {
alias: 'out-file',
describe: 'Output into a single file',
nargs: 1,
type: 'string',
})
.alias('h', 'help')
.version(pkg.version)
.alias('v', 'version')
.locale('en')
.example(`$0 'src/App.js'`, 'One file.')
.example(`$0 'src/**/*.js'`, 'Pattern to specify files')
.example(`$0 'src/**/*.js' -o message.json`, 'Output into a single file.')
.epilogue(
'For more information go to https://github.com/evenchange4/react-intl-cra'
)
.fail((msg, err) => {
if (err) throw err; // preserve stack
console.error(chalk.red(msg)); // eslint-disable-line
process.exit(1);
}).argv;
if (!srcPattern || !desPath) {
console.log('[React-intl-cra] error - srcPattern and desPath isRequired');
process.exit(1);
}
const result = JSON.stringify(extract(pattern), null, 2);
const result = extract(srcPattern);
// Output
spawnSync('mkdir', ['-p', path.dirname(desPath)]);
fs.writeFileSync(desPath, JSON.stringify(result, null, 2));
console.log(
`${path.relative(process.cwd(), srcPattern)} -> ${path.relative(
process.cwd(),
desPath
)}`
);
if (outFile) {
spawnSync('mkdir', ['-p', path.dirname(outFile)]);
fs.writeFileSync(outFile, result);
console.log( // eslint-disable-line
`${path.relative(process.cwd(), pattern)} -> ${path.relative(
process.cwd(),
outFile
)}`
);
} else {
console.log(result); // eslint-disable-line
}
## Change Log
### upcoming (2017/12/14 07:06 +00:00)
### upcoming (2017/12/15 09:01 +00:00)
- [2af6b11](https://github.com/evenchange4/react-intl-cra/commit/2af6b114ab6a1d7288880efb7bb20ce653a30ba6) refactor(ramda) (@evenchange4)
- [e595594](https://github.com/evenchange4/react-intl-cra/commit/e5955946189965ffc149e55278f12bbcaf8ce762) docs(CHANGELOG): release 0.2.12 (@evenchange4)
### v0.2.12 (2017/12/14 07:11 +00:00)
- [284c4fb](https://github.com/evenchange4/react-intl-cra/commit/284c4fb8c3c9dc5d3c9eeff717b32c18be715d3f) 0.2.12 (@evenchange4)
- [#4](https://github.com/evenchange4/react-intl-cra/pull/4) fix(prettier): use es5 trailingComma (#4) (@evenchange4)
- [9441627](https://github.com/evenchange4/react-intl-cra/commit/944162750485bfac3cb247b5c748331cd7f28ca0) docs(CHANGELOG): release 0.2.11 (@evenchange4)

@@ -5,0 +11,0 @@

{
"name": "react-intl-cra",
"version": "0.2.12",
"version": "0.3.0",
"description": "Extract messages of `Creact React App` from the command line",

@@ -29,4 +29,6 @@ "repository": "https://github.com/evenchange4/react-intl-cra",

"babel-preset-react-app": "^3.1.0",
"chalk": "^2.3.0",
"glob": "^7.1.2",
"ramda": "^0.25.0"
"ramda": "^0.25.0",
"yargs": "^10.0.3"
},

@@ -41,3 +43,3 @@ "devDependencies": {

"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jest": "^21.4.2",
"eslint-plugin-jest": "^21.5.0",
"eslint-plugin-prettier": "^2.3.1",

@@ -44,0 +46,0 @@ "flow-bin": "^0.61.0",

@@ -20,6 +20,2 @@ # react-intl-cra

## Demo
Standalone example based on Create-React-App: https://github.com/evenchange4/react-intl-po-example
## Installation

@@ -31,6 +27,8 @@

## Usage
## Demo
Standalone example based on Create-React-App: https://github.com/evenchange4/react-intl-po-example
```json
$ react-intl-cra './src/**/*.js' './messages.json'
$ react-intl-cra './src/**/*.js' -o messages.json
```

@@ -41,3 +39,3 @@

```json
// Output: messages.json
// messages.json

@@ -60,9 +58,35 @@ [

## API
### API
| **Arguments** | **Description** |
| -------------------- | ---------------------------------------- |
| First - `srcPattern` | The pattern of React component files |
| Second - `desPath` | The output pathname of the `.json` file. |
```cmd
$ react-intl-cra --help
Usage: react-intl-cra <pattern> [options]
<pattern> Glob pattern to specify files.
Needs to be surrounded with quotes to prevent shell globbing.
Guide to globs: https://github.com/isaacs/node-glob
Options:
-o, --out-file Output into a single file [string]
-h, --help Show help [boolean]
-v, --version Show version number [boolean]
Examples:
react-intl-cra 'src/App.js' One file.
react-intl-cra 'src/**/*.js' Pattern to specify files
react-intl-cra 'src/**/*.js' -o message.json Output into a single file.
For more information go to https://github.com/evenchange4/react-intl-cra
```
## NPM Usage
```js
import extract from 'react-intl-cra';
const result = extract('./src/**/*.js');
```
## Development

@@ -69,0 +93,0 @@

@@ -9,5 +9,5 @@ // @flow

function extract(srcPattern /* : string */) /* : string */ {
const srcPaths = glob.sync(srcPattern, { absolute: true });
const relativeSrcPaths = glob.sync(srcPattern);
function extract(pattern /* : string */) /* : string */ {
const srcPaths = glob.sync(pattern, { absolute: true });
const relativeSrcPaths = glob.sync(pattern);
const contents = srcPaths.map(p => fs.readFileSync(p, 'utf-8'));

@@ -29,4 +29,4 @@ const messages = contents

)
.filter(m => m.length !== 0)
.reduce((acc, m) => acc.concat(m), []);
.filter(R.complement(R.isEmpty))
.reduce(R.concat, []);

@@ -33,0 +33,0 @@ return result;