-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.js
More file actions
75 lines (65 loc) · 2.16 KB
/
setup.js
File metadata and controls
75 lines (65 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Bash Installer
* Install the bash files for those who
* do not already know how to configure their own bash files.
*/
const winSep = new RegExp(/\\/g);
const dedupeSep = new RegExp(/\/\//g);
const posixSep = '/';
const path = require('path');
const osType = require('os').type();
const shell = require('shelljs');
const now = Date.now();
shell.config.silent = true;
const home = {
// eslint-disable-next-line no-process-env
user: process.env.HOME
.replace(winSep, posixSep)
.replace(dedupeSep, posixSep)
, projects: path
// devroot derived from parent folder of this repo
.dirname(process.cwd())
.replace(winSep, posixSep)
.replace(dedupeSep, posixSep)
, tools: process.cwd()
.replace(winSep, posixSep)
.replace(dedupeSep, posixSep)
};
const bash = {
tools: `${home.tools}/dev-tools/src/bash.sh`
, home: `${home.user}/.bashrc`
};
const profile = {
home: `${home.user}/.bash_profile`
};
const login = {
home: `${home.user}/.bash_login`
};
if(!shell.which('bash')) {
process.stdout.write('Sorry, this script requires Bash shell\n');
process.exitCode = 1;
throw new Error('no bash');
}
shell.config.shell = shell.which('bash');
// bashrc
shell.mv(bash.home, `${bash.home}_dev_tools_${now}.bak`);
shell.touch(bash.home);
shell.echo('echo \'loading ~/.bashrc\'\n').toEnd(bash.home);
shell.echo('\n# dev-tools - start').toEnd(bash.home);
shell.echo(`export DEVROOT='${home.projects}'`).toEnd(bash.home);
shell.echo(`source '${bash.tools}'`).toEnd(bash.home);
shell.echo('# dev-tools - end\n').toEnd(bash.home);
shell.echo('\n# Personal additions and over-rides\n').toEnd(bash.home);
// Over-ride some settings based on OS
if(osType === 'Darwin') {
shell.echo('unalias find').toEnd(bash.home);
}
// bash_profile
shell.mv(profile.home, `${profile.home}_dev_tools_${now}.bak`);
shell.touch(profile.home);
shell.echo(`source ${bash.home}`).toEnd(profile.home);
// bash_login
shell.mv(login.home, `${login.home}_dev_tools_${now}.bak`);
shell.touch(login.home);
shell.echo(`source ${bash.home}`).toEnd(login.home);
shell.echo('Done - open new shell. You should see a new command prompt');