Wingysam / Christmas-Community

Christmas lists for families
GNU Affero General Public License v3.0
245 stars 41 forks source link

build: support multi platform development/deployment #109

Closed cj13579 closed 10 months ago

cj13579 commented 10 months ago

For my sins, I am a Windows user. This change makes local development and deployment easier for folks like me.

I've removed the placeholder bulmaswatch link that was in the repository and replaced it with instructions in the README on how to create platform specific symbolic links. For non-Windows users, they just need to follow the code block. Windows folks still need to do a little extra.

The change also modifies the Dockerfile so that existing links are ignored and in-container link is created.

Wingysam commented 10 months ago

I don't like adding the extra step of manually creating the symlink. I would also prefer to switch the project from yarn to npm. Maybe creating the symlink could be done by a custom postinstall script that does the right thing depending on platform? That way npm would automatically run it and there would be no additional step.

cj13579 commented 10 months ago

I get that. The problem is that Windows is annoying for symbolic links. You have to create them with Administrator permissions, even if its in a non-privileged location. So an npm install with a postinstall hook to a node script or something still fails:

PS C:\Users\Chris\Source\cj13579\Christmas-Community> node .\postinstall.js
[Error: EPERM: operation not permitted, symlink '.\node_modules\bulmaswatch' -> 'C:\Users\Chris\Source\cj13579\Christmas-Community\src\static\libraries\bulmaswatch'] {
  errno: -4048,
  code: 'EPERM',
  syscall: 'symlink',
  path: '.\\node_modules\\bulmaswatch',
  dest: 'C:\\Users\\Chris\\Source\\cj13579\\Christmas-Community\\src\\static\\libraries\\bulmaswatch'
}

That postinstall.js file looks like this:

const fs = require('fs');
fs.symlink('./node_modules/bulmaswatch', './src/static/libraries/bulmaswatch', (err) => { 
    if (err) console.log(err); 
}); 

My (albeit brief) search doesn't suggest there is a way around it. It would be possible to have a platform check here and it automatically create the links on posix systems and spit out a note on windows with the command to run (as an Administrator).

cj13579 commented 10 months ago

@Wingysam I've added another change to remove references to yarn. I've also added a postinstall action which produces the following output currently:

image

Wingysam commented 10 months ago

It looks like the Dockerfile still manually symlinks the directory. Should that be removed now that npm install does it?

cj13579 commented 10 months ago

Yes, it should! I’ll do that today.

cj13579 commented 10 months ago

@Wingysam - yesterday ran away with me. removed the manual symlink creation from the docker file and updated a path bug as part of testing.

Wingysam commented 10 months ago

Thanks for doing that!