|
| 1 | +const fs = require('fs'); |
| 2 | +const path = require('path'); |
| 3 | + |
| 4 | +let hasError = false; |
| 5 | +checkAll(); |
| 6 | +if (hasError) { |
| 7 | + process.exit(1); |
| 8 | +} else { |
| 9 | + console.error(`Everything's fine!`); |
| 10 | +} |
| 11 | + |
| 12 | +// checkPublicVariables('D:\\Codes\\jigsaw\\src\\jigsaw\\mobile-components\\alert\\alert.ts'); |
| 13 | + |
| 14 | +function checkAll(folder) { |
| 15 | + const cmpHome = path.resolve(`${__dirname}/../../src/jigsaw`); |
| 16 | + const cmpFolders = fs.readdirSync(cmpHome); |
| 17 | + cmpFolders.forEach(cmpFolder => { |
| 18 | + const pathname = path.join(cmpHome, cmpFolder); |
| 19 | + const stat = fs.lstatSync(pathname); |
| 20 | + if (stat.isDirectory()) { |
| 21 | + checkSourceFiles(pathname); |
| 22 | + } |
| 23 | + }); |
| 24 | +} |
| 25 | + |
| 26 | +function checkSourceFiles(sourceFolder) { |
| 27 | + const files = fs.readdirSync(sourceFolder); |
| 28 | + files.forEach(file => { |
| 29 | + const pathname = path.join(sourceFolder, file); |
| 30 | + const stat = fs.lstatSync(pathname); |
| 31 | + if (stat.isDirectory()) { |
| 32 | + checkSourceFiles(pathname) |
| 33 | + } else { |
| 34 | + checkPublicVariables(pathname); |
| 35 | + } |
| 36 | + }); |
| 37 | +} |
| 38 | + |
| 39 | +function checkPublicVariables(srcPath) { |
| 40 | + if (!srcPath.match(/.+\.ts$/i)) { |
| 41 | + return; |
| 42 | + } |
| 43 | + |
| 44 | + console.log(`Checking ${srcPath} ...`); |
| 45 | + const source = fs.readFileSync(srcPath).toString(); |
| 46 | + |
| 47 | + const vars = source.match(/\spublic\s+(static\s+)?_\$?\w+/g); |
| 48 | + if (!vars) { |
| 49 | + return; |
| 50 | + } |
| 51 | + |
| 52 | + vars.forEach(variable => { |
| 53 | + const fixed = variable.replace(/\$/g, '\\$'); |
| 54 | + const reg = new RegExp(`[\\s\\S]*\\/\\*\\*([\\s\\S]*?)\\*\\/\\s*(@\\w+.*\\s*)?${fixed}\\b`); |
| 55 | + const match = source.match(reg); |
| 56 | + if (!match || match[1].indexOf('@internal') === -1) { |
| 57 | + const name = variable.replace(/public\s*(static\s+)?/, '').trim(); |
| 58 | + error(`Error: variable "${name}" has no @internal flag!`); |
| 59 | + } |
| 60 | + }); |
| 61 | +} |
| 62 | + |
| 63 | +function error(msg) { |
| 64 | + console.error(msg); |
| 65 | + hasError = true; |
| 66 | +} |
| 67 | + |
| 68 | + |
0 commit comments