sfdx-plugin-update-notifier 1.2.0 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## [1.2.2](https://github.com/jayree/sfdx-plugin-update-notifier/compare/v1.2.1...v1.2.2) (2022-10-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **deps:** bump oclif-plugin-update-notifier from 1.5.0 to 1.5.1 ([02e8e91](https://github.com/jayree/sfdx-plugin-update-notifier/commit/02e8e9109355e340b278304ef681ea7e70189a04))
7
+
8
+ ## [1.2.1](https://github.com/jayree/sfdx-plugin-update-notifier/compare/v1.2.0...v1.2.1) (2022-09-20)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add missing changelog hook ([11e9fe6](https://github.com/jayree/sfdx-plugin-update-notifier/commit/11e9fe6955ff44f3607df475e6bd367d6eef90c7))
14
+
1
15
  # [1.2.0](https://github.com/jayree/sfdx-plugin-update-notifier/compare/v1.1.0...v1.2.0) (2022-09-20)
2
16
 
3
17
 
package/README.md CHANGED
@@ -21,7 +21,7 @@ $ sfdx plugins:install sfdx-plugin-update-notifier
21
21
  $ sfdx plugins:[COMMAND]
22
22
  running command...
23
23
  $ sfdx plugins
24
- sfdx-plugin-update-notifier 1.2.0
24
+ sfdx-plugin-update-notifier 1.2.2
25
25
  $ sfdx help plugins:[COMMAND]
26
26
  USAGE
27
27
  $ sfdx plugins:COMMAND
@@ -0,0 +1,2 @@
1
+ import { Hook } from '@oclif/core';
2
+ export declare const changelog: Hook<'changelog'>;
@@ -0,0 +1,95 @@
1
+ /*
2
+ * Copyright (c) 2022, jayree
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ */
7
+ /* istanbul ignore file */
8
+ import { join } from 'node:path';
9
+ import fs from 'fs-extra';
10
+ import Debug from 'debug';
11
+ import TerminalRenderer from 'marked-terminal';
12
+ import { marked } from 'marked';
13
+ import semver from 'semver';
14
+ // original from https://github.com/salesforcecli/plugin-info/blob/main/src/shared/parseReleaseNotes.ts
15
+ const parseReleaseNotes = (notes, version) => {
16
+ let found = false;
17
+ let closestVersion;
18
+ let versions;
19
+ const parsed = marked.lexer(notes);
20
+ let tokens;
21
+ const findVersion = (desiredVersion) => {
22
+ versions = [];
23
+ tokens = parsed.filter((token) => {
24
+ // TODO: Could make header depth (2) a setting in oclif.info.releasenotes
25
+ if (token.type === 'heading' && token.depth <= 2) {
26
+ const coercedVersion = semver.coerce(token.text).version;
27
+ // We will use this to find the closest patch if passed version is not found
28
+ versions.push(coercedVersion);
29
+ if (coercedVersion === desiredVersion) {
30
+ found = true;
31
+ return token;
32
+ }
33
+ found = false;
34
+ }
35
+ else if (found === true) {
36
+ return token;
37
+ }
38
+ });
39
+ };
40
+ findVersion(version);
41
+ if (!tokens.length) {
42
+ // If version was not found, try again with the closest patch version
43
+ const semverRange = `${semver.major(version)}.${semver.minor(version)}.x`;
44
+ closestVersion = semver.maxSatisfying(versions, semverRange);
45
+ findVersion(closestVersion);
46
+ }
47
+ if (closestVersion !== undefined) {
48
+ const warning = marked.lexer(`# ATTENTION: Version ${version} was not found. Showing notes for closest patch version ${closestVersion}.`)[0];
49
+ tokens.unshift(warning);
50
+ }
51
+ return tokens;
52
+ };
53
+ // eslint-disable-next-line @typescript-eslint/require-await
54
+ export const changelog = async function () {
55
+ const debug = Debug(`${this.config.bin}:sfdx-plugin-update-notifier:hooks:changelog`);
56
+ process.once('exit', () => {
57
+ try {
58
+ const pluginRootPath = join(new URL('./', import.meta.url).pathname, '..', '..');
59
+ const { name, version } = fs.readJsonSync(join(pluginRootPath, 'package.json'));
60
+ const changelogFile = fs.readFileSync(join(pluginRootPath, 'CHANGELOG.md'), 'utf8');
61
+ const cacheDir = join(this.config.cacheDir, name);
62
+ const versionFile = join(cacheDir, 'version');
63
+ fs.ensureFileSync(versionFile);
64
+ let latestVersion;
65
+ try {
66
+ latestVersion = fs.readJSONSync(versionFile);
67
+ }
68
+ catch (error) {
69
+ latestVersion = { version: '0.0.0' };
70
+ }
71
+ debug({ latestVersion: latestVersion.version, version });
72
+ if (latestVersion.version !== version) {
73
+ const tokens = parseReleaseNotes(changelogFile, version);
74
+ if (!tokens.length) {
75
+ debug(`${name} - didn't find version '${version}'.`);
76
+ }
77
+ else {
78
+ marked.setOptions({
79
+ renderer: new TerminalRenderer({ emoji: false }),
80
+ });
81
+ tokens.unshift(marked.lexer(`# Changelog for '${name}':`)[0]);
82
+ this.log(marked.parser(tokens));
83
+ fs.writeJsonSync(versionFile, { version });
84
+ }
85
+ }
86
+ else {
87
+ debug(`${name} - no update`);
88
+ }
89
+ }
90
+ catch (error) {
91
+ debug(error);
92
+ }
93
+ });
94
+ };
95
+ //# sourceMappingURL=changelog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"changelog.js","sourceRoot":"","sources":["../../src/hooks/changelog.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,0BAA0B;AAC1B,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,MAAM,UAAU,CAAC;AAC1B,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,gBAAgB,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B,uGAAuG;AACvG,MAAM,iBAAiB,GAAG,CAAC,KAAa,EAAE,OAAe,EAAkB,EAAE;IAC3E,IAAI,KAAK,GAAG,KAAK,CAAC;IAClB,IAAI,cAAsB,CAAC;IAC3B,IAAI,QAAkB,CAAC;IAEvB,MAAM,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;IAEnC,IAAI,MAAsB,CAAC;IAE3B,MAAM,WAAW,GAAG,CAAC,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IAAI,2BAA2B,OAAO,IAAI,CAAC,CAAC;iBACtD;qBAAM;oBACL,MAAM,CAAC,UAAU,CAAC;wBAChB,QAAQ,EAAE,IAAI,gBAAgB,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC;qBACjD,CAAC,CAAC;oBACH,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,oBAAoB,IAAI,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;oBAC9D,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC;oBAChC,EAAE,CAAC,aAAa,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;iBAC5C;aACF;iBAAM;gBACL,KAAK,CAAC,GAAG,IAAI,cAAc,CAAC,CAAC;aAC9B;SACF;QAAC,OAAO,KAAK,EAAE;YACd,KAAK,CAAC,KAAK,CAAC,CAAC;SACd;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":"1.2.0","commands":{}}
1
+ {"version":"1.2.2","commands":{}}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "sfdx-plugin-update-notifier",
3
3
  "description": "update-notifier for sfdx plugins",
4
- "version": "1.2.0",
4
+ "version": "1.2.2",
5
5
  "author": "jayree",
6
6
  "type": "module",
7
7
  "bugs": "https://github.com/jayree/sfdx-plugin-update-notifier/issues",
@@ -9,7 +9,11 @@
9
9
  "@oclif/core": "^1.16.3",
10
10
  "@salesforce/kit": "^1.6.1",
11
11
  "debug": "^4.3.4",
12
+ "fs-extra": "^10.1.0",
13
+ "marked": "^4.1.0",
14
+ "marked-terminal": "^5.1.1",
12
15
  "oclif-plugin-update-notifier": "^1.5.0",
16
+ "semver": "^7.3.7",
13
17
  "tslib": "^2.4.0"
14
18
  },
15
19
  "devDependencies": {
@@ -29,6 +33,7 @@
29
33
  "@types/marked-terminal": "^3.1.3",
30
34
  "@types/mocha": "^9.1.1",
31
35
  "@types/node": "^18.7.18",
36
+ "@types/semver": "^7.3.12",
32
37
  "@types/sinon": "^10.0.13",
33
38
  "@typescript-eslint/eslint-plugin": "^5.38.0",
34
39
  "@typescript-eslint/parser": "^5.38.0",
@@ -75,7 +80,8 @@
75
80
  "bin": "sfdx",
76
81
  "hooks": {
77
82
  "init": "./lib/hooks/init",
78
- "prerun": "./lib/hooks/prerun"
83
+ "prerun": "./lib/hooks/prerun",
84
+ "update": "./lib/hooks/changelog"
79
85
  },
80
86
  "plugins": [
81
87
  "oclif-plugin-update-notifier"