Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { execSync } from 'child_process';
- import { join } from 'path';
- import { readFileSync, writeFileSync } from 'fs';
- import * as sassExtract from 'sass-extract';
- const materilPalettePath = './src/modules/common/style/angular-material';
- const warnColor = '#ed1c24';
- sassExtract.render({
- file: `./src/modules/common/style/colors.scss`,
- }).then(rendered => {
- generatePaletteFile(rendered.vars.global.$mainColor.value.hex, materilPalettePath, 'primary.scss');
- replaceInFile(
- join(materilPalettePath, 'primary.scss'),
- '$palette',
- '$primaryPalette'
- );
- const primaryColorHex: number = parseInt(rendered.vars.global.$mainColor.value.hex.replace('#', ''), 16);
- const whiteColorHex: number = 0xffffff;
- const accentColorHexStr: string = `#${convertRgbaToHex(primaryColorHex, 0.5, whiteColorHex)}`;
- generatePaletteFile(accentColorHexStr, materilPalettePath, 'accent.scss');
- replaceInFile(
- join(materilPalettePath, 'accent.scss'),
- '$palette',
- '$accentPalette'
- );
- generatePaletteFile(warnColor, materilPalettePath, 'warn.scss');
- replaceInFile(
- join(materilPalettePath, 'warn.scss'),
- '$palette',
- '$warnPalette'
- );
- });
- function generatePaletteFile(color: string, path: string, filename: string) {
- execSync(`material-palette-generator -c '${color}' --format material2 -d ${path} --file-name ${filename}`, {
- maxBuffer: 1024 * 1024,
- encoding: 'utf8',
- stdio: 'inherit'
- });
- }
- function replaceInFile(path: string, searchValue: string | RegExp, replaceValue: string) {
- let fileStr = readFileSync(path, 'utf8');
- fileStr = fileStr.replace(searchValue, replaceValue);
- writeFileSync(path, fileStr, 'utf8');
- }
- function convertRgbaToHex(color: number, alpha: number, backgroundColor: number): string {
- return (color * alpha + backgroundColor * (1 - alpha)).toString(16);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement