transpiler changes

This commit is contained in:
Yuri Kuznetsov
2023-06-14 15:28:06 +03:00
parent de42e7e4c1
commit db43fd3a12
3 changed files with 57 additions and 6 deletions

View File

@@ -26,11 +26,34 @@
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/
const Transpiler = require('../../js/transpiler');
const Transpiler = require('./transpiler/transpiler');
(new Transpiler({})).process();
let file;
(new Transpiler({
let fIndex = process.argv.findIndex(item => item === '-f');
if (fIndex > 0) {
file = process.argv.at(fIndex + 1);
if (!file) {
throw new Error(`No file specified.`);
}
}
const transpiler1 = new Transpiler({
file: file,
});
const transpiler2 = new Transpiler({
mod: 'crm',
path: 'client/modules/crm',
})).process();
file: file,
});
const result1 = transpiler1.process();
const result2 = transpiler2.process();
let count = result1.transpiled.length + result2.transpiled.length;
let copiedCount = result1.copied.length + result2.copied.length;
console.log(`\n transpiled: ${count}, copied: ${copiedCount}`)

View File

@@ -37,25 +37,53 @@ class Transpiler {
* path?: string,
* destDir?: string,
* mod?: string,
* file?: string,
* }} config
*/
constructor(config) {
this.path = (config.path ?? 'client') + '/src';
this.destDir = config.destDir || 'client/lib/transpiled';
this.mod = config.mod;
this.file = config.file;
this.contentsCache = {};
}
/**
* @return {{
* transpiled: string[],
* copied: string[],
* }}
*/
process() {
let allFiles = globSync(this.path + '/**/*.js')
.map(file => file.replaceAll('\\', '/'));
if (this.file) {
let file = this.file.replaceAll('\\', '/');
if (!allFiles.includes(file)) {
return {
transpiled: [],
copied: [],
};
}
allFiles = [file];
}
let files = allFiles.filter(file => this.#isToBeTranspiled(file));
let otherFiles = allFiles.filter(file => !files.includes(file));
let otherFiles = !this.file ?
allFiles.filter(file => !files.includes(file)) : [];
files.forEach(file => this.#processFile(file));
otherFiles.forEach(file => this.#copyFile(file));
return {
transpiled: files,
copied: otherFiles,
};
}
/**