Skip to content

Commit 1dd9593

Browse files
committed
create directory when not exists
1 parent 052d311 commit 1dd9593

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

index.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const VirtualModulePlugin = require('virtual-module-webpack-plugin');
1010
const readFile = util.promisify(fs.readFile);
1111
const unlink = util.promisify(fs.unlink);
1212
const stat = util.promisify(fs.stat);
13+
const mkdir = util.promisify(fs.mkdir);
1314

1415
async function exists(path: fs.PathLike) {
1516
try {
@@ -191,10 +192,20 @@ export default class I18nextPlugin {
191192
));
192193
try {
193194
// write missing
194-
await Promise.all(_.map(this.missingKeys, async (namespaces, lng) =>
195-
_.map(namespaces, async (keys, ns) => new Promise<void>(resolve => {
195+
await Promise.all(_.map(this.missingKeys, async (namespaces, lng) => {
196+
const resourceTemplate = path.join(this.context, getPath(this.option.pathToSaveMissing, lng));
197+
const resourceDir = path.dirname(resourceTemplate);
198+
try {
199+
await mkdir(resourceDir);
200+
} catch (e) {
201+
if (e.code !== 'EEXIST') {
202+
throw e;
203+
}
204+
}
205+
206+
return _.map(namespaces, async (keys, ns) => new Promise<void>(resolve => {
196207
delete remains[lng][ns];
197-
const missingPath = path.join(this.context, getPath(this.option.pathToSaveMissing, lng, ns));
208+
const missingPath = getPath(resourceTemplate, undefined, ns);
198209
const stream = fs.createWriteStream(missingPath, {
199210
defaultEncoding: "utf-8"
200211
});
@@ -206,8 +217,8 @@ export default class I18nextPlugin {
206217
stream.on("close", () => resolve());
207218

208219
compilation.warnings.push(`missing translation ${keys.length} keys in ${lng}/${ns}`);
209-
}))
210-
));
220+
}));
221+
}));
211222
// remove previous missings
212223
await Promise.all(_.map(remains, async (namespaces, lng) =>
213224
_.map(namespaces, async (__, ns) => {

0 commit comments

Comments
 (0)