Skip to content

Commit

Permalink
Convert the postinstall script to .js for windows support
Browse files Browse the repository at this point in the history
  • Loading branch information
nevir committed Aug 1, 2017
1 parent 8fd59cc commit 400e45f
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 25 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package-lock.json
/output/
*.d.ts
*.js
!/scripts/*.js

# TypeScript
!/typings/**/*.d.ts
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Place your settings in this file to overwrite default and user settings.
{
"files.exclude": {
"**/*.js": true,
"**/*.js.map": true,
"**/.DS_Store": true,
"**/.git": true,
"**/.hg": true,
"**/.svn": true,
"**/CVS": true,
"{src,test}/**/*.d.ts": true,
"{src,test}/**/*.js": true,
"node_modules/": true,
"output/": true
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dev": "./scripts/dev.sh",
"fix:style": "./scripts/fix:style.sh",
"greenkeeper:lockfile": "./scripts/greenkeeper:lockfile.sh",
"postinstall": "./scripts/postinstall.sh",
"postinstall": "node ./scripts/postinstall.js",
"release": "./scripts/release.sh",
"test": "./scripts/test.sh",
"test:compile": "./scripts/test:compile.sh",
Expand All @@ -48,6 +48,7 @@
"greenkeeper-lockfile": "^1.7.2",
"jest": "^20.0.4",
"jest-junit": "^2.1.0",
"rimraf": "^2.6.1",
"typescript": "^2.4.2",
"typescript-eslint-parser": "eslint/typescript-eslint-parser#ts-2.4"
}
Expand Down
58 changes: 58 additions & 0 deletions scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#!/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';
// We set an environment flag to ensure that this script doesn't loop.
var compiling_var = 'compiling:' + process.env.npm_package_name;

// When installing directly from GitHub, we get the TypeScript source, but none
// of the compiled JavaScript.
function isCompiled() {
// It will be.
if (process.env[compiling_var]) return true;

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 (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.env[compiling_var] = 'true';
process.stdout.write('Compiling TypeScript sources… ');
childProcess.execSync(runner + ' install');
childProcess.execSync(runner + ' run compile');
process.stdout.write('done\n');

// Sneaky, but rimraf is included as a devDependency.
require('rimraf').sync(node_modules);

// Restore any production dependencies.
if (isDirectory(temp_modules)) {
fs.renameSync(temp_modules, node_modules);
}
23 changes: 0 additions & 23 deletions scripts/postinstall.sh

This file was deleted.

0 comments on commit 400e45f

Please sign in to comment.