Skip to content

Commit

Permalink
fix: fix NUTs because topics changed (#330)
Browse files Browse the repository at this point in the history
* chore: dep bumps

* chore: snapshot (short chars)

* test: split slow nuts

* fix: mark external topics that aren't top-level commands

* test: ut for function, explanatory comments, proper test watching

* refactor: comment cleanup, immutability
  • Loading branch information
mshanemc authored Jun 2, 2023
1 parent 7fc11df commit fc792dd
Show file tree
Hide file tree
Showing 11 changed files with 574 additions and 517 deletions.
1 change: 1 addition & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"require": "ts-node/register,source-map-support/register",
"watch-extensions": "ts",
"watch-files": ["src", "test"],
"recursive": true,
"reporter": "spec",
"timeout": 240000
Expand Down
193 changes: 89 additions & 104 deletions command-snapshot.json
Original file line number Diff line number Diff line change
@@ -1,105 +1,90 @@
[
{
"command": "dev:audit:messages",
"plugin": "@salesforce/plugin-dev",
"flags": [
"json",
"messages-dir",
"project-dir",
"source-dir"
],
"alias": []
},
{
"command": "dev:configure:repo",
"plugin": "@salesforce/plugin-dev",
"flags": [
"bot",
"dry-run",
"json",
"repository"
],
"alias": []
},
{
"command": "dev:configure:secrets",
"plugin": "@salesforce/plugin-dev",
"flags": [
"dry-run",
"json",
"repository"
],
"alias": []
},
{
"command": "dev:convert:messages",
"plugin": "@salesforce/plugin-dev",
"flags": [
"file-name",
"json",
"project-dir"
],
"alias": []
},
{
"command": "dev:convert:script",
"plugin": "@salesforce/plugin-dev",
"flags": [
"json",
"no-prompt",
"script"
],
"alias": []
},
{
"command": "dev:generate:command",
"plugin": "@salesforce/plugin-dev",
"flags": [
"force",
"name",
"nuts",
"unit"
],
"alias": []
},
{
"command": "dev:generate:flag",
"plugin": "@salesforce/plugin-dev",
"flags": [
"dry-run"
],
"alias": []
},
{
"command": "dev:generate:hook",
"plugin": "@salesforce/plugin-dev",
"flags": [
"event",
"force"
],
"alias": []
},
{
"command": "dev:generate:library",
"plugin": "@salesforce/plugin-dev",
"flags": [],
"alias": []
},
{
"command": "dev:generate:plugin",
"plugin": "@salesforce/plugin-dev",
"flags": [],
"alias": [
"plugins:generate"
]
},
{
"command": "dev:hook",
"plugin": "@salesforce/plugin-dev",
"flags": [
"json",
"plugin"
],
"alias": []
}
]
{
"command": "dev:audit:messages",
"plugin": "@salesforce/plugin-dev",
"flags": ["json", "messages-dir", "project-dir", "source-dir"],
"alias": [],
"flagChars": ["m", "p", "s"],
"flagAliases": ["messagesdir", "projectdir", "sourcedir"]
},
{
"command": "dev:configure:repo",
"plugin": "@salesforce/plugin-dev",
"flags": ["bot", "dry-run", "json", "repository"],
"alias": [],
"flagChars": ["b", "d", "r"],
"flagAliases": ["dryrun"]
},
{
"command": "dev:configure:secrets",
"plugin": "@salesforce/plugin-dev",
"flags": ["dry-run", "json", "repository"],
"alias": [],
"flagChars": ["d", "r"],
"flagAliases": ["dryrun"]
},
{
"command": "dev:convert:messages",
"plugin": "@salesforce/plugin-dev",
"flags": ["file-name", "json", "project-dir"],
"alias": [],
"flagChars": ["f", "p"],
"flagAliases": ["filename", "projectdir"]
},
{
"command": "dev:convert:script",
"plugin": "@salesforce/plugin-dev",
"flags": ["json", "no-prompt", "script"],
"alias": [],
"flagChars": ["s"],
"flagAliases": []
},
{
"command": "dev:generate:command",
"plugin": "@salesforce/plugin-dev",
"flags": ["force", "name", "nuts", "unit"],
"alias": [],
"flagChars": ["n"],
"flagAliases": []
},
{
"command": "dev:generate:flag",
"plugin": "@salesforce/plugin-dev",
"flags": ["dry-run"],
"alias": [],
"flagChars": ["d"],
"flagAliases": ["dryrun"]
},
{
"command": "dev:generate:hook",
"plugin": "@salesforce/plugin-dev",
"flags": ["event", "force"],
"alias": [],
"flagChars": [],
"flagAliases": []
},
{
"command": "dev:generate:library",
"plugin": "@salesforce/plugin-dev",
"flags": [],
"alias": [],
"flagChars": [],
"flagAliases": []
},
{
"command": "dev:generate:plugin",
"plugin": "@salesforce/plugin-dev",
"flags": [],
"alias": ["plugins:generate"],
"flagChars": [],
"flagAliases": []
},
{
"command": "dev:hook",
"plugin": "@salesforce/plugin-dev",
"flags": ["json", "plugin"],
"alias": [],
"flagChars": ["p"],
"flagAliases": []
}
]
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
"dependencies": {
"@oclif/core": "^2.8.5",
"@octokit/rest": "^19.0.7",
"@salesforce/core": "^3.36.0",
"@salesforce/kit": "^3.0.0",
"@salesforce/sf-plugins-core": "^2.4.2",
"@salesforce/ts-types": "^2.0.1",
"@salesforce/core": "^4.1.0",
"@salesforce/kit": "^3.0.2",
"@salesforce/sf-plugins-core": "^3.0.2",
"@salesforce/ts-types": "^2.0.2",
"change-case": "^4.1.2",
"fast-glob": "^3.2.12",
"got": "^11.8.5",
Expand All @@ -25,12 +25,12 @@
"yosay": "^2.0.2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^3.3.14",
"@oclif/plugin-command-snapshot": "^4.0.2",
"@oclif/test": "^2.3.17",
"@salesforce/cli-plugins-testkit": "^3.3.5",
"@salesforce/cli-plugins-testkit": "^4.0.1",
"@salesforce/dev-config": "^4.0.1",
"@salesforce/dev-scripts": "^5.1.0",
"@salesforce/plugin-command-reference": "^2.4.2",
"@salesforce/dev-scripts": "^5.4.2",
"@salesforce/plugin-command-reference": "^3.0.2",
"@salesforce/prettier-config": "^0.0.3",
"@salesforce/ts-sinon": "1.4.7",
"@swc/core": "1.3.20",
Expand All @@ -42,25 +42,25 @@
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.52.0",
"chai": "^4.3.7",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.6.0",
"eslint": "^8.41.0",
"eslint-config-prettier": "^8.8.0",
"eslint-config-salesforce": "^2.0.1",
"eslint-config-salesforce-license": "^0.2.0",
"eslint-config-salesforce-typescript": "^1.1.1",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-header": "^3.1.1",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-sf-plugin": "^1.15.1",
"eslint-plugin-jsdoc": "^43.0.5",
"eslint-plugin-sf-plugin": "^1.15.6",
"husky": "^7.0.4",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"oclif": "^3.6.1",
"oclif": "^3.9.0",
"prettier": "^2.8.8",
"pretty-quick": "^3.1.3",
"shx": "^0.3.3",
"sinon": "10.0.0",
"ts-node": "^10.4.0",
"typescript": "^4.9.4",
"typescript": "^4.9.5",
"wireit": "^0.9.5",
"yeoman-test": "^6.3.0"
},
Expand Down
20 changes: 12 additions & 8 deletions src/generators/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,23 +23,27 @@ export interface CommandGeneratorOptions extends Generator.GeneratorOptions {
unit: boolean;
}

/** returns the modifications that need to be made for the oclif pjson topics information. Returns an empty object for "don't change anything" */
export function addTopics(
newCmd: string,
existingTopics: Record<string, Topic>,
commands: string[] = []
): Record<string, Topic> {
const updated: Record<string, Topic> = {};

const paths: string[] = [];
const parts = newCmd.split(':').slice(0, -1);
while (parts.length > 0) {
const name = parts.join('.');
if (name) paths.push(name);
parts.pop();
}
const paths = newCmd
.split(':')
// omit last word since it's not a topic, it's the command name
.slice(0, -1)
.map((_, index, array) => array.slice(0, index + 1).join('.'))
// reverse to build up the object from most specific to least
.reverse();

for (const p of paths) {
const isExternal = commands.includes(p);
const pDepth = p.split('.').length;
// if new command if foo.bar and there are any commands in the foo topic, this should be marked external.
// if new command if foo.bar.baz and there are any commands in the foo.bar subtopic, it should be marked external.
const isExternal = commands.some((c) => c.split('.').slice(0, pDepth).join('.') === p);
const existing = get(updated, p);
if (existing) {
const merged = isExternal
Expand Down
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { Flags } from '@salesforce/sf-plugins-core';
export type Topic = {
description?: string;
external?: boolean;
subtopics: Topic;
subtopics?: Record<string, Topic>;
};

export type NYC = {
Expand Down
Loading

0 comments on commit fc792dd

Please sign in to comment.