Skip to content

Commit

Permalink
Update dependencies
Browse files Browse the repository at this point in the history
Fixes: #24
  • Loading branch information
darekkay committed Mar 21, 2021
1 parent 1422f8c commit b2fbdf8
Show file tree
Hide file tree
Showing 9 changed files with 1,050 additions and 941 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
## [Unreleased]

- :book: Add documentation for GitLab Pages integration.
- :hammer: Add CLI unit tests.
- :construction_worker: Add CLI unit tests.
- :construction_worker: Update dependencies.

## [2.2.4] - 2020-10-19

Expand Down
17 changes: 14 additions & 3 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const build = require("./build/index");
const importBookmarks = require("./import");
const report = require("./report");

// eslint-disable-next-line consistent-return
const cli = (program, argv) => {
program
.description(pkg.description)
Expand Down Expand Up @@ -57,12 +58,22 @@ const cli = (program, argv) => {

program.parse(argv);

const commands = program.args.filter((argument) => argument._name);
// const commands = program.args.filter((argument) => argument._name);

const availableCommands = program.commands.map((command) => command.name());

// missing/unknown subcommand
if (program.args.length === 0 || commands.length === 0) {
logger.error(`Error: Missing or unknown command.\n`);
if (program.rawArgs.length < 3) {
logger.error(`Error: Missing command.\n`);
program.help();
return process.exit(1);
}

const command = program.rawArgs[2];
if (!availableCommands.includes(command)) {
logger.error(`Error: Unknown command '${command}'.\n`);
program.help();
return process.exit(1);
}
};

Expand Down
2 changes: 1 addition & 1 deletion bin/report/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const report = ({ args, options }) => {
const links = files
.map((file) => {
try {
return yaml.safeLoad(fs.readFileSync(file, "utf8"));
return yaml.load(fs.readFileSync(file, "utf8"));
} catch (error) {
return logger.error(
`Could not convert YAML file: ${file}\n `,
Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@
"url": "https://github.com/darekkay/static-marks/issues"
},
"dependencies": {
"@darekkay/logger": "1.0.2",
"@darekkay/logger": "1.1.0",
"bookmarks-parser": "1.5.0",
"commander": "3.0.2",
"commander": "4.1.1",
"glob": "7.1.6",
"js-yaml": "3.14.0",
"mkdirp": "0.5.1"
"js-yaml": "4.0.0",
"mkdirp": "1.0.4"
},
"devDependencies": {
"@darekkay/eslint-config": "2.1.1",
"chai": "4.2.0",
"eslint": "7.6.0",
"eslint-config-prettier": "6.11.0",
"eslint-plugin-import": "2.22.0",
"@darekkay/eslint-config": "2.4.0",
"chai": "4.3.4",
"eslint": "7.17.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-import": "2.22.1",
"eslint-plugin-node": "11.1.0",
"eslint-plugin-prettier": "3.1.4",
"eslint-plugin-unicorn": "21.0.0",
"mocha": "8.1.0",
"prettier": "2.0.5",
"eslint-plugin-prettier": "3.3.1",
"eslint-plugin-unicorn": "26.0.1",
"mocha": "8.3.2",
"prettier": "2.2.1",
"sinon": "9.2.4"
},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions src/import/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require("fs");
const parse = require("bookmarks-parser");
const { safeDump } = require("js-yaml");
const { dump } = require("js-yaml");
const logger = require("@darekkay/logger");

const { writeFile } = require("../utils");
Expand Down Expand Up @@ -45,7 +45,7 @@ const importBookmarks = (file, config) => {
});
});

const yaml = safeDump({ Imported: nonEmpty });
const yaml = dump({ Imported: nonEmpty });

if (config.output) {
writeFile(config.output, yaml);
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const build = (files, config) => {
const bookmarks = files
.map((file) => {
try {
const json = yaml.safeLoad(fs.readFileSync(file, "utf8"));
const json = yaml.load(fs.readFileSync(file, "utf8"));
return {
key: path.basename(file, ".yml"),
collections: transform(json),
Expand Down
20 changes: 11 additions & 9 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ const mkdirp = require("mkdirp");
const logger = require("@darekkay/logger");

const writeFile = (output, contents) => {
mkdirp(path.dirname(output), (error) => {
if (error) return logger.error(error);

return fs.writeFile(output, contents, (writeError) =>
writeError
? logger.error(writeError)
: logger.info(`Saved file: ${path.resolve(output)}`)
);
});
try {
mkdirp(path.dirname(output)).then(() => {
return fs.writeFile(output, contents, (writeError) =>
writeError
? logger.error(writeError)
: logger.info(`Saved file: ${path.resolve(output)}`)
);
});
} catch (error) {
logger.error(error);
}
};

module.exports.writeFile = writeFile;
18 changes: 13 additions & 5 deletions test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const report = require("../bin/report");
const cli = require("../bin/cli");

describe("CLI", () => {
afterEach(function () {
afterEach(() => {
sinon.restore();
});

Expand Down Expand Up @@ -101,35 +101,43 @@ describe("CLI", () => {
expect(reportSpy.callCount).to.equal(1);
});

it("display help page if no command is provided", () => {
it("display help page and exit if no command is provided", () => {
const consoleErrorSpy = sinon.fake();
sinon.replace(logger, "error", consoleErrorSpy);

const processExitSpy = sinon.fake();
sinon.replace(process, "exit", processExitSpy);

const program = new commander.Command();
const programHelpSpy = sinon.fake();
sinon.replace(program, "help", programHelpSpy);

cli(program, ["node", "static-marks"]);

expect(
consoleErrorSpy.calledWithMatch(sinon.match("Missing or unknown command"))
consoleErrorSpy.calledWithMatch(sinon.match("Missing command"))
).to.equal(true);
expect(programHelpSpy.callCount).to.equal(1);
expect(processExitSpy.callCount).to.equal(1);
});

it("display help page if an unknown command is provided", () => {
it("display help page and exit if an unknown command is provided", () => {
const consoleErrorSpy = sinon.fake();
sinon.replace(logger, "error", consoleErrorSpy);

const processExitSpy = sinon.fake();
sinon.replace(process, "exit", processExitSpy);

const program = new commander.Command();
const programHelpSpy = sinon.fake();
sinon.replace(program, "help", programHelpSpy);

cli(program, ["node", "static-marks", "unknown"]);

expect(
consoleErrorSpy.calledWithMatch(sinon.match("Missing or unknown command"))
consoleErrorSpy.calledWithMatch(sinon.match("Unknown command"))
).to.equal(true);
expect(programHelpSpy.callCount).to.equal(1);
expect(processExitSpy.callCount).to.equal(1);
});
});
Loading

0 comments on commit b2fbdf8

Please sign in to comment.