Skip to content
This repository has been archived by the owner on Dec 10, 2024. It is now read-only.

Commit

Permalink
feat(cli): config folder (#154)
Browse files Browse the repository at this point in the history
* feat(cli): config folder

* version(cli): release 0.8.0
  • Loading branch information
productdevbook authored Feb 14, 2024
1 parent 2e1ff92 commit d6a6b51
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages-core/cli/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@pergel/cli",
"type": "module",
"version": "0.7.1",
"version": "0.8.0",
"packageManager": "[email protected]",
"description": "Full Stack Nuxt Application. It contains the necessary toolkits for a software developer and a fast, clean, tested toolkit.",
"author": "Mehmet @productdevbook",
Expand Down
5 changes: 5 additions & 0 deletions packages-core/cli/playground/.config/pergel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { definePergel } from 'pergel'

export default definePergel({

})
5 changes: 0 additions & 5 deletions packages-core/cli/playground/pergel.config.ts

This file was deleted.

9 changes: 7 additions & 2 deletions packages-core/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { writeFileSync } from 'node:fs'
import { join } from 'node:path'
import { existsSync } from 'node:fs'
import { defineCommand } from 'citty'
import { writeFilePergel } from '../utils/writeFilePergel'

const template = `import { definePergel } from 'pergel'
Expand All @@ -15,6 +17,9 @@ export default defineCommand({
version: '0.0.1',
},
async run() {
writeFileSync('pergel.config.ts', template)
const file = join('.config', 'pergel.ts')

if (!existsSync(file))
writeFilePergel(file, template)
},
})
26 changes: 26 additions & 0 deletions packages-core/cli/src/utils/writeFilePergel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { accessSync, mkdirSync, writeFileSync } from 'node:fs'
import { dirname } from 'node:path'

async function isExists(path: string) {
try {
accessSync(path)
return true
}
catch {
return false
}
};

export async function writeFilePergel(filePath: string, data: any) {
try {
const _dirname = dirname(filePath)
const exist = await isExists(_dirname)
if (!exist)
mkdirSync(_dirname, { recursive: true })

writeFileSync(filePath, data, 'utf8')
}
catch (err: any) {
throw new Error(err)
}
}

0 comments on commit d6a6b51

Please sign in to comment.