Skip to content

Instantly share code, notes, and snippets.

@andrewn
Last active January 10, 2016 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewn/1715ae53ef8dc36ad5d2 to your computer and use it in GitHub Desktop.
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
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