zixulu 1.71.1 → 1.71.3
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/dist/index.js +3 -106
- package/dist/index.js.map +1 -1
- package/package.json +25 -27
- package/src/index.ts +1 -0
- package/src/utils/addPrettier.ts +3 -121
- package/src/utils/installDependceny.ts +1 -0
package/dist/index.js
CHANGED
|
@@ -1421,126 +1421,23 @@ const config = {
|
|
|
1421
1421
|
arrowParens: "avoid",
|
|
1422
1422
|
endOfLine: "lf",
|
|
1423
1423
|
printWidth: 160,
|
|
1424
|
-
plugins: ["
|
|
1424
|
+
plugins: ["@1adybug/prettier"],
|
|
1425
1425
|
controlStatementBraces: "add",
|
|
1426
1426
|
}
|
|
1427
1427
|
|
|
1428
1428
|
export default config
|
|
1429
1429
|
`;
|
|
1430
|
-
function getPluginConfig({ isTailwind, isReact }) {
|
|
1431
|
-
const config = `// @ts-check
|
|
1432
|
-
|
|
1433
|
-
import { readFileSync } from "fs"
|
|
1434
|
-
import { builtinModules } from "module"
|
|
1435
|
-
|
|
1436
|
-
import removeBraces from "@1adybug/prettier-plugin-remove-braces"
|
|
1437
|
-
import { createPlugin } from "@1adybug/prettier-plugin-sort-imports"
|
|
1438
|
-
import JSON5 from "json5"
|
|
1439
|
-
import blockPadding from "prettier-plugin-block-padding"${isTailwind ? `
|
|
1440
|
-
import * as tailwindcss from "prettier-plugin-tailwindcss"` : ""}
|
|
1441
|
-
${isReact ? `
|
|
1442
|
-
/**
|
|
1443
|
-
* @param {string} path
|
|
1444
|
-
*/
|
|
1445
|
-
function isReact(path) {
|
|
1446
|
-
return /^@?react\\b/.test(path)
|
|
1447
|
-
}
|
|
1448
|
-
` : ""}
|
|
1449
|
-
/**
|
|
1450
|
-
* @param {string} path
|
|
1451
|
-
*/
|
|
1452
|
-
function isBuiltin(path) {
|
|
1453
|
-
return path.startsWith("node:") || builtinModules.includes(path)
|
|
1454
|
-
}
|
|
1455
|
-
|
|
1456
|
-
/** @type {string[]} */
|
|
1457
|
-
let pathAlias = []
|
|
1458
|
-
|
|
1459
|
-
try {
|
|
1460
|
-
const tsConfig = JSON5.parse(readFileSync("tsconfig.json", "utf-8"))
|
|
1461
|
-
pathAlias = Object.keys(tsConfig.compilerOptions?.paths ?? {})
|
|
1462
|
-
.map(item => item.match(/^(@.*\\/)\\*/))
|
|
1463
|
-
.filter(Boolean)
|
|
1464
|
-
.map(item => /** @type {string} */ (item?.[1]))
|
|
1465
|
-
} catch {}
|
|
1466
|
-
|
|
1467
|
-
/**
|
|
1468
|
-
* @param {string} path
|
|
1469
|
-
*/
|
|
1470
|
-
function isAbsolute(path) {
|
|
1471
|
-
return pathAlias.some(item => path.startsWith(item))
|
|
1472
|
-
}
|
|
1473
|
-
|
|
1474
|
-
/**
|
|
1475
|
-
* @param {string} path
|
|
1476
|
-
*/
|
|
1477
|
-
function isRelative(path) {
|
|
1478
|
-
return path.startsWith("./") || path.startsWith("../")
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
/**
|
|
1482
|
-
* @param {string} a
|
|
1483
|
-
* @param {string} b
|
|
1484
|
-
*/
|
|
1485
|
-
function compareGroupName(a, b) {
|
|
1486
|
-
const orders = [${isReact ? '"react", ' : ""}"builtin", "third-party", "absolute", "relative"]
|
|
1487
|
-
|
|
1488
|
-
a = a.replace(/-side-effect$/, "")
|
|
1489
|
-
b = b.replace(/-side-effect$/, "")
|
|
1490
|
-
return orders.indexOf(a) - orders.indexOf(b) || a.localeCompare(b)
|
|
1491
|
-
}
|
|
1492
|
-
|
|
1493
|
-
export default createPlugin({
|
|
1494
|
-
getGroup({ path, isSideEffect }) {
|
|
1495
|
-
if (isSideEffect) {${isReact ? `
|
|
1496
|
-
if (isReact(path)) return "react-side-effect"` : ""}
|
|
1497
|
-
if (isBuiltin(path)) return "builtin-side-effect"
|
|
1498
|
-
if (isAbsolute(path)) return "absolute-side-effect"
|
|
1499
|
-
if (isRelative(path)) return "relative-side-effect"
|
|
1500
|
-
return "third-party-side-effect"
|
|
1501
|
-
}
|
|
1502
|
-
${isReact ? `
|
|
1503
|
-
if (isReact(path)) return "react"` : ""}
|
|
1504
|
-
if (isBuiltin(path)) return "builtin"
|
|
1505
|
-
if (isAbsolute(path)) return "absolute"
|
|
1506
|
-
if (isRelative(path)) return "relative"
|
|
1507
|
-
return "third-party"
|
|
1508
|
-
},
|
|
1509
|
-
sortGroup(a, b) {
|
|
1510
|
-
return (
|
|
1511
|
-
Number(a.isSideEffect) - Number(b.isSideEffect) ||
|
|
1512
|
-
compareGroupName(a.name, b.name)
|
|
1513
|
-
)
|
|
1514
|
-
},
|
|
1515
|
-
separator: "",
|
|
1516
|
-
sortSideEffect: true,
|
|
1517
|
-
removeUnusedImports: true,
|
|
1518
|
-
otherPlugins: [blockPadding${isTailwind ? ", tailwindcss" : ""}, removeBraces],
|
|
1519
|
-
})
|
|
1520
|
-
`;
|
|
1521
|
-
return config;
|
|
1522
|
-
}
|
|
1523
1430
|
async function addPrettier() {
|
|
1524
1431
|
consola_0.start("开始添加 prettier 配置");
|
|
1525
|
-
const packageJson = await readPackageJson();
|
|
1526
|
-
const isTailwind = Object.keys(packageJson.dependencies ?? {}).includes("tailwindcss") || Object.keys(packageJson.devDependencies ?? {}).includes("tailwindcss");
|
|
1527
|
-
const isReact = await hasDependency("react");
|
|
1528
|
-
await writeFile("prettier-plugin-sort-imports.mjs", getPluginConfig({
|
|
1529
|
-
isTailwind,
|
|
1530
|
-
isReact
|
|
1531
|
-
}), "utf-8");
|
|
1532
1432
|
await writeFile("prettier.config.mjs", prettierConfig, "utf-8");
|
|
1533
1433
|
await writeFile(".prettierignore", ignoreConfig, "utf-8");
|
|
1534
1434
|
const config2 = {
|
|
1535
1435
|
package: [
|
|
1536
1436
|
"prettier",
|
|
1537
|
-
"@1adybug/prettier
|
|
1538
|
-
"prettier-plugin-block-padding",
|
|
1539
|
-
"json5"
|
|
1437
|
+
"@1adybug/prettier"
|
|
1540
1438
|
],
|
|
1541
1439
|
type: "devDependencies"
|
|
1542
1440
|
};
|
|
1543
|
-
if (isTailwind) config2.package.push("prettier-plugin-tailwindcss");
|
|
1544
1441
|
await addDependency(config2);
|
|
1545
1442
|
const packageJson2 = await readPackageJson();
|
|
1546
1443
|
packageJson2.scripts ??= {};
|
|
@@ -1579,7 +1476,7 @@ async function addPrettier() {
|
|
|
1579
1476
|
}
|
|
1580
1477
|
try {
|
|
1581
1478
|
consola_0.start("配置 pre-commit hook");
|
|
1582
|
-
const preCommitHook = "
|
|
1479
|
+
const preCommitHook = "npx lint-staged";
|
|
1583
1480
|
await writeFile(".husky/pre-commit", preCommitHook, "utf-8");
|
|
1584
1481
|
consola_0.success("pre-commit hook 配置成功");
|
|
1585
1482
|
} catch (error) {
|