create-antd-skin 1.1.0 → 1.1.1

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 (2) hide show
  1. package/bin/layout.js +23 -15
  2. package/package.json +1 -1
package/bin/layout.js CHANGED
@@ -52,20 +52,27 @@ async function patchLayoutFile(filePath) {
52
52
  sourceType: "module",
53
53
  plugins: ["typescript", "jsx"],
54
54
  });
55
- const layoutNames = new Set();
56
- let hasImport = false;
55
+ let layoutNames = new Set();
56
+ let hasLayoutImport = false;
57
+ let hasWardenSkinImport = false;
57
58
  let changed = false;
58
59
  // 1. 收集 import
59
60
  (0, traverse_1.default)(ast, {
60
61
  ImportDeclaration(path) {
61
- if (path.node.source.value === ANTD_LAYOUT_PKG) {
62
- hasImport = true;
62
+ const source = path.node.source.value;
63
+ // layout package
64
+ if (source === "@adminui-dev/antd-layout") {
65
+ hasLayoutImport = true;
63
66
  for (const spec of path.node.specifiers) {
64
67
  if (t.isImportSpecifier(spec)) {
65
68
  layoutNames.add(spec.local.name);
66
69
  }
67
70
  }
68
71
  }
72
+ // ❗关键:wardenSkin 是否已存在
73
+ if (source === "../components/warden-skin") {
74
+ hasWardenSkinImport = true;
75
+ }
69
76
  },
70
77
  });
71
78
  if (layoutNames.size === 0)
@@ -73,33 +80,34 @@ async function patchLayoutFile(filePath) {
73
80
  // 2. 修改 JSX
74
81
  (0, traverse_1.default)(ast, {
75
82
  JSXOpeningElement(path) {
76
- if (!t.isJSXIdentifier(path.node.name))
83
+ const name = path.node.name;
84
+ if (!t.isJSXIdentifier(name))
77
85
  return;
78
- const name = path.node.name.name;
79
- // 关键:只处理来自 layout package 的组件
80
- if (!layoutNames.has(name))
86
+ if (!layoutNames.has(name.name))
81
87
  return;
82
- const hasThemeSkins = path.node.attributes.some(attr => t.isJSXAttribute(attr) &&
83
- t.isJSXIdentifier(attr.name) &&
84
- attr.name.name === "themeSkins");
85
- if (hasThemeSkins)
88
+ if (hasThemeSkinsProp(path.node))
86
89
  return;
87
90
  path.node.attributes.push(t.jsxAttribute(t.jsxIdentifier("themeSkins"), t.jsxExpressionContainer(t.identifier("wardenSkin"))));
88
91
  changed = true;
89
- },
92
+ }
90
93
  });
91
94
  if (!changed)
92
95
  return;
93
96
  // 3. 注入 import(只在 layouts 文件里)
94
- if (!hasImport) {
97
+ if (!hasWardenSkinImport) {
95
98
  ast.program.body.unshift(t.importDeclaration([
96
- t.importDefaultSpecifier(t.identifier("wardenSkin")),
99
+ t.importDefaultSpecifier(t.identifier("wardenSkin"))
97
100
  ], t.stringLiteral("@/components/warden-skin")));
98
101
  }
99
102
  const output = (0, generator_1.default)(ast, {}, code);
100
103
  await fs_extra_1.default.writeFile(filePath, output.code);
101
104
  console.log("✔ updated:", path_1.default.relative(process.cwd(), filePath));
102
105
  }
106
+ function hasThemeSkinsProp(node) {
107
+ return node.attributes.some(attr => t.isJSXAttribute(attr) &&
108
+ t.isJSXIdentifier(attr.name) &&
109
+ attr.name.name === "themeSkins");
110
+ }
103
111
  async function getLayoutFiles(dir) {
104
112
  const result = [];
105
113
  const items = await fs_extra_1.default.readdir(dir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-antd-skin",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "this is skin-cli for @adminui-dev/antd-layout",
5
5
  "main": "index.js",
6
6
  "author": "zhouwenqi",