codeforpdx / PASS

PASS project - with HMIS module integration
MIT License
24 stars 24 forks source link

[Bug Report] - Cannot build properly with PowerShell #602

Open joshua-cornett opened 3 months ago

joshua-cornett commented 3 months ago

Describe the bug:

Build fails with config files when using PowerShell

Expected behavior:

The build should complete successfully without any errors

Actual Behavior:

The build fails after a few moments

To Reproduce:

  1. run npm start from PowerShell

Desktop (please complete the following information):

Possible Fix:

Ensure compatibility with PowerShell for builds in the long term.

Additional context:

The issue does not occur with WSL (Windows Subsystem for Linux), indicating an environment-specific problem.

leekahung commented 3 months ago

For additional context, could you include a screenshot of the error message? Think that would be useful when debugging.

leekahung commented 3 months ago

After discussion, we could potentially solve this with a new npm package that's used as a devDependency. A package like cross-env seems to be useful for cross-platform compatibility.

DionSat commented 2 months ago

I'm honestly not encountering any errors for this. I run windows on my desktop and tried to run npm run start through my windows powershell and it runs fine. image

Are you sure this is not an issue with your environment setup or PATH issue. I can't tell without the errors but since its able to build and run on my PowerShell then I don't think it's a compatibility issue.

joshua-cornett commented 2 months ago

I think you're probably right and we can see if I can't replicate it at tomorrow's meeting off of my laptop.

Sent with Proton Mail secure email.

On Tuesday, April 9th, 2024 at 4:41 PM, Dion Satcher @.***> wrote:

I'm honestly not encountering any errors for this. I run windows on my desktop and tried to run npm run start through my windows powershell and it runs fine. image.png (view on web)

Are you sure this is not an issue with your environment setup or PATH issue. I can't tell without the errors but since its able to build and run on my PowerShell then I don't think it's an environment issue.

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

leekahung commented 2 months ago

The issue seems to be related to incorrect syntax. Think we could resolve this by updating the syntax.

joshua-cornett commented 2 months ago

I believe I have a script which should handle cross-environment setup/installation. The only thing the user needs is to have node installed. I'm still testing it, but if it works, I think it'd be a nice one-size-fits-all.

If acceptable, this could reduce user setup instructions to:

  1. Install node
  2. Clone the repo with git clone https://github.com/codeforpdx/PASS.git
  3. Navigate to the cloned repo with cd PASS
  4. Run the setup script with node setup.js
#!/usr/bin/env node

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

// Detect the platform
const platform = process.platform;
const isWindows = platform === 'win32';
const isMacOS = platform === 'darwin';

// Function to check if a command exists
const commandExists = (command) => {
  try {
    const cmd = isWindows ? `where ${command}` : `command -v ${command}`;
    execSync(cmd, { stdio: 'ignore' });
    return true;
  } catch (error) {
    return false;
  }
};

// Adjust install commands based on OS
const installNvm = () => {
  if (isWindows) {
    console.log('Installing nvm-windows...');
    console.log('Downloading nvm-setup.exe...');
    const file = fs.createWriteStream('nvm-setup.exe');
    const request = https.get('https://github.com/coreybutler/nvm-windows/releases/latest/download/nvm-setup.exe', function(response) {
      response.pipe(file);
      file.on('finish', function() {
        file.close(() => {
          console.log('nvm-setup.exe downloaded successfully.');
          console.log('Please run nvm-setup.exe, follow the installation instructions, and then reopen your command prompt or PowerShell to continue.');
        });
      });
    }).on('error', function(err) {
      fs.unlink('nvm-setup.exe', () => {}); // Delete the file if download fails
      console.error('Error downloading nvm-setup.exe:', err);
    });
  } else if (isMacOS) {
    console.log('Installing nvm for macOS...');
    execSync('curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash', {
      stdio: 'inherit',
      shell: true
    });
    console.log('Please reopen your terminal and run the script again.');
  } else {
    console.log('Installing nvm for Unix-like OS...');
    execSync('curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash', {
      stdio: 'inherit',
      shell: true
    });
  }
};

// Check if nvm is installed
if (!commandExists('nvm')) {
  installNvm();
} else {
  console.log('NVM is already installed.');
}

// Define commands to be executed
const commands = ['nvm install 18', 'npm install'];

// Execute commands one by one
commands.forEach((command) => {
  try {
    console.log(`Executing command: ${command}`);
    execSync(command, { stdio: 'inherit', shell: true });
  } catch (error) {
    console.error(`Error executing command: ${command}`, error);
    process.exit(1);
  }
});

// Copying environment files
const templatePath = path.join(__dirname, 'env.template');
const envPath = path.join(__dirname, '.env');
try {
  console.log('Copying environment template file...');
  fs.copyFileSync(templatePath, envPath);
  console.log('Environment template file copied successfully.');
} catch (error) {
  console.error('Error copying environment template file:', error);
  process.exit(1);
}
joshua-cornett commented 1 month ago

For additional context, it has come to light that configuration has issues with file paths containing spaces.