Skip to content

Commit 9e7bdff

Browse files
Integrate build verification into main build process
- Created root-level wrapper scripts (collect-build-metadata.cjs, verify-build.cjs) - Added prebuild hook to collect metadata and embed in app/utils/build-info.ts - Added postbuild hook to verify builds with warnings - Added verify and verify:enforce scripts for manual verification - Ignored generated build-info.ts and build-metadata.json files - Scripts automatically build verification package if needed - Fixed Template interface to include localPath property - Tested from root directory - works for both official and unofficial builds
1 parent 3116809 commit 9e7bdff

5 files changed

Lines changed: 173 additions & 2 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ site
4242
# commit file ignore
4343
app/commit.json
4444
changelogUI.md
45+
46+
# build verification (generated files)
47+
app/utils/build-info.ts
48+
build-metadata.json
4549
docs/instructions/Roadmap.md
4650
.cursorrules
4751
*.md

app/types/template.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ export interface Template {
33
label: string;
44
description: string;
55
githubRepo?: string; // For remote templates
6-
subdir?: string; // Subdirectory within the repo (for monorepos)
7-
localPath?: string; // For local templates (e.g., 'codinit-vite-react-ts')
6+
localPath?: string; // For local templates
87
source?: 'local' | 'github'; // Indicate the source of the template
98
tags?: string[];
109
icon?: string;

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@
1212
},
1313
"scripts": {
1414
"deploy": "npm run build && wrangler pages deploy",
15+
"prebuild": "node scripts/collect-build-metadata.cjs --embed app/utils/build-info.ts",
1516
"build": "cross-env NODE_OPTIONS=--max-old-space-size=4096 remix vite:build",
17+
"postbuild": "node scripts/verify-build.cjs --mode warn --verbose",
18+
"verify": "node scripts/verify-build.cjs",
19+
"verify:enforce": "node scripts/verify-build.cjs --mode enforce --verbose",
1620
"dev": "node pre-start.cjs && remix vite:dev",
1721
"test": "vitest --run",
1822
"test:watch": "vitest",

scripts/collect-build-metadata.cjs

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Root-level script to collect build metadata
5+
* This wraps the build verification package and can be run from anywhere
6+
*
7+
* Usage:
8+
* node scripts/collect-build-metadata.js
9+
* node scripts/collect-build-metadata.js --output build-info.json
10+
* node scripts/collect-build-metadata.js --embed app/utils/build-info.ts
11+
*/
12+
13+
const { execSync } = require('child_process');
14+
const path = require('path');
15+
const fs = require('fs');
16+
17+
const packageDir = path.join(__dirname, '../packages/codinit-dev');
18+
const args = process.argv.slice(2);
19+
20+
// Check if the package is built
21+
const distPath = path.join(packageDir, 'dist/index.js');
22+
23+
if (!fs.existsSync(distPath)) {
24+
console.log('Building verification package...');
25+
26+
try {
27+
execSync('pnpm build', { cwd: packageDir, stdio: 'inherit' });
28+
} catch (error) {
29+
console.error('Failed to build verification package');
30+
process.exit(1);
31+
}
32+
}
33+
34+
// Import and run the collector
35+
const { collectBuildMetadata } = require(distPath);
36+
const metadata = collectBuildMetadata();
37+
38+
// Display metadata
39+
console.log('\n' + '='.repeat(60));
40+
console.log('Build Metadata Collected');
41+
console.log('='.repeat(60));
42+
console.log(`Commit: ${metadata.commit}`);
43+
console.log(`Branch: ${metadata.branch}`);
44+
console.log(`Timestamp: ${metadata.timestamp}`);
45+
console.log(`Builder: ${metadata.builder}`);
46+
console.log(`Environment: ${metadata.environment}`);
47+
console.log(`Official: ${metadata.isOfficial ? 'YES' : 'NO'}`);
48+
49+
if (metadata.buildNumber) {
50+
console.log(`Build #: ${metadata.buildNumber}`);
51+
}
52+
53+
if (metadata.tags && metadata.tags.length > 0) {
54+
console.log(`Tags: ${metadata.tags.join(', ')}`);
55+
}
56+
57+
if (metadata.signature) {
58+
console.log(`Signature: ${metadata.signature.slice(0, 16)}...`);
59+
}
60+
61+
console.log('='.repeat(60) + '\n');
62+
63+
// Handle output flags
64+
const outputFlag = args.indexOf('--output');
65+
const embedFlag = args.indexOf('--embed');
66+
67+
// Output to JSON file
68+
if (outputFlag !== -1 && args[outputFlag + 1]) {
69+
const outputPath = path.resolve(process.cwd(), args[outputFlag + 1]);
70+
fs.writeFileSync(outputPath, JSON.stringify(metadata, null, 2));
71+
console.log(`✓ Metadata written to: ${outputPath}\n`);
72+
}
73+
74+
// Embed as TypeScript module
75+
if (embedFlag !== -1 && args[embedFlag + 1]) {
76+
const embedPath = path.resolve(process.cwd(), args[embedFlag + 1]);
77+
const tsContent = `/**
78+
* Auto-generated build metadata
79+
* Generated at: ${new Date().toISOString()}
80+
* DO NOT EDIT MANUALLY
81+
*/
82+
83+
export const BUILD_METADATA = ${JSON.stringify(metadata, null, 2)} as const;
84+
85+
export type BuildMetadata = typeof BUILD_METADATA;
86+
`;
87+
88+
// Ensure directory exists
89+
fs.mkdirSync(path.dirname(embedPath), { recursive: true });
90+
fs.writeFileSync(embedPath, tsContent);
91+
console.log(`✓ Metadata embedded in: ${embedPath}\n`);
92+
}
93+
94+
// Exit successfully
95+
process.exit(0);

scripts/verify-build.cjs

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Root-level script to verify build
5+
* This wraps the build verification package and can be run from anywhere
6+
*
7+
* Usage:
8+
* node scripts/verify-build.js
9+
* node scripts/verify-build.js --mode enforce
10+
* node scripts/verify-build.js --mode warn --verbose
11+
* node scripts/verify-build.js --metadata build-info.json
12+
*/
13+
14+
const { execSync } = require('child_process');
15+
const path = require('path');
16+
const fs = require('fs');
17+
18+
const packageDir = path.join(__dirname, '../packages/codinit-dev');
19+
const args = process.argv.slice(2);
20+
21+
// Check if the package is built
22+
const distPath = path.join(packageDir, 'dist/index.js');
23+
24+
if (!fs.existsSync(distPath)) {
25+
console.log('Building verification package...');
26+
27+
try {
28+
execSync('pnpm build', { cwd: packageDir, stdio: 'inherit' });
29+
} catch (error) {
30+
console.error('Failed to build verification package');
31+
process.exit(1);
32+
}
33+
}
34+
35+
// Import the verification functions
36+
const { collectBuildMetadata, performVerification } = require(distPath);
37+
38+
// Parse arguments
39+
const modeFlag = args.indexOf('--mode');
40+
const verboseFlag = args.indexOf('--verbose');
41+
const metadataFlag = args.indexOf('--metadata');
42+
43+
const mode = modeFlag !== -1 && args[modeFlag + 1] ? args[modeFlag + 1] : 'warn';
44+
const verbose = verboseFlag !== -1;
45+
46+
let metadata;
47+
48+
// Load metadata from file or collect fresh
49+
if (metadataFlag !== -1 && args[metadataFlag + 1]) {
50+
const metadataPath = path.resolve(process.cwd(), args[metadataFlag + 1]);
51+
52+
if (fs.existsSync(metadataPath)) {
53+
metadata = JSON.parse(fs.readFileSync(metadataPath, 'utf-8'));
54+
console.log(`\nLoaded metadata from: ${metadataPath}`);
55+
} else {
56+
console.error(`\nError: Metadata file not found: ${metadataPath}`);
57+
process.exit(1);
58+
}
59+
} else {
60+
metadata = collectBuildMetadata();
61+
}
62+
63+
// Perform verification
64+
const config = {
65+
mode: mode === 'enforce' ? 'enforce' : 'warn',
66+
verbose,
67+
};
68+
69+
performVerification(metadata, config);

0 commit comments

Comments
 (0)