@oceanbase/codemod 1.0.0-alpha.8 → 1.0.0-alpha.9

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 (36) hide show
  1. package/README.md +85 -0
  2. package/bin/cli.js +39 -3
  3. package/package.json +4 -4
  4. package/transforms/__testfixtures__/less-to-cssvar/basic.input.less +16 -0
  5. package/transforms/__testfixtures__/less-to-cssvar/basic.output.less +14 -0
  6. package/transforms/__testfixtures__/less-to-cssvar/color-scales.input.less +23 -0
  7. package/transforms/__testfixtures__/less-to-cssvar/color-scales.output.less +21 -0
  8. package/transforms/__testfixtures__/less-to-cssvar/complex-values.input.less +22 -0
  9. package/transforms/__testfixtures__/less-to-cssvar/complex-values.output.less +20 -0
  10. package/transforms/__testfixtures__/less-to-cssvar/control-tokens.input.less +29 -0
  11. package/transforms/__testfixtures__/less-to-cssvar/control-tokens.output.less +27 -0
  12. package/transforms/__testfixtures__/less-to-cssvar/css-modules-global.input.less +21 -0
  13. package/transforms/__testfixtures__/less-to-cssvar/css-modules-global.output.less +19 -0
  14. package/transforms/__testfixtures__/less-to-cssvar/custom-prefix.input.less +9 -0
  15. package/transforms/__testfixtures__/less-to-cssvar/custom-prefix.output.less +7 -0
  16. package/transforms/__testfixtures__/less-to-cssvar/fill-tokens.input.less +36 -0
  17. package/transforms/__testfixtures__/less-to-cssvar/fill-tokens.output.less +34 -0
  18. package/transforms/__testfixtures__/less-to-cssvar/mixed-values.input.less +21 -0
  19. package/transforms/__testfixtures__/less-to-cssvar/mixed-values.output.less +19 -0
  20. package/transforms/__testfixtures__/less-to-cssvar/multiple-imports.input.less +9 -0
  21. package/transforms/__testfixtures__/less-to-cssvar/multiple-imports.output.less +8 -0
  22. package/transforms/__testfixtures__/less-to-cssvar/nested-selectors.input.less +24 -0
  23. package/transforms/__testfixtures__/less-to-cssvar/nested-selectors.output.less +22 -0
  24. package/transforms/__testfixtures__/less-to-cssvar/no-transform.input.less +8 -0
  25. package/transforms/__testfixtures__/less-to-cssvar/no-transform.output.less +8 -0
  26. package/transforms/__testfixtures__/less-to-cssvar/obui-import.input.less +7 -0
  27. package/transforms/__testfixtures__/less-to-cssvar/obui-import.output.less +5 -0
  28. package/transforms/__testfixtures__/less-to-cssvar/status-colors.input.less +25 -0
  29. package/transforms/__testfixtures__/less-to-cssvar/status-colors.output.less +23 -0
  30. package/transforms/__testfixtures__/less-to-token/case-insensitive.input.less +4 -0
  31. package/transforms/__testfixtures__/less-to-token/case-insensitive.output.less +4 -0
  32. package/transforms/__testfixtures__/style-to-token/function-component.input.js +2 -2
  33. package/transforms/__testfixtures__/style-to-token/function-component.output.js +2 -2
  34. package/transforms/__tests__/less-to-cssvar.test.ts +124 -0
  35. package/transforms/less-to-cssvar.js +482 -0
  36. package/transforms/utils/token.js +19 -0
@@ -0,0 +1,25 @@
1
+ @import '~@oceanbase/design/es/theme/index.less';
2
+
3
+ .status {
4
+ &.success {
5
+ color: @colorSuccess;
6
+ background: @colorSuccessBg;
7
+ border-color: @colorSuccessBorder;
8
+ }
9
+ &.warning {
10
+ color: @colorWarning;
11
+ background: @colorWarningBg;
12
+ border-color: @colorWarningBorder;
13
+ }
14
+ &.error {
15
+ color: @colorError;
16
+ background: @colorErrorBg;
17
+ border-color: @colorErrorBorder;
18
+ }
19
+ &.info {
20
+ color: @colorInfo;
21
+ background: @colorInfoBg;
22
+ border-color: @colorInfoBorder;
23
+ }
24
+ }
25
+
@@ -0,0 +1,23 @@
1
+ .status {
2
+ &.success {
3
+ color: var(--ant-color-success);
4
+ background: var(--ant-color-success-bg);
5
+ border-color: var(--ant-color-success-border);
6
+ }
7
+ &.warning {
8
+ color: var(--ant-color-warning);
9
+ background: var(--ant-color-warning-bg);
10
+ border-color: var(--ant-color-warning-border);
11
+ }
12
+ &.error {
13
+ color: var(--ant-color-error);
14
+ background: var(--ant-color-error-bg);
15
+ border-color: var(--ant-color-error-border);
16
+ }
17
+ &.info {
18
+ color: var(--ant-color-info);
19
+ background: var(--ant-color-info-bg);
20
+ border-color: var(--ant-color-info-border);
21
+ }
22
+ }
23
+
@@ -5,11 +5,15 @@
5
5
  border-color: #FF4D4F;
6
6
  scrollbar-color: #FFFFFF;
7
7
  font-size: 14px;
8
+ font-weight: 400;
9
+ border-radius: 4px;
8
10
  .content {
9
11
  color: rgba(0, 0, 0, 0.85);
10
12
  background: rgba(0, 0, 0,0.65);
11
13
  background-color: rgba(0,0,0,0.45);
12
14
  border: 1px solid #D9D9D9;
13
15
  font-size: 12px;
16
+ font-weight: 500;
17
+ border-radius: 6px;
14
18
  }
15
19
  }
@@ -6,11 +6,15 @@
6
6
  border-color: @colorError;
7
7
  scrollbar-color: @colorBgContainer;
8
8
  font-size: @fontSize;
9
+ font-weight: @fontWeight;
10
+ border-radius: @borderRadius;
9
11
  .content {
10
12
  color: @colorText;
11
13
  background: @colorTextSecondary;
12
14
  background-color: @colorTextTertiary;
13
15
  border: 1px solid @colorBorder;
14
16
  font-size: @fontSizeSM;
17
+ font-weight: @fontWeightStrong;
18
+ border-radius: @borderRadiusMD;
15
19
  }
16
20
  }
@@ -5,8 +5,8 @@ function Demo1() {
5
5
  const tokenList = ['rgb(0 0 0 / 45%)', '#006AFF', '#f3f6fc'];
6
6
  return (
7
7
  <div>
8
- <Alert style={{ color: 'rgba(0, 0, 0, 0.85)', background: 'rgba(0, 0, 0,0.65)', backgroundColor: 'rgba(0,0,0,0.45)', border: '1px solid #d9d9d9', fontSize: 14 }} />
9
- <Button style={{ color: '#1890ff', background: '#52c41a', backgroundColor: '#faad14', borderColor: '#ff4D4F', fontSize: '12px' }}></Button>
8
+ <Alert style={{ color: 'rgba(0, 0, 0, 0.85)', background: 'rgba(0, 0, 0,0.65)', backgroundColor: 'rgba(0,0,0,0.45)', border: '1px solid #d9d9d9', fontSize: 14, fontWeight: 400, borderRadius: 4 }} />
9
+ <Button style={{ color: '#1890ff', background: '#52c41a', backgroundColor: '#faad14', borderColor: '#ff4D4F', fontSize: '12px', fontWeight: 500, borderRadius: 6 }}></Button>
10
10
  <Tooltip color="#ffffff" backgroundColor="#fff1f0" borderColor="#fafafa" border="1px solid #fafafa" />
11
11
  </div>
12
12
  );
@@ -6,8 +6,8 @@ function Demo1() {
6
6
  const tokenList = [token.colorTextTertiary, token.colorInfo, token.colorBgLayout];
7
7
  return (
8
8
  <div>
9
- <Alert style={{ color: token.colorText, background: token.colorTextSecondary, backgroundColor: token.colorTextTertiary, border: `1px solid ${token.colorBorder}`, fontSize: token.fontSize }} />
10
- <Button style={{ color: token.colorInfo, background: token.colorSuccess, backgroundColor: token.colorWarning, borderColor: token.colorError, fontSize: token.fontSizeSM }}></Button>
9
+ <Alert style={{ color: token.colorText, background: token.colorTextSecondary, backgroundColor: token.colorTextTertiary, border: `1px solid ${token.colorBorder}`, fontSize: token.fontSize, fontWeight: token.fontWeight, borderRadius: token.borderRadius }} />
10
+ <Button style={{ color: token.colorInfo, background: token.colorSuccess, backgroundColor: token.colorWarning, borderColor: token.colorError, fontSize: token.fontSizeSM, fontWeight: token.fontWeightStrong, borderRadius: token.borderRadiusMD }}></Button>
11
11
  <Tooltip color={token.colorBgContainer} backgroundColor={token.colorErrorBg} borderColor={token.colorBgLayout} border={`1px solid ${token.colorBgLayout}`} />
12
12
  </div>
13
13
  );
@@ -0,0 +1,124 @@
1
+ import fs from 'fs';
2
+ import path from 'path';
3
+ import { transform, convertLessCommentsToCss, camelToKebab, LESS_TOKENS } from '../less-to-cssvar';
4
+
5
+ const testUnit = 'less-to-cssvar';
6
+
7
+ // Tests with default prefix 'ant'
8
+ const defaultPrefixTests = [
9
+ 'basic',
10
+ 'status-colors',
11
+ 'complex-values',
12
+ 'obui-import',
13
+ 'no-transform',
14
+ 'nested-selectors',
15
+ 'css-modules-global',
16
+ 'control-tokens',
17
+ 'color-scales',
18
+ 'mixed-values',
19
+ 'multiple-imports',
20
+ 'fill-tokens',
21
+ ];
22
+
23
+ // Tests with custom prefix
24
+ const customPrefixTests = ['custom-prefix'];
25
+
26
+ describe(testUnit, () => {
27
+ describe('with default prefix (ant)', () => {
28
+ defaultPrefixTests.forEach(test => {
29
+ it(test, async () => {
30
+ const { content: result } = await transform(
31
+ path.join(__dirname, `../__testfixtures__/less-to-cssvar/${test}.input.less`),
32
+ { prefix: 'ant' }
33
+ );
34
+ const output = fs.readFileSync(
35
+ path.join(__dirname, `../__testfixtures__/less-to-cssvar/${test}.output.less`),
36
+ 'utf-8'
37
+ );
38
+ expect(result).toEqual(output);
39
+ });
40
+ });
41
+ });
42
+
43
+ describe('with custom prefix (ob)', () => {
44
+ customPrefixTests.forEach(test => {
45
+ it(test, async () => {
46
+ const { content: result } = await transform(
47
+ path.join(__dirname, `../__testfixtures__/less-to-cssvar/${test}.input.less`),
48
+ { prefix: 'ob' }
49
+ );
50
+ const output = fs.readFileSync(
51
+ path.join(__dirname, `../__testfixtures__/less-to-cssvar/${test}.output.less`),
52
+ 'utf-8'
53
+ );
54
+ expect(result).toEqual(output);
55
+ });
56
+ });
57
+ });
58
+
59
+ describe('camelToKebab', () => {
60
+ it('should convert camelCase to kebab-case', () => {
61
+ expect(camelToKebab('colorPrimary')).toBe('color-primary');
62
+ expect(camelToKebab('colorBgContainer')).toBe('color-bg-container');
63
+ expect(camelToKebab('fontSizeLG')).toBe('font-size-lg');
64
+ expect(camelToKebab('borderRadiusSM')).toBe('border-radius-sm');
65
+ expect(camelToKebab('controlItemBgHover')).toBe('control-item-bg-hover');
66
+ });
67
+
68
+ it('should handle consecutive uppercase letters', () => {
69
+ expect(camelToKebab('colorBgTextHover')).toBe('color-bg-text-hover');
70
+ expect(camelToKebab('marginXXL')).toBe('margin-xxl');
71
+ });
72
+ });
73
+
74
+ describe('convertLessCommentsToCss', () => {
75
+ it('should convert single-line Less comments to CSS comments', () => {
76
+ const input = '// This is a comment\n.class { color: red; }';
77
+ const output = '/* This is a comment */\n.class { color: red; }';
78
+ expect(convertLessCommentsToCss(input)).toBe(output);
79
+ });
80
+
81
+ it('should convert inline Less comments', () => {
82
+ const input = '.class { color: red; // inline comment\n}';
83
+ const output = '.class { color: red; /* inline comment */\n}';
84
+ expect(convertLessCommentsToCss(input)).toBe(output);
85
+ });
86
+
87
+ it('should not convert URLs with //', () => {
88
+ const input = 'background: url(https://example.com/image.png);';
89
+ expect(convertLessCommentsToCss(input)).toBe(input);
90
+ });
91
+
92
+ it('should handle multiple comments', () => {
93
+ const input = '// Comment 1\n.a { }\n// Comment 2\n.b { }';
94
+ const output = '/* Comment 1 */\n.a { }\n/* Comment 2 */\n.b { }';
95
+ expect(convertLessCommentsToCss(input)).toBe(output);
96
+ });
97
+ });
98
+
99
+ describe('LESS_TOKENS', () => {
100
+ it('should contain common tokens', () => {
101
+ expect(LESS_TOKENS).toContain('colorPrimary');
102
+ expect(LESS_TOKENS).toContain('fontSize');
103
+ expect(LESS_TOKENS).toContain('borderRadius');
104
+ expect(LESS_TOKENS).toContain('padding');
105
+ });
106
+
107
+ it('should contain control tokens', () => {
108
+ expect(LESS_TOKENS).toContain('controlHeight');
109
+ expect(LESS_TOKENS).toContain('controlItemBgHover');
110
+ });
111
+
112
+ it('should contain color scale tokens', () => {
113
+ expect(LESS_TOKENS).toContain('gray1');
114
+ expect(LESS_TOKENS).toContain('blue4');
115
+ expect(LESS_TOKENS).toContain('green4');
116
+ });
117
+
118
+ it('should be loaded from @oceanbase/design theme', () => {
119
+ // LESS_TOKENS should be an array with significant length
120
+ expect(Array.isArray(LESS_TOKENS)).toBe(true);
121
+ expect(LESS_TOKENS.length).toBeGreaterThan(50);
122
+ });
123
+ });
124
+ });