Skip to content

Commit

Permalink
💎 feat: enhance cleanup logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Rettend committed Jan 23, 2024
1 parent 508e512 commit 70e4946
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 29 deletions.
5 changes: 3 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
- [ ] `conventional (boolean) [true]` - only allow conventional commits, this package should work without conventional commits as well
- [ ] new option: `mode (overwrite|append) [append]` - overwrite or append the config (for both json and ts) (idea: if emoji prop is specified, overwrite, else use default + you can import the default emojis to append them)
- [x] add `-v` alias for `--version`
- [ ] make the consola start and success logs sane in the cleanup command
- [x] make the consola start and success logs sane in the cleanup command
- [ ] investigate speed, prepare script for init
- [ ] rewrite the bin files in typescript and also build them
- [ ] refactor a lot!
- [ ] Generate the readme emoji table from `emojis.json` (jsonc for description? how to bundle jsonc?)
- [ ] Generate the readme emoji table from `emojis.json` (jsonc for description)
- [ ] try astro and create a small website explaining which emoji to use and when, + stuff
2 changes: 2 additions & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ export default defineBuildConfig({
'citty',
'cosmiconfig',
'lodash-es',
'jsonc-parser',
'@cozy-console/mini',
],
})
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
"commit",
"emoji"
],
"sideEffects": false,
"exports": {
".": {
"import": "./dist/index.mjs",
Expand All @@ -42,17 +41,19 @@
"test": "vitest",
"test:ui": "vitest --ui --coverage --api 9527",
"lint": "eslint .",
"lint:fix": "pnpm run lint --fix",
"lint:fix": "eslint . --fix",
"typecheck": "tsc --noEmit",
"release": "bumpp && unbuild && pnpm publish",
"postinstall": "node ./bin/postinstall.cjs",
"preuninstall": "node ./bin/eemoji.mjs cleanup",
"prepare": "simple-git-hooks"
},
"dependencies": {
"@cozy-console/mini": "^0.0.1",
"citty": "^0.1.4",
"consola": "^3.2.3",
"cosmiconfig": "^8.3.6",
"jsonc-parser": "^3.2.0",
"lodash-es": "^4.17.21"
},
"devDependencies": {
Expand All @@ -68,7 +69,6 @@
"simple-git-hooks": "^2.9.0",
"typescript": "5.3.3",
"unbuild": "^2.0.0",
"vite": "^5.0.2",
"vitest": "^1.2.1"
},
"simple-git-hooks": {
Expand Down
14 changes: 10 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions src/commands/cleanup.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as fs from 'node:fs'
import path from 'node:path'
import { defineCommand } from 'citty'
import { consola } from 'consola'
import * as jsonc from 'jsonc-parser'
import { cozy as console } from '@cozy-console/mini'
import { ConfigObject } from '../config'
import { name } from '../../package.json'

Expand All @@ -13,56 +14,59 @@ export default defineCommand({
description: 'Cleanup git hook and settings.json',
},
async run() {
consola.start('Removing git hook...')
console.start('Removing git hook...')

if (fs.existsSync(C.hookFile)) {
fs.unlinkSync(C.hookFile)
consola.success(`Removed ${C.hookFile}`)
console.success(`Removed ${C.hookFile}`)
}
else {
consola.info(`No ${C.hookFile} found`)
console.info(`No ${C.hookFile} found`)
}

consola.start('Removing VSCode settings...')
console.start('Removing VSCode settings...')

if (fs.existsSync(C.vscodeSettingsFile)) {
const settings = JSON.parse(fs.readFileSync(C.vscodeSettingsFile, 'utf-8'))
const settings = jsonc.parse(fs.readFileSync(C.vscodeSettingsFile, 'utf-8'))

if (settings['json.schemas']) {
settings['json.schemas'] = settings['json.schemas'].filter((schema: any) => {
return schema.url !== `https://rettend.github.io/${name}/${name}-config-schema.json`
&& schema.url !== `./json/${name}-config-schema.json`
})

if (settings['json.schemas'].length === 0)
delete settings['json.schemas']
}

if (Object.keys(settings).length === 0) {
fs.unlinkSync(C.vscodeSettingsFile)
fs.rmdirSync(path.dirname(C.vscodeSettingsFile))
consola.success(`Removed ${C.vscodeSettingsFile}`)
console.success(`Removed ${C.vscodeSettingsFile}`)
}
else {
fs.writeFileSync(C.vscodeSettingsFile, JSON.stringify(settings, null, 2))
consola.info(`Updated ${C.vscodeSettingsFile}`)
fs.writeFileSync(C.vscodeSettingsFile, `${JSON.stringify(settings, null, 2)}\n`)
console.info(`Updated ${C.vscodeSettingsFile}`)
}
}
else {
consola.info(`No ${C.vscodeSettingsFile} found`)
console.info(`No ${C.vscodeSettingsFile} found`)
}

consola.start('Removing config files...')
console.start('Removing config files...')
let removedFiles = false

;[...C.jsFiles, ...C.jsonFiles.filter(file => file !== 'package.json')].forEach((file: string) => {
if (fs.existsSync(file)) {
fs.unlinkSync(file)
consola.success(`Removed ${file}`)
console.success(`Removed ${file}`)
removedFiles = true
}
})

if (!removedFiles)
consola.info('No config files found')
console.info('No config files found')

else
consola.success('Cleanup complete!')
console.success('\nCleanup complete!\n')
},
})
4 changes: 2 additions & 2 deletions src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import process from 'node:process'
import { defineCommand } from 'citty'
import { consola } from 'consola'
import { name } from '../../package.json'
import type { ConfigType, JsFiles, JsonFiles } from './../config'
import { ConfigObject, configTypes } from './../config'
import type { ConfigType, JsFiles, JsonFiles } from '../config'
import { ConfigObject, configTypes } from '../config'

const C = new ConfigObject()

Expand Down
2 changes: 1 addition & 1 deletion src/commands/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { consola } from 'consola'
import { cosmiconfig } from 'cosmiconfig'
import { name } from '../../package.json'
import { createExampleCommitMessage, eemojify, unemojify } from '../utils/emoji'
import { type Config, ConfigObject } from './../config'
import { type Config, ConfigObject } from '../config'

const C = new ConfigObject()

Expand Down
2 changes: 1 addition & 1 deletion src/utils/emoji.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { consola } from 'consola'
import type { Config } from './../config'
import type { Config } from '../config'

/**
* Formats a commit message with an emoji based on the type.
Expand Down
1 change: 0 additions & 1 deletion test/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// import the function and the default config
import { describe, expect, it } from 'vitest'
import { eemojify, unemojify } from '../src/utils/emoji'
import { type Config, ConfigObject } from '../src/config'
Expand Down

0 comments on commit 70e4946

Please sign in to comment.