diff --git a/package.json b/package.json index 0813599..f7e423f 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "colors": "1.4.0", "cosmiconfig": "6.0.0", "gluegun": "4.1.2", - "isomorphic-git": "0.78.5", + "isomorphic-git": "1.0.0", "latest-version": "5.1.0", "prompts": "2.3.1", "tslib": "1.11.0" diff --git a/src/commands/add/prettier.ts b/src/commands/add/prettier.ts index 835ad70..e1cdd89 100644 --- a/src/commands/add/prettier.ts +++ b/src/commands/add/prettier.ts @@ -2,7 +2,6 @@ import { BaseCommand } from '../../utls/base-command'; import { system, filesystem } from 'gluegun'; import * as prompts from 'prompts'; -import { add, commit } from 'isomorphic-git'; import { BaseAddCommand } from '../../utls/base-add-command'; export default class Prettier extends BaseAddCommand { @@ -70,9 +69,8 @@ export default class Prettier extends BaseAddCommand { await system.exec('yarn'); if (shouldCommit) { - await add({ filepath: 'package.json', dir: '.' }); - await commit({ - dir: '.', + await this.gitAdd({ filepath: 'package.json' }); + await this.gitCommit({ message: ':wrench: add script and husky to package.json', }); } @@ -92,9 +90,8 @@ export default class Prettier extends BaseAddCommand { }); if (shouldCommit) { - await add({ filepath: '.prettierrc', dir: '.' }); - await commit({ - dir: '.', + await this.gitAdd({ filepath: '.prettierrc' }); + await this.gitCommit({ message: ':wrench: add prettierrc config file', }); } @@ -105,8 +102,7 @@ export default class Prettier extends BaseAddCommand { if (shouldCommit) { await this.gitAddUnstaged(); - await commit({ - dir: '.', + await this.gitCommit({ message: ':art: apply prettier style to project', }); } @@ -160,9 +156,8 @@ export default class Prettier extends BaseAddCommand { await filesystem.write(eslintPath, finalEslintConfig, { jsonIndent: 2 }); if (shouldCommit) { - await add({ filepath: eslintFileName, dir: '.' }); - await commit({ - dir: '.', + await this.gitAdd({ filepath: eslintFileName }); + await this.gitCommit({ message: ':wrench: update eslint to use prettier', }); } @@ -207,9 +202,8 @@ export default class Prettier extends BaseAddCommand { await filesystem.write(tslintPath, finalEslintConfig, { jsonIndent: 2 }); if (shouldCommit) { - await add({ filepath: 'tslint.json', dir: '.' }); - await commit({ - dir: '.', + await this.gitAdd({ filepath: 'tslint.json' }); + await this.gitCommit({ message: ':wrench: update tslint to use prettier', }); } diff --git a/src/commands/add/tailwind.ts b/src/commands/add/tailwind.ts index 4429eee..5f3c48d 100644 --- a/src/commands/add/tailwind.ts +++ b/src/commands/add/tailwind.ts @@ -1,7 +1,6 @@ import { BaseCommand } from '../../utls/base-command'; import { system, filesystem, patching } from 'gluegun'; import * as prompts from 'prompts'; -import { add, commit } from 'isomorphic-git'; import { BaseAddCommand } from '../../utls/base-add-command'; export default class Tailwind extends BaseAddCommand { @@ -50,9 +49,8 @@ export default class Tailwind extends BaseAddCommand { await system.exec('yarn tailwindcss init --full'); if (shouldCommit) { - await add({ filepath: 'tailwind.config.js', dir: '.' }); - await commit({ - dir: '.', + await this.gitAdd({ filepath: 'tailwind.config.js' }); + await this.gitCommit({ message: ':wrench: add tailwind config file', }); } @@ -77,8 +75,8 @@ module.exports = { ); if (shouldCommit) { - await add({ filepath: 'postcss.config.js', dir: '.' }); - await commit({ dir: '.', message: ':wrench: add postcss config file' }); + await this.gitAdd({ filepath: 'postcss.config.js' }); + await this.gitCommit({ message: ':wrench: add postcss config file' }); } }); @@ -95,8 +93,8 @@ module.exports = { ); if (shouldCommit) { - await add({ filepath: 'src/css/tailwind.src.css', dir: '.' }); - await commit({ dir: '.', message: ':wrench: add tailwind css file' }); + await this.gitAdd({ filepath: 'src/css/tailwind.src.css' }); + await this.gitCommit({ message: ':wrench: add tailwind css file' }); } }); @@ -119,9 +117,8 @@ module.exports = { await filesystem.write(packagePath, finalPackageJson, { jsonIndent: 2 }); if (shouldCommit) { - await add({ filepath: 'package.json', dir: '.' }); - await commit({ - dir: '.', + await this.gitAdd({ filepath: 'package.json' }); + await this.gitCommit({ message: ':wrench: add script for tailwind to package.json', }); } @@ -131,9 +128,8 @@ module.exports = { await patching.append('.gitignore', '\n# ignore tailwind generated css\nsrc/tailwind.css'); if (shouldCommit) { - await add({ filepath: '.gitignore', dir: '.' }); - await commit({ - dir: '.', + await this.gitAdd({ filepath: '.gitignore' }); + await this.gitCommit({ message: ':see_no_evil: add generated tailwind to .gitignore', }); } diff --git a/src/utls/base-add-command.ts b/src/utls/base-add-command.ts index 0f3b453..2486482 100644 --- a/src/utls/base-add-command.ts +++ b/src/utls/base-add-command.ts @@ -1,11 +1,9 @@ import { BaseCommand } from './base-command'; -import { add, plugins, commit, config as gitConfig, statusMatrix } from 'isomorphic-git'; +import { add, commit, setConfig, statusMatrix } from 'isomorphic-git'; import * as latestVersion from 'latest-version'; import { filesystem, system } from 'gluegun'; import * as fs from 'fs'; -plugins.set('fs', fs); - export abstract class BaseAddCommand extends BaseCommand { static flags = { ...BaseCommand.flags, @@ -20,12 +18,14 @@ export abstract class BaseAddCommand extends BaseCommand { this.error('Missing config key git.email for git commits'); } try { - await gitConfig({ + await setConfig({ + fs, dir: '.', path: 'user.name', value: config?.git?.user, }); - await gitConfig({ + await setConfig({ + fs, dir: '.', path: 'user.email', value: config?.git?.email, @@ -33,14 +33,26 @@ export abstract class BaseAddCommand extends BaseCommand { } catch { this.error('Could not set git config. Maybe the command was not run in a git repository.'); } - const changes = (await statusMatrix({ dir: '.', pattern: '**' })).filter( - ([_, head, workdir]) => head !== workdir, + const changes = (await statusMatrix({ dir: '.', fs })).filter( + ([, head, workdir]) => head !== workdir, ); if (changes.length > 0) { this.error('There is unsaved changed in the git repository, aborting'); } } + async gitAdd({ filepath, dir = '.' }: { filepath: string; dir?: string }) { + await add({ filepath, dir, fs }); + } + + async gitCommit({ message }: { message: string }) { + await commit({ + dir: '.', + fs, + message, + }); + } + hasDirPackageJson() { return filesystem.isFile(filesystem.path('.', 'package.json')); } @@ -62,10 +74,10 @@ export abstract class BaseAddCommand extends BaseCommand { } async gitAddUnstaged() { - const commitsPromice = (await statusMatrix({ dir: '.', pattern: '**' })) - .filter(([_, head, workdir]) => head !== workdir) + const commitsPromice = (await statusMatrix({ dir: '.', fs })) + .filter(([, head, workdir]) => head !== workdir) .map(arr => arr[0]) - .map(filepath => add({ filepath, dir: '.' })); + .map(filepath => this.gitAdd({ filepath })); await Promise.all(commitsPromice); } @@ -75,10 +87,9 @@ export abstract class BaseAddCommand extends BaseCommand { const versionToInstall = await latestVersion(name); await system.exec(`yarn add -D ${name}@${versionToInstall}`); if (shouldCommit) { - await add({ filepath: 'package.json', dir: '.' }); - await add({ filepath: 'yarn.lock', dir: '.' }); - await commit({ - dir: '.', + await this.gitAdd({ filepath: 'package.json' }); + await this.gitAdd({ filepath: 'yarn.lock' }); + await this.gitCommit({ message: `:heavy_plus_sign: add ${name}@${versionToInstall} as a dev dependency`, }); } @@ -90,10 +101,9 @@ export abstract class BaseAddCommand extends BaseCommand { const versionToInstall = await latestVersion(name); await system.exec(`yarn add ${name}@${versionToInstall}`); if (shouldCommit) { - await add({ filepath: 'package.json', dir: '.' }); - await add({ filepath: 'yarn.lock', dir: '.' }); - await commit({ - dir: '.', + await this.gitAdd({ filepath: 'package.json' }); + await this.gitAdd({ filepath: 'yarn.lock' }); + await this.gitCommit({ message: `:heavy_plus_sign: add ${name}@${versionToInstall} as a dependency`, }); } diff --git a/yarn.lock b/yarn.lock index 9053fd4..af76982 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3998,11 +3998,6 @@ globals@^12.1.0: dependencies: type-fest "^0.8.1" -globalyzer@^0.1.4: - version "0.1.4" - resolved "https://registry.yarnpkg.com/globalyzer/-/globalyzer-0.1.4.tgz#bc8e273afe1ac7c24eea8def5b802340c5cc534f" - integrity sha512-LeguVWaxgHN0MNbWC6YljNMzHkrCny9fzjmEUdnF1kQ7wATFD1RHFRqA1qxaX2tgxGENlcxjOflopBwj3YZiXA== - globby@11.0.0, globby@^11.0.0: version "11.0.0" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.0.tgz#56fd0e9f0d4f8fb0c456f1ab0dee96e1380bc154" @@ -4029,11 +4024,6 @@ globby@^10.0.1: merge2 "^1.2.3" slash "^3.0.0" -globrex@^0.1.2: - version "0.1.2" - resolved "https://registry.yarnpkg.com/globrex/-/globrex-0.1.2.tgz#dd5d9ec826232730cd6793a5e33a9302985e6098" - integrity sha512-uHJgbwAMwNFf5mLst7IWLNg14x1CkeqglJb/K3doi4dw6q2IvAAmM/Y81kevy83wP+Sst+nutFTYOGg3d1lsxg== - gluegun@4.1.2: version "4.1.2" resolved "https://registry.yarnpkg.com/gluegun/-/gluegun-4.1.2.tgz#75b887450de2ebdc6656b598e5942b9a33157d06" @@ -4815,20 +4805,17 @@ isobject@^4.0.0: resolved "https://registry.yarnpkg.com/isobject/-/isobject-4.0.0.tgz#3f1c9155e73b192022a80819bacd0343711697b0" integrity sha512-S/2fF5wH8SJA/kmwr6HYhK/RI/OkhD84k8ntalo0iJjZikgq1XFvR5M8NPT1x5F7fBwCG3qHfnzeP/Vh/ZxCUA== -isomorphic-git@0.78.5: - version "0.78.5" - resolved "https://registry.yarnpkg.com/isomorphic-git/-/isomorphic-git-0.78.5.tgz#013f8f8c280b8e0f8bb10ffa251eb87e9bb1190b" - integrity sha512-LrF5t9x7RdFeg84NsYpZo9qF1MZeb56LpBm6Jv47qMjnWMv0Il/3wPTA8I/lUYywgVbvF/e7xypHauj5auKW3w== +isomorphic-git@1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/isomorphic-git/-/isomorphic-git-1.0.0.tgz#6220fd649bc56ea447c6e75fb76d175a8a6dfeb5" + integrity sha512-YwyHqWP8ZGgb3Ul3HOg1MKSXD52ogWI4V3r58ck+EGuGKyXJYjxEjCRXeFEqOX3cxZRxvRyS1nD2J4at/l6fLQ== dependencies: async-lock "^1.1.0" clean-git-ref "^2.0.1" crc-32 "^1.2.0" diff3 "0.0.3" git-apply-delta "0.0.7" - globalyzer "^0.1.4" - globrex "^0.1.2" ignore "^5.1.4" - marky "^1.2.1" minimisted "^2.0.0" pako "^1.0.10" pify "^4.0.1" @@ -6021,11 +6008,6 @@ marked@^0.8.0: resolved "https://registry.yarnpkg.com/marked/-/marked-0.8.0.tgz#ec5c0c9b93878dc52dd54be8d0e524097bd81a99" integrity sha512-MyUe+T/Pw4TZufHkzAfDj6HarCBWia2y27/bhuYkTaiUnfDYFnCP3KUN+9oM7Wi6JA2rymtVYbQu3spE0GCmxQ== -marky@^1.2.1: - version "1.2.1" - resolved "https://registry.yarnpkg.com/marky/-/marky-1.2.1.tgz#a3fcf82ffd357756b8b8affec9fdbf3a30dc1b02" - integrity sha512-md9k+Gxa3qLH6sUKpeC2CNkJK/Ld+bEz5X96nYwloqphQE0CKCVEKco/6jxEZixinqNdz5RFi/KaCyfbMDMAXQ== - meant@~1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/meant/-/meant-1.0.1.tgz#66044fea2f23230ec806fb515efea29c44d2115d"