Skip to content

Commit 29fc36a

Browse files
committed
Adds build-utilities in separated files
1 parent e88609f commit 29fc36a

File tree

6 files changed

+75
-1
lines changed

6 files changed

+75
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ jspm_packages
3737
.node_repl_history
3838

3939
.idea
40-
40+
build-utilities/compiled
4141
dist/
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import path from 'path';
2+
import argv from 'yargs';
3+
import listFile from './listFilesIntoDirectoryRecursively';
4+
5+
const args = argv
6+
.usage('Usage: $0 --data [file]')
7+
.option('config', {
8+
type: 'string',
9+
describe: 'JSON/JavaScript data file',
10+
requiresArg: true
11+
})
12+
.argv;
13+
14+
const list = listFile(args.data, true)
15+
.filter(element => path.extname(element) === '.svg');
16+
17+
process.stdout.write(JSON.stringify(list));
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sass from 'node-sass';
2+
import hexToRgb from './hexToRgb';
3+
4+
const getPaletteFromSass = palettes => name => {
5+
// Get the variable name from sass function (when it is invoked)
6+
// Take the palette with the given name from object palettes
7+
const palette = palettes[name.getValue()];
8+
// Get all key from the palette
9+
const keys = Object.keys(palette);
10+
// Create a sass Map object
11+
const map = sass.types.Map(keys.length);
12+
// Get the Sass Color class
13+
const ColorClass = sass.types.Color;
14+
// Iterate every key
15+
let convertedColor;
16+
keys.forEach((key, i) => {
17+
// Convert the value of the given key on the object palette into rgb format
18+
convertedColor = hexToRgb(palette[key]);
19+
// Set the key value in the sass Map
20+
map.setKey(i, sass.types.String(key));
21+
map.setValue(i, new ColorClass(convertedColor.r, convertedColor.g, convertedColor.b));
22+
});
23+
return map;
24+
};
25+
26+
module.exports = getPaletteFromSass;

build-utilities/src/hexToRgb.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const hexToRgb = hex => {
2+
if (typeof hex !== 'string') throw new TypeError('Expected a string');
3+
hex = hex.replace(/^#/, '');
4+
if (hex.length === 3) hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
5+
const num = parseInt(hex, 16);
6+
return { r: num >> 16, g: num >> 8 & 255, b: num & 255};
7+
};
8+
module.exports = hexToRgb;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import fs from'fs';
2+
import path from 'path';
3+
4+
const walkSync = (dir, onlyName = false, filelist = []) => {
5+
fs.readdirSync(dir).forEach(file => {
6+
filelist = fs.statSync(path.join(dir, file)).isDirectory()
7+
? walkSync(path.join(dir, file), onlyName, filelist)
8+
: filelist.concat(onlyName ? file : path.join(dir, file));
9+
});
10+
return filelist;
11+
};
12+
module.exports = walkSync;

build-utilities/src/typography.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sass from 'node-sass';
2+
import sassUtilsLib from 'node-sass-utils';
3+
const sassUtils = sassUtilsLib(sass);
4+
5+
const getTypography = typography => () => sassUtils.castToSass(typography);
6+
const getType = typography => name => sassUtils.castToSass(typography[name.getValue()]);
7+
8+
module.exports = {
9+
getType,
10+
getTypography
11+
};

0 commit comments

Comments
 (0)