New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@sketch-hq/sketch-assistant-cli

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sketch-hq/sketch-assistant-cli - npm Package Compare versions

Comparing version 5.0.0-next.15 to 5.0.0-next.16

# @sketch-hq/sketch-assistant-cli
## 5.0.0-next.16
### Minor Changes
- 974a5e4: Add a `--profile` flag for outputting basic statistics about the run instead of results.
- 8351103: Add rule timings to profile data.
### Patch Changes
- Updated dependencies [8351103]
- @sketch-hq/sketch-assistant-types@5.0.0-next.16
- @sketch-hq/sketch-assistant-utils@5.0.0-next.16
## 5.0.0-next.15
### Major Changes

@@ -5,0 +19,0 @@

@@ -64,3 +64,7 @@ "use strict";

folder.
--profile
Output statistics instead of results.
--workspace

@@ -139,2 +143,6 @@

},
profile: {
type: 'boolean',
default: false,
},
},

@@ -147,2 +155,3 @@ });

const writeFile = util_1.promisify(fs.writeFile);
const stat = util_1.promisify(fs.stat);
/**

@@ -206,2 +215,48 @@ * Return the path to a usable temporary directory that remains consistent between cli runs.

});
const makeProfileData = (cliResults) => __awaiter(void 0, void 0, void 0, function* () {
const profile = {};
for (const cliResult of cliResults) {
if (cliResult.code === 'error')
continue;
const processingTimeMS = cliResult.output.input.processedFile.profile.time;
const numObjects = cliResult.output.input.processedFile.profile.numObjects;
const sizeMB = (yield stat(cliResult.filepath)).size / 1024 / 1024;
const complexityObjPerMB = numObjects / sizeMB;
const objects = Object.keys(cliResult.output.input.processedFile.objects).reduce((acc, key) => {
return Object.assign(Object.assign({}, acc), {
// @ts-ignore
[key]: { count: cliResult.output.input.processedFile.objects[key].length } });
}, {});
profile[cliResult.filepath] = {
file: { processingTimeMS, numObjects, sizeMB, complexityObjPerMB, objects },
assistants: {},
};
Object.keys(cliResult.output.assistants).forEach((key) => {
const result = cliResult.output.assistants[key];
if (result.code === 'error')
return;
const violations = result.result.violations.length;
const ruleErrors = result.result.ruleErrors.length;
const ruleTimingsMS = result.result.profile.ruleTimings;
const runTimeMS = Object.keys(ruleTimingsMS).reduce((acc, key) => acc + ruleTimingsMS[key], 0);
const rules = Object.keys(result.result.profile.ruleTimings).reduce((acc, key) => {
const runTimeMS = result.result.profile.ruleTimings[key];
const violations = result.result.violations.filter((violation) => violation.ruleName === key).length;
const impactMSPerViolation = runTimeMS / violations;
return Object.assign(Object.assign({}, acc), { [key]: {
runTimeMS,
violations,
impactMSPerViolation,
} });
}, {});
profile[cliResult.filepath].assistants[result.result.metadata.assistant.name] = {
violations,
ruleErrors,
runTimeMS,
rules,
};
});
}
return profile;
});
/**

@@ -228,3 +283,3 @@ * Format results as a human readable string.

}
for (const [name, res] of Object.entries(cliResult.output)) {
for (const [name, res] of Object.entries(cliResult.output.assistants)) {
if (res.code === 'error') {

@@ -284,3 +339,3 @@ append(2, `${name}: ${chalk_1.default.red(res.result.message)}`);

const spinner = ora_1.default({
stream: cli.flags.json ? fs.createWriteStream('/dev/null') : process.stdout,
stream: cli.flags.json || cli.flags.profile ? fs.createWriteStream('/dev/null') : process.stdout,
});

@@ -364,2 +419,5 @@ spinner.start(spinnerMessage(filename, ''));

}
else if (cli.flags.profile) {
console.log(JSON.stringify(yield makeProfileData(results), null, 2));
}
else {

@@ -366,0 +424,0 @@ console.log(formatResults(results));

{
"name": "@sketch-hq/sketch-assistant-cli",
"version": "5.0.0-next.15",
"version": "5.0.0-next.16",
"bin": {

@@ -23,4 +23,4 @@ "sketch-assistants": "bin/cli.js"

"dependencies": {
"@sketch-hq/sketch-assistant-types": "5.0.0-next.15",
"@sketch-hq/sketch-assistant-utils": "5.0.0-next.15",
"@sketch-hq/sketch-assistant-types": "5.0.0-next.16",
"@sketch-hq/sketch-assistant-utils": "5.0.0-next.16",
"chalk": "4.0.0",

@@ -27,0 +27,0 @@ "conf": "6.2.4",

@@ -12,8 +12,32 @@ # sketch-assistant-cli

Until this package is published to npm the only way to invoke it is by building it from source and
invoking it directly.
### Global
In this folder:
```sh
npm i -g @sketch-hq/sketch-assistant-cli
```
Or,
```sh
yarn global add @sketch-hq/sketch-assistant-cli
```
The `sketch-assistants` command will then be available. See below for usage instructions.
### Local
Alternatively the CLI will work when installed locally to a project too.
```sh
yarn add @sketch-hq/sketch-assistant-cli
```
The `sketch-assistants` command will then be available to use in your `package.json` scripts.
## Local development
Setup the monorepo according to the [Getting Started](../../README.md#getting-started) instructions,
and then in this folder:
```sh
yarn build

@@ -23,4 +47,2 @@ ./bin/cli.js <args>

TODO: Update this section once this package is published to npm.
## Usage

@@ -61,2 +83,6 @@

#### `--profile`
Output statistics instead of results.
#### `--workspace`

@@ -63,0 +89,0 @@