Skip to content

Commit 50317e3

Browse files
authored
feat: 2.x API refactor with sync (#16)
1 parent ba34858 commit 50317e3

3 files changed

Lines changed: 13 additions & 13 deletions

File tree

bin/easy-i18n-cli.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ const { version } = require('../package');
1111
program
1212
.option('-v, --version')
1313
.option('--check', 'check locale file')
14-
.option('-c, --config <string>', 'config file path');
15-
16-
program.parse();
14+
.option('-c, --config <string>', 'config file path')
15+
.parse();
1716

1817
const options = program.opts();
1918

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "easy-i18n-cli",
3-
"version": "1.2.4",
3+
"version": "2.0.0",
44
"description": "easy-i18n-cli",
55
"keywords": [
66
"i18n"

src/easy-i18n.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ const path = require('path');
55
const chalk = require('chalk');
66
const globby = require('globby');
77
const { promises: fs } = require('fs');
8+
const originFs = require('fs');
89
const { sync: mkdirp } = require('mkdirp');
910

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

73-
async resolveDir() {
74+
resolveDirSync() {
7475
const { options } = this;
7576
mkdirp(options.distDir);
76-
const list = globby
77+
return globby
7778
.sync(options.srcDirs, { cwd: options.cwd })
7879
.map(filePath => path.resolve(options.cwd, filePath))
79-
.map(filePath => this.resolveFile(filePath));
80-
await Promise.all(list);
80+
.map(filePath => this.resolveFileSync(filePath));
8181
}
8282

8383
sortKey(data) {
@@ -131,23 +131,25 @@ class EasyI18n {
131131
return res;
132132
}
133133

134-
async resolveFile(filePath) {
135-
const content = await fs.readFile(filePath, 'utf-8');
134+
resolveFileSync(filePath) {
135+
const content = originFs.readFileSync(filePath, 'utf-8');
136136
const res = this.getI18nTokens(content);
137+
137138
this.currentData = {
138139
...this.currentData,
139140
...res,
140141
};
141142
}
142143

143-
async initData() {
144+
initData() {
144145
const { distFile } = this.options;
145146
try {
146147
const data = require(distFile);
147148
this.existedData = data.default || data;
148149
} catch (e) {
149150
console.error(e);
150151
}
152+
this.resolveDirSync();
151153
}
152154

153155
async run(options = {}) {
@@ -156,8 +158,7 @@ class EasyI18n {
156158
...options,
157159
};
158160
this.debugLog('options:\n%s\n', JSON.stringify(this.options, null, 2));
159-
await this.initData();
160-
await this.resolveDir();
161+
this.initData();
161162
await this.output();
162163
}
163164

0 commit comments

Comments
 (0)