-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathvcr-build.js
More file actions
74 lines (59 loc) · 2.33 KB
/
Copy pathvcr-build.js
File metadata and controls
74 lines (59 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import simpleGit from 'simple-git';
import archiver from 'archiver';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const vcrBuildDir = path.join(__dirname, 'vcr-build');
const releaseDir = path.join(__dirname, 'release');
const repoUrl = 'https://github.com/Vonage-Community/sample-video-node-learning_server.git';
// Check for version argument
const version = process.argv[2];
if (!version) {
console.error('Error: Version argument is required. Usage: npm run vcrbuild <version>');
process.exit(1);
}
const zipFileName = `vcr-build-${version}.zip`;
async function runVcrBuild() {
try {
// Check if the release file already exists
if (fs.existsSync(path.join(releaseDir, zipFileName))) {
console.error(`Error: Release file for version ${version} already exists.`);
process.exit(1);
}
// Create release directory if it doesn't exist
if (!fs.existsSync(releaseDir)) {
fs.mkdirSync(releaseDir);
}
// Step 1: Delete vcr-build directory if it exists
if (fs.existsSync(vcrBuildDir)) {
fs.rmSync(vcrBuildDir, { recursive: true });
}
// Step 2: Perform a clean checkout of the repository
await simpleGit().clone(repoUrl, vcrBuildDir);
// Step 3: Copy vcr.yml to vcr-build
const neruFilePath = path.join(vcrBuildDir, 'vcr.yml.dist');
fs.copyFileSync(neruFilePath, path.join(vcrBuildDir, 'vcr.yml'));
fs.rmSync(vcrBuildDir + '/.git', { recursive: true })
fs.rmSync(vcrBuildDir + '/.gitignore')
fs.rmSync(neruFilePath)
// Step 4: Create a ZIP file from vcr-build with version name
await createZipFile(vcrBuildDir, zipFileName);
console.log(`VCR build process completed successfully. File created: ${zipFileName}`);
} catch (error) {
console.error('Error during VCR build process:', error);
}
}
async function createZipFile(sourceDir, zipFileName) {
return new Promise((resolve, reject) => {
const output = fs.createWriteStream(path.join(releaseDir, zipFileName));
const archive = archiver('zip', { zlib: { level: 9 } });
output.on('close', () => resolve());
archive.on('error', (err) => reject(err));
archive.pipe(output);
archive.directory(sourceDir, false);
archive.finalize();
});
}
runVcrBuild();