Skip to content
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
5 changes: 2 additions & 3 deletions bin/easy-i18n-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ const { version } = require('../package');
program
.option('-v, --version')
.option('--check', 'check locale file')
.option('-c, --config <string>', 'config file path');

program.parse();
.option('-c, --config <string>', 'config file path')
.parse();

const options = program.opts();

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "easy-i18n-cli",
"version": "1.2.4",
"version": "2.0.0",
"description": "easy-i18n-cli",
"keywords": [
"i18n"
Expand Down
19 changes: 10 additions & 9 deletions src/easy-i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require('path');
const chalk = require('chalk');
const globby = require('globby');
const { promises: fs } = require('fs');
const originFs = require('fs');
const { sync: mkdirp } = require('mkdirp');

const defaultOptions = {
Expand Down Expand Up @@ -70,14 +71,13 @@ class EasyI18n {
this.infoLog('output file: %s', options.distFile);
}

async resolveDir() {
resolveDirSync() {
const { options } = this;
mkdirp(options.distDir);
const list = globby
return globby
.sync(options.srcDirs, { cwd: options.cwd })
.map(filePath => path.resolve(options.cwd, filePath))
.map(filePath => this.resolveFile(filePath));
await Promise.all(list);
.map(filePath => this.resolveFileSync(filePath));
}

sortKey(data) {
Expand Down Expand Up @@ -131,23 +131,25 @@ class EasyI18n {
return res;
}

async resolveFile(filePath) {
const content = await fs.readFile(filePath, 'utf-8');
resolveFileSync(filePath) {
const content = originFs.readFileSync(filePath, 'utf-8');
const res = this.getI18nTokens(content);

this.currentData = {
...this.currentData,
...res,
};
}

async initData() {
initData() {
const { distFile } = this.options;
try {
const data = require(distFile);
this.existedData = data.default || data;
} catch (e) {
console.error(e);
}
this.resolveDirSync();
}

async run(options = {}) {
Expand All @@ -156,8 +158,7 @@ class EasyI18n {
...options,
};
this.debugLog('options:\n%s\n', JSON.stringify(this.options, null, 2));
await this.initData();
await this.resolveDir();
this.initData();
await this.output();
}

Expand Down