pulsar/script/clean
Pritam Baral f5c3bdb845 Use os.tmpdir() on Linux
/tmp isn't always available, is on precious RAM-backed fs or simply not
what the user has set his $TMPDIR to. According to the specification, we
should use $TMPDIR, which node lets us find through os.tmpdir().

Also, contributing.md isn't in favour of using platform-dependent code.

This commit focusses only on Linux, and leaves OS X as is with /tmp for
discussion.
2014-05-19 23:57:48 +05:30

38 lines
1.2 KiB
JavaScript
Executable File

#!/usr/bin/env node
var cp = require('./utils/child-process-wrapper.js');
var path = require('path');
var os = require('os');
var removeCommand = process.platform === 'win32' ? 'del /F /Q /S ' : 'rm -rf ';
var productName = require('../package.json').productName;
process.chdir(path.dirname(__dirname));
var home = process.env[(process.platform === 'win32') ? 'USERPROFILE' : 'HOME'];
var tmpdir = process.platform !== 'darwin' ? os.tmpdir() : '/tmp';
// Windows: Use START as a way to ignore error if Atom.exe isnt running
var killatom = process.platform === 'win32' ? 'START taskkill /F /IM ' + productName + '.exe' : 'pkill -9 ' + productName + ' || true';
var commands = [
killatom,
[__dirname, '..', 'node_modules'],
[__dirname, '..', 'build', 'node_modules'],
[__dirname, '..', 'apm', 'node_modules'],
[__dirname, '..', 'atom-shell'],
[home, '.atom', '.node-gyp'],
[home, '.atom', 'storage'],
[home, '.atom', '.npm'],
[home, '.atom', 'compile-cache'],
[tmpdir, 'atom-build'],
[tmpdir, 'atom-cached-atom-shells'],
];
var run = function() {
var next = commands.shift();
if (!next)
process.exit(0);
if (Array.isArray(next))
next = removeCommand + path.resolve.apply(path.resolve, next);
cp.safeExec(next, run);
};
run();