|
| 1 | +var _ = require('lodash'); |
| 2 | +var exec = require('child_process').execSync; |
| 3 | +var fs = require('fs'); |
| 4 | +var path = require('path'); |
| 5 | +const rimraf = require('rimraf'); |
| 6 | + |
| 7 | +let args = process.argv.length <= 2 ? [] : process.argv.slice(2, process.argv.length); |
| 8 | + |
| 9 | +/* |
| 10 | +This script rebuilds all frameworks from scratch, |
| 11 | +it deletes all package.json and package-lock.json files |
| 12 | +and invokes npm install and npm run build-prod for all benchmarks |
| 13 | +
|
| 14 | +If building a framework fails you can resume building like |
| 15 | +npm run rebuild-frameworks --restartWith keyed/react |
| 16 | +*/ |
| 17 | + |
| 18 | +// Use npm ci or npm install ? |
| 19 | +let ci = args.includes("--ci"); |
| 20 | +// Copy package-lock back for docker build or build locally? |
| 21 | +let docker = args.includes("--docker"); |
| 22 | +let restartBuildingWith = args.find(a => !a.startsWith("--")); |
| 23 | + |
| 24 | + |
| 25 | +var restartWithFramework = restartBuildingWith || ''; |
| 26 | +console.log("ARGS", "ci", ci, "docker", docker, "restartWith", restartWithFramework); |
| 27 | + |
| 28 | +var frameworks = [].concat( |
| 29 | + fs.readdirSync('./frameworks/keyed').map(f => ['keyed', f]), |
| 30 | + fs.readdirSync('./frameworks/non-keyed').map(f => ['non-keyed', f])); |
| 31 | + |
| 32 | +var notRestarter = ([dir, name]) => { |
| 33 | + if (!restartWithFramework) return false; |
| 34 | + if (restartWithFramework.indexOf("/")>-1) { |
| 35 | + return !(dir+"/"+name).startsWith(restartWithFramework); |
| 36 | + } else { |
| 37 | + return !name.startsWith(restartWithFramework); |
| 38 | + } |
| 39 | +}; |
| 40 | + |
| 41 | +let skippable = _.takeWhile(frameworks, notRestarter); |
| 42 | +let buildable = _.slice(frameworks, skippable.length); |
| 43 | + |
| 44 | +console.log("Building ", buildable); |
| 45 | + |
| 46 | + |
| 47 | +for (f of buildable) { |
| 48 | + console.log("BUILDING ", f); |
| 49 | + let [keyed,name] = f; |
| 50 | + let path = `frameworks/${keyed}/${name}`; |
| 51 | + if (!fs.existsSync(path+"/package.json")) { |
| 52 | + console.log("WARN: skipping ", f, " since there's no package.json"); |
| 53 | + } else { |
| 54 | + // if (fs.existsSync(path)) { |
| 55 | + // console.log("deleting folder ",path); |
| 56 | + // exec(`rm -r ${path}`); |
| 57 | + // } |
| 58 | + // rsync(keyed,name); |
| 59 | + let rm_cmd = `rm -rf ${ci ? '' : 'package-lock.json'} yarn.lock dist elm-stuff bower_components node_modules output` |
| 60 | + console.log(rm_cmd); |
| 61 | + exec(rm_cmd, { |
| 62 | + cwd: path, |
| 63 | + stdio: 'inherit' |
| 64 | + }); |
| 65 | + |
| 66 | + let install_cmd = `npm ${ci ? 'ci' : 'install'} && npm run build-prod`; |
| 67 | + console.log(install_cmd); |
| 68 | + exec(install_cmd, { |
| 69 | + cwd: path, |
| 70 | + stdio: 'inherit' |
| 71 | + }); |
| 72 | + |
| 73 | + if (docker) { |
| 74 | + let packageLockPath = path+"/package-lock.json"; |
| 75 | + fs.copyFileSync(packageLockPath, "/src/"+packageLockPath); |
| 76 | + } |
| 77 | + } |
| 78 | +} |
| 79 | + |
| 80 | +console.log("All frameworks were built!"); |
0 commit comments