|
| 1 | +/** |
| 2 | + * This file uses the test project at test/typings-test to validate |
| 3 | + * that AngularFire typings don't produce errors in user code. |
| 4 | + * |
| 5 | + * 1. Create a temp directory to copy the test project |
| 6 | + * 2. Create a package.json based on test-project/package.sample.json, |
| 7 | + * using versions from the project's root package.json. |
| 8 | + * 3. NPM install inside the temporary project directory |
| 9 | + * 4. Run TSC against the project's local tsconfig.json and local node_modules |
| 10 | + * 5. |
| 11 | + */ |
| 12 | +const fs = require('fs'); |
| 13 | +const path = require('path'); |
| 14 | +const ncp = require('ncp'); |
| 15 | +const rimraf = require('rimraf'); |
| 16 | +const child_process = require('child_process'); |
| 17 | +const pathToTestSrcFolder = path.resolve(__dirname, '../test/typings-test/'); |
| 18 | +const binaryPath = path.resolve(__dirname, '../node_modules/.bin') |
| 19 | +const rootPackage = require(path.resolve(__dirname, '../package.json')); |
| 20 | + |
| 21 | +const startingCwd = process.cwd(); |
| 22 | + |
| 23 | +const pathToTestFolder = fs.mkdtempSync('/tmp/typings-test-'); |
| 24 | + |
| 25 | +process.chdir(pathToTestFolder) |
| 26 | + |
| 27 | +ncp(pathToTestSrcFolder, pathToTestFolder, () => { |
| 28 | + const samplePackage = require(`${pathToTestFolder}/package.sample.json`); |
| 29 | + |
| 30 | + fs.writeFileSync(`${pathToTestFolder}/package.json`, JSON.stringify(samplePackage, null, 2) |
| 31 | + .replace('{{ANGULARFIRE_VERSION}}', path.resolve(__dirname, '../dist')) |
| 32 | + .replace('{{FIREBASE_VERSION}}', rootPackage.dependencies.firebase) |
| 33 | + .replace('{{RXJS_VERSION}}', rootPackage.dependencies.rxjs) |
| 34 | + .replace('{{ZONE_VERSION}}', rootPackage.devDependencies['zone.js']) |
| 35 | + .replace('{{TYPESCRIPT_VERSION}}', rootPackage.devDependencies.typescript) |
| 36 | + .replace(/\{\{ANGULAR_VERSION\}\}/g, rootPackage.dependencies['@angular/core'])); |
| 37 | + |
| 38 | + spawnIt('npm', ['install']) |
| 39 | + .then(_ => spawnIt(`${pathToTestFolder}/node_modules/.bin/tsc`, ['--version'])) |
| 40 | + .then(_ => new Promise((res, rej) => { |
| 41 | + child_process.exec(`${pathToTestFolder}/node_modules/.bin/tsc --diagnostics -p ${pathToTestFolder}/tsconfig.json`, (err, stdout, stderr) => { |
| 42 | + console.log(stdout); |
| 43 | + if (err) { |
| 44 | + rej(1); |
| 45 | + } else { |
| 46 | + res(); |
| 47 | + } |
| 48 | + }); |
| 49 | + })) |
| 50 | + .catch(_ => { |
| 51 | + // resolve with exit code 1 |
| 52 | + return Promise.resolve(1) |
| 53 | + }) |
| 54 | + .then(cleanup) |
| 55 | + .then(code => process.exit(code || 0)); |
| 56 | +}) |
| 57 | + |
| 58 | +function spawnIt(program, args) { |
| 59 | + console.log('-----------------------------------'); |
| 60 | + console.log(program, (args && args.join(' ')) || ''); |
| 61 | + console.log('-----------------------------------'); |
| 62 | + return new Promise((res, rej) => { |
| 63 | + child_process.spawn(program, args, { |
| 64 | + cwd: pathToTestFolder, |
| 65 | + stdio: 'inherit' |
| 66 | + }) |
| 67 | + .on('close', (code) => { |
| 68 | + if (code) return rej(code); |
| 69 | + res(); |
| 70 | + }) |
| 71 | + }); |
| 72 | +} |
| 73 | + |
| 74 | +function cleanup (val) { |
| 75 | + rimraf.sync(pathToTestFolder); |
| 76 | + return val; |
| 77 | +} |
0 commit comments