1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | const { join } = require('path')
|
11 | const { chmodSync } = require('fs')
|
12 | const { execSync } = require('child_process')
|
13 | const { packageJson, install, lines } = require('mrm-core')
|
14 |
|
15 | function task () {
|
16 | |
17 |
|
18 |
|
19 | const pkgFile = packageJson()
|
20 | pkgFile.unset('husky.hooks.pre-commit')
|
21 | pkgFile.save()
|
22 |
|
23 | |
24 |
|
25 |
|
26 | execSync('npx husky install')
|
27 |
|
28 | |
29 |
|
30 |
|
31 | const commitFile = lines('.husky/pre-commit')
|
32 | .add('#!/bin/sh')
|
33 | .add('. "$(dirname "$0")/_/husky.sh"')
|
34 | .add('npx doctoc README.md --title=\'## Table of contents\'')
|
35 | .add('git add README.md')
|
36 |
|
37 | const fileAlreadyExists = commitFile.exists()
|
38 | commitFile.save()
|
39 |
|
40 | |
41 |
|
42 |
|
43 | if (!fileAlreadyExists) {
|
44 | chmodSync(join(process.cwd(), '.husky/pre-commit'), 0o0755)
|
45 | }
|
46 |
|
47 | |
48 |
|
49 |
|
50 | install(['doctoc', 'husky'])
|
51 | }
|
52 |
|
53 | task.description = 'Generate TOC for readme.md file'
|
54 | module.exports = task
|