Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PICGO_ENV should not be coupled in picgo-core #103

Closed
upupming opened this issue Oct 5, 2021 · 7 comments
Closed

PICGO_ENV should not be coupled in picgo-core #103

upupming opened this issue Oct 5, 2021 · 7 comments

Comments

@upupming
Copy link
Member

upupming commented Oct 5, 2021

Currently in picgo-core it will see if it is 'GUI' mode (in PicGo Electron) and look at different path for the clipboard scripts.

// for PicGo GUI
const env = ctx.getConfig('PICGO_ENV') === 'GUI'
const platformPaths: {
[index: string]: string
} = {
darwin: env ? path.join(ctx.baseDir, 'mac.applescript') : './clipboard/mac.applescript',
win32: env ? path.join(ctx.baseDir, 'windows.ps1') : './clipboard/windows.ps1',
win10: env ? path.join(ctx.baseDir, 'windows10.ps1') : './clipboard/windows10.ps1',
linux: env ? path.join(ctx.baseDir, 'linux.sh') : './clipboard/linux.sh',
wsl: env ? path.join(ctx.baseDir, 'wsl.sh') : './clipboard/wsl.sh'
}

In my opinion, picgo core is just a library, it should not handle this kind of "hack" by itself. In the past, this special hack also affects vs-picgo: PicGo/vs-picgo#75

Also, vs-picgo has to do something like "copy the clipboard" files when bundling itself. See:

https://github.com/PicGo/vs-picgo/blob/f81a1dd7eaa5daf4be2b7329d92e9abf829892b7/esbuild.mjs#L96-L99


I think all these problems can be solved by just read these scripts into bundle by something like raw-loader. And write to a script when needed before running the script. In this way, all the scripts can be "bundled" into picgo-core with no trouble. And no one needs to handle the scripts files any more.

I have solved this in #102

@Molunerfinn
Copy link
Member

PICGO_ENV will be used in many ways, such as GUI\CLI\WEB. But now it comes from ctx.getConfig which is a bad option. It will be used in plugins.

inline-loader is a good solution for these scripts, I think you should just open a PR for inline-loader, I will take care of PICGO_ENV

@upupming
Copy link
Member Author

upupming commented Oct 9, 2021

@Molunerfinn It seems the only usage of PICGO_ENV in picgo-core now is just to handle the clipboard script files, as I have used inline loader to load this scripts in PR #102, this PICGO_ENV is no longer used in picgo-core. It seems the PICGO_ENV is written to config file by PicGo Electron but not PicGo-Core.

@Molunerfinn
Copy link
Member

If we want to support picgo to different platforms, the PICGO_ENV will be a key for plugins to get

@Molunerfinn
Copy link
Member

For now, it may not be used in code, but would be used in the future

@upupming
Copy link
Member Author

upupming commented Oct 9, 2021

@Molunerfinn

If we want to support picgo to different platforms, the PICGO_ENV will be a key for plugins to get

Like your idea, this env will make plugins be aware of current picgo environment, it is super cool! But I think we should not save this PICGO_ENV in the configuration file but determine it at runtime. This is because:

  1. all environment web/cli/gui should be able to read an existed configuration file
  2. picgo electron depends on picgo-core, and picgo-core has cli integration, too. Actually picgo electron can still run cli mode if it wants.

@Molunerfinn
Copy link
Member

Yes, as I said, it comes from ctx.getConfig which is a bad option, it will be a param of ctx, that would be better.

@Molunerfinn
Copy link
Member

done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants