Skip to content

Commit

Permalink
metrics cli add support for string globs (#2595)
Browse files Browse the repository at this point in the history
* metrics cli add support for string globs

CLI can throw an error when globs are expanded and script gets too many arguments. For those cases we can use quotet globs so they will be expanded by script.

* remove test code
  • Loading branch information
clxandstuff authored Dec 6, 2022
1 parent 3a83401 commit 0ee5299
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 5 additions & 0 deletions bin/metrics/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@ const command = meow({
$ yarn sg-metrics [options...] <paths>
Options
--dry Dry run (no data is send to database)
--ignore Pattern to ignore files
`,
flags: {
dry: {
type: 'boolean',
default: false,
},
ignore: {
type: 'string',
default: null,
},
},
alias: {
h: 'help',
Expand Down
17 changes: 15 additions & 2 deletions bin/metrics/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ const {Lambda} = require('@aws-sdk/client-lambda');
const prettier = require('prettier');
const fs = require('fs');
const execSync = require('child_process').execSync;
const glob = require('glob');

/* eslint-disable no-console */

exports.main = async function (paths, {dry} = {}) {
exports.main = async function (paths, {dry, ignore} = {}) {
if (!paths) {
throw new Error(
'Missing paths. For more infgormation run: sg-metrics --help'
Expand All @@ -21,10 +22,22 @@ exports.main = async function (paths, {dry} = {}) {

const version = getVersion();

let files;

const globOptions = {
ignore: ignore || 'node_modules',
};

if (Array.isArray(paths)) {
files = paths.map(p => glob.sync(p, globOptions)).flat();
} else {
files = glob.sync(paths, globOptions);
}

const result = {
styleguideVersion: version,
commitID,
components: getComponents(paths),
components: getComponents(files),
commitDate: new Date(parseInt(commitDate, 10)).toISOString(),
project: getProject(),
};
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@
"chromatic": "NODE_ENV=production STORYBOOK_ENV=chromatic npx chromatic --exit-zero-on-changes",
"prettier-check": "prettier --check src",
"prettier-fix": "prettier --write src",
"run-codemod": "node ./bin/codemods/cli.js"
"run-codemod": "node ./bin/codemods/cli.js",
"run-metrics": "node ./bin/metrics/cli.js"
},
"jest": {
"setupFiles": [
Expand Down

0 comments on commit 0ee5299

Please sign in to comment.