-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate-release.js
More file actions
executable file
·99 lines (82 loc) · 3.07 KB
/
Copy pathcreate-release.js
File metadata and controls
executable file
·99 lines (82 loc) · 3.07 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env node
/**
* Create Release Package
*
* Creates a zip file containing only phantom.js and phantom.min.js
* for distribution to the community.
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
// Get version from package.json or environment variable
function getVersion() {
// Check if version is provided via environment variable (for CI)
if (process.env.RELEASE_VERSION) {
return process.env.RELEASE_VERSION;
}
// Get from package.json
const packageJsonPath = path.join(__dirname, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'));
return packageJson.version;
}
const VERSION = getVersion();
const RELEASE_DIR = path.join(__dirname, '..', 'release');
// Use shorter filename format: phantom-0.1.5-beta.zip instead of phantom-v0.1.5-beta.zip
const ZIP_NAME = `phantom-${VERSION}.zip`;
const ZIP_PATH = path.join(RELEASE_DIR, ZIP_NAME);
// Files to include in release
const RELEASE_FILES = [
'phantom.js',
'phantom.min.js'
];
console.log('📦 Creating release package...\n');
// Ensure minified file exists
const minifiedPath = path.join(__dirname, '..', 'phantom.min.js');
if (!fs.existsSync(minifiedPath)) {
console.log('⚠️ phantom.min.js not found. Generating...');
execSync('npm run minify', { stdio: 'inherit', cwd: __dirname });
}
// Create release directory
if (!fs.existsSync(RELEASE_DIR)) {
fs.mkdirSync(RELEASE_DIR, { recursive: true });
}
// Copy files to release directory
console.log('📋 Copying files to release directory...');
RELEASE_FILES.forEach(file => {
const srcPath = path.join(__dirname, '..', file);
const destPath = path.join(RELEASE_DIR, file);
if (!fs.existsSync(srcPath)) {
console.error(`❌ Error: ${file} not found!`);
process.exit(1);
}
fs.copyFileSync(srcPath, destPath);
const stats = fs.statSync(destPath);
console.log(` ✓ ${file} (${(stats.size / 1024).toFixed(2)} KB)`);
});
// Create zip file
console.log('\n🗜️ Creating zip archive...');
try {
// Remove old zip if exists
if (fs.existsSync(ZIP_PATH)) {
fs.unlinkSync(ZIP_PATH);
}
// Create zip using zip command (available on macOS/Linux)
// For Windows, user can manually zip or use 7zip
const zipCommand = `cd "${RELEASE_DIR}" && zip -q "${ZIP_NAME}" ${RELEASE_FILES.join(' ')}`;
execSync(zipCommand, { stdio: 'inherit' });
const zipStats = fs.statSync(ZIP_PATH);
console.log(` ✓ ${ZIP_NAME} created (${(zipStats.size / 1024).toFixed(2)} KB)`);
console.log('\n✅ Release package created successfully!');
console.log(`\n📁 Location: ${ZIP_PATH}`);
console.log(`\n📦 Contents:`);
RELEASE_FILES.forEach(file => {
console.log(` - ${file}`);
});
console.log(`\n🚀 Ready for distribution!\n`);
} catch (error) {
console.error('\n❌ Error creating zip file:', error.message);
console.log('\n💡 Alternative: Manually zip the files in the release directory:');
console.log(` cd ${RELEASE_DIR}`);
console.log(` zip ${ZIP_NAME} ${RELEASE_FILES.join(' ')}\n`);
process.exit(1);
}