committed by
GitHub
11 changed files with 78 additions and 33 deletions
@ -1,14 +1,14 @@ |
|||||
# default onwer |
# default onwer |
||||
* anncwb vince292007 |
* anncwb@126.com vince292007@gmail.com |
||||
|
|
||||
# vben core onwer |
# vben core onwer |
||||
/.github/ anncwb vince292007 |
/.github/ anncwb@126.com vince292007@gmail.com |
||||
/.vscode/ anncwb vince292007 |
/.vscode/ anncwb@126.com vince292007@gmail.com |
||||
/packages/ anncwb vince292007 |
/packages/ anncwb@126.com vince292007@gmail.com |
||||
/packages/@core/ anncwb vince292007 |
/packages/@core/ anncwb@126.com vince292007@gmail.com |
||||
/internal/ anncwb vince292007 |
/internal/ anncwb@126.com vince292007@gmail.com |
||||
/scripts/ anncwb vince292007 |
/scripts/ anncwb@126.com vince292007@gmail.com |
||||
|
|
||||
# vben team onwer |
# vben team onwer |
||||
apps/ @vbenjs/team-v5 |
apps/ anncwb@126.com vince292007@gmail.com @vbenjs/team-v5 |
||||
docs/ @vbenjs/team-v5 |
docs/ anncwb@126.com vince292007@gmail.com @vbenjs/team-v5 |
||||
|
|||||
@ -0,0 +1,41 @@ |
|||||
|
import { promises as fs } from 'node:fs'; |
||||
|
import { dirname } from 'node:path'; |
||||
|
|
||||
|
export async function outputJSON( |
||||
|
filePath: string, |
||||
|
data: any, |
||||
|
spaces: number = 2, |
||||
|
) { |
||||
|
try { |
||||
|
const dir = dirname(filePath); |
||||
|
await fs.mkdir(dir, { recursive: true }); |
||||
|
const jsonData = JSON.stringify(data, null, spaces); |
||||
|
await fs.writeFile(filePath, jsonData, 'utf8'); |
||||
|
console.log(`JSON data written to ${filePath}`); |
||||
|
} catch (error) { |
||||
|
console.error('Error writing JSON file:', error); |
||||
|
throw error; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export async function ensureFile(filePath: string) { |
||||
|
try { |
||||
|
const dir = dirname(filePath); |
||||
|
await fs.mkdir(dir, { recursive: true }); |
||||
|
await fs.writeFile(filePath, '', { flag: 'a' }); // 'a' flag to append if file exists, otherwise create
|
||||
|
console.log(`File ensured: ${filePath}`); |
||||
|
} catch (error) { |
||||
|
console.error('Error ensuring file:', error); |
||||
|
throw error; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export async function readJSON(filePath: string) { |
||||
|
try { |
||||
|
const data = await fs.readFile(filePath, 'utf8'); |
||||
|
return JSON.parse(data); |
||||
|
} catch (error) { |
||||
|
console.error('Error reading JSON file:', error); |
||||
|
throw error; |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue