Skip to content

Commit 0252d21

Browse files
author
Test User
committed
feat: add build.js script for npm package preparation
- Create scripts/build.js to verify required files before publishing - Checks for bin/doplan.js, scripts, README.md, and LICENSE - Validates bin/doplan.js has proper shebang - Restore build script reference in package.json - Build script runs before prepublish validation
1 parent b4b935a commit 0252d21

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
},
99
"scripts": {
1010
"postinstall": "node scripts/postinstall.js",
11-
"prepublishOnly": "node scripts/prepublish.js"
11+
"build": "node scripts/build.js",
12+
"prepublishOnly": "npm run build && node scripts/prepublish.js"
1213
},
1314
"files": [
1415
"bin/",

scripts/build.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Build script for npm package
5+
* Prepares the package for publishing by verifying required files
6+
*/
7+
8+
const fs = require('fs');
9+
const path = require('path');
10+
11+
console.log('DoPlan CLI: Building npm package...');
12+
13+
// Verify required files exist
14+
const requiredFiles = [
15+
'bin/doplan.js',
16+
'scripts/postinstall.js',
17+
'scripts/prepublish.js',
18+
'README.md',
19+
'LICENSE'
20+
];
21+
22+
let hasErrors = false;
23+
24+
for (const file of requiredFiles) {
25+
const filePath = path.join(__dirname, '..', file);
26+
if (!fs.existsSync(filePath)) {
27+
console.error(`Error: Required file missing: ${file}`);
28+
hasErrors = true;
29+
} else {
30+
console.log(`✓ Found: ${file}`);
31+
}
32+
}
33+
34+
// Verify bin/doplan.js is executable (on Unix systems)
35+
const binPath = path.join(__dirname, '..', 'bin', 'doplan.js');
36+
if (fs.existsSync(binPath)) {
37+
try {
38+
// Check if file has shebang
39+
const content = fs.readFileSync(binPath, 'utf8');
40+
if (!content.startsWith('#!/usr/bin/env node')) {
41+
console.warn('Warning: bin/doplan.js missing shebang line');
42+
}
43+
} catch (error) {
44+
console.warn(`Warning: Could not read bin/doplan.js: ${error.message}`);
45+
}
46+
}
47+
48+
if (hasErrors) {
49+
console.error('\nBuild failed. Please fix the errors above.');
50+
process.exit(1);
51+
}
52+
53+
console.log('\n✅ Build completed successfully!');
54+
console.log('Package is ready for publishing.');
55+

0 commit comments

Comments
 (0)