Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["@babel/plugin-transform-runtime", "@babel/plugin-proposal-object-rest-spread"],
"presets": [
[
"@babel/preset-env",
{
"modules": "commonjs"
}
]
],
"plugins": [
[
"@babel/plugin-transform-modules-commonjs",
{
"allowTopLevelThis": true,
"interop": "auto",
"strictMode": false
}
]
],
"env": {
"test": {
"plugins": ["istanbul"]
}
},
"targets": "node 14.0"
}
}
14 changes: 0 additions & 14 deletions .editorconfig

This file was deleted.

54 changes: 0 additions & 54 deletions .eslintrc.yaml

This file was deleted.

2 changes: 1 addition & 1 deletion .jsdoc.conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"destination": "./docs/",
"encoding": "utf8",
"private": true,
"template": "./node_modules/minami"
"template": "node_modules/clean-jsdoc-theme"
}
}
67 changes: 67 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import eslint from "@eslint/js";
import eslintConfigPrettier from "eslint-config-prettier/flat";
import importPlugin from "eslint-plugin-import";
import mochaPlugin from "eslint-plugin-mocha";
import pluginPromise from "eslint-plugin-promise";
// eslint-disable-next-line import/no-unresolved
import { defineConfig, globalIgnores } from "eslint/config";
import globals from "globals";

export default defineConfig([
globalIgnores(["docs/**", "dist/**", "bin/**"]),
eslint.configs.recommended,
mochaPlugin.configs.flat.recommended,
importPlugin.flatConfigs.recommended,
pluginPromise.configs["flat/recommended"],
{
files: ["**/*.{cjs,mjs,js}"],
languageOptions: {
ecmaVersion: 2020,
sourceType: "module",
globals: {
...globals.node,
},
},
rules: {
"no-undef": "error",
"no-unreachable": 1,
"no-empty": "error",
"array-callback-return": "error",
"no-var": "error",
"prefer-const": "error",
"no-template-curly-in-string": "error",
"consistent-return": "error",
"no-multiple-empty-lines": ["error", { max: 1, maxBOF: 0 }],
"arrow-body-style": ["error", "as-needed"],
"prefer-arrow-callback": ["error", { allowNamedFunctions: true }],
"prefer-destructuring": ["error", { object: true, array: false }],
"prefer-spread": "error",
"prefer-rest-params": "error",
"import/no-unresolved": "error",
"import/named": "off", //temp
"import/default": "error",
"import/namespace": "error",
"no-unused-vars": "off",
"no-debugger": "error",
strict: "error",
},
},
{
files: ["**/*.spec.js"],
languageOptions: {
globals: {
...globals.mocha,
},
},
rules: {
"prefer-arrow-callback": "off",
"mocha/no-setup-in-describe": "off",
"promise/no-callback-in-promise": "off",
"promise/catch-or-return": "off",
"promise/always-return": "off",
"mocha/no-mocha-arrows": "off",
},
extends: [],
},
eslintConfigPrettier, // goes last
]);
21 changes: 2 additions & 19 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const babel = require("gulp-babel");
const chmod = require("gulp-chmod");
const eslint = require("gulp-eslint");
const prettier = require("gulp-prettier");
const gulp = require("gulp");

gulp.task("scripts", (done) => {
Expand All @@ -14,20 +12,5 @@ gulp.task("scripts", (done) => {
done();
});

gulp.task("lint", () =>
gulp
.src("./lib/**/*.js")
.pipe(
eslint({
fix: true,
}),
)
.pipe(eslint.format())
.pipe(prettier())
.pipe(gulp.dest("./lib/")),
);

gulp.task("watch", () => gulp.watch("./lib/**/*.js", gulp.series(["lint", "scripts"])));

gulp.task("build", gulp.series(["lint", "scripts"]));
gulp.task("default", gulp.series(["build", "watch"]));
gulp.task("build", gulp.series(["scripts"]));
gulp.task("default", gulp.series(["build"]));
4 changes: 3 additions & 1 deletion lib/gren-examples.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env node

import gren from "commander";
import { Command } from "commander";
import chalk from "chalk";
import examples from "./_examples";

const gren = new Command();

let command;
const commandList = Object.keys(examples).filter(
(example) => example !== "default" && example !== "generateExamples",
Expand Down
5 changes: 4 additions & 1 deletion lib/gren-init.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#!/usr/bin/env node

import gren from "commander";
import { Command } from "commander";
import { green } from "chalk";
import ObjectAssignDeep from "object-assign-deep";
import init from "../dist/_init";
import utils from "../dist/_utils";
import fs from "fs";

const gren = new Command();

gren
.name(`${green("gren")} release`)
.description("Initialise the module options.")
Expand Down Expand Up @@ -48,6 +50,7 @@ init()
fs.writeFileSync(fileType, fileContent);

console.log(green(`\nGreat news! Your ${fileType} as been created!`));
return;
},
)
.catch((error) => {
Expand Down
5 changes: 3 additions & 2 deletions lib/gren.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env node

import gren from "commander";
import { Command } from "commander";
import { version, description } from "../package.json";

const gren = new Command("gren");
const argvWithVersion = (argvs) => {
const vPos = argvs.indexOf("-v");

Expand All @@ -15,7 +16,7 @@ const argvWithVersion = (argvs) => {

gren
.version(version)
.description(`gren (🤖 ) ${description}`)
.description(`gren (🤖) ${description}`)
.usage("<command> [options]")
.command("init", "Initialise the module options")
.alias("i")
Expand Down
14 changes: 7 additions & 7 deletions lib/src/GitHubInfo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { exec } from "child_process";
import chalk from "chalk";
import { matchAll } from "regex-match-all";

/** Class retrieving GitHub informations from the folder where .git is initialised. */
class GitHubInfo {
Expand Down Expand Up @@ -52,7 +51,7 @@ class GitHubInfo {
}
});
})
.then(callback)
.then(callback) // eslint-disable-line promise/no-callback-in-promise
.catch((error) => {
throw new Error(
chalk.red(error) +
Expand All @@ -75,20 +74,21 @@ class GitHubInfo {
*/
_repo(callback) {
return this._executeCommand("git config remote.origin.url", (repo) => {
const repoPath = matchAll(/([\w-.]+)\/([\w-.]+?)(\.git)?$/g, repo);
const regex = /([\w-.]+)\/([\w-.]+?)(\.git)?$/g;
const matches = [...repo.matchAll(regex)];

if (!repoPath[1]) {
if (!matches[0]) {
return Promise.reject(new Error("No repo found"));
}

const user = repoPath[1][0];
const name = repoPath[1][1];
const user = matches[0][1];
const name = matches[0][2];

return {
username: user,
repo: name,
};
}).then(callback);
}).then(callback); // eslint-disable-line promise/no-callback-in-promise
}

/**
Expand Down
5 changes: 2 additions & 3 deletions lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ class Gren {
*
* @return {string}
*/
// eslint-disable-next-line camelcase

_templateCommits({
sha,
html_url,
Expand All @@ -587,7 +587,7 @@ class Gren {
{
sha,
message: message.split("\n")[0],
// eslint-disable-next-line camelcase

url: html_url,
author: author && author.login,
authorName: name,
Expand Down Expand Up @@ -1082,7 +1082,6 @@ class Gren {
const since = releaseRanges[releaseRanges.length - 1][1].date;
let relevantIssues = [];

// eslint-disable-next-line prefer-regex-literals
const re = new RegExp("([\\w-]+)/([\\w-]+)/issues/([0-9]+)", "gi");
const prs = await this._getMergedPullRequests(since);
prs.sort((pr1, pr2) => new Date(pr2.merged_at) - new Date(pr1.merged_at));
Expand Down
18 changes: 14 additions & 4 deletions lib/src/Program.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import GitHubInfo from "./GitHubInfo";
import program from "commander";
import { Command } from "commander";
import { getGrenConfig } from "./_utils.js";

/** Class creating a Commander program, managing the options passed via bash and config file. */
class Program {
constructor(props) {
const { programOptions, defaults } = this._consumeOptions(props.options);
const program = new Command();

this.name = props.name;
this.description = props.description;
Expand Down Expand Up @@ -118,9 +119,18 @@ class Program {
* @return {Commander}
*/
_programWithOptions(program, options) {
options.forEach(({ name, description, action, defaultValue }) =>
program.option(...[name, description, action, defaultValue].filter(Boolean)),
);
options.forEach(({ name, description, action, defaultValue }) => {
if (typeof name !== "string" || !name.trim()) return; // ⛔ skip if name is missing/blank

const args = [name, description, action, defaultValue].filter((v) => v !== undefined);

if (!name || typeof name !== "string" || !name.trim()) {
console.warn("Invalid option name:", { name, description });
}

program.option(...args);
});

return program;
}

Expand Down
Loading