lism-css 0.22.2 → 0.23.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/config/default-config.d.ts +137 -49
  2. package/dist/config/default-config.js +8 -6
  3. package/dist/config/defaults/breakpoints.d.ts +15 -0
  4. package/dist/config/defaults/breakpoints.js +10 -0
  5. package/dist/config/defaults/props.d.ts +21 -30
  6. package/dist/config/defaults/props.js +33 -29
  7. package/dist/config/defaults/token-scope.d.ts +9 -0
  8. package/dist/config/defaults/token-scope.js +7 -0
  9. package/dist/config/defaults/token-var-prefix.d.ts +11 -0
  10. package/dist/config/defaults/token-var-prefix.js +11 -0
  11. package/dist/config/defaults/tokens.d.ts +118 -21
  12. package/dist/config/defaults/tokens.js +112 -24
  13. package/dist/config/index.d.ts +285 -105
  14. package/dist/config/index.js +18 -15
  15. package/dist/config/presets/props-full.d.ts +20 -0
  16. package/dist/config/presets/props-full.js +28 -0
  17. package/dist/css/base/set.css +1 -1
  18. package/dist/css/base.css +1 -1
  19. package/dist/css/full.css +1 -0
  20. package/dist/css/full_no_layer.css +1 -0
  21. package/dist/css/main.css +1 -1
  22. package/dist/css/main_no_layer.css +1 -1
  23. package/dist/css/props.css +1 -1
  24. package/dist/index.d.ts +4 -0
  25. package/dist/index.js +1 -0
  26. package/dist/lib/getBpData.d.ts +2 -2
  27. package/dist/lib/getBpData.js +7 -7
  28. package/dist/lib/getLismProps.d.ts +5 -3
  29. package/dist/lib/getLismProps.js +59 -54
  30. package/dist/lib/getMaybeTokenValue.d.ts +1 -7
  31. package/dist/lib/getMaybeTokenValue.js +10 -22
  32. package/dist/lib/getTokenVarName.d.ts +13 -0
  33. package/dist/lib/getTokenVarName.js +8 -0
  34. package/dist/lib/getTokenVarName.test.d.ts +1 -0
  35. package/dist/lib/isTokenValue.js +11 -22
  36. package/dist/lib/types/CustomPropRegistry.d.ts +9 -0
  37. package/dist/lib/types/CustomTraitRegistry.d.ts +9 -0
  38. package/dist/lib/types/FullModeRegistry.d.ts +26 -0
  39. package/dist/lib/types/PropValueTypes.d.ts +45 -13
  40. package/dist/lib/types/ResponsiveProps.d.ts +57 -13
  41. package/dist/lib/types/ResponsiveProps.module-augmentation.test.d.ts +1 -0
  42. package/dist/lib/warnUnsupportedBp.js +1 -1
  43. package/dist/scss/auto_output.test.d.ts +1 -0
  44. package/package.json +23 -33
  45. package/src/scss/_auto_output.scss +54 -42
  46. package/src/scss/_prop-config-full.gen.scss +1317 -0
  47. package/src/scss/{_prop-config.scss → _prop-config.gen.scss} +37 -13
  48. package/src/scss/_setting.scss +6 -11
  49. package/src/scss/auto_output.test.ts +91 -0
  50. package/src/scss/base/index.scss +1 -3
  51. package/src/scss/base/set/index.scss +5 -0
  52. package/src/scss/base/tokens/_tokens.gen.scss +69 -0
  53. package/src/scss/base/tokens/_tokens.scss +31 -30
  54. package/src/scss/full.scss +12 -0
  55. package/src/scss/full_no_layer.scss +32 -0
  56. package/src/scss/props/index.scss +0 -1
  57. package/src/scss/trait/is/_wrapper.scss +1 -1
  58. package/bin/__build-css.cjs +0 -92
  59. package/bin/build-config.js +0 -155
  60. package/bin/build-css.js +0 -90
  61. package/bin/cli.mjs +0 -79
  62. package/bin/script-build-css.js +0 -6
  63. package/src/scss/base/tokens/_shadow.scss +0 -23
  64. package/src/scss/base/tokens/_space.scss +0 -30
  65. package/src/scss/base/tokens/_typography.scss +0 -69
  66. package/src/scss/props/_lh.scss +0 -16
@@ -8,7 +8,6 @@ $props: (
8
8
  'fz': (
9
9
  prop: 'font-size',
10
10
  utilities: (
11
- 'root': 'var(--fz--root)',
12
11
  'base': 'var(--fz--base)',
13
12
  '5xl': 'var(--fz--5xl)',
14
13
  '4xl': 'var(--fz--4xl)',
@@ -55,11 +54,27 @@ $props: (
55
54
  ),
56
55
  ),
57
56
  'lh': (
58
- prop: 'line-height',
57
+ prop: '--hl',
59
58
  utilities: (
59
+ '1': '0px',
60
+ 'base': 'var(--hl--base)',
61
+ 'xs': 'var(--hl--xs)',
62
+ 's': 'var(--hl--s)',
63
+ 'l': 'var(--hl--l)',
60
64
  ),
61
- exUtility: (
65
+ isVar: 1,
66
+ ),
67
+ 'hl': (
68
+ prop: '--hl',
69
+ utilities: (
70
+ '0': '0px',
71
+ 'base': 'var(--hl--base)',
72
+ 'xs': 'var(--hl--xs)',
73
+ 's': 'var(--hl--s)',
74
+ 'l': 'var(--hl--l)',
62
75
  ),
76
+ bp: 1,
77
+ isVar: 1,
63
78
  ),
64
79
  'lts': (
65
80
  prop: 'letter-spacing',
@@ -69,7 +84,6 @@ $props: (
69
84
  'l': 'var(--lts--l)',
70
85
  'xl': 'var(--lts--xl)',
71
86
  ),
72
- bp: 0,
73
87
  ),
74
88
  'ta': (
75
89
  prop: 'text-align',
@@ -104,7 +118,7 @@ $props: (
104
118
  'inline': 'inline',
105
119
  'inline-block': 'inline-block',
106
120
  ),
107
- bp: lg,
121
+ bp: 1,
108
122
  ),
109
123
  'o': (
110
124
  prop: 'opacity',
@@ -589,11 +603,11 @@ $props: (
589
603
  'gap': 'inherit',
590
604
  ),
591
605
  ),
592
- bp: lg,
606
+ bp: 1,
593
607
  ),
594
608
  'cols': (
595
609
  prop: '--cols',
596
- bp: lg,
610
+ bp: 1,
597
611
  isVar: 1,
598
612
  ),
599
613
  'rows': (
@@ -646,21 +660,21 @@ $props: (
646
660
  ),
647
661
  'gta': (
648
662
  prop: 'grid-template-areas',
649
- bp: lg,
663
+ bp: 1,
650
664
  ),
651
665
  'gtc': (
652
666
  prop: 'grid-template-columns',
653
667
  utilities: (
654
668
  'subgrid': 'subgrid',
655
669
  ),
656
- bp: lg,
670
+ bp: 1,
657
671
  ),
658
672
  'gtr': (
659
673
  prop: 'grid-template-rows',
660
674
  utilities: (
661
675
  'subgrid': 'subgrid',
662
676
  ),
663
- bp: lg,
677
+ bp: 1,
664
678
  ),
665
679
  'gaf': (
666
680
  prop: 'grid-auto-flow',
@@ -675,21 +689,21 @@ $props: (
675
689
  utilities: (
676
690
  '1\\/1': '1 / 1',
677
691
  ),
678
- bp: lg,
692
+ bp: 1,
679
693
  ),
680
694
  'gc': (
681
695
  prop: 'grid-column',
682
696
  utilities: (
683
697
  '1\\/-1': '1 / -1',
684
698
  ),
685
- bp: lg,
699
+ bp: 1,
686
700
  ),
687
701
  'gr': (
688
702
  prop: 'grid-row',
689
703
  utilities: (
690
704
  '1\\/-1': '1 / -1',
691
705
  ),
692
- bp: lg,
706
+ bp: 1,
693
707
  ),
694
708
  'ai': (
695
709
  prop: 'align-items',
@@ -829,3 +843,13 @@ $props: (
829
843
  bp: 1,
830
844
  ),
831
845
  );
846
+
847
+ $breakpoints: (
848
+ 'xs': 0,
849
+ 'sm': '480px',
850
+ 'md': '800px',
851
+ 'lg': '1120px',
852
+ 'xl': 0,
853
+ );
854
+
855
+ $default_important: 0;
@@ -1,20 +1,15 @@
1
1
  @use 'sass:map';
2
2
  @use 'sass:string';
3
- @use './prop-config' as props;
3
+ @use './prop-config.gen' as props;
4
4
 
5
- $default_important: 0 !default;
5
+ // $default_important: lism.config.js の defaultImportant を prop-config.gen 経由で既定値に読む。
6
+ // `@use ... with ($default_important: ...)` で明示上書きされた場合は、!default が無効化されそちらが優先される。
7
+ $default_important: props.$default_important !default;
6
8
  $is_container_query: 1 !default;
7
- $common_support_bp: 'md' !default;
8
9
 
10
+ // breakpoints: サイズ 0 は「無効」(_query.scss の bp-up / bp-down がスキップする)。
9
11
  $breakpoints: () !default;
10
- $breakpoints: map.merge(
11
- (
12
- 'sm': '480px',
13
- 'md': '800px',
14
- 'lg': '1120px',
15
- ),
16
- $breakpoints
17
- );
12
+ $breakpoints: map.merge(props.$breakpoints, $breakpoints);
18
13
 
19
14
  $props: () !default;
20
15
  $props: map.deep-merge(props.$props, $props);
@@ -0,0 +1,91 @@
1
+ import { dirname, resolve } from 'node:path';
2
+ import { fileURLToPath, pathToFileURL } from 'node:url';
3
+ import * as sass from 'sass';
4
+ import { describe, expect, test } from 'vitest';
5
+
6
+ const currentDir = dirname(fileURLToPath(import.meta.url));
7
+
8
+ const testProp = (bp: string) => `
9
+ $props: (
10
+ 'zztest': (
11
+ prop: 'padding',
12
+ utilities: (
13
+ '10': '10px',
14
+ ),
15
+ bp: ${bp},
16
+ alwaysVar: 1,
17
+ ),
18
+ )
19
+ `;
20
+
21
+ function compileAutoOutput(settingOverrides: string): string {
22
+ const result = sass.compileString(
23
+ `
24
+ @use './setting' with (
25
+ ${settingOverrides}
26
+ );
27
+ @use './auto_output';
28
+ `,
29
+ {
30
+ url: pathToFileURL(resolve(currentDir, '__auto_output_test.scss')),
31
+ logger: {
32
+ warn: () => {},
33
+ debug: () => {},
34
+ },
35
+ }
36
+ );
37
+
38
+ return result.css;
39
+ }
40
+
41
+ describe('auto_output breakpoint output', () => {
42
+ test('bp: 1 outputs default enabled breakpoints only', () => {
43
+ const css = compileAutoOutput(testProp('1'));
44
+
45
+ expect(css).not.toContain('.-zztest_xs');
46
+ expect(css).toContain('.-zztest_sm');
47
+ expect(css).toContain('.-zztest_md');
48
+ expect(css).toContain('.-zztest_lg');
49
+ expect(css).not.toContain('.-zztest_xl');
50
+ });
51
+
52
+ test('bp: 1 outputs xs and xl when breakpoints define their sizes', () => {
53
+ const css = compileAutoOutput(`
54
+ $breakpoints: (
55
+ 'xs': '360px',
56
+ 'xl': '1440px',
57
+ ),
58
+ ${testProp('1')}
59
+ `);
60
+
61
+ expect(css).toContain('.-zztest_xs');
62
+ expect(css).toContain('.-zztest_sm');
63
+ expect(css).toContain('.-zztest_md');
64
+ expect(css).toContain('.-zztest_lg');
65
+ expect(css).toContain('.-zztest_xl');
66
+ });
67
+
68
+ test('bp list outputs only explicitly listed breakpoints', () => {
69
+ const css = compileAutoOutput(`
70
+ $breakpoints: (
71
+ 'xs': '360px',
72
+ 'xl': '1440px',
73
+ ),
74
+ ${testProp("('sm', 'md')")}
75
+ `);
76
+
77
+ expect(css).not.toContain('.-zztest_xs');
78
+ expect(css).toContain('.-zztest_sm');
79
+ expect(css).toContain('.-zztest_md');
80
+ expect(css).not.toContain('.-zztest_lg');
81
+ expect(css).not.toContain('.-zztest_xl');
82
+ });
83
+
84
+ test('bp string does not output breakpoint classes', () => {
85
+ const css = compileAutoOutput(testProp("'md'"));
86
+
87
+ expect(css).not.toContain('.-zztest_sm');
88
+ expect(css).not.toContain('.-zztest_md');
89
+ expect(css).not.toContain('.-zztest_lg');
90
+ });
91
+ });
@@ -1,7 +1,5 @@
1
1
  @forward './tokens/tokens';
2
- @forward './tokens/typography';
3
- @forward './tokens/space';
4
- @forward './tokens/shadow';
2
+ @forward './tokens/tokens.gen'; // tokens.ts のインライン値から自動生成されるトークン値
5
3
 
6
4
  // 各html要素のベーススタイル
7
5
  @forward './html';
@@ -4,3 +4,8 @@
4
4
  @forward './bleed';
5
5
  @forward './plain';
6
6
  @forward './revert';
7
+
8
+ .set--s {
9
+ // 何も指定しなければ em 単位に変換する
10
+ --s-unit: 0.5em;
11
+ }
@@ -0,0 +1,69 @@
1
+ // このファイルは自動生成されます。直接編集しないでください(次回ビルド時に上書きされます)。
2
+ // 生成元: コア → config/defaults/tokens.ts / 利用側 → defaults + lism.config.js の tokens
3
+ :root {
4
+ --white: #fff;
5
+ --black: #000;
6
+ --fz--base: 1rem;
7
+ --fz--5xl: calc(1em * var(--fz-mol) / (var(--fz-mol) - 6));
8
+ --fz--4xl: calc(1em * var(--fz-mol) / (var(--fz-mol) - 5));
9
+ --fz--3xl: calc(1em * var(--fz-mol) / (var(--fz-mol) - 4));
10
+ --fz--2xl: calc(1em * var(--fz-mol) / (var(--fz-mol) - 3));
11
+ --fz--xl: calc(1em * var(--fz-mol) / (var(--fz-mol) - 2));
12
+ --fz--l: calc(1em * var(--fz-mol) / (var(--fz-mol) - 1));
13
+ --fz--m: 1em;
14
+ --fz--s: calc(1em * var(--fz-mol) / (var(--fz-mol) + 1));
15
+ --fz--xs: calc(1em * var(--fz-mol) / (var(--fz-mol) + 2));
16
+ --fz--2xs: calc(1em * var(--fz-mol) / (var(--fz-mol) + 3));
17
+ --hl--base: calc(var(--hl-unit) * 3);
18
+ --hl--xs: var(--hl-unit);
19
+ --hl--s: calc(var(--hl-unit) * 2);
20
+ --hl--l: calc(var(--hl-unit) * 4);
21
+ --lts--base: normal;
22
+ --lts--s: -0.025em;
23
+ --lts--l: 0.05em;
24
+ --lts--xl: 0.1em;
25
+ --ff--base: -apple-system, 'BlinkMacSystemFont', 'Hiragino Sans', sans-serif;
26
+ --ff--accent: Georgia, serif;
27
+ --ff--mono: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
28
+ --fw--light: 300;
29
+ --fw--normal: 400;
30
+ --fw--bold: 600;
31
+ --o--mp: 0.9;
32
+ --o--p: 0.75;
33
+ --o--pp: 0.5;
34
+ --o--ppp: 0.25;
35
+ --bdrs--10: 0.25rem;
36
+ --bdrs--20: 0.5rem;
37
+ --bdrs--30: 1rem;
38
+ --bdrs--40: 1.5rem;
39
+ --bdrs--99: 99rem;
40
+ --sz--xs: 400px;
41
+ --sz--s: 640px;
42
+ --sz--m: 880px;
43
+ --sz--l: 1200px;
44
+ --sz--xl: 1600px;
45
+ --ar--og: 1.91/1;
46
+ }
47
+ :root,
48
+ .set--bxsh {
49
+ --bxsh--10: var(--shsz--10) var(--shc);
50
+ --bxsh--20: var(--shsz--20) var(--shc);
51
+ --bxsh--30: var(--shsz--30) var(--shc);
52
+ --bxsh--40: var(--shsz--40) var(--shc);
53
+ --bxsh--50: var(--shsz--50) var(--shc);
54
+ }
55
+ :root,
56
+ .set--s {
57
+ --s5: calc(var(--s-unit) * 0.5);
58
+ --s10: var(--s-unit);
59
+ --s15: calc(var(--s-unit) * 1.5);
60
+ --s20: calc(var(--s-unit) * 2);
61
+ --s25: calc(var(--s-unit) * 2.5);
62
+ --s30: calc(var(--s-unit) * 3);
63
+ --s35: calc(var(--s-unit) * 4);
64
+ --s40: calc(var(--s-unit) * 5);
65
+ --s50: calc(var(--s-unit) * 8);
66
+ --s60: calc(var(--s-unit) * 13);
67
+ --s70: calc(var(--s-unit) * 21);
68
+ --s80: calc(var(--s-unit) * 34);
69
+ }
@@ -1,8 +1,15 @@
1
+ /* --------------------------------------------------
2
+ ハーフレディング管理変数
3
+ -------------------------------------------------- */
4
+ @property --hl {
5
+ syntax: '<length>';
6
+ inherits: true;
7
+ initial-value: 0.25rem;
8
+ }
9
+
1
10
  /* --------------------------------------------------
2
11
  bleedサイズ保持変数
3
- Memo: 最外側の is--container 直下の子で 100cqi に上書きされ、それ以降は inherit
4
- 子孫まで伝搬する。is--container が祖先に存在しない場合の fallback として
5
- 初期値に 100svi(small viewport inline size)を設定する。
12
+ Memo: 最外側の is--container 直下の子で 100cqi に上書きされ、それ以降は inherit で子孫まで伝搬する。
6
13
  cqi を算出値で保持するために登録済みカスタムプロパティとして定義する。
7
14
  -------------------------------------------------- */
8
15
  @property --sz--bleed {
@@ -11,24 +18,17 @@
11
18
  inherits: true;
12
19
  }
13
20
 
21
+ /* --------------------------------------------------
22
+ 色・構造系トークン(手書き)
23
+ Memo: 多くのインライン値は tokens.ts → _tokens.gen.scss へ自動生成。色とスコープ用の構造変数だけ
24
+ ここに実値を残す(tokens.ts 側は '-' センチネル)。
25
+ -------------------------------------------------- */
14
26
  :root {
15
- /**
16
- * Content size
17
- */
18
- --sz--xl: 1600px; // 80*20
19
- --sz--l: 1200px; // 80*15
20
- --sz--m: 880px; // 80*11
21
- --sz--s: 640px; // 80*8
22
- --sz--xs: 400px; // 80*5
23
-
24
27
  /**
25
28
  * カラーパレット
26
29
  * 1. 赤を基準として 明度L・彩度C を決める。
27
30
  * 2. 各色は 色相H を固定セット。 L,C は色によって微調整。
28
31
  */
29
- --black: #000;
30
- --white: #fff;
31
-
32
32
  // 基準の明度と彩度(red)
33
33
  --L: 60%;
34
34
  --C: 0.2;
@@ -71,30 +71,28 @@
71
71
  --neutral: hsl(220, 2%, 80%);
72
72
 
73
73
  /**
74
- * opacity
75
- * 音楽の強弱記号(piano 系列)に由来。p の反復回数が多いほど透明度が増す。
74
+ * shadow の構造変数
76
75
  */
77
- --o--mp: 0.9;
78
- --o--p: 0.75;
79
- --o--pp: 0.5;
80
- --o--ppp: 0.25;
76
+ --shc: var(--shadow);
77
+ --shsz--10: 0px 1px 3px;
78
+ --shsz--20: 0px 2px 6px;
79
+ --shsz--30: 0px 4px 12px;
80
+ --shsz--40: 0px 8px 24px;
81
+ --shsz--50: 0px 16px 48px;
81
82
 
82
83
  /**
83
- * border-radius
84
+ * typography トークンの構造変数
84
85
  */
85
- --bdrs--10: 0.25rem; // 4px
86
- --bdrs--20: 0.5rem; //8px
87
- --bdrs--30: 1rem; // ≒ 16px
88
- --bdrs--40: 1.5rem; // ≒ 24px
89
- --bdrs--99: 99rem;
86
+ --fz-mol: 8; // 倍音列の分母(7~ に対応)
87
+ --hl-unit: calc(var(--fz--base) * 0.125); /* ハーフレディングの計算単位 2px */
90
88
 
91
89
  /**
92
- * aspect-ratio
90
+ * SPACE トークンの構造変数
93
91
  */
94
- --ar--og: 1.91/1;
92
+ --s-unit: calc(var(--fz--base) * 0.5); // 余白の計算単位 ≒ 8px(フィボナッチ数列ベース)
95
93
 
96
94
  /**
97
- * サイトコンテンツの左右につける余白量の基準値
95
+ * コンテンツの左右につける余白量
98
96
  * Memo: -max-sz\:full などからも参照されるのでrootで定義している
99
97
  */
100
98
  --gutter--base: var(--s30);
@@ -106,6 +104,9 @@
106
104
  --flow--s: var(--s20);
107
105
  }
108
106
 
107
+ /**
108
+ * 日本語環境での調整
109
+ */
109
110
  :root:where([lang='ja']) {
110
111
  --flow--base: var(--s35);
111
112
  }
@@ -0,0 +1,12 @@
1
+ /*
2
+ full版(@layer あり):
3
+ isVar系を除く全propsのBPサポートを lg まで拡張したビルド。
4
+ CSS purge と併用し、未使用分を削る前提の「全部入り」配布物。
5
+ _prop-config-full.gen.scss は config/presets/props-full.ts から生成される。
6
+ */
7
+ @use './prop-config-full.gen' as full;
8
+ @use './setting' with (
9
+ $props: full.$props
10
+ );
11
+ @use './with_layer';
12
+ @use './props/index' as props;
@@ -0,0 +1,32 @@
1
+ /*
2
+ full版(@layer なし):
3
+ full.css と同じく isVar系を除く全propsのBPサポートを lg まで拡張し、
4
+ main_no_layer.css と同じく @layer を使わずに出力するレガシー対応ビルド。
5
+ ※ @use ... with は対象モジュールの初回ロード前に行う必要があるため、
6
+ setting → mixin の順で設定すること(mixin は内部で setting をロードする)。
7
+ */
8
+ @use './prop-config-full.gen' as full;
9
+ @use './setting' with (
10
+ $props: full.$props
11
+ );
12
+ @use './mixin' with (
13
+ $layer_mode: 0
14
+ );
15
+
16
+ // reset(ここはレイヤーあり)
17
+ @use './reset' as reset;
18
+
19
+ // base
20
+ @use './base/index' as base;
21
+
22
+ // Trait(独立レイヤー)
23
+ // primitive より弱い位置に配置。詳細は _with_layer.scss のコメント参照。
24
+ @use './trait/index' as trait;
25
+
26
+ // Primitives
27
+ @use './primitives/layout/index' as layout;
28
+ @use './primitives/atomic/index' as atomic;
29
+
30
+ // utility
31
+ @use './utility/index' as utility;
32
+ @use './props/index' as props;
@@ -2,7 +2,6 @@
2
2
  // @forward './pass-get'; // 先に読み込む
3
3
 
4
4
  // 特殊
5
- @forward './lh';
6
5
  @forward './border';
7
6
  @forward './size';
8
7
 
@@ -8,4 +8,4 @@
8
8
  }
9
9
  }
10
10
 
11
- // Memo: .-contentSize:s / m / l / xl は contentSize Prop の auto-generated 出力(src/scss/_prop-config.scss 経由)から自動的に props 層に出力される。
11
+ // Memo: .-contentSize:s / m / l / xl は contentSize Prop の auto-generated 出力(src/scss/_prop-config.gen.scss 経由)から自動的に props 層に出力される。
@@ -1,92 +0,0 @@
1
- /* eslint no-console: 0 */
2
- const path = require('path');
3
- const fs = require('fs');
4
-
5
- // glob
6
- const glob = require('glob');
7
-
8
- // node-sass
9
- // const sass = require('node-sass');
10
- const sass = require('sass');
11
- // const globImporter = require('node-sass-glob-importer');
12
-
13
- // postcss
14
- const postcss = require('postcss');
15
- const autoprefixer = require('autoprefixer');
16
- const cssnano = require('cssnano');
17
- // const mqpacker = require('css-mqpacker');
18
-
19
- // consoleの色付け
20
- const COLOR = {
21
- red: '\u001b[31m',
22
- green: '\u001b[32m',
23
- reset: '\x1b[0m',
24
- };
25
-
26
- // 環境変数・引数
27
- // const envTYPE = process.env.TYPE || '';
28
- // const TARGET_DIR = process.argv[2] || '';
29
-
30
- (() => {
31
- // パス(絶対パスに変換)
32
- let src = path.resolve(__dirname, '../src/scss');
33
- let dist = path.resolve(__dirname, '../dist/css');
34
- compileSCSS(src, dist);
35
-
36
- // component
37
- src = path.resolve(__dirname, '../src/components');
38
- dist = path.resolve(__dirname, '../dist/components');
39
- console.log('compileSCSS', src, dist);
40
- compileSCSS(src, dist);
41
- })();
42
-
43
- // scssファイル処理
44
- async function compileSCSS(src, dist) {
45
- let files = [];
46
-
47
- const ignore = ['**/_*.scss'];
48
- files = glob.sync(src + '/**/*.scss', { ignore });
49
- // console.log('files', files);
50
-
51
- for (const filePath of files) {
52
- console.log(COLOR.green + 'Start sassRender: ' + COLOR.reset + filePath);
53
-
54
- const fileName = filePath.replace(src + '/', '');
55
- const srcPath = path.resolve(__dirname, src, fileName);
56
- const distPath = path.resolve(__dirname, dist, fileName).replace('.scss', '.css').replace('/index.css', '.css');
57
-
58
- try {
59
- // dart sass コンパイル
60
- const compiledCSS = sass.compile(srcPath, {
61
- style: 'expanded', // 圧縮はcssnanoに任せる
62
- });
63
-
64
- // postcss実行
65
- postcss([autoprefixer, cssnano])
66
- .process(compiledCSS.css, { from: undefined })
67
- .then((postcssResult) => {
68
- writeCSS(distPath, postcssResult.css);
69
- });
70
-
71
- // console.log(COLOR.green + 'Completed.');
72
- } catch (error) {
73
- console.log(COLOR.red + '\n========== ! ERROR ==========' + COLOR.reset);
74
- console.log(error);
75
- console.log(COLOR.red + '========== / ERROR ========== \n' + COLOR.reset);
76
- }
77
- }
78
- }
79
-
80
- // 書き出し処理
81
- function writeCSS(filePath, css) {
82
- const dir = path.dirname(filePath);
83
-
84
- // ディレクトリがなければ作成
85
- if (!fs.existsSync(dir)) {
86
- console.log('mkdir ' + dir);
87
- fs.mkdirSync(dir, { recursive: true });
88
- }
89
-
90
- // css書き出し
91
- fs.writeFileSync(filePath, css);
92
- }