scripts / setup.cjs
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
async function setup() {
const repoUrl = 'https://github.com/CheMiguel23/MemoryMesh';
const targetDir = path.join(process.cwd(), 'MemoryMesh');
console.log('[setup] Starting MemoryMesh installation...');
if (fs.existsSync(targetDir)) {
console.log('[setup] MemoryMesh directory already exists. Attempting to update...');
try {
execSync('git pull', { cwd: targetDir, stdio: 'inherit' });
console.log('[setup] Successfully updated MemoryMesh.');
} catch (err) {
console.error('[setup] Failed to update MemoryMesh. Please check your git installation or internet connection.');
}
} else {
console.log(`[setup] Cloning ${repoUrl}...`);
try {
execSync(`git clone ${repoUrl} MemoryMesh`, { stdio: 'inherit' });
console.log('[setup] Successfully cloned MemoryMesh.');
} catch (err) {
console.error('[setup] Failed to clone MemoryMesh.');
process.exit(1);
}
}
// Crucial step for the wrapper:
// We need to build MemoryMesh so that dist/ exists and contains schemas.
console.log('[setup] Building MemoryMesh...');
try {
// Step 1: Install dependencies in the sub-project (using --ignore-scripts to avoid 'prepare' script error)
console.log('[setup] Installing dependencies (ignoring scripts)...');
execSync('npm install --ignore-scripts', { cwd: targetDir, stdio: 'inherit' });
const binPath = path.join(targetDir, 'node_modules', '.bin');
// Step 2: Run build commands using absolute paths to local binaries
console.log('[setup] Compiling TypeScript...');
execSync(`${path.join(binPath, 'tsc')}`, { cwd: targetDir, stdio: 'inherit' });
console.log('[setup] Running tsc-alias...');
execSync(`${path.join(binPath, 'tsc-alias')}`, { cwd: targetDir, stdio: 'inherit' });
console.log('[setup] Setting permissions and copying files...');
// Use space before arguments
execSync(`${path.join(binPath, 'shx')} chmod +x dist/*.js`, { cwd: targetDir, stdio: 'inherit' });
execSync(`${path.join(binPath, 'copyfiles')} -u 1 src/data/schemas/*.json src/data/*.json dist/`, { cwd: targetDir, stdio: 'inherit' });
console.log('[setup] MemoryMesh built successfully.');
} catch (err) {
console.error('[setup] Failed to build MemoryMesh after installation.');
process.exit(1);
}
console.log('[setup] Environment ready.');
}
setup().catch(err => {
console.error('[setup] Unexpected error:', err);
process.exit(1);
});
scripts / setup.cjs
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
async function setup() {
const repoUrl = 'https://github.com/CheMiguel23/MemoryMesh';
const targetDir = path.join(process.cwd(), 'MemoryMesh');
console.log('[setup] Starting MemoryMesh installation...');
if (fs.existsSync(targetDir)) {
console.log('[setup] MemoryMesh directory already exists. Attempting to update...');
try {
execSync('git pull', { cwd: targetDir, stdio: 'inherit' });
console.log('[setup] Successfully updated MemoryMesh.');
} catch (err) {
console.error('[setup] Failed to update MemoryMesh. Please check your git installation or internet connection.');
}
} else {
console.log(`[setup] Cloning ${repoUrl}...`);
try {
execSync(`git clone ${repoUrl} MemoryMesh`, { stdio: 'inherit' });
console.log('[setup] Successfully cloned MemoryMesh.');
} catch (err) {
console.error('[setup] Failed to clone MemoryMesh.');
process.exit(1);
}
}
// Crucial step for the wrapper:
// We need to build MemoryMesh so that dist/ exists and contains schemas.
console.log('[setup] Building MemoryMesh...');
try {
// Step 1: Install dependencies in the sub-project (using --ignore-scripts to avoid 'prepare' script error)
console.log('[setup] Installing dependencies (ignoring scripts)...');
execSync('npm install --ignore-scripts', { cwd: targetDir, stdio: 'inherit' });
const binPath = path.join(targetDir, 'node_modules', '.bin');
// Step 2: Run build commands using absolute paths to local binaries
console.log('[setup] Compiling TypeScript...');
execSync(`${path.join(binPath, 'tsc')}`, { cwd: targetDir, stdio: 'inherit' });
console.log('[setup] Running tsc-alias...');
execSync(`${path.join(binPath, 'tsc-alias')}`, { cwd: targetDir, stdio: 'inherit' });
console.log('[setup] Setting permissions and copying files...');
// Use space before arguments
execSync(`${path.join(binPath, 'shx')} chmod +x dist/*.js`, { cwd: targetDir, stdio: 'inherit' });
execSync(`${path.join(binPath, 'copyfiles')} -u 1 src/data/schemas/*.json src/data/*.json dist/`, { cwd: targetDir, stdio: 'inherit' });
console.log('[setup] MemoryMesh built successfully.');
} catch (err) {
console.error('[setup] Failed to build MemoryMesh after installation.');
process.exit(1);
}
console.log('[setup] Environment ready.');
}
setup().catch(err => {
console.error('[setup] Unexpected error:', err);
process.exit(1);
});