Skip to content

Commit

Permalink
perf: update package.json directly for dependency
Browse files Browse the repository at this point in the history
- use @npmcli/package-json
 - to update pkg.json directly without installig
 - to add scripts
  • Loading branch information
MomenSherif committed Jan 24, 2022
1 parent f95d88c commit 073bef0
Show file tree
Hide file tree
Showing 16 changed files with 301 additions and 166 deletions.
86 changes: 63 additions & 23 deletions package-lock.json

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

7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,15 @@
},
"homepage": "https://github.com/MomenSherif/create-react-linters#readme",
"engines": {
"node": "^12.22.0 || ^14.17.0 || >=16.0.0",
"npm": ">=7.0.0"
"node": "^12.22.0 || ^14.17.0 || >=16.0.0"
},
"dependencies": {
"@babel/runtime": "^7.16.7",
"@npmcli/package-json": "^1.0.1",
"ansi-colors": "^4.1.1",
"enquirer": "^2.3.6",
"fs-extra": "^10.0.0"
"fs-extra": "^10.0.0",
"pretty-ms": "^7.0.1"
},
"devDependencies": {
"@babel/cli": "^7.16.8",
Expand Down
45 changes: 44 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,50 @@
import Path from 'path';

const CONSTANTS = {
import { Packages } from '@types';

type Constants = {
configFolder: string;
packages: Record<Packages, string>;
};

const CONSTANTS: Constants = {
configFolder: Path.join(__dirname, './configurations'),
packages: {
// eslint
eslint: '^8.7.0',
'eslint-config-airbnb': '^19.0.4',
'eslint-config-airbnb-typescript': '^16.1.0',
'@typescript-eslint/eslint-plugin': '^5.10.0',
'@typescript-eslint/parser': '^5.10.0',
'eslint-plugin-import': '^2.25.4',
'eslint-plugin-jsx-a11y': '^6.5.1',
'eslint-plugin-react': '^7.28.0',
'eslint-plugin-react-hooks': '^4.3.0',
'eslint-plugin-jest': '^26.0.0',
'eslint-plugin-jest-dom': '^4.0.1',
'eslint-plugin-testing-library': '^5.0.4',
// stylelint
stylelint: '^14.3.0',
'stylelint-config-standard': '^24.0.0',
'stylelint-config-standard-scss': '^3.0.0',
//commitlint
'@commitlint/cli': '^16.1.0',
'@commitlint/config-conventional': '^16.0.0',
// prettier
prettier: '2.5.1',
'eslint-config-prettier': '^8.3.0',
'eslint-plugin-prettier': '^4.0.0',
'stylelint-config-prettier': '^9.0.3',
'stylelint-prettier': '^2.0.0',
// commitizen
commitizen: '^4.2.4',
'cz-conventional-changelog': '^3.3.0',
// husky & lint-staged
'cross-env': '^7.0.3',
husky: '^7.0.4',
'is-ci': '^3.0.1',
'lint-staged': '^12.3.1',
},
};

export default CONSTANTS;
22 changes: 11 additions & 11 deletions src/generators/commitizen.generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ import pkgManager from '@utils/pkgManager';
export default async function commitizenConfigGenerator() {
console.log(c.blue('\nConfiguring Commitizen 🔨 🔨'));

await pkgManager.install(['commitizen', 'cz-conventional-changelog']);
await pkgManager.addDevDeps(['commitizen', 'cz-conventional-changelog']);

const packageJson = await fse.readJSON('package.json');

packageJson.config = {
commitizen: {
path: 'cz-conventional-changelog',
await pkgManager.update({
config: {
commitizen: {
path: 'cz-conventional-changelog',
},
},
};

await fse.writeJSON('package.json', packageJson, { spaces: 2 });
});

await pkgManager.runCommand('npm set-script commit "cz"');
await pkgManager.addScripts({
commit: 'cz',
});

console.log(c.blue('Commtizien successfully configured 🎉 🎉'));
console.log(c.blue('\nCommtizien successfully configured 🎉 🎉'));
}
4 changes: 2 additions & 2 deletions src/generators/commitlint.generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import pkgManager from '@utils/pkgManager';
export default async function commitlintConfigGenerator() {
console.log(c.blue('\nConfiguring Commitlint 🔨 🔨'));

await pkgManager.install([
await pkgManager.addDevDeps([
'@commitlint/cli',
'@commitlint/config-conventional',
]);
Expand All @@ -18,5 +18,5 @@ export default async function commitlintConfigGenerator() {
{ spaces: 2 },
);

console.log(c.blue('Commitlint successfully configured 🎉 🎉'));
console.log(c.blue('\nCommitlint successfully configured 🎉 🎉'));
}
4 changes: 2 additions & 2 deletions src/generators/editorconfig.generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import c from 'ansi-colors';
import CONSTANTS from '@constants';

export default async function editorConfigGenerator() {
console.log(c.blue('\nConfiguring EditorConfig 🔨 🔨\n'));
console.log(c.blue('\nConfiguring EditorConfig 🔨 🔨'));

const file = await fse.readFile(
path.join(CONSTANTS.configFolder, '.editorconfig'),
);

await fse.writeFile('.editorconfig', file);

console.log(c.blue('EditorConfig successfully configured 🎉 🎉'));
console.log(c.blue('\nEditorConfig successfully configured 🎉 🎉'));
}
Loading

0 comments on commit 073bef0

Please sign in to comment.