@oceanbase/codemod 0.2.9 → 0.2.10

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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # OceanBase Codemod
2
2
 
3
- A collection of codemod scripts that help migrate from `antd`, `@alipay/ob-ui`, `@alipay/tech-ui`, `@ant-design/pro-components` and `@ant-design/charts` to OceanBase Design System by using [jscodeshift](https://github.com/facebook/jscodeshift) and [postcss](https://github.com/postcss/postcss). (Inspired by [@ant-design/codemod-v5](https://github.com/ant-design/codemod-v5))
3
+ A collection of codemod transformers that help migrate from `antd`, `@alipay/ob-ui`, `@alipay/tech-ui`, `@ant-design/pro-components` and `@ant-design/charts` to OceanBase Design System by using [jscodeshift](https://github.com/facebook/jscodeshift) and [postcss](https://github.com/postcss/postcss). (Inspired by [@ant-design/codemod-v5](https://github.com/ant-design/codemod-v5))
4
4
 
5
5
  [![NPM version](https://img.shields.io/npm/v/@oceanbase/codemod.svg?style=flat)](https://npmjs.org/package/@oceanbase/codemod) [![NPM downloads](http://img.shields.io/npm/dm/@oceanbase/codemod.svg?style=flat)](https://npmjs.org/package/@oceanbase/codemod) [![Github Action](https://github.com/oceanbase/oceanbase-design/actions/workflows/ci.yml/badge.svg)](https://github.com/oceanbase/oceanbase-design/actions/workflows/ci.yml)
6
6
 
@@ -10,17 +10,24 @@ A collection of codemod scripts that help migrate from `antd`, `@alipay/ob-ui`,
10
10
 
11
11
  ## Usage
12
12
 
13
- Before run codemod scripts, you'd better make sure to commit your local git changes firstly.
13
+ Before run codemod, you'd better make sure to commit your local git changes firstly.
14
14
 
15
15
  ```shell
16
16
  # Run directly through npx
17
17
  # `src` is the target directory or file that you want to transform.
18
18
  npx -p @oceanbase/codemod codemod src
19
19
  # options
20
- # --disablePrettier // disable prettier
20
+ # --transformer=t1,t2 // run specify transformers
21
+ # --disablePrettier // disable prettier
21
22
  ```
22
23
 
23
- ## Codemod scripts introduction
24
+ Run specific transformers:
25
+
26
+ ```shell
27
+ npx -p @oceanbase/codemod codemod src --transformer=style-to-token,less-to-token
28
+ ```
29
+
30
+ ## Codemod transformers introduction
24
31
 
25
32
  ### `antd-to-oceanbase-design`
26
33
 
package/bin/cli.js CHANGED
@@ -101,7 +101,10 @@ function getRunnerArgs(transformerPath, parser = 'babylon', options = {}) {
101
101
  }
102
102
 
103
103
  async function run(filePath, args = {}) {
104
- for (const transformer of transformers) {
104
+ const targetTransformers =
105
+ args.transformer?.split(',')?.filter(transformer => transformers.includes(transformer)) ||
106
+ transformers;
107
+ for (const transformer of targetTransformers) {
105
108
  await transform(transformer, 'babylon', filePath, args);
106
109
  }
107
110
  }
@@ -250,9 +253,10 @@ async function upgradeDetect(targetDir, needOBCharts, needObUtil) {
250
253
 
251
254
  /**
252
255
  * options
253
- * --force // force skip git checking (dangerously)
254
- * --cpus=1 // specify cpus cores to use
255
- * --disablePrettier // disable prettier
256
+ * --force // force skip git checking (dangerously)
257
+ * --cpus=1 // specify cpus cores to use
258
+ * --disablePrettier // disable prettier
259
+ * --transformer=t1,t2 // specify target transformer
256
260
  */
257
261
 
258
262
  async function bootstrap() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oceanbase/codemod",
3
- "version": "0.2.9",
3
+ "version": "0.2.10",
4
4
  "description": "Codemod for OceanBase Design upgrade",
5
5
  "keywords": [
6
6
  "oceanbase",
@@ -46,5 +46,5 @@
46
46
  "enzyme": "^3.11.0",
47
47
  "enzyme-to-json": "^3.6.2"
48
48
  },
49
- "gitHead": "c9a4257a5c6357396e72c6a7acccd24613c4ceaf"
49
+ "gitHead": "debd02b577d782f8a403fe0f6133efb172168898"
50
50
  }
@@ -0,0 +1,8 @@
1
+ @import '~@alipay/ob-ui/es/theme/index.less';
2
+
3
+ .container {
4
+ color: @colorInfo;
5
+ background: @colorSuccess;
6
+ background-color: @colorWarning;
7
+ border-color: @colorError;
8
+ }
@@ -0,0 +1,7 @@
1
+ @import '~@oceanbase/design/es/theme/index.less';
2
+ .container {
3
+ color: @colorInfo;
4
+ background: @colorSuccess;
5
+ background-color: @colorWarning;
6
+ border-color: @colorError;
7
+ }
@@ -3,7 +3,13 @@ import path from 'path';
3
3
  import { transform } from '../less-to-token';
4
4
 
5
5
  const testUnit = 'less-to-token';
6
- const tests = ['antd-v4-less-to-token', 'obui-less-to-token', 'case-insensitive', 'mixin'];
6
+ const tests = [
7
+ 'antd-v4-less-to-token',
8
+ 'obui-less-to-token',
9
+ 'case-insensitive',
10
+ 'mixin',
11
+ 'obui-less-token-to-token',
12
+ ];
7
13
 
8
14
  describe(testUnit, () => {
9
15
  tests.forEach(test => {
@@ -37,14 +37,18 @@ async function transform(file) {
37
37
  const { root: ast } = await postcss([]).process(content, {
38
38
  syntax: postcssLess,
39
39
  });
40
- let modified = false;
40
+ let hasToken = false;
41
41
  let tokenLessImported = false;
42
42
  // 遍历 AST
43
43
  ast.walk(node => {
44
- const { key, token, formattedValue } = tokenParse(node.value);
45
- if (node.type === 'decl' && token) {
46
- node.value = formattedValue.replace(key, `@${token}`);
47
- modified = true;
44
+ if (node.type === 'decl') {
45
+ const { key, token, formattedValue } = tokenParse(node.value);
46
+ if (token) {
47
+ node.value = formattedValue.replace(key, `@${token}`);
48
+ hasToken = true;
49
+ } else if (node.value?.includes('@')) {
50
+ hasToken = true;
51
+ }
48
52
  } else if (node.type === 'atrule' && node.name === 'import') {
49
53
  if (node.params === "'~@oceanbase/design/es/theme/index.less'") {
50
54
  tokenLessImported = true;
@@ -54,7 +58,7 @@ async function transform(file) {
54
58
  }
55
59
  });
56
60
  // prepend @import '~@oceanbase/design/es/theme/index.less';
57
- if (modified && !tokenLessImported) {
61
+ if (hasToken && !tokenLessImported) {
58
62
  ast.prepend({
59
63
  name: 'import',
60
64
  params: "'~@oceanbase/design/es/theme/index.less'",