@kui-shell/core
Version:
An Electron-based shell for cloud-native development
94 lines • 4.25 kB
JavaScript
/*
* Copyright 2017 The Kubernetes Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import Debug from 'debug';
const debug = Debug('main/main');
debug('loading');
function getPrefsFromEnv(env, defaultPrefs) {
if (env.subwindowPrefs) {
const envPrefs = typeof env.subwindowPrefs === 'string' ? JSON.parse(env.subwindowPrefs) : env.subwindowPrefs;
return Object.assign(defaultPrefs, envPrefs);
}
else {
return defaultPrefs;
}
}
/**
* This is the main entry point to kui
*
*/
export const main = (argv, env = process.env, execOptions) => __awaiter(void 0, void 0, void 0, function* () {
const N = argv.length;
const isRunningHeadless = !!process.env.KUI_HEADLESS || (argv[N - 3] === 'bash' && argv[N - 2] === 'websocket');
if (!isRunningHeadless || !!process.env.KUI_FORCE_GRAPHICS) {
// then spawn the electron graphics
debug('shortcut to graphics', argv);
const { getCommand, initElectron } = yield import(/* webpackChunkName: "electron-main" */ './spawn-electron');
const { argv: strippedArgv, subwindowPlease, subwindowPrefs } = getCommand(argv, process.cwd(), env, () => __awaiter(void 0, void 0, void 0, function* () {
return import('electron').catch(err => {
debug('Error importing electron. We are probably running a headless client.', err);
return { screen: undefined, BrowserWindow: undefined };
});
}));
initElectron(strippedArgv, { isRunningHeadless }, !!(env.subwindowPlease || subwindowPlease), getPrefsFromEnv(env, subwindowPrefs));
}
else {
// otherwise, don't spawn the graphics; stay in headless mode
const { initHeadless } = yield import(/* webpackChunkName: "headless-main" */ './headless');
const result = yield initHeadless(argv, false, isRunningHeadless, execOptions).catch(err => {
if (env.KUI_REPL_MODE) {
const errResponse = Object.assign({
code: err.code,
statusCode: err.statusCode,
message: err.message
}, err);
return errResponse;
}
else {
throw err;
}
});
if (env.KUI_REPL_MODE) {
if (env.KUI_REPL_MODE === 'stdout') {
debug('emitting repl mode result');
console.log(JSON.stringify({
type: typeof result,
response: result
}));
}
else {
debug('returning repl mode result', env.KUI_REPL_MODE);
return result;
}
}
}
// try {
// if (isRunningHeadless && app.dock) app.dock.hide()
// } catch (e) {
// }
debug('isRunningHeadless %s', isRunningHeadless);
debug('all done here, the rest is async');
});
main(process.argv, process.env, process.env.KUI_EXEC_OPTIONS && JSON.parse(process.env.KUI_EXEC_OPTIONS));
//# sourceMappingURL=main.js.map