Skip to content

Commit

Permalink
build: copy proto files into dist
Browse files Browse the repository at this point in the history
  • Loading branch information
rixcian committed Aug 28, 2024
1 parent 57664cf commit 75d7756
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
39 changes: 39 additions & 0 deletions afterBuild.js
Original file line number Diff line number Diff line change
@@ -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');
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 .",
Expand Down

0 comments on commit 75d7756

Please sign in to comment.