Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,5 @@ test-results/
secrets.yaml
node_modules
*.darwin
/tools/builders/prebuild-application/dist
src/frontend/packages/core/src/index.html
4 changes: 2 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"prebuildScripts": [
{
"name": "Clean symlinks",
"script": "sh -c 'mv build/clean-symlinks.js build/clean-symlinks.cjs && node build/clean-symlinks.cjs && mv build/clean-symlinks.cjs build/clean-symlinks.js'",
"script": "node build/run-script-cjs.cjs build/clean-symlinks.js",
"phase": 1,
"cache": true,
"cacheKey": ["src/frontend/packages/**/package.json"],
Expand All @@ -24,7 +24,7 @@
},
{
"name": "Store git metadata",
"script": "sh -c 'mv build/store-git-metadata.js build/store-git-metadata.cjs && node build/store-git-metadata.cjs && mv build/store-git-metadata.cjs build/store-git-metadata.js'",
"script": "node build/run-script-cjs.cjs build/store-git-metadata.js",
"phase": 1,
"cache": true,
"cacheKey": [".git/HEAD", ".git/refs/heads/**"],
Expand Down
54 changes: 54 additions & 0 deletions build/build-builders.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env node
/**
* Cross-platform script to build custom Angular builders
*/

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

const ROOT_DIR = path.join(__dirname, '..');
const BUILDERS_DIR = path.join(ROOT_DIR, 'tools', 'builders', 'prebuild-application');
const TARGET_DIR = path.join(ROOT_DIR, 'node_modules', '@stratos', 'builders');
const DIST_DIR = path.join(BUILDERS_DIR, 'dist');

console.log('Building custom Angular builders...');

try {
// Install dependencies
console.log('Installing dependencies...');
execSync('bun install', {
cwd: BUILDERS_DIR,
stdio: 'inherit'
});

// Build
console.log('Building...');
execSync('bun run build', {
cwd: BUILDERS_DIR,
stdio: 'inherit'
});

// Create target directory
console.log('Copying to node_modules...');
if (!fs.existsSync(TARGET_DIR)) {
fs.mkdirSync(TARGET_DIR, { recursive: true });
}

// Copy dist directory
if (fs.existsSync(DIST_DIR)) {
const targetDist = path.join(TARGET_DIR, 'dist');
if (fs.existsSync(targetDist)) {
fs.rmSync(targetDist, { recursive: true, force: true });
}
fs.cpSync(DIST_DIR, targetDist, { recursive: true });
console.log('✓ Builders built successfully');
} else {
console.error('❌ Build succeeded but dist directory not found');
process.exit(1);
}

} catch (err) {
console.error('❌ Failed to build builders:', err.message);
process.exit(1);
}
4 changes: 3 additions & 1 deletion build/post-setup.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ function error(message) {
function runScript(scriptName, scriptPath) {
log(`Running ${scriptName}...`);
try {
execSync(`sh -c 'mv ${scriptPath} ${scriptPath.replace('.js', '.cjs')} 2>/dev/null || true && node ${scriptPath.replace('.js', '.cjs')} && mv ${scriptPath.replace('.js', '.cjs')} ${scriptPath} 2>/dev/null || true'`, {
// Use the cross-platform wrapper script
const wrapperScript = path.join(ROOT_DIR, 'build', 'run-script-cjs.cjs');
execSync(`node "${wrapperScript}" "${scriptPath}"`, {
cwd: ROOT_DIR,
stdio: 'inherit'
});
Expand Down
61 changes: 61 additions & 0 deletions build/run-script-cjs.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#!/usr/bin/env node
/**
* Cross-platform script runner for .js files that need to run as .cjs
* Usage: node build/run-script-cjs.js <path-to-script>
*/

const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');

const scriptPath = process.argv[2];

if (!scriptPath) {
console.error('Error: No script path provided');
console.error('Usage: node build/run-script-cjs.js <path-to-script>');
process.exit(1);
}

const absolutePath = path.resolve(scriptPath);
const cjsPath = absolutePath.replace(/\.js$/, '.cjs');
let renamed = false;

try {
// Rename .js to .cjs if needed
if (fs.existsSync(absolutePath) && absolutePath !== cjsPath) {
try {
fs.renameSync(absolutePath, cjsPath);
renamed = true;
} catch (e) {
// If rename fails, try to use the file as-is
console.warn(`Warning: Could not rename ${absolutePath} to ${cjsPath}`);
}
}

// Run the script
const targetScript = renamed || fs.existsSync(cjsPath) ? cjsPath : absolutePath;
execSync(`node "${targetScript}"`, {
stdio: 'inherit',
cwd: process.cwd()
});

} catch (err) {
// Rename back before exiting with error
if (renamed && fs.existsSync(cjsPath)) {
try {
fs.renameSync(cjsPath, absolutePath);
} catch (e) {
// Ignore
}
}
process.exit(err.status || 1);
} finally {
// Rename back to .js
if (renamed && fs.existsSync(cjsPath)) {
try {
fs.renameSync(cjsPath, absolutePath);
} catch (e) {
console.warn(`Warning: Could not rename ${cjsPath} back to ${absolutePath}`);
}
}
}
1 change: 0 additions & 1 deletion bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading