Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add --dir flag for export command #1

Merged
merged 2 commits into from
Jul 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ Here is an example:
}
```

### --dir

By default, `vue-i18n-service` looks for SFCs in the `src/` directory, if your components are in another directory, specify it by passing the `--dir` flag:

```bash
npx vue-i18n-service export --dir=client/ > translations.json
```

## Importing `translations.json` file to the SFCs

After bulk changing files, you can distribute import all the files calling `import` command.
Expand Down
6 changes: 5 additions & 1 deletion bin/vue-i18n-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const glob = require('glob')
const fs = require('fs')
const myjson = require('myjson-api')
const compiler = require('vue-template-compiler')
const argv = require('yargs').argv

function replaceBetween (str, start, end, what) {
return str.substring(0, start) + what + str.substring(end)
Expand Down Expand Up @@ -40,7 +41,8 @@ function runImport () {
}

function runExport (fn) {
glob('src/**/*.vue', (_, files) => {
const dir = argv.dir || 'src/'
glob(`${dir}**/*.vue`, (_, files) => {
const out = {}
files.forEach(file => {
const componentAst = compiler.parseComponent(fs.readFileSync(file).toString())
Expand Down Expand Up @@ -76,6 +78,8 @@ switch (process.argv[2]) {
console.log('commands:')
console.log(' vue-i18n-services export > translations.json')
console.log(' Collects all the <i18n> tags in SCF .vue files and exports them in a file\n')
console.log(' Flags:')
console.log(' --dir=src/ Specify the directory where SFCs are located, defaults to src/\n')
console.log(' vue-i18n-services import < translations.json')
console.log(' Distributes all the changes on translations.json file to the related components\n')
console.log(' vue-i18n-services translate')
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"dependencies": {
"glob": "^7.1.3",
"myjson-api": "^1.0.1",
"vue-template-compiler": "^2.5.17"
"vue-template-compiler": "^2.5.17",
"yargs": "^12.0.2"
}
}
Loading