diff --git a/afterBuild.js b/afterBuild.js new file mode 100644 index 0000000..920dc10 --- /dev/null +++ b/afterBuild.js @@ -0,0 +1,39 @@ +import fs from 'fs'; +import path from 'path'; + +function copyProtoFiles(sourceDir, targetDir) { + // Ensure the target directory exists + if (!fs.existsSync(targetDir)) { + fs.mkdirSync(targetDir, { recursive: true }); + } + + // Function to recursively find all .proto files + function findProtoFiles(dir, fileList = []) { + const files = fs.readdirSync(dir, { withFileTypes: true }); + + for (const file of files) { + const filePath = path.join(dir, file.name); + if (file.isDirectory()) { + findProtoFiles(filePath, fileList); + } else if (path.extname(file.name) === '.proto') { + fileList.push(filePath); + } + } + + return fileList; + } + + // Find all .proto files in the source directory and its subdirectories + const protoFiles = findProtoFiles(sourceDir); + + // Copy each .proto file to the target directory + for (const sourcePath of protoFiles) { + const fileName = path.basename(sourcePath); + const targetPath = path.join(targetDir, fileName); + fs.copyFileSync(sourcePath, targetPath); + console.log(`Copied: ${sourcePath} -> ${targetPath}`); + } +} + +// Copy .proto files from src to dist +copyProtoFiles('src', 'dist'); diff --git a/package.json b/package.json index 4fbab5b..5622bde 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,8 @@ "type": "module", "license": "MIT", "scripts": { - "build": "rimraf dist && tsup", - "ci": "npm run build && npm run lint:fix && npm run test", + "build": "rimraf dist && tsup && node afterBuild.js", + "ci": "npm run build && node afterBuild.js && npm run lint:fix && npm run test", "dev": "tsc --watch", "lint:fix": "tsc && prettier --write .", "lint": "tsc && prettier --check --ignore-unknown .",