2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-06-03 13:20:47 +00:00
nativefier/src/infer/inferOs.ts
Adam Weeden 8f9135312b
Docker: fix Windows builds (fix #997), line endings, switch to Alpine (PR #1122)
- Docker builds for Windows are fixed (fixes #997)
- Switched over to use Alpine (as was indicated as desired in https://github.com/nativefier/nativefier/issues/375#issuecomment-304247033) - which may mean #375 is fixed as well.
- Fixed bug where Docker has the wrong line endings when copying from a Windows host
- Fixed the invalid `arm` arch to `armv7l`
- Add `npm t` to the docker build to ensure tests pass before we start trying to do builds
- Add a message to help the user when trying to build Mac apps on Windows as a non-Admin (currently an unhelpful exception)

Co-authored-by: Ronan Jouchet <ronan@jouchet.fr>
2021-03-02 00:16:30 -05:00

44 lines
1.2 KiB
TypeScript

import * as os from 'os';
import * as log from 'loglevel';
// Ideally we'd get this list directly from electron-packager, but it's not
// accessible in the package without importing its private js files, which felt
// dirty. So if those change, we'll update these as well.
// https://electron.github.io/electron-packager/master/interfaces/electronpackager.options.html#platform
// https://electron.github.io/electron-packager/master/interfaces/electronpackager.options.html#arch
export const supportedArchs = ['ia32', 'x64', 'armv7l', 'arm64'];
export const supportedPlatforms = [
'darwin',
'linux',
'mac',
'mas',
'osx',
'windows',
];
export function inferPlatform(): string {
const platform = os.platform();
if (
platform === 'darwin' ||
// @ts-ignore
platform === 'mas' ||
platform === 'win32' ||
platform === 'linux'
) {
log.debug('Inferred platform', platform);
return platform;
}
throw new Error(`Untested platform ${platform} detected`);
}
export function inferArch(): string {
const arch = os.arch();
if (!supportedArchs.includes(arch)) {
throw new Error(`Incompatible architecture ${arch} detected`);
}
log.debug('Inferred arch', arch);
return arch;
}