|
| 1 | +import * as fs from 'fs'; |
| 2 | +import * as path from 'path'; |
| 3 | + |
| 4 | +const repoRoot = process.env.RepoRoot; |
| 5 | +if (!repoRoot) { |
| 6 | + throw new Error('RepoRoot environment variable is not set') |
| 7 | +} |
| 8 | + |
| 9 | +// Search all the folders in the src directory for the files "jquery.validate.js" and "jquery.validate.min.js" but skip this |
| 10 | +// folder as well as the "node_modules" folder, the "bin" folder, and the "obj" folder. Recurse over subfolders. |
| 11 | + |
| 12 | +const srcDir = path.join(repoRoot, 'src'); |
| 13 | +const files = []; |
| 14 | +const search = (dir) => { |
| 15 | + const entries = fs.readdirSync(dir, { withFileTypes: true }); |
| 16 | + for (const entry of entries) { |
| 17 | + if (entry.isDirectory() && entry.name !== 'node_modules' && entry.name !== 'bin' && entry.name !== 'obj') { |
| 18 | + search(path.join(dir, entry.name)); |
| 19 | + } else if (entry.isFile() && (entry.name === 'jquery.validate.js' || entry.name === 'jquery.validate.min.js')) { |
| 20 | + files.push(path.join(dir, entry.name)); |
| 21 | + } |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +search(srcDir); |
| 26 | + |
| 27 | +// Replace the files found with the versions from <<current-folder>>/node_modules/jquery-validation/dist. |
| 28 | +// Note that <<current-folder>>/node_modules/jquery-validation/dist/jquery.validate.js needs to override the |
| 29 | +// jquery.validate.js file found in the files array and the same for jquery.validate.min.js. |
| 30 | +const nodeModulesDir = path.join(import.meta.dirname, 'node_modules', 'jquery-validation', 'dist'); |
| 31 | + |
| 32 | +for (const file of files) { |
| 33 | + const source = path.join(nodeModulesDir, path.basename(file)); |
| 34 | + const target = file; |
| 35 | + fs.copyFileSync(source, target); |
| 36 | + console.log(`Copied ${path.basename(file)} to ${target}`); |
| 37 | +} |
0 commit comments