diff --git a/Gruntfile.js b/Gruntfile.js index 951340c1a2..6c425b91d8 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -303,7 +303,7 @@ module.exports = grunt => { }); grunt.registerTask('transpile', () => { - cp.execSync("node js/scripts/transpile"); + cp.execSync("node js/transpile"); }); grunt.registerTask('chmod-folders', () => { diff --git a/js/scripts/transpile.js b/js/transpile.js similarity index 68% rename from js/scripts/transpile.js rename to js/transpile.js index 2aff8b0c03..bcff3a7988 100644 --- a/js/scripts/transpile.js +++ b/js/transpile.js @@ -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}`) diff --git a/js/transpiler.js b/js/transpiler/transpiler.js similarity index 87% rename from js/transpiler.js rename to js/transpiler/transpiler.js index 869d0de1fb..9ecc7d9832 100644 --- a/js/transpiler.js +++ b/js/transpiler/transpiler.js @@ -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, + }; } /**