mirror of
https://github.com/certd/certd.git
synced 2026-04-24 12:27:25 +08:00
refactor: 重构优化
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import os from 'os'
|
||||
import fs from 'fs-extra'
|
||||
import pathUtil from '../utils/util.path.js'
|
||||
import cryptoRandomString from 'crypto-random-string'
|
||||
import zipUtil from '../utils/util.zip.js'
|
||||
import path from 'path'
|
||||
|
||||
export default {
|
||||
async exportsToZip (options, dirName) {
|
||||
const tempDir = os.tmpdir()
|
||||
const targetDir = path.join(tempDir, 'certd-server', cryptoRandomString(10))
|
||||
const projectName = dirName
|
||||
const targetProjectDir = path.join(targetDir, projectName)
|
||||
const templateDir = pathUtil.join('templates/' + projectName)
|
||||
|
||||
fs.copySync(templateDir, targetProjectDir)
|
||||
|
||||
// const packageFilePath = path.join(targetProjectDir, 'package.json')
|
||||
const optionsFilePath = path.join(targetProjectDir, 'options.json')
|
||||
|
||||
fs.writeJsonSync(optionsFilePath, options)
|
||||
|
||||
const zipName = dirName + '.zip'
|
||||
const outputFilePath = path.join(targetDir, zipName)
|
||||
|
||||
console.log('targetDir', targetDir)
|
||||
console.log('projectName', projectName)
|
||||
console.log('tempalteDir', templateDir)
|
||||
console.log('targetProjectDir', targetProjectDir)
|
||||
console.log('outputFilePath', outputFilePath)
|
||||
await zipUtil.compress({ dir: targetProjectDir, output: outputFilePath })
|
||||
return {
|
||||
dir: targetDir,
|
||||
fileName: zipName,
|
||||
zipPath: outputFilePath
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user