Skip to content

Commit

Permalink
♻️ Extract getConfig into the core package
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukáš Horák committed Mar 27, 2022
1 parent ed9be46 commit 1d14110
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 14 deletions.
3 changes: 0 additions & 3 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
},
"bugs": "https://github.com/AckeeCZ/lokse/issues",
"dependencies": {
"@endemolshinegroup/cosmiconfig-typescript-loader": "^3.0.2",
"@lokse/core": "^2.1.4",
"@oclif/command": "^1",
"@oclif/config": "^1",
Expand All @@ -22,8 +21,6 @@
"@types/dedent": "^0.7.0",
"@types/update-notifier": "^5.0.0",
"array.prototype.flat": "^1.2.4",
"cosmiconfig": "^7.0.0",
"cosmiconfig-ts-loader": "^0.1.1",
"dedent": "^0.7.0",
"dotenv-flow": "^3.2.0",
"open": "^7.2.1",
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Command } from "@oclif/command";
import * as updateNotifier from "update-notifier";

import { get as getConfig, ConfigType } from "./config";
import { getConfig } from "@lokse/core";
import type { ConfigType } from "@lokse/core";

const pkg = require("../package.json");

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/open.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { flags } from "@oclif/command";
import * as open from "open";

import { NAME } from "../constants";
import { NAME } from "@lokse/core";
import Base from "../base";
import * as cliFlags from "../flags";

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ import {
Line,
FatalError,
loadPlugins,
NAME,
} from "@lokse/core";
import type { WorksheetLinesByTitle } from "@lokse/core";

import { NAME } from "../constants";
import logger from "../logger";
import Base from "../base";

Expand Down
1 change: 0 additions & 1 deletion packages/cli/src/constants.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/cli/src/flags/id.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { flags } from "@oclif/command";
import { getConfig } from "@lokse/core";
import { MissingFlagValue } from "./errors";
import * as config from "../config";

export const flag = flags.build({
char: "i",
description: "spreadsheet id",

default: ({ flags }) => {
const conf = config.get();
const conf = getConfig();
const id = process.env.SPREADSHEET_ID ?? flags.id ?? conf?.sheetId;

return id;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"@types/google-spreadsheet": "^3.0.1",
"@types/mkdirp": "^1.0.1",
"bluebird": "^3.7.2",
"cosmiconfig": "^7.0.0",
"cosmiconfig-ts-loader": "^0.1.1",
"dedent": "^0.7.0",
"google-spreadsheet": "^3.2.0",
"lodash": "^4.17.20",
Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/config.ts → packages/core/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { cosmiconfigSync } from "cosmiconfig";
import typeScriptLoader from "cosmiconfig-ts-loader";
import { OutputFormat } from "@lokse/core";
import type { PluginName, PluginDefinition, SheetsFilter } from "@lokse/core";

import { NAME } from "./constants";
import { OutputFormat, NAME } from "./constants";
import type { PluginDefinition, PluginName } from "./plugins";
import type { SheetsFilter } from "./reader";

// TODO: use async API once custom oclif flags will be asynchronous
const explorerSync = cosmiconfigSync(NAME, {
Expand Down Expand Up @@ -41,7 +41,7 @@ export type ConfigType = {
plugins?: (PluginName | PluginDefinition)[];
};

export function get(): undefined | null | ConfigType {
export function getConfig(): undefined | null | ConfigType {
const result = explorerSync.search();
return result?.config;
}
2 changes: 2 additions & 0 deletions packages/core/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const NAME = "lokse";

export enum OutputFormat {
JSON = "json",
ANDROID = "android",
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ export { transformersByFormat } from "./transformer";
export { default as FileWriter } from "./writer";
export { default as Line } from "./line";

export { OutputFormat } from "./constants";
export { OutputFormat, NAME } from "./constants";

export { FatalError } from "./errors";

export * from "./config";

export * from "./plugins";

export * from "./utils";

0 comments on commit 1d14110

Please sign in to comment.