-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathpostinstall.js
executable file
·51 lines (43 loc) · 1.43 KB
/
postinstall.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
#!/usr/bin/env node
/* eslint-disable */
var childProcess = require('child_process');
var fs = require('fs');
var path = require('path');
var node_modules = path.resolve(__dirname, '..', 'node_modules');
var temp_modules = node_modules + '.tmp';
var dev_modules = node_modules + '.dev';
// When installing directly from GitHub, we get the TypeScript source, but none
// of the compiled JavaScript.
function isCompiled() {
try {
return !!require.resolve('.');
} catch (error) {
return false;
}
}
function isDirectory() {
var fullPath = path.join.apply(path, arguments);
try {
return fs.statSync(fullPath).isDirectory();
} catch (error) {
return false;
}
}
// When installing directly from GitHub, we get the source, but none of the
// compiled JavaScript.
if (isDirectory(node_modules, 'typescript') || isCompiled()) return;
// Install our dev dependencies (aka TypeScript) into a sandbox, so that we can
// compile our code.
if (isDirectory(node_modules)) {
fs.renameSync(node_modules, temp_modules);
}
var runner = /yarn/i.test(process.env.npm_config_user_agent) ? 'yarn' : 'npm';
process.stdout.write('Compiling TypeScript sources… ');
childProcess.execSync(runner + ' install');
childProcess.execSync(runner + ' run compile');
process.stdout.write('done\n');
// Restore any production dependencies.
fs.renameSync(node_modules, dev_modules);
if (isDirectory(temp_modules)) {
fs.renameSync(temp_modules, node_modules);
}