This repository has been archived by the owner on Jan 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
postinstall.js
executable file
·81 lines (69 loc) · 2.34 KB
/
postinstall.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
72
73
74
75
76
77
78
79
80
81
var fs = require('fs'),
path = require('path');
const VENDORS = './src/scss/vendors';
const CONFIG = './config';
const DEV_CONFIG = CONFIG + '/gulp-dev-config';
const JSON = '.json';
const JS = '.js';
function createLink(link, name, isNotNode) {
var prefix = isNotNode ? '.' : './node_modules';
return {
source: prefix + '/' + link,
target: (isNotNode ? './node_modules' : VENDORS) + '/' + name,
type: 'dir',
name: name,
};
}
const LINKS = [
createLink('src/js', 'example', true),
createLink('react-dd-menu/src/scss', 'react-dd-menu'),
createLink('react-buttons/src/scss', 'react-buttons'),
createLink('font-awesome/scss', 'font-awesome'),
createLink('bootstrap-sass/assets/stylesheets', 'bootstrap'),
];
console.log('Creating symlinks for:\n%s\n', LINKS.map(function(link) { return link.name; }).join(', '));
LINKS.forEach(function(link) {
var source = path.resolve(link.source);
var target = path.resolve(link.target);
if(fs.existsSync(target) && fs.lstatSync(target).isSymbolicLink()) {
fs.unlinkSync(target);
}
try {
fs.symlinkSync(source, target, link.type);
} catch(e) {
if(e.code == 'EPERM') {
console.error('SYMLINK ERR! You must run this as administrator in Windows to create symlinks.');
console.error('SYMLINK ERR! Run \'npm install\' again once you open an admin terminal');
this.process.exit(1);
} else {
throw e;
}
}
});
console.log('Symlinks have been create successfully.');
/**
* Attempts to copy a src file to a dest file. If the file already exists,
* it does not copy.
*
* The file naming scheme was 'SomeFile.js.example', so if this changes, this function
* needs to be updated
*
* @param file the file
* @param fileEnding the file ending
* @param completedMsg the message to display when completed. Optional
*/
function attemptFileCopy(file, fileEnding, completedMsg) {
var srcFile = file + fileEnding + '.example';
var destFile = file + fileEnding;
if(fs.existsSync(destFile)) {
return;
}
fs.createReadStream(path.resolve(srcFile))
.pipe(fs.createWriteStream(destFile))
.on('error', function(err) {
console.error(err.message);
throw err;
});
completedMsg && console.log(completedMsg);
}
attemptFileCopy(DEV_CONFIG, JSON, "Your configuration file has been copied with the defaults as '" + DEV_CONFIG + JSON + "'");