This repository has been archived by the owner on Jan 24, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
74 lines (61 loc) · 1.76 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
* @adonisjs/mrm-preset
*
* (c) Harminder Virk <virk@adonisjs.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
const { join } = require('path')
const { chmodSync } = require('fs')
const { execSync } = require('child_process')
const { packageJson, install, template, lines } = require('mrm-core')
const prTemplate = '.github/COMMIT_CONVENTION.md'
function task () {
const pkgFile = packageJson()
/**
* Below is the script for interactively creating a commit
*/
pkgFile.setScript('commit', 'git-cz')
pkgFile.set('config.commitizen.path', 'cz-conventional-changelog')
/**
* Save the package file
*/
pkgFile.save()
/**
* Install required dependencies
*/
install(['cz-conventional-changelog', 'commitizen', 'husky'])
/**
* Setup husky
*/
execSync('npx husky install')
/**
* Create commit-msg file
*/
const commitFile = lines('.husky/commit-msg')
.add('#!/bin/sh')
.add('. "$(dirname "$0")/_/husky.sh"')
.add('HUSKY_GIT_PARAMS=$1 node ./node_modules/@adonisjs/mrm-preset/validate-commit/conventional/validate.js')
const fileAlreadyExists = commitFile.exists()
commitFile.save()
/**
* Change mode when file not already exists
*/
if (!fileAlreadyExists) {
chmodSync(join(process.cwd(), '.husky/commit-msg'), 0o0755)
}
/**
* Remove old husky hooks block
*/
pkgFile.unset(
'husky.hooks.commit-msg',
'node ./node_modules/@adonisjs/mrm-preset/validateCommit/conventional/validate.js'
)
/**
* Copy commit convention template
*/
template(prTemplate, join(__dirname, 'conventional', 'template.md')).apply({}).save()
}
task.description = 'Enforces commit message convention'
module.exports = task