ngx-i18n-combine
Version:
Merge i18n files from components and merge to common locale files
76 lines • 2.86 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Combine = void 0;
const picocolors_1 = __importDefault(require("picocolors"));
const glob = __importStar(require("glob"));
const fs = __importStar(require("fs"));
const root = __importStar(require("app-root-path"));
const path = __importStar(require("path"));
class Combine {
constructor(options, parser, compiller) {
this.options = options;
this.parser = parser;
this.compiller = compiller;
this.locales = {};
}
run() {
this.locales = this.parser.parse() || {};
if (Object.keys(this.locales).length) {
this.compiller.compile(this.locales);
if (this.options.watch) {
this.watch();
}
}
}
watch() {
this.options.input.forEach((filesPath) => {
const files = this.getFiles(filesPath);
if (!files.length) {
this.log(picocolors_1.default.red(picocolors_1.default.bold('ERROR: files not found')));
}
else {
files.forEach((file) => {
fs.watchFile(file, () => {
console.log('File Changed ...');
console.log(`File content at: ${new Date()} is \n ${file}`);
this.run();
});
});
}
});
}
getFiles(filePath) {
const pattern = '/**/*.json';
const fileName = !!(path.extname(filePath));
const pathWp = fileName ? filePath : filePath + pattern;
return glob.sync(pathWp, { root: root.path })
.filter(file => fs.statSync(file).isFile());
}
log(...args) {
console.log.apply(this, args);
}
}
exports.Combine = Combine;
//# sourceMappingURL=combine.class.js.map