diff --git a/README.md b/README.md index dedfa699..18a7ae03 100644 --- a/README.md +++ b/README.md @@ -29,13 +29,13 @@ are not necessary to explicitly install: ## Usage ``` -npx d2-style --help +yarn d2-style --help -npx d2-style install --help +yarn d2-style install --help -npx d2-style js --help -npx d2-style js check --help -npx d2-style js apply --help +yarn d2-style js --help +yarn d2-style js check --help +yarn d2-style js apply --help ``` ## Report an issue diff --git a/config/git/hooks/commit-msg b/config/git/hooks/commit-msg new file mode 100755 index 00000000..3be737cd --- /dev/null +++ b/config/git/hooks/commit-msg @@ -0,0 +1,2 @@ +#!/bin/sh +yarn d2-style commit check "$1" diff --git a/docs/faq.md b/docs/faq.md index 27379fd6..af77f5df 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -6,11 +6,13 @@ Some wisdom from Go: # I'm getting husky errors -This library depends on husky, which requires node >= 10 and git >= 2.13.0. If you're getting errors like this: +This library as of version 8.0.0 no longer depends on husky, so if you +are getting errors like: ``` Can't find Husky, skipping pre-commit hook You can reinstall it using 'npm install husky --save-dev' or delete this hook ``` -Ensure that your node and git versions satisfy the above requirements. You can check this by running `git --version` and `node --version` from your terminal. +You can remove the husky hooks from `.git/hooks` and opt in to use the +hooks provided here with e.g. `d2-style install git-hooks/all`. diff --git a/docs/getting-started.md b/docs/getting-started.md index 9aa7fe6a..a84efd79 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -41,7 +41,7 @@ repository for you. For a list of valid groups and what tools they will configure, use: ```bash -npx d2-style install --list-groups +yarn d2-style install --list-groups ``` Run `install` without arguments to get an interactive mode where it is @@ -65,16 +65,11 @@ specification and get the standard [EditorConfig](https://editorconfig.org/): ``` -npx d2-style install project/base +yarn d2-style install project/base -# * project/base (includes: tools/editorconfig, git/husky) +# * project/base (includes: tools/editorconfig, git-hooks/commit-msg) ``` -This gives you a starting point, and after that it is possible to extend -the `.huskyrc.js` configuration with specific hooks, see -[config/husky-frontend.local.js](config/husky-frontend.local.js) for an -example on how to extend the configuration file for Husky. - For example, most repos has structured text in the form of YAML or Markdown, so adding a pre-commit hook to validate the format of that makes sense in most cases. @@ -87,10 +82,10 @@ configuration. It does not use any framework specific rules and should be applicable to any JavaScript project. ``` -npx d2-style install project/js +yarn d2-style install project/js # * project/js (includes: tools/all, github/all, linter/eslint, -# formatter/prettier, git/husky-frontend) +# formatter/prettier, git/commit-msg) ``` ### React @@ -99,8 +94,8 @@ The `project/react` should be a good starting point for a React project, as it adds `eslint-plugin-react`. ``` -npx d2-style install project/react +yarn d2-style install project/react # * project/react (includes: base/all, github/all, linter/eslint-react, -# formatter/prettier, git/husky-frontend) +# formatter/prettier, git/commit-msg) ``` diff --git a/docs/migrate-guide.md b/docs/migrate-guide.md index a29533ac..2a2db599 100644 --- a/docs/migrate-guide.md +++ b/docs/migrate-guide.md @@ -37,13 +37,13 @@ it, only to install it fresh after. ```bash # no assumption about the project - npx d2-style install project/base --force + yarn d2-style install project/base --force # assuming a javascript project - npx d2-style install project/js --force + yarn d2-style install project/js --force # assuming a react project - npx d2-style install project/react --force + yarn d2-style install project/react --force ``` (You did take a backup of modified configuration files earlier, right?) diff --git a/src/commands/install.js b/src/commands/install.js index da989082..f3d8325e 100644 --- a/src/commands/install.js +++ b/src/commands/install.js @@ -1,7 +1,5 @@ const { reporter, prompt } = require('@dhis2/cli-helpers-engine') -const { log } = reporter - const { configure } = require('../utils/config.js') const { printGroups, projects } = require('../utils/groups.js') @@ -36,7 +34,7 @@ exports.builder = { exports.handler = async argv => { if (argv.listGroups) { - log.print(printGroups()) + reporter.print(printGroups()) process.exit(0) } diff --git a/src/utils/groups.js b/src/utils/groups.js index bb6d16ee..4534a538 100644 --- a/src/utils/groups.js +++ b/src/utils/groups.js @@ -2,9 +2,9 @@ const path = require('path') const { BROWSERSLIST_CONFIG, + COMMIT_MSG_HOOK, ESLINT_CONFIG, ESLINT_REACT_CONFIG, - HUSKY_CONFIG, PRETTIER_CONFIG, STALE_CONFIG, DEPENDABOT_CONFIG, @@ -14,8 +14,6 @@ const { LOCAL_ESLINT_REACT_CONFIG, LOCAL_PRETTIER_CONFIG, LOCAL_ESLINT_CONFIG, - LOCAL_HUSKY_CONFIG, - LOCAL_HUSKY_FRONTEND_CONFIG, } = require('./paths.js') /** @@ -24,7 +22,7 @@ const { * * The format of a selector is: 'identifier/specifier', e.g. * - * git/husky + * git/hooks * * This is represented by a multi-dimensional array: * @@ -58,12 +56,11 @@ const groups = [ [['prettier', [LOCAL_PRETTIER_CONFIG, path.join('.prettierrc.js')]]], ], [ - 'git', + 'git-hooks', [ - ['husky', [LOCAL_HUSKY_CONFIG, path.join('.huskyrc.js')]], [ - 'husky-frontend', - [LOCAL_HUSKY_FRONTEND_CONFIG, path.join('.huskyrc.js')], + 'commit-msg', + [COMMIT_MSG_HOOK, path.join('.git', 'hooks', 'commit-msg')], ], ], ], @@ -102,7 +99,7 @@ const groups = [ * wants to bundle, acting as a short-hand. */ const projects = [ - ['base', ['tools/editorconfig', 'git/husky']], + ['base', ['tools/editorconfig', 'git-hooks/commit-msg']], [ 'js', [ @@ -110,7 +107,7 @@ const projects = [ 'github/all', 'linter/eslint', 'formatter/prettier', - 'git/husky-frontend', + 'git-hooks/commit-msg', ], ], [ @@ -120,7 +117,7 @@ const projects = [ 'github/all', 'linter/eslint-react', 'formatter/prettier', - 'git/husky-frontend', + 'git-hooks/commit-msg', ], ], ] @@ -295,9 +292,6 @@ const bundledConfigPaths = () => { config.eslintReact = ESLINT_REACT_CONFIG config['eslint-react'] = ESLINT_REACT_CONFIG break - case 'husky': - config.husky = HUSKY_CONFIG - break default: config[toolName] = sourceConfigPath break diff --git a/src/utils/paths.js b/src/utils/paths.js index e0034b36..c499e789 100644 --- a/src/utils/paths.js +++ b/src/utils/paths.js @@ -23,13 +23,7 @@ const EDITORCONFIG_CONFIG = path.join(CONFIG_DIR, 'editorconfig.config.rc') const DEPENDABOT_CONFIG = path.join(CONFIG_DIR, 'github', 'dependabot.yml') const STALE_CONFIG = path.join(CONFIG_DIR, 'github', 'stale.yml') const SEMANTIC_PR_CONFIG = path.join(CONFIG_DIR, 'github', 'semantic.yml') - -const HUSKY_CONFIG = path.join(CONFIG_DIR, 'husky.config.js') -const LOCAL_HUSKY_FRONTEND_CONFIG = path.join( - CONFIG_DIR, - 'husky-frontend.local.js' -) -const LOCAL_HUSKY_CONFIG = path.join(CONFIG_DIR, 'husky.local.js') +const COMMIT_MSG_HOOK = path.join(CONFIG_DIR, 'git', 'hooks', 'commit-msg') // local configuration files for repositories const LOCAL_ESLINT_REACT_CONFIG = path.join( @@ -43,6 +37,7 @@ const LOCAL_PRETTIER_CONFIG = path.join(CONFIG_DIR, 'js', 'prettier.local.js') module.exports = { CONSUMING_ROOT, + COMMIT_MSG_HOOK, BROWSERSLIST_CONFIG, COMMITLINT_CONFIG, PACKAGE_ROOT, @@ -57,7 +52,4 @@ module.exports = { PRETTIER_CONFIG, SEMANTIC_PR_CONFIG, STALE_CONFIG, - HUSKY_CONFIG, - LOCAL_HUSKY_CONFIG, - LOCAL_HUSKY_FRONTEND_CONFIG, } diff --git a/tests/group-resolution.js b/tests/group-resolution.js index ecebca2e..4e10b560 100644 --- a/tests/group-resolution.js +++ b/tests/group-resolution.js @@ -12,7 +12,6 @@ const { const { BROWSERSLIST_CONFIG, - HUSKY_CONFIG, STALE_CONFIG, DEPENDABOT_CONFIG, EDITORCONFIG_CONFIG, @@ -77,8 +76,8 @@ test('a valid project can be resolved into groups', t => { test('valid groups can be expanded', t => { t.plan(1) - const comboGroup = 'git/all' - const targetGroups = findGroup('git') + const comboGroup = 'git-hooks/all' + const targetGroups = findGroup('git-hooks') const expandedGroups = expandGroupAll(comboGroup) t.deepEqual( @@ -89,12 +88,11 @@ test('valid groups can be expanded', t => { }) test('convert to tool:config object', t => { - t.plan(8) + t.plan(7) const obj = bundledConfigPaths() t.equals(obj.eslint, ESLINT_CONFIG) - t.equals(obj.husky, HUSKY_CONFIG) t.equals(obj.prettier, PRETTIER_CONFIG) t.equals(obj.dependabot, DEPENDABOT_CONFIG) t.equals(obj['probot-stale'], STALE_CONFIG)