Skip to content

Commit

Permalink
feat: generator template replace husky to simple git hook (#6180)
Browse files Browse the repository at this point in the history
  • Loading branch information
caohuilin authored Sep 6, 2024
1 parent d6e0118 commit 28f0101
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 63 deletions.
11 changes: 11 additions & 0 deletions .changeset/tough-ligers-exercise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
'@modern-js/upgrade-generator': patch
'@modern-js/module-generator': patch
'@modern-js/base-generator': patch
'@modern-js/mwa-generator': patch
'@modern-js/prod-server': patch
---

feat: generator replace husky to simple git hook

feat: 生成器模板替换 husky 为 simple-git-hook
2 changes: 0 additions & 2 deletions packages/generator/generators/base-generator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ const handleTemplateFile = async (
.replace('.handlebars', ''),
);
}

fs.chmodSync(path.join(generator.outputPath, '.husky', 'pre-commit'), '755');
};

export default async (context: GeneratorContext, generator: GeneratorCore) => {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{{#if isMonorepoSubProject}}
"prepare": "modern build",
{{else}}
"prepare": "modern build && husky install",
"prepare": "modern build && simple-git-hooks",
{{/if}}
"dev": "modern dev",
"build": "modern build",
Expand All @@ -34,6 +34,9 @@
"node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"
]
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"eslintIgnore": [
"node_modules/",
"dist/"
Expand All @@ -51,7 +54,7 @@
"rimraf": "~3.0.2",
"lint-staged": "~13.1.0",
"prettier": "~2.8.1",
"husky": "~8.0.1"
"simple-git-hooks": "^2.11.1"
},
"sideEffects": [],
"publishConfig": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"new": "modern new",
"lint": "modern lint",
{{#unless isMonorepoSubProject}}
"prepare": "husky install",
"prepare": "simple-git-hooks",
{{/unless}}
"upgrade": "modern upgrade"
},
Expand All @@ -23,6 +23,9 @@
"node --max_old_space_size=8192 ./node_modules/eslint/bin/eslint.js --fix --color --cache --quiet"
]
},
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"eslintIgnore": [
"node_modules/",
"dist/"
Expand All @@ -47,7 +50,7 @@
{{/if}}
"lint-staged": "~13.1.0",
"prettier": "~2.8.1",
"husky": "~8.0.1",
"simple-git-hooks": "^2.11.1",
"rimraf": "~3.0.2"
}
}
39 changes: 0 additions & 39 deletions packages/generator/generators/upgrade-generator/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,45 +181,6 @@ export const handleTemplateFile = async (

spinner.stop();

// update husky
const huskyVersion = deps.husky;
try {
if (huskyVersion && semver.lt(huskyVersion, '8.0.0')) {
generator.logger.info(`${i18n.t(localeKeys.updateHusky)}`);
await jsonAPI.update(
context.materials.default.get(path.join(appDir, 'package.json')),
{
query: {},
update: {
$set: {
'devDependencies.husky': '^8.0.0',
},
},
},
);

const pkgPath = context.materials.default.get(
path.join(appDir, 'package.json'),
).filePath;
const pkgInfo = fs.readJSONSync(pkgPath, 'utf-8');
const { prepare } = pkgInfo.scripts;
if (!prepare) {
pkgInfo.scripts.prepare = 'husky install';
} else if (!prepare.includes('husky install')) {
pkgInfo.scripts.prepare = `${prepare} && husky install`;
}
pkgInfo.husky = undefined;

fs.writeJSONSync(pkgPath, pkgInfo, { spaces: 2 });

await appApi.forgeTemplate('templates/**/*');
fs.chmodSync(
path.join(generator.outputPath, '.husky', 'pre-commit'),
'755',
);
}
} catch (e) {}

await appApi.runInstall();

appApi.showSuccessInfo(i18n.t(localeKeys.success));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ export const EN_LOCALE = {
'The project is not allowed to contain more than one solution tool',
},
success: 'Upgrade Modern.js package version success!',
updateHusky: 'Upgrade husky to v8',
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,4 @@ export const ZH_LOCALE = {
'项目中不允许同时包含多种工程方案相关依赖,请先移除不相关的工程方案依赖。',
},
success: '已更新 Modern.js 依赖至最新版本',
updateHusky: '升级 Husky 至 v8',
};

This file was deleted.

1 change: 0 additions & 1 deletion packages/server/prod-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
"@types/merge-deep": "^3.0.0",
"@types/node": "~16.11.7",
"@types/source-map-support": "0.5.10",
"husky": "^8.0.0",
"jest": "^29",
"lint-staged": "~13.1.0",
"prettier": "^2.8.1",
Expand Down
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion tests/integration/module/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
"@types/jest": "^29",
"@types/node": "~16.11.7",
"@types/react": "^18",
"husky": "^8.0.0",
"lint-staged": "~13.1.0",
"path-browserify": "1.0.1",
"prettier": "^2.8.1",
Expand Down

0 comments on commit 28f0101

Please sign in to comment.