Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
implement cliDir
Browse files Browse the repository at this point in the history
  • Loading branch information
keremciu committed Apr 14, 2021
1 parent 58ee899 commit b04444a
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 13 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "adr-tool",
"description": "easy CLI for ADR docs",
"version": "0.0.0",
"version": "0.0.1",
"author": "Kerem Sevencan @keremciu",
"bin": {
"adr-tool": "./bin/run"
Expand Down
8 changes: 3 additions & 5 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {error} from '@oclif/errors'
import {adrDir} from '../config'

const templateFile = adrDir + '/template.md'
const tocFile = adrDir + '/README.md'
const tocFilePath = adrDir + 'README.md'
const extension = 'md'
const slicePos = -extension.length

Expand Down Expand Up @@ -80,17 +80,15 @@ a decision created on ./docs/adr/0001-use-adr-tool.md
const filePath = adrDir + filename + '.md'
fs.writeFileSync(filePath, fileData)

const tocFileRaw = fs.readFileSync(tocFile, 'utf8')
const tocFileRaw = fs.readFileSync(tocFilePath, 'utf8')
const tocFileArray = tocFileRaw.split('\n')

const tocString = `* [ADR-${fileIndex}](${filename}.md) - ${args.title}`

const tocStopIndex = tocFileArray.indexOf('<!-- tocstop -->')
tocFileArray.splice(tocStopIndex - 1, 0, tocString)

const tocPath = adrDir + 'README.md'

fs.writeFileSync(tocPath, tocFileArray.join('\n'))
fs.writeFileSync(tocFilePath, tocFileArray.join('\n'))

this.log('a decision created on ' + filePath)
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ const path = require('path')
import {Command, flags} from '@oclif/command'
import {error} from '@oclif/errors'

import {adrDir} from '../config'
import {adrDir, cliDir} from '../config'

const dirname = __dirname
const cliTemplates = path.join(dirname + '/../templates/')
const cliTemplates = path.join(cliDir + '/../templates/')
const cliTemplateFile = cliTemplates + 'template.md'
const cliTOCFile = cliTemplates + 'toc.md'

Expand Down
10 changes: 6 additions & 4 deletions src/commands/toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ const path = require('path')
import {Command, flags} from '@oclif/command'
import {error} from '@oclif/errors'

import {adrDir} from '../config'
import {adrDir, cliDir} from '../config'

const cliTemplates = path.join(cliDir + '/../templates/')

const dirname = __dirname
const cliTemplates = path.join(dirname + '/../templates/')
const cliTOCFile = cliTemplates + 'toc.md'

export default class Toc extends Command {
Expand All @@ -28,7 +28,9 @@ export default class Toc extends Command {
error('docs/adr/README.md file is already exist.')
}

fs.copyFile(cliTOCFile, adrDir + 'README.md', () => null)
fs.copyFile(cliTOCFile, adrDir + 'README.md', (err: Error) => {
if (err) throw err
})

this.log('./docs/adr/README.md file is created!')
}
Expand Down
4 changes: 4 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
const path = require('path')
const fs = require('fs')

export const workDir = process.cwd()
export const adrDir = workDir + '/docs/adr/'
export const cliDir = path.dirname(fs.realpathSync(__filename))

0 comments on commit b04444a

Please sign in to comment.