Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
chore(twig): updated dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mgrsskls committed Dec 17, 2021
1 parent e473dc0 commit 6f8c64f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 32 deletions.
58 changes: 29 additions & 29 deletions packages/stack-twig/lib/lint.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,41 @@
const chalk = require("chalk");
const { spawn } = require("child_process");

/**
* @param {string} command
* @returns {Array}
*/
function getAdditionalParams(command) {
const indexCommand = process.argv.indexOf(command);

if (indexCommand >= 0) {
const args = process.argv.slice(indexCommand + 1);
const indexOfOnly = args.indexOf("--only");
const indexOfSkip = args.indexOf("--skip");

if (indexOfOnly >= 0 || indexOfSkip >= 0) {
const index = indexOfOnly >= 0 ? indexOfOnly : indexOfSkip;

args.splice(index, 2);
}

return args;
}

return [];
}
const {
getAdditionalParams,
getStagedFiles,
} = require("@factorial/stack-core/helpers");

/**
* Returns an array with all cli params after "lint --only twig"
*
* @param {string} rootFolder
* @returns {Array}
*/
function getArgs(rootFolder) {
const args = [
async function getArgs(rootFolder) {
const defaultParams = [
"--severity",
"error",
"--ruleset",
"Factorial\\twigcs\\TwigCsRuleset",
...getAdditionalParams("lint"),
];
const additionalParams = getAdditionalParams("lint");
const hasStagedParam = additionalParams.includes("--staged");
const directories = hasStagedParam
? await getStagedFiles(["twig"])
: [rootFolder];

if (directories.length === 0) {
return null;
}

return args ? [rootFolder, ...args] : [rootFolder];
return [
...directories,
...defaultParams,
...(hasStagedParam
? additionalParams.filter((entry) => entry !== "--staged")
: additionalParams),
];
}

/**
Expand All @@ -53,8 +48,13 @@ function getArgs(rootFolder) {
* @param {object} config
* @returns {Promise} - gets resolved/rejected based on if twig linting failed or not
*/
module.exports = function lint({ rootFolder }, config) {
const args = getArgs(config?.folder || rootFolder);
module.exports = async function lint({ rootFolder }, config) {
const args = await getArgs(config?.folder || rootFolder);

if (!args) {
console.log(`\ntwigcs: ${chalk.green("0 errors!")}`);
return Promise.resolve();
}

return new Promise((resolve, reject) => {
const process = spawn(
Expand Down
4 changes: 2 additions & 2 deletions packages/stack-twig/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
"release": "standard-version -t twig/v"
},
"dependencies": {
"chalk": "^4.1.1"
"chalk": "^4.1.2"
},
"peerDependencies": {
"@factorial/stack-core": "^0.3.16"
"@factorial/stack-core": "^0.3.17"
}
}
2 changes: 1 addition & 1 deletion packages/stack-twig/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ ansi-styles@^4.1.0:
dependencies:
color-convert "^2.0.1"

chalk@^4.1.1:
chalk@^4.1.2:
version "4.1.2"
resolved "https://registry.yarnpkg.com/chalk/-/chalk-4.1.2.tgz#aac4e2b7734a740867aeb16bf02aad556a1e7a01"
integrity sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==
Expand Down

0 comments on commit 6f8c64f

Please sign in to comment.