Skip to content
Snippets Groups Projects
Commit 0d156199 authored by Baptiste Lemoine's avatar Baptiste Lemoine Committed by tykayn
Browse files

:zap: add Husky to automatically lint and format things with Prettier

parent fbaedac0
No related branches found
No related tags found
2 merge requests!1296WIP: Feature/husky linting,!1295Feature/husky linting
{"/var/www/html/duniter/app/lib/common-libs/index.ts":{"size":959,"mtime":1587206548928,"hashOfConfig":"1m0359q","results":{"filePath":"/var/www/html/duniter/app/lib/common-libs/index.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/var/www/html/duniter/app/lib/common-libs/moment.ts":{"size":736,"mtime":1587206548928,"hashOfConfig":"1m0359q","results":{"filePath":"/var/www/html/duniter/app/lib/common-libs/moment.ts","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0,"output":"// Source file from duniter: Crypto-currency software to manage libre currency such as Ğ1\n// Copyright (C) 2018 Cedric Moreau <cem.moreau@gmail.com>\n//\n// This program is free software: you can redistribute it and/or modify\n// it under the terms of the GNU Affero General Public License as published by\n// the Free Software Foundation, either version 3 of the License, or\n// (at your option) any later version.\n//\n// This program is distributed in the hope that it will be useful,\n// but WITHOUT ANY WARRANTY; without even the implied warranty of\n// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n// GNU Affero General Public License for more details.\n\nconst _moment_ = require(\"moment\")\n\nexport const moment = _moment_\n"}}}
\ No newline at end of file
{
"parserOptions": {
"ecmaVersion": 8
"ecmaVersion": 8,
"sourceType": "module"
},
"plugins": [
"mocha"
......
......@@ -11,30 +11,30 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
const Command = require('commander').Command;
const pjson = require('../package.json');
const Command = require("commander").Command;
const pjson = require("../package.json");
export const ExecuteCommand = () => {
const options: any = [];
const commands: any = [];
return {
addOption: (optFormat: string, optDesc: string, optParser: any) =>
options.push({ optFormat, optDesc, optParser }),
addOption: (optFormat:string, optDesc:string, optParser:any) => options.push({ optFormat, optDesc, optParser }),
addCommand: (command:any, executionCallback:any) => commands.push({ command, executionCallback }),
addCommand: (command: any, executionCallback: any) =>
commands.push({ command, executionCallback }),
// To execute the provided command
execute: async (programArgs: string[]) => {
const program = new Command();
// Callback for command success
let onResolve: any;
// Callback for command rejection
let onReject:any = () => Promise.reject(Error("Uninitilized rejection throw"));
let onReject: any = () =>
Promise.reject(Error("Uninitilized rejection throw"));
// Command execution promise
const currentCommand = new Promise((resolve, reject) => {
......@@ -44,43 +44,84 @@ export const ExecuteCommand = () => {
program
.version(pjson.version)
.usage('<command> [options]')
.option('--home <path>', 'Path to Duniter HOME (defaults to "$HOME/.config/duniter").')
.option('-d, --mdb <name>', 'Database name (defaults to "duniter_default").')
.option('--autoconf', 'With `config` and `init` commands, will guess the best network and key options witout asking for confirmation')
.option('--addep <endpoint>', 'With `config` command, add given endpoint to the list of endpoints of this node')
.option('--remep <endpoint>', 'With `config` command, remove given endpoint to the list of endpoints of this node')
.option('--cpu <percent>', 'Percent of CPU usage for proof-of-work computation', parsePercent)
.option('--nb-cores <number>', 'Number of cores uses for proof-of-work computation', parseInt)
.option('--prefix <nodeId>', 'Prefix node id for the first character of nonce', parseInt)
.option('-c, --currency <name>', 'Name of the currency managed by this node.')
.option('--nostdout', 'Disable stdout printing for `export-bc` command')
.option('--noshuffle', 'Disable peers shuffling for `sync` command')
.option('--socks-proxy <host:port>', 'Use Socks Proxy')
.option('--tor-proxy <host:port>', 'Use Tor Socks Proxy')
.option('--reaching-clear-ep <clear|tor|none>', 'method for reaching an clear endpoint')
.option('--force-tor', 'force duniter to contact endpoint tor (if you redirect the traffic to tor yourself)')
.option('--rm-proxies', 'Remove all proxies')
.option('--timeout <milliseconds>', 'Timeout to use when contacting peers', parseInt)
.option('--httplogs', 'Enable HTTP logs')
.option('--nohttplogs', 'Disable HTTP logs')
.option('--isolate', 'Avoid the node to send peering or status informations to the network')
.option('--forksize <size>', 'Maximum size of fork window', parseInt)
.option('--notrim', 'Disable the INDEX trimming.')
.option('--notrimc', 'Disable the C_INDEX trimming specifically.')
.option('--memory', 'Memory mode')
;
.usage("<command> [options]")
.option(
"--home <path>",
'Path to Duniter HOME (defaults to "$HOME/.config/duniter").'
)
.option(
"-d, --mdb <name>",
'Database name (defaults to "duniter_default").'
)
.option(
"--autoconf",
"With `config` and `init` commands, will guess the best network and key options witout asking for confirmation"
)
.option(
"--addep <endpoint>",
"With `config` command, add given endpoint to the list of endpoints of this node"
)
.option(
"--remep <endpoint>",
"With `config` command, remove given endpoint to the list of endpoints of this node"
)
.option(
"--cpu <percent>",
"Percent of CPU usage for proof-of-work computation",
parsePercent
)
.option(
"--nb-cores <number>",
"Number of cores uses for proof-of-work computation",
parseInt
)
.option(
"--prefix <nodeId>",
"Prefix node id for the first character of nonce",
parseInt
)
.option(
"-c, --currency <name>",
"Name of the currency managed by this node."
)
.option("--nostdout", "Disable stdout printing for `export-bc` command")
.option("--noshuffle", "Disable peers shuffling for `sync` command")
.option("--socks-proxy <host:port>", "Use Socks Proxy")
.option("--tor-proxy <host:port>", "Use Tor Socks Proxy")
.option(
"--reaching-clear-ep <clear|tor|none>",
"method for reaching an clear endpoint"
)
.option(
"--force-tor",
"force duniter to contact endpoint tor (if you redirect the traffic to tor yourself)"
)
.option("--rm-proxies", "Remove all proxies")
.option(
"--timeout <milliseconds>",
"Timeout to use when contacting peers",
parseInt
)
.option("--httplogs", "Enable HTTP logs")
.option("--nohttplogs", "Disable HTTP logs")
.option(
"--isolate",
"Avoid the node to send peering or status informations to the network"
)
.option("--forksize <size>", "Maximum size of fork window", parseInt)
.option("--notrim", "Disable the INDEX trimming.")
.option("--notrimc", "Disable the C_INDEX trimming specifically.")
.option("--memory", "Memory mode");
for (const opt of options) {
program
.option(opt.optFormat, opt.optDesc, opt.optParser);
program.option(opt.optFormat, opt.optDesc, opt.optParser);
}
for (const cmd of commands) {
......@@ -90,7 +131,10 @@ export const ExecuteCommand = () => {
.action(async function () {
const args = Array.from(arguments);
try {
const resOfExecution = await cmd.executionCallback.apply(null, [program].concat(args));
const resOfExecution = await cmd.executionCallback.apply(
null,
[program].concat(args)
);
onResolve(resOfExecution);
} catch (e) {
onReject(e);
......@@ -98,19 +142,21 @@ export const ExecuteCommand = () => {
});
}
program
.on('*', function (cmd:any) {
console.log("Unknown command '%s'. Try --help for a listing of commands & options.", cmd);
program.on("*", function (cmd: any) {
console.log(
"Unknown command '%s'. Try --help for a listing of commands & options.",
cmd
);
onResolve();
});
program.parse(programArgs);
if (programArgs.length <= 2) {
onReject('No command given.');
onReject("No command given.");
}
return currentCommand;
}
},
};
};
......
......@@ -11,6 +11,6 @@
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
const _moment_ = require("moment")
const _moment_ = require("moment");
export const moment = _moment_
\ No newline at end of file
export const moment = _moment_;
......@@ -30,6 +30,11 @@
"test": "nyc --reporter html mocha",
"start": "node bin/duniter start",
"build": "tsc && cd \"node_modules/duniter-ui\" && npm install && npm run build",
"lint": "lint-staged",
"prettier": "prettier --write app/**/*/*.ts",
"reformat": "eslint --cache --fix app/**/*/*.ts",
"format:check": "prettier --list-different \"app/**/*.{jsx,ts,tsx,json}\"",
"format:all": "prettier --write \"app/**/*.{jsx,ts,tsx,json}\"",
"test-travis": "nyc --reporter lcovonly mocha test/"
},
"nyc": {
......@@ -91,6 +96,7 @@
"node-pre-gyp": "0.6.34",
"node-uuid": "1.4.8",
"optimist": "0.6.1",
"prettier": "^2.0.4",
"q-io": "^1.13.5",
"querablep": "^0.1.0",
"request": "2.81.0",
......@@ -119,6 +125,8 @@
"coveralls": "2.11.4",
"eslint": "4.18.2",
"eslint-plugin-mocha": "4.8.0",
"husky": ">=4",
"lint-staged": ">=10",
"mocha": "^3.4.2",
"mocha-eslint": "0.1.7",
"nyc": "^11.0.3",
......@@ -133,5 +141,15 @@
"peerDependencies": {},
"bin": {
"duniter": "./bin/duniter"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"app/**/*.{js,jsx,ts,tsx,md,html,css,scss}": [
"prettier --write"
]
}
}
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment