2020-02-27 14:55:30 +00:00
|
|
|
/*
|
|
|
|
Copyright 2020 Balena
|
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import * as BalenaSdk from 'balena-sdk';
|
2020-02-28 15:25:12 +00:00
|
|
|
import chalk from 'chalk';
|
2020-02-28 13:06:14 +00:00
|
|
|
import * as visuals from 'resin-cli-visuals';
|
2020-02-27 14:55:30 +00:00
|
|
|
|
|
|
|
// Equivalent of _.once but avoiding the need to import lodash for lazy deps
|
|
|
|
const once = <T>(fn: () => T) => {
|
|
|
|
let cached: T;
|
|
|
|
return (): T => {
|
|
|
|
if (!cached) {
|
|
|
|
cached = fn();
|
|
|
|
}
|
|
|
|
return cached;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
export const getBalenaSdk = once(() =>
|
|
|
|
(require('balena-sdk') as typeof BalenaSdk).fromSharedOptions(),
|
|
|
|
);
|
2020-02-28 13:06:14 +00:00
|
|
|
|
|
|
|
export const getVisuals = once(
|
|
|
|
() => require('resin-cli-visuals') as typeof visuals,
|
|
|
|
);
|
2020-02-28 15:25:12 +00:00
|
|
|
|
|
|
|
export const getChalk = once(() => require('chalk') as typeof chalk);
|