Skip to content

Commit

Permalink
Merge pull request #317 from salesforcecli/sm/win-generator-fix
Browse files Browse the repository at this point in the history
Sm/win-generator-fix
  • Loading branch information
WillieRuemmele authored May 6, 2023
2 parents 656f4de + 175403e commit 46ac85e
Show file tree
Hide file tree
Showing 22 changed files with 1,430 additions and 2,186 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ docs
package.json.bak.

# -- CLEAN ALL
*.tsbuildinfo
.eslintcache
.wireit
node_modules

# --
Expand Down
2 changes: 1 addition & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"watch-extensions": "ts",
"recursive": true,
"reporter": "spec",
"timeout": 5000
"timeout": 240000
}
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.ejs
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022, Salesforce.com, Inc.
Copyright (c) 2023, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
156 changes: 129 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^2.0.7",
"@oclif/core": "^2.8.5",
"@octokit/rest": "^19.0.7",
"@salesforce/core": "^3.36.0",
"@salesforce/kit": "^1.8.2",
"@salesforce/sf-plugins-core": "^2.2.10",
"@salesforce/kit": "^3.0.0",
"@salesforce/sf-plugins-core": "^2.4.2",
"@salesforce/ts-types": "^2.0.1",
"change-case": "^4.1.2",
"fast-glob": "^3.2.12",
"got": "^11.8.5",
Expand All @@ -19,20 +20,20 @@
"replace-in-file": "^6.3.2",
"shelljs": "^0.8.5",
"tslib": "^2",
"yeoman-environment": "^3.13.0",
"yeoman-generator": "^5.7.0",
"yeoman-environment": "^3.15.1",
"yeoman-generator": "^5.8.0",
"yosay": "^2.0.2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^3.3.5",
"@oclif/test": "^2.3.17",
"@salesforce/cli-plugins-testkit": "^3.3.5",
"@salesforce/dev-config": "^3.1.0",
"@salesforce/dev-scripts": "^3.1.1",
"@salesforce/plugin-command-reference": "^2.2.10",
"@salesforce/dev-config": "^4.0.1",
"@salesforce/dev-scripts": "^5.0.1",
"@salesforce/plugin-command-reference": "^2.4.2",
"@salesforce/prettier-config": "^0.0.2",
"@salesforce/ts-sinon": "1.4.6",
"@swc/core": "^1.3.29",
"@swc/core": "1.3.20",
"@types/js-yaml": "^4.0.5",
"@types/shelljs": "^0.8.10",
"@types/yeoman-generator": "^5.2.10",
Expand All @@ -41,19 +42,16 @@
"@typescript-eslint/eslint-plugin": "^5.48.1",
"@typescript-eslint/parser": "^5.52.0",
"chai": "^4.3.7",
"cz-conventional-changelog": "^3.3.0",
"eslint": "^7.32.0",
"eslint": "^8.21.0",
"eslint-config-prettier": "^8.6.0",
"eslint-config-salesforce": "^0.1.6",
"eslint-config-salesforce": "^2.0.1",
"eslint-config-salesforce-license": "^0.2.0",
"eslint-config-salesforce-typescript": "^0.2.7",
"eslint-config-salesforce-typescript": "^1.1.1",
"eslint-plugin-header": "^3.0.0",
"eslint-plugin-import": "2.27.5",
"eslint-plugin-jsdoc": "^35.1.2",
"eslint-plugin-prettier": "^3.4.1",
"eslint-plugin-sf-plugin": "^1.14.1",
"eslint-plugin-jsdoc": "^39.3.6",
"eslint-plugin-sf-plugin": "^1.15.1",
"husky": "^7.0.4",
"lint-staged": "^11.2.6",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"oclif": "^3.6.1",
Expand All @@ -63,6 +61,7 @@
"sinon": "10.0.0",
"ts-node": "^10.4.0",
"typescript": "^4.9.4",
"wireit": "^0.9.5",
"yeoman-test": "^6.3.0"
},
"config": {
Expand All @@ -71,7 +70,7 @@
}
},
"engines": {
"node": ">=12.0.0"
"node": ">=16.0.0"
},
"files": [
"/lib",
Expand Down Expand Up @@ -123,24 +122,127 @@
},
"repository": "salesforcecli/plugin-dev",
"scripts": {
"build": "sf-build",
"build": "wireit",
"clean": "sf-clean",
"clean-all": "sf-clean all",
"clean:lib": "shx rm -rf lib && shx rm -rf coverage && shx rm -rf .nyc_output && shx rm -f oclif.manifest.json",
"compile": "sf-compile",
"compile": "wireit",
"docs": "sf-docs",
"format": "sf-format",
"lint": "sf-lint",
"format": "wireit",
"lint": "wireit",
"postpack": "shx rm -f oclif.manifest.json",
"posttest": "yarn lint && yarn test:deprecation-policy",
"prepack": "sf-prepack",
"pretest": "sf-compile-test",
"test": "sf-test --timeout 600000",
"test:deprecation-policy": "./bin/dev snapshot:compare",
"test": "wireit",
"test:nuts": "nyc mocha \"test/**/*.nut.ts\" --slow 4500 --timeout 600000 --parallel --jobs 10",
"test:only": "wireit",
"version": "oclif readme"
},
"publishConfig": {
"access": "public"
},
"wireit": {
"build": {
"dependencies": [
"compile",
"lint"
]
},
"compile": {
"command": "tsc -p . --pretty --incremental",
"files": [
"src/**/*.ts",
"**/tsconfig.json",
"messages/**"
],
"output": [
"lib/**",
"*.tsbuildinfo"
],
"clean": "if-file-deleted"
},
"format": {
"command": "prettier --write \"+(src|test|schemas)/**/*.+(ts|js|json)|command-snapshot.json\"",
"files": [
"src/**/*.ts",
"test/**/*.ts",
"schemas/**/*.json",
"command-snapshot.json",
".prettier*"
],
"output": []
},
"lint": {
"command": "eslint src test --color --cache --cache-location .eslintcache",
"files": [
"src/**/*.ts",
"test/**/*.ts",
"messages/**",
"**/.eslint*",
"**/tsconfig.json"
],
"output": []
},
"test:compile": {
"command": "tsc -p \"./test\" --pretty",
"files": [
"test/**/*.ts",
"**/tsconfig.json"
],
"output": []
},
"test": {
"dependencies": [
"test:compile",
"test:only",
"test:command-reference",
"test:deprecation-policy",
"lint",
"test:json-schema"
]
},
"test:only": {
"command": "nyc mocha \"test/**/*.test.ts\"",
"env": {
"FORCE_COLOR": "2"
},
"files": [
"test/**/*.ts",
"src/**/*.ts",
"**/tsconfig.json",
".mocha*",
"!*.nut.ts",
".nycrc"
],
"output": []
},
"test:command-reference": {
"command": "\"./bin/dev\" commandreference:generate --erroronwarnings",
"files": [
"src/**/*.ts",
"messages/**",
"package.json"
],
"output": [
"tmp/root"
]
},
"test:deprecation-policy": {
"command": "\"./bin/dev\" snapshot:compare",
"files": [
"src/**/*.ts"
],
"output": [],
"dependencies": [
"compile"
]
},
"test:json-schema": {
"command": "\"./bin/dev\" schema:compare",
"files": [
"src/**/*.ts",
"schemas"
],
"output": []
}
}
}
}
41 changes: 18 additions & 23 deletions src/commands/dev/audit/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/
import * as fs from 'fs';
import { join, parse, relative, resolve } from 'path';
import { ensureString } from '@salesforce/ts-types';
import { Logger, Messages } from '@salesforce/core';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { Duration, ThrottledPromiseAll } from '@salesforce/kit';
Expand Down Expand Up @@ -78,20 +79,22 @@ export default class AuditMessages extends SfCommand<AuditResults> {
aliases: ['sourcedir'],
}),
};
private flags: Interfaces.InferredFlags<typeof AuditMessages.flags>;
private messagesDirPath: string;
// set near top of run
private flags!: Interfaces.InferredFlags<typeof AuditMessages.flags>;
private logger!: Logger;

private messagesDirPath?: string;
private bundles: string[] = [];
private sourceDirPath: string;
private sourceDirPath?: string;
private source: Map<string, string> = new Map();
private auditResults: AuditResults = {
unusedBundles: [],
unusedMessages: [],
missingBundles: [],
missingMessages: [],
};
private package: string;
private projectDir: string;
private logger: Logger;
private package?: string;
private projectDir?: string;
private graph: MultiDirectedGraph<Node> = new MultiDirectedGraph<Node>();

public async run(): Promise<AuditResults> {
Expand Down Expand Up @@ -119,14 +122,14 @@ export default class AuditMessages extends SfCommand<AuditResults> {
}

private async loadMessages(): Promise<void> {
this.messagesDirPath = resolve(this.projectDir, this.flags['messages-dir']);
this.messagesDirPath = resolve(ensureString(this.projectDir), this.flags['messages-dir']);
this.logger.debug(`Loading messages from ${this.messagesDirPath}`);
const messagesDir = await fs.promises.readdir(this.messagesDirPath, { withFileTypes: true });
Messages.importMessagesDirectory(this.messagesDirPath);
this.bundles = messagesDir.filter((entry) => entry.isFile()).map((entry) => entry.name);
this.logger.debug(`Loaded ${this.bundles.length} bundles with names ${this.bundles.toString()}`);
const bundleMap = this.bundles.reduce((m, bundle) => {
const count = m.get(parse(bundle).name) || 0;
const count = m.get(parse(bundle).name) ?? 0;
m.set(parse(bundle).name, count + 1);
return m;
}, new Map<string, number>());
Expand All @@ -139,14 +142,14 @@ export default class AuditMessages extends SfCommand<AuditResults> {
}

private async loadSource(): Promise<void> {
this.sourceDirPath = resolve(this.projectDir, this.flags['source-dir']);
this.sourceDirPath = resolve(ensureString(this.projectDir), this.flags['source-dir']);
this.logger.debug(`Loading source from ${this.sourceDirPath}`);
const throttledPromise = new ThrottledPromiseAll<string, void>({ concurrency: 10, timeout: Duration.minutes(5) });
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const fileProducer = async (file: string, producer: ThrottledPromiseAll<string, void>): Promise<void> => {
this.logger.trace(`Loading file ${file}`);
const fileContents = await fs.promises.readFile(file, 'utf8');
this.source.set(relative(this.projectDir, file), fileContents);
this.source.set(relative(ensureString(this.projectDir), file), fileContents);
};

const dirHandler = async (dir: string, producer: ThrottledPromiseAll<string, void>): Promise<void> => {
Expand Down Expand Up @@ -260,7 +263,7 @@ export default class AuditMessages extends SfCommand<AuditResults> {
this.bundles.forEach((bundleFileName) => {
this.logger.trace(`Adding bundle ${bundleFileName} to graph`);
// load the bundle and add its node in the graph
const bundle: Messages<string> = Messages.loadMessages(this.package, parse(bundleFileName).name);
const bundle: Messages<string> = Messages.loadMessages(ensureString(this.package), parse(bundleFileName).name);
const bundleName = parse(bundleFileName).name;
this.graph.addNode(bundleName, { type: 'bundle', name: bundleFileName, x: 1, y: 1 });
// add the messages nodes and edges to the graph
Expand Down Expand Up @@ -371,14 +374,10 @@ export default class AuditMessages extends SfCommand<AuditResults> {
.filterNodes(
(node, attrs) =>
attrs.type === 'messageReference' &&
!this.graph.someOutboundNeighbor(node, (msgNode, msgAtrs) => {
return msgAtrs.type === 'message';
})
!this.graph.someOutboundNeighbor(node, (msgNode, msgAtrs) => msgAtrs.type === 'message')
)
.map((key) => {
const bundleRef = this.graph.findInboundNeighbor(key, (node, attrs) => {
return attrs.type === 'bundleReference';
});
const bundleRef = this.graph.findInboundNeighbor(key, (node, attrs) => attrs.type === 'bundleReference');
if (!bundleRef) {
throw new Error(`Unable to find bundle reference for ${key}`);
}
Expand Down Expand Up @@ -410,19 +409,15 @@ export default class AuditMessages extends SfCommand<AuditResults> {
.filterNodes(
(node, attrs) =>
attrs.type === 'message' &&
!this.graph.someInboundNeighbor(node, (inboundNode, inboundAttrs) => {
return inboundAttrs.type === 'messageReference';
})
!this.graph.someInboundNeighbor(node, (inboundNode, inboundAttrs) => inboundAttrs.type === 'messageReference')
)
.map((key) => {
const [Bundle, Name] = key.split(':');
return { Bundle, Name, ReferencedInNonLiteral: nonLiteralMessageBundleRefs.has(Bundle) ? '*' : '' };
})
// filter out messages that are part of an unused bundle
.filter((unused) => !this.auditResults.unusedBundles.includes(unused.Bundle))
.sort((a, b) => {
return a.Bundle.localeCompare(b.Bundle) || a.Name.localeCompare(b.Name);
});
.sort((a, b) => a.Bundle.localeCompare(b.Bundle) || a.Name.localeCompare(b.Name));

const snowflakeMessages = this.auditResults.unusedMessages.filter(
(m) =>
Expand Down
2 changes: 1 addition & 1 deletion src/commands/dev/configure/repo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

// because github api isn't camelcased
/* eslint-disable camelcase */
import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
import { Messages } from '@salesforce/core';
import { Octokit } from '@octokit/rest';
import { OctokitError } from '../../../types';
Expand Down
6 changes: 3 additions & 3 deletions src/commands/dev/convert/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ export default class DevConvertMessages extends SfCommand<DevConvertMessagesResu
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
const contents = ([...bundle.messages.keys()] as string[])
.map((key) => {
.map((key) =>
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
return convertValue(key, bundle.messages.get(key) as ValueType);
})
convertValue(key, bundle.messages.get(key) as ValueType)
)
.join(skip1Line);
const newName = filename.replace(/\.js$|\.json$/, '.md');
await fs.promises.writeFile(newName, contents, 'utf8');
Expand Down
Loading

0 comments on commit 46ac85e

Please sign in to comment.