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