Skip to content

Commit

Permalink
⬆️ Upgrade to oclif v2
Browse files Browse the repository at this point in the history
  • Loading branch information
Lukáš Horák committed Jun 15, 2022
1 parent 2f4bf9c commit 8a15467
Show file tree
Hide file tree
Showing 20 changed files with 1,304 additions and 292 deletions.
19 changes: 19 additions & 0 deletions packages/cli/bin/dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node

require("dotenv-flow").config();

const oclif = require("@oclif/core");

const path = require("path");
const project = path.join(__dirname, "..", "tsconfig.json");

// In dev mode -> use ts-node and dev plugins
process.env.NODE_ENV = "development";

require("ts-node").register({ project });

// In dev mode, always show stack traces
oclif.settings.debug = true;

// Start the CLI
oclif.run().then(oclif.flush).catch(oclif.Errors.handle);
3 changes: 3 additions & 0 deletions packages/cli/bin/dev.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off

node "%~dp0\dev" %*
8 changes: 5 additions & 3 deletions packages/cli/bin/run
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

require("dotenv-flow").config();

require("@oclif/command")
const oclif = require("@oclif/core");

oclif
.run()
.then(require("@oclif/command/flush"))
.catch(require("@oclif/errors/handle"));
.then(require("@oclif/core/flush"))
.catch(require("@oclif/core/handle"));
12 changes: 6 additions & 6 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
"bugs": "https://github.com/AckeeCZ/lokse/issues",
"dependencies": {
"@lokse/core": "^2.1.4",
"@oclif/command": "^1",
"@oclif/config": "^1",
"@oclif/core": "^1.9.2",
"@oclif/errors": "^1.3.4",
"@oclif/plugin-help": "^3",
"@oclif/plugin-help": "^5",
"@oclif/plugin-version": "^1.1.0",
"@sindresorhus/slugify": "^1.1.0",
"@types/array.prototype.flat": "^1.2.1",
Expand All @@ -35,8 +33,8 @@
"update-notifier": "^5.1.0"
},
"devDependencies": {
"@oclif/dev-cli": "^1",
"@oclif/test": "^1",
"oclif": "^2",
"@oclif/test": "^2",
"@types/jest-when": "^2.7.2",
"@types/node": "^12",
"jest-when": "^3.0.1"
Expand All @@ -52,7 +50,9 @@
],
"homepage": "https://github.com/AckeeCZ/lokse",
"keywords": [
"oclif"
"cli",
"localization",
"spreadsheet"
],
"license": "MIT",
"main": "lib/index.js",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Command } from "@oclif/command";
import { Command } from "@oclif/core";
import * as updateNotifier from "update-notifier";

import { getConfig } from "@lokse/core";
Expand All @@ -17,6 +17,6 @@ export default abstract class Base extends Command {
});
notifier.notify();

this.conf = getConfig();
this.conf = await getConfig();
}
}
14 changes: 7 additions & 7 deletions packages/cli/src/commands/__tests__/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test as oclifTest } from "@oclif/test";
import { cosmiconfigSync } from "cosmiconfig";
import { cosmiconfig } from "cosmiconfig";
import * as dedent from "dedent";
import { prompt } from "inquirer";
import logger from "../../logger";
Expand All @@ -8,7 +8,7 @@ jest.mock("cosmiconfig");
const explorerMock = {
search: jest.fn(),
};
(cosmiconfigSync as jest.Mock).mockReturnValue(explorerMock);
(cosmiconfig as jest.Mock).mockReturnValue(explorerMock);

const writeFileAsyncMock = jest.fn();

Expand Down Expand Up @@ -38,7 +38,7 @@ describe("init command", () => {
.stdout()
.setupMocks()
.do(() => {
explorerMock.search.mockReturnValue({
explorerMock.search.mockResolvedValue({
config: { splitTranslations: true },
});
})
Expand All @@ -55,7 +55,7 @@ describe("init command", () => {
test
.setupMocks()
.do(() => {
explorerMock.search.mockReturnValue(null);
explorerMock.search.mockResolvedValue(null);
promptMock
.mockReturnValueOnce({ type: "typescript" })
.mockReturnValueOnce({
Expand Down Expand Up @@ -93,7 +93,7 @@ describe("init command", () => {
test
.setupMocks()
.do(() => {
explorerMock.search.mockReturnValue(null);
explorerMock.search.mockResolvedValue(null);
promptMock
.mockReturnValueOnce({ type: "javascript" })
.mockReturnValueOnce({
Expand Down Expand Up @@ -132,7 +132,7 @@ describe("init command", () => {
test
.setupMocks()
.do(() => {
explorerMock.search.mockReturnValue(null);
explorerMock.search.mockResolvedValue(null);
promptMock.mockReturnValueOnce({ type: "rc file" }).mockReturnValueOnce({
sheetId: "",
outDir: "",
Expand Down Expand Up @@ -161,7 +161,7 @@ describe("init command", () => {
test
.setupMocks()
.do(() => {
explorerMock.search.mockReturnValue(null);
explorerMock.search.mockResolvedValue(null);
promptMock
.mockReturnValueOnce({ type: "typescript" })
.mockReturnValueOnce({
Expand Down
36 changes: 18 additions & 18 deletions packages/cli/src/commands/__tests__/update.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { test as oclifTest } from "@oclif/test";
import { cosmiconfigSync } from "cosmiconfig";
import { cosmiconfig } from "cosmiconfig";
import * as dedent from "dedent";
import { when } from "jest-when";

Expand All @@ -21,7 +21,7 @@ jest.mock("cosmiconfig", () => {
};

return {
cosmiconfigSync: jest.fn().mockReturnValue(mockExplorer),
cosmiconfig: jest.fn().mockReturnValue(mockExplorer),
};
});

Expand Down Expand Up @@ -66,7 +66,7 @@ WorksheetReaderMock.mockReturnValue({
const outputFormats = Object.values(OutputFormat).join(", ");

describe("update command", () => {
const searchMock = cosmiconfigSync("foo").search as jest.Mock;
const searchMock = cosmiconfig("foo").search as jest.Mock;

let consoleErrorBackup: typeof console.error;
const fakeSpreadsheetId = "fake-spreadsheet-id";
Expand Down Expand Up @@ -154,7 +154,7 @@ describe("update command", () => {

test
.do(() =>
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { languages: "cs,en" },
})
)
Expand Down Expand Up @@ -219,7 +219,7 @@ describe("update command", () => {
test
.setupMocks()
.do(() => {
searchMock.mockReturnValue({ config: { sheets: true } });
searchMock.mockResolvedValue({ config: { sheets: true } });

WorksheetReaderMock.mockImplementationOnce(() => {
throw new InvalidFilterError(true);
Expand All @@ -237,7 +237,7 @@ describe("update command", () => {
test
.setupMocks()
.do(() =>
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { sheets: "Secondary translations" },
})
)
Expand All @@ -253,7 +253,7 @@ describe("update command", () => {
test
.setupMocks()
.do(() =>
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { sheets: ["Main translations", "Secondary translations"] },
})
)
Expand All @@ -270,7 +270,7 @@ describe("update command", () => {
test
.setupMocks()
.do(() =>
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: {
sheets: {
include: ["Main translations", "Other translations"],
Expand All @@ -290,7 +290,7 @@ describe("update command", () => {
test
.setupMocks()
.do(() =>
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: {
sheets: {
exclude: ["Main translations", "Other translations"],
Expand All @@ -309,7 +309,7 @@ describe("update command", () => {
test
.setupMocks()
.do(() =>
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: {
sheets: {
include: "Main translations",
Expand Down Expand Up @@ -494,7 +494,7 @@ describe("update command", () => {
.setupMocks()
.do(() => {
mockRead.mockReturnValue(threeSheets);
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { splitTranslations: true },
});
mockWrite
Expand Down Expand Up @@ -559,7 +559,7 @@ describe("update command", () => {
.stub(process, "cwd", jest.fn().mockReturnValue("/ROOT_PKG_PATH"))
.do(() => {
mockRead.mockReturnValue(threeSheets);
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { splitTranslations: true },
});
})
Expand Down Expand Up @@ -625,7 +625,7 @@ describe("update command", () => {
.setupMocks()
.do(() => {
mockRead.mockReturnValue({ "Sheet 1": mockSheetLines });
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { splitTranslations: true },
});
})
Expand Down Expand Up @@ -664,7 +664,7 @@ describe("update command", () => {
.setupMocks()
.do(() => {
mockRead.mockReturnValue(threeSheets);
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { splitTranslations: ["sheet1", "sheet3"] },
});
})
Expand Down Expand Up @@ -778,7 +778,7 @@ describe("update command", () => {
throw new Error(`Write error 2`);
});

searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { splitTranslations: true },
});
})
Expand Down Expand Up @@ -861,7 +861,7 @@ describe("update command", () => {
"sheet1 Title": mockSheetLines,
"sheet2 Title": mockSheetLines2,
});
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { splitTranslations: ["sheet1", "sheet2"] },
});
})
Expand Down Expand Up @@ -932,7 +932,7 @@ describe("update command", () => {
"sheet1 Title": [{ key: "sheet.1.line" }, { key: "sheet.1.line" }],
"sheet2 Title": [{ key: "sheet.2.line" }, { key: "sheet.2.line" }],
});
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { splitTranslations: ["sheet.1", "sheet.2"] },
});
})
Expand Down Expand Up @@ -983,7 +983,7 @@ describe("update command", () => {
{ key: "sheet12.line" },
],
});
searchMock.mockReturnValue({
searchMock.mockResolvedValue({
config: { splitTranslations: ["sheet1", "sheet12"] },
});
})
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/commands/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flags } from "@oclif/command";
import { Flags } from "@oclif/core";
import { promisifyAll } from "bluebird";
import { template } from "lodash";
import * as path from "path";
Expand All @@ -22,7 +22,7 @@ class Init extends Base {
static examples = [`$ ${NAME} init`];

static flags = {
help: flags.help({ char: "h" }),
help: Flags.help({ char: "h" }),
};

async run(): Promise<void> {
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/commands/open.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { flags } from "@oclif/command";
import { Flags } from "@oclif/core";
import * as open from "open";

import { NAME, createSheetUrl } from "@lokse/core";
Expand All @@ -13,12 +13,12 @@ class Open extends Base {
];

static flags = {
help: flags.help({ char: "h" }),
help: Flags.help({ char: "h" }),
id: idFlag.flag(),
};

async run(): Promise<void> {
const { flags } = this.parse(Open);
const { flags } = await this.parse(Open);

const sheetId = flags.id;

Expand Down
Loading

0 comments on commit 8a15467

Please sign in to comment.