UNPKG

1.23 kBJavaScriptView Raw
1/*
2* @adonisjs/mrm-preset
3*
4* (c) Harminder Virk <virk@adonisjs.com>
5*
6* For the full copyright and license information, please view the LICENSE
7* file that was distributed with this source code.
8*/
9
10const { join } = require('path')
11const { chmodSync } = require('fs')
12const { execSync } = require('child_process')
13const { packageJson, install, lines } = require('mrm-core')
14
15function task () {
16 /**
17 * Remove existing pre commit hook
18 */
19 const pkgFile = packageJson()
20 pkgFile.unset('husky.hooks.pre-commit')
21 pkgFile.save()
22
23 /**
24 * Setup husky
25 */
26 execSync('npx husky install')
27
28 /**
29 * Create pre-commit file
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 * Change mode when file not already exists
42 */
43 if (!fileAlreadyExists) {
44 chmodSync(join(process.cwd(), '.husky/pre-commit'), 0o0755)
45 }
46
47 /**
48 * Install required dependencies
49 */
50 install(['doctoc', 'husky'])
51}
52
53task.description = 'Generate TOC for readme.md file'
54module.exports = task