|
3 | 3 | const del = require('del');
|
4 | 4 | const fs = require('fs-extra');
|
5 | 5 | const op = require('object-path');
|
6 |
| -const path = require('path'); |
| 6 | +const path = require('node:path'); |
7 | 7 | const globby = require('./globby-patch');
|
8 | 8 | const webpack = require('webpack');
|
9 | 9 | const browserSync = require('browser-sync');
|
@@ -529,15 +529,6 @@ $assets: map.set($assets, "{{key}}", "{{{dataURL}}}");
|
529 | 529 | const mappings = [];
|
530 | 530 | for (const entry of entries) {
|
531 | 531 | const [key, fileName] = entry;
|
532 |
| - console.log( |
533 |
| - `Adding ${key}: ${path.resolve( |
534 |
| - base, |
535 |
| - fileName, |
536 |
| - )} to partial at ${path.resolve( |
537 |
| - base, |
538 |
| - '_reactium-style-variables.scss', |
539 |
| - )}`, |
540 |
| - ); |
541 | 532 | const dataURL = await fileReader(
|
542 | 533 | new File(path.resolve(base, fileName)),
|
543 | 534 | );
|
@@ -751,39 +742,68 @@ $assets: map.set($assets, "{{key}}", "{{{dataURL}}}");
|
751 | 742 | done();
|
752 | 743 | };
|
753 | 744 |
|
| 745 | + const colorTemplate = data => { |
| 746 | + const template = handlebars.compile(` |
| 747 | +// |
| 748 | +// DO NOT EDIT! |
| 749 | +// This file is generated by gulp styles:colors task. |
| 750 | +// |
| 751 | +@use "sass:map"; |
| 752 | +
|
| 753 | +{{#each this}} |
| 754 | +\${{{ key }}}: "{{{value}}}" !default; |
| 755 | +{{/each}} |
| 756 | +
|
| 757 | +$color: () !default; |
| 758 | +
|
| 759 | +{{#each this}} |
| 760 | +$color: map.set($color, "{{key}}", \${{{ key }}}); |
| 761 | +{{/each}} |
| 762 | +`); |
| 763 | + return template(data); |
| 764 | + }; |
| 765 | + |
754 | 766 | const stylesColors = done => {
|
755 | 767 | const colorProfiles = globby.sync(config.src.colors);
|
756 |
| - if (colorProfiles.length > 0) { |
757 |
| - let colorFileContents = |
758 |
| - '// WARNING: Do not directly edit this file !!!!\n// File generated by gulp styles:colors task\n'; |
759 |
| - let colorVars = []; |
760 |
| - let colorArr = []; |
761 | 768 |
|
| 769 | + if (colorProfiles.length > 0) { |
762 | 770 | colorProfiles.forEach(filePath => {
|
763 |
| - let profile = fs.readFileSync(path.resolve(filePath)); |
764 |
| - profile = JSON.parse(profile); |
765 |
| - |
766 |
| - colorVars.push(`\n\n// ~/${filePath}`); |
| 771 | + const profile = fs.readJsonSync(path.resolve(filePath)); |
| 772 | + const location = path.dirname(filePath); |
| 773 | + const { name } = path.parse(path.basename(filePath)); |
| 774 | + let [, prefix = 'variables', ...suffixParts] = name.split('-'); |
| 775 | + |
| 776 | + const prefixes = [ |
| 777 | + 'mixins', |
| 778 | + 'variables', |
| 779 | + 'base', |
| 780 | + 'atoms', |
| 781 | + 'molecules', |
| 782 | + 'organisms', |
| 783 | + 'overrides', |
| 784 | + ]; |
| 785 | + ReactiumGulp.Hook.runSync('color-profile-prefixes', prefixes); |
| 786 | + |
| 787 | + if (!prefixes.includes(prefix)) { |
| 788 | + suffixParts = [prefix].concat(suffixParts); |
| 789 | + prefix = 'variables'; |
| 790 | + } |
767 | 791 |
|
768 |
| - Object.keys(profile).forEach(k => { |
769 |
| - let code = profile[k]; |
770 |
| - let cvar = `$${k}`; |
771 |
| - let vline = `${cvar}: ${code} !default;`; |
772 |
| - let cname = k.split('color-').join(''); |
773 |
| - let aline = `\t"${cname}": ${cvar}`; |
| 792 | + const suffix = suffixParts.join('-'); |
| 793 | + const outputFileName = `_reactium-style-${prefix}-colors${ |
| 794 | + suffix.length > 0 ? `-${suffix}` : '' |
| 795 | + }.scss`; |
| 796 | + const outputPath = path.resolve(location, outputFileName); |
| 797 | + |
| 798 | + const colorFileContents = colorTemplate( |
| 799 | + Object.entries(profile).map(([key, value]) => ({ |
| 800 | + key, |
| 801 | + value, |
| 802 | + })), |
| 803 | + ); |
774 | 804 |
|
775 |
| - colorVars.push(vline); |
776 |
| - colorArr.push(aline); |
777 |
| - }); |
| 805 | + fs.writeFileSync(outputPath, colorFileContents, 'utf8'); |
778 | 806 | });
|
779 |
| - |
780 |
| - colorFileContents += colorVars.join('\n') + '\n\n\n'; |
781 |
| - colorFileContents += `$color: (\n${colorArr.join( |
782 |
| - ',\n', |
783 |
| - )}\n) !default;\n\n\n`; |
784 |
| - |
785 |
| - fs.ensureFileSync(config.dest.colors); |
786 |
| - fs.writeFileSync(config.dest.colors, colorFileContents, 'utf8'); |
787 | 807 | }
|
788 | 808 |
|
789 | 809 | done();
|
|
0 commit comments