From 1508fc4dc4765ad6ff702d2566afcfaf8fa8a91a Mon Sep 17 00:00:00 2001 From: Rafa Mel Date: Tue, 7 May 2019 09:31:26 +0200 Subject: [PATCH] feat(public): removes public options; kpo file, when js, should also export an options and scripts o BREAKING CHANGE: doesn't further export options(); kpo file should have a scripts and options key containing an object, even when a js file; kpo file can't export a default function --- src/core/load.ts | 34 +++++++++++++++++----------------- src/public/kpo/index.ts | 1 - src/public/kpo/options.ts | 15 --------------- 3 files changed, 17 insertions(+), 33 deletions(-) delete mode 100644 src/public/kpo/options.ts diff --git a/src/core/load.ts b/src/core/load.ts index b011b1b..c354694 100644 --- a/src/core/load.ts +++ b/src/core/load.ts @@ -16,7 +16,9 @@ export default async function load(paths: IPaths): Promise { .then((pkg) => processPkg(paths.pkg as string, pkg)) : null; - const kpo = paths.kpo ? await loadFile(paths.kpo) : null; + const kpo = paths.kpo + ? await loadFile(paths.kpo).then((kpo) => (kpo ? processKpo(kpo) : null)) + : null; return { kpo, pkg }; } @@ -28,17 +30,27 @@ export async function loadFile(file: string): Promise | null> { case '.js': return requireLocal(file); case '.json': - return fs.readJSON(file).then(processStatic); + return fs.readJSON(file); case '.yml': case '.yaml': - const kpo = yaml.safeLoad(await fs.readFile(file).then(String)); - return processStatic(kpo); + return yaml.safeLoad(await fs.readFile(file).then(String)); default: throw Error(`Extension not valid for ${file}`); } } -export async function processStatic( +export async function requireLocal(file: string): Promise> { + let kpo: any; + try { + kpo = require(file); + } catch (err) { + throw open(err); + } + + return kpo; +} + +export async function processKpo( kpo: IOfType ): Promise | null> { if (kpo.options) await options.setScope(kpo.options); @@ -63,15 +75,3 @@ export async function processPkg( await options.setScope(opts); return pkg; } - -export async function requireLocal(file: string): Promise> { - let scripts: any; - try { - scripts = require(file); - } catch (err) { - throw open(err); - } - - // TODO remove as fn - return typeof scripts === 'function' ? scripts(_public) : scripts; -} diff --git a/src/public/kpo/index.ts b/src/public/kpo/index.ts index 3e05212..a82f78d 100644 --- a/src/public/kpo/index.ts +++ b/src/public/kpo/index.ts @@ -1,4 +1,3 @@ export { default as run } from './run'; export { default as list } from './list'; -export { default as options } from './options'; export { default as raise } from './raise'; diff --git a/src/public/kpo/options.ts b/src/public/kpo/options.ts deleted file mode 100644 index 8215f32..0000000 --- a/src/public/kpo/options.ts +++ /dev/null @@ -1,15 +0,0 @@ -import core from '~/core'; -import { IScopeOptions } from '~/types'; -import { error } from '~/utils/errors'; - -// TODO remove -/** - * Programmatically sets *kpo* options. - */ -export default async function options(opts: IScopeOptions): Promise { - try { - await core.options.setScope(opts); - } catch (err) { - throw error(err); - } -}