-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.js
71 lines (59 loc) · 1.62 KB
/
install.js
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
const shell = require('shelljs');
if (!shell.which('git')) {
shell.echo('Sorry, this script requires git');
shell.exit(1);
}
const path = require('path');
const pjson = require('./package.json');
const packageName = pjson.name;
const projectDir = process.cwd().replace(path.join('node_modules', packageName), '');
const tmpDirName = '.tmpdir';
const entryFileName = 'install.js';
const tmpDirPath = path.join(__dirname, tmpDirName);
const entryFilePath = path.join(__dirname, entryFileName);
function entry() {
// clearConsole();
cloneTemplate('default');
copyTemplate();
cleanTheMess();
final();
}
function clearConsole() {
// Clear console
process.stdout.write('\x1B[2J\x1B[0f');
}
function cloneTemplate(name) {
console.log(`Installing template...`);
if (shell.exec(`git clone https://github.com/ke-mantha/mantha-template-${name}.git ${tmpDirName} --quiet`).code !== 0) {
shell.echo('Error: Git template clone failed');
shell.exit(1);
}
console.log('');
}
function filesToCopy(list = []) {
const result = [];
list.forEach(el => {
result.push(path.join(tmpDirPath, el));
});
return result;
}
function copyTemplate(dest = projectDir) {
console.log(`Deploying template...`);
shell.cp('-Rf', filesToCopy([
'.*',
'*'
]), dest);
console.log('');
}
function cleanTheMess() {
console.log(`Cleaning the mess...`);
shell.rm('-rf', tmpDirPath);
shell.rm(entryFilePath);
console.log('');
}
function final() {
console.log('Installing environment...');
var child_process = require('child_process');
child_process.execSync(`cd ${projectDir} && npm i`, { stdio: [0, 1, 2] });
}
entry();