Last active
January 10, 2016 12:47
-
-
Save andrewn/1715ae53ef8dc36ad5d2 to your computer and use it in GitHub Desktop.
Simple script to install your projects esformatter plugins in the atom-esformatter package
This file contains hidden or 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
var fs = require('fs'); | |
var path = require('path'); | |
var spawn = require('child_process').spawn; | |
var esformatterPath = process.argv[2]; | |
var homeDir = (process.platform === 'win32') ? process.env.HOMEPATH : process.env.HOME; | |
var atomPackagePath = path.join(homeDir, '.atom', 'packages', 'esformatter'); | |
var config; | |
var plugins; | |
var cmd; | |
console.log('esformatterPath', esformatterPath); | |
console.log('atomPackagePath', atomPackagePath); | |
try { | |
config = JSON.parse(fs.readFileSync(esformatterPath)); | |
} catch (e) { | |
console.error('Path to .esformatter invalid or file contents are not JSON'); | |
process.exit(1); | |
} | |
plugins = config.plugins; | |
cmd = 'npm'; | |
args = ['install'].concat(plugins); | |
console.log('Run:'); | |
console.log('\tcwd : ', atomPackagePath); | |
console.log('\tcmd : ', cmd); | |
console.log('\targs: ', args); | |
npm = spawn(cmd, args, { | |
cwd: atomPackagePath | |
}); | |
npm.stdout.on('data', (data) => { | |
console.log('npm [out]: ', data.toString()); | |
}); | |
npm.stderr.on('data', (data) => { | |
console.log('npm [err]: ', data.toString()); | |
}); | |
npm.on('close', (code) => { | |
console.log('npm exited with code ' + code); | |
console.log('Done'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment