Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add script to build offline installer
- Loading branch information
Showing
2 changed files
with
74 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env node | ||
|
||
/* | ||
* bundle-offline-installer.js | ||
* | ||
* Copyright (C) 2009-13 by RStudio, Inc. | ||
* | ||
* This program is licensed to you under the terms of version 3 of the | ||
* GNU Affero General Public License. This program is distributed WITHOUT | ||
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT, | ||
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the | ||
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details. | ||
* | ||
*/ | ||
|
||
var fs = require('fs'); | ||
var path = require('path'); | ||
var child_process = require('child_process'); | ||
|
||
var packageJson = path.join(__dirname, '../package.json'); | ||
var packageJsonContents = fs.readFileSync(packageJson, 'utf-8') | ||
var package = JSON.parse(packageJsonContents); | ||
var deps = package.dependencies; | ||
var depnames = []; | ||
for (dep in deps) { | ||
if (deps.hasOwnProperty(dep)) | ||
depnames.push(dep); | ||
} | ||
|
||
package.bundledDependencies = depnames; | ||
|
||
var contents = JSON.stringify(package, null, ' '); | ||
|
||
fs.writeFileSync(packageJson, contents, 'utf-8'); | ||
function restoreContents() { | ||
fs.writeFileSync(packageJson, packageJsonContents, 'utf-8'); | ||
} | ||
process.on('exit', function() { | ||
restoreContents(); | ||
}); | ||
process.on('uncaughtException', function(err) { | ||
restoreContents(); | ||
console.log('ERROR: ' + err.message); | ||
process.exit(1); | ||
}); | ||
|
||
var cp = child_process.spawn( | ||
'sh', | ||
['-c', 'npm install && echo Building package... && npm pack'], | ||
{ | ||
cwd: path.join(__dirname, '..'), | ||
stdio: 'inherit' | ||
} | ||
); | ||
|
||
cp.on('exit', function(code) { | ||
if (code) { | ||
process.stderr.write('Bundling failed!\n'); | ||
process.exit(code); | ||
} else { | ||
var filename = 'shiny-server-' + package.version + '.tgz'; | ||
|
||
console.log('\n'); | ||
console.log('Your package has been built. To install, call this command as root or sudo:'); | ||
console.log(' npm install --no-registry -g ' + filename); | ||
console.log('\n'); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters