Skip to content

Commit

Permalink
wip: wip (hooray)
Browse files Browse the repository at this point in the history
  • Loading branch information
remmycat committed Feb 7, 2024
1 parent e09c0f3 commit 5980e92
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 132 deletions.
28 changes: 5 additions & 23 deletions bin/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,7 @@ const cli = require("cac")();
const chalk = require("chalk");
const clear = require("clear");

const { rootLogger } = require("ts-jest");
const {
configuration,
Install,
Check,
Update,
} = require("../dist/main.umd.js");
const { Install, Check, Update } = require("../dist/main.umd.js");
const { version } = require("../package.json");

clear();
Expand All @@ -29,11 +23,7 @@ cli
"The root folder of the project, the one where the documentation folder is or will be located."
)
.action((options) => {
const install = new Install({
...options,
...configuration,
packageVersion: version,
});
const install = new Install(options, version);
install.run();
});

Expand All @@ -47,11 +37,7 @@ cli
"The root folder of the project, the one where the documentation folder is located."
)
.action((options) => {
const check = new Check({
...options,
...configuration,
packageVersion: version,
});
const check = new Check(options, version);
check.run();
});

Expand All @@ -65,14 +51,10 @@ cli
"The root folder of the project, the one where the documentation folder is located."
)
.action((options) => {
const update = new Update({
...options,
...configuration,
packageVersion: version,
});
const update = new Update(options, version);
update.run();
});

cli.help();
cli.version(require("../package.json").version);
cli.version(version);
cli.parse();
9 changes: 3 additions & 6 deletions src/__tests__/check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,9 @@ describe("deven-cli", () => {
lazy: false,
}),
});
check = new Check({
basePath: "fake_test_folder",
...configuration,
moduleBasePath: path.join(".", "src"),
packageVersion: "1.0.0",
});
check = new Check({ basePath: "fake_test_folder" }, "1.0.0");
// installation path during tests is relative to the uncompiled source files
check.ownInstallationBasePath = path.join(__dirname, "../..");
});

describe("check", () => {
Expand Down
34 changes: 18 additions & 16 deletions src/__tests__/command.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as path from "path";
import * as fs from "fs-extra";
import { configuration } from "../shared/configuration";
import { Command } from "../commands/command";
import { BaseCommand } from "../commands/command";
import mockFs from "mock-fs";
import {
mockProcessExit,
Expand All @@ -15,7 +15,7 @@ let mockStdout: jest.SpyInstance;
let mockStderr: jest.SpyInstance;
let mockLog: jest.SpyInstance;

let command: Command;
let command: BaseCommand;
describe("deven-cli", () => {
afterEach(() => {
mockFs.restore();
Expand All @@ -38,12 +38,14 @@ describe("deven-cli", () => {
lazy: false,
}),
});
command = new Command({
basePath: "fake_test_folder",
...configuration,
moduleBasePath: path.join(".", "src"),
packageVersion: "1.0.0",
});
command = new BaseCommand(
{
basePath: "fake_test_folder",
},
"1.0.0"
);
// installation path during tests is relative to the uncompiled source files
command.ownInstallationBasePath = path.join(__dirname, "../..");
});

describe("command", () => {
Expand Down Expand Up @@ -78,32 +80,32 @@ describe("deven-cli", () => {
);
});
it("return false when the config file doesn't exist", async () => {
expect(command.existsConfigFile).toBeFalsy();
expect(command.existsConfigFile()).toBeFalsy();
});
it("return true when the config file exists", async () => {
fs.writeFileSync(command.configFilePath, "");
expect(command.existsConfigFile).toBeTruthy();
expect(command.existsConfigFile()).toBeTruthy();
});
it("return false when the outdated doc folder doesn't exist", async () => {
expect(command.existsOutdatedDocFolder).toBeFalsy();
expect(command.existsOutdatedDocFolder()).toBeFalsy();
});
it("return true when the outdated doc folder exists", async () => {
fs.mkdirSync(command.outdatedDocPath);
expect(command.existsOutdatedDocFolder).toBeTruthy();
expect(command.existsOutdatedDocFolder()).toBeTruthy();
});
it("return the list of all the available chapters (except the readme)", async () => {
expect(command.docsSourceFiles.length).toBe(8);
expect(command.findDocsSourceFiles().length).toBe(8);
});
it("return the list of all local chapters (except the readme)", async () => {
fs.copySync(command.docsSourcePath, command.docsPath);
expect(command.docsFiles.length).toBe(8);
expect(command.findDocsFiles().length).toBe(8);
});
it("return the list of all the chapters", async () => {
fs.copySync(command.docsSourcePath, command.docsPath);
expect(command.coverage).toBe(100);
expect(command.coverage()).toBe(100);
fs.rmSync(path.join(command.docsPath, "CONTRIBUTE.md"));
fs.rmSync(path.join(command.docsPath, "TESTING.md"));
expect(command.coverage).toBe(75);
expect(command.coverage()).toBe(75);
});
});
});
14 changes: 8 additions & 6 deletions src/__tests__/install.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,14 @@ describe("deven-cli", () => {
}),
});
enquirer.prompt = jest.fn().mockResolvedValue({ confirm: true });
install = new Install({
basePath: "fake_test_folder",
...configuration,
moduleBasePath: path.join(".", "src"),
packageVersion: "1.0.0",
});
install = new Install(
{
basePath: "fake_test_folder",
},
"1.0.0"
);
// installation path during tests is relative to the uncompiled source files
install.ownInstallationBasePath = path.join(__dirname, "../..");
});

describe("install", () => {
Expand Down
22 changes: 14 additions & 8 deletions src/__tests__/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,14 @@ describe("deven-cli", () => {
lazy: false,
}),
});
update = new Update({
basePath: "fake_test_folder",
...configuration,
moduleBasePath: path.join(".", "src"),
packageVersion: "1.0.0",
});
update = new Update(
{
basePath: "fake_test_folder",
},
"1.0.0"
);
// installation path during tests is relative to the uncompiled source files
update.ownInstallationBasePath = path.join(__dirname, "../..");
});

describe("update", () => {
Expand Down Expand Up @@ -175,13 +177,17 @@ describe("deven-cli", () => {
fs.writeFileSync(update.readmePath, "");
fs.writeFileSync(update.configFilePath, "");
update.updateChapters();
expect(update.docsFiles.length).toBe(update.docsSourceFiles.length);
expect(update.findDocsFiles().length).toBe(
update.findDocsSourceFiles().length
);
});
it("creates the docs folder and copies the missing files into it", async () => {
fs.writeFileSync(update.readmePath, "");
fs.writeFileSync(update.configFilePath, "");
update.updateChapters();
expect(update.docsFiles.length).toBe(update.docsSourceFiles.length);
expect(update.findDocsFiles().length).toBe(
update.findDocsSourceFiles().length
);
});

it("updates the version in the config file ", async () => {
Expand Down
18 changes: 9 additions & 9 deletions src/commands/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,32 @@ import Table from "cli-table3";

import { logger } from "../Logger";
import { messages } from "../shared/messages";
import { Command } from "./command";
import { BaseCommand, ExecutableCommand } from "./command";

export class Check extends Command {
export class Check extends BaseCommand implements ExecutableCommand {
public preliminaryCheck(): void {
if (this.existsConfigFile) {
if (this.existsConfigFile()) {
logger.info(messages.check.checkConfigExists);
} else {
logger.error(messages.check.checkConfigNotExists);
process.exit(1);
}

if (this.existsDocsFolder) {
if (this.existsDocsFolder()) {
logger.info(messages.check.checkFolderExist);
} else {
logger.error(messages.check.checkFolderNotExist);
process.exit(1);
}

if (this.existsOutdatedDocFolder) {
if (this.existsOutdatedDocFolder()) {
logger.info(messages.check.checkOutdatedFolderNotExist);
} else {
logger.error(messages.check.checkOutdatedFolderExist);
process.exit(1);
}

if (this.existsReadme) {
if (this.existsReadme()) {
logger.info(messages.check.readmeExists);
} else {
logger.error(messages.check.checkFolderNotExist);
Expand All @@ -42,15 +42,15 @@ export class Check extends Command {
style: { head: ["cyan"] },
head: [
`Files (vers. ${this.packageVersion})`,
`Project (${Math.round(this.coverage)}% file coverage)`,
`Project (${Math.round(this.coverage())}% file coverage)`,
],
colWidths: [40],
});

this.docsSourceFiles.forEach((f) => {
this.findDocsSourceFiles().forEach((f) => {
table.push([
f.replace(".md", ""),
this.docsFiles.includes(f)
this.findDocsFiles().includes(f)
? chalk.green(`Found`)
: chalk.red("Not found"),
]);
Expand Down
Loading

0 comments on commit 5980e92

Please sign in to comment.