File size: 1,100 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
const { promises: fs, constants: fsConstants } = require( 'fs' );
const os = require( 'os' );
const path = require( 'path' );

const getShellRc = () => {
	if ( ! process.env.SHELL ) {
		return null;
	}

	if ( process.env.SHELL.match( /zsh/ ) ) {
		return path.join( process.env.HOME, '.zshrc' );
	}
	return path.join( process.env.HOME, '.bashrc' );
};

const getNpmRc = () => path.join( process.env.HOME, '.npmrc' );

const getMemInMb = () => Math.round( os.totalmem() / 1024 / 1024 );

const getDockerSettings = () =>
	path.join( process.env.HOME, 'Library/Group Containers/group.com.docker/settings.json' );

const isDockerInstalled = async () => {
	try {
		await fs.access( getDockerSettings(), fsConstants.R_OK );
		return true;
	} catch {
		return false;
	}
};

const getDockerConfig = async () => {
	try {
		const content = await fs.readFile( getDockerSettings(), 'utf8' );
		return JSON.parse( content );
	} catch ( err ) {
		throw new Error( `Can't load Docker config, ${ err.stack }` );
	}
};

module.exports = {
	getShellRc,
	getNpmRc,
	getMemInMb,
	getDockerConfig,
	isDockerInstalled,
};