-
Notifications
You must be signed in to change notification settings - Fork 104
/
Copy pathindex.js
119 lines (98 loc) · 4.45 KB
/
index.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
module.exports = function (dest, options) {
try {
let root = __dirname;
let fs = require('fs');
let defaults = require('./system/defaults/settings.js');
let innerMerge = {
container: true,
breakPoints: false,
mixinNames: true
};
if (typeof options !== "object") {
options = defaults;
} else {
for (let key in defaults) {
if (typeof (options[key]) === "undefined") {
options[key] = defaults[key];
}
else if (typeof options[key] === "object" && innerMerge[key]) {
for (let k in defaults[key]) {
if (typeof (options[key][k]) === "undefined") {
options[key][k] = defaults[key][k];
}
}
}
}
}
let orderedBreakPointsArr = [];
let i = 0;
let sameUnits= true;
for(let name in options.breakPoints){
let tmp = {name: name};
tmp.point = options.breakPoints[name];
orderedBreakPointsArr.push(tmp);
if(i > 0){
let u1 = orderedBreakPointsArr[i].point.width.replace(/\d(.\d)*/g, '');
let u2 = orderedBreakPointsArr[i - 1].point.width.replace(/\d(.\d)*/g, '');
if(u1 !== u2){
console.log('Notice: we can`t to order breakPoints with different width units!');
sameUnits = false;
orderedBreakPointsArr = [];
break;
}
}
i++;
}
if(sameUnits){
orderedBreakPointsArr.sort(function(a, b){
let w1 = parseFloat(a.point.width);
let w2 = parseFloat(b.point.width);
if(w1 > w2){
return options.mobileFirst ? 1 : -1;
}
else if(w1 < w2){
return options.mobileFirst ? -1 : 1;
}
});
/* перезаписать options.breakPoints */
let points = {};
for(let i = 0; i < orderedBreakPointsArr.length; i++){
points[orderedBreakPointsArr[i].name] = orderedBreakPointsArr[i].point;
}
options.breakPoints = points;
}
let patterns = {};
patterns.mixin = fs.readFileSync(root + '/system/patterns/mixin');
patterns.clearfix = fs.readFileSync(root + '/system/patterns/clearfix');
patterns.reset = fs.readFileSync(root + '/system/patterns/reset');
patterns.fromTo = fs.readFileSync(root + '/system/patterns/fromTo');
let patternDebug = fs.readFileSync(root + '/system/patterns/debug');
let sizeCalling = ['(1)'];
for(let name in options.breakPoints){
if(options.breakPoints[name].offset !== undefined){
sizeCalling.push(`-${name}(1)`);
}
}
for(let i = 0; i < sizeCalling.length; i++){
sizeCalling[i] = '{{tab}}{{tab}}{{tab}}{{tab}}{{call}}' + options.mixinNames.size + sizeCalling[i] + '{{;}}';
}
patterns.debug = patternDebug.toString()
.replace('{{sizes}}', sizeCalling.join('\n'), 'g')
.replace('{{mixinNames.container}}', options.mixinNames.container, 'g')
.replace('{{mixinNames.row-flex}}', options.mixinNames.row, 'g')
.replace('{{mixinNames.col}}', options.mixinNames.column, 'g');
let build = require('./build.js');
let res = build(options, patterns);
if (dest === undefined) {
console.log('It`s test mode, because you don`t set destination folder');
} else {
let buildFile = dest + '/' + options.filename + '.' + res.type;
fs.writeFileSync(buildFile, res.grid);
console.log('Grid placed into ' + buildFile);
}
console.log('Grid length is ' + res.grid.length + ' :)');
console.log("Its work! Good day!");
} catch (err) {
console.log("Oops -> " + err.stack);
}
}