File base.js changed (mode: 100644) (index 45af94f..2775b7a) |
... |
... |
const shell = require("shelljs"), |
4 |
4 |
ansi = require("ansi"), |
ansi = require("ansi"), |
5 |
5 |
cursor = ansi(process.stdout), |
cursor = ansi(process.stdout), |
6 |
6 |
homedir = require("os").homedir(), |
homedir = require("os").homedir(), |
7 |
|
bashPath = path.join(homedir, ".bashrc"), |
|
|
7 |
|
rcPath = getRCFilePath(), |
8 |
8 |
exec = shell.exec, |
exec = shell.exec, |
9 |
9 |
{ COPYFILE_EXCL } = fs.constants; |
{ COPYFILE_EXCL } = fs.constants; |
10 |
10 |
|
|
|
11 |
|
function getRCFilePath() { |
|
12 |
|
try { |
|
13 |
|
fs.accessSync(path.join(homedir, ".zshrc")); |
|
14 |
|
return ".zshrc"; |
|
15 |
|
} catch (err) { |
|
16 |
|
try { |
|
17 |
|
fs.accessSync(path.join(homedir, ".bashrc")); |
|
18 |
|
return ".bashrc"; |
|
19 |
|
} catch (err) { |
|
20 |
|
console.error("No bash file found"); |
|
21 |
|
throw err; |
|
22 |
|
} |
|
23 |
|
} |
|
24 |
|
} |
|
25 |
|
|
11 |
26 |
function cloneRepo(url, dest) { |
function cloneRepo(url, dest) { |
12 |
27 |
return exec(`git clone ${url} --depth=1 --single-branch ${dest}`); |
return exec(`git clone ${url} --depth=1 --single-branch ${dest}`); |
13 |
28 |
} |
} |
|
... |
... |
function installFile(fileName) { |
31 |
46 |
|
|
32 |
47 |
function sourceOnSession(scriptName) { |
function sourceOnSession(scriptName) { |
33 |
48 |
const scriptPath = path.join(__dirname, scriptName); |
const scriptPath = path.join(__dirname, scriptName); |
34 |
|
let bashRC = fs.readFileSync(bashPath, "utf8"); |
|
|
49 |
|
let bashRC = fs.readFileSync(rcPath, "utf8"); |
35 |
50 |
if (!bashRC.match(scriptName)) { |
if (!bashRC.match(scriptName)) { |
36 |
51 |
console.log(`installing ${scriptName}`); |
console.log(`installing ${scriptName}`); |
37 |
52 |
bashRC += `\n. ${scriptPath}`; |
bashRC += `\n. ${scriptPath}`; |
38 |
|
fs.writeFileSync(bashPath, bashRC); |
|
|
53 |
|
fs.writeFileSync(rcPath, bashRC); |
39 |
54 |
} else { |
} else { |
40 |
55 |
console.log(`${scriptName} already installed`); |
console.log(`${scriptName} already installed`); |
41 |
56 |
} |
} |
File pre-commit.js changed (mode: 100755) (index fd74a26..feded20) |
2 |
2 |
|
|
3 |
3 |
const shellExec = require("shelljs").exec, |
const shellExec = require("shelljs").exec, |
4 |
4 |
fs = require("fs"), |
fs = require("fs"), |
5 |
|
path = require( 'path' ), |
|
|
5 |
|
path = require("path"), |
6 |
6 |
{ tryAndRunScript, print } = require("./base"), |
{ tryAndRunScript, print } = require("./base"), |
7 |
7 |
exec = function (cmd) { |
exec = function (cmd) { |
8 |
|
print(cmd); |
|
9 |
8 |
return shellExec(cmd); |
return shellExec(cmd); |
10 |
9 |
}; |
}; |
11 |
10 |
|
|
12 |
|
print(__filename); |
|
13 |
|
const stagedFiles = shellExec(`git diff --staged --name-only`, { |
|
14 |
|
silent: true, |
|
15 |
|
}).stdout.split("\n"), |
|
16 |
|
hasChanges = stagedFiles.length > 1; |
|
17 |
|
if (hasChanges) { |
|
18 |
|
exec("git stash --keep-index -q"); |
|
19 |
|
} |
|
|
11 |
|
exec(`git stash push --keep-index`); |
|
12 |
|
|
20 |
13 |
for (const step of ["test.js"]) { |
for (const step of ["test.js"]) { |
21 |
14 |
if (!tryAndRunScript(path.join(process.cwd(), step))) { |
if (!tryAndRunScript(path.join(process.cwd(), step))) { |
22 |
15 |
break; |
break; |
23 |
16 |
} |
} |
24 |
17 |
} |
} |
25 |
|
if (hasChanges) { |
|
26 |
|
exec("git stash pop -q"); |
|
27 |
|
} |
|
|
18 |
|
|
|
19 |
|
exec("git stash pop"); |