forked from aruberto/react-foundation-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create-flex-components.js
52 lines (43 loc) · 1.64 KB
/
create-flex-components.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
/* eslint-disable no-console, strict */
'use strict';
const path = require('path');
const fs = require('fs-extra');
const s = require('underscore.string');
const createFlexSccsContent = (component) =>
`$global-flexbox: true;
@import '../${component}/styles';
`;
const FLEX_COMPONENTS = [
'button-group',
'forms',
'media-object',
'menu',
'title-bar',
'top-bar',
];
FLEX_COMPONENTS.forEach((component) => {
const directoryPath = path.join(__dirname, 'lib', component);
const indexPath = path.join(directoryPath, 'index.js');
const scssPath = path.join(directoryPath, '_styles.scss');
try {
fs.accessSync(indexPath, fs.F_OK);
fs.accessSync(scssPath, fs.F_OK);
} catch (e) {
// Not component directory
console.warn(`Skipping component ${component}!`);
return;
}
const flexDirectoryPath = path.join(__dirname, 'lib', `${component}-flex`);
const flexIndexPath = path.join(flexDirectoryPath, 'index.js');
const flexScssPath = path.join(flexDirectoryPath, '_styles.scss');
let flexIndexContent = s(fs.readFileSync(indexPath, 'utf8'));
FLEX_COMPONENTS.forEach((dependency) => {
flexIndexContent = flexIndexContent.replace(`'../${dependency}'`, `'../${dependency}-flex'`);
});
flexIndexContent = flexIndexContent.replace('\'../grid\'', '\'../grid-flex\'');
flexIndexContent = flexIndexContent.replace('\'../flex-mock\'', '\'../flex\'');
flexIndexContent = flexIndexContent.replace('IS_FLEX_MODE = false', 'IS_FLEX_MODE = true');
fs.ensureDirSync(flexDirectoryPath);
fs.writeFileSync(flexIndexPath, flexIndexContent.value(), 'utf8');
fs.writeFileSync(flexScssPath, createFlexSccsContent(component), 'utf8');
});